|
|
源文件中_Interface文件夹下WndField.cpp文件
5 f/ e2 R/ |% i# d! s0 T( H1 N! N搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
- G3 h% b0 y$ k& q. J: j7 [: @5 R1 A7 l! q0 L; W) I
struct sItem
' a6 d8 w+ I; i/ b{, J# t* M: V) G1 \
DWORD dwId;
" a0 [6 b& g, z- _+ BDWORD dwKind2;" a# z$ j7 ^6 {
DWORD dwItemId;$ G" l7 J5 h T! p! R; ^0 K4 p: R
BYTE nIndex;
- o2 _9 c0 \' ^/ z% FsItem(){1 H" T2 h* o- {. [; H/ u {5 B+ i
dwId = dwKind2 = dwItemId = nIndex = 0;
* n# K: C+ j3 B7 _/ D/ O7 m8 {' w/ G}+ c7 i3 d) ~' x( q& K+ R
bool operator < (const sItem p2)
, n, w- {0 t l" x; U{
0 y: i5 [7 a, ]$ D' o2 p0 K if (dwKind2 == p2.dwKind2)
t- O" I$ v5 e$ i2 | {% X% V* W% d( s" t: a1 b4 G
return dwItemId < p2.dwItemId;
& Q! ~* [: e$ n/ f: w x* }: [2 E }else{) h' g; I$ L T) D3 w* v/ G
return dwKind2 < p2.dwKind2;
6 ?8 ~' m* E Z( ?4 G& r) b5 g }
@1 o' F3 H$ n% b" V( y}. o3 Q. |. N ^( m9 T3 e* v
};: g; k! w: h; A
class CInventorySort
+ ~# r: c* n. z! f1 p{8 f; n) { {0 Z% n; i: i
public:3 c9 _: e9 T, d8 Z, x
CInventorySort()8 X6 x L! R" A) Y1 p0 r
{# H3 x6 _- L l6 D) Z/ [
m_dwPos = 0;2 C- d6 V* k- B% S1 C+ w
}
" }& h6 P( @ c~CInventorySort(){}+ J1 t( P. D* q: N2 P
private:
2 n/ A# K; w g$ s7 }1 |. zsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息4 n( _- L: }8 [" L% ^! t$ Q
DWORD m_dwPos;, }: A: |% k3 @; Y% ]4 ]
public:1 Q: K8 b+ m# Y8 y# a3 A
void Add(BYTE nIndex)' P2 d$ L S8 Y2 Q* ^8 V
{
& C7 ?) N* N/ l( I# V! s if (m_dwPos >= MAX_INVENTORY)
# X" S k( c# B; P) n3 v {
% x+ [ {: Q/ A! c8 H2 U) n% b9 j return;6 e& K) D8 B. h
}7 Y' G' X7 D0 u3 [6 _
m_Item[m_dwPos].nIndex = nIndex;
: W% o5 }# M* B5 ]: ] @ m_Item[m_dwPos].dwId = m_dwPos;+ r4 Y' U7 I) X; {4 x. P# Q7 _0 L
m_dwPos++;
& s6 P! f$ i Z+ b7 w}
7 C @6 B. x9 l! wBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
F; g# x( G0 c{* m' C8 i" @1 L9 K
for (int i=0;i<MAX_INVENTORY;i++)
2 j8 ]0 H: f/ H {' R: ?* W/ `8 p- E$ p M
if (m_Item.dwId == dwId)% }0 s$ c7 |7 P+ u- C! s \8 g+ p
{
$ F4 W4 G9 R0 ?4 ~% k+ j return m_Item.nIndex;1 H1 d7 S" Y" J- ?
}
. K, n, E! ~* G" l/ B+ F }: L( S( t8 x# N5 F, t% L, P
return 255;
/ N: i; _/ m( r% {+ o; m}
# X) w9 H. x( x) `: J3 E f" Hvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
! h# A' q( Y' n0 q/ d6 R8 J5 }: Z+ S{
1 C4 D! c, d; a6 K; ? BYTE nTmp = 0;
/ B4 v" ]4 M# I- r, C; k3 T bool bDest = false,bSrc = false;
( m0 h# O) R2 i: U- P) ^. W for (int i=0;i<MAX_INVENTORY;i++)1 x e% h( p: u; G( D4 J: M3 D% a# T
{
( d& B. l9 d9 i1 {; o. M: M if (dwSrcId == m_Item.dwId); a4 w9 o# M0 @* H4 M' I" l3 d
{$ }7 r3 m/ W* F: b* d
//id相等 则 改变对应的dest和src. _- f5 e8 p' l
nTmp = m_Item.nIndex;
- N% Z/ k% c6 R8 V7 g% N m_Item.nIndex = dest;7 I% Q; m1 z( O% f5 z, q3 l/ |
}+ d- l# t- K" ]# ?: t2 L
}8 k3 c- D( A9 k, G
//临时数据保存完毕,交换开始. E) E! V# _5 ?! R
for (int i=0;i<MAX_INVENTORY;i++), K( Q e5 }- f: E$ A
{
# K% O3 P! v. F& D: ^8 f0 m Y if (dest == m_Item.nIndex)
) B {) a) _' ?5 Y2 ^ {
& W$ C0 g, e e' ?6 [ //id相等 则 改变对应的dest和src T: ^4 e/ D! @# u% Q7 W
m_Item.nIndex = nTmp;
9 s( ?2 r5 ^8 A }
5 W4 c: B8 e2 i' a+ h3 B. q }
+ C2 Z4 w( H: V+ t i+ }, b}& L* @/ I' z6 ~3 k/ F, E( ^
};
x8 h! `. P2 g-------------------------------------------------------------------------
( ^0 u" Z- x, H0 v9 z" P依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
- `0 C9 G- J/ @4 L. I搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase); W9 w- e! e; `$ J2 D0 {+ Z
紧靠其上添加:
' z9 R7 P# m# nif( pWndBase == &m_wndMenu )8 Y$ b1 l; V1 Z; S) M% j. V0 |; x
{) I9 ?/ I: s; y% f* l3 n* y( F
switch( nID )
2 | D' `6 | L. R/ B {
2 o6 [+ s1 f) d+ t y- ^ case 2:
% @1 e, U" ^+ g, K, s {7 R) B; _ R: R( {1 P1 T. y
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
8 k6 T4 O) }+ F if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
2 v; L) T P* z# x {! \/ q) a( L6 Q/ a% t" {1 |+ ?2 l
break;% E) b4 U6 ?/ U z4 {
}
: q$ E8 A( [+ u3 I) I for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)* s% ]+ P" A; ?
{0 S* Z9 u L2 D# X. N
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
1 X S' X1 @$ g4 K if( !pItemElem )
$ Q; E2 ~/ Z; I$ j; p continue;
* Y& g" h4 W: R1 p2 c9 v) `# S6 g- ~ if(pItemElem->GetExtra() > 0)
6 @! o$ y* p( s" M! s continue;
& F' }+ u3 _/ q n0 m if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
+ l* s& A1 m$ L9 A% _4 u6 j v continue;
) e4 h# H' Z) L G& k if( g_pPlayer->IsUsing( pItemElem ) )( M& T7 b( j- j/ a$ p1 o" T3 } Z
continue;
4 X- o3 _- i$ q4 K/ | if( pItemElem->IsUndestructable() == TRUE )5 s: U: i3 C; H' e q) K
{0 f3 S9 r. `# W. u! ]* L) [
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );& \3 H" O9 B! Y1 Y
continue;
/ m7 ^( f( e- | }6 z* J! Q6 w: d) J& c
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
, b$ o' T, L$ `/ T0 n }
2 P; R3 _3 m. ~# c break;
1 G- i; p; C# v6 [& y9 J }
/ @" q0 E* P2 {6 s8 T5 v; J$ F case 1:
$ r! O3 t; L! x& p _ v# F" O {
; w& z" [0 ?1 m7 U! o* M0 S //整理背包
9 [5 Z! [5 p# N$ I5 { //////////////////////////////////////////////////////////////////////////, x9 x# Z) C' E- ]+ f# O: J( ]. W) a
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
# z1 J- D0 G8 L& s. A: W/ W //////////////////////////////////////////////////////////////////////////
; ?6 B! f- d/ c9 C //////////////////////////////////////////////////////////////////////////- W# g: Z4 A( O: \- L7 ?
CInventorySort* pInvSort = new CInventorySort;7 @" N: C5 ^8 I
vector <sItem> vItem;
5 k6 p+ y7 j9 y& S vItem.resize(MAX_INVENTORY);//初始化大小
3 B: V8 I) l; U) i //////////////////////////////////////////////////////////////////////////
4 G" Y4 f: b6 X: O( S/ h //填充数据
2 d9 x. L0 U6 |/ b: z for (int i=0;i<MAX_INVENTORY;i++)
( R3 Z, L9 a& S0 ^* U* s, G) \ {
9 l( M3 g D* `1 _' L% { CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
7 F! ?+ Q! ^% z6 d c0 M/ g- w if (!pItemElem)
' E0 R7 X# W; D. q; ~ c+ Q: ~ {
) l5 m! j6 G8 V* ?" I vItem.dwKind2 = 0xffffffff;
. d/ k# ]. x" n# K vItem.dwItemId = 0xffffffff;
1 G+ s- M3 u7 c. Z' r9 O! w vItem.nIndex = i;2 O9 M* T- |/ {' B/ r) ]6 v
}else {
6 A/ {# r; \2 {9 D ItemProp* pProp = pItemElem->GetProp();6 t; {) h# o3 K$ |3 ?2 e* V* H
vItem.dwKind2 = pProp->dwItemKind2;) R) w0 ~/ e! ^; _( ~
vItem.dwItemId = pItemElem->m_dwItemId;
& |; \6 N# o# h4 B" k3 D2 p. [ vItem.nIndex = i;
& \6 u% f1 I& j$ F: f3 I }5 j4 q/ ]& A0 y3 ]
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);6 {% \; s7 _9 g* i! G1 p7 b# k
}
, l3 ^' z2 \. @% W' D6 W7 J# ?8 q //////////////////////////////////////////////////////////////////////////3 W* W7 M& k6 N; ]( u. {
sort(vItem.begin(),vItem.end());//排序
+ ^1 P8 j( d0 `3 j/ { //////////////////////////////////////////////////////////////////////////, x. ]) I' U* n
//交换0 R3 O' B; ]1 N8 D0 A. D
for (size_t i=0;i<vItem.size();i++)
/ }3 x+ I7 g9 W( B* X {/ ^- A! z' D' p: J
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);0 \ F9 E0 J. r1 l, K# S
pInvSort->Add(vItem.nIndex);5 ]5 l" j! M6 i( Y- S1 n" V
}. i2 q1 J c% Z# @ A
BYTE nDestPos = 0;
% w6 e) r0 ^) a6 ^- ] q for (int i=0;i<MAX_INVENTORY;i++)4 F8 |/ h, q% P2 t4 J. m. z( B
{
5 ~6 Y# k/ ~4 }+ _% o CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
6 ^3 x; \8 G4 N1 P3 a+ s- k+ F$ s if (pItemElem)
* \. E$ V3 z8 w) g1 A" f. S- d {
! D3 K! {* s3 c% I if (IsUsingItem(pItemElem))0 U( ~, l" m' a' H
{
; s" V9 Q3 @6 v: }9 v. l //这个位置无法放
7 o1 I8 l+ l4 [2 b, g nDestPos++;6 {3 r& O( A: y
}
& y0 D/ d0 l0 P* j2 s% R, z3 a }( C! _7 n$ B y' Y0 Y9 H
BYTE nSrc = pInvSort->GetItemSrc(i);
4 z1 q4 P! O- o( K& Q5 K pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);! \1 Y! y0 Q. B W9 |
if (pItemElem)- b1 L, b& b. }7 {; N
{3 P/ c$ z' N* m6 s9 r3 O7 M
if (IsUsingItem(pItemElem))
! L! z! X7 q- d" G2 O+ h3 X4 h {* b1 l' |. W5 F& h5 f* L9 y, L
//这个道具无法移动,跳过
- y- X1 R3 ~3 [8 y6 Z0 n8 o continue;
u+ S1 L9 \5 D; G W$ z }" ]/ F c/ N+ {. N' a5 m/ I) n
}else{3 @8 ]' ^5 ]& O+ v$ r6 h/ L
//空位置 不用动% o( @, L, {6 K) M0 z
continue;
+ r0 l2 K8 s, |: U, }: O }
; B2 E6 ?# Q1 R Q. e' U) z //////////////////////////////////////////////////////////////////////////
: I9 ^5 K- `5 D# Q7 t0 X //开始移动0 f3 Q/ J$ c) M' i/ Q- g* C5 A ?
if (nSrc == nDestPos)# J- _1 I$ x( P
{
3 n/ L7 J* U/ O7 s; _7 `' f7 G; V //原地不动
/ S4 m5 O' D3 N" h. o nDestPos++;
t3 _8 r! U$ N3 b, y1 B | continue; z/ M. U. }; E$ H- j! S
}5 O7 z: `$ g% J- V; k4 c
pInvSort->MoveItem(i,nDestPos);
* Z: @7 L1 G' J* n6 n g_DPlay.SendMoveItem(0,nSrc,nDestPos);2 {. G, Z4 t) K: _) h% k5 \1 n8 H
Sleep(5);' A- S) i7 R# L7 C: q- o3 c( }
//Error("移动 - %d->%d",nSrc,nDestPos);
8 m, F, u8 Z+ ^0 N nDestPos++;& G6 j6 x- v* M* z7 G
}
0 Y7 x0 U' T, x$ d5 F5 n9 U: E //取第一个元素的信息
% \. _# @/ g" P+ B+ D- k /*
3 R9 Q3 Z2 [+ ]+ T if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff) o+ e' |# X: K- W) K
{( b4 n4 _8 o Z9 \$ X9 l
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
: v9 C# a% K- [, A% O; [$ ~ g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);' f, l; l$ u. H' u* I
}
/ j! {' X' _* g* [8 ` */% ?$ K9 A G; i, q& t" F$ ~1 F
//////////////////////////////////////////////////////////////////////////# C6 g% h% f4 a( |# S9 p
break;# M& B5 i" t3 ^
}% G8 V2 M- d; ^
}
+ }5 U K2 `; ]7 B, a* f}( h1 @' I( @6 s( M$ s: T/ H
m_wndMenu.SetVisible(FALSE);
% B. U2 e) M' }$ R& p4 H7 ?3 I0 B1 x; L0 X$ M2 d' {. u" v
--------------------------------------------------------------------------------------------------------
7 S7 _5 S" C/ F) t0 E3 k搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)9 v1 @9 d- L) D: y* P
{8 T2 E" v1 y$ @3 B; c+ H
BaseMouseCursor();
. b6 g8 l! @: G* e3 C9 X+ D3 y}
* l U u( B6 _( V U% \# Y7 \在其下添加:
4 R4 Y; c3 g) k1 Vvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)5 C$ g& X4 }% l
{; }0 s& \# ?, p
m_wndMenu.DeleteAllMenu();/ @2 b6 ^5 R7 {
m_wndMenu.CreateMenu(this);* |1 \ [5 ^: F- R! I$ s
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");8 p7 M) g. ]+ S2 s7 ^* c/ U4 @
5 t' \8 c0 `/ W. x& l/ Fif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))' Q* `. g9 X7 O; u3 x
{
/ l( d: |# Z, r+ z5 A) N4 r //P以上级别才可以删除所有道具- v- ^; u7 j) @
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
+ r) g: k# w6 i2 ^0 p2 I} d1 `: H2 n. G( O; S
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
. s3 k$ N7 |$ ]! r, X% c0 vm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );' E. q G* e! p8 x2 a! V$ t4 e
m_wndMenu.SetFocus();
4 X$ U( d6 A( n2 R! b}
/ h u% g( r! `. D4 ~8 }------------------------------------------------------------------------------------------------------------ x( j7 [. N+ @( R6 W( K1 }
*************************4 Q2 P" }+ a" a
WndField.h文件
# i+ e" P; w& `4 d0 M+ j*************************
8 V& m! t- x6 I0 p1 Q1 l6 @搜索:BOOL m_bReport;3 a# S! R5 Y9 |( l
其后添加:) D6 N I. H2 c' Z$ G
CWndMenu m_wndMenu;5 G0 l; [: \/ M' `
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);4 d/ k6 w' y' M* K- k
其后添加:) _8 m: X' { l
virtual void OnRButtonUp(UINT nFlags, CPoint point);
% S& Y+ D2 S+ k
" e p" {7 `* V' U9 Y- L8 O2 u4 M$ u3 _8 e& ]" ] T% M, N
|
|