|
|
源文件中_Interface文件夹下WndField.cpp文件# p$ W0 Z6 G' C5 l( i" M; X
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )# I6 c% d/ V2 @6 d
9 ^) `' ]+ z. `
struct sItem4 b( C3 B# v# X" ^, I; y* o* O
{. Z' G3 |$ s& A. m6 l9 {8 z
DWORD dwId;: f# Y# X% t- C* g+ \* q0 L2 l
DWORD dwKind2;
" Y$ o6 a* g2 j7 I U aDWORD dwItemId;
8 d: s0 u: `/ N& A0 [4 g/ tBYTE nIndex;* F0 O& @, q% g# D f
sItem(){2 D8 Z9 i6 f; k
dwId = dwKind2 = dwItemId = nIndex = 0;( j9 k" x5 W& [1 y1 \% r9 Y; }
}
& ]) I) w' h% @/ Z+ D1 u' n: T9 Bbool operator < (const sItem p2)5 A2 c: F+ V. A# M7 E v( ~: Q# [
{
' L6 E+ y. e$ `3 R* _' B if (dwKind2 == p2.dwKind2)
# h: w0 P& o4 S1 Y {
+ v5 G, p6 k, W0 j return dwItemId < p2.dwItemId;
( v1 X7 H2 _" E& E# r' I* K }else{
) ]( z/ e0 L0 i, Y- [% |$ X$ K return dwKind2 < p2.dwKind2;" C2 h; K. |8 K- }' c7 B
}+ L; g( H0 L3 Z2 d
}( u5 C2 V8 ]) M( C. S/ Z# L( u. Y
};
; N3 P2 ]! V7 k+ d9 q8 Xclass CInventorySort" Z. S/ |6 G3 g, ]3 a
{% Z% F' R, |3 {* y- l7 y) }
public:. T' U' R( K1 I/ B# v
CInventorySort()7 @0 Z2 t: g& d( V. \
{2 t y9 L( M8 T5 }" N
m_dwPos = 0;
- g6 m2 V+ B) M Z+ R0 y}
: V2 {' I# z' \' d% y( l: Z~CInventorySort(){}
0 ^$ X( p0 b- X& `private:
& B# v7 b4 u9 ~0 ]2 Z9 |/ ZsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
% C4 w) Y; h, F0 R8 kDWORD m_dwPos;* Q* Q9 ?8 B' t: I+ E
public:
2 K7 p; _) a. N6 G3 @0 @void Add(BYTE nIndex)
% r3 J. Y& B7 l0 t% r! y{1 [% Y& H2 F+ c1 H
if (m_dwPos >= MAX_INVENTORY)0 e0 B- k8 [% K
{$ q8 I6 V5 ~( }5 t2 B- L8 c/ W
return;$ ^, F2 Y0 P5 f: H! B
}' }( `! l3 u- s# O2 T
m_Item[m_dwPos].nIndex = nIndex;
+ s* D" P6 E' w m_Item[m_dwPos].dwId = m_dwPos;2 A: s8 a$ J: X9 L& _" t
m_dwPos++;
- k+ h+ _" {! ~) f/ ]9 H}, G/ T9 U- @! ?$ s" }% \
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列' i5 w5 j, a: ^' M* P9 c
{6 t5 @3 O5 |( [; }7 b
for (int i=0;i<MAX_INVENTORY;i++). V/ s2 S1 o: D' J8 K- R
{+ |/ w$ A9 T" l* j* u8 e0 g
if (m_Item.dwId == dwId)
% q3 I8 B/ A! ^ O: t: n {* D( |/ r" @8 A6 C3 I
return m_Item.nIndex;
8 [* G9 e- ^! [; m* U }0 [) l0 _, d- g
}, F) |4 C) A+ _ c5 @; I( \
return 255;
0 B: w( n0 E+ e5 i7 w0 \}+ W5 l, B; R; n7 F
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
- ]. Q' [: G: i{! W& p7 Y7 Z1 B" S* ?1 l
BYTE nTmp = 0;
- {& i; v. o+ I k, [: q bool bDest = false,bSrc = false;
. @+ S& t0 t s: R0 q for (int i=0;i<MAX_INVENTORY;i++)
8 f, ^6 Q. a4 q {+ o7 y" Z+ d. P+ d( K' Q/ v
if (dwSrcId == m_Item.dwId), ?2 @; ~% d" g; Q# k$ T+ \
{
! x+ Y: s0 y% I. i9 u1 m //id相等 则 改变对应的dest和src" y' ^2 {" |* ^) W; j/ r2 ~* _
nTmp = m_Item.nIndex;
4 f3 r# P+ {1 G0 _; x% B m_Item.nIndex = dest;
( ~# S: a! ~7 O p% c W# Z) M }
5 Y3 H! r: k7 g; [% @ }
0 [: {3 C! H/ q, g //临时数据保存完毕,交换开始
& b9 w( t" k: p% q$ B$ a for (int i=0;i<MAX_INVENTORY;i++)
+ m D$ K! @9 t0 ] {
. C8 _2 K2 d8 m$ W! C7 ?/ S if (dest == m_Item.nIndex); B0 ]6 W: J' S; P z5 t5 K
{
3 y% T0 I! j' u$ Q //id相等 则 改变对应的dest和src& ?; K( }2 l" K! l* E4 B3 x
m_Item.nIndex = nTmp;
3 l3 @# w8 U4 P) B# b2 P4 ^3 p }! S+ b( x$ L+ c- V$ b
}: [7 ~" w1 S7 \1 |: Y; }( _
}4 K0 \& z) P- T
};
j2 o d4 r$ N- {-------------------------------------------------------------------------* K/ F. ~- \9 o" i _0 ]7 g# V3 K
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
( H, ]8 v1 P) i t4 k$ N7 ~0 L搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);" G8 y; w. c- a* c
紧靠其上添加:0 s+ e: n9 x7 C. `: l1 B, ?9 g
if( pWndBase == &m_wndMenu )
9 u4 g6 y0 l4 b& S$ X' |{
3 V( \9 H' B8 d$ a8 G1 U; [) J switch( nID )
( @. s2 P9 N$ j6 Z {) E, v7 ~; y% A/ ~* l
case 2:: n3 _' q7 H$ Q
{
* L& G0 r: ?( D- j! g/ I8 z //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
- j5 q. h/ Y6 d( X8 v$ i* u; x if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))- x9 t: X* T/ s4 D* s o; G* f# z
{
) r: V& j [0 y# j" Q/ C9 z break;
& u# w# u' w+ w% B) z4 L& v }
& v+ I8 U: P- R. \7 X* s for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)# D* d4 R/ `- r6 V$ J
{
1 W2 n, t0 v. P/ d" j7 u7 p CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);+ p4 X) X+ m8 Z; x, Z' s0 T
if( !pItemElem )
`( ]5 D) r# g. B% v9 I* R0 y% R1 ~ continue;
8 L* k& c" Z E' h D if(pItemElem->GetExtra() > 0)
" }) f" T& f5 f& y' i continue;
t( T# G" y# G" A- S/ Y if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
+ S6 L+ @& ~# |3 @" R+ h continue;; D; `2 y3 N& Q" R3 ^7 g5 D6 m
if( g_pPlayer->IsUsing( pItemElem ) )
3 v' T1 P9 h! Q continue;
, j3 y0 I u0 c3 j5 Y if( pItemElem->IsUndestructable() == TRUE ): O2 `, f8 P$ w l3 x1 L# A
{ i0 ]' d) w6 v$ I7 w
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) ); N% T2 Z4 m5 {1 d) d3 V2 u
continue; D' i7 u% f' X1 i7 R$ [
}
. P% l9 K1 f+ Z g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
* j" p* U! d" X7 A }
2 @" D* J# ~3 u9 S, e: G) v" o break;5 {: S$ y! L: Y
}$ U9 z0 S( B& Z, O8 }
case 1:9 S; k. I* D+ r$ Z. s5 [
{* X$ B( q( R) l! V: q; Q
//整理背包& p' G* C0 o, M# v
//////////////////////////////////////////////////////////////////////////3 W0 k9 C$ h7 [9 l" a: J
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );) {, }% x$ s+ q& X3 k. W
//////////////////////////////////////////////////////////////////////////
! U8 b7 X3 e' {7 j9 P8 y //////////////////////////////////////////////////////////////////////////% C; d" o/ L) s* ?, ?
CInventorySort* pInvSort = new CInventorySort;+ h: O* J0 m5 R; _& C; c; r
vector <sItem> vItem;
V3 E- X5 s" b( \5 U6 h vItem.resize(MAX_INVENTORY);//初始化大小5 ]1 E2 V- q g7 w4 y
//////////////////////////////////////////////////////////////////////////
$ W w0 Q* u2 A //填充数据% L+ f6 b& h1 Z9 N" i- `
for (int i=0;i<MAX_INVENTORY;i++)% N1 H) ~9 X) y3 H0 T* i ~" p
{
% o- {5 i# m: \# D$ x; H CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
1 x' I2 U: [4 x3 p, k' G if (!pItemElem)# f2 z4 X7 h: Z6 v# j2 [7 h
{
b$ g: H) m0 ?, A vItem.dwKind2 = 0xffffffff;7 M0 [; s) p5 |5 i. r- J. O
vItem.dwItemId = 0xffffffff;
. s& @4 J" ]* |" V: W: V vItem.nIndex = i;
/ c0 |" O6 I4 x$ n/ K7 F9 M }else {. J6 c* O8 f+ m" M+ Q u
ItemProp* pProp = pItemElem->GetProp();! N. B8 D5 p" s- ^+ i8 T5 C
vItem.dwKind2 = pProp->dwItemKind2;1 G' x0 x! ?2 `; i5 o- H8 u
vItem.dwItemId = pItemElem->m_dwItemId;
+ O2 s* }% |' p# ^7 a vItem.nIndex = i;
! |9 [1 x1 v3 ?0 V }4 b, I/ g. b/ W& p2 p8 f
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);3 b' j1 \8 D6 d+ j
}
7 b+ r$ l7 G* b& u8 j7 \0 ~, L* v //////////////////////////////////////////////////////////////////////////( j/ J {: h2 [: X4 k3 M0 P
sort(vItem.begin(),vItem.end());//排序
3 I8 F8 `) v' I: z( `& Z //////////////////////////////////////////////////////////////////////////" }/ Q, O/ N/ y6 O: \0 }
//交换9 ~) n7 `2 ]* K |4 I
for (size_t i=0;i<vItem.size();i++)$ ^, e6 F1 k# Y" _! `1 i
{
% j% Q( E3 n/ E9 { //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);0 S" C$ X/ a$ B" O0 _7 z5 k3 r
pInvSort->Add(vItem.nIndex);! [& x) o; a3 ]/ R2 e8 F/ G- d
}1 R6 }6 |( E7 b% Q K- `* Y1 D7 V+ K
BYTE nDestPos = 0;8 I: l8 I8 Y- B9 O
for (int i=0;i<MAX_INVENTORY;i++)6 U P/ F# g4 E# l5 K0 Y! v
{3 L# {" [( Z3 z6 n6 P
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
7 l; v8 D1 A/ i, L9 F& A2 [ if (pItemElem)3 ]1 u4 x' \6 T! s4 O
{
; E- O9 ^8 T* }5 f9 x8 Z if (IsUsingItem(pItemElem))* k a' A. d* X% X3 X' W
{( ^; S0 f h* ]
//这个位置无法放
~/ s( ]! _7 J! G* F* \' Z M* i nDestPos++;8 o9 z7 |$ B3 y0 ]2 x
} ]% {# h( c* b9 l% X" l* ?& A
}
]3 |" D* Q8 z& ^ {& H* C BYTE nSrc = pInvSort->GetItemSrc(i);; e1 |" G" S! _+ q) y( d
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);! n- Z7 Q1 W6 ^9 v+ n
if (pItemElem)/ Z0 s' n( o- ~/ O3 c$ Q" F/ y
{# c6 o0 B5 I. T+ f
if (IsUsingItem(pItemElem))* X9 Z/ q H: B- y! o4 |7 b& K G* ^
{: q( c$ [7 W* c" r6 J0 n/ a' ~5 P( h
//这个道具无法移动,跳过9 E2 [* f$ ]: F
continue;* B Y) J; ?* v7 W, v0 {
}: A! g, g. v4 t
}else{
' r1 q% L$ Q1 d( D$ h, Z7 M //空位置 不用动$ u( ^) G8 }6 N( G; ]: Z
continue;) @2 c: r+ X6 {& b: z
}
" e3 ]8 s7 ?" x6 M5 O //////////////////////////////////////////////////////////////////////////: h+ ^: f- M% |, h( V
//开始移动
! `4 H/ h: B" z; `4 B( _" T if (nSrc == nDestPos)9 F* f. |* {# h9 r1 y: Y
{
4 ?6 R& t. f$ z' ~ //原地不动1 v1 d, J$ E5 f: V( [5 |, U8 g! T6 @
nDestPos++;
2 `+ X7 l! x6 a/ X4 O0 b continue;0 Y! w/ D, I) |! {/ y$ a% N# u& B; X5 q
}
8 x8 s' Y( k! V pInvSort->MoveItem(i,nDestPos);; H [ N* N2 h; q
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
6 \( A% {9 p, x* x4 N' ]- | Sleep(5);
* \/ E t: Z3 f# y //Error("移动 - %d->%d",nSrc,nDestPos);
9 `$ Y f" \% M W( e& ?* E nDestPos++;' i3 B, _8 `7 o" ^0 N: [/ f
}# H8 ]* r0 K' }- s+ t
//取第一个元素的信息
; k# j5 C7 F* p /*$ ?; U+ W+ |2 B# T- |
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
7 D% P0 J5 L1 b; ]- @& U {4 L3 w, w0 J3 r8 Z* c7 P
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);4 @; n4 E1 X; X' g! U
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
; \; Z. i7 s: P) m9 w C2 e; G/ M }
: }. b0 h5 L& o. J */
1 o5 x& w9 |4 ~3 z$ R" G //////////////////////////////////////////////////////////////////////////0 ]1 U- I& Z* ]
break;
) V0 R8 F4 I6 w- t0 m n _3 A* e }
# f% D5 f _: t( R* l3 W: | } / `6 A3 k# L4 i( D" D+ l' }
}, Y. g0 g. a: { F% G8 J' l2 @; B
m_wndMenu.SetVisible(FALSE);
b: o. u/ X5 {" g& e' C w5 S* r( H5 y, \- y
--------------------------------------------------------------------------------------------------------# `+ c$ T# v! l& ^7 d; k! t
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)7 b( a% o* C2 y( c( j8 H) L$ Y
{
. _; h1 P( b. f; p4 fBaseMouseCursor();
& x# k" R& f1 B5 b, ~& `$ w}4 w+ O% u$ g) z3 O7 t# z% U6 t$ s
在其下添加:
# i5 B6 e7 A! Z+ P5 Ivoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
1 H7 J6 j# P: Y8 h2 b{) m2 |- @: D5 N* j! A1 z
m_wndMenu.DeleteAllMenu();
# Q; y' S/ C' d2 k/ Nm_wndMenu.CreateMenu(this);
1 }: o( |3 E ^6 A! i" g) Jm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
) g6 G2 P( R' o* N9 d0 ^4 F6 S8 r/ s" d: X* S, F1 p
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
1 ?0 f: E; j8 d! S{
8 v% _- {8 `5 o2 x" n1 D //P以上级别才可以删除所有道具, b* C8 T: t, \! ?
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
% q+ h6 K, j" s- j* w/ p/ H! V: b0 a}' O6 g/ U* D& J* b. [$ n
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );& Q% y) p7 {7 p5 B
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );. M/ i3 o( {8 a' H$ N6 v* Y. K
m_wndMenu.SetFocus();
, ^: @8 I ]! l, R" d}. j) E) N5 ^/ S$ q8 n J
------------------------------------------------------------------------------------------------------------
5 R4 u7 [8 L7 x, N*************************
) _/ {0 q! s) zWndField.h文件% U& y2 q2 c# i4 ~# z* K
*************************
0 k' s' ^1 m1 G1 r* y搜索:BOOL m_bReport;
9 [8 y u B" @0 t, h1 r其后添加:
: |& p6 E& V9 W( {3 g3 MCWndMenu m_wndMenu;
( J$ d& B% Q R5 o搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);; u; ?2 _0 W, i+ A4 X: t$ \. c6 f
其后添加:
6 x- |$ `6 X: }. M% Rvirtual void OnRButtonUp(UINT nFlags, CPoint point);
! n# x5 f3 O+ ?( x. x' } U4 k! j' L# l, M8 y2 ~ f
* R9 y% S7 t( ` |
|