|
源文件中_Interface文件夹下WndField.cpp文件
; a1 N" r* p K6 p" V搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )/ j$ i) G7 i& M5 e* J$ E. J
" ^" G1 [& T5 ?struct sItem
. S8 S: M; O; Q! G5 O{
- B/ Y# z* d/ S0 z. k& O; B/ e# TDWORD dwId;
3 d+ L; V0 n8 fDWORD dwKind2;
7 d; r3 E1 S4 `0 pDWORD dwItemId;- H- ?* n) }& `. l
BYTE nIndex;
/ f0 l7 ^7 h- P" {: x. }% N! B3 k: C9 E/ rsItem(){, w" {: _8 X. C7 q( o
dwId = dwKind2 = dwItemId = nIndex = 0;, U4 o6 }8 W% P
}2 u" {" y/ s- s1 }/ a. G2 r8 l
bool operator < (const sItem p2)
& u: I, g7 |9 c0 \. N{$ z. D+ ^: s4 ?% W- ]! I
if (dwKind2 == p2.dwKind2)
" @6 N' o7 {: [0 c' U: ?) d. \ {
7 l. p, f+ S4 I return dwItemId < p2.dwItemId;# Z$ v8 e! ~- U5 Q g" O
}else{/ y, Y8 n: q0 I
return dwKind2 < p2.dwKind2;# W/ e7 k& s; {2 m
}+ x- S7 g$ \/ G& d5 s
}' k# \: j- Q# D) ~3 d8 Q
};
( z6 X$ l6 l% Q8 Z2 |# w$ gclass CInventorySort2 K2 m2 h6 i/ Z
{
; Z0 H l3 H0 tpublic:0 _4 W2 h8 l7 x
CInventorySort()6 F: { s: B, m4 C m
{3 B; U% l* N! j. Q
m_dwPos = 0;' _- u6 |8 h- [* _
}
' x4 b \0 X) }3 _3 j0 b~CInventorySort(){}
. H- Y# |6 G1 u+ k& w8 l$ tprivate:
$ ]; X, [; C! J. PsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
* J* S9 a+ n( o# KDWORD m_dwPos;
7 C; }1 \2 {4 u; gpublic:
( x1 o7 H8 E; \' n5 `$ w' svoid Add(BYTE nIndex)
! H& _- q% t1 E* K u$ h{
, W6 m5 N; d+ [7 w: m1 K if (m_dwPos >= MAX_INVENTORY)
+ j- G) ]6 A* c/ t b& B3 P {+ a. e6 A. j; |9 R8 k% z7 f/ I
return;
7 i2 @9 V* |2 ~1 r& v9 e) o6 Q1 x }/ r3 q+ t I% x o3 F6 g
m_Item[m_dwPos].nIndex = nIndex;2 p2 c) M4 M& M6 P
m_Item[m_dwPos].dwId = m_dwPos;
8 t' F# d8 J) S' E+ E m_dwPos++;
" O8 _, U. |% Z7 ?+ J8 L* t0 a}
! b1 Y/ ~8 s! `# _/ {3 mBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
* g; f1 [) Z9 m9 F% \2 ]* G, C{( U$ {0 k9 Z @$ u
for (int i=0;i<MAX_INVENTORY;i++)
! O7 R8 {5 ?! h9 A+ }0 W {
% H- \; s6 p) E; m. \2 q _9 b if (m_Item.dwId == dwId)
6 w. M; i. s$ F. \- o4 L {9 ~0 R( a% D0 N F; [: x
return m_Item.nIndex;
) ]& a. C8 F _ }
0 b- o! K! O: A6 q$ R; A }* i9 c- ~% j/ g( ]2 l
return 255;6 x/ p6 w# e! m: l }
}
! k5 r6 M& P' {) m* ]$ X& ovoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
2 ]. t) L9 @6 l1 \. |) X{' V, d" ?, L1 F; X, T
BYTE nTmp = 0;
* S3 W9 z: u) `1 N7 h bool bDest = false,bSrc = false;
' L, R* m7 f G+ [0 N2 h: k V8 ] for (int i=0;i<MAX_INVENTORY;i++)
9 n7 j1 f( _) y& I {
8 R4 X8 o$ R# b9 `5 _ if (dwSrcId == m_Item.dwId)
4 d' L- [) j7 X% m- \0 D {
2 q2 A$ b7 J( Z o# h //id相等 则 改变对应的dest和src2 y# M M5 H! ]' z+ {
nTmp = m_Item.nIndex;
$ h4 E( R* L$ C& Y/ G+ q; T0 R/ [ m_Item.nIndex = dest;! s* T3 I+ P% [! u* U
}
- U ]" y1 _/ C: e" K }
! r' z# n3 ]( C$ T0 Y9 S) V; I //临时数据保存完毕,交换开始& @5 U0 w3 K, Y# A( ~: G5 @
for (int i=0;i<MAX_INVENTORY;i++)+ _! @1 r6 _% |1 e
{ g% _& g$ n( {$ V, G! s0 H
if (dest == m_Item.nIndex)
4 n% c3 C7 g( ]1 ` x1 W T- r2 a) v {
) v! \8 r2 M5 w //id相等 则 改变对应的dest和src! P4 I E7 v; A0 I$ c. j; p2 s% L
m_Item.nIndex = nTmp;/ E# ?& ]& |6 a7 P7 t5 A7 I6 j
}
9 M: x- ~; w0 M* ~" S* D }3 W k: q% K# w. H) M M; t
}4 e0 X, }( ]& a; U @
};0 V) J* h' V8 w% U4 h+ m
-------------------------------------------------------------------------
7 x c6 A: p! q/ s依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )! V: n6 s" h: m0 K$ \8 K
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);. c0 [+ }) r, b4 n) g7 W
紧靠其上添加:/ o U2 r' {: \3 u* z
if( pWndBase == &m_wndMenu )
! K. M+ `3 E, V( h1 v' p{/ ~4 C) m' U+ R" G# P: p- w Z' T/ o
switch( nID )) i# f$ V) R0 l" c9 r9 g
{$ i. g: }# }. p5 K0 ]
case 2:
# h; x$ j2 Q! `, D {6 E/ ], A3 F* T4 k$ ]+ O# X& r( O/ R, @5 h
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
" R1 D) o4 s9 t) h3 p$ ? if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))' p) n0 B5 r0 ], a: J5 w& B9 W
{) Q: @5 J! l& u6 u- ?
break;
0 I: B# X, w! _. o# _9 x }5 @# Q$ Q! e9 g. Q C: W0 P
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)) z( |( p \6 i+ _$ Y4 X0 w
{* H5 ]+ q/ a3 n# q2 J& l; ]
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
; Z5 H/ v) t# @+ t a' P2 W if( !pItemElem )# t! h6 ^+ q! } x# n! ^5 R+ y- [ G/ v
continue;
! j+ x5 }4 Q/ O+ L* a7 Y% E0 k if(pItemElem->GetExtra() > 0)
' K* C u& z( M+ e% E continue;
, }6 m( w7 f, n @ if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
# E( s7 y$ m5 j( P8 n4 U( r" `& Z1 L continue;
6 Z) F" L3 y/ e9 x, w) L if( g_pPlayer->IsUsing( pItemElem ) )& [, A9 Z4 v ]: B- F
continue;* F. }' b9 Y* b+ H
if( pItemElem->IsUndestructable() == TRUE )" v2 O# r( u6 O4 q) |
{
2 h0 X. H* |% z6 h g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );7 l, m& B4 b. w/ @' p% O/ g5 a
continue;
' U9 s. U# p0 a2 c$ N }
# B& h, ]$ S1 F* h g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);: o0 w% O0 b& i) o% U! _+ C
}2 ^$ K5 o3 p% C1 l" ?+ [
break;7 B9 i+ a' a. T$ L# E1 ~2 H# t
}- B/ M" r* D e
case 1:- S+ B- B$ v1 ? T( o; _% ^: Y1 d
{
. s6 _9 z! i* \) _ //整理背包! k* c6 [: T/ ^
//////////////////////////////////////////////////////////////////////////' z+ p& B# U) Q3 P$ n; B
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
) }. a1 a& x! n3 } //////////////////////////////////////////////////////////////////////////
+ [ A) N6 J" G. e* V& _ //////////////////////////////////////////////////////////////////////////5 \" @4 P5 R3 w. F% T
CInventorySort* pInvSort = new CInventorySort; e. w2 i I- E: I! R" ?
vector <sItem> vItem;" O' M, D9 v$ a. l% Q: T, ]$ w
vItem.resize(MAX_INVENTORY);//初始化大小$ r ^) F" i$ G7 P$ F
//////////////////////////////////////////////////////////////////////////
( l: h p: P) k4 ?( i! ? //填充数据* x* k5 p: o2 b, Y2 L2 ~
for (int i=0;i<MAX_INVENTORY;i++)4 Y2 ^1 u) M5 r6 z& b& l
{. r- C* e5 U' q; A5 U
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
! `6 q: t' o* y) F+ \8 i" ~) X2 m9 ~ if (!pItemElem); W$ r* Q* T/ E& v% ^5 G5 d* c( V
{
7 ]( W0 p5 B# o( U vItem.dwKind2 = 0xffffffff;
8 g* g3 o2 c3 y+ `# k3 K9 w( @ vItem.dwItemId = 0xffffffff;9 f' T. d& ]2 d1 e
vItem.nIndex = i;4 X- H3 ]8 ~! J
}else {
/ I# F+ U% U* W5 I: m ItemProp* pProp = pItemElem->GetProp();
) p7 }1 u& ^$ w- S4 p) i; a" N vItem.dwKind2 = pProp->dwItemKind2;' v9 y" f0 |( z; j8 K
vItem.dwItemId = pItemElem->m_dwItemId;
% Q& x, V7 g" H4 v6 r) j vItem.nIndex = i;
p8 |, x4 r8 R- R }, y! `7 ]# W0 x. Z( t$ g
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);4 F4 p8 @9 }! l- P; ?* R
}
: \8 o' K- h& F3 c6 B) ]. H //////////////////////////////////////////////////////////////////////////& G; O+ _5 z* m$ j, n, i
sort(vItem.begin(),vItem.end());//排序" X9 P6 ~4 t$ W6 r. l" U% e
//////////////////////////////////////////////////////////////////////////
" O. a$ V0 _6 w% L0 f6 a( \ //交换
. ]3 \1 @8 o: L1 C* ?* E for (size_t i=0;i<vItem.size();i++)
3 v9 r$ U' _# i+ D% l. Y {
% P5 ]8 H' S% y4 e$ l) ?0 M //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
: d$ t$ S* H2 \) D pInvSort->Add(vItem.nIndex);9 |3 U7 _+ {2 @, a
}
8 w* ?, P7 {. Z: y) c BYTE nDestPos = 0;5 j2 f3 I6 t* h
for (int i=0;i<MAX_INVENTORY;i++)0 S& W9 n: R7 Q# p- u( h
{+ P' a$ m* ?( t& I; K. w
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);9 p. T8 E2 b$ v( ^- c
if (pItemElem)6 |: M$ _# H4 p" x% O: d% C6 q
{
- S; }8 R0 A" b0 k/ n if (IsUsingItem(pItemElem))* r* [. n/ f" D( O# w
{# @4 g& L: C+ s) |- l8 c' @+ c2 K/ y
//这个位置无法放
3 t) E1 U' q7 E$ E0 J8 C nDestPos++;7 u. c8 Z0 p6 J% I% W' E
}
# K- i( f2 |: H( M- d1 _ L" Y }6 T1 `* v# J0 k
BYTE nSrc = pInvSort->GetItemSrc(i);
; f' j0 B# `8 i; }6 n pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);, l0 h2 M) D9 x, J2 m) s( C
if (pItemElem)
& [' ?- H1 G8 L3 a1 } {: l4 ?# t! o) G8 }$ ?$ Y
if (IsUsingItem(pItemElem))1 G* H2 e7 L0 L( P- W, E* X
{
0 \/ T/ n* ?: L$ d: K# E //这个道具无法移动,跳过
; [- I$ l% n/ j ]! H0 n* V continue;
7 Q$ X+ r) C, j; o }: \) S" f+ o6 _- N
}else{; L. Q" Y0 m9 c% H. l6 u: m
//空位置 不用动
R- {9 V: K6 r* }! r6 W continue;& [: t0 R; D4 v- J% |5 l! t
}
* o% y; j" J5 a' T0 `$ f4 M //////////////////////////////////////////////////////////////////////////
1 k2 @' N7 q' v3 ~/ ]; R //开始移动, |9 ^, L5 ]. e& [2 a1 ?
if (nSrc == nDestPos)+ X" Z) k0 c6 T4 ]" o
{; |8 _7 l- Y- u& D
//原地不动
, ?7 q% W% e/ @1 F nDestPos++;
/ N( V& O# c# c: u6 T | continue;" S1 w1 `( ~0 k4 `2 B$ I R
}$ H- l; g2 h6 Q3 s, |! J" t) s
pInvSort->MoveItem(i,nDestPos);* w9 |, S" D3 `# _
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
0 @) _9 ?$ l4 l' E Sleep(5);
. F5 {5 V( {# q7 ]) g, Y+ m) t //Error("移动 - %d->%d",nSrc,nDestPos);4 T: L* S( k' t4 j. {
nDestPos++;5 L' C. G5 f- P @4 P$ J3 A
}
4 y8 U0 O5 j* [4 j2 E //取第一个元素的信息
/ v) s! N$ F) Z- R /*
' f/ ?, A6 g2 l2 N if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)4 V; F' O0 K4 [/ z
{7 J2 P3 | E+ O) \" }4 t
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
2 c. H( p3 `) E- R' [& n g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
J) N! l P8 O }
, I2 w- Q8 f; z0 N& B3 b/ ] */
% E \0 P/ ~" `2 ~ u& [9 i //////////////////////////////////////////////////////////////////////////
" ?# J" y7 T( `3 H; Y% R3 [ break;
( j6 o7 B& t0 h. o2 z- b8 `, K* } }. t) z, I! H* Y* O0 d0 i. F- T
}
! j8 [' ?' s: i; c g* y( C}& K: \; M. T: o o" y. U' t+ A( X
m_wndMenu.SetVisible(FALSE);
9 G: J' k2 t$ N2 r
3 E' F" _ m' |* w--------------------------------------------------------------------------------------------------------3 j: ~7 X7 E: }* Z$ h% m
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point); q4 w& v2 ~6 _3 P- b
{
( [" e: J4 S& K. g# k' gBaseMouseCursor();
& Z. s& _0 K& _0 ~9 D& o}
. Q9 @! z& @: H& k在其下添加:
, h9 U N! f8 }% i: T) [, [$ D% Xvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)5 U" n: W" y l0 r5 ]/ ~
{# A! c) X+ O$ w' U8 m
m_wndMenu.DeleteAllMenu();2 \) X6 y1 e8 E- B* {' u
m_wndMenu.CreateMenu(this); j3 G. k% m8 Z# x
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");1 d+ ~5 n) H, K& E
( n" }6 O/ K8 U
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
9 f* j; D7 ^( N{
9 e" t' G# Y) Z5 H" g; ^' ^5 S. X //P以上级别才可以删除所有道具0 O7 L( w/ |# v) c' d) M$ o' p
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");0 M/ m: j4 O* c9 h* ^: w( M2 W6 a/ R
}
- r* g" g4 [1 n+ o9 fm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
; [0 F" z. _& a% z1 H, ]$ Nm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );1 z. h3 g7 f( q5 @& h. S2 ]
m_wndMenu.SetFocus();
* S7 `2 s, Y) | C: H+ o0 e$ Z}8 n3 U& j* D4 i: f1 [
------------------------------------------------------------------------------------------------------------
9 u/ G6 D$ K1 \$ T+ c8 p*************************
3 `3 g+ o, P& R. _/ cWndField.h文件
: \( ~7 r9 Y$ l! K$ p/ V* U$ T*************************
$ X3 Q- i$ K" g. S5 O6 }1 t搜索:BOOL m_bReport;$ F, U% r5 _$ H+ p- Z/ t
其后添加:5 |3 R7 L# H8 f9 j9 @( C
CWndMenu m_wndMenu;
% I) z; d b3 O& z2 |; K搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
3 x. J+ o- a: X' R其后添加:
7 q+ I" W. W, i' P6 g: Svirtual void OnRButtonUp(UINT nFlags, CPoint point);* b3 i0 w3 S! D7 ^- q- L1 c
+ I: x# ?$ ]. u( h
1 B" V. N* X7 ~7 h+ X) n1 `8 O+ h |
|