|
|
源文件中_Interface文件夹下WndField.cpp文件
: K2 u% f* w" m* d5 f搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )# H" ?! d3 K$ s3 v0 C ~
. p0 z g/ Q! V- u2 O" K# U+ Gstruct sItem
$ I' W) Y; R; D3 A* v& P0 I1 Q{
9 \ w4 u/ b0 q# l( e: z9 fDWORD dwId;$ I c5 ^& M5 o6 S9 D8 G7 }5 A! S
DWORD dwKind2;6 u- A& X7 I, i& H/ M/ o
DWORD dwItemId; M ^2 j4 B* a+ H# n; Y
BYTE nIndex;+ M* z" e) Y( P3 n2 p& _
sItem(){0 R, X9 I1 C0 \6 b* M' B- y
dwId = dwKind2 = dwItemId = nIndex = 0;
/ _5 g6 U& k( a# A/ n q: @; r}
7 K, o( W2 a) H2 _0 M6 Bbool operator < (const sItem p2)
" y! K% e4 H7 f' |# W7 E" _* E{* g% @, x" B' Q6 g
if (dwKind2 == p2.dwKind2)
9 C' t! O9 W- Z* p { v9 }* d g, h5 e
return dwItemId < p2.dwItemId; g7 x; V7 Y0 o8 E0 y1 I
}else{' z) a1 u9 Q+ ^# o. `
return dwKind2 < p2.dwKind2;
5 ]- D2 J" A1 `; A1 V }8 a# \8 F% G1 R: r: _! j5 C
}1 E8 K+ N$ {. y/ d* g
};6 z! I. p7 X9 j
class CInventorySort w( v* F! Y; [9 O( R; x* Q- E; V
{
7 U) R; f( C/ ~2 Xpublic:- q. \3 \' y* T
CInventorySort()5 v3 ?+ t& h" D+ S' D
{, X4 y2 k- ]$ ?! f+ Z$ @2 A
m_dwPos = 0;
8 }) m, Y/ z4 F2 n$ _4 K2 Q; S}
% h: ?5 G" @8 ]. \% c6 T~CInventorySort(){}
: o6 t* z4 V) t$ E7 |5 Fprivate:
, ]/ @/ m9 P ?: dsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息7 o0 H% L/ h2 \' u+ J/ \
DWORD m_dwPos;
8 C% Q4 D% W9 j( S0 o+ Dpublic:
, |, L3 S, }4 ]2 c4 U/ q! Dvoid Add(BYTE nIndex): `' I5 \5 W8 D
{) L& w- S9 |8 o3 k' ^
if (m_dwPos >= MAX_INVENTORY)
& }3 G0 l" ? o0 E0 S {
; u. R; X3 Y- q return;
, n, G2 c+ Y$ t$ W5 t; L3 F7 N }; g# l+ I% z6 q0 \
m_Item[m_dwPos].nIndex = nIndex;3 {: y: O: P: J) G5 C2 Q/ m
m_Item[m_dwPos].dwId = m_dwPos;* c. ?( C0 `1 D. x
m_dwPos++;
3 | ~! {9 }( i/ _}
" K- d8 Z" w- Q/ \: ~BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
5 s; ^, ~5 i0 _! q0 {{ n; h& a5 h. g2 p* \1 r
for (int i=0;i<MAX_INVENTORY;i++) ?) O& I) V$ Q; C' f& i
{5 I+ I! y" p. `, H
if (m_Item.dwId == dwId)) M0 Z$ x# B) H+ e) N
{. v/ m2 C7 u, t: c: K- J
return m_Item.nIndex;
9 U" h c0 `3 m0 S5 a! z" H- \ }2 {( s5 i7 ]5 E6 O
}3 v/ T6 b) e/ h* T& g
return 255;2 X. F$ Q6 a! Z. {" J
}
F b3 H; B: G( j% nvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
X5 K6 x0 w2 l% G7 ]: s3 |! n4 B{
! ~5 i+ x( w. n6 n4 M8 B% c BYTE nTmp = 0;2 X) W! s# [1 t8 U
bool bDest = false,bSrc = false;
/ r0 t3 g, s' n0 R# a' B. u2 X for (int i=0;i<MAX_INVENTORY;i++) G! g5 |7 u Y8 d
{# `& x" X7 x. E0 j- X# t
if (dwSrcId == m_Item.dwId)4 `& u& r" s: f# J* u3 z
{' L( h3 r/ N& r: \% \1 q
//id相等 则 改变对应的dest和src
8 q6 r/ ?- e0 Z nTmp = m_Item.nIndex;8 Y7 }- ~/ u5 y& y
m_Item.nIndex = dest;7 u9 O# R* P2 R; r' r' Y
}" \% f4 ^" r5 A$ ~/ n
}
5 R: e/ H, d. O6 {1 \( q( ` //临时数据保存完毕,交换开始
4 S; \# d2 J% p7 |+ c+ p( i( S for (int i=0;i<MAX_INVENTORY;i++)
- {0 L# D0 A6 M' q2 S3 t4 [& ?$ T {
, v/ ^7 l) @* K7 Y! e if (dest == m_Item.nIndex): n4 ? O) o% ?9 D- ^
{
. L7 Y' I" x2 ?- ] //id相等 则 改变对应的dest和src
5 d9 W( L# E W- ] m_Item.nIndex = nTmp;' q# [. O' n7 V1 K" ~& J( t" J2 c$ ?
}9 `. A+ D7 ~1 W+ N u; s
}, y; X7 F2 K% m5 J
}
4 Z* S+ B/ W: T9 M( O};
4 Q' D2 C J7 j" f5 `-------------------------------------------------------------------------# |. c4 V! G1 \0 }( ?6 T
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )6 I o6 @( ]0 V. V5 R" D/ e
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);7 a A- m7 V3 w; v7 S" m
紧靠其上添加:
7 e; k% N% G+ q9 V: ]if( pWndBase == &m_wndMenu )
, a; A1 }/ O5 ^; |$ s H{5 u) k7 Z) p; T/ ?
switch( nID )
1 A6 ]2 Z- _8 X1 `; f {( [( T) O6 E1 o# j. n Z C
case 2:3 j x( j5 w; q9 k( P
{$ O% d; T+ i W+ O3 c. h* y* U. U
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);. h# C" V$ J$ q
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
' ^( j5 k( D' f. R* b$ `/ k {& b8 |2 [, D$ ^, U% W) H) l
break;3 ~& i( D8 ?5 O5 S3 g
}& T. R' G5 ^8 Q& a8 o' m
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
) \: t: j' U2 Q; Y* U' S4 i {7 d4 r; \7 u4 P1 \9 s: r
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
6 U7 ?1 c# x9 H' X7 O if( !pItemElem )
5 U' n% N# |3 e1 g7 O+ W continue;
2 x7 H# i4 m5 v7 c5 U if(pItemElem->GetExtra() > 0)( ^* {0 q# N6 W; v! e( c0 i3 u+ `1 H
continue;3 |5 v0 I+ F' ]
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 7 e* `6 N, z! R
continue;
% q/ _9 o1 T1 x. U* G, k3 E0 _ if( g_pPlayer->IsUsing( pItemElem ) )
. v( q/ l5 K& A+ K$ c. Z7 \ continue;
4 k5 t! ~9 R4 F3 S6 |) [0 }9 u4 m if( pItemElem->IsUndestructable() == TRUE )9 M+ W! M2 D( H& j5 l
{9 {1 r5 l2 W1 f2 _1 h& M! o" O
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
) F$ F- g# Y3 {) \+ Q$ V continue;
2 b, r d1 g/ |- a5 c9 W0 F }: i4 z, D: e3 g
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
7 B- {* E) e" y4 ^9 F6 u$ f }8 ^! E8 b- y/ s0 W' e
break;& Z2 m, H: F0 ^2 y: r
}
* U0 F- A5 T* c* r ~( B case 1:4 G5 t& |( f& i/ p" x& h& A+ \: r
{- s$ ]4 j" V2 F6 B' Q) K. E& `
//整理背包
' f# S* g# [( u3 u //////////////////////////////////////////////////////////////////////////3 {# v# v/ v' m. V4 ]1 E# W
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );; a) m' l& G6 O% o1 r0 W
//////////////////////////////////////////////////////////////////////////
- f; w. [+ L$ S% s% U/ S6 [( u //////////////////////////////////////////////////////////////////////////7 r9 L: f( k' |3 t/ P8 V
CInventorySort* pInvSort = new CInventorySort;/ c/ o s: N* J9 Y
vector <sItem> vItem;, K/ s# ~7 P" x! ~, h4 r
vItem.resize(MAX_INVENTORY);//初始化大小
( I" g8 d2 O) c //////////////////////////////////////////////////////////////////////////
/ \- B5 J7 Q9 ~1 R0 T //填充数据( W; o" _; \9 F
for (int i=0;i<MAX_INVENTORY;i++)
1 O) g7 u4 F( r, I3 U* G% [. h) C) H { Q$ n9 U# ~: M# N4 v+ d5 H
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i); ~& C' R: o3 _7 P
if (!pItemElem)/ c# r* U& o) v* W
{ M) J1 s$ M* H' |8 G8 K9 K
vItem.dwKind2 = 0xffffffff;
4 @; `+ b/ ?6 h2 N8 Z0 H vItem.dwItemId = 0xffffffff;1 a3 o: P7 a. D& {1 P* j; L
vItem.nIndex = i;
% K+ y9 n6 A% [, f0 [ e: B }else {
# V9 }' P" {9 F ItemProp* pProp = pItemElem->GetProp();
3 w1 x. _- L: ~' t& q- @7 Q+ e vItem.dwKind2 = pProp->dwItemKind2;
5 H: |1 ?" f9 N( ^ [+ a vItem.dwItemId = pItemElem->m_dwItemId;' t% z r; ?( [6 d/ a) r' Z4 P$ I
vItem.nIndex = i;
1 \- n7 J4 x( W- I3 [( X; S, M5 w }' G+ O% Y- t6 V7 u
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
) z: |4 u1 E- e. q- ` |3 l4 x* M }3 J& c) G7 ?" {$ ~" I# [
//////////////////////////////////////////////////////////////////////////
2 [9 |( |, K# L K sort(vItem.begin(),vItem.end());//排序( y5 L* [- y$ `" E2 L0 I
//////////////////////////////////////////////////////////////////////////
5 p' f' B: v" y$ h$ ?+ ?. G //交换7 _" w6 t4 P# d- |: w
for (size_t i=0;i<vItem.size();i++)) q& d H- ?4 w1 v
{1 e" e/ |' a- h' G# k) D* w; {
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);% {! e# z. f8 B* D( V
pInvSort->Add(vItem.nIndex);! T# ?& _% L9 Y
}- `$ l; w7 N6 h2 k9 ~4 U4 y4 v
BYTE nDestPos = 0;
9 U5 l& C8 }0 z9 M( B! |- O for (int i=0;i<MAX_INVENTORY;i++)
$ Y2 ?6 H( \0 O/ I" k+ G {
& |8 G; u8 r, X9 C CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
; c' G6 q& `8 r1 ? if (pItemElem)* n# s. V5 Q7 U
{7 E8 O% R3 h0 l1 O6 X: o
if (IsUsingItem(pItemElem))& x4 X. k* f8 X3 O
{6 @4 M( e- W1 p5 m0 E$ T. P* Q
//这个位置无法放
; U+ w. t% O5 v& c) D nDestPos++;* h0 u; M3 A" O
}
% }* a# l4 u o, S8 F }/ r# m+ H; i, Q
BYTE nSrc = pInvSort->GetItemSrc(i);
, k& l( H. u5 i5 j7 X: S2 v pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);9 v' @" L/ u$ y4 }/ j
if (pItemElem)9 ]1 ?9 ]1 ]1 i' i) X9 g m
{ l2 E9 F a$ D& N- k
if (IsUsingItem(pItemElem))4 k8 c, ^6 R' D! |! S& i
{7 P! E* |. A8 T$ ]8 k0 \1 t4 B
//这个道具无法移动,跳过
0 h# H( }) i5 i continue;6 X: ?7 ?1 c" p7 _8 e; _
}
: v( U& P4 X* b& f; X$ m' K2 o }else{
. V' K3 I: d0 ~- C% f //空位置 不用动
0 \' o6 m2 R, o! r4 w$ c$ T continue;
2 O7 R' P8 P$ N, \1 ]2 l/ d: r6 @ }3 o4 p# {, l0 s0 m7 R/ U4 e0 ]8 ]9 c
//////////////////////////////////////////////////////////////////////////
" e5 F3 y3 s8 D1 ]6 f //开始移动
" P" Q. ~ h, W* y if (nSrc == nDestPos)* a: K; W" ~4 `$ t
{
6 ]: B1 G6 Z6 @* j$ U //原地不动
% t9 C& t) F9 `% K- w5 ~/ M nDestPos++;6 M) {4 j# Y" ?
continue;, f7 W% p! B. a3 R
}
& a, ~1 c4 ]5 z1 X( @0 k8 x pInvSort->MoveItem(i,nDestPos);
" O0 W# k- R9 H' S4 v g_DPlay.SendMoveItem(0,nSrc,nDestPos);
5 v$ l- P! g+ E, ~ Sleep(5);
) ~( @* o) B& q- W" p: b //Error("移动 - %d->%d",nSrc,nDestPos);
4 x4 K* S1 ]0 @ @ nDestPos++;
: v1 \. p( N) @5 o }
$ c% S/ Z, `9 ?4 T, H+ y //取第一个元素的信息( v, Q. p" O) ~( M; U% R
/*
, P7 K# w$ M! o K8 Q if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
1 ]( p! d. e' X8 A! y {
3 z$ ^6 }1 L# K% u+ w Error("Move - From:%d,To:%d",vItem[0].nIndex,x);! b+ G+ D* q/ X% J
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);" d1 I. J9 N9 O! p; G
}5 x- v# V) @' i, x2 M* P
*/0 U, ^5 J6 G+ i3 `! C* F" B
/////////////////////////////////////////////////////////////////////////// \: ]! E4 w6 \5 Y' x
break;+ F: @" g& N; W* Z' ]# I3 N z; V0 W
}1 z3 W9 x" K7 X) ?6 X- V' c$ O
} 3 k& `. `" |: Q. [7 E' u5 R5 K
}6 s% h3 X! t% Y- T
m_wndMenu.SetVisible(FALSE);
& Y. `) X4 E) E; O$ k+ e5 _
2 {+ G% [+ Y* t3 k0 L5 L4 i: {--------------------------------------------------------------------------------------------------------
/ C' M1 y5 Z7 I$ H搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)! F5 |" i( e' f, [- g1 O c
{, z* @7 G- \, q! g% `
BaseMouseCursor();- P! ]" P+ b V+ ~* _! j
}
; q7 M7 H* L& T2 h* p在其下添加:
) |! j6 E( l% i4 k f& ]/ tvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
6 ~4 s$ C$ I% T0 l& k' b5 _. S{& Q- p' n' o. j- [0 l
m_wndMenu.DeleteAllMenu();4 X f4 x6 i3 g0 T2 _! |
m_wndMenu.CreateMenu(this);
6 F3 z+ t4 [0 n7 Vm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");$ [0 ~. B$ B! v5 v
8 k4 A7 U* d. c# }6 ~
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
3 l1 n" @$ }: T8 h, G( J# t( l" x{8 w- W! |! h1 Q
//P以上级别才可以删除所有道具+ R0 m/ \2 f5 S* V ~. u
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
3 a0 \7 K, C" j' E6 o' G}
% j4 j( \& F+ i- o9 Qm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );1 y6 G3 k/ i( H! ~2 C
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
" @7 C& `! x0 Z' l6 om_wndMenu.SetFocus();6 X: a, Z: h* B {) L Y& ?- R) ]0 x
}; _9 a+ N9 U) Z
------------------------------------------------------------------------------------------------------------
$ F8 c3 M6 ?! o8 h$ z7 g*************************" M7 o: ~+ r3 ]# ^+ \; ?# }% H* U
WndField.h文件
! ^* K8 H$ g$ D2 `, \2 D' Q) ~*************************
: h3 V! T, W# X0 x搜索:BOOL m_bReport;
& V9 p: C, a2 j, l其后添加:
1 B0 }' {+ y8 e* N7 o- j" w% V3 @CWndMenu m_wndMenu;
% K) z( Q8 A: @0 E8 w搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);0 F. }5 b& M+ y7 F D' @% N
其后添加:9 b) e; n- I3 F0 F# C8 h% T
virtual void OnRButtonUp(UINT nFlags, CPoint point);
4 X3 _+ r' ~$ _" P+ F; w2 f% ~3 |- Y% E! R4 Y+ d; w6 L
- g: U) g8 k" n0 [0 W0 Y
|
|