|
|
源文件中_Interface文件夹下WndField.cpp文件
8 o h4 g' P5 Y. m搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
4 W& ]; F. s4 z% n0 R0 Q$ P" [4 X u. j: ^
struct sItem
. E7 U+ W1 t4 H3 l: ^6 R# S3 [ S+ {{
2 _) R! [( H9 T" v$ tDWORD dwId;, J' J/ v2 }9 M% H
DWORD dwKind2;
1 c6 @3 x! q+ A5 Y# M, _DWORD dwItemId;( w* U: p5 k0 C \
BYTE nIndex;. j4 d# t# c1 K F
sItem(){1 @# V! c) |3 u! l& X
dwId = dwKind2 = dwItemId = nIndex = 0;( S8 D; m" q( @
}
& K- E+ F% r) l4 e7 nbool operator < (const sItem p2), N+ ~- P& m1 ~; U( b5 p7 y
{
' g$ B2 N0 ^: O if (dwKind2 == p2.dwKind2)* G2 n* U4 y7 q
{
* E/ @+ A* I5 C7 Y# ^9 v! D, c return dwItemId < p2.dwItemId;; Y* K) H! M) ]7 A& i2 |/ r
}else{1 N5 N5 q) L9 x3 J
return dwKind2 < p2.dwKind2;
6 J1 M: g ^ J) D; Q/ [! F }
: S% \. V7 b2 I* T: M}
0 e1 j) @* @; Q( E};. s, P$ D- L/ v$ m1 x' f+ d
class CInventorySort! d; f: \1 Q! {5 a9 A
{
# O1 ~$ P% r: [! r8 |% Vpublic:6 J6 f5 v- h- H, g3 v4 ^
CInventorySort()1 Q+ z1 u6 B; `% Q w
{
: g5 ]" |/ D. |5 d; A8 f9 t- H m_dwPos = 0;% \' s2 H- f0 L% \3 K2 m& S
}4 p# B$ d" w0 A% d! ]
~CInventorySort(){}
1 ?8 L; f5 u2 w8 t; w) tprivate:
9 D7 S$ a' j, ? u |sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
% D% Y5 @: `: c4 q! LDWORD m_dwPos;
1 V/ D4 W+ B( R& ~% Spublic:
2 D# T! S3 E `0 {+ Jvoid Add(BYTE nIndex). T7 ?% A" g5 Q3 u0 x- y
{5 l% F, D7 {; E+ x% M1 J+ ~
if (m_dwPos >= MAX_INVENTORY)! J: I( K. s- K' V5 o1 c& U ]# _, ~+ m
{6 y1 @% D( H: t; k- x% ^6 ~, [: R d
return;3 h7 R& ]4 C5 V* x1 ~0 P6 P+ i
}
) z/ F; p k7 d& c+ Z) M5 f1 x m_Item[m_dwPos].nIndex = nIndex;
& M( N4 C/ m+ Y# ] m_Item[m_dwPos].dwId = m_dwPos;
2 }% O8 n1 t% |' n* a m_dwPos++;6 \! I1 ^, p: G" T" u4 U M: ^
}
; ?4 i: \1 q- S* ZBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列9 J: }7 ~" J* Q
{
0 V+ Y3 D7 K) Y n$ S5 l1 R$ L for (int i=0;i<MAX_INVENTORY;i++)
* v! _2 }3 w( k$ q {" |. ~5 b. y7 X; k6 n# n$ n
if (m_Item.dwId == dwId)
b$ {% F$ V" f$ R4 `4 r- q { | C6 i2 [# h6 P1 |
return m_Item.nIndex;
/ x" n# H) D( G% ]' w5 C$ ~ }& C2 H/ J7 k$ b$ c4 H( u
}' Q/ Q+ y& `* M8 e m @
return 255;# t% P# ^* w/ r0 B, u) `
}
- W0 S, q9 ~& M5 y7 o/ f7 Ovoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置1 v, i- F2 z+ y9 `$ f6 ?" { c
{, o# z5 W/ O1 f! ?( J
BYTE nTmp = 0;
) J+ s0 {$ F4 ]# O/ z2 U; r bool bDest = false,bSrc = false;
+ @+ i3 `4 ]- V7 M for (int i=0;i<MAX_INVENTORY;i++)# ]3 K/ T! ] x4 n" j, b
{3 q$ [3 G+ x V0 Q8 ~3 ]
if (dwSrcId == m_Item.dwId)
2 f z! t" o2 O9 b {
* o! ]5 N5 V+ W8 J9 Y //id相等 则 改变对应的dest和src3 A% R& ?0 G& L0 a: _# C
nTmp = m_Item.nIndex;
) P4 M$ w8 t0 b+ `2 q' j m_Item.nIndex = dest;
+ ?4 X/ G6 g# @, @6 r" W }
5 v& @* c& C g0 w) b: }% f" k }
4 C5 E! C/ P. N) L //临时数据保存完毕,交换开始. h% }; Q+ e1 N4 W
for (int i=0;i<MAX_INVENTORY;i++)/ T+ V- ?' f5 L: h/ Y" d
{3 D! Y9 A C# q+ v+ Q
if (dest == m_Item.nIndex)* C& h. f( K/ w s
{) \% D) e' L M4 A: a* P- ?" i
//id相等 则 改变对应的dest和src
7 k# e) ^1 g: \6 u m_Item.nIndex = nTmp; o$ _/ A9 i; \ ]8 `: P
}
, o* g& ]+ H, F# D0 k }
( T) K5 @' v2 v, ~3 I& w}
! N" ?! ^) X* Y};7 s ^* }1 R; d1 } u
-------------------------------------------------------------------------
# P( L/ W W$ }# S; l7 g依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
/ T" s0 I- Y& ? C搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);' a8 R }1 ]$ a" h4 `
紧靠其上添加:
# v* c _5 ~& q$ | K$ `if( pWndBase == &m_wndMenu )
8 [# v* Z3 R/ Q5 O( R' L0 q3 |6 g- C{
3 y: J; g5 E) d; L; F% a switch( nID )* c# {$ {7 @/ r/ ~
{
/ X7 y9 F) L0 `. L3 i8 M f5 j case 2:
5 D3 @% V/ P9 o+ ?# Z {
3 G% S8 [, O' U7 h. W //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);5 Z1 R! w" s2 B) q+ F d1 u2 g6 O
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))* \' M' k% i1 {1 b
{! F, \/ N9 q1 V. G; k4 D
break;
* ~8 A1 g2 N' M4 B2 w: y5 \0 ? }; W" X7 U) i4 Y/ r0 S" U. J& a
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)1 ~3 E/ K' @: j' ^
{1 u8 k- g6 V X2 o5 u" }/ M
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
3 N) D K; x* x' _4 f: M2 F+ s6 k# m& Y) d1 X if( !pItemElem )
+ N$ G! ]8 S9 ^, B$ x& z6 s continue;/ ~& ?4 g8 F0 f
if(pItemElem->GetExtra() > 0)
. I( }" L! i* ` continue;
9 n: ]+ Z5 M9 l' x1 p2 W if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
: a A, f5 u* }$ m& \5 U' A continue;
# V1 r! V) ^# f9 ^ {. B if( g_pPlayer->IsUsing( pItemElem ) )* j5 G2 R$ c" V+ A, `: L1 u
continue;
/ t# M' l! j, R, u+ w, H8 V if( pItemElem->IsUndestructable() == TRUE )
{! C2 Q. t6 S {
) s: Z5 s7 d) { g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );) Y9 Q# O4 y$ K
continue;6 A3 b' r, a6 q: @+ ^4 L) r ], j4 _
}
. E+ G& N7 h3 }, o/ Q g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
6 M0 t6 s6 X/ E- N }
9 @& _# i# v: ]1 ~# R/ m break;% b4 P$ D. L. s1 u0 B
}# @( }4 ^; x! _; g0 @7 v
case 1:
- G5 C) Q! d4 a3 ~1 s9 {" l {
3 [. i* z$ s; H. R D9 o6 [2 F //整理背包3 Y& Z, a: d3 ^0 v5 t, d! y
//////////////////////////////////////////////////////////////////////////. Q0 G; V9 v7 d) \6 }8 _' u
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
. s5 E' J3 K" l+ D6 g0 ^4 g //////////////////////////////////////////////////////////////////////////& z) m. p, t1 e/ k2 V
//////////////////////////////////////////////////////////////////////////
# j; j5 J3 `5 k5 R0 \' j; n4 |$ v CInventorySort* pInvSort = new CInventorySort;* N' p7 n) \( X- h; j7 J
vector <sItem> vItem;$ T+ {: O h( p! P _7 x+ B: b
vItem.resize(MAX_INVENTORY);//初始化大小0 H0 {6 X: ] C8 E1 d! j
//////////////////////////////////////////////////////////////////////////8 \1 m7 p+ Y( O
//填充数据
+ O; Y$ A4 u; _& D- ~7 V: R for (int i=0;i<MAX_INVENTORY;i++)! v5 |5 u N6 Z% W2 t7 y
{9 G2 J( n9 Z8 o9 G4 I. z4 N
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);6 V: B& O$ ~0 @' R5 B
if (!pItemElem)
) b" M9 M$ B; ]% S6 ? {" s4 W! N' T& V5 b, ]& c
vItem.dwKind2 = 0xffffffff;
6 H0 _. c9 G( J vItem.dwItemId = 0xffffffff;/ s% k( E! J+ W0 M1 T, Y$ O5 f" @
vItem.nIndex = i;
( x5 A2 _3 v+ ?# D( s; h }else {* Q x& I/ g( q' q- B; a! g
ItemProp* pProp = pItemElem->GetProp();# t* W0 l# l8 Q0 V
vItem.dwKind2 = pProp->dwItemKind2;# m9 Q8 X* _0 L1 `( J0 [
vItem.dwItemId = pItemElem->m_dwItemId;" H" x$ H1 `- h1 h2 X! [7 D
vItem.nIndex = i;
, g6 `6 o* [6 I2 C$ F1 S1 _ }
/ \0 I; h- e4 S d6 x //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);# f" V/ b6 p$ l9 a% X/ b7 X
}8 k& h4 Z0 Y% t- Q+ L
//////////////////////////////////////////////////////////////////////////6 H7 [' l3 C6 @" m! Y
sort(vItem.begin(),vItem.end());//排序* o4 m. V6 @* R. z4 |) q4 S0 _
//////////////////////////////////////////////////////////////////////////7 a4 N) A H; l4 U! p
//交换3 o3 ?& ^) V# L' Y# C
for (size_t i=0;i<vItem.size();i++)
" J+ p) a1 L. h* [- n( J+ r h {$ q" p5 P( J5 a" K; f" Q
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
; c* C% J+ i3 ]4 G3 a) u4 _ pInvSort->Add(vItem.nIndex);
$ ^! k$ K2 t! y8 I }0 M6 s6 f. A; y: X( N+ [
BYTE nDestPos = 0;
1 t6 Y( V* ] a4 u2 |6 ]( v% c. }0 r7 j+ J for (int i=0;i<MAX_INVENTORY;i++)
% |, q" R2 ^) ?+ z3 c {
4 @5 E: `/ i4 }# H- t, Y CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
- p% P9 s2 U5 N, a. |9 X if (pItemElem)
5 M9 e. h! x* x* `# D0 T. o {
3 ? N1 M# a& I if (IsUsingItem(pItemElem))
+ h h# D' P9 s8 o4 ` {
0 h6 n( M+ @; e0 D1 s //这个位置无法放
% Q3 O9 M4 }0 u nDestPos++;
* l% W) k4 a% D& E2 X }$ F# |& _1 W8 D! H$ j
}4 \6 A6 E+ O( a! l
BYTE nSrc = pInvSort->GetItemSrc(i);
) _3 j, H: ~' X* l8 @, b pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);. g2 [7 N2 A) X8 ]
if (pItemElem)
; d1 W5 T0 H- E, p% h9 i( l {
# B3 t2 e q: B O1 l# ~ if (IsUsingItem(pItemElem))
5 k. v; @9 J3 i4 p {+ P3 T' g& R/ m' b; ~& Z% R: l
//这个道具无法移动,跳过
( _5 _, b5 D2 X; ` continue;, M0 T& \6 w6 H) W
}/ ]/ A! J0 O: Q: w) p/ ?- ^9 i
}else{+ n. B: g M- P% b V
//空位置 不用动2 L8 @: Q& p6 T% _1 z* v/ E- z
continue;. O2 B8 D6 H) F' Z! i
}
3 R/ _% ~+ v A G6 _ G- B1 i( Q1 B* H //////////////////////////////////////////////////////////////////////////3 \+ K; O' h4 o- b F$ w6 z
//开始移动9 m8 l5 j0 W8 k7 `
if (nSrc == nDestPos)
; G- H4 H0 ], r: v; ` {
7 T# Y$ W m5 m //原地不动
( e7 @/ E8 o6 r5 p nDestPos++;
# T1 E4 B( i6 p. Z continue;" }" t: o- H; Y# ?
}
! [8 R0 E* T1 Z% W7 B' ]5 Y pInvSort->MoveItem(i,nDestPos);4 t: s( a. [- ]
g_DPlay.SendMoveItem(0,nSrc,nDestPos);! c3 z, n! }; }- J' \
Sleep(5);) _" R: R' G5 F8 @% u8 b
//Error("移动 - %d->%d",nSrc,nDestPos);
+ i z8 B! }6 [* s+ X$ e; V+ p nDestPos++;
; k4 D m* }/ G* q" \ }
- ?& q: ` X) r* ?" h! h: ] //取第一个元素的信息" j& T' r$ b8 |: L- w+ q3 T
/*
4 l) G4 \/ m) S0 I+ q/ e if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
6 l! L5 U0 Y' f0 e6 B, b# e8 ]) H% D* O {
) S6 J8 V2 T8 }; U2 @ Error("Move - From:%d,To:%d",vItem[0].nIndex,x);' G+ Y7 T1 Y6 J
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);" d# E# M( w# ~" N
}
5 L; ]4 t- e$ ?- P. ~ */( Y J6 `2 D6 [. J+ e* B
//////////////////////////////////////////////////////////////////////////
0 f5 D0 I& A* k- Y ^1 d break;
+ @0 N! d8 i' Q3 F+ D. Z+ m5 E- `( @ }
* r* z0 C6 \5 S' U. ` } 8 @$ V4 h6 _: ` f
}! A# [1 M4 d7 [ v2 S2 C
m_wndMenu.SetVisible(FALSE);7 e; v* o6 F) k% D; {% L$ ]$ [
% R% C. @) P" [1 G--------------------------------------------------------------------------------------------------------) |& T; ]/ I, D( l# _
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)4 y: C2 w# x& }9 d+ d/ g; [
{$ ]' [! S2 i7 _( F; H* g) h& m) e8 n
BaseMouseCursor();) P( A* ~; }& ~( f
}
: c4 s7 {5 t( ~, h# E2 E$ {7 r& q在其下添加:- E0 d+ ^' P! y9 a
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)( Q p6 m4 G& V& S
{% X2 h- {7 k* j4 r9 _( M
m_wndMenu.DeleteAllMenu();( L/ l. T2 G! ~1 E
m_wndMenu.CreateMenu(this);8 p4 \9 J( ?& r. `/ h
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
' O1 D! X5 q% b2 s6 w
) f ?' G5 H1 h8 w7 }3 Wif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))1 h6 }# I! H- O2 e
{( z9 C, {! N9 \3 m' h6 [
//P以上级别才可以删除所有道具2 C& A; C* p0 _' \2 U# |
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");: m$ a( q, J/ [* a( l9 [
}
1 N: G1 I; E% O6 j9 D Km_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
, u0 w: |# W. Mm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
9 h8 N% C; P# e7 e+ c1 Gm_wndMenu.SetFocus(); W% L0 `- q" q4 t' y
}
* S( n5 P4 R2 ~! H8 {( }3 d------------------------------------------------------------------------------------------------------------
1 T$ T, p, V2 t4 T/ A0 G& A*************************( f7 J5 n7 e. d& M
WndField.h文件$ p+ ]7 Z6 r Q1 f
*************************! c$ m% m; c% C% P S; _
搜索:BOOL m_bReport;. }9 r7 B5 e2 [, U0 l( w
其后添加: }2 m1 ^/ ], i0 X4 y
CWndMenu m_wndMenu;+ [1 ?: ]/ g8 Y) ^' Z
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point); M: j/ n+ m! h$ J% Y+ C
其后添加:# L& s) S# Q' |9 j* M: P
virtual void OnRButtonUp(UINT nFlags, CPoint point);
2 w* O+ X( c* y+ ` K- A: P
% s5 J' j) [: j) i9 b1 C4 k4 L7 i, h
|
|