|
|
源文件中_Interface文件夹下WndField.cpp文件
3 f, J- G3 R. h搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
0 @6 [: d# {; ?! F7 \4 i4 n) J$ s2 g; Q3 i W5 F
struct sItem, s2 v+ X6 I4 E' w8 T
{1 j; z; j: y, Z5 h& ^( i7 U& C R5 h4 Y
DWORD dwId;
4 }3 F2 v ]8 uDWORD dwKind2;
! B$ j% `( p& Y0 Z4 ADWORD dwItemId;9 j: ]2 m% I# r- T/ ?- S. n
BYTE nIndex;/ b1 t- ^0 F n
sItem(){5 f( M; X8 Y% y. [3 }
dwId = dwKind2 = dwItemId = nIndex = 0;
5 q1 C! R8 ?) U3 o7 C2 {( K3 N}
; V _# }6 W5 G) Y, S( Ybool operator < (const sItem p2)
* I7 l- V8 d0 R1 h0 p5 p2 L9 N{
% B% w" \! ^ R% e if (dwKind2 == p2.dwKind2)
4 g" g4 w' I; s {
- B( O! y l- c return dwItemId < p2.dwItemId;
$ [7 m: S# O# M6 J }else{) B+ `" `! Y. J) E, S2 i8 h9 G
return dwKind2 < p2.dwKind2;* |" H* G% q: s3 l" q
}+ p2 Q! B' w% t
}
) V9 U% @. ~% C6 B, ?' ?};! E+ y& @, N" O% D. l
class CInventorySort2 G8 n) S% y; K. b6 @, d' t, T7 Y
{
( p! s+ X4 R0 G' J# dpublic: E& ?' O/ Z9 j- M7 L9 o
CInventorySort()- Q- ?- Y8 o$ x
{- |+ B8 O' [3 _. ]# N
m_dwPos = 0;
+ I ~- F% |3 k9 D}
; q& M4 ^1 o6 k~CInventorySort(){}
( N6 G, }1 H O5 Lprivate:
6 r+ l' T- c. d2 o; ?sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
# ]) Q/ Y# h& e: VDWORD m_dwPos;
~7 t! ]2 \0 _3 ]public:3 r F$ f% H, f% I
void Add(BYTE nIndex)
q2 O% o+ A' p( S' {+ h) @( [; H! D{2 O7 q8 O& `) g9 R/ D5 p$ E! N
if (m_dwPos >= MAX_INVENTORY)7 Y0 A$ e, O4 Z" D& R. i- i" y
{
* x; n/ W* T; e7 P2 u6 ]. v0 Z return;6 S9 B/ ~- U0 }/ t6 j1 L9 t3 T
}3 R4 g' t! W7 `% j4 H' }- F* m7 b& e
m_Item[m_dwPos].nIndex = nIndex;
: _" D, J0 d w; F4 h m_Item[m_dwPos].dwId = m_dwPos;
4 x4 d) w1 r! a2 f8 R0 D m_dwPos++;0 j! V8 ?4 h R0 [8 }( ^
}, O7 B1 J! N, [8 i$ @
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
$ A. i3 J! K7 R A1 m1 V{
( s- R3 {+ N I* j. W for (int i=0;i<MAX_INVENTORY;i++)
, T9 S) b; L" H8 h {3 m/ }0 C, z/ O0 b. J x% B9 e9 P/ O
if (m_Item.dwId == dwId)4 H/ J A* Z _- t
{
* J6 u0 n! ^/ t- U" {" k* {5 d return m_Item.nIndex;
^& }& ]+ O4 z }2 r! e8 b+ F7 d! D$ {( q' `; o
}
4 F+ m _6 |* P return 255;
: ]7 D9 m% D% R- p( J}7 z. P. |2 y1 m3 R. c
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
& A8 K: @$ m$ ^) D" ]' N% a! m{
+ n3 X0 |% }; h3 [7 p" P& ~ BYTE nTmp = 0;/ i4 u# _4 D; c/ M2 H7 w! y) C
bool bDest = false,bSrc = false;
G0 @& w3 e+ n/ H0 u for (int i=0;i<MAX_INVENTORY;i++)( ^6 c- n( g: e9 m0 R
{
3 p4 y/ n9 r3 e$ s z; ] if (dwSrcId == m_Item.dwId) T+ y# ~7 O5 ?1 _
{3 A' q9 [' p0 k' z5 L
//id相等 则 改变对应的dest和src
% l/ A8 j) e L nTmp = m_Item.nIndex;
l& A( h/ Z) H m_Item.nIndex = dest;
, l: ^5 \# N- I) N; A: H }
' x7 g! V. s/ W [' e }
& u* A( m0 R; s+ f2 Y! T //临时数据保存完毕,交换开始# D; J, A0 t8 a; ^; r+ W( }' D" X
for (int i=0;i<MAX_INVENTORY;i++)! p" x0 \. s6 |# u" _( b7 J
{% r: i- F0 v8 M& ?8 @6 v o
if (dest == m_Item.nIndex)/ D# G0 h3 n& @& ]7 Z7 r. F% s
{5 D6 B& T3 s# S! G
//id相等 则 改变对应的dest和src
8 Q& {. ~! K7 u8 V$ V m_Item.nIndex = nTmp;, T8 N( @$ W! ~2 I) a
}
( B2 s( ?0 [/ g }0 H' F' f& s7 Q9 H8 c& b) G
}
% Z7 m2 O3 K3 P; X% ?- h};
8 Q7 u* n2 H' |( d- a e/ X: d7 v-------------------------------------------------------------------------
7 v: Y* r4 o# Y+ O8 L依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
7 ~1 n2 t$ F4 k, Q7 v: o搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);/ T& w2 z# Q! t5 y1 v
紧靠其上添加:
& Q% o: |0 F* o- R, @% G+ Fif( pWndBase == &m_wndMenu )
. X- R+ \& h' H{
; N/ _( y6 x2 K+ s" U+ w switch( nID )5 l8 u* e1 ^, n
{3 w$ j5 a( C3 g
case 2:
- q N8 H: \+ L# Q' O5 {8 a5 R3 t {6 D# U* e- s& `7 P' Q
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
( j% e1 T8 q# ~' p+ t6 z: A if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
+ y! w. }4 L5 d( O7 B {9 d" T+ K; U' h
break;
0 E4 ^2 P) c7 E8 y }
' W5 u* a- X) D( N! [) ~ for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
) j9 g4 G0 I" x$ m {% F7 F. G) f" N$ j1 t p3 I, `
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
6 E( |, h% l. c9 H& z# U if( !pItemElem )8 X+ e6 O, y6 q" w( m; a
continue;
' n @0 o$ q8 R5 S if(pItemElem->GetExtra() > 0)0 o( q* @$ e7 _" x" S
continue;
% z3 @+ }! J" l& ?" k if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) % v) ^; n7 ^& p. w& o9 w* [5 I
continue;
& r3 U) k# \% ]+ ~. _& D# g9 f if( g_pPlayer->IsUsing( pItemElem ) )* D) v/ k A- W9 D# R+ }
continue;! o/ f4 z' H A+ U
if( pItemElem->IsUndestructable() == TRUE )
. K; l' L- k2 P: Q( f {) G, h8 n7 X& c2 z) ^8 h5 M5 D
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
, j s; g* U+ e- ~ continue;; |! {+ `1 K# s7 X: q0 n! G/ ^
}* \& f- S0 I" e8 J5 S
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
' T9 j. f# g! R4 | }0 P4 U! W3 R% v$ ^
break;
8 Z9 W4 e/ d3 a* j& `5 h }0 q( G6 M) X( a* _0 j+ K
case 1:
2 T- ?$ K: E" s F2 i% T$ r2 P. _ {
0 T& T9 S( n$ B* e/ I t) R //整理背包$ V' d- T# E: x4 i( F
//////////////////////////////////////////////////////////////////////////
! B# j0 D o3 ? //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
/ \# V, d3 M+ G: H //////////////////////////////////////////////////////////////////////////
8 y6 @9 D4 Y; `: A4 C: [$ F //////////////////////////////////////////////////////////////////////////- I' S8 C% [ @* x0 v
CInventorySort* pInvSort = new CInventorySort;
' F: t+ z7 F( H' d. Y6 e h$ W vector <sItem> vItem;0 L. n" [7 U j# X" G) h [
vItem.resize(MAX_INVENTORY);//初始化大小% L: J$ z3 T: E+ C
//////////////////////////////////////////////////////////////////////////$ k W/ y* N0 Y, T% p4 v
//填充数据
F. ~- n2 o' h* V* c0 [ for (int i=0;i<MAX_INVENTORY;i++)
0 V; v9 F5 @% N+ E% H8 }- n {7 P) m# D' O$ P8 ~6 S
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);# p, z X/ k( o/ r3 b9 n4 M3 F
if (!pItemElem)
) y; P, F6 h7 F) ?) K7 r. R {0 S; C- w* |! \: D% l& R
vItem.dwKind2 = 0xffffffff;
9 ^. r8 }- ~, x3 ?9 V o vItem.dwItemId = 0xffffffff;0 v/ X! P8 y4 e$ T# o6 t
vItem.nIndex = i;, l( d, b; M( ?% E: C* c
}else {/ R, ?: i" b" d O+ w8 y) z
ItemProp* pProp = pItemElem->GetProp();% p; ], N- M3 i
vItem.dwKind2 = pProp->dwItemKind2;; N: t! }7 m; l2 e% l
vItem.dwItemId = pItemElem->m_dwItemId;
- w. X0 q( r' Y* O% V, W1 B vItem.nIndex = i;
+ ^; x! |9 s% f; _ }/ W; O* I9 |! R! n( {' A
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
3 d. z8 f' G! t7 {0 l) B6 _1 X( O1 Q }+ F3 X& l9 M# |5 I* d3 s
//////////////////////////////////////////////////////////////////////////
1 U6 W' s# c5 ~ N: | O K sort(vItem.begin(),vItem.end());//排序' ]' X3 \& ^6 p8 [7 N' l
//////////////////////////////////////////////////////////////////////////$ z. J# ~( a; y% q
//交换" R5 Q0 V3 u6 m; @
for (size_t i=0;i<vItem.size();i++)$ n S2 N1 V/ l' E L3 R4 c1 `
{3 ^6 Q) n a5 `; H& \$ m6 Q
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
0 J# ]' L" b8 [9 g: L9 r pInvSort->Add(vItem.nIndex);
% B* j9 d* r; [: O }. P" o6 s" {, E) {+ Z/ A% s! _+ ]5 v
BYTE nDestPos = 0;
- J6 A6 p# E0 Z, Z* e" n for (int i=0;i<MAX_INVENTORY;i++)+ E0 o2 d# h: G9 O7 w: j$ W
{
7 {7 R" r2 i% K CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);6 Q8 G. a' b# `, E1 J: t' O
if (pItemElem)( v- Y4 A) p. I* e: }1 g
{
* {* d3 c# n/ \, b$ ?* W if (IsUsingItem(pItemElem))% X' _! l \8 t$ Q M- S: A' }
{" c9 ]3 R+ l0 ^) G2 q
//这个位置无法放9 G% \5 F* W# ]# v& w# p) n
nDestPos++;, ]8 `+ ?! w: l, D: |: O
}
' C9 O& p$ e, K a8 n, v& W1 s }
# T) M4 J, D* w- v5 G, Y) R4 j% { BYTE nSrc = pInvSort->GetItemSrc(i);7 j" x8 v/ T% D* z
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);0 ~" O! b" I5 W9 E# z7 H {
if (pItemElem)
5 o$ e0 _( w/ Q- x1 u# D {4 K J" H! C0 o0 L
if (IsUsingItem(pItemElem))8 a- n; r ~8 E9 w
{
& y, u' y- y* ~' I) j9 F; J3 K, W //这个道具无法移动,跳过
( c6 o2 e, E0 a8 O% o) G continue;
% U/ w2 h. {5 D8 `2 t }
3 \/ Z. o8 K6 b: k7 Z9 r& c% g }else{- K: j g- }! l: t N) }
//空位置 不用动$ z% c: I# O1 S
continue;
2 C) D( r, O/ v$ g% S }% U7 C, k' r4 R( g
//////////////////////////////////////////////////////////////////////////" ]% X/ d+ O. x4 l9 s
//开始移动
3 i7 g# J: D( X' b( l9 }' Z/ E if (nSrc == nDestPos)
9 ?& j* }- _" Q) y6 b7 g {
6 F+ C3 A! i0 l //原地不动3 Y% ?) x. n9 S- Z
nDestPos++;; H" K6 @+ f1 n. O* V2 _- `
continue;
% F6 ]; ?$ ?" z- W2 x$ Z }
8 L( A; d# s+ O) F+ ]+ | pInvSort->MoveItem(i,nDestPos);* D+ W; ]0 R f9 @ M
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
. q5 b b6 q9 Z K Sleep(5);& ` ^# ^1 D) X. ?! k
//Error("移动 - %d->%d",nSrc,nDestPos);
9 } X5 W5 K: f P8 Y7 ]* f nDestPos++;2 X2 V# q- q) ~) z! w
}3 F# x1 O! X, p( N
//取第一个元素的信息
& e e' K2 n/ Z- J$ Q /*: e+ w% M) C9 c; s% e
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)4 E& ~" ^1 Y& B+ B
{& h$ a+ e) e* {2 ~/ f0 d+ T
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
, t( ?3 ~% m! S A% f6 H g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);; c" S% C9 k2 Z* }* `, d
}* _ u7 m j. ]
*/
( O& [ u6 I( J) y" j7 W6 ` //////////////////////////////////////////////////////////////////////////
* E1 ]. ?$ D3 P8 D2 N% q2 d break;
# l' M& }5 _) v* P! z }
2 w6 a0 ~* K- w3 F% W% T4 a6 m; {" ] } ; O9 Y' Z) ~8 O4 g
}, S2 B3 n! T/ j% A9 F+ v9 q6 V# q
m_wndMenu.SetVisible(FALSE);+ B2 ?( o. I% F9 \) t; ]! @
/ Q5 V! S3 M p0 w, K8 L" L! Z
--------------------------------------------------------------------------------------------------------; Q9 ]; |' N, M0 P6 w1 ^
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
6 v' c2 N5 {0 O. Z; p! }{
6 ` W3 c" c5 n$ _9 dBaseMouseCursor();
' Y8 {. L) Q8 L- C0 }}
. y8 @! q/ N; p在其下添加: v& i) X& W8 \
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
& @4 P5 P% e* G" W2 D; ~5 P( d. U: f{+ l' W; F1 y! i- o- P
m_wndMenu.DeleteAllMenu();; R/ S5 e, @$ z! ^: M
m_wndMenu.CreateMenu(this);& a8 ?% h! ]( v% D2 \: `
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");! D) W; M) Y! K5 h9 t# V; @) c
1 U2 S! T$ @7 H( x8 a. aif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))5 g' x. W: {' I6 K5 H- G4 b
{
8 H- B+ v( P1 | //P以上级别才可以删除所有道具
) ?! D' h( M7 L5 q2 i: ` m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");+ ]8 J8 Y& m" o! n8 w: h
}% k! D4 I" V) }5 g5 m; {7 {" D% C1 X
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );9 I+ q6 n7 X. M, Y
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );1 W* z# A3 J* y, }' W4 C# U( s- i8 }
m_wndMenu.SetFocus();& X: _: B! E$ |0 l9 s( J3 Y; S5 i( a, L
}
0 s1 s+ B) N, C5 h' `' f7 a" ~------------------------------------------------------------------------------------------------------------
# o# C# X8 D, S4 H6 t( _! v' M*************************, A1 |/ Y1 n% o g. ^/ b
WndField.h文件
7 T4 ~( B3 k! X7 Y*************************9 f* h. ?/ c0 R2 F6 _ R3 W
搜索:BOOL m_bReport;) I4 l! q5 v" ^5 [% A" t
其后添加:8 z3 Q% F7 U2 e5 l1 e. b1 s& F0 T M
CWndMenu m_wndMenu;
3 I4 r$ m' U2 F0 F; J6 P I搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
3 V( E+ c3 X3 y j其后添加:
& j9 x5 l5 A; O8 ?& Qvirtual void OnRButtonUp(UINT nFlags, CPoint point);1 M# q$ O9 ^( m/ d5 d, c+ z
! T" r J( G) M1 V' b9 X( E9 `& _, p4 i% _1 d: ~
|
|