|
|
源文件中_Interface文件夹下WndField.cpp文件
1 i, p+ b5 `4 i0 k8 u! E( C E搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )& t) W' k* E% r: a9 } m
, k$ V( H+ R, @" c# H( D9 jstruct sItem1 i$ G" b; y* v5 |, J9 K
{
# M. ^1 o8 \0 I/ w8 J+ a& w3 dDWORD dwId;
6 }+ C& I8 u. W, ]( _2 i9 \DWORD dwKind2;0 p! g; G+ B3 V! j
DWORD dwItemId;9 N# t! ?5 x, D6 a! S
BYTE nIndex;
/ u8 {3 o2 F3 v6 wsItem(){
! _. Z# ]. O1 Q$ j3 F: g dwId = dwKind2 = dwItemId = nIndex = 0;
$ k5 P$ m/ q: O: F# _* k}6 ? Y+ ?& e$ }! x7 T y
bool operator < (const sItem p2); ?+ v r' o7 e
{- U1 Q3 z; L0 a7 V1 X
if (dwKind2 == p2.dwKind2)
8 q$ y( ?6 @. r0 n( B {
8 G, t1 P/ ~! v8 M& y return dwItemId < p2.dwItemId;: n, u3 H; L( {- b0 \
}else{
. f( C. l- A) K- a% a4 s return dwKind2 < p2.dwKind2;
' I$ O1 r# ]: H7 S, ], | }
4 f5 d) d0 n4 O/ \, g n' @}- `+ U1 O9 h1 p! ~
};
L- y# m' l. l3 D9 oclass CInventorySort, l% D e9 ]9 N/ u, D$ L0 g
{
. o ]8 M) h% \2 {4 Zpublic:
/ Q- D5 q4 v8 n! gCInventorySort()
; r) Q. N3 b% I3 d{
6 b+ ]) ` X2 Y' k9 M0 K m_dwPos = 0;
7 c: Y6 Q W! Q8 l$ a& n/ K* l}) ^: `5 q& s& n8 I' |' } T
~CInventorySort(){}6 |$ U. G; G. ?
private:& Q! Y6 q$ n& P( o5 H6 n
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息& O+ ~# x$ u& @# f! d
DWORD m_dwPos;# m# v- S" Y% K) B2 D5 `; a
public:
+ ~1 O6 o1 m' S0 R, g; B) Dvoid Add(BYTE nIndex)
2 \ u/ O6 i8 R5 `1 X% K{, Q4 b! s7 t4 b- T0 q/ ?' L
if (m_dwPos >= MAX_INVENTORY)+ y8 p4 ]* W, i: f" @0 l! J# n# N
{$ ?* N' u! f, D+ ~4 r/ f
return;
$ Z0 R6 d( t0 P& K0 _: d9 E }
+ v) k0 D+ ~ G6 v) X$ ^8 X m_Item[m_dwPos].nIndex = nIndex;
$ K; F7 M" w% } ~ w+ r0 ^ r1 b m_Item[m_dwPos].dwId = m_dwPos;- ~" M9 D% m8 z" ]
m_dwPos++;
# \$ m- n) `, O+ R' W}
* i) W1 L3 [/ H1 z* F! ?BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列, b# S8 D7 H0 q& {1 c0 L
{
9 }3 v. Q: [( U+ |0 a8 H for (int i=0;i<MAX_INVENTORY;i++)/ M2 E. j% A: X
{
9 F+ O, B0 Y( F6 t if (m_Item.dwId == dwId)$ f% a, o0 I# R& a9 j
{
* q( `1 j- ?/ }0 o4 G! ~ o$ A return m_Item.nIndex;
4 U* X7 o7 M C4 C! J+ K/ e S. v }
, U0 r0 A/ }* X" l# ~/ k6 C0 V- p }
( g, V; r% z2 Y- M return 255;0 O; L0 Y2 @: ]( z2 j- X
}, e5 ~6 L7 d( y
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置/ W% O3 q; Q& Z* m) ~, E3 y
{# K% U5 a( O. s$ i4 d% Q
BYTE nTmp = 0;
% O2 J* ?$ E/ G1 e0 V bool bDest = false,bSrc = false;
5 Y9 }& P9 g! F9 F! g for (int i=0;i<MAX_INVENTORY;i++)6 g8 n. f5 F& [
{1 |; D0 o, I, c2 [, P }( X
if (dwSrcId == m_Item.dwId)
+ V: n$ G7 ]2 s7 l {( K0 @) p; g Q' L4 z
//id相等 则 改变对应的dest和src T: Z3 Y' D- Y+ d7 Z
nTmp = m_Item.nIndex;7 |. R& r7 \- j2 G; U4 Z3 q( |
m_Item.nIndex = dest;5 O* `3 k+ A [( O5 t
}/ f% ~8 P; ^$ ~) G* _1 r
}
5 |+ l6 n+ f- B% j //临时数据保存完毕,交换开始8 F0 F( R3 H9 v* [1 |8 I' ]7 R
for (int i=0;i<MAX_INVENTORY;i++)! l3 B$ `7 ~) J% j Z# w+ ]/ f
{0 l! d& K5 Z! y/ [& x
if (dest == m_Item.nIndex)3 s; B' Z' A: Q+ m* X2 [- ]9 Z- y
{
. i+ y' G, Q" @9 D' N //id相等 则 改变对应的dest和src" s2 u/ t, o2 k* l( u; d
m_Item.nIndex = nTmp;4 O8 O$ e; W, d/ R9 _0 D. {0 t
}& N2 Z5 L9 N! K9 W, G1 j1 ]
}
+ l2 ~: ?5 g9 t; I) X/ s' b}8 g$ g8 D) i! E, C o0 I% @
};- F7 y- `( A3 @
-------------------------------------------------------------------------
6 ^/ b% e+ _" Q. s7 s. z依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
8 \+ n t0 d* U; O* d0 T搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
5 u* [8 R/ i! }; }' Y& ?% c紧靠其上添加:% d, ?0 W9 a8 d9 h. V# n4 S
if( pWndBase == &m_wndMenu )
/ x" B% u& r% H8 i5 E' Y9 x{$ g }6 N9 q g8 ^! q* g
switch( nID )
/ v* D0 c' {) `7 D! i9 f {
4 j: S5 h: u' t( i case 2:
% T6 @3 J9 G7 L {
' H8 J% |5 b; d' r2 y$ h //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
" \6 I( k; ?% T `! t" v7 n- ~ if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
+ m, g7 t* E2 |5 c { Q; o% W) U8 \; R( H
break;
5 l. Y1 N. q5 F; `/ Z }
( B Q7 X$ h/ z; l" c% z for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
6 }" \9 M0 N3 C3 |8 u {( D* Y' ~6 n& `/ U2 ?; b
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);1 |; M/ B0 P3 |' Y1 ^5 `
if( !pItemElem )
, z- z* y8 n1 Q8 E3 } N6 a- i continue;
' Z5 I$ v$ Y! F; d0 z5 L& I" V6 _ if(pItemElem->GetExtra() > 0)
- f- K0 N' n8 d continue;
) |. |* _1 b; Y. H if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 5 S6 j6 D4 B; N+ d" i1 z
continue;) [; O- x! @) _0 D0 Q
if( g_pPlayer->IsUsing( pItemElem ) )
9 n2 Y W1 k. n1 S9 x% t, f continue;
2 ?. e5 g. d+ z4 D if( pItemElem->IsUndestructable() == TRUE )) k, v1 c' a* L" p
{
. u& ]8 F |& S, {2 G9 W g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );$ M1 X& j5 S) W) r/ k
continue;2 D8 _1 r1 I4 g( l9 Q- [' s
}
9 s; ~' E" ?1 E3 K+ k g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
/ v( _) [* T' U8 r } b7 ?3 @; Z2 i/ o
break;' R/ F1 b' |$ T1 _3 W. S6 z
}
# W" F9 |2 k4 p5 c# k3 R' I v; J case 1:% k* K- }" ^* `5 C) ~8 y
{
1 D+ @$ u% P$ m I //整理背包3 E6 ], ~) l# Q# d k) |4 I5 [
//////////////////////////////////////////////////////////////////////////
2 R5 K" A, h: Q- d //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
3 S/ x' K( o1 M //////////////////////////////////////////////////////////////////////////
1 J P7 w7 {3 r7 v //////////////////////////////////////////////////////////////////////////* e4 {3 E% T( \4 \" c* s0 @
CInventorySort* pInvSort = new CInventorySort;
) _1 m$ Y/ X1 j# } vector <sItem> vItem;# T/ \# [8 B9 a* d
vItem.resize(MAX_INVENTORY);//初始化大小; _" r" i! M9 @7 R1 `5 [2 ^
//////////////////////////////////////////////////////////////////////////
; k2 k( K9 q7 r7 W v7 R //填充数据( P) ^' o" k7 g1 g2 }5 {; o( A
for (int i=0;i<MAX_INVENTORY;i++)
. u2 h* [, A z( b+ w {
4 s% w7 J8 } l* _ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);$ P/ M- i4 r* |! T/ j$ i- d
if (!pItemElem)
" x& q4 l" v6 o, u {
* S7 E$ @8 y. Z: A/ n, ? vItem.dwKind2 = 0xffffffff;
: q0 X& H% p3 b* I4 F% a vItem.dwItemId = 0xffffffff;0 r3 H" M( q( \+ S
vItem.nIndex = i;
5 ~( W p5 C% y6 t! c' ^) e }else {
) `% y- I5 e5 I) A+ L6 x ItemProp* pProp = pItemElem->GetProp();, y) R$ x' w% t r% h p
vItem.dwKind2 = pProp->dwItemKind2;0 \& U& J: O% p. h. ]1 H
vItem.dwItemId = pItemElem->m_dwItemId;* g0 ]: T3 a7 C3 @; N3 M/ Q
vItem.nIndex = i;
2 _# Q [1 w2 ~- Z+ r }
& i7 A8 [* C# `0 P B //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId); P } s7 X" b# X% e0 e) @
}
6 n; `% C* K( G N# U U' S //////////////////////////////////////////////////////////////////////////- P$ W, S2 M4 z1 X2 o a
sort(vItem.begin(),vItem.end());//排序
: M7 r: |; v* o! e: V //////////////////////////////////////////////////////////////////////////2 q6 d+ l+ J1 |( g9 E
//交换4 H0 ~8 D: z5 x L* K
for (size_t i=0;i<vItem.size();i++)7 n6 [1 A$ B; M9 {5 U L6 S/ b
{% v: \' R* q! K' |/ M2 w" E$ j
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
5 @! u7 T3 x, m1 E) X; F/ Q pInvSort->Add(vItem.nIndex);& E& g: A0 p* n" `2 i$ j( z+ d
}
' B! Y/ R) s/ P5 l9 ^& @. K BYTE nDestPos = 0;" _' @( J) x9 L" f
for (int i=0;i<MAX_INVENTORY;i++)
: X2 Q2 [+ r$ {! N1 x( W+ n x { o8 i3 L% T0 r. T, K t6 L( ^
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);# q+ t" k3 V) Q/ H9 T. T! a
if (pItemElem). t& F- d) f1 v+ L( l4 G9 `, v
{
5 C( y2 V# {( i3 P* Y* N- }4 r if (IsUsingItem(pItemElem))# A2 a1 I( P0 ?/ ~: X7 [5 U1 ~& T
{, j8 M' k, M! V- H9 M3 J6 O& v V+ \7 K
//这个位置无法放
6 a+ F8 u5 m9 h nDestPos++;
% W) d$ @+ f1 w1 u' J" }- Q# R }4 ^. W; { @: p" x$ u
}. ~3 n/ J: F8 I/ V# S4 F
BYTE nSrc = pInvSort->GetItemSrc(i);
4 c8 k4 u' L4 [ pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);" }" p$ E! h, c) P5 S
if (pItemElem)8 Y, Q6 ]+ G! \5 L
{* \7 D" B& V. ~# ?
if (IsUsingItem(pItemElem))% R4 h2 |: V3 `7 ]. s* y) r7 f1 x
{% ?5 }* M4 H$ ?$ Z& U1 s
//这个道具无法移动,跳过
+ q) J/ V ^6 ~. Q7 M- Z, f continue;; W$ R/ Z3 a6 {. Y! l( N; L$ X
}7 f0 @6 b/ Z. u0 z7 Z+ p
}else{; C$ z _- I b: E
//空位置 不用动3 e: M. B- d- ^5 \
continue;1 q. T( N! C9 ?/ g( j- b l
}- w6 i9 E+ T9 j$ S+ A1 H
//////////////////////////////////////////////////////////////////////////5 x' D3 I T7 B7 ^& h& ?2 A
//开始移动
9 y# C5 o# f F9 z if (nSrc == nDestPos)
8 @" ^, f0 H/ C$ H9 R3 l {
- q' b3 \* p6 @# K$ C) N$ f //原地不动! |5 i1 M$ {2 c; A* {
nDestPos++;6 ~/ c$ }$ c" _- d
continue;: K" {4 N( u$ {6 O* X6 J
}
4 c1 H% ~4 C, M) l pInvSort->MoveItem(i,nDestPos);
) l4 ?6 d2 o6 k: ^; z- ? g_DPlay.SendMoveItem(0,nSrc,nDestPos);
9 B- x( n) @+ Z" \* [% x5 B Sleep(5);2 ~) Q9 l! K0 W' X Y/ y
//Error("移动 - %d->%d",nSrc,nDestPos);
5 M7 F( e; W3 ?: o nDestPos++;
1 T0 a& q) l0 y7 L9 t0 l } d# H8 Y3 d; l
//取第一个元素的信息
5 x3 i5 A/ H6 S0 I' Q2 h /*' V ~& B0 n6 N4 h2 R
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)/ j5 A& {+ ^+ U" ~6 Z6 F6 m
{/ j9 L$ ]7 l. _( M! S
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
1 d0 B) j4 v3 N. x- P Q8 W4 Y$ W g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);+ Y2 _- e( d. s
}
' P" b6 l. T3 r6 Y8 {4 N- N% w1 L */" |& q% c4 n: h" z! a& o: K8 q. z
//////////////////////////////////////////////////////////////////////////
8 W5 Q2 a/ l4 E) ]) N; D' x break;
) a( r0 Z# A/ D1 V }8 q5 e; i% T4 W( e0 }- y
} - ]6 f" R& k; C9 c3 F% v
}2 c7 `! c) r+ [& D+ o$ h# v0 a
m_wndMenu.SetVisible(FALSE);/ |% r. G) W& K7 X# ^/ p
8 _0 z! T* \1 M# l5 Q3 Z0 X
-------------------------------------------------------------------------------------------------------- ]1 r u* @2 k+ l+ I4 I
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
) U& v3 k- N9 Z# e{4 N2 m6 v, r7 `7 t
BaseMouseCursor();0 y" o& a% D" Z9 I
}
Q# B) w1 j3 Y @" A* ~7 ]" k$ v在其下添加:$ y2 F* @+ ^9 t; F# B
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)3 }" b f4 C( M" j V3 H0 X
{
. Y: R8 r8 ^4 f3 X6 G3 mm_wndMenu.DeleteAllMenu();
" ~. X* H: T# i4 v) Gm_wndMenu.CreateMenu(this);
" Y9 k$ U) o- G1 Q9 G' km_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
- H# m9 _$ A: T& B
4 |+ {) ^* \: Z3 G P. U) Rif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
1 c$ ~/ F X4 X# @) ]) |" y y' J{( n Z& L! m+ y6 m: F3 Q
//P以上级别才可以删除所有道具; R- p2 S7 v( s+ ~/ e+ R0 Z
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");+ u0 J' n' W) F2 x
}/ U1 ?) K0 v* Z8 g( a
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );" V* ]& T4 F0 m; i% _
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );! r H) h- ^# e
m_wndMenu.SetFocus();% X |1 L, H4 T, R. s
}
& X* T, S$ Y0 w) @8 x h4 h+ k------------------------------------------------------------------------------------------------------------
" e5 i! ^2 j5 |4 B$ M w*************************! i: n3 `# D5 \3 Y
WndField.h文件
% T1 ]8 \; X! L- Y! _5 E' N9 w3 n*************************1 P; s% y8 z7 G$ D
搜索:BOOL m_bReport;9 Z6 R3 {9 w, f
其后添加:) h5 {% d: @+ O) t; t: ~3 ]
CWndMenu m_wndMenu;: l- u: }0 U% F' @# e/ Z
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);( l- _5 i) y9 F# U7 b
其后添加:" ^( h6 }/ E' J* h+ u& Y
virtual void OnRButtonUp(UINT nFlags, CPoint point);% i) I" }" |3 r1 u: h Z
: M" t: t& T4 r2 w) y: S! R8 A# T9 A1 x' S+ ]. F/ s/ S
|
|