|
|
源文件中_Interface文件夹下WndField.cpp文件
3 b8 G4 D! _" M* Z搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )+ I3 ^/ U% O) Y3 z
0 W0 y8 b" z8 G# }. Gstruct sItem3 P+ a# o% \1 A8 V
{ ]' j+ O" f3 X# [! \
DWORD dwId;! K2 I+ h% {8 m$ A6 A
DWORD dwKind2;
I- s* Q% T. _0 p* w% yDWORD dwItemId;
: |% _+ n. j; o) T# x9 X, gBYTE nIndex;
+ e/ c/ v R2 s; ^5 ^$ `sItem(){
+ }; n$ M! T$ h5 }3 w8 s9 n dwId = dwKind2 = dwItemId = nIndex = 0;
0 i- m# R+ g# W1 R}3 O" ^1 l1 G5 a
bool operator < (const sItem p2)
; {- g6 m0 M7 S( X8 w{+ a( S* i, j' H/ I: c
if (dwKind2 == p2.dwKind2)
( L) M+ W2 _! c {( C" g- h# L- W" m6 ^$ ?
return dwItemId < p2.dwItemId;
5 z2 D- O/ g: @& F# d2 r6 D }else{
. R2 \, N; S- _+ u return dwKind2 < p2.dwKind2;0 F! A. @4 w# P0 H7 [3 ^
}( T* A" E5 W% v" Y G
}3 X& @- _7 B0 F0 n2 I0 R7 m
};
) Z; B" C) J& F. v" V( Mclass CInventorySort h- e& t$ }. g) B
{
* }0 e7 ^4 J0 B* N9 y8 Ppublic:
. Y4 d5 h+ D2 |+ }# o! v, j" \CInventorySort()( k$ q3 X f" a s( |& n e% Y! Z2 O
{ k) U5 N9 o! l( L- V
m_dwPos = 0;- s ?4 e# |/ w3 Q6 e* b! \3 e
}% L1 a* x8 e3 H# o- x/ u
~CInventorySort(){}
$ w; Q0 q6 }9 F8 s+ l1 yprivate:
: A/ @# b' D+ g. {; F, R& k7 j- LsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
2 w5 u G& M5 W$ i: bDWORD m_dwPos;
6 ]1 E$ R% t% @( T2 Y/ X( \& Vpublic:( @9 A9 {# z3 ?2 Z
void Add(BYTE nIndex)
, Q& \6 E$ K: }+ [& R! T) o{, N2 t m. K1 }& J+ R" Z
if (m_dwPos >= MAX_INVENTORY)" V5 `" _* l! }- t0 Q0 q6 e' V# G
{
6 G* h4 Y0 M! j# [ return;
7 D; S6 R) ^( g }
) B7 }- @0 B" S! r( v) J+ @. E7 U. ^ m_Item[m_dwPos].nIndex = nIndex;2 ?0 l( b$ E5 z) \
m_Item[m_dwPos].dwId = m_dwPos;
0 n" J9 S" e+ S4 L# O8 W m_dwPos++;- x4 k/ ?$ U1 l! N5 {2 A9 D
}8 T8 W! A8 g9 m2 s+ R
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列) C5 l% Z0 B# D" m1 j& Y3 O
{2 W2 {' a$ R7 k8 |- M7 t1 ~+ I& P8 b
for (int i=0;i<MAX_INVENTORY;i++)) c3 h2 ^1 ^, S, h0 H
{
4 Y S; H( c1 |- [, Q. A. q M if (m_Item.dwId == dwId)
* T5 s* n6 ^$ {0 r( L+ @6 j7 g {$ F& k3 o3 w( `* J5 m0 g- A) h
return m_Item.nIndex;
' C( G/ D) ^# A* M9 a }5 [5 m2 R+ ~" k ~+ ~4 f5 o2 r
}( m, w* z. h& F
return 255;$ \/ x6 o/ ~5 j1 s, R4 p
}3 B, S; m2 S0 i* o4 }: t
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置& l8 C- x) Q9 N
{
5 n+ X: ^9 R* H, G8 B4 Y* d BYTE nTmp = 0;3 P* w: v: [* }2 z1 B: V
bool bDest = false,bSrc = false;; n3 ^# k) |9 x. @$ ]
for (int i=0;i<MAX_INVENTORY;i++)( Q3 z( i7 S8 i% z* h* g
{
( C% X* }' O! M if (dwSrcId == m_Item.dwId)
4 U7 k ]5 X: L: [# E {
1 W' _2 L1 d1 Z //id相等 则 改变对应的dest和src( y; X% ]" W2 [
nTmp = m_Item.nIndex;
$ W- a8 W1 q4 h2 e8 E2 Y3 I7 a( y m_Item.nIndex = dest;1 t$ K: }5 L5 F# N P
}
2 N$ q: ]+ a% r3 u; o3 u; Q5 F }" C' W) E7 U7 t, t. g
//临时数据保存完毕,交换开始9 ?, G s' p$ H0 G/ q
for (int i=0;i<MAX_INVENTORY;i++)2 x, |3 N1 _3 D
{. S, X+ }6 E6 b4 ]% M! j
if (dest == m_Item.nIndex)7 ]+ G6 c& Y3 U+ v. T) C. w9 l
{2 e" p! e3 ~1 l7 r2 k
//id相等 则 改变对应的dest和src y( v: q0 n3 i J' W) h
m_Item.nIndex = nTmp;6 U2 ] l2 W7 e+ K- J$ R5 F
}
8 w( b! M/ D, e9 X2 z }0 c0 m" B0 a4 `1 |/ F. ]1 A& ]
}5 q3 m2 u- W+ g# b Z8 V# Q( k: t! y
};
* u7 h% C) W: q# L-------------------------------------------------------------------------- ?- Q# L* _. R: l& M% f# u6 U' J7 P- Z
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )* }! P4 s' B9 |$ r, Y2 H
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
$ C9 W0 d3 [# j* N Z$ k紧靠其上添加:
5 `9 @1 L3 L- a4 z4 `8 bif( pWndBase == &m_wndMenu )2 z. E7 j) s) E! c8 Y3 Y1 O: n: |
{4 L/ a0 ?* Z) V- [( d7 W7 ~, A# O, T- ?
switch( nID )# c, ]' V% R, c" e2 v
{
. \! P7 x+ W: y case 2:0 o5 f3 E' y D1 F5 x* O$ [
{2 w q' d4 e) N6 u4 `0 @
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
& g- |: X& v# | if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))5 N0 y" ~ Y# w$ y
{6 B( X' Q( H# K H
break;; Z: Q W5 N% z$ I8 b
}
& J% _+ I9 p1 K& N5 N for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
3 f2 Y* r& w. q5 o. `% h/ a$ P {
* I% |( L. B- p" E( C CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
' n l9 v+ g8 P, Z( Q; ~& e% V if( !pItemElem )% I) g/ C o' d% T2 @: w @" w9 w
continue;
$ R7 F; O5 v: g9 v7 U8 a if(pItemElem->GetExtra() > 0)
% P s3 s% X# R$ p+ [" D continue;' t2 t) l, [8 i/ Z7 m4 R
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) # E8 _- l# l: v: s. K- }# b$ M0 z; v
continue;9 D) R! z: ~% ]! O5 O& k- a, h
if( g_pPlayer->IsUsing( pItemElem ) )0 P$ D- g0 d: ?. O- B- X
continue;9 A! j* E, w6 W6 [
if( pItemElem->IsUndestructable() == TRUE )" _7 I( v G6 o, b- D) O
{# a6 P+ w: J0 A! R9 d x. V
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
( p# [, M& o& A, ^) } continue;
$ t- A: Y, A4 [ }! j6 _2 e- F- |9 V0 v& J
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
3 @5 Q/ r- s3 R }
. z: m) f3 N ]$ J- B; v! A break;! z! F/ N( G/ }. u1 R$ V1 Z J9 F
}1 z3 {1 x w9 g( ?, F
case 1:
4 r$ j2 c! ]0 @% I! }9 ?7 ~2 a: B {
( J) A/ b. K$ z* \$ j' q6 a# J //整理背包, N; M9 [9 v! U7 X0 h6 @
//////////////////////////////////////////////////////////////////////////
8 v1 o7 g0 g( v. F7 f0 h& [# D //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
+ ?& f2 _5 {% \' D+ t. n: x //////////////////////////////////////////////////////////////////////////
; N1 d, X$ r: N, r4 e //////////////////////////////////////////////////////////////////////////
7 y; f9 g4 v$ q8 ^) c; [& u CInventorySort* pInvSort = new CInventorySort;
! l% b: R- _9 g) H7 X vector <sItem> vItem;
* Q- o% o( B/ z+ T vItem.resize(MAX_INVENTORY);//初始化大小
% g% u: O! v3 A, ~6 z8 n //////////////////////////////////////////////////////////////////////////
6 F" ^8 C2 N( g% P$ Q' e //填充数据
( J- t* y2 H* p& a1 U1 c for (int i=0;i<MAX_INVENTORY;i++)
% G: V+ d4 R4 Y3 i, C* K1 K; c {' s! R: Y" T# L
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);0 E: j1 i+ u5 X4 {9 _# O
if (!pItemElem)3 [3 Y/ t" I$ w
{) {5 I6 h$ {/ y% y; [
vItem.dwKind2 = 0xffffffff;6 f$ N c) I2 u& y9 @
vItem.dwItemId = 0xffffffff;
; s0 t, M. W0 E8 t; s vItem.nIndex = i;
+ n$ R3 Q! D4 a8 ?! Y3 e }else {5 y# z' y* F: G/ r8 k2 g, C
ItemProp* pProp = pItemElem->GetProp(); `6 f' b- z7 x- E( L# }
vItem.dwKind2 = pProp->dwItemKind2;
; I8 P* d' e( m vItem.dwItemId = pItemElem->m_dwItemId;/ f% H+ Z5 S4 G% I6 P$ A
vItem.nIndex = i;4 H/ P4 @! u1 i' s2 [9 p
}4 S& l$ `6 A0 k+ o5 k1 J) v# I2 g( l# |
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);( T7 D. {' n6 I1 I/ o
}5 X- s6 a& X* K" n. q- g$ J
//////////////////////////////////////////////////////////////////////////' Y$ }; _; x8 W
sort(vItem.begin(),vItem.end());//排序
/ _% M7 B7 ~) v //////////////////////////////////////////////////////////////////////////
* n B( r0 I* N( c" B //交换
. H" z# t% H1 B( \, j for (size_t i=0;i<vItem.size();i++)
& B) e! t6 s# j0 _ @) [ {8 v% ^. ]; I* [& v: O
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
! t- ~( _4 a+ U1 i0 i+ b pInvSort->Add(vItem.nIndex);
* X8 g. G9 ^- G' Q6 q+ V }
; i$ t3 s: t: u$ |; O- b BYTE nDestPos = 0;6 z, i# X/ d% Z8 T
for (int i=0;i<MAX_INVENTORY;i++)& C, p2 t: K- V9 d( E+ B: {" C
{
0 n6 m" v. l9 x+ V3 a$ M* D CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
# j7 p4 B J$ h. l E( w9 G if (pItemElem)
: E/ r; v# ^: D* V {+ B" a0 k" e5 }; X
if (IsUsingItem(pItemElem))6 I3 k b; e* K( M. y
{( t4 k. {9 ^5 ^# P# M
//这个位置无法放; f, n! p3 N, E* S) W! o3 n; I
nDestPos++;/ w* S4 ~: y; c7 `! Z, L
}
' [2 R& S! g! _* d }4 R( V; `: w9 R) F5 A$ Z9 B
BYTE nSrc = pInvSort->GetItemSrc(i);
* T; j' y% j/ ]! k pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
! z* {# C( m) ~" ~4 N7 a) L x if (pItemElem)
) b" w- G+ W9 e+ @ P& q {
) O) n1 Y+ {+ u6 ]9 L9 l$ h if (IsUsingItem(pItemElem))
8 l+ _& k& @7 x& { {( O+ A9 L7 d; i5 O. j: W6 ]
//这个道具无法移动,跳过
1 u- O. I7 R( S! V# |) l5 a1 l continue;4 s6 a, y8 u, J0 u+ N2 z
}
# F' p+ r0 G: P4 i+ X }else{
4 @8 \4 S# ~3 [1 }; O" ]7 @& f$ m //空位置 不用动
6 m" {' C5 C* T% c2 ]6 L continue;) S! `& f% ~9 L/ [ Y4 z
}
% [* o, i( M5 {/ z //////////////////////////////////////////////////////////////////////////
4 x+ W% D4 _4 i8 l, K+ W //开始移动
0 W. S4 C6 B2 ?5 T if (nSrc == nDestPos)$ n- U& ~/ }# ~ p- q
{' S* b$ Q+ J1 i! {# q
//原地不动& u# c2 d( s1 H4 v9 n+ D
nDestPos++;* L; X/ R* K* W! i
continue;
% L& y/ R9 ^4 c }
. N2 h2 |$ T; @2 `" V pInvSort->MoveItem(i,nDestPos);. Q+ ^3 m9 ?) n: U$ \/ D! N3 ~
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
/ k4 H( j8 s& x Sleep(5);
5 \ W, O/ z2 U5 U //Error("移动 - %d->%d",nSrc,nDestPos);: U( A! h# m. V: n! {" h5 [
nDestPos++;% |! } m: E2 M" v5 U/ g
}
6 Z! ?( e4 H- r //取第一个元素的信息
1 O0 \8 c+ B2 a% N$ r- q! W /*7 O; [. c' @3 e$ c) x" @1 U
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
& Y9 ~+ c5 ~/ W2 w4 W {
1 N b! v I8 D Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
' ]/ f1 s0 i1 I g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);" M/ z F& X6 e! m9 C) W) H5 k
}, ]0 n/ G* T; X4 v% K
*/
F# ^8 j, o9 k I9 \ //////////////////////////////////////////////////////////////////////////
j# O" y3 k) F break;8 M+ [) [/ c, }3 _8 W1 v: c8 J5 z5 a
}
, r( z8 v- D* W. n! p* C: e } - d7 n- m# s, B. D& E
}
$ V' ]8 I( u9 ]) k' am_wndMenu.SetVisible(FALSE);
5 Q/ H# L: N! f' [; i& ?
3 R* o8 H" Y! c6 d# c' ]--------------------------------------------------------------------------------------------------------3 h7 g5 r! X5 u4 v" K
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)! H3 }" J1 |5 F0 h$ ^
{
: V, U( F9 H8 T% d9 u4 T# rBaseMouseCursor();
: d% M; g4 _8 q& @. o2 s, {}
, p: s. d: V6 Q% e; I* o在其下添加:
7 y0 x: D# e6 Q# l ^2 [9 avoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point), m$ D4 `" u: k# q
{
; y; u3 L2 F& D+ tm_wndMenu.DeleteAllMenu();
0 P3 [- f! E# Nm_wndMenu.CreateMenu(this);2 M( G0 y! e; M8 r! d/ T6 b
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
: J( ~6 D: O: R) z4 U( W" T' _ n8 |* B
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))7 `; x6 g( T4 `7 |
{; o+ p R" |$ m
//P以上级别才可以删除所有道具 z8 y; a' H' m' W6 R" D4 `, i
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
$ F0 J0 A0 `2 e! z, ?6 j* D- D+ g}; ?# z2 F4 _' |: R
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
0 b4 K) k( c2 b3 h' p( Y7 D) Jm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );8 U0 W! h! _8 K+ j; }2 \) \6 @
m_wndMenu.SetFocus();# i4 @5 @# a N
}
: h: S* g; |& B( j2 c" z------------------------------------------------------------------------------------------------------------
% g, x: _6 b2 p: h& W*************************/ L) ~- i a/ V( Z
WndField.h文件
# `1 t! B( @4 X- A*************************
# C( f' X- ^1 R搜索:BOOL m_bReport;
& p" k0 `. P; l4 @! \+ ^其后添加:' e6 X& x, N* W6 `+ \ _' e: J. P
CWndMenu m_wndMenu;" p( ]$ G) e5 I6 Q3 f! L
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);/ w1 u& ^2 D, ^% d9 X
其后添加:
$ a1 {% y1 ~7 Y" _) Q. ovirtual void OnRButtonUp(UINT nFlags, CPoint point);
( O" K( l6 \5 k( e- s& J; ~* {
/ ?& w, E" _3 q3 z3 q, x
8 M0 d8 A& t t |
|