|
|
源文件中_Interface文件夹下WndField.cpp文件
0 r% E8 a$ D6 P; b6 U( Z$ E8 ~搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
& y: |9 p3 n1 u8 R) `, K+ \0 b9 Z3 g5 G% u# m) q
struct sItem B" V% I! P" T9 }. k {
{
* T( `$ e+ ?: Y3 o1 zDWORD dwId;
/ c$ ]) H4 Q4 [9 @( A, GDWORD dwKind2;
* n5 |& {% I9 C8 l+ o( uDWORD dwItemId;
0 D7 u) L ^3 H: G5 j6 P# q" k* WBYTE nIndex;
; S6 y+ u# ?% b EsItem(){
9 i% A5 x% G' Z" c0 b0 j7 d dwId = dwKind2 = dwItemId = nIndex = 0;
5 r; i8 W- }0 {3 ^ L4 H+ ~}. P0 o4 }5 M6 X$ |
bool operator < (const sItem p2)' O0 R* z( }" I! a: t0 D
{
6 [, Y" u3 G( j8 J6 }. E1 ` if (dwKind2 == p2.dwKind2)4 v4 f5 m# Y: \( z& k3 F
{, T% O) m1 a/ T& g
return dwItemId < p2.dwItemId;0 R/ w# \! b+ f2 k/ f- l& O' q
}else{" q7 B/ D( p% M* R
return dwKind2 < p2.dwKind2;
3 H& A7 A; L* z7 {$ ~ }
8 _- j9 E v* S9 i' k}
" Y" |4 f5 U. G) \$ l7 q2 O};- o0 M( }. @3 e5 A( J( s
class CInventorySort3 H/ Z5 p$ ^; n3 C }# I
{
6 ~ f1 W/ H& |0 i& opublic:7 n' ]) ^" Y) j4 V9 U1 S7 |( |
CInventorySort()
2 }# @ {* t$ J4 X{: _' |6 r+ J* Z
m_dwPos = 0;
# R/ c8 k- _/ e$ ]}
8 N, [/ I- W# v7 e x1 F2 n. R; f~CInventorySort(){}
6 E- |6 K" v, `private:! w4 c8 b" i3 R9 s
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
# I o# S: \0 J' F, a! }% _: N2 kDWORD m_dwPos;8 L3 c5 X! @. Y- y
public:9 n' i8 I# H% L+ K7 o, e
void Add(BYTE nIndex)
; T. ~+ M; V5 U1 \$ g{
" T1 S. l7 Y4 _$ W$ v1 z if (m_dwPos >= MAX_INVENTORY)
: Y: k8 y4 d9 z; l7 J, g8 `9 F {. x7 w! ^& s; s5 I0 `, F2 a
return;
' a8 ~& c! J0 ^2 N }7 V2 o: o- m+ s9 s
m_Item[m_dwPos].nIndex = nIndex;/ G) s& Z3 Y6 e4 }' Q4 D
m_Item[m_dwPos].dwId = m_dwPos;4 U c, n- j# P
m_dwPos++;
2 f4 s' }, J1 d( K" b I}5 M( a+ t7 o, ^, S- l
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
( \' f# N' R3 Q4 b. E. n" P0 Y{3 }- ]5 a3 z8 ^8 C
for (int i=0;i<MAX_INVENTORY;i++) M/ n! s5 m$ Q$ Z1 ^. y% I
{
# _, X( P6 ?2 e* P5 o if (m_Item.dwId == dwId)6 B+ S3 h- k4 p `( B) v, S8 s5 p
{( L- Q5 X# }8 d* T+ n" h
return m_Item.nIndex;, x% q- d6 M, g) S3 g6 f
}/ c$ T' l' L4 S+ a; J b
}1 R2 b- _$ _3 A5 Z" m* U7 U: ?! q
return 255;
0 p% o; n- w0 f9 A# b$ n}
( I, S- i$ E* C: @+ H! ~void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置' d! d4 f, z& o# G
{$ l. i9 j: b; s6 z0 ^
BYTE nTmp = 0;
0 K& q d0 s0 u$ D) J/ U6 `7 \ bool bDest = false,bSrc = false;
0 O" p5 m9 x7 r' h2 r for (int i=0;i<MAX_INVENTORY;i++)0 _; L3 Z, q+ \/ z) Z
{
8 d3 m! ?3 V9 p# J if (dwSrcId == m_Item.dwId)! c- S2 v2 s ^3 {0 N/ Y7 V, E
{
7 I( B/ k* {4 _! G //id相等 则 改变对应的dest和src3 y* L& [3 X! P# d- A9 Y
nTmp = m_Item.nIndex;" S& b: [( Y0 \( X
m_Item.nIndex = dest;, h. w! J( @1 Q) J& r( N
}' x, L* O- A1 M7 A
}
) O: d8 D+ b% | //临时数据保存完毕,交换开始% q, i, n# |6 U! X- Q" a
for (int i=0;i<MAX_INVENTORY;i++)# h0 k3 H# i# R! E5 K8 m, u
{ ^' s k: s$ c6 L" j" t" D/ e9 \
if (dest == m_Item.nIndex)% U: S9 ]) v0 O1 @7 B5 [6 I2 E
{3 [7 C2 d3 e z1 q& G$ }9 K R
//id相等 则 改变对应的dest和src; C+ o0 [' C0 w$ m2 C
m_Item.nIndex = nTmp;; [" a0 i3 Q Y# w [
}
v0 j" k! T* `( \* F }
- K, ], \# _& r _, y: A6 e1 N}* A1 Q% H- H1 ~* b
};
+ b$ A3 Y3 ]6 ^% y-------------------------------------------------------------------------9 k/ `! n4 W4 q
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )! T( V5 R5 v, ~7 u$ z' i' j
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);; ^9 J Y8 o" h& B6 V
紧靠其上添加:
+ r6 ~0 x+ {3 ?if( pWndBase == &m_wndMenu ) d2 O( x( H! f: g$ f4 @
{9 ?5 k. W/ ~. ~! f
switch( nID )3 Z! y" I/ g+ v) B/ J, k! Z
{
- m$ j% x9 c5 Y! K1 u& F: g case 2:% Z4 f* n4 S/ g" |/ @, J9 {) g
{+ T4 ?' |- Q. Q7 Y
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);+ ?# _, u! W" M0 |* y( N
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
; q4 k, ], c$ C4 |5 `% S { y, D" ^5 `# t5 O1 e1 G/ e
break;% a: ~1 n. U6 M
}! ]8 P7 q# y, p4 w+ ^% M8 V
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
7 ?0 e- M- L0 K! L {, U; {' y! E0 C: O9 |. s* p5 V7 e: z
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);: U$ S8 r: C+ B$ h$ {5 T$ M' A. m
if( !pItemElem ); Q0 I* t2 q9 H
continue;
+ S2 `" ^8 W4 @$ }; Z4 L if(pItemElem->GetExtra() > 0)
3 x! h. l& ?5 } continue;
% b$ p% w4 T! Q a, ]) x if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) . ]# t, _' p$ @+ d# J& N; w
continue;
3 ]1 N7 z! }8 t2 J% B if( g_pPlayer->IsUsing( pItemElem ) )
# | E( a P+ m5 s2 ^, W9 t continue;! q M+ ^) K! R8 b B
if( pItemElem->IsUndestructable() == TRUE )) l% u7 M, O! \* p6 r
{" c0 ~) h: R7 |% w
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );+ Z q: ^" }) `: i% p5 q! @
continue;- P6 g2 Z' v6 A# A5 v
}
. x: F3 Z+ e% O' n3 h/ ?% E g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);4 H' F$ [# k- Z8 o: Z. h: v
}; j1 U7 e ` Q X, r' F- w0 @
break;
2 ]7 J& I+ P- }! H; L6 ^) Y% T }
- ^/ Y& {3 ?8 s1 I% d case 1:
% V& l% K4 Q$ b3 i {# M+ A- J8 D7 \& [9 H2 c" E" W
//整理背包
, s+ W: P2 H$ v2 f/ C% V5 u- B4 W //////////////////////////////////////////////////////////////////////////
# \ f. o8 ?; s //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );6 z4 B8 e4 [; v1 x p( U/ N
//////////////////////////////////////////////////////////////////////////! V! n5 M3 q% E% O9 u. s
//////////////////////////////////////////////////////////////////////////
8 \7 O9 j/ Y5 m CInventorySort* pInvSort = new CInventorySort;
9 M# s5 ~ r- g vector <sItem> vItem;, p" K0 E1 G5 T
vItem.resize(MAX_INVENTORY);//初始化大小
7 p O% i& b8 U9 I' I- q //////////////////////////////////////////////////////////////////////////
% k4 ?3 X2 b: h" k# V //填充数据
7 ]1 N+ u) o& @" m1 N9 n5 f for (int i=0;i<MAX_INVENTORY;i++)
( e6 Y! Q+ H5 @- T% e {
3 p+ @$ D& ?+ M6 T1 R( m CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
" N6 }: A6 v2 I( q1 V) d6 w if (!pItemElem)
6 \4 i# A4 Y2 v7 o4 | {
a& F+ E+ }0 i1 P9 F' q vItem.dwKind2 = 0xffffffff;1 y3 d8 \- r, R/ Y
vItem.dwItemId = 0xffffffff;
, S" x2 d$ J/ p; y: X- H; l vItem.nIndex = i;0 e& l& S4 ]# a& [/ Q
}else {
" R2 t& {/ z* z( C ItemProp* pProp = pItemElem->GetProp();) G& ?: w7 Y* }- k# H% ~
vItem.dwKind2 = pProp->dwItemKind2;" l5 P9 K0 M4 X6 A( \
vItem.dwItemId = pItemElem->m_dwItemId;- y/ | B! r! n; k3 u& u
vItem.nIndex = i;
3 {7 ~( Q6 g" |* ^1 ^, d' N) U }6 h; A& `) f, v3 ^6 Z
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);) h6 N7 f* A% o6 U, ?' }
}
# ~2 E4 i0 w1 _! }9 H# L: { /////////////////////////////////////////////////////////////////////////// {# u! v' Q7 J4 k3 h, H$ c+ H
sort(vItem.begin(),vItem.end());//排序
% }: ~: ?' A8 }& S" I# h+ n //////////////////////////////////////////////////////////////////////////) C- R- T6 @1 f) Z6 ^: G( n
//交换# Q% w: p3 |! l3 c7 h8 ~+ Z
for (size_t i=0;i<vItem.size();i++). Z& b" s, l: A4 X. @
{
' N2 `! c, K. \# t: F6 h //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);: G, h0 e% s& x2 w `
pInvSort->Add(vItem.nIndex);
( z& n/ U- H+ Z( W! R) R }4 W. x8 R0 e; ~2 {0 F1 N: {2 l
BYTE nDestPos = 0;5 c5 u- V4 z# e( r
for (int i=0;i<MAX_INVENTORY;i++)& f8 U v# N2 B& n# x, t% k
{
* k0 U8 }, L0 ^. n: D( W) b CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
4 j- Y9 U: n' b1 U% I% Y' ~ if (pItemElem)$ a; p( C2 q3 I5 p7 h6 D* I
{" `+ T- ?! n6 U: g& d6 w0 V
if (IsUsingItem(pItemElem))
& p- p# }3 u2 {% D$ |3 a& \( y {
' [& \) ~! `6 z5 m. R& n1 @3 t //这个位置无法放
: S% t6 Q# c! }# @3 ` nDestPos++;
3 ?/ Y& J( o* V* b: m3 \ }
1 ~3 x- E3 J- _0 O$ Z* ~' K }; Y! e% y# _( g! ?: v
BYTE nSrc = pInvSort->GetItemSrc(i);% N4 t$ \7 `; a
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
8 N9 P, H1 w' n: Z6 }: K if (pItemElem)
- d% {0 ^2 F/ b, A {' x: A. ?0 \' T( M
if (IsUsingItem(pItemElem))
* @- N M: Z, A9 ]3 Q {
- t6 Z$ c$ `; a, s! m$ B //这个道具无法移动,跳过% J: K/ D/ q7 L& }# X5 P
continue;
7 d6 ?. x+ \- ~, S }
% k0 c; s* o2 q) h! } }else{
! f6 p* R% U! ^# D: f9 D //空位置 不用动; r$ y# h; `& O$ \9 l" ^
continue;1 O8 u5 Y2 Z' q! Z
}3 r _7 v* [9 `$ U- j' H
//////////////////////////////////////////////////////////////////////////
) L7 |% H3 e0 _0 x7 Q$ y, h7 ? //开始移动7 b0 `( m: e$ @: j1 j& p. P" n3 \4 L
if (nSrc == nDestPos): t# T" E5 l( R8 c5 _
{" e; o; v, y9 W- U3 V+ T, Q" u4 \
//原地不动
% g( v- X( S# h! y% c6 l9 V$ X nDestPos++; Q) r- \) n0 f. P d$ c
continue;; `: O' c- k2 o! i& `1 L9 ?4 i
}' {; R9 h0 G3 M0 c$ o" j5 E
pInvSort->MoveItem(i,nDestPos);
; | m0 B) q. n( F g_DPlay.SendMoveItem(0,nSrc,nDestPos);1 n& G K; d. x( h; n$ O3 C; o
Sleep(5);
1 S, ^. a2 A2 J5 i4 d3 [; U6 c //Error("移动 - %d->%d",nSrc,nDestPos);/ I* _1 O7 \0 z# ?4 |0 _" `
nDestPos++;
- `0 X! n8 a9 S3 {+ _# _" X. h }
6 Y2 J$ y# o5 B" ], K1 K, \ //取第一个元素的信息
8 i/ ~5 m# J; A /** j2 D9 p- ]' x( j6 z
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
+ s, q) C5 e1 J, R" I: |/ B' C {1 t7 g R% m i7 b8 }
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
9 D$ l! v$ N# J+ [) [* Q g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
8 @% P. w2 ^0 ^ }
2 [, ^! y, H- Q* M */
1 M8 l/ S+ @' ] //////////////////////////////////////////////////////////////////////////
5 E7 t1 k- S! V! Y8 R break;! c1 H w X. p4 P% ]/ v; @3 R
}
! Z0 a! R% I0 L }
. T; y& Z- }/ Q0 ?' Z( B" I}
4 M( K0 U" o3 P) k- N7 h1 p: s; {; n8 Zm_wndMenu.SetVisible(FALSE); {+ g* ~2 ]; ?( Q8 d5 p$ c
9 V6 \& o: `+ T1 l: P--------------------------------------------------------------------------------------------------------
9 i E- V3 C+ v+ E搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point); _ Q, _/ h' k3 A
{
( y" B8 A8 `+ c* hBaseMouseCursor();
; Z% @6 D: F; u* H$ v6 w}0 p8 t- H9 j* \4 }& D4 k4 l4 G6 L
在其下添加:) z2 w/ L' W% p6 u8 x
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
! q' Z: A+ Y1 p$ N3 `{
& m/ F% u# |5 G8 Ym_wndMenu.DeleteAllMenu();
( Y: e, z+ v. V* sm_wndMenu.CreateMenu(this);7 y) B4 R9 Q5 W" m9 x
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
j9 j- N9 l* z4 X. z4 P2 K8 ?/ C: Y
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)). f4 {2 ]7 H; N6 ?- A8 \. t
{9 @5 ]) y3 |& P( ~ s
//P以上级别才可以删除所有道具/ g3 E) o8 k0 L e) r
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");5 V8 V# l6 m: p' u0 b: l5 W3 `, W
}
y/ d+ y1 ]/ U# D+ y9 Xm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );" W* t) a% k6 w( x1 f3 Z6 x
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );: M- K; p* ~5 y! f l" R
m_wndMenu.SetFocus();
* q1 H% |2 d4 B! H# W4 m3 e}
8 [( t( _0 R# v- T3 t1 V, P2 l4 Z------------------------------------------------------------------------------------------------------------
; }$ _9 z0 U, H3 C+ W************************** c/ G; {) B1 j( X0 `. r7 @2 K7 b
WndField.h文件
9 o( r. l, w; x) N6 z% J' u+ y*************************
' r% c& ]! m8 j/ o' m2 I搜索:BOOL m_bReport;8 z; S7 E' f3 I* X0 W8 w- _
其后添加:1 t# k" \7 a; h$ q9 n4 I
CWndMenu m_wndMenu;
/ M% S: q( B0 g- ?7 t8 z- L搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
2 n2 ^/ s9 m# d0 f. T* X, {其后添加:2 H& s2 I+ b( N$ j7 D$ y% m& ^2 c
virtual void OnRButtonUp(UINT nFlags, CPoint point);
- c c8 h G5 Q+ s& S5 I% O& ]4 {8 z. w$ Z; A( ^, u/ _% _0 v
+ g% I- I7 C; O) i' {" F |
|