|
|
源文件中_Interface文件夹下WndField.cpp文件
+ v* `4 q3 ]7 U8 W* C; R4 C; j搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
4 [- F: c, f1 c! E K3 ?
+ r2 U: b3 l! @/ Q0 N) pstruct sItem
6 `. x1 ?1 {8 _& ]' R{
' m% o# A7 i* @' iDWORD dwId;8 S8 d( Q6 V% i2 w! G. E* ~
DWORD dwKind2;7 v1 _4 W/ Z/ }, P$ t, W, V
DWORD dwItemId;
; @4 X) N H! G. G! H- g, aBYTE nIndex;
- m" S+ y1 k1 G2 z1 ^. BsItem(){7 W3 [$ A" G6 R$ J5 w5 I0 l6 x1 D
dwId = dwKind2 = dwItemId = nIndex = 0;0 |/ T0 J0 E7 C, K, [" ]* W* V+ F
}
2 A$ y9 ]* M# n+ Sbool operator < (const sItem p2)
/ r# S1 b& K: s( S{
0 M2 q7 W( Y6 p if (dwKind2 == p2.dwKind2)
9 o, G) s f6 H, @7 a& N {
6 R8 G- T4 O: Y/ a* f; ^+ E9 ~6 L return dwItemId < p2.dwItemId;
9 D% E. Q: l- \5 Z0 w; d; T }else{$ @- H" K9 j1 X2 Q0 G
return dwKind2 < p2.dwKind2;
2 {4 J+ Y" X6 W9 V! C- O }
3 k7 S: B" y$ T. \: C& V( l}
7 I( V1 t: ?- @0 T( `& _};
) h8 }6 L. t, A9 Dclass CInventorySort
& I! R F' N c+ }) r& ]6 V& X{+ K' h% J& [& P: t- F. V4 S
public:
# O. y9 I- ]7 C+ |* [- KCInventorySort()
* t/ j N' a8 R% ^! `; w# E% M{: t# h3 j9 A# k0 X" m9 M/ {3 K
m_dwPos = 0;. j) H5 T( F6 ^ L- N# e( C
}. h$ o- ]# ^% H& {' j$ E
~CInventorySort(){}% K; Q& Q ^- n, r; C
private:6 \% H$ P9 z- X' r$ ` Q
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
" R2 F# Z `1 } G5 P. q$ T" h" e1 R& QDWORD m_dwPos;
( w3 N) q8 ^5 l$ o3 xpublic:( o0 I0 P0 ^6 x' M9 Y, ~
void Add(BYTE nIndex)
; F$ L& l f( Y{( i. x. L0 V& Z" k3 F2 v) p
if (m_dwPos >= MAX_INVENTORY)* P3 n- g7 h8 Z0 [ n1 ^( n
{ p0 @& [9 E8 h: o/ A$ I8 T3 i
return;
! L8 @2 N, f% @2 v h; ~/ L }
% Q. C: u) ^9 U" [3 s m_Item[m_dwPos].nIndex = nIndex;6 J/ I. W! [( W7 _/ s
m_Item[m_dwPos].dwId = m_dwPos;
3 j% d8 r! b% ^6 m) Y m_dwPos++;
% }! u' A' g' e. ]7 O' s' L u}/ h) e. {+ H" q+ C$ ]3 B
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列$ B: T$ ~) i2 I1 U
{
& ?2 M ?3 D! {8 a: `- Z1 P for (int i=0;i<MAX_INVENTORY;i++)
, P. b4 Z* F o2 q& \ {0 B' b; D G( I/ a. H; l" Z: i
if (m_Item.dwId == dwId)
% X; Y2 n- f# |1 x* f b {1 R; S" w0 [$ t# P1 e1 O$ Z) o
return m_Item.nIndex;6 M" J4 D% u; T9 X# `
}6 }) X' B- c6 ~) ?
}5 {; @9 R7 v- ]1 K7 ?5 E
return 255;
5 d+ P7 E- x" y T2 j' \2 @/ m( ^}
; u, C* L4 {; |( i# k; p) u$ Avoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
. [! w3 s3 K" u% |4 j' C; ~0 e{
4 y2 w% b2 l- _- c* J( H1 {4 ^# a BYTE nTmp = 0;$ h4 b1 f9 \7 q7 L5 S5 K5 M& X
bool bDest = false,bSrc = false;# C. y; L+ ]: e
for (int i=0;i<MAX_INVENTORY;i++)" P/ B, F! C4 v. c3 Z3 j7 J0 v# @
{
( A. P; B$ F3 i* G& g, \9 O if (dwSrcId == m_Item.dwId)7 y: ?- u) g O/ k5 Q. Z
{' Y6 ~0 Z. u) G0 n+ R% |
//id相等 则 改变对应的dest和src* A4 R O1 N* P6 s
nTmp = m_Item.nIndex;! c# Y1 y$ s" g, M2 Q }; l
m_Item.nIndex = dest;
9 p% f& G0 S4 w5 j- s }
b" m$ D7 _ R) f }/ i J# v* ]8 a* \
//临时数据保存完毕,交换开始
4 U, x2 f) o' U x4 }7 E for (int i=0;i<MAX_INVENTORY;i++)8 M1 Z; U' p" \$ H: h" }
{) |8 C( T) ]# e2 s4 D( D9 o- D
if (dest == m_Item.nIndex)1 X! R% X4 ]- S4 n/ J
{& _ y( b0 t' w6 o2 K ]. ~, x
//id相等 则 改变对应的dest和src5 p8 x) C8 `' l8 r
m_Item.nIndex = nTmp;- W9 [8 L. n' s5 {
}: E! B& F; L* [3 c- \
}
) [! p& J- ]9 E* H& y8 v* d}
9 r: V& Z' E# L$ U$ `9 K8 C) _};& n9 o" ^" V- g4 C. i9 W! U- o' j
-------------------------------------------------------------------------
+ b* R" N8 T0 v) c8 t X依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
' ^3 |' R; m( r" y* \搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
1 z5 e8 y$ }1 X紧靠其上添加:/ @* F1 N" P5 U/ m6 M7 g4 Z4 i
if( pWndBase == &m_wndMenu )0 d P9 B% m! R- q" t6 w" M
{: W- J+ i, ]/ F8 U( H- Q
switch( nID )' m& Q6 l! A/ ~& h( y$ T" f
{" d1 M; H. C, O3 {
case 2:' n. o: ~+ D3 F3 h# l
{: M9 X) J0 T7 n+ M/ M, v3 s! U
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
0 Y7 |' s# U4 L1 { H if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))( W2 b+ S/ [- R6 A0 K6 W3 G& ^! g
{
" G! f3 x# e' M# Z# v break;5 S+ y. e9 Z+ X" Q, c
}
7 f7 U3 p4 {( v for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
6 X; n' O: G( k$ ~" @8 b. H {
3 G$ Z0 d* M E. Y/ \% o( L: g CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);; m/ R$ d& b. n7 E# P
if( !pItemElem )
+ T( D6 m* E: e continue;" V9 X& Q- r' a- Z& L# ~* ~9 ~& m
if(pItemElem->GetExtra() > 0)8 a+ s9 `4 _% p6 g- |
continue;# o U9 i2 }* A! [9 G
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
+ d$ L) M% a" x" x, m' _) d continue;3 t- ^+ B& Z3 H9 x: a0 @8 ?, {/ x
if( g_pPlayer->IsUsing( pItemElem ) )
( c% G+ _! n1 H. h) k continue;3 \; }" X- S! W
if( pItemElem->IsUndestructable() == TRUE )
# g' M, M d1 ~) Z {4 ^3 {! _ E4 G
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) ); a% f3 \# t ?5 }0 c
continue;
, }+ K4 G6 D% ]- v8 j+ F0 j }
5 E6 I- f4 Y& W9 a) @ g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
, I# X `+ H/ q3 ~1 {/ Q }, m& @' H# f, t$ W8 Y |& E6 t
break; h2 y1 m' J7 B
}% E4 Q2 ?7 k! } A
case 1:
8 |, `: t4 A& K0 {% x! p+ X {
1 a6 D9 ]7 O& _2 K$ h; k9 I //整理背包
. O+ D8 A2 O5 _0 }5 q) z1 q //////////////////////////////////////////////////////////////////////////2 Y; Q6 x. z# O6 n" w( B6 C
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );8 G( Q! {+ m! g& p; S$ ?
//////////////////////////////////////////////////////////////////////////
7 n+ M$ f+ q4 R# X$ s //////////////////////////////////////////////////////////////////////////
) ?3 i: f& P! a. `: R2 H CInventorySort* pInvSort = new CInventorySort;
# z( \5 |0 F1 q& Z& X+ a vector <sItem> vItem;) h( r9 E# h0 n% S; u7 R
vItem.resize(MAX_INVENTORY);//初始化大小
; z2 h8 E( Q- |. k: V) n4 ~ //////////////////////////////////////////////////////////////////////////
+ x. _( v, C/ G. V //填充数据$ Z; w1 f5 D, S# z% E
for (int i=0;i<MAX_INVENTORY;i++)
& I, ~* f7 }* N$ k8 Q {! |# S0 s+ Q! w
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
! X! H% ]' a4 F9 N8 D if (!pItemElem)
) i* y* ^1 i8 Z9 }# L( J% D {
1 C/ ?$ W2 M. I2 Z8 } ~ vItem.dwKind2 = 0xffffffff;( ]1 i- k3 n* K" n) }3 m/ z- G9 V1 g- ~
vItem.dwItemId = 0xffffffff;. G: ^8 f* t+ H" x9 n
vItem.nIndex = i;
}+ E# ]2 Q/ ] }else {- Z, \* Z5 {( t, N# s
ItemProp* pProp = pItemElem->GetProp();; {6 l+ {0 ~0 I" }" W
vItem.dwKind2 = pProp->dwItemKind2;
, p9 W% ^, K( \4 U' e& p1 |" | vItem.dwItemId = pItemElem->m_dwItemId;
/ Y# L1 \0 Z0 E3 V vItem.nIndex = i;. c8 E9 `; _" t, x3 P
}6 j; J$ ~# @( K4 m( ~
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);: m3 w' C2 D3 c2 C
}
! W7 ?/ M5 t7 F7 l //////////////////////////////////////////////////////////////////////////3 T' s+ _ W! s$ E; h4 `
sort(vItem.begin(),vItem.end());//排序
+ R, ^# ^) `0 ?8 I5 ^# T //////////////////////////////////////////////////////////////////////////+ T" a3 D# K3 {
//交换/ ?% Q7 p0 \* c. a# b4 s
for (size_t i=0;i<vItem.size();i++)" L) F6 S+ l5 E+ ^3 P
{+ A, O& K7 { u% v9 o" X
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
, n9 h2 Q. B4 c0 U$ n* u/ y/ O pInvSort->Add(vItem.nIndex);! K& o- u* i* w3 u/ f6 ~
}
; x) Y3 q0 y# N1 q y/ O. A BYTE nDestPos = 0;
2 ~6 F8 d R1 A! l: G for (int i=0;i<MAX_INVENTORY;i++)! E3 W" Y1 }! S
{! q- Z) y, F% J* d9 \) F; |
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
9 M% I4 w+ b) B0 B6 H* Q if (pItemElem)) U. }( h' E- b) {$ j8 w5 I& Y/ }% ^
{2 ]5 |5 P- D( N8 p8 T/ ^" V! v: Z8 y
if (IsUsingItem(pItemElem))
" _ N8 d- Q1 X- I {9 S# o! P* _' V2 ]+ F$ I& `
//这个位置无法放
. c8 t- b1 a6 O6 g/ f3 x1 P nDestPos++;
$ Y5 L* } H6 ]: ~& y }
% Z# c" L; @$ F }) I( ~8 |8 v1 }+ g
BYTE nSrc = pInvSort->GetItemSrc(i);# w( c S) Y: _" V1 ~
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);% c6 N4 L( v; [
if (pItemElem)
( a; t3 K, [# Z( u/ _! M0 g {
3 _7 |. V& ]/ Z! h$ j1 O j if (IsUsingItem(pItemElem))
: S0 N0 C' h7 o" {! w {* H# A0 u8 w" y) `$ g; }, Z
//这个道具无法移动,跳过" Y# D/ e- N9 G. B( }. e
continue;
3 j( x6 l( y$ X' [" b' o) G }
0 `. w0 W6 `+ } }/ k }else{
+ m: r8 t: I3 @. z. J* J //空位置 不用动" [/ `2 ^+ R1 G6 G. p: l
continue;
$ p1 o' v# Q; G( ^4 V# B$ C }" H8 j9 d% ]' t/ c
//////////////////////////////////////////////////////////////////////////
# V- I& a) k! j! M8 J* p) E' A& B //开始移动
, ?4 \- l' h8 G' z5 t if (nSrc == nDestPos)
& J; T! q9 C) O0 S! _2 j% P {
& Z/ E( s1 i7 Q1 Y ~, X //原地不动
+ Z8 J) h) S8 p nDestPos++;$ S3 \ g( l. E! Q, v$ s( |* r
continue;+ l7 H! E* a( u& \7 H. R& l4 u
}
c' u# ?* _3 b pInvSort->MoveItem(i,nDestPos);. f1 I3 z2 r- a( W8 E- o, o
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
7 i% O: X/ W; u' k Sleep(5);5 ^% E, O7 q/ L4 x
//Error("移动 - %d->%d",nSrc,nDestPos);
+ L( @$ ?' j7 L( M! T nDestPos++;
: `4 p; [/ o- f, @; q }# ^+ I+ S& W5 M& d% O% e- ~- x) p8 V
//取第一个元素的信息
0 ?% ~) J" g. M' X8 U2 t3 I8 y7 ] /*
$ C8 l! }. y8 G5 j! @ if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)9 ]1 F. \2 ~# O8 g& I2 W/ c
{/ k/ C1 i. J* b9 r0 I' |6 @
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
( Q& V# k6 U; ~9 P8 U0 { g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
. @ s! f4 J6 t" ?; r( @( p7 G3 T }* y- l, {9 A. m# w& t( \& ^, c, |
*/3 @ {' f% K; y- X% o
//////////////////////////////////////////////////////////////////////////& E' A; S n: @1 Z1 o
break;0 x+ N8 c5 W; ?( V
}
7 e- l% d p) r( R- D+ c g } ! ?4 H+ x! k. _6 ]
}
( T" L1 l4 H8 c( i3 v g1 ?m_wndMenu.SetVisible(FALSE);# f- m* X# G& j' `$ o5 V# Z
* x: ]; H, Q9 B% T1 m: e q--------------------------------------------------------------------------------------------------------
$ r* n! S. ]) E, r$ a ~8 V, o+ \( y搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
) ^. t8 R( t% {; u0 W{
' V3 ]% Q$ h M/ k- l I8 pBaseMouseCursor();
1 Q" p. O3 {4 d. j7 B}
6 P0 B( K# S+ p; P$ j) x! @. q在其下添加:
1 `1 B$ |- ~7 xvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)' H! ~5 s: C( d3 Y. \" R2 ~/ j. Y
{. d. ]) d# _. T4 _
m_wndMenu.DeleteAllMenu();
" s K+ s! C$ @: I+ i$ F8 M+ Om_wndMenu.CreateMenu(this);
. C: r5 m& }$ ?$ Q) V! Qm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");2 @, P# P: h0 j- Q; k7 B( y+ j) }
% _& Q; J; d$ l, E2 v, g& j, ?% z; nif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))" i; }8 w" s& n0 ?
{
; S+ f/ T3 ^5 O$ r7 b1 |1 Z //P以上级别才可以删除所有道具
5 ] f- q+ G7 o0 N" J: B m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
+ D. ~5 b7 E1 z o7 ]9 r}" R/ N% v# T8 j4 \0 M0 o; y9 Y$ q
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );: g, G4 f n! W0 E3 T
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );9 L* B% b8 |7 ^# `
m_wndMenu.SetFocus();
T& Q6 M+ _: E}( e0 @/ `" [# D* G2 h6 t
------------------------------------------------------------------------------------------------------------
2 @5 J1 [9 g! i1 z*************************
- z; Z; E, G3 FWndField.h文件7 T* P* y' k1 X( s
************************** g9 C3 Z7 E$ o, C3 @3 b! W3 u
搜索:BOOL m_bReport;7 N* Z1 v" H" ~$ R+ ?
其后添加:
G- `# V8 F3 L O6 RCWndMenu m_wndMenu;8 O- p( t2 l) N9 j3 a, Y( \
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);! ?+ ?4 z1 a7 [& @- Y7 C. l' D9 _) J* k
其后添加:
+ D" Z' V% C" X& l. I; z E; l$ yvirtual void OnRButtonUp(UINT nFlags, CPoint point);$ _) I3 m+ b8 [, ^6 z1 O: b
' F# x8 c" W4 O2 I
( ]2 j0 u' ?. } M3 i |
|