|
|
源文件中_Interface文件夹下WndField.cpp文件
4 B. g5 t. J/ g搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )! r4 ]5 E; h3 b
) W) ~( ~8 |6 v( p9 O
struct sItem
5 M6 |4 N8 \1 K: i W{' P8 v; u) T" z7 U, V% v1 `
DWORD dwId;
: W) r( j$ N, m. P) gDWORD dwKind2;
/ s2 t4 Y* p$ eDWORD dwItemId;
, E# n1 N5 ^ ~, H3 g0 T eBYTE nIndex;
, @. i2 a" A2 nsItem(){" U i6 Q+ M: Q: F. s
dwId = dwKind2 = dwItemId = nIndex = 0;9 L }3 |: S# l5 I) R" }
}
* @! f& @2 m# z2 _9 Ibool operator < (const sItem p2)
0 z( p0 z# [. d! {$ \+ S A{& Q* \! j, m7 O! _# n, Y; q
if (dwKind2 == p2.dwKind2)3 r' T6 E. G# K$ D
{3 _# |7 P4 G) S( g! @, v: n% \ H
return dwItemId < p2.dwItemId;! N5 v" k% A: M' ~
}else{/ l, `2 {! F3 g% Y K2 A
return dwKind2 < p2.dwKind2; u& J" V$ h* ?) [$ J/ G
}
" L, m$ p, I! `+ x1 L# N}
2 M+ r+ n' g/ @+ i7 M1 `. p) [};
; Y( v9 _" Z, g7 Vclass CInventorySort
# [- d2 _2 f0 H- ]* h{
/ N) M, h; x3 _! V! ]% Apublic:0 F; K" o6 R# o% ?
CInventorySort()
7 r' F4 y7 p0 H{
4 L1 r# h5 c3 j! ~7 | m_dwPos = 0;* f1 U d+ B. @+ A+ B
}: v* K9 _* x3 w& r* e
~CInventorySort(){}
& e! z3 z/ b% i/ P7 Q! E7 C/ wprivate:* N2 ?1 R4 H: W+ H! x `
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
. G/ W& T8 W: O! @DWORD m_dwPos;
9 b- z% q- P8 c/ D8 npublic:
6 Z; P3 A4 V$ T$ ~void Add(BYTE nIndex)- Q7 }* ]- P+ ^) v% c
{
5 c6 K+ ] Z" ^" b+ d/ j% { if (m_dwPos >= MAX_INVENTORY)
; ^% r6 f- c0 T# n) w/ v {9 F e3 l7 n" u: \$ s2 w" I2 G
return;
2 F$ h' R. h: e- X0 s6 D, }) L } D N G0 n5 x8 @' P# ?" l7 ?. r
m_Item[m_dwPos].nIndex = nIndex;9 m4 }% `$ T4 I8 ^
m_Item[m_dwPos].dwId = m_dwPos;
# o, F& c- k5 t ^ m_dwPos++;
0 s8 r0 f. F2 O' b0 ?& N}
% d3 e% m: k& y$ V9 NBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
7 `- y. r% U, e# N) V5 _3 F* r& a{: `: d* V" ?- R5 r, i. F* c5 S
for (int i=0;i<MAX_INVENTORY;i++)4 y0 Q: R6 e6 b" X: T! ?; S! I
{+ ]# `- G1 t8 B
if (m_Item.dwId == dwId)+ r% i* Y% V; U, a5 v* p
{" l: G' B6 H. C1 Z. r& V$ n$ Q8 {
return m_Item.nIndex;
5 o" p: b' P) j. q- T' R( \ }
. x4 [2 G* e( I; V2 e( I& c/ M }
. ~" c# i# Q* x! _* j2 t return 255;
$ q! i# @5 W: B}
* H. j; _) w. t7 F1 B# ?3 qvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置/ l: I9 @9 P, M- W( d3 A
{
. X: |! E0 ~" S$ J t# ~# [ BYTE nTmp = 0;
/ d+ Q {* \8 Q8 P" ` b9 K bool bDest = false,bSrc = false;
9 ^: M- A* p% q2 u4 f: h for (int i=0;i<MAX_INVENTORY;i++)
4 C( |( }; d8 a( } {' t( a# x( @6 j7 \+ R: k" [
if (dwSrcId == m_Item.dwId)
9 _+ E d2 p y6 o {
/ ^/ ]9 m( c; ^+ {) d //id相等 则 改变对应的dest和src
0 A- c+ `) m6 T1 ^ nTmp = m_Item.nIndex;
/ g1 J) ^ c1 U# X& a m_Item.nIndex = dest; A# w/ i* p6 \! C! w" `: E
}7 v. _( ?8 G& M
}/ u3 q7 H8 I, u: ]0 |3 ]& o
//临时数据保存完毕,交换开始
; \) U" ^2 D. @2 v+ A: g: s- {9 ]8 ] for (int i=0;i<MAX_INVENTORY;i++)
. B7 \- h& Y% \( {9 G {) u- i# L' \/ r; m% N9 a
if (dest == m_Item.nIndex)/ d& T% `: p J* \3 g m# P
{
/ Y" k+ \3 ^3 K& M/ }7 r$ y: Q //id相等 则 改变对应的dest和src
& g* a* S9 ~ W F, D5 N, I1 Z m_Item.nIndex = nTmp;
" u' ]' G' e t3 | }7 n/ g% Q. z0 a! ^7 K) I9 H; @
}
8 U" b$ n& n7 V9 C}
' b) Y) V. \ z) X/ x& g9 M. D' @};9 ?+ C' d+ O, O. P [6 p
-------------------------------------------------------------------------
& B; X9 g5 a+ [5 R/ I* e依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ). L( t* R6 v( v) `9 J
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);6 |1 b6 H! x( U+ G) `+ a
紧靠其上添加:
3 y2 r3 M: B* i7 lif( pWndBase == &m_wndMenu )9 o1 O2 N7 }8 W: W2 v4 T
{
7 O E- a @/ o* R8 G switch( nID )$ g9 V5 t' W' K" H! A
{
- N, y X2 ~& c: m4 o# D case 2:
& w! C U$ p5 {/ Y* {+ G {6 v9 v6 l$ S+ p* o
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
0 g4 y( O5 w1 n* P% I; D if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))5 z' c& F( C* p& Z4 j
{
( L" m J4 s' I3 g6 X' q break;
( r+ T; U4 x0 [" D5 y# V2 A; | }, ?# O9 y- b% y# o
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)& S8 I( b; t( B$ F# y
{4 P. o# D6 }/ C6 K: T7 v
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
& ?! V+ w6 ^+ f# {" b$ p if( !pItemElem ) Z" b1 f. z; h7 S
continue;
8 ?9 K& G' a& B0 \" E; z, c if(pItemElem->GetExtra() > 0)
& f& h) S$ Q) Y c: p continue;/ N/ {. [/ t) w! N
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
% z) b1 m- G' }) }7 J continue;
$ _# k: ?' B) @ if( g_pPlayer->IsUsing( pItemElem ) ); G. o! i/ Z5 a8 g) ^
continue;6 j S7 j" R' p" D P
if( pItemElem->IsUndestructable() == TRUE )" W2 A- z9 S5 F& |* E" ^
{
1 U7 }1 Y) p8 n g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );# ]- P# l+ ?. b$ O$ d
continue;, Z5 I7 u/ G+ m: f
}) z' ]# \& `! n+ | V* J& w) Q
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
) k5 a8 z: y+ N8 x. _' D }
; I7 {# y. Z7 t- _, d8 |+ q/ \2 P: y' D break;
{8 t. w# Q; q: p) s# E5 N }
' M5 f' f7 \: B! _/ S& d K% [% w case 1:/ ?& O, `1 |; K: q- b1 z8 B2 W
{2 E: p* e% y3 O" W' G
//整理背包9 g" F' O! ?+ m. f& T
//////////////////////////////////////////////////////////////////////////
7 Y5 [' K" p# w$ C. `( X; t //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
( [9 }2 G3 Z0 S2 }/ J r$ P$ m9 W /////////////////////////////////////////////////////////////////////////// m5 P0 j; O# s; F% E
//////////////////////////////////////////////////////////////////////////
5 a$ f- {2 i7 ` CInventorySort* pInvSort = new CInventorySort;) }. z# V& W1 Q' @
vector <sItem> vItem;' W- N) v9 }( B) o
vItem.resize(MAX_INVENTORY);//初始化大小$ L( s) l5 p7 U5 O D2 R
//////////////////////////////////////////////////////////////////////////
% o. h. W3 z' @6 ^# I, q3 C( x //填充数据
4 s' ?) R `( A8 [; L* w for (int i=0;i<MAX_INVENTORY;i++)
) e- D/ K5 {3 I2 |7 N" d {
6 o5 K0 z! F- }% }# m" R0 U CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
+ M# H9 m; D; n$ g' R! W6 A& a/ \ if (!pItemElem)7 W* r2 s5 ?* s" P+ V3 y
{
7 q @1 l- d: d( q" A# @ vItem.dwKind2 = 0xffffffff;
# r3 y6 [" v1 q d6 k7 z4 G0 U vItem.dwItemId = 0xffffffff;
( m! b2 S; k7 E; q vItem.nIndex = i;/ b9 c, Z8 R: m
}else { E! b% a4 G3 w1 @; ^4 ?- P/ A
ItemProp* pProp = pItemElem->GetProp();
! f* v: B9 b, J6 o) a vItem.dwKind2 = pProp->dwItemKind2;8 L. F0 Y8 y! n5 t# p( L
vItem.dwItemId = pItemElem->m_dwItemId;
! [' L- v) Z* X* Q8 w& R" U* G, q vItem.nIndex = i;
7 M% c- M0 W8 w/ C8 L8 n- B }
- ? s) G I( D) G2 z* \ //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
# `: m$ `$ m0 s# b }
5 i5 s0 Q, i1 e //////////////////////////////////////////////////////////////////////////
" j T' \1 L0 Y- E8 E& c w sort(vItem.begin(),vItem.end());//排序$ Q6 A/ A% N1 Q$ s
//////////////////////////////////////////////////////////////////////////
3 V1 N; {5 `. C% z* H& e3 ` A% _3 k //交换
- j# a% l9 N! y9 ?, `/ N; b9 E, [ for (size_t i=0;i<vItem.size();i++)3 g- r2 _% o8 Y8 [9 C
{
1 e7 j! i G! {* M6 {1 a //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
+ ^; n: ^# v8 o4 F) w pInvSort->Add(vItem.nIndex);! X$ D1 Y! G$ r* s9 s
}1 I: X& {0 L. M" U" y
BYTE nDestPos = 0;) }" ~! K M @8 I' C" F' B, X
for (int i=0;i<MAX_INVENTORY;i++)9 y0 r$ @& d7 o- Q2 j
{
0 t: C" \3 e- @/ E& f0 Z CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
5 n/ F0 P( J, F& c$ d if (pItemElem)4 i E" M9 ?2 F" |% r) T. D
{ ]8 `8 w# F; J( [8 _: F/ o9 [; V
if (IsUsingItem(pItemElem))
2 d! K' |$ P( V$ {6 p+ i {) ?: I$ N2 u3 t8 V
//这个位置无法放# t7 j7 _8 R4 A3 ?# n+ T) Y- V6 m
nDestPos++;
& F4 ?! M2 [+ {. D }
1 I1 C. s# M+ I) Q- O9 p& `2 a }9 ?8 f& G8 {& j+ Z; g& P
BYTE nSrc = pInvSort->GetItemSrc(i);
: ]/ \: U) z3 M& A2 r) C pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
! P( j9 z4 C% [) V if (pItemElem)4 {! u" M( z' K" n( y; I
{9 j. q$ k% q5 f$ {- P1 y2 m, Z
if (IsUsingItem(pItemElem))
' d8 \! j% K* p3 h {1 {+ {# J$ \6 h3 w: F
//这个道具无法移动,跳过
2 O) Z8 R7 R8 {: z% y continue;
5 c1 E3 c" [1 o; V( w. _; M/ N5 j: H }4 H$ M R" y7 D; A/ G8 d
}else{
7 w4 _% T9 k2 X @ //空位置 不用动7 Y8 J3 \, _8 S. U4 P
continue;
* W8 Z7 m4 n& y }
( t b0 e9 q% Y! c3 c+ g3 j //////////////////////////////////////////////////////////////////////////! M, U: b( B( j2 `
//开始移动1 R+ M, {0 x! ^5 T% U4 R
if (nSrc == nDestPos)
+ U2 Q* \4 H) r: O+ h7 { {) M- Y3 p7 N. J- v
//原地不动
( [ q1 S; H" B0 I. @% C nDestPos++;
) R7 v" p# g. x" I* i continue;; @; K8 n& U* v, ~2 D- h0 c4 J- @' I
}
4 P% f6 L5 c- h6 P- w pInvSort->MoveItem(i,nDestPos);: c5 D6 A7 w* u6 k
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
4 D( x4 H( C. J- g! v- W: z Sleep(5);9 d4 O' b, y* D; }6 R j; A* ~
//Error("移动 - %d->%d",nSrc,nDestPos);
2 {0 ], x# q2 [" m; c$ D nDestPos++;
0 v: i; V1 Q% j1 l/ L0 N }5 t" C( E8 D" @" W' Z- d
//取第一个元素的信息" P1 g6 K! \$ B' @) C: f
/*: u, M8 ?5 {5 F" \, O& q: Y
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)6 ~/ @+ Q/ H0 l" T& C s$ ~* k
{
0 N" Y" K0 {/ l9 x6 g Error("Move - From:%d,To:%d",vItem[0].nIndex,x);. R& r8 Z- e$ t" o
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
% `! u7 c5 O" `& I9 _ }2 }' ^- B, X7 ~8 O% H" f
*/
! s3 P$ O* G* D8 s/ T( Z //////////////////////////////////////////////////////////////////////////
/ k+ @" ^ y# C! Z8 ~2 | break;
+ q0 @2 t0 b* N- [# I6 G" f }9 |1 u1 W5 A$ N3 y
} " E# q8 M7 o) p
}
( k4 \ V4 s) I0 h* H( B3 o3 f+ X tm_wndMenu.SetVisible(FALSE);
6 W% w/ U6 y* K) N5 l: ]; C
N, g8 I! i9 Y- y--------------------------------------------------------------------------------------------------------
9 l _0 v% Q( [% \. \4 ~$ P0 h搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
, _! u$ V7 s1 {8 e( v5 f{4 u4 y* d$ q$ f+ z( m9 M: N. X5 H
BaseMouseCursor();
6 V Q9 J2 R6 t, Z}: P+ j. j1 |0 a" R
在其下添加:
( C$ h1 S! w$ \) o9 I2 u. _) T4 ?void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)( V: Q1 A- z, _' k
{
% @2 Y, b+ R+ h& a- ~m_wndMenu.DeleteAllMenu();
7 e$ a' i n1 e+ _# J& Xm_wndMenu.CreateMenu(this);" t' w/ Q4 s* Y/ e
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
% ]5 x$ q# t) l8 s% J2 ^
2 C1 V9 u4 Y+ K) L0 p% f% _if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
( j0 e4 M! Z1 p6 Y$ v2 y{- }# [5 {: i( `% e/ e9 E
//P以上级别才可以删除所有道具
8 u* {( y. Y3 a$ n m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");; \1 _; A+ i' q- } T# @. `
}
/ w; [0 ^2 P! L4 N- Z3 p! T [1 _" Km_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
$ G6 {" _# e) ~$ R7 vm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
6 b: m$ |2 M) im_wndMenu.SetFocus();( u# ?% Z8 v" b$ L* y
}
2 T# K- t3 t4 h& K------------------------------------------------------------------------------------------------------------1 g t" M3 Z* o- W+ o) [7 k) y. G
************************** l% d8 }. i2 `
WndField.h文件
- L6 r4 u ]) D/ m2 ]2 ~) @*************************. |& F1 X. }. P' p4 [8 l$ G* L
搜索:BOOL m_bReport;" e2 F# F; Y9 Y# g* u- g6 B
其后添加:
7 o! s+ t$ W2 h( i' x6 u6 cCWndMenu m_wndMenu;
* H$ b2 ?& t3 m, h6 H; r搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
; l' s+ i3 U+ {8 y& v4 J其后添加:+ h) T: x# P( u! S- j1 c$ I2 P
virtual void OnRButtonUp(UINT nFlags, CPoint point);
* ^ _' p' _2 ~- X& C3 }5 Q+ o4 P: u/ W
5 h( |. z; T: Y9 t
|
|