|
|
源文件中_Interface文件夹下WndField.cpp文件+ u$ l% n9 ~) t$ L, p1 q
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
3 h+ Y) T8 q2 M \1 ]6 h8 r& a, s
# ]; [+ \/ _; z6 f; U. ]struct sItem3 ?# e: Y$ ?) P ?) {3 ~" |" C
{
& p( \# b- K, M/ `, Z) KDWORD dwId; Y, ?8 }. E& ]2 y* F* c% `% U
DWORD dwKind2;
+ t! c' S( Y% h6 R( W5 ?DWORD dwItemId;
v6 r& i1 m' ]- O" rBYTE nIndex;; t) N% L4 \8 W
sItem(){
7 v- B/ m3 x. X$ S: C dwId = dwKind2 = dwItemId = nIndex = 0;" k2 j5 d p7 M+ r' x% F
}! q8 p7 s/ ]/ a: Q) S7 ?9 t( n
bool operator < (const sItem p2)' M0 G% l& r! r( L7 {
{
' r+ K1 H8 a) }. S4 O if (dwKind2 == p2.dwKind2)2 `( z; b7 `: Q3 k! l
{+ M7 m% `3 S" H. ~+ l- ~" i) m, ^( l
return dwItemId < p2.dwItemId;3 r* J2 v$ T G
}else{
* @7 C" [2 e5 `8 q return dwKind2 < p2.dwKind2;! Y) i5 V; M' Q+ r) {- P& m/ w' Y
}
9 V/ }! ~5 n! s8 M: @}
( n" S4 K8 v9 \* n [4 ]; g};7 {2 M9 K. ~7 W" [0 O1 P4 A0 y
class CInventorySort) X, |0 Z$ p% N5 b3 \: U2 X% b5 P
{
- t& ] \) O+ T6 R; v; Qpublic:
& M `" m: X3 S H8 F- HCInventorySort()+ a. k7 Y( l* m1 ?8 O4 t0 |
{
; `- r3 ?. h( q/ t/ V& y' [ m_dwPos = 0;+ v! G# }$ y7 X# k
}7 p7 ?) x- g: E; c* P' Y2 t
~CInventorySort(){}+ Z( ^0 k! t0 m) C0 l* p9 g
private:' f, L9 {' |% [3 y, `6 e
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
3 L: u6 x7 g- u0 XDWORD m_dwPos;/ s# f" Y. h6 s: j2 k
public:& }2 f3 B+ @0 E4 P
void Add(BYTE nIndex)
% S: r& I r2 Q7 x{
8 ^) R- a I# w5 F if (m_dwPos >= MAX_INVENTORY). E% ^3 l( w" {9 w" v7 j( t
{7 M R# U. n' t% x- G' G* W0 F
return;
: N; a9 ]! n9 ]) V, i! S }
/ r9 D5 f" r" w m_Item[m_dwPos].nIndex = nIndex;
, y$ z% n n8 x m_Item[m_dwPos].dwId = m_dwPos;
# e, H/ p; X" i, B0 b) T m_dwPos++;: W( c0 J3 o. d7 B
}
& l9 M+ C! C0 O" I7 k( EBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列2 `2 a8 e& {, B+ w/ R: m. ], Y# Y
{+ h G7 g: T, V) a
for (int i=0;i<MAX_INVENTORY;i++)
! e1 |8 e! F3 L" K5 g- K4 C {
) {% h/ P5 y6 S e. @ if (m_Item.dwId == dwId)& P) j. q6 g- |" c( O% l# T
{
8 d) ^- S. z: Y return m_Item.nIndex;( }" K2 x1 D; G( O% S- {
}
% ]7 I; f: E# d5 ^ |8 D }
; [) j" z; h+ u/ D& s8 t return 255;
4 K; g8 _, K$ P/ P+ `& j}1 ~" m2 H; ~8 ~* N- s
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
7 X4 y% a/ z- r- i3 G' _0 {: S{* `1 v/ h% P9 [/ j w
BYTE nTmp = 0;. e9 G. V% Z! r5 R2 t. K
bool bDest = false,bSrc = false;
( t1 D# O4 u: F& Z for (int i=0;i<MAX_INVENTORY;i++)
$ J# y7 z+ h7 [; d: d( C/ a {
6 u+ q4 ~: Q, \- | if (dwSrcId == m_Item.dwId)
$ J; m1 D( \7 X* w$ _6 O {( {$ z0 I! t9 ]" @$ r. V
//id相等 则 改变对应的dest和src' Z" X# ^) @" v1 A8 j8 q( Q# E
nTmp = m_Item.nIndex;
4 u( ]: A$ l$ J8 G m_Item.nIndex = dest;* c: L- T k" M/ |0 x
}
3 j. _- _, O4 ?- h* U: b }% L7 y, c" k# q' f( P, t0 @
//临时数据保存完毕,交换开始
, b' e5 X/ w% b. t5 f6 ^, ^/ l for (int i=0;i<MAX_INVENTORY;i++)& {# |- R+ @0 e4 K8 ?
{
. R+ B5 I" D2 F0 d) N$ Q, @ if (dest == m_Item.nIndex)
' t% P8 k7 ~ ?" _ {8 @: l; [5 }: U" V! `
//id相等 则 改变对应的dest和src
: e: |& _+ T" ^- G# N/ E7 R5 o m_Item.nIndex = nTmp; h6 r# w) u x% G( @
}" C I% q x: ~
}
( f1 q3 J4 J7 L3 B7 j9 x}
9 u/ ^$ |2 V6 S0 P+ _};
, l3 O% t# W2 r+ j0 f5 ^- i; \9 E' }-------------------------------------------------------------------------
9 D, x8 i0 {' l依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ); x3 ]$ ?3 k( o, d. y# ?
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
N; x! \% K+ @/ h" M Z紧靠其上添加:
5 E0 V$ ]" i: o( t2 M# {% _if( pWndBase == &m_wndMenu )0 c7 X6 F% [3 d) a* [
{
7 V1 T8 N# n0 u8 n/ E: S switch( nID )
6 N" ^6 u+ i/ P6 W) W0 r {/ p( J4 \& g! J7 j
case 2:
3 l; \6 K9 k; O5 h$ ]& [ {; c4 F( \8 P( d; O8 e# C
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
7 w! i! P3 v. k' | if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
7 k3 R. D# c! U+ J5 j( X {0 s% F+ s9 c" C1 _7 e
break;
- l! y1 K& ^7 D( S% o% A+ S }1 ?3 L+ `) I+ Y. o
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)% L) Y; E/ ~: h. \! h( e- x9 \
{& o }0 [8 p+ U1 j1 M- _7 z& w1 x
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i); u6 e7 T: b I# C; E5 [
if( !pItemElem )
9 a- y( u( U& Y n' ^+ S9 q7 ?6 u continue;
B; T5 d4 R6 r" W; m if(pItemElem->GetExtra() > 0)
* R4 [6 Q6 b. l( Q/ ~ continue;+ l. I- k# k$ [: z, J
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ' I' B' g" o' p: a% J
continue;9 r2 s5 G' q! l1 a8 S( G0 C
if( g_pPlayer->IsUsing( pItemElem ) )/ _) P7 H0 ]' g/ f) U: J
continue; a3 Q9 {8 N* W
if( pItemElem->IsUndestructable() == TRUE ): i' C4 Y0 A' j/ k; _/ O
{
* K" T* H" ~) E" d% V g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );7 W% |. V4 L( n) h" z
continue;! V9 j( ]$ y. {. h
}- L% |; p G8 A7 t) ^7 ^# b [
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);5 _+ |& h# B+ b4 d0 v. ~5 d8 g; C
}" B& X3 a& d2 M# ~& x
break;
( h) @* S2 ~% B% K7 F }
; a5 `7 f+ E" \+ u5 Q4 h, S ~ case 1:
9 a6 U! i$ ?5 c' D6 Q3 ~7 _ {
( a* w9 L0 X6 |! m //整理背包
2 I2 k0 M& e$ ]0 u! y8 b //////////////////////////////////////////////////////////////////////////
0 j) _. G% r1 H8 Z; W0 t, d //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
# U( I: t- M) `$ s //////////////////////////////////////////////////////////////////////////: }/ y: {& G# c
//////////////////////////////////////////////////////////////////////////
# K% @1 L) @ Z" v2 S CInventorySort* pInvSort = new CInventorySort;
# h! S& z" T0 h& ` vector <sItem> vItem;. j5 ]; }+ Y( y6 M
vItem.resize(MAX_INVENTORY);//初始化大小
( \! e7 n2 L2 P- f& X. r( w7 T //////////////////////////////////////////////////////////////////////////
4 O; U9 e3 R, [- T3 T" ` //填充数据
% H/ N" O! `7 }2 n6 o for (int i=0;i<MAX_INVENTORY;i++)
0 u0 j* A6 q- W0 {* A- e0 o {% I j( }# M) n$ i
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);# E4 Z. i! F2 n( W7 t
if (!pItemElem)
: D& x. }: t9 Q$ U" {3 z# N/ ^% L3 X {
7 ~: K$ } X9 t- z+ A' l& H vItem.dwKind2 = 0xffffffff;9 Q' o+ m) O5 \
vItem.dwItemId = 0xffffffff;+ d+ {( E, A4 r' A' O- Q: z
vItem.nIndex = i;8 {0 x' K, p2 w* q0 J
}else {; i' b6 N& z3 G: d% O+ I, a7 A1 `
ItemProp* pProp = pItemElem->GetProp();
: V8 H4 v( l( H$ R0 Z8 u vItem.dwKind2 = pProp->dwItemKind2;- c5 d. N9 c" N, t, X! l
vItem.dwItemId = pItemElem->m_dwItemId;
' L9 y$ V* p: v: t vItem.nIndex = i;
a+ A, N! B' w X9 m& b& Q }
+ m6 p, p- ~# [# ]/ a //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
: d" ^- |. R2 } }5 s U7 c) {- G+ M' `& P a
//////////////////////////////////////////////////////////////////////////3 G* m, T$ C! M6 j" N- D* y6 k
sort(vItem.begin(),vItem.end());//排序 m1 J' w* f0 x! q' X9 Y! {9 ?
//////////////////////////////////////////////////////////////////////////1 D3 X6 f i0 k! d" ^$ K
//交换
' z8 W! i. s d" \, r6 Q* F) R for (size_t i=0;i<vItem.size();i++)
: O- f1 Y- M/ X6 E2 l {: P7 ^, }$ R3 N: K) o& _: d- b
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId); W$ E- v" {: W& R4 `
pInvSort->Add(vItem.nIndex);
- Q/ J* H: C) b8 d W, D: }9 p: i# Z }
/ F: `6 h' ?% n. e BYTE nDestPos = 0;
) u$ }# z# O5 x4 U/ [. U* ?$ u# G for (int i=0;i<MAX_INVENTORY;i++)
$ I6 U5 {" |) w6 { {! e" z5 ~ L! R0 @) X
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
; U9 ~" u, H% a) {3 i$ f. [2 w/ b; W if (pItemElem)
8 I0 j. y1 c0 h8 E0 A9 m' b1 u+ b {' r" u$ ]1 E" P6 l/ B/ _4 n- j
if (IsUsingItem(pItemElem))
4 { Z1 X- H' M6 s$ y( {9 l$ l( M {
; L8 S2 o5 T2 [- O# T //这个位置无法放
1 C/ k- A! \3 l; ~ nDestPos++; D6 J5 y c0 c, l/ C& _
}
* |6 i$ ~9 @1 w4 f5 x }8 i y% n' a% y& l. N% T3 ]6 T' u
BYTE nSrc = pInvSort->GetItemSrc(i);7 d. d! I/ `" P& }5 X0 g4 f
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
* T' s" g- o& N h& s4 L/ W, e if (pItemElem)
, Z M" P, T) g1 r/ Y" n {
5 w1 v# K% k% Y: Y) L( J/ t: e if (IsUsingItem(pItemElem))3 q1 o: Y0 B7 R' P y3 a
{
D8 A/ Q; g1 e6 K //这个道具无法移动,跳过
3 Z. S% w T8 T& o continue;
, b% v% o9 r7 s2 l/ Y; M }) ?$ p5 x0 A" i9 y9 A/ b9 Y- @
}else{/ u7 t0 q+ M# D: B/ \
//空位置 不用动3 P& ~8 G% ~/ w }
continue;. h; r7 b( K5 x# `! K
}' `9 [2 D h o/ J( t4 _
//////////////////////////////////////////////////////////////////////////
* K b0 L R+ C( N7 v //开始移动7 b! u6 i# S2 c5 Y
if (nSrc == nDestPos)
% V1 Y9 i# L# U! s {
" Z4 q6 C# j9 ~+ z" M# J: t //原地不动
; X: i0 J$ e! E6 B- h" D; y7 @5 K nDestPos++;* G2 R- f* B9 t2 |* o( F8 X9 e1 }( X
continue;! c5 d/ X( M5 f, {
}0 t) c9 i1 n6 f1 W
pInvSort->MoveItem(i,nDestPos);# Y+ ^- p5 X0 u8 W
g_DPlay.SendMoveItem(0,nSrc,nDestPos);* i" A, y" E- q' M! Y6 U/ Y
Sleep(5);
3 h1 _0 V: ?' G8 o. l //Error("移动 - %d->%d",nSrc,nDestPos);% D7 w/ C$ q/ Y( i5 K4 m8 p8 e
nDestPos++;' \6 f% i4 N: p# [
}- y# n& _& f6 x2 t4 b$ [9 ]
//取第一个元素的信息# W6 m6 I1 F% `0 |( d: O
/*7 K! g8 i" `: \$ W7 g, I
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)/ @5 T# v- x+ z6 Z( @# G. I7 h$ I
{
5 y v8 H& D0 f Y$ j! L- u Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
. Q, l% Q, n* r) I+ Y g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
7 ]- K! G, l( m! e }0 d" C. {: B9 y, G
*/
2 j! I' u3 ^$ O- i- X //////////////////////////////////////////////////////////////////////////
! Y% ?( N5 r' ~4 P break;% W. q1 E# h# v: E- \+ W7 }" }
}
) J4 N( A! |* ]# Q5 n: v L } + F# K8 o4 w. X
}
% T/ W8 N. F4 Y2 P' G8 \. }; K4 Om_wndMenu.SetVisible(FALSE);
, P" {' M$ h) u2 ] r6 @/ W9 S
2 ?/ d. c8 }* T/ U--------------------------------------------------------------------------------------------------------
8 ]6 }' j! W) m( g搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)8 g( {9 [$ \% Y) s: S* _$ a; W
{6 y. l" j9 q. ?6 i* v
BaseMouseCursor();
* g) p* g) K0 o# N6 q: G i& i6 x}
( U7 H) y, P4 r% E: } y在其下添加:
: i8 a" y( P5 [/ e* ]void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
+ K& O# F0 [* P$ Y$ S{; G- X7 J& O* t$ X7 A, d# D
m_wndMenu.DeleteAllMenu();% p K7 O' u/ B& @: |+ u+ _
m_wndMenu.CreateMenu(this);: F0 X7 h* f/ X/ [6 b
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
" {, K: P' P5 ]( U& ~2 Q6 _2 b! {5 R+ l& Q; f
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))% B/ _' V4 }# T$ \. L* X8 k
{6 W! p q/ y; [8 M+ {
//P以上级别才可以删除所有道具
2 Q& n2 {. |. h( z/ ]" z, N m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
. H, T* Z+ n4 J! G- T}
3 [, X" X* W; U; S' r }m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );4 p$ f7 p: `$ B$ C- r
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
, H2 M7 M! d. [1 u5 k) [m_wndMenu.SetFocus();3 E' I. H& U* G" Y" p0 d1 b- d
}4 c; z# T: z% t( X4 V. R8 M4 n
------------------------------------------------------------------------------------------------------------( @, ^) q! J# ~. V, c/ n9 Q- i
*************************3 _) f4 n9 Y2 h9 b2 \+ A
WndField.h文件
, i2 e8 y( ]& ]0 t/ S*************************
* \1 w4 R- c, k0 y Y. X& O+ Z% V0 t搜索:BOOL m_bReport;
% S* Q7 ^) w- x P% j7 q& h其后添加:
7 o% B& W, Q& i) T1 f9 C Y+ ZCWndMenu m_wndMenu;
0 ?' E! W4 `# a$ F7 Y" [' `2 `搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
& w( x( w1 C1 P其后添加:2 e6 j! E6 T/ K
virtual void OnRButtonUp(UINT nFlags, CPoint point);
% |; `6 }& s; q
. _* J9 P# e3 b3 u: ~
( A8 ^) b. }+ L' P9 \3 m+ l |
|