|
源文件中_Interface文件夹下WndField.cpp文件1 q; y# d1 A, f: o4 ~5 z/ u
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )2 u- N4 V$ a4 q# |, s- C- O3 b+ H
2 b- k" u+ {- Q4 F3 i& c
struct sItem
8 I- R9 I5 K5 q; \- \{
, t% O7 e8 s9 B+ g d( J+ `DWORD dwId;) D- x A' Q4 e0 k8 a3 a/ V
DWORD dwKind2;
* S! U; I: ]6 a: }DWORD dwItemId;
% p6 c/ u3 j# eBYTE nIndex;& }3 a( W \) c- Z% N! O2 e
sItem(){
! s* q m6 I5 L& D! B) [' ]/ Q dwId = dwKind2 = dwItemId = nIndex = 0;# T- h7 a; |8 `: |+ T# ~
}% l( o( q2 M9 Y* w% w
bool operator < (const sItem p2). [. |& \# g* C8 [8 U* o
{8 q7 _% j0 o+ y9 J* u8 K
if (dwKind2 == p2.dwKind2)
3 x' M3 o3 v/ I {- `2 x" [6 k/ x$ P; L! d) B
return dwItemId < p2.dwItemId;! _) m" d$ I' n- U
}else{) G8 Y {0 C8 ]5 m
return dwKind2 < p2.dwKind2;9 }5 A8 A. A. E& u
}
1 a, J5 R& X3 g" J}! c1 S# k, | \* T; @
};: I* \. A9 D% B4 a a
class CInventorySort
, W$ k2 |6 y3 i9 l! z! p/ s{
0 |* j/ P$ V2 p+ B; Bpublic:
- N6 d5 D' A3 H3 J4 i2 [ t' H/ vCInventorySort()
6 l' h w! I7 H& }; o" j* f{
2 u3 L8 q2 Z- t) E/ ?3 } m_dwPos = 0;* w5 J$ u, t: J( s1 b, o
}8 A" ~& Q. m! f! Q0 }
~CInventorySort(){}$ V+ `, G$ T6 s: U, L
private:
3 t1 O# _# b% b7 m' LsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息( h; F+ X r: C& ^: r/ R
DWORD m_dwPos;
; E! U$ e) }( \. c: upublic:' T8 i8 f; |" a* L) ? i
void Add(BYTE nIndex)
2 _7 X0 `9 p" `2 f) m8 g; v, \5 `{+ I3 V- _& }( u7 P! g
if (m_dwPos >= MAX_INVENTORY)! ?7 q( ]) k B/ [3 c5 S" M# u
{
% z* i2 j( u1 {. M return;
: n$ j8 T Y& @ x }
& R% O9 I* \ U+ I! y! n8 D! [ m_Item[m_dwPos].nIndex = nIndex;% I, g* @0 R2 U# O: t' F
m_Item[m_dwPos].dwId = m_dwPos;
" I# d3 ]0 c$ R$ @ m_dwPos++;0 D/ ?4 n7 l6 ?# K0 X; X
}+ e" [( g6 Q) _/ i
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列1 L$ Q; z1 J1 a0 ]$ w
{7 T) j9 Y. W! ~
for (int i=0;i<MAX_INVENTORY;i++)7 Y5 N$ O& {3 M/ I9 @
{$ o: i! s) j* Q q" a/ M
if (m_Item.dwId == dwId)* K% G( _# V0 _! c8 ~ ?- @
{* d! n" `' s8 U: C( ~
return m_Item.nIndex;
4 H$ ?2 [- d) W: S }
/ z! d p6 _( m1 T8 c& f }
/ Q9 ?2 R3 ]+ L) R! p return 255;! b- K! M# |3 X% H1 g$ z
}
# a; \. v/ _% B5 Uvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置3 W8 Z2 g% a6 }, }- u- `
{: F3 W% l3 B$ t' j4 K0 Z
BYTE nTmp = 0;( Y+ ^7 ]* O- j, q1 s) ]
bool bDest = false,bSrc = false;- ~ a9 v. {& O6 w! `) L& P3 l% H
for (int i=0;i<MAX_INVENTORY;i++)/ q3 i/ ~/ I0 ^0 U% v4 [
{0 G1 l! O9 w4 c
if (dwSrcId == m_Item.dwId); Q- M j( E& Q0 a: X
{
: J& _ I' F3 d( A+ _8 ]( e6 p //id相等 则 改变对应的dest和src
! O( B# v" S: n0 d5 n' u* T nTmp = m_Item.nIndex;
w! R% D& {' O# H( H m_Item.nIndex = dest;
H% w2 A5 U6 _1 Q }
# o7 Z, I4 s5 ?9 T. h! _3 _ }
' E; x5 C5 J6 ? //临时数据保存完毕,交换开始
, F/ E9 j: }1 d for (int i=0;i<MAX_INVENTORY;i++)
! u8 H3 x/ j: P: h {
) \6 W+ i3 [ M8 [4 [0 w; i: n0 ? if (dest == m_Item.nIndex). Z) Y4 k+ n2 {
{! @1 A4 F& q, V* s# m, t& p
//id相等 则 改变对应的dest和src3 ?/ c0 h6 B- V& X4 W
m_Item.nIndex = nTmp;
% P8 s4 k0 u0 ]$ T2 F3 P }
7 z ^6 p8 L! [3 f }$ w+ E/ \2 \# _7 k( T8 t
}0 f- B( c* r+ N n, }6 A9 C/ E; x
};7 N3 C0 [3 Y! q* k) P( |' u; h" b
-------------------------------------------------------------------------
5 }7 l* l" C5 ^% t6 z, f依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
9 c, A4 y* S( x搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);, ?3 i" L* k$ M4 q+ V" x
紧靠其上添加:9 L( i- X1 t; t2 b& d; M v/ x
if( pWndBase == &m_wndMenu )0 f7 C9 g2 m& ]8 T- Q
{
& A w( y$ |$ ^ switch( nID )1 S3 d G* ?0 D2 z! y5 t" H
{
8 @ \$ K- B: b% L% n case 2:
3 }, k, t$ p+ e1 I8 N7 U/ ], s/ ^ {
( C2 _" h2 J% @+ X. ] //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
$ }' H! t5 ?2 m- K" M& M% S I if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
# S& Y# F" T4 T6 U {" w1 C) s( i8 J$ m
break;
2 X, g* c0 a- S( \ }
4 s0 A, k& A% w; _) a, K3 u3 ` for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
: j' z! w9 e2 o' X; e {
J$ C) v4 n, E3 ~) Y" k9 J CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);& \' J6 W4 m4 z* p
if( !pItemElem )
- L* l5 c: j) ?! O continue;1 G3 V; d$ s9 J ^4 V; q0 r
if(pItemElem->GetExtra() > 0)- o5 T3 e P4 S0 O+ S2 o/ G
continue;8 \' x. }8 K, E, r5 r/ ?0 s
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 7 f+ V. T& I# B5 S+ o# j
continue;, p5 S4 K( D$ ^3 W. [/ t
if( g_pPlayer->IsUsing( pItemElem ) )- G9 g9 m& F9 F# @: q
continue;! w; V h: z, y r, ?0 H( @
if( pItemElem->IsUndestructable() == TRUE )5 {+ a& Y( B2 V0 Z, `
{% V5 g6 m" {- g# Q* r
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );7 L: `6 H- X# N( g6 A
continue;7 m' f5 F" E/ \
}
! T4 p3 Q& W; }# c5 J+ x% g! h g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);8 q6 H$ X8 [4 ?. V! l
}
1 s8 |# x) b- J# m) [ break;9 _: o: n1 m) h Q2 k
}. h- _/ Y: D, ~* j1 s" \1 d( m
case 1:
5 p/ h; c$ H' b# T4 Z* m {
- N: W/ p! F1 w( n //整理背包
! s+ h1 V( b; d A //////////////////////////////////////////////////////////////////////////
% {, {4 k5 q+ m, k2 E3 \, p //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );$ ^+ o8 e- ^8 |- @: a9 x
//////////////////////////////////////////////////////////////////////////: T3 J0 _, F& p1 }9 e0 x; L: Z5 \. Y n
//////////////////////////////////////////////////////////////////////////
; [' j) t2 \, w- S7 ?4 p- J7 c) { CInventorySort* pInvSort = new CInventorySort;
' X5 `/ C% f E2 W+ } vector <sItem> vItem;
. F# v9 @. u) p vItem.resize(MAX_INVENTORY);//初始化大小9 D0 J, v- I( S$ }9 O
//////////////////////////////////////////////////////////////////////////
. B+ _; D! {( ?" m! l B5 S //填充数据5 \; h6 I2 L; ~0 j3 X
for (int i=0;i<MAX_INVENTORY;i++)
% h2 |: L, O4 G( O! f5 A; g {0 p# o( o+ g1 D1 \* [7 J
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
) j9 b" k* _3 H. T3 v5 D4 J j if (!pItemElem)3 [+ g% K( Q, ^
{
% B7 g" z# _: [' P4 Z vItem.dwKind2 = 0xffffffff;$ E0 t( ]0 ]6 k. z9 B
vItem.dwItemId = 0xffffffff;4 t; B6 S* @) u* g/ }
vItem.nIndex = i; t+ f5 J5 q6 i$ W
}else {: C+ |& Z' L2 I4 J& k
ItemProp* pProp = pItemElem->GetProp();1 M8 S( y3 x' `' j6 _ a
vItem.dwKind2 = pProp->dwItemKind2;6 I& M# Y7 Q4 U2 G: F* @- x
vItem.dwItemId = pItemElem->m_dwItemId;4 @1 v* G8 e5 W1 J
vItem.nIndex = i;
( @8 U! k2 Q/ ]% ^. n- V }& u* [7 r( S/ C. P+ m# A& L
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
4 c+ K9 t' i8 o' H/ M! ^: X }7 ^9 Q4 P. j5 z8 e" F
//////////////////////////////////////////////////////////////////////////$ |, r: S( T$ n& T4 I. [( @
sort(vItem.begin(),vItem.end());//排序
6 o8 o$ Z# L0 k' f* W //////////////////////////////////////////////////////////////////////////5 O, |! Z: ~- P ~
//交换: G% k. c% z" e5 t; ?5 C
for (size_t i=0;i<vItem.size();i++)$ s( p' Z0 o3 q8 i ^( {
{& N! b3 b( ^0 |
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);8 R1 D$ b6 L P5 J6 P, A
pInvSort->Add(vItem.nIndex);( { P$ X( A% L: v5 x( L
}
5 {" B2 \; y/ H* G BYTE nDestPos = 0;
K* }, G& y1 ?3 D. g' h* m3 G2 s2 {8 Y for (int i=0;i<MAX_INVENTORY;i++)
$ L9 V2 J( v4 ~7 `4 N4 N( d; o {
3 E' ^: @0 C1 D3 ^ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);( W. e6 b/ E! T/ {/ Z [
if (pItemElem)
! V9 E+ @& ]+ X% }- b% w2 u {
8 E2 M: k9 |# i: q% U if (IsUsingItem(pItemElem))) B [3 R5 q* V% ^* O5 _
{
# v) k& k+ r+ }. h* o* Q. x //这个位置无法放# L% z3 }4 P- z; l+ P
nDestPos++;
8 J" c5 w2 \5 E: j3 I }
% z$ ~8 n5 ` B8 c9 A' E }
& ?6 Q" r7 l& Y' T w0 @! y BYTE nSrc = pInvSort->GetItemSrc(i);
# p0 @1 Y. Q1 `# g pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
4 j& F- K0 y# q# _ if (pItemElem); L# R3 V" z4 S# z% Y. s9 T* H7 a
{
. P2 y: |2 |# O3 ` if (IsUsingItem(pItemElem))% b& D) q9 ]4 e; F5 Z7 {7 {) P
{
* K8 T8 S% k$ }9 s5 ~5 R //这个道具无法移动,跳过" Y6 o) m- @+ X4 }
continue;
S( Q5 \# c. O! {1 C1 Z d }
2 V3 d7 T+ L8 D3 q! m7 G }else{
: h, r5 m/ x, l' P //空位置 不用动
( P! s( e- _+ Q4 A" q9 h0 g continue;
. N# L1 ~( ]9 t4 Q d9 s } b2 h& P. {, B9 i
//////////////////////////////////////////////////////////////////////////
2 T. H0 K9 j' \1 a //开始移动8 Z% A+ {6 \' O' W
if (nSrc == nDestPos)
8 y0 ]4 b ^4 ?( X {' w8 z7 r' k, ^& M1 E5 X# e
//原地不动9 B8 A9 V# |2 C7 l" l
nDestPos++;( y/ \% |$ [9 C2 r1 N8 V
continue;
7 [2 ?/ }( F! R w ~ }
: s9 Y6 S) i- C, B/ n* ^ pInvSort->MoveItem(i,nDestPos);
& d1 q9 [( t8 b5 c g_DPlay.SendMoveItem(0,nSrc,nDestPos);% [( i2 @; j7 ?& p. j; A9 D
Sleep(5); I; t- O$ Z5 G8 ^' D
//Error("移动 - %d->%d",nSrc,nDestPos);" ~: O+ b! d" e& V; Q& @! w" N
nDestPos++;% C3 j% l4 P/ f
}! ^- A( n4 ^6 c
//取第一个元素的信息5 k* n8 ]$ R' l( s' I! o
/*5 L% [7 p: u. j+ H: v
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)$ M9 o$ j! ]7 @! X
{
; c3 Y3 Q2 P J Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
: n* E7 @/ ?3 } g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);! H0 @% _! \+ x9 L0 s9 H+ T
}9 t, [, _' u+ O+ C% Q
*/* Q) g$ z9 w7 j& h& R) B9 {
//////////////////////////////////////////////////////////////////////////
" \4 k" S* ^: S9 s8 v4 v break;! {; ?. o5 R5 O$ d3 H& R" B
}6 I4 _1 L) E1 B9 d7 `& O
}
' k( m1 f+ s5 U}
7 _6 L M6 {" v' o% M- km_wndMenu.SetVisible(FALSE);& ]/ c/ [. [- G: t/ R y
# g* J; k# H7 E5 A! R
--------------------------------------------------------------------------------------------------------
& I2 w( b' `6 U- z) E; Q搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
7 q& l# h& @& p- \/ V7 v{
+ X9 N6 y' F9 Q: w; |4 ?BaseMouseCursor();
* \5 V2 _( x c5 \+ h}+ Y2 _! @" U8 T; H
在其下添加:0 C: B' M# ~5 _" p
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
1 `& m! F4 U+ k{
6 E+ f* W9 I, em_wndMenu.DeleteAllMenu();% o* t+ x( c- Q; c7 S$ }
m_wndMenu.CreateMenu(this);
7 C/ k( s! u9 V+ C0 Cm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
; @7 W; M# s8 w5 S- t! I. t- q. W
: B/ V4 |3 @1 Iif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
8 c* m' ~/ `. ]) m{
2 W5 Z0 |7 u& U- [" H8 [ //P以上级别才可以删除所有道具
+ b% M$ X C$ y+ |6 W) U m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");% h; f* s4 t% Z. {. _
}
! h& m6 a! ~$ }6 k# z1 om_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );: p/ J1 z2 n! c4 A4 s6 `, U
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
1 R' c Z, Z3 |1 Gm_wndMenu.SetFocus();4 `# D$ N$ y+ M# y
}! Y. y' v3 N. }$ L0 v+ I- R
------------------------------------------------------------------------------------------------------------
$ ?; m/ u) ?. e9 O( v*************************
: S5 P1 f# P& KWndField.h文件
# |) d: W0 }' r$ g' @0 h* Y3 s/ I*************************
. q! o. |$ l: d搜索:BOOL m_bReport;
+ J# h r, k# \8 v% H) S其后添加:0 p1 { M9 v% B/ e$ ]2 h
CWndMenu m_wndMenu;1 v5 t. O) w( @ f F) q! L
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
1 E0 C7 g; Z5 g+ M* o, g* \其后添加:# k! Z& M( W+ E8 R
virtual void OnRButtonUp(UINT nFlags, CPoint point);+ D$ G) A9 ?+ x! B9 y' L$ L7 J8 {
4 b/ {: z% K0 u) u9 I4 v! ^3 X6 U: l+ r; s5 d. `6 ?& X
|
|