|
|
源文件中_Interface文件夹下WndField.cpp文件! e- Z3 E' H8 V# |
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
6 |! C" N6 Q- I" e) ?8 f: E( a& U. m0 y
struct sItem, |/ ]/ _2 d( W5 K8 [5 Y1 H
{! s9 `7 s0 ~8 V8 y9 C) I; U7 q
DWORD dwId;7 U8 X) P* p1 F- x+ [4 o+ }3 e( k
DWORD dwKind2;$ b! y( a2 X. C# n- y3 a
DWORD dwItemId;
8 T7 h( |# A4 ZBYTE nIndex;4 m/ d }/ K. T) Y: N, v, V
sItem(){
0 U" L( B$ \# s3 J dwId = dwKind2 = dwItemId = nIndex = 0;. E+ X/ g+ k/ W+ q+ y
}
, r( b6 B" K' q+ ]. ~bool operator < (const sItem p2)
( C& d+ Y# \5 q* v- |{
' v, j) c v8 b( J: F0 J2 o if (dwKind2 == p2.dwKind2)
2 k9 J3 \" R$ C6 y* v2 D8 U6 u" q {* K5 v, \! |& C
return dwItemId < p2.dwItemId;
& K$ E9 C# ]) X- w6 ?# |- Y }else{& K0 E( x" T4 S" H! c1 X
return dwKind2 < p2.dwKind2;; s6 w. g4 q# U) i0 Z. f3 `, ^
}
1 D. Q; o; K/ T/ j1 V}& e4 n" t: }+ a( f* G/ K9 n$ r3 {8 ~# |
};
N! U6 f* h$ f5 [1 ?class CInventorySort
) K' n1 S& J6 D$ g3 L; d) G+ _{
2 d& }+ C8 k; f h- L# b epublic:
' F2 \/ Z1 G! D8 p& V% z; k' MCInventorySort()
$ W' q9 ?$ {8 m{
) R0 K& W2 f" |- Z! a7 s& \0 w0 [ m_dwPos = 0;+ N& O( p( D7 f2 x4 F" T
}' C% O1 \* K1 W9 G( P; c5 b8 @5 E, O
~CInventorySort(){}
5 n# ^1 f$ P$ n0 Q. j" W& U, I# n" R$ cprivate:
3 h# _- W7 K2 m" LsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
9 w$ B. W4 h8 y X0 x% hDWORD m_dwPos;7 |! p2 J/ }/ ]
public:. `5 e5 v6 M% f+ d: k5 a3 L8 y
void Add(BYTE nIndex)
5 |% n X- s7 u7 i{
' K( x. Y- Q5 E" n {. B6 [ if (m_dwPos >= MAX_INVENTORY)/ s# I$ l4 {- c
{/ c7 ?7 @: ?8 ^4 [! |
return;
4 Y& W% u ~1 ^ }# F5 ?1 C( \/ G! d$ K& g
m_Item[m_dwPos].nIndex = nIndex;
6 K& \) f2 H. [/ {, d& i m_Item[m_dwPos].dwId = m_dwPos;
# }- |1 E; J' x4 V! n6 ~ m_dwPos++;
' j# @9 {1 P8 M5 M}. \- Z% v: `. e3 a% E; B
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列- n8 l3 u9 [2 k4 `8 s6 C
{% b& \! K# ^) h; ~" Y: {/ A8 o
for (int i=0;i<MAX_INVENTORY;i++)# A# S" j3 k0 i& [$ X7 x' `4 e
{7 d- M, i2 \2 l( Y" f/ I
if (m_Item.dwId == dwId)
, z3 B( w( A' a0 J {! k* \- j7 `! o2 y) j4 L, h9 b
return m_Item.nIndex;
E: W# D, `' A5 D }
: o7 f" X R5 M$ B/ Y% W& R }
8 h1 t3 ^. M2 }- y$ | return 255;
3 P+ d6 [- o R}4 S! w$ F8 |, c
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置+ y6 V5 f* o* E6 t! ]4 i+ D# \* k
{ p5 M! @2 F7 w# ]
BYTE nTmp = 0;
! [/ N8 P3 [$ |) ~ Y bool bDest = false,bSrc = false;
% E l; m5 L' s# _ for (int i=0;i<MAX_INVENTORY;i++)8 E6 y' P7 Z/ @, ^$ {) f
{" V0 s$ K8 r7 r4 p% s
if (dwSrcId == m_Item.dwId)- P2 n# `% C' w( I9 f9 J
{9 Y* R: o& e- a1 u
//id相等 则 改变对应的dest和src! z! D$ k4 |2 g
nTmp = m_Item.nIndex;
$ p$ H& s, F- I m_Item.nIndex = dest;; b M3 ?" l3 [0 V# q. ]
}" d9 c' B( y. F. u6 F
}+ ^, c9 F) w% _& U5 N* J- _- h! l
//临时数据保存完毕,交换开始
$ b( z5 I; T. k2 m* g R& }4 ? for (int i=0;i<MAX_INVENTORY;i++)
* T: p+ c+ d- i, d7 N- Y {
/ o, Z, m: f, g/ Q if (dest == m_Item.nIndex)9 g$ A) u; u+ z6 Q- U. _
{
/ v( r) l1 \% D0 P //id相等 则 改变对应的dest和src
# @" E2 O4 W9 v9 ` m_Item.nIndex = nTmp;* a) w. y; A' V) {2 N# Y
}
6 J2 ?9 h# m7 s4 j Y) g+ X- Q* g% P }6 p5 ?5 A' g% z0 v
}
0 _4 }. b) V3 @) \};
. S) C; w) ~6 B* y" t6 O-------------------------------------------------------------------------
6 f' B( G& J/ ~6 O I% p8 V( A依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )# [- o, [- R( @5 `1 h
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);; N `3 v1 V$ X5 [7 S: F" _
紧靠其上添加:. g: f* B0 f1 t# {+ o: j' }
if( pWndBase == &m_wndMenu )7 W w5 G4 _8 w- h. L2 Z! \
{
$ M* q1 ? Z+ v+ w- `$ t6 e switch( nID )
0 c, j3 g) h( @0 G& H) l) T. g$ e {
5 Z9 Q% K0 u& J; y7 W case 2:
$ n, e, E7 G, x( b/ E" N8 { K3 v {, z* j1 I. v% f2 M
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);! ?3 v. U2 T5 {% i% a2 \7 D" C7 O- v# e
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))0 t) X7 i* x* F) x% K
{
" V) i% c7 i+ z3 y6 q break;
9 P. L" o3 X" O0 b j) F) s }0 I& [3 p' Q9 T
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
3 l4 l1 G* P( d ] {
+ Y- w V% K% }+ X1 s CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);4 {8 y$ l+ p7 r, Q5 F
if( !pItemElem )( m: y& }; j* w4 K9 O/ s' ]/ E
continue;
G5 Q) K+ k6 a1 s if(pItemElem->GetExtra() > 0)+ u8 ~; A9 n7 N# l0 ^, c3 f0 `+ @2 ?
continue;
5 ]8 Z9 w( ?$ R B# N5 E! Q if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
; z s( z* S$ }7 m6 b. |/ N continue;6 w, G! t E. U- J$ Q5 q8 p5 K- r
if( g_pPlayer->IsUsing( pItemElem ) ), }. f- i8 z0 Z7 z7 v- c
continue;
" _9 d* ~, V2 a% r if( pItemElem->IsUndestructable() == TRUE )6 K. {- f. L4 \5 v
{
$ V) @/ \3 l' ~ y3 R9 @ g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
1 i- G+ C/ Q$ T! E continue;* C7 B& A2 o' J( G" r; u* b% i* ?
}
. U1 `# ~' }8 k* O2 K. W& F g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);; y! U" j* t9 f4 T& X
}
3 c9 j6 C% u$ {4 [4 m6 O% Y break;
' X$ _5 S# G' ` \ }
2 I* D0 h3 S" O! K case 1:
5 U- o1 \! Q$ H& Q6 [ {9 J/ S4 u0 D. R9 d
//整理背包
7 P: X) U/ B4 x1 l) q //////////////////////////////////////////////////////////////////////////
" w/ a- Z# S% d# N //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );1 B0 A0 V. {) g; z' K
//////////////////////////////////////////////////////////////////////////; h" h) C/ _! J' T1 i2 |
//////////////////////////////////////////////////////////////////////////! o$ m3 {% r$ _7 {2 Z! Q
CInventorySort* pInvSort = new CInventorySort;3 a- k$ Q) u9 x2 T" m1 M9 i/ T
vector <sItem> vItem;* G+ Q, s2 L0 A0 v
vItem.resize(MAX_INVENTORY);//初始化大小
7 g9 q# R/ ]" a/ n //////////////////////////////////////////////////////////////////////////$ ~* f5 G: `3 K; _* R- K$ D
//填充数据9 _7 o9 }6 _2 _5 s/ S
for (int i=0;i<MAX_INVENTORY;i++)
5 ~: O5 Z9 l" b8 G0 j/ H {
% I1 `4 G6 {: I8 z. k- I6 F( l3 _ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);. q. U b( g' { c7 ` _
if (!pItemElem)
% d( s; x1 g. x0 n7 S6 f1 Z! v {1 W4 s& Z# A/ g
vItem.dwKind2 = 0xffffffff;
) _7 @. q# B0 X# w vItem.dwItemId = 0xffffffff;, m; g) v! l! c) a+ u6 u0 x4 Z9 |
vItem.nIndex = i;8 i! _. b( ^& q
}else {/ J4 f2 s8 m# |) r& O2 f) n
ItemProp* pProp = pItemElem->GetProp();
$ X0 e+ {; C, A2 w4 x vItem.dwKind2 = pProp->dwItemKind2;
y4 F& `# w1 y1 g2 t, K vItem.dwItemId = pItemElem->m_dwItemId;
9 f( H4 D/ z% W+ `3 T0 l vItem.nIndex = i;
0 E( Y/ V! {1 w; }9 Z& @ }+ U* `4 _& v: c/ I
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
; S& V% f6 s& |, y1 i }
% [2 C( I+ p1 ?# p$ [ //////////////////////////////////////////////////////////////////////////; k* P" C9 F0 e2 v
sort(vItem.begin(),vItem.end());//排序! W! X( K E- Q4 o8 p' F5 ^
//////////////////////////////////////////////////////////////////////////$ F# a; V" m7 l1 ]6 |' s
//交换
i1 T( b: n6 V/ ?0 U j for (size_t i=0;i<vItem.size();i++)
, c( I3 X3 P% v# P% y {) |" L2 Q' @+ N9 x& W# ?4 a& Q
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
! }6 J7 k. P0 N2 e0 m5 ] l% P" { pInvSort->Add(vItem.nIndex);! A/ i5 R7 @" V, ^8 X# V1 A
} E6 ]! ~" E, J6 ~- B- Q
BYTE nDestPos = 0;8 h, o& A) Q( }; _- N. R# u
for (int i=0;i<MAX_INVENTORY;i++)- Q* M# l' p4 S! n
{5 {6 v- |6 ~2 w- |( i
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);$ D* \5 g( N6 W, `' L% @* x: \# O) s
if (pItemElem)
. l; i, B& p0 K m {
4 L" P, p. B& j% K if (IsUsingItem(pItemElem))
8 g$ I5 E' D; P, M {$ |$ ~2 ]8 f3 z$ x8 C# J \2 e
//这个位置无法放
5 u: [2 V" A5 J ~& p nDestPos++;
" l' F, x% r9 x' x; w4 g" r: S }% R$ F7 _/ @; T$ c
}
* B* j6 S: ~4 `' _, y BYTE nSrc = pInvSort->GetItemSrc(i);
+ V1 A% @% q: f pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
8 A% W9 u" \) z if (pItemElem)( u6 ]: e% ?; @/ h3 i; E. f0 U
{1 u: g/ [7 j! E' [; ?3 J6 U
if (IsUsingItem(pItemElem))& [1 t% W( [: @+ E% g1 d" S
{: ]3 X. {- z; G5 v* X0 v2 V
//这个道具无法移动,跳过
% g% W: q, o @. I7 ^/ M continue;
4 ^& C( i% B& D; d# u) r6 R$ { }
8 K, r9 k. l h" ^" H4 W }else{3 B4 u) \8 O1 ?! K
//空位置 不用动
% G7 z: g: }, U( r continue;
7 |# D9 g. [) b% q: b- ` }
: f" U/ U7 } k% _( y //////////////////////////////////////////////////////////////////////////- @- y. |$ g' L; a( y0 Z
//开始移动. x- C t) |4 Z: K' V* p! l5 J0 F
if (nSrc == nDestPos)
+ I2 E2 c6 z! T6 O0 P {) t, z2 Q9 v T) K9 V: c. a6 y
//原地不动; x6 r+ e1 D; z/ Q- s$ p
nDestPos++;
/ d/ V) d( I* b7 ^# w: @ continue;
& G% O/ z) q! n3 {* c- p3 v }' F! G; B+ N# H+ N$ l
pInvSort->MoveItem(i,nDestPos);
! |- o: J. X3 Q! k; w* X1 H9 Z g_DPlay.SendMoveItem(0,nSrc,nDestPos);
: u5 x \& O" G% M+ Y$ y* Y Sleep(5);
9 y) h% S0 o* F! M2 t" U //Error("移动 - %d->%d",nSrc,nDestPos);3 {8 P+ `0 q. B/ H( ?) f! P, K
nDestPos++;
: ]% H& n& g+ z Y- D& p }7 e8 H8 K: _( w7 ?- x
//取第一个元素的信息
' G) A. n; H+ Q) ]' K+ u Z7 B /*- p* k1 i& b' I
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff). H( a! ^% [' b8 R% _5 x
{3 B8 z* J) B7 A0 b% S! [5 ~
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
& ~$ T. O# q" C0 p! h$ i3 y g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
8 ~/ x, b( v; R- T6 J1 X5 w }
& V) ^/ s; o4 \! n! O0 X; I */2 _" o3 ^" j9 t8 z9 C& z
//////////////////////////////////////////////////////////////////////////
$ u" n- M& I6 V7 x9 P, m: u break;+ H- u2 J3 `, E e V) {2 ^
}7 R% E- n% L( d& h
}
% B9 e4 l0 ~% P7 E) s( _: `- t}6 D: s! T8 W# B" Y5 H% k" ~! |
m_wndMenu.SetVisible(FALSE);
5 ~/ e; \5 b Q& @( E$ t3 N, Q
|! j3 M# q7 C! Q9 B1 e--------------------------------------------------------------------------------------------------------
6 P, y: A7 l4 n搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
1 t' g Z5 \# `{3 v- ?) L G, R0 M! a3 z: t
BaseMouseCursor();
+ a8 B$ V( j8 F, a( ~6 B4 _5 `}
" F6 J2 u& g' Z; Q: z在其下添加:
$ _' T9 A2 p/ F5 m6 n0 N3 zvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
+ @% K" R$ J+ q{2 s" X+ A2 x; Q6 H3 {; p2 g
m_wndMenu.DeleteAllMenu();6 a+ s% U. n: ^
m_wndMenu.CreateMenu(this);
( W4 P1 f2 q/ wm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
( t- z7 c9 B* T% [( }5 ^$ Y9 p2 T$ X+ I; _" F" Z3 K: r& B
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))3 l0 u8 F) V9 t1 i ^& |% c. z
{& {- I2 k, x- Q- W, U
//P以上级别才可以删除所有道具
, f; V9 e- E3 b+ T D5 S5 O6 J m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
- s+ [- ?) Z% N& \* w}
! Z' Z# F. d G' C0 c- u/ J. km_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
( c0 j4 u- Q; H0 z- D8 Cm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );) F6 F) F. y B6 b0 Z$ Z0 p
m_wndMenu.SetFocus();
2 r- S3 Z f( A}( T0 R3 `! p- P$ J7 T! C
------------------------------------------------------------------------------------------------------------+ f) Z5 E5 n0 B5 ^6 t# L. O8 ?6 |
*************************
4 T9 ~' D4 u. H% {WndField.h文件5 Y& k. s9 K+ x2 i# }
*************************! C! @! z$ q% z+ }# ?
搜索:BOOL m_bReport;
$ c! U7 W5 d% O0 [2 B其后添加:' f6 [8 Z; i* Z! ]8 L% M* w( X- M
CWndMenu m_wndMenu;
' Y6 h$ r5 p( ?9 m) ^! e搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
6 X9 W# F; y9 F" t( \+ u其后添加:" W! N8 {% z2 c) i- u
virtual void OnRButtonUp(UINT nFlags, CPoint point);6 W2 V9 Y* p; R6 u) [- [4 j; J( R
8 D q7 s* v: @8 {/ \- Z p; U8 G- p- t6 G" A; D
|
|