|
|
源文件中_Interface文件夹下WndField.cpp文件' v+ y0 e; i z5 E: Q$ o
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
+ T1 m1 `) E; g7 [1 h; G0 E7 J6 s+ J8 N4 k
struct sItem
/ m0 S$ m& W s _{
: n ^! u! _- B# ]8 \0 mDWORD dwId;
* z1 i+ z* |2 u6 B+ i, }5 VDWORD dwKind2;
( w* p8 X; i! Z6 EDWORD dwItemId;7 N7 P8 O/ B& `6 f' l
BYTE nIndex;
6 n4 C2 }" y. P) Q# m2 lsItem(){5 M0 T, e z5 k# t$ V) E2 \
dwId = dwKind2 = dwItemId = nIndex = 0;
! O# Z! G7 y! F7 G0 {0 W! i}
: j) e5 H1 A' ], ^8 @0 }2 `9 k. vbool operator < (const sItem p2)
- Z( N- n+ ?/ ^& E* D{
* }& f6 O. h9 f. k if (dwKind2 == p2.dwKind2)/ w- C# O: P* [4 j, t
{
* {8 t- Y' x- a( L( j) d6 k return dwItemId < p2.dwItemId;% X! M8 A5 J) d4 D- r1 f
}else{# a) j. a/ R0 D( f9 o
return dwKind2 < p2.dwKind2;
4 ?& l$ [/ i7 s }
; d' z7 @* w9 c0 V. Y, w; B}+ W/ I" S8 M" {1 m2 _7 t
};
5 M/ z; a, W* ?2 u2 F: bclass CInventorySort
2 ^8 N1 c+ \# e{
V7 C+ s! T$ Z1 spublic:
' l: _. W3 \& L+ U, f$ FCInventorySort()+ V; d' t$ j( _# v
{, y" X) T4 U* b f4 e" x3 w
m_dwPos = 0;2 t2 M v9 a& G7 K$ i2 e
}
3 P6 w! i; W0 }- w~CInventorySort(){}
- n, k" {. A/ t# v9 mprivate:4 J! ]1 n }5 J" V4 m+ h2 z' A
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息: C+ k6 i H4 J7 V' s; V) v
DWORD m_dwPos;
9 P2 Y& O5 \. Y0 Y1 ^public:: A- n2 X, p' y: v+ h
void Add(BYTE nIndex)
( C! L7 t. X" u* I{4 r. \( U; a9 q1 y" L
if (m_dwPos >= MAX_INVENTORY)
$ [/ Z, s* @+ F$ H* B) C+ j {/ k8 n3 {* {6 A! ]
return;
5 ^! A2 r+ T+ \& {1 B/ \ }/ n+ g7 U; a/ l) e& b) n
m_Item[m_dwPos].nIndex = nIndex;
3 I+ b* u4 b' d& C; ~+ A5 O m_Item[m_dwPos].dwId = m_dwPos;
4 i; T! r& x" U H$ g' F m_dwPos++;
# B7 K- C& c# |: z) Y}4 m8 y4 g+ z1 b$ f* C% b8 _' f) n, _
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列5 E! y5 v, Y3 K: ^7 u
{; l0 N1 |+ G/ |$ K, {5 @4 r
for (int i=0;i<MAX_INVENTORY;i++)7 [) x+ o4 u: Y8 l& [
{
8 T `) p1 s8 K1 x6 E if (m_Item.dwId == dwId). ^0 Y$ e4 q1 X, E# |2 r
{ U& d: Q7 u/ P0 F& L
return m_Item.nIndex;
/ q+ C3 _! q$ ~1 d }# F1 Q4 Z% n) z& y; _+ y' O
}
0 V( d* D: B# T( f3 H, P n return 255;, g; t$ k2 o0 P' z% E
}
) \* w: D' `+ Ivoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置" T6 P% Q0 h+ |- _8 s; X
{: j1 V8 {6 l( q/ e! Y
BYTE nTmp = 0;+ l2 l; q6 E4 Q0 V5 x
bool bDest = false,bSrc = false;% `" v( e+ E9 D5 z5 N* O; R2 ]# g
for (int i=0;i<MAX_INVENTORY;i++)4 | y+ K( C# Q" J# q% N) B
{
5 ?% \/ _4 V1 `, x if (dwSrcId == m_Item.dwId)
# G8 {; r% ~0 j {
" `( }# S& {7 v" n3 m9 w //id相等 则 改变对应的dest和src
( Z6 ]1 G- E9 E8 P nTmp = m_Item.nIndex;
: ^ t, g) e! s/ [0 C$ F m_Item.nIndex = dest;- \1 o5 |" D1 M% a- n3 [! ^9 ^
}. D4 D7 K3 G. ~
}% P5 U) x) j2 M2 b+ n. Y( {
//临时数据保存完毕,交换开始 N& u( [2 f* r" M8 H n
for (int i=0;i<MAX_INVENTORY;i++), W- F$ z( w5 Q6 |% b+ Z
{
* W: [, A9 D3 N, x) w: S if (dest == m_Item.nIndex)/ g; g4 x C2 S$ d
{ j8 d R" k4 p5 u
//id相等 则 改变对应的dest和src
* }& }' m! p6 I/ S m_Item.nIndex = nTmp;; o5 y- L; `4 {* @: G$ W
}
! T2 |# }$ E1 |2 p$ B } Q) l8 e! B- r \# c8 b
}
- m1 q4 Z" X( j) ]& S$ H};7 @4 ]: Q. ]; r' ^' R$ \: T4 L
-------------------------------------------------------------------------
5 g7 F7 {. J" g, C; u依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
0 H$ I$ z- E6 W, B L l搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
* L- H( ?4 J0 D紧靠其上添加:
4 c( z$ z4 o) C5 p% y. `/ Pif( pWndBase == &m_wndMenu )8 Y* B9 U* i6 a7 e7 O3 C) D
{
& M5 X4 @2 N, ~; @ switch( nID )4 K' E5 b2 o/ e4 ]8 E' l
{4 F6 E( H# e: D. ~2 T
case 2:
" v2 z; I- ?# i- M# C# J {
: g$ |3 H* h8 D7 v8 S9 i //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
, H3 r' ^' K/ L5 M9 e1 Y$ n# b if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))) N; N+ a9 I0 X* v1 G
{
1 J. ]% I1 L- E j: \) e break;4 ^6 q/ U4 H* J5 n$ G4 s
}
: U% P; X D6 n6 w8 }; R for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
4 f3 n1 x+ J- [3 v& |$ D {3 G: M0 p s7 ?6 a: ^/ N/ y
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);, d2 h/ T9 y6 q* B
if( !pItemElem )
9 ~/ X( J" o5 H# } continue;1 U% X" }; L/ [8 w' [* L
if(pItemElem->GetExtra() > 0)
$ v4 @' w: l' L0 E# U continue;
. y6 o* D' Q' D8 u if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 3 y |" g% h4 |1 n/ [5 P8 g) I. y
continue;, c# z0 |- `7 m3 [: A; {
if( g_pPlayer->IsUsing( pItemElem ) )
- c0 h+ Z* p0 V' j. } continue;
z! c; a" ^9 }8 O if( pItemElem->IsUndestructable() == TRUE )& E. f+ @2 W! C9 z1 b
{9 A) e$ `: p u0 W" F
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );# {! M+ z6 j* t7 R6 }0 |
continue;
" k s4 S- `7 s" [5 @- ~ }
; `, d1 d% z$ y* q P, U8 _* E% b g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);" i7 ~/ `/ F8 k. h
}0 j- G2 F U Y
break;
9 _7 T2 B+ r$ g* _" h }8 O! @5 \" w7 y) ~8 k* |' Y5 Y G
case 1:
2 q8 ~& u/ V- M' ?% F) ]) h2 n: h {
1 a: i; W" w; y7 A! ]* T7 f- | //整理背包
7 r2 [: L' ~" X: ?0 x$ N1 [ //////////////////////////////////////////////////////////////////////////! Q/ @% D/ f+ f# _1 t7 K3 T
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
) Y2 g; z' O, r //////////////////////////////////////////////////////////////////////////
# j3 n0 A" H, J* a y% ^ //////////////////////////////////////////////////////////////////////////. J6 x6 L; U5 _- {* w T
CInventorySort* pInvSort = new CInventorySort;
8 }# Y' ]1 U s9 L0 t# p6 V Y; Z vector <sItem> vItem;
; j3 U' e r" @ vItem.resize(MAX_INVENTORY);//初始化大小
* V6 l0 e; w7 p7 d1 A //////////////////////////////////////////////////////////////////////////2 O# H$ r$ N2 _7 P
//填充数据! F1 u2 c, n6 v! e c0 l
for (int i=0;i<MAX_INVENTORY;i++)4 U( X( T8 n& X
{
# ]$ `1 v" N: r% s0 P! T CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);$ Q7 F f" U9 E- r5 Y2 f
if (!pItemElem)) u8 \1 ^% U7 u9 U5 h2 e& b
{
: p9 K8 ~, D/ a2 o! c vItem.dwKind2 = 0xffffffff;
1 D9 i9 c# w: W# q- h9 U; x7 T vItem.dwItemId = 0xffffffff;2 F! \9 V \9 ?3 d& w/ c7 T
vItem.nIndex = i;6 r6 F# {1 @& w; k5 O& d: C
}else {' h+ u3 L5 J8 W# ]& z- J
ItemProp* pProp = pItemElem->GetProp();
$ g3 ~2 M+ ^1 q* k8 J vItem.dwKind2 = pProp->dwItemKind2;' B8 [. h2 n) p
vItem.dwItemId = pItemElem->m_dwItemId;
0 @1 Q# I; ]8 f2 I9 }, ~7 M vItem.nIndex = i;2 Y! T: v( T2 H& w) v9 ?0 R
}
J1 u: H( P# O u5 @. ^* m! ?5 k //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);7 f; M# i3 O7 p
}8 R c% j( v! I; O" L, d" v; S
//////////////////////////////////////////////////////////////////////////
9 \5 x/ p9 y- D3 K% |" h) Y sort(vItem.begin(),vItem.end());//排序
) S0 E9 w+ x2 O' [( j //////////////////////////////////////////////////////////////////////////" L6 v6 x( }6 H7 J
//交换/ O. n! P* M: K/ `: G2 E% V
for (size_t i=0;i<vItem.size();i++)/ q; E& T! x/ u& H! M3 ~
{/ q5 h1 \4 \& p8 T4 b
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);' I3 S4 c6 O( e2 k- ~, o6 [) R
pInvSort->Add(vItem.nIndex);- o" V2 r: Q# N2 M& R) s5 ]- @
}
% T7 ~0 p0 F* t! J$ j. ]( P* i BYTE nDestPos = 0;
7 m0 H: O c7 k- `1 G for (int i=0;i<MAX_INVENTORY;i++) S- y N7 j2 K# a% K; l5 A
{& G5 x- p. E; d+ T# H0 V( O
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
0 r) t! Q( Q' @- p6 h if (pItemElem)* O6 j' M: t( \* @$ v. e
{2 W, f4 _: f* @. r; W+ @: R8 P0 q
if (IsUsingItem(pItemElem))
* |. b, H3 k3 d9 g, e4 w* ~: V {
7 Y' M" ~, T, o# [# d! |6 o9 B //这个位置无法放
3 J; E1 x$ X9 J+ y" v) _9 C nDestPos++;2 L% O9 `7 N3 N" _# A6 L: v
}
2 p" V8 o) R- I1 F9 R/ L0 q }7 C- \( A6 d" Z& H9 ?
BYTE nSrc = pInvSort->GetItemSrc(i);* P/ Y ?# O' B( o
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);2 X2 l, G g' y2 ?
if (pItemElem)
6 M; b5 ]# L0 a { @( B- i' Z$ @ ?
if (IsUsingItem(pItemElem))0 Z. T6 M9 ^) V
{
7 [6 t7 h% F) i& l, ~ //这个道具无法移动,跳过3 X4 d2 g" z! A, L H; }
continue;# D& T) T: o2 l) Q4 b0 w) x/ _
}$ B8 V: c/ V) x% J8 _5 _/ C
}else{9 X4 j8 Y2 l1 W2 `
//空位置 不用动
y9 x+ Q2 ~6 h: J* G+ @9 O continue;
0 m; ^' r* D/ D( M3 P) ]( } }6 p5 T8 [% E5 S8 j' r0 k) a
//////////////////////////////////////////////////////////////////////////
( C- O9 y! g; v1 [ //开始移动
# f2 {. U( o4 k- O* q if (nSrc == nDestPos)
8 x) T1 U* @5 f1 M X3 h$ w {- l* k) `; l% i+ X @
//原地不动
]$ \8 i9 M$ ^' l nDestPos++;/ c4 L6 P" m) U3 S4 C7 u$ q2 m
continue;
% j) _6 v! P5 Z0 [" ` }
7 w2 P% l0 H9 c1 _/ X pInvSort->MoveItem(i,nDestPos);. U# ~4 ]& Z9 j
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
0 s( M8 z6 f% d3 G; m, H Sleep(5);: g9 H1 k) q& R. b+ Z( [4 [. J0 X
//Error("移动 - %d->%d",nSrc,nDestPos);
/ P+ e# _* G6 z. n nDestPos++;
7 O, C) t1 r5 L1 S+ z0 x9 B }/ r) `/ C3 e/ w$ v
//取第一个元素的信息
) o0 l) N T, C9 G/ p' B- I /*
% s1 o6 n( {6 V3 b: J/ t if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)( x+ S; U' ~! r: g- l6 G& F) |
{( z& ~; `, X: ]; B& J& s- a
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);8 u9 T/ Y/ Q7 Z5 G3 @/ ]0 [
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);8 w6 b( K2 O* [, A" x
}8 }+ ?* j7 `6 o* K9 G6 {
*/
. f) S' T. y$ v //////////////////////////////////////////////////////////////////////////
9 d) ~: o. Z% j r* e: E! C. J break;
# R; Q" K8 D* {1 x. d }' z0 `% b8 O, ~) k1 ^
}
9 o1 k# Y+ f2 S7 D% X}$ t% T* w9 Y% S: Q
m_wndMenu.SetVisible(FALSE);; ~# ~1 W2 M: B c: L- O
) h8 ~/ S3 h+ ?! W. A2 {--------------------------------------------------------------------------------------------------------
& B$ ~( a O6 O( Q搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)* e' f/ F8 m, `; ~
{
* O3 c( [# K c* PBaseMouseCursor();3 w! A3 l% U+ L$ O# U+ s# q; L
}
& u. R2 v+ B. X* }1 c9 h在其下添加:
7 |7 }. j, S( K0 ?. ?# g" gvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
3 o7 _# m1 a! ?4 e{
: m0 g+ U) S B5 Dm_wndMenu.DeleteAllMenu();2 d/ `" Y3 r( w* w5 D
m_wndMenu.CreateMenu(this);' I, L! d' U2 i! p7 C- W
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
, N# f6 i3 U8 l# ?. G/ J6 \
x# Y4 X. v8 h3 Gif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
$ w& A; E% ~* N! W' D& `, }0 M{1 K; B* q& W V$ O2 L' j
//P以上级别才可以删除所有道具
8 G5 i* v7 U! K/ ^3 D m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
2 c& Q a* @, Z+ ` [1 S Z) M}
& ~4 ^+ _" c3 _0 @. ?! Bm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );: w4 o2 F) P8 w* |( \" ]7 m
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
9 G4 X; X: f! V( R, D( V/ w9 r0 Sm_wndMenu.SetFocus();
$ d- t. @$ p& Y' m3 }. t}
, [2 x3 A6 o( a; o2 E. a8 p------------------------------------------------------------------------------------------------------------
1 q8 K7 T* j7 V3 U*************************3 j, W1 P. L1 T) L' Z
WndField.h文件. d: J1 \- X+ C
*************************! F5 l. t6 x8 T) k/ i- @
搜索:BOOL m_bReport;5 t3 F( I) h6 j/ @" O" r$ t; S
其后添加:+ p+ Q# J% k- [3 P, w! E
CWndMenu m_wndMenu;& m( p8 G% x8 A% y$ u- I
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);/ G0 B- u: z& i% f+ K
其后添加:
8 H' a Z6 B$ V4 b5 ^4 u2 Cvirtual void OnRButtonUp(UINT nFlags, CPoint point);
0 M) J6 P2 X! `
7 b& L" x- w+ h% N- S, O- I2 [6 h' u& |" j6 Y
|
|