|
|
源文件中_Interface文件夹下WndField.cpp文件
" G$ p: i$ q8 p5 Y! `( i" J7 s0 A搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )8 v5 @( e1 s7 z7 H& s! B
" }) N! Q5 f3 l$ a+ B$ lstruct sItem
3 y* g2 v. z0 T3 g* V{
8 H( r$ p' w Y) h& Z1 XDWORD dwId;
2 Q6 L' D9 L0 A' e1 h% oDWORD dwKind2;
b9 W3 Z2 d# T$ c$ cDWORD dwItemId;
6 A8 T# d, x2 z: {2 ~BYTE nIndex;. m4 W( h2 [% S, I& m
sItem(){ n! U. ?; [& C+ N
dwId = dwKind2 = dwItemId = nIndex = 0;0 U7 O5 j2 `" B3 H4 M9 q0 g+ U1 N
}9 N, E8 E8 R \3 d" U" Z3 n& Q
bool operator < (const sItem p2)4 R1 h# y0 x: D" @
{ L! d* ^( Y9 L$ Q5 Z% N
if (dwKind2 == p2.dwKind2)
5 C6 ]3 H$ }/ l' a2 [8 {7 D {
* ~, Z$ V& c T3 ]% Z return dwItemId < p2.dwItemId;
7 I: k$ Y9 v2 w0 _! _) @ }else{' }! d0 v ?" O/ _1 Z6 l
return dwKind2 < p2.dwKind2;2 n! Z. q. s; r. Z8 x% v' g; i: E) C
}
7 f4 N, W R. s}
* B) o; t. {0 n! y( T};2 Y$ {7 J. p; x' C
class CInventorySort7 e- K$ a! D+ Y- w( ^' t
{
- y4 L0 D; U5 z0 cpublic:# x4 C' S# r% a v" P
CInventorySort()$ v3 R: L6 i4 B
{6 p) Y/ B% {- ]
m_dwPos = 0;
0 z2 e: M5 D; `9 `2 \4 y}
0 |2 a. C0 z5 Y~CInventorySort(){}# k9 O1 v- y! C
private:9 p6 }- G( n, ?( X& ^; Z
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
- O6 X7 |; T6 s( aDWORD m_dwPos;6 A. h; u5 _" H9 {+ I
public: t. e, `- |+ I( p0 \. c4 g
void Add(BYTE nIndex)2 y! L) M' u& A, k
{
0 \' O& S: p" w4 f if (m_dwPos >= MAX_INVENTORY)
0 h% }! s1 t& Z* E/ G* T% P. g {9 a" K" ?7 O' s) E8 t# w
return;
# z' h4 w% }, @ }
: y) @# F8 l: _% e- Q m_Item[m_dwPos].nIndex = nIndex;2 }5 M& Z5 k9 p8 ^5 c
m_Item[m_dwPos].dwId = m_dwPos;* `3 r6 `! _( @0 Y7 y7 l; q8 R
m_dwPos++;0 N/ ~- t. X3 a- R$ E, r1 v/ N
}
, Q4 |, T4 g' wBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列3 @: l' a5 P/ A1 p
{
6 _ j* a' ^' G- u- x for (int i=0;i<MAX_INVENTORY;i++)6 s+ P% s6 @) p/ ^) K
{8 \# N$ w* a: j; Y
if (m_Item.dwId == dwId)
0 J7 V. p; t- G4 L- F+ d" |& S1 ? {: i, v5 p! A6 U7 c
return m_Item.nIndex;/ |7 _) }# g1 s$ y3 s0 U# O
}8 W, Q" Q' G- D9 B/ L- c8 Z
}( t* N8 R9 m1 @0 G5 r+ M
return 255;0 e, e0 g+ u" K. j4 a7 h, G
}+ F. m. D) M' c# X# p k
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
! a) g5 z d, x{
: z9 |8 x0 n1 Y. R, ^ BYTE nTmp = 0;
: D F/ _2 g; v: z9 b+ d bool bDest = false,bSrc = false;
( o! |4 X2 @% w2 l3 K! Z1 y for (int i=0;i<MAX_INVENTORY;i++)
0 Q; d y8 D. S) w" p& F7 O; B {% j$ C- ?. \, _
if (dwSrcId == m_Item.dwId)) l T% j. w; y7 t( \
{% D: W/ K/ `9 L- F/ a
//id相等 则 改变对应的dest和src
: w1 B! L- _" W7 `6 M nTmp = m_Item.nIndex;; a+ Q: n; M& g* | p
m_Item.nIndex = dest;
& N+ m6 O/ |; ?+ @2 m }
2 D9 G U/ _: g! r, ~ }0 `# ^9 d, A* B6 b9 o7 p* Y
//临时数据保存完毕,交换开始
! N. U! l3 @1 m# m for (int i=0;i<MAX_INVENTORY;i++) M! M2 S+ Z2 C7 I) ^
{
W% P# A, E3 l5 P4 j1 ` if (dest == m_Item.nIndex)
. s9 C0 V" m' w7 x6 }" g {
3 t# d' _. {9 t5 k7 B //id相等 则 改变对应的dest和src6 I8 w4 F. d% |# G3 c
m_Item.nIndex = nTmp;
/ {- f3 f, |5 Q }
# m1 a$ Y4 Z' c# Y* ?; A }
& t4 x- K( r1 i( x}( M: e, ~) _: b
};
: q/ M* o8 n, s' b8 C; I1 T-------------------------------------------------------------------------7 B/ x7 i4 s+ Z- B" `, R, i. |
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
- q4 h' v# h) V7 n& X搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);. Y5 I J3 \# r5 i. I( Y6 k
紧靠其上添加:% p' T, u5 o$ c3 z. M
if( pWndBase == &m_wndMenu )7 U. C3 t- F ^5 f' }: ^8 w7 ^ D# i* v
{
! _7 x* r$ o; F& h* n# g8 | switch( nID )
1 t: F8 J4 I0 Y {. V% G, J8 M, S! U8 x, z: t
case 2:+ q' q# O6 H" m
{! E) p, ^' J2 X+ f( I
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
8 t& N$ q7 Q( s! Q% F if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
/ D+ S1 `0 v) T5 L {0 ]: P) I; h. e2 @7 E Z* Z
break;
0 R, ^4 f8 ?2 F! ^. R) ?# _0 I9 u }- O, c- q) ^( |6 ^& o; b
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
A" y t3 w* T) [ {; G' m" J! S% l. _; O# V+ c
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);9 G4 Y) T+ K, ?6 u9 k$ _# G& k
if( !pItemElem )
f$ m1 u7 W% Q, O2 l* p continue;
8 {( |" i1 U- I/ [& n: R' q5 B) E if(pItemElem->GetExtra() > 0)0 C+ L: B6 @: y
continue;6 ~2 K/ g) a; h
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 0 S0 Q4 g: `% U/ f, l. l. m
continue;
& G3 u7 A1 c/ ]0 D6 i& p if( g_pPlayer->IsUsing( pItemElem ) )
1 c: H3 r' L2 j: Z$ [ continue;
8 F7 b2 Y3 H% w4 g if( pItemElem->IsUndestructable() == TRUE )
$ S, j* u2 B( i% @3 P/ U {3 E; \' g9 K, U- d
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );! {" K! u+ P9 n( D5 G1 ~3 h
continue;
( A5 j" H& d( ]7 z6 W }
; r5 D9 X$ k2 g+ c& k5 c- F g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);7 A4 n" m [6 c! J( F/ C1 `7 e
}
; z. q% c( P4 W1 `5 ~+ ~ break; T; }/ v% `! Z7 g/ _# p$ n+ U
}( ~8 T7 H$ n( Z6 h0 n
case 1:
7 X2 b" i: B4 s4 q+ ^ {
6 v& v' Y K( _0 C/ n //整理背包9 |3 U7 t) j, \
//////////////////////////////////////////////////////////////////////////
8 I: w) _' h( l/ S9 c! d$ |; | //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );/ N$ L8 h* L0 u* M$ h4 H2 \. ~
//////////////////////////////////////////////////////////////////////////
9 N5 r( b1 W) d, Z1 c$ ?# ?/ K //////////////////////////////////////////////////////////////////////////
$ x$ e9 \7 _* b9 k# I CInventorySort* pInvSort = new CInventorySort;# \1 A, K; k0 s7 X5 m
vector <sItem> vItem;" }" Y& `# r) [5 a' E: y8 I. j
vItem.resize(MAX_INVENTORY);//初始化大小
7 J* I' H. e) A$ [0 p6 S //////////////////////////////////////////////////////////////////////////' E9 y( O# _& V6 g6 O: B
//填充数据
% Q0 C7 B; J7 K" k. O for (int i=0;i<MAX_INVENTORY;i++)
- s$ T+ L# S7 |1 K" r: W {- I0 q1 b# w8 ~6 Y& r
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
4 v: R, c# B g2 T if (!pItemElem)
7 w& s6 @4 \; o9 | k {
+ ]0 i( z& F( s8 f* \: E! i vItem.dwKind2 = 0xffffffff;
& b. K) ^' w9 q; J' A- X0 w6 J+ B vItem.dwItemId = 0xffffffff;
% E3 V5 h* k! ~( H* ] vItem.nIndex = i;2 n! j! b. h7 ]3 q
}else {
6 S2 F( T- m' ? ItemProp* pProp = pItemElem->GetProp();
+ I- F( L% @+ b* }$ C# \ vItem.dwKind2 = pProp->dwItemKind2;
( Z4 j) y2 g2 E( ^5 F7 @ vItem.dwItemId = pItemElem->m_dwItemId;1 M4 e% b9 ]9 C% J, Y
vItem.nIndex = i;
) o7 Q9 G! `$ ~1 {! E$ P0 S1 z }
6 U0 l. T D, ~. H+ ? //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);( p" P3 M* \. y! L# ^
}0 A5 S6 Z# a0 Y! I
//////////////////////////////////////////////////////////////////////////
/ T5 [- [6 Q8 I" z sort(vItem.begin(),vItem.end());//排序& {1 K3 r }* x% K0 e
//////////////////////////////////////////////////////////////////////////
1 ]( G) {9 {+ O+ F" T# g //交换
" J& x$ ~) f! }5 z for (size_t i=0;i<vItem.size();i++)
9 ]9 @6 a7 ^% E. k8 X6 Q! a0 C3 K {
" {* K" n% P: q d+ n) \# k5 a0 b //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
. U, Z& ^; b# r pInvSort->Add(vItem.nIndex);* l2 q Q* m" w& @0 n/ d, a( L
}2 p! f" \1 X0 g0 u) b+ S
BYTE nDestPos = 0;
6 J: S: {% u: M. ?+ t for (int i=0;i<MAX_INVENTORY;i++)
; H. s& J: i! W6 o# Y1 x {
) F; w9 Z$ [6 I. ~* E CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
X/ S7 T1 i* M3 @3 d if (pItemElem)
/ i; ^$ H/ m" A! U% N) l {9 `: g3 h- u; k. H
if (IsUsingItem(pItemElem))
* `# e( j: r" P+ U8 Q" {9 @0 _ {" x3 \2 w+ Q1 r7 M7 L/ \. D
//这个位置无法放
M+ d% v; b( j5 M nDestPos++;
1 N' X/ y5 l. ~+ ~, d }
8 f8 Z* r f) E R3 z3 c/ O }
; h2 y9 m: X( C2 C0 @- ^1 |& p/ ~: e BYTE nSrc = pInvSort->GetItemSrc(i);/ z7 e7 E, G) Z* I) P1 U
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
( \% E& B: ?3 _0 n# l" C2 y7 p9 Q if (pItemElem)
. C9 B3 D& e$ v8 {8 P9 E3 m {
. J9 T, `; C, h: ^* s0 P if (IsUsingItem(pItemElem))" G# S( h5 o' i, ?4 @
{9 z# w4 u5 U3 r$ J0 U9 k4 P* j2 }
//这个道具无法移动,跳过
8 F5 Q, ]8 t0 b7 I5 @/ E, g continue;2 j2 \8 f6 G' _6 ^* F6 T( w
}
) _) Y' J) z: j2 V }else{
9 h: m% q7 h1 q# J) Z( X8 u' z7 g //空位置 不用动
$ z: q+ C3 r( X8 f4 Y0 |6 e9 Y continue;
( r* G0 F2 |8 v8 q+ P }# E/ _5 R9 h$ ?7 T7 y
//////////////////////////////////////////////////////////////////////////" L) M8 @6 C5 m, e+ ]+ V% S
//开始移动/ r7 t. z, j4 D" a. L' D- Q
if (nSrc == nDestPos)) k9 T* q" P) g7 w) e6 g J- ^
{
, z' g+ t9 u! T( ]- z8 o8 _ //原地不动; v/ k; `3 M! W
nDestPos++;4 c) j. s( H% k# H5 J0 m
continue;
9 w/ }2 Y7 q9 l# }# _$ [# q \' r }. y t# \& t, H1 O+ `7 ?/ O
pInvSort->MoveItem(i,nDestPos);; F! V, j1 A7 j- T# b
g_DPlay.SendMoveItem(0,nSrc,nDestPos); b8 G. I$ Z' T4 o/ D H8 y
Sleep(5);
8 w: f& O2 v( _( P+ n) f9 P //Error("移动 - %d->%d",nSrc,nDestPos);) v/ d- [" [ \( ^$ b1 ~: X
nDestPos++;
/ @) m( J# m+ E; o }
3 I1 i% I* F( G6 @3 e0 _8 H //取第一个元素的信息- {/ G; U7 n+ g: O( \5 K* h! u
/*
& Q, S: {) \: f& p) d, Z if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)( _9 Z6 R$ l3 \
{" h1 ~, V' ^* P8 @ } x
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);2 c0 I+ v2 d' \4 }( c' k
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);' W. D) _" E. I# U, }# ~5 W8 P$ }
}4 }4 p E5 ^5 @0 A- S
*/
+ s9 R1 S1 F: C$ `! Q8 ] //////////////////////////////////////////////////////////////////////////7 a5 q3 P& K' ]! l3 h; d$ P
break;
9 j$ |. j- P9 s }" V u2 K" L/ P4 U+ o* |# x
} 9 Z+ B ]( M6 g
}) C& B. V1 l) G. g# l' F6 j7 q3 z
m_wndMenu.SetVisible(FALSE);& [: H `( P) X$ i" r, \' L: d% C4 f- w, }
& d1 m) A# @8 ] Y
--------------------------------------------------------------------------------------------------------
. X7 Z. f, Z2 u; D* H( Q搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
9 I' v; I$ |; y- s- B6 X* g{1 X# }; \) f4 o0 _
BaseMouseCursor();
. C l b# r+ @! E( K* r}8 |2 B. \3 t" _& h8 d& q
在其下添加:6 |: }$ L* m& F
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
6 e2 F: v- ?3 b& L( F; G7 \{
: \, l* l9 D4 p. y, B! b; Im_wndMenu.DeleteAllMenu();: w; F" _/ b$ \3 {& Q8 `( t" O
m_wndMenu.CreateMenu(this);# ^' C) ~1 L8 O+ n
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");* o' `7 b* g/ `, w6 ?7 T9 m
( b6 f: W' b$ J& tif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
+ x5 [( ?8 i+ H3 Y% u{
2 I \- f# W x2 j+ ?4 R5 V. c //P以上级别才可以删除所有道具
/ T. b+ a. b1 X( Y m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");) r: s5 K' E' e& p' k* v) O
}' b7 G# t/ D' p; E# c% f
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
0 A# B S) i$ A, D# x$ |# Om_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );$ O# w, ?, _$ h1 u) n8 \
m_wndMenu.SetFocus();$ B" S. Y" n: a# R
}
* Z& E j+ G: b! E3 W------------------------------------------------------------------------------------------------------------# s, P0 z1 z0 |8 Z4 F3 A9 u- P2 h
*************************
) w! h" Z, ~. M* cWndField.h文件# N! k! \0 S" X. T. i1 F, a
*************************9 ?7 i2 E& ^3 V. c I
搜索:BOOL m_bReport;
/ R/ I+ r2 A" X6 X# t其后添加:
9 I+ L& K- I6 C9 B* c- I) YCWndMenu m_wndMenu;8 a/ Q5 Y6 k+ A9 ^
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
# y$ Q, t |5 n! g其后添加:* f# |" L( c) L( i9 R4 [
virtual void OnRButtonUp(UINT nFlags, CPoint point);. z# m3 |/ `, _% y9 r8 U
5 C( R/ Z5 j" T% E. G/ ^4 L
8 m( L. t* t8 ]" Y4 I5 @, X6 }2 g |
|