|
|
源文件中_Interface文件夹下WndField.cpp文件
1 \4 w- w* \9 K; d; W搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )- W" X9 d9 T6 R% w9 \$ K
, @. j7 O4 T, |* f% fstruct sItem
3 H$ S! s/ d7 x* j* E3 Q{2 l, t2 A9 S1 r0 r7 b% c2 z
DWORD dwId;/ f+ T" Q. @) o" g H v
DWORD dwKind2;
' \3 y6 }2 _, `6 Z/ V {, C0 S, q [DWORD dwItemId;
' g; O S5 C7 m2 t! U) s( _; UBYTE nIndex;( Z& m) r t+ Y- I
sItem(){2 q6 z4 f _' `2 ^9 s
dwId = dwKind2 = dwItemId = nIndex = 0;. y# H* E" e. W% Y
}0 z5 ^, Z# v5 X) B
bool operator < (const sItem p2)# V% f' Y0 S' W; f( L/ ?7 I; f ~
{
7 X* J6 [1 x2 n# b& L- Y if (dwKind2 == p2.dwKind2)
4 e( v0 z: T% y* | {9 ^4 t7 _* [7 U! B& m, Y
return dwItemId < p2.dwItemId;
, S, O- ]; Z5 w- r( j }else{' w: o7 S: L6 Q2 ^" G+ K% F$ F' b
return dwKind2 < p2.dwKind2;
3 n/ d0 i2 J, r% S$ l7 V8 i, A }
8 r: f; \2 A4 i+ E" c$ j} [, @- x8 j+ h( q0 F5 e
};
# p K" a! g9 h1 Kclass CInventorySort
6 x* {- E/ @2 Q+ A9 c{
. W$ Y* w5 k L3 Z+ B! rpublic:
9 [$ k( S8 D! Z, \CInventorySort()6 k9 C, ^) Q8 W
{4 N0 F$ @; ^3 h( u
m_dwPos = 0;
7 {) i/ [1 z& b- R E4 O}
4 a4 }: Y& I1 h9 X& u- E~CInventorySort(){}- V0 ]' `7 V# r+ L& c1 x! T
private:' |0 A& t8 ]9 P+ i2 \# C1 {; W" {
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
/ r5 _8 [3 d0 {4 }% ADWORD m_dwPos;1 M* j" Q3 T5 g1 V S
public:
4 K& K5 Z4 ]9 W# j; W1 Tvoid Add(BYTE nIndex) K& g; l' I# v5 j$ {% B
{
1 k# m$ j- m* _! F k if (m_dwPos >= MAX_INVENTORY), M5 j# k9 f* }& U& o! J* \1 h: O
{( O0 \2 M- k( C5 p1 e
return;
5 |2 {$ W+ O3 m, A2 u }' \* [( A9 B! e* a' v: V2 C
m_Item[m_dwPos].nIndex = nIndex;' [) v" J- F/ K& ^# B5 ~7 f
m_Item[m_dwPos].dwId = m_dwPos;
; w! J3 p; x$ l m_dwPos++;
7 v' Y4 F1 x, R: H7 p0 V1 s}
- ]( A/ W& \, s: V& tBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列( U4 b. t' T1 J4 ]" d
{* y* V3 r3 z& P$ G& z8 S; x
for (int i=0;i<MAX_INVENTORY;i++)
& v0 R( q* ^1 d. q/ k {5 h( C8 a, Q0 o# d" q' l6 c
if (m_Item.dwId == dwId)
! J* H, s' h0 G4 V8 E4 w( X {
* w; T- I4 |; L8 s. ~0 _ return m_Item.nIndex;# p9 o: @! @3 x& V$ @' t
}
# \! N5 M0 v2 v1 C; y0 E }, C. I( n0 `0 n! Y
return 255;
" s& T7 L; o6 J}# F5 p+ L, A% h! X
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
( O. `3 `) N. D{1 V: f; t( E8 C9 t6 ]" L
BYTE nTmp = 0;
' Q1 Z3 L+ [3 s bool bDest = false,bSrc = false;7 \" u5 d/ K7 m$ g% ^# P. f+ C( L
for (int i=0;i<MAX_INVENTORY;i++)
( D( t; r( R6 l# E/ g- Z! L" Y {* i6 P) }# |3 L# x8 u% Y
if (dwSrcId == m_Item.dwId)) y' a2 L& \) f+ l( ^, t! r
{
* U( l: b: H) H& s* } //id相等 则 改变对应的dest和src6 T. j/ ]+ v/ e
nTmp = m_Item.nIndex;
6 ^) G( [2 Y1 u5 O5 G m_Item.nIndex = dest;$ l# C& G/ c1 V8 |# j
}
( l# Q/ }" R3 D3 L' @ }
1 P$ b) q' _ h5 E& C2 U //临时数据保存完毕,交换开始4 z* b* S4 V! e8 {* W& g' B
for (int i=0;i<MAX_INVENTORY;i++)) ~( Z; c' U/ ?( ]9 x$ S
{8 b; Q y- w( w% w: {
if (dest == m_Item.nIndex). o, [ o! M" N, q4 R! \
{& }4 G: t8 d) @/ Y& N' c3 @ {
//id相等 则 改变对应的dest和src
. |5 y: G7 E/ X2 _' a1 d m_Item.nIndex = nTmp;
# q/ u% O( W. x$ K7 y }& q& m7 Q- X+ Y( r/ B/ a0 r
}: y8 `" A' p0 N" l
}
' O5 ~5 H. F+ U3 v* F0 \) D; G, ]0 D};. m s1 q7 @ `" }8 [* E t. t
-------------------------------------------------------------------------
3 X0 @5 l4 K2 s1 J8 E/ g* k依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
# ]9 p' u' M/ @6 g6 m: K/ Z搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);9 A n- F/ J9 h6 J( @3 Y: u4 } q
紧靠其上添加:
! z. ?& g9 J: O6 R2 o P7 ^if( pWndBase == &m_wndMenu )3 N7 S+ n: H h/ z- u
{
5 F" X0 ~# w: r0 B( {! ~" j7 F5 }& _ switch( nID )
9 D0 N( D8 A" Q3 @3 b0 k {3 |# r. L5 a. r9 s$ l* K
case 2:* O* u3 V6 ~! `: A# G1 `3 ^
{8 X) A- Q9 g" Y$ \5 y7 Q( [8 E* o
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);; {" a) R* ?. Z5 v
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)). ^5 m( M* `* a% T+ B0 ?
{8 s% b* q7 |4 E5 l' h" L
break;
; u% Y4 A, ~4 M- q$ l& t }: p* l' d8 V# K4 N0 a' V l
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
/ O( ]% X+ M! Z6 F( u {
- j! Y+ o4 Z4 H$ k7 X4 w CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);$ I8 d% b/ a+ x |6 p- w+ C
if( !pItemElem )
: w% R5 F2 J4 w5 U3 d5 l continue;
J# V6 }# r9 g. B( F if(pItemElem->GetExtra() > 0)
$ m1 M3 S0 R& ?& F" W$ t0 L3 P continue;6 U7 e) j* J8 H& {0 l# q
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
! l/ \# U* u! d continue;6 s, h5 u$ h1 ?, L; R7 K$ e
if( g_pPlayer->IsUsing( pItemElem ) )
( `, ~$ E, y- T9 _% i+ T continue;
T! J5 @1 q. t! ^3 ] if( pItemElem->IsUndestructable() == TRUE ); @& u) o) f+ H
{1 s: } C; h* E" p% U% {& e2 c
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
" }4 Q e5 O- w/ j6 q9 N continue;; X- b9 G* _% D6 d* G% s! ]
}
) N \4 D7 e4 ~" }! Z; d; L. @ g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
- v6 ?( Q- Q$ v. w1 Y0 i- W }0 H% X5 B2 z; J: M: o: W( C @' ?
break;+ g2 u+ Z( ~1 |6 K. Y9 b7 V
}
2 U! c7 d3 C2 e: m case 1:
$ h$ c$ a" u" Z; v; g2 b {
& W; e6 `0 _8 E6 f) a //整理背包0 N# ]1 D& I) t4 H$ Z
//////////////////////////////////////////////////////////////////////////1 a$ t5 i( [% {; ]+ L
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );& ]" a6 N& y/ M+ l
//////////////////////////////////////////////////////////////////////////
; H3 w9 p1 D) H, v; _) ]! z //////////////////////////////////////////////////////////////////////////
& C( M# \3 n. J/ W; R5 u1 u CInventorySort* pInvSort = new CInventorySort;
* q& z$ w# R3 K% d% a vector <sItem> vItem;
6 k" I2 H+ B1 G. l/ m5 C" @' P/ K2 a8 g vItem.resize(MAX_INVENTORY);//初始化大小
. z2 V" P$ H' X9 x* M- @ { //////////////////////////////////////////////////////////////////////////
- ~2 D) p/ p+ p \6 V# `7 | //填充数据
% R8 E% ~2 p I9 w$ P: D X for (int i=0;i<MAX_INVENTORY;i++)
. l* U8 T$ F$ K) I$ \. v3 b {
! z9 C: e- j! ^2 G CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);& l' o& s* g) q
if (!pItemElem)
( F% _1 P7 L+ m( d3 v$ u! J {0 K3 O+ O/ i: t
vItem.dwKind2 = 0xffffffff;" I. [6 ~3 A4 J' h' ]. Y
vItem.dwItemId = 0xffffffff;/ L' S; g t; C/ ~- J
vItem.nIndex = i;
% F4 g6 C+ Y5 j V }else {
1 a4 J% @, q; \) X! J( A ItemProp* pProp = pItemElem->GetProp();
! d# I. x4 ^- ?: ~ vItem.dwKind2 = pProp->dwItemKind2;
( _, v6 K% O- f3 c P( g1 A vItem.dwItemId = pItemElem->m_dwItemId;
6 l. q' ?8 v* ~9 j( D vItem.nIndex = i;% q7 d" K: f) U6 e; R6 p4 U
}) S7 _% T% q9 d3 S+ R/ T; k
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);3 N0 s3 k0 \( Y5 w# v% ?
}
5 Q1 {& o, V: D) S //////////////////////////////////////////////////////////////////////////
9 I! z6 L2 h$ K* w& R4 p6 s2 v sort(vItem.begin(),vItem.end());//排序8 w9 u6 `) U: {$ L8 v) P2 H5 S
//////////////////////////////////////////////////////////////////////////; y2 c: H2 M: f9 Z; F& |
//交换, r) {' S0 C. q4 |: z1 l
for (size_t i=0;i<vItem.size();i++)
, g7 n! I3 w3 G. A {
1 q1 V& n) T6 Y# l" R7 X/ ?8 R% F //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);: i% Q; }7 ]- W- h; s" ]' D( |
pInvSort->Add(vItem.nIndex);3 }; M; e; H# h: t4 i) k
}/ ]- ~ `$ \0 I& a1 X
BYTE nDestPos = 0;
. T$ a2 X3 ~* V4 J3 n# W) O7 P for (int i=0;i<MAX_INVENTORY;i++)7 j7 n* d4 j) C B$ @8 s1 E* f
{
3 ~& s( V5 h2 F i" T5 ~* R CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
6 x. j2 s' W) W* x! O- g if (pItemElem)# u$ N, z' \* F! V: p+ \
{
/ M# s" i. W7 e if (IsUsingItem(pItemElem))
$ M$ b% n) m1 H# w& `, ~. @9 l; i {- O' X0 y! R/ K' k! R
//这个位置无法放
6 |; f5 E7 B; @ nDestPos++;
* s4 { X! b* n1 z( Q2 \, A E }
9 u/ H; ^$ [( \3 b$ u9 o6 h }
4 j5 S* Q1 D7 l3 m0 N0 m- D; R" R BYTE nSrc = pInvSort->GetItemSrc(i);
: M+ K: J6 s4 p- M0 z, M7 Q( b pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
# I. ^" M1 i4 r$ ?+ O if (pItemElem)
) y* @) K& G, l+ i9 Q3 l% \& E7 M2 m {( w5 j% g2 N# R1 E$ w: o
if (IsUsingItem(pItemElem)): f( |5 J0 H$ o9 t( r! h
{% r, H: w8 m* L4 Q
//这个道具无法移动,跳过, q8 ~0 D$ Q! @! C3 X1 Z; v
continue;
9 P( Z) K: Q/ |9 i/ B% | }$ I, O, Z$ H( h& I6 C. P2 u
}else{1 n7 B+ u/ A- ]3 {* _: A# O, F
//空位置 不用动
$ I5 q7 U4 \: K6 L continue;) q8 `5 Z7 d* r0 t
}
( r& U" {7 i" S- {& E0 G3 a0 E //////////////////////////////////////////////////////////////////////////
7 q' `: C/ b- k, P //开始移动1 R1 _3 X, e8 O" U' p
if (nSrc == nDestPos)
, Y7 ]$ t0 r. [* a( N2 v6 R* ~ {& I5 w) p, C! Q" ^/ `+ p1 I
//原地不动6 ?/ G; ~! y9 I
nDestPos++;8 e6 i7 G) a8 r0 k7 ]. o
continue;
+ a& }4 V# e0 } n+ c* x }
" u& |8 T2 H" n- f% Q pInvSort->MoveItem(i,nDestPos);
* h% l+ ?% o- Z, W9 w! c2 S! F: \3 ~ g_DPlay.SendMoveItem(0,nSrc,nDestPos);4 ?, s, _( |' q5 r5 H$ o
Sleep(5);
" s8 g4 R/ F% v- q- `4 @ //Error("移动 - %d->%d",nSrc,nDestPos);& [7 {% t. i6 }* m2 _4 m F
nDestPos++;8 m4 |& H; T: ]7 @, ~2 ]) z
}
`% J3 c7 Y- ~& q+ c5 ` //取第一个元素的信息4 V& d) z0 a" y9 f4 B
/*9 p2 f7 `1 x; T) |
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff): _: P; Z& K5 k: h
{$ K+ C9 B" L. b/ d- G
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
1 y: @0 n6 \% B) h4 Y4 H I g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);% ]; ?- I2 |& ?" p7 Y% ^/ V" W
}
" L) u: O9 A& H" \ */: \2 Y( P; M' N) Z( G
//////////////////////////////////////////////////////////////////////////7 V0 G: K1 B4 p" K) G' {' @
break;, N' X9 x& }* g* ~! y0 t8 V9 w
}6 G& y" W+ g8 j
} - I& \" f' I J
}5 z& _$ w, ~8 w7 @1 d. E6 y
m_wndMenu.SetVisible(FALSE);4 c/ M2 v5 \1 ]$ v( K: k
+ y- y, w; h/ z# Z
--------------------------------------------------------------------------------------------------------
- X- \2 D% N& n6 T/ M# d$ h搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
- t1 C6 Y4 f% D6 V6 v6 e{) B- I% q* s! c! E( U6 e& k N
BaseMouseCursor();4 y g( t. g9 m6 v3 {
}; ]. x: r5 i4 \ ]" t5 D
在其下添加:
9 s$ R a( W( b0 H) j7 {void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point) O0 @: D& r0 c( j0 r
{
# l& _3 M& z& p# |/ B% F! b# |% ?m_wndMenu.DeleteAllMenu();
4 A4 ^( ?/ Y/ Lm_wndMenu.CreateMenu(this);
$ { @* y) m* x& a8 lm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
; j6 V" [6 t: i. n0 J+ [5 K: X: T1 l3 w$ ?: t
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
2 G" W; \# D6 O" X; D{2 R0 X( }4 Y0 p( P$ Q% @, q0 R
//P以上级别才可以删除所有道具
4 c- h( L" v& G# r m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");" b T l3 r# E, ^
}6 G; l+ D! Q- @- j e) Y
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
" \# S; A j% w" Um_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );# x; T( R/ m' v# k9 {$ m) y
m_wndMenu.SetFocus();
7 Z8 l. q; w5 d7 u}$ v5 E1 O; G( w* n2 H! j+ Y( `
------------------------------------------------------------------------------------------------------------# I% B; s! V* ?" ?+ K9 a; |
*************************; G/ I/ W: s( ~
WndField.h文件
0 q3 _" P) h3 G( X4 M************************* v% F, e: C3 P6 U+ K, W
搜索:BOOL m_bReport;
5 @$ ^* ^) b+ M7 B j其后添加:7 {9 T! v$ e3 W0 o4 ~2 u6 F. B
CWndMenu m_wndMenu;- D6 b* c5 l/ g# U0 ^% l2 r8 s9 j
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
' B$ o4 ^" `( Z! d其后添加:; y# m* u/ V) H
virtual void OnRButtonUp(UINT nFlags, CPoint point);
. L& n6 P1 ^2 U0 ?" ^: `/ _* ?
& I6 ^# p) J, b+ r4 ~1 l; `8 g
9 f) l+ E/ |0 Z. ^' b |
|