|
|
源文件中_Interface文件夹下WndField.cpp文件- M2 i( d2 [" `7 Y/ M- p
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
' o2 _/ P1 V2 F8 \" j3 B5 B( A% I2 ?: {. l5 V
struct sItem/ X j9 y7 ? `/ Q; ~/ x7 i
{+ ~1 M) {/ u; t6 p, K' j
DWORD dwId;
% h7 Q% |# {" E* y9 ^( b0 I! E- LDWORD dwKind2;
3 _# Y: Z7 S: R, HDWORD dwItemId;
$ j3 b ~, P5 x% l! f; I9 ABYTE nIndex;
1 ]: n5 f0 T- [7 N) n5 z: z' L5 SsItem(){
! v+ i) f; V+ F9 p dwId = dwKind2 = dwItemId = nIndex = 0;+ z3 |2 U* j: p$ A {( [
}
% A$ X4 w' H# `3 t- M$ R2 k& c5 J. pbool operator < (const sItem p2)
1 A) U9 v: g4 R7 f3 F, h{
0 J8 G7 o; [! ]5 J4 [6 x if (dwKind2 == p2.dwKind2)
% A3 }! F" T. p# m! N) ] {4 N' L1 O3 I6 y) _$ T" T
return dwItemId < p2.dwItemId;
% L4 X' ], M) j4 _ a) C7 D }else{
0 c+ D( @" z- N4 `9 Q return dwKind2 < p2.dwKind2;7 g& o" L7 G/ M" V
}7 v+ d! P5 Z- v8 c$ s
} u) @' z& {0 S2 J6 q
};
' i" B' x: t- H5 c2 }3 Xclass CInventorySort- ]& i) n2 I2 Q) N" ~% w
{; X( s, u. \' L3 W
public:8 j) ` x* x9 D) b- C( v
CInventorySort()5 ^/ S9 ]8 p6 y7 ]
{
8 L1 z$ u. Q. I0 K; ^! H- }+ I m_dwPos = 0;4 Q' J/ u/ R# \/ Z. _( l+ m0 ~. r2 R
}
0 S. u* H3 Y8 R1 @; J~CInventorySort(){}
J& _/ X7 u! W) {private:% g! i; L) _3 c& T4 N+ B% _
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
; T& M% y6 A9 O) u% MDWORD m_dwPos;
8 d' A0 k% y7 k$ ?) x" u) z o- hpublic:
- ?# `% z% H' _) i# K' L# ~: |; lvoid Add(BYTE nIndex). `( I3 W8 f# X2 u' ]
{
: _4 ^3 U( t3 e+ H# P E# n if (m_dwPos >= MAX_INVENTORY)9 f" ^6 Y O* L3 Z9 G8 {. k, W& l
{
: ^6 f. Z- @4 M return;
0 F. P! f; c Q3 ]. K }
9 ~" B! H4 W& M+ P; b/ y6 y& F m_Item[m_dwPos].nIndex = nIndex;- B1 Z0 e# u/ c6 {! R/ A* \+ Q; c' v
m_Item[m_dwPos].dwId = m_dwPos;) t5 G: f1 v _& y5 P4 a( ~* _
m_dwPos++;7 t$ I/ z" ?8 v; E% I2 ~9 k
}
3 o) j: R) T) ?+ J1 Y0 z4 pBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列5 ^2 j+ S0 X/ h5 F3 i& `% w
{
% R6 u% J# A% Y7 S) ^ for (int i=0;i<MAX_INVENTORY;i++)
9 y9 P# R5 o# d! |/ R1 z- p) \+ h {
" c y2 P$ r1 O if (m_Item.dwId == dwId)* C8 M: a- j( D
{$ Q* ^5 ?9 e& L+ V. @* U6 x
return m_Item.nIndex;: u$ z# d ^$ x; P. V, h7 }
}
" P0 H( z4 b4 A. r }7 u T4 I: f P" h# @, j
return 255;
z/ j% g' n3 z& }4 n0 K; x* S}
$ T, G- @; e* fvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
4 i9 h, f o2 ~$ K- t{
, S. K& j& z% @( ^5 w BYTE nTmp = 0;
- T3 K8 o2 X: U* m; t% y bool bDest = false,bSrc = false;/ F) c M& Q" i% Q, c* x
for (int i=0;i<MAX_INVENTORY;i++)
7 c0 W4 s$ i4 H- ? {; d g8 p) o2 J. n1 y# Y
if (dwSrcId == m_Item.dwId) H# x% P! M$ Y0 L, n0 p
{" R# K7 c$ l) [0 {
//id相等 则 改变对应的dest和src5 _. x2 I" H$ j l9 m% `' z; C
nTmp = m_Item.nIndex;" q G! F* [$ Q
m_Item.nIndex = dest;/ D2 Y+ |5 @" O" U: r/ _
}
" e* q: K8 V' v3 f }2 T: s& c7 Z3 {% F* o
//临时数据保存完毕,交换开始
# s' w2 r8 M! M( \$ Y8 S for (int i=0;i<MAX_INVENTORY;i++)
: e& G) Q1 J0 r. ~, r. @ {
3 A1 y4 J: r) P9 L7 s+ @; r7 u if (dest == m_Item.nIndex)
; M; A7 R& K. L9 p {
1 [: x/ X/ i2 `( }8 k //id相等 则 改变对应的dest和src
/ v' h' @, k5 c5 ^% | m_Item.nIndex = nTmp;
9 Q( U7 A R& N2 H# E1 f; l }+ B' U2 u% \* ?/ b4 X8 l
}
5 R4 G& l2 L# V+ ?5 u}$ ?# j/ F0 }# L9 ?- Y7 I' `6 ~. x: M N
};. j7 ?* o' n! y0 W
-------------------------------------------------------------------------7 H2 t# b0 {/ c6 V
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )9 Z4 ^- Y/ G3 C- R$ o2 V
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);) @* V; K$ c; p$ B
紧靠其上添加:9 \/ B& S. m% o. g/ O; ~2 f: C
if( pWndBase == &m_wndMenu )3 k$ k- `' w. u9 o
{; {' [& ?) h, T* R( m( a' z
switch( nID )
K5 ?7 W! M0 _8 D {
3 [ F2 S6 z8 i$ I+ ^9 j+ U+ z case 2:
+ B8 S4 C- V9 W$ l {
" W: p$ t) T( B9 K2 [ _6 L3 S //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);& S1 e* j& b& r* U
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))) d, _8 x' `! Y+ t
{
3 h+ Y% E3 ]/ E break;/ \8 ^& Y( t+ U9 B( f/ b
}
3 b4 S1 L! U: ^ D for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
& A! G. G; b8 A X% \8 Z4 y {
' ^, j/ w# X! D! K+ r- [ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
# p! z, ]4 D! J$ C( r9 y8 T8 W if( !pItemElem )
/ O% `: W$ h" ` continue;- y' l5 f0 K- W+ M
if(pItemElem->GetExtra() > 0)
) p+ S+ ^+ Y+ Y# w6 T continue;* G Y1 B# [" R' v" M
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) . d8 A M3 N5 G8 `9 c& V# f# s) x
continue;, Q& Z0 k6 G: F9 J+ L1 P7 ~
if( g_pPlayer->IsUsing( pItemElem ) )
! a# V! ~0 N5 U continue;
, Z& e3 U& _' o( e I) ?5 D! U( { if( pItemElem->IsUndestructable() == TRUE )) v' h+ T# U8 G+ S7 ~0 J
{! r6 ~& |5 g$ X/ u/ N
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
5 X' g/ s/ H! h continue;
' K- \5 g( h3 c f6 G3 {. S }- |9 D+ s0 {) Z5 K
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
5 t) c0 o0 h+ K- |0 b }% S9 b& o h! c$ H% g2 V% U
break;
, \' i) D0 t5 y& T }
) R9 x8 v2 M5 {3 w- ?! e1 A4 L% ` case 1:' g! c- M3 h5 e+ h8 ~
{* Q, I+ Z! U! E$ o5 {
//整理背包0 Z' n7 v. r3 c5 t" h
//////////////////////////////////////////////////////////////////////////
8 y4 Y) F8 f( n& [( f //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );: C( j- F4 q. r
//////////////////////////////////////////////////////////////////////////
& e4 [( R7 H" w: r- B* d //////////////////////////////////////////////////////////////////////////
- w# \7 I9 C& ]; G2 H+ P( r CInventorySort* pInvSort = new CInventorySort;
{. m& Q5 `# ?9 U- t vector <sItem> vItem;
) t( v9 m7 Y* d' D vItem.resize(MAX_INVENTORY);//初始化大小
" C! ~. K! J$ l8 h1 E6 S //////////////////////////////////////////////////////////////////////////5 C8 y6 \- |! X# P! X5 R. P
//填充数据
1 M* z0 H# j1 x3 { n: ~ for (int i=0;i<MAX_INVENTORY;i++)+ L* N: Z/ `1 K- r- b4 ?& ~
{. A" d- G. X; i2 ?: I
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
9 e! u6 E0 K' h6 h j7 g if (!pItemElem)
8 H! w i9 W* m8 f {
2 b! K- I8 }2 \4 v vItem.dwKind2 = 0xffffffff;0 [2 K: Z# k, ?. ?' L& ?* O' u
vItem.dwItemId = 0xffffffff;
" b: y( t' s; p, @( G" z vItem.nIndex = i;% q0 n; p5 q' `6 a1 n: A
}else {
; A+ b7 D3 G. [9 b6 S+ P ItemProp* pProp = pItemElem->GetProp();1 V; N7 J! E+ ]) M- N
vItem.dwKind2 = pProp->dwItemKind2;
6 Y2 H* R7 M( ^4 T+ e vItem.dwItemId = pItemElem->m_dwItemId;
% X& J( j' a5 Z9 T) c9 V* W vItem.nIndex = i;
. y7 ^* G/ { r, I5 V9 k5 N }
, w6 z5 B5 s1 s6 E% F //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
# g3 ~+ Y* [8 f, [ }
) g3 l! J: r$ G0 b' p. r //////////////////////////////////////////////////////////////////////////
8 o) u# ]( a$ ?; z$ a7 f% w$ A: x sort(vItem.begin(),vItem.end());//排序# Y0 [ N+ Y2 `! t9 t
//////////////////////////////////////////////////////////////////////////
! v% C. ] c" r% @9 I //交换- z$ B) N! x1 c0 y2 a
for (size_t i=0;i<vItem.size();i++)/ u! D6 ]" }. j* ?
{" ~- W, \$ g0 F
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);1 z5 ]4 G1 M3 j6 i( e
pInvSort->Add(vItem.nIndex);3 g* A2 D: Y* n5 }% o/ v1 m% ~
}
+ I. z9 D* C/ S7 T- A BYTE nDestPos = 0;4 n, T- x8 A- N6 Q" u) }$ }1 X! ^% M
for (int i=0;i<MAX_INVENTORY;i++)
8 O H5 J& b2 l6 N$ Z4 r, Q {
$ Y1 d# K" T) w/ U+ \' |! Z" ^ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);! y; i# P. Z6 i, t0 I
if (pItemElem)
, T) G0 h5 r: @ X4 x# V7 b {
( p/ k; E$ @& `+ X$ q if (IsUsingItem(pItemElem)), O- j* e& v* q# a* L. ~7 K
{
( e/ l$ K2 G9 d4 [ //这个位置无法放
3 l8 y+ _1 F8 K6 c2 e* W/ A nDestPos++;$ O1 C1 s8 P. e/ @7 k7 `
}
. o9 K; H! F8 W$ \ }" a: m- [& X6 K+ O
BYTE nSrc = pInvSort->GetItemSrc(i);
) H' y6 B" R% a7 k2 J! N7 f) r pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);4 V. \: W" ]4 u1 D8 d( r# e: p4 Z
if (pItemElem)) [' q& T3 E$ [
{' V# \3 u4 U" s5 V6 I1 V
if (IsUsingItem(pItemElem))
- l* z4 `8 W' Z5 E {& i; S# a% C- S
//这个道具无法移动,跳过
! }$ u( H# {& e6 a continue;
& f% m* }$ x. K$ G }
4 _7 o9 u% Y# g }else{
3 c, O) [9 W4 X //空位置 不用动
: b. C4 E0 g+ R+ A6 W continue;5 C, J9 e& A. [# f0 z" Z: [3 k
}: i/ }$ y4 l+ u) \# r, `
//////////////////////////////////////////////////////////////////////////
4 u* V: [5 z0 j) ~& _; o) p7 k) ?8 u //开始移动
9 ~! |# N. P. _% _+ D* [2 Y1 D; t if (nSrc == nDestPos)
4 s3 O% X( {" e2 M6 j& f {8 p& x$ p0 d$ q" b
//原地不动
T! L; V/ V( b+ f8 h& C7 K% G7 @8 A nDestPos++;
) |5 T( ]/ f3 [, u. _" x+ d continue;* s: @5 x' g/ g) ]5 G; \
}* D( @" ~/ z$ x, ~3 Z; T
pInvSort->MoveItem(i,nDestPos);
0 M1 j' Z+ c; r% n+ ? g_DPlay.SendMoveItem(0,nSrc,nDestPos);
. |* ^- {& d3 v+ p5 o: H; Y Sleep(5);
. d% N1 i' K* [1 e //Error("移动 - %d->%d",nSrc,nDestPos);' M0 f8 U; N% B; I. E
nDestPos++;( L( d- X' L! o: X
}( W! S9 g0 k$ k0 \
//取第一个元素的信息+ ]- p; {. v: i4 M! i8 r
/*
: I! {3 s5 H" i if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)# a0 |, q" C. G# i1 O8 X
{) Z5 _0 X8 p( {/ s& I
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);9 {8 ^$ G2 h ~/ V$ b1 x M! i
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);3 \: A5 ~3 e0 l% u
}
% i$ Y" D' W) ~) A B/ p */
. }' i! ]5 G9 z8 J- _ //////////////////////////////////////////////////////////////////////////
1 O. A4 j6 D, n' I" A8 G break;
$ c+ Q) q: a6 t* u0 U }) d; ~) @) r4 I: M
} * o, W$ b; D- ]. b+ @2 z
}' K* |3 | N. [/ t4 s
m_wndMenu.SetVisible(FALSE);
2 P5 o' W7 i) ]; |, N- H1 i2 V& C' R+ k# S2 Y' q) G
--------------------------------------------------------------------------------------------------------
) R" p# A- b, c+ n/ p) e! G- E搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)7 Z0 `7 T4 Y$ {+ x# j
{6 m* R- t) W, H4 f9 E3 u' r) ]! J) e
BaseMouseCursor();
" ]1 d6 }. Q: E) s9 |$ D. |. P}: S1 r8 J i3 P+ [# [2 v, E7 X
在其下添加:
: W7 J. p2 o# N& D4 Cvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
, Q3 ]/ R# s% V6 L5 V{. k7 t3 @4 M/ s* j1 x( b& r% h
m_wndMenu.DeleteAllMenu();
; u3 f; w$ z1 l- \# D4 Xm_wndMenu.CreateMenu(this);
# O& J C" z; t# S5 e# tm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
x& C8 }- D! T3 r5 w+ K$ d9 [
/ o1 s1 E z! ]" z- ^if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)): @* e3 W* ~: {' e) f
{/ s4 ~5 [8 r9 ^+ U( G
//P以上级别才可以删除所有道具
& j3 t- x) j1 B& A; E8 C8 C8 | m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");6 ^8 L' ^5 M6 c: P2 ?+ U4 U3 O
}
$ Y3 @ `; ^) c% Pm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );9 O1 d3 J+ }6 v& _2 J* x3 Y$ E
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );9 u2 a! \; q/ K) {% F0 p( z' P
m_wndMenu.SetFocus();& h- X; Y* Z7 }% @
}8 ~$ ~# m" B3 e! q$ |, u0 I; f4 |
------------------------------------------------------------------------------------------------------------5 y0 }; K$ b- R6 K) p3 s
*************************
, U/ s8 {* @! G0 KWndField.h文件
- k5 C- L; K6 P+ [1 {% E& S& H*************************
( |5 h, ^! I2 ? t9 C搜索:BOOL m_bReport;) E* C. b1 {0 v4 }
其后添加:
( C5 A+ `, a) v# W+ CCWndMenu m_wndMenu;1 a( g- D& |0 W; |$ K3 W% e
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
?& w, w" |# J* ^. q7 j2 H其后添加:
2 ~/ C. Z0 b$ I* dvirtual void OnRButtonUp(UINT nFlags, CPoint point);" y, O5 O. z% B$ c5 i
9 @ A- m9 I6 P- s0 r% E
5 P, h* i8 p8 i( h) W+ z0 u7 w, a |
|