|
|
源文件中_Interface文件夹下WndField.cpp文件$ p& q I) N. T0 {* V5 v! E
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )9 x- j; n# E2 l
4 l1 `! g$ A+ v( B0 @& Q
struct sItem# Z a* J3 R. Z
{# a' |% @- z& w9 `7 F. a
DWORD dwId;$ J! H* o3 y$ y8 S( ~
DWORD dwKind2;6 ^6 J) q( C4 M7 z, _9 O i
DWORD dwItemId;
1 Q0 E2 z0 n% }5 bBYTE nIndex;9 D3 ^/ I8 }3 ~3 _ n, n! O# ]8 ]
sItem(){7 m1 n& G) I, L4 M( {* ^
dwId = dwKind2 = dwItemId = nIndex = 0;
" E/ m7 G( B; ?5 F- m}
4 M( U; ?, y0 l$ v* ?$ b$ z) @bool operator < (const sItem p2)$ `2 J2 S( z, I: R5 d5 m1 E* q7 ?
{' F+ Y" {9 x' E
if (dwKind2 == p2.dwKind2)1 _4 K; I% O3 X, d& @
{( O. Q! Z4 e7 P' F( @: y$ e
return dwItemId < p2.dwItemId;! N. s% t" Q5 d5 d
}else{; a& q# l/ ?) L4 q
return dwKind2 < p2.dwKind2;
% N8 e8 M" `0 n$ K% ?1 `2 G% S+ a }) Q8 _4 L; \7 B/ i" C
}
& Q+ z+ \# I( P, A* I d};
: g) t2 a$ j) y3 _8 _5 }1 |class CInventorySort( V8 O; s* t+ L. f
{
) p# A* l6 \; y8 C4 `public:
/ B4 a4 x8 [' f" K' K, i( o3 `% JCInventorySort() G- f) O$ b; {) y6 ?
{
& m2 c6 \6 [& a1 } m_dwPos = 0;
3 @. r5 _" a# s}0 S; X5 m, h9 u, M7 K# @9 S
~CInventorySort(){}' g6 J E8 S( n- R7 o
private: }/ N$ C3 m: O, S$ [% e5 b
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
# n4 j0 \' \& h' @) ?& l1 x; jDWORD m_dwPos;
+ `* w+ L9 Y; ?! M5 V/ xpublic:8 h6 \$ `0 s+ G$ {' }
void Add(BYTE nIndex)
0 t3 n0 j0 b3 o3 k{3 G( O& E' o/ m" e( |) R
if (m_dwPos >= MAX_INVENTORY)
$ m( d* N8 `+ \ {
6 H) x) _( V8 v0 Z# z" k$ y9 ? return;
8 r0 i* ?$ T" [, c3 z+ H' ~6 @ } N0 `) W2 O' u
m_Item[m_dwPos].nIndex = nIndex;' D* ?( g' B5 L2 y+ V* D7 {
m_Item[m_dwPos].dwId = m_dwPos;$ ~- i' A y# P2 I' u+ H( R
m_dwPos++;* T8 t' o0 p$ {
}- }; {& V; ~- ?2 L$ f+ E: H
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列5 M2 J% f+ G) C$ [
{
5 l7 H' V. V- t; o for (int i=0;i<MAX_INVENTORY;i++)6 p# y0 x7 T! n
{
+ {, t5 N+ n7 `" \6 m/ |$ O. i) H! i& m if (m_Item.dwId == dwId)- }. H8 j8 L: K0 b/ h+ o" }
{0 d3 b2 I' n/ K
return m_Item.nIndex;* o* ]1 G! c) ]. v# l
}+ q) f0 O7 o* X$ U% i: h; r
}5 {( O8 N' w& `( D0 I
return 255;! b* u: C; F R% N9 m
}$ n# u" \4 E9 g& a) E
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
/ e8 Z1 I. J _9 j. ^; K{6 P' @4 m4 B7 Z9 M1 X$ w$ H
BYTE nTmp = 0;. Y) n# O+ ^/ n
bool bDest = false,bSrc = false;
# O7 N9 D2 T7 |1 I9 v1 H+ G for (int i=0;i<MAX_INVENTORY;i++)
8 G1 G! {# l8 b6 F {' h( A/ R. c: f, F
if (dwSrcId == m_Item.dwId)
* ^- Q/ D$ |1 X7 i$ l+ D {$ N7 x V0 p& \9 H! ]8 c
//id相等 则 改变对应的dest和src
1 z/ m3 }7 a. ]- k( g nTmp = m_Item.nIndex;
/ E+ Z) q. x7 U) U' H B m_Item.nIndex = dest;9 T$ M a0 m+ W. {
}
/ b; S. }0 L+ O* g; {0 R }% y8 r) M2 d& A- W$ q. l+ @0 i
//临时数据保存完毕,交换开始
6 Z6 l' E, R5 f- j( h0 U. w for (int i=0;i<MAX_INVENTORY;i++)% [( ]# j/ S! o4 X; c% A @6 y
{& c7 h+ I+ |9 `, Z: X, K
if (dest == m_Item.nIndex)
+ | x/ a' W; {$ C ?2 C" N. ?- ? {& U& P* @5 U" f# r, o
//id相等 则 改变对应的dest和src
- r* {7 c! L0 M+ E2 e m_Item.nIndex = nTmp;8 C" Q: y2 \/ ^- B- m9 i2 f" s$ R2 S
}+ R1 V' v% ~/ f" z) [0 O& R
}
, a1 |0 y0 r0 D- g}
' o, N, z' [) \8 i9 F};8 ?9 c% f3 t$ D, @) q5 Z/ N) m
-------------------------------------------------------------------------( B1 F- \( J& G0 l9 c3 d. C
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
3 P4 h- E2 s7 }' E6 _, w搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);4 A! q2 {3 v. Z6 F* J- s. E
紧靠其上添加:) ?; h7 C( J9 B3 p7 w
if( pWndBase == &m_wndMenu )0 W+ g: Y! Q, D- g2 I
{/ C/ K2 K2 Z" f5 v* w' [/ h5 V
switch( nID )1 d' M! i! o$ d0 v, ]" I; d# B
{
3 d1 p# ` u+ F; V k case 2:- R6 P5 {; v$ X- @! T5 @
{
+ ~% ?7 u4 X( B) \+ u6 g( T/ Z //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);; C. q0 w1 X- Z) `) g! F
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
1 }2 E! W: q/ Y+ Z3 x {
! O' t r+ Y# L- Q% p break;6 y# v2 g, \8 j- H
}' ]% H+ B. p- |
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
- M) P+ `4 U( R D0 x( J) i( a {
3 ]/ U/ t% z1 M% b% B% U' l CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);0 J- ]3 X. E: ?$ x+ G
if( !pItemElem )! c3 n0 g5 G; ~+ _ E" v. H2 b
continue;
+ h# b! e" h" I3 h. E if(pItemElem->GetExtra() > 0)
0 r2 x9 c# x/ x8 a: p continue;
& t1 C+ e8 H6 L8 Q0 L, u if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
9 V. k1 x0 U) s ^, y& j1 G continue;
j l$ w" |7 r1 x! x2 j if( g_pPlayer->IsUsing( pItemElem ) ): Y' Y$ F4 L8 U# q- S; ?* p
continue;, D; v% j9 v& ^7 `* Y
if( pItemElem->IsUndestructable() == TRUE )
" N- M. n% r0 u2 D {
1 T8 e1 `# }/ z1 B+ o3 J g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
! R6 E1 {" V6 F6 y8 Y continue;
- b! m* [1 U, \" C }' M, {, K- N6 U0 c9 j- m
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);0 N% I2 t7 u. t+ ^
}3 l0 l; M$ P/ b3 t4 _
break;
8 d* x2 `* T. e* i% q i3 w W4 J }
2 U. R4 J7 t. Z( \; \) Z case 1:) a/ ^$ B+ @/ }+ d6 B# Z
{" q6 W, X! r" I2 @6 L+ [; j% [
//整理背包
% N0 O3 A9 Z9 M6 ~- W* m) ~ //////////////////////////////////////////////////////////////////////////" S2 x$ Z2 Y( N5 X4 O: A+ R# A5 l8 M
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );0 u2 R0 A$ S0 L
//////////////////////////////////////////////////////////////////////////
$ A- _2 a: m* k; ~* Y! L //////////////////////////////////////////////////////////////////////////4 g. Y+ M. A& Z2 Q9 X& V4 X
CInventorySort* pInvSort = new CInventorySort;
8 N# F3 @, s9 Z$ W3 `( S* ? vector <sItem> vItem;
2 b0 Y5 ^" i) b& |- d5 t* V: J vItem.resize(MAX_INVENTORY);//初始化大小
+ h0 J Q& L* c( T' R; X //////////////////////////////////////////////////////////////////////////" x; S0 l( Z4 j) `
//填充数据' z- b: G% Z, x5 n
for (int i=0;i<MAX_INVENTORY;i++)
2 c3 D8 x6 _& g' ` {
. v! y' g$ L, h8 U CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
1 V% \0 f9 R' ^" t" b( I1 F; m8 a if (!pItemElem)
( O) H" \0 y4 A$ G6 b {" Z: B1 {: W. {% a/ u5 Z/ s
vItem.dwKind2 = 0xffffffff;
) x8 E0 Q+ S& o* G( ] vItem.dwItemId = 0xffffffff;3 ~" S. P9 V) D$ a
vItem.nIndex = i;2 P9 z6 ^, B- o3 w
}else {- u I; `7 ^5 |$ S# ~$ r
ItemProp* pProp = pItemElem->GetProp();
3 H# S" ~4 U, p. Q9 v& I: { vItem.dwKind2 = pProp->dwItemKind2;. P5 G: }/ \! ?6 A( |/ H
vItem.dwItemId = pItemElem->m_dwItemId;4 z8 s T; q# K# Y% f
vItem.nIndex = i;
. u5 u, x" _. n, p" ` }' f: P$ c. B9 {% u/ I, N* H
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
2 r' [0 ^! [, F3 ]# s7 U }
' y& V3 Q- a1 x- F4 o% C7 g //////////////////////////////////////////////////////////////////////////
( U& W, u8 b3 m" f; _4 o9 e" z sort(vItem.begin(),vItem.end());//排序) V+ Y; `0 i( Y& K @! t0 H9 Z
//////////////////////////////////////////////////////////////////////////
6 M# V, P) Y7 `0 Y1 X //交换: ?! s/ Q a7 @( L# N( h
for (size_t i=0;i<vItem.size();i++)/ \1 R# F, O+ M9 j
{! E; c0 O8 h! o7 b; z# f
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
- F- O0 D; X j; t. p2 H" O pInvSort->Add(vItem.nIndex);
" D2 k) @5 x# A0 o- b' x" y% f }
3 z0 o( l! }. ]) c8 B8 L8 z BYTE nDestPos = 0;/ U; K- W# B/ g% T# e
for (int i=0;i<MAX_INVENTORY;i++)
8 @0 U6 W5 K2 a) [( k5 T {
% X4 N) Q; H) }. s: D( L CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);& [# W1 y5 ], E u7 @8 Y
if (pItemElem)" T: Q: \3 L4 Y- _* u
{
* o' B3 z; I' V; _& C* S7 p if (IsUsingItem(pItemElem))
4 b! U/ c1 X9 ~9 T! t- { {
% F; h4 L8 r0 |4 q0 _+ d //这个位置无法放- B' ]1 G- N4 p( |
nDestPos++;
! z+ E8 p1 D+ b4 G" B1 P }; {7 @4 `. {; Q) t! ]! \- b* M) t
}
6 X p: d# @, O, x" {% \, S4 p BYTE nSrc = pInvSort->GetItemSrc(i);
) O/ P$ H. `4 i2 r: f" \ pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
) r: a/ s6 ?; B$ Q) C. A if (pItemElem)6 p& x( ~0 f) |! F7 j g
{/ Z; R8 p C; z! A
if (IsUsingItem(pItemElem))0 C& D: B4 l" u6 _
{
! k; T. ?( F8 ^" G //这个道具无法移动,跳过2 z+ r! h4 J" j5 |- s% T
continue;
9 D" Q; ] H7 [ W& s! j9 r2 ]- n }# W! Y" ]( V/ W3 y; C
}else{
; S. S5 a6 B7 I/ R //空位置 不用动, Y7 ]- @* a7 v: l
continue;
3 h4 Y/ E* Y; c8 m/ m }
6 S4 x3 E0 j$ O4 j- k) s0 H /////////////////////////////////////////////////////////////////////////// q. r6 N2 b" D# x; e+ d% D
//开始移动
, ]% c" @! b+ Y' \$ A if (nSrc == nDestPos)% B- `/ s4 ]8 a4 [/ t* J. Z
{9 r1 D# ]1 E) C4 q# `
//原地不动/ y5 Z& j: Z7 J" E6 D
nDestPos++;
; L. c& N6 R/ O% n$ K- m0 k continue;
$ j6 R. P. w; m( U: C4 Q; ^ }) U8 c; q1 A% q
pInvSort->MoveItem(i,nDestPos);$ Z2 T, X9 u# }9 q
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
6 j+ A# P* E: g/ y$ G- Q Sleep(5);
, T9 f7 n: w4 S2 p/ P8 i- } //Error("移动 - %d->%d",nSrc,nDestPos);* e; f9 J4 U$ Z9 d
nDestPos++;
4 V, O/ k" d! M% r7 @ }
# U7 L+ k0 J, b/ i/ {0 G/ B //取第一个元素的信息3 w& _ ^& n0 {3 A$ [; T$ \
/*
! F" J& o/ v) d if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
% b+ a$ B4 _, z" m {$ f) d/ n* w5 U0 m. s
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);/ ~1 d' g" R8 G- G, U& n) b% v
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
, E x$ F+ J" p# ~) u }0 B1 h5 e. d* N! e# \8 `5 M6 k
*/
X* h: W7 k+ |9 J' x. v //////////////////////////////////////////////////////////////////////////5 B# X* H1 n3 A! y
break;! c# G q6 t1 i5 u! D+ L9 P
}
% r/ r6 c! y+ f8 ^. }$ N! q( b: | }
0 N" j$ @( N: ^9 T7 B}1 q8 I& V' x# W: k, m5 e0 ~" y5 w
m_wndMenu.SetVisible(FALSE);" h" {# s4 a, M n$ e* _" k. F3 h
* f. F2 P7 p! O2 i* T- q) P
--------------------------------------------------------------------------------------------------------2 N" ~& D: f- k" ?
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)7 S0 [: n* U r7 Z% Y0 A
{
' g3 A" _9 S" ^ jBaseMouseCursor();
: c8 @7 \' W- h& z# C9 G}
# d: [( G4 E/ O/ L/ w% e+ I/ b. O) s+ u在其下添加:9 q$ v# H' @( q, F! u
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
9 P: A( G+ x( @ k0 S8 S1 n{# w' B' Q6 J* r7 d! ^
m_wndMenu.DeleteAllMenu();8 ~. r& ~3 ?1 k8 z
m_wndMenu.CreateMenu(this);# `$ D* c, o# Y6 T0 J1 N. C
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");* M! W) p: i5 B, [0 G: r
r4 a& S/ B$ Z7 Y
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))5 e I0 ^+ S2 r* u5 e. m
{
* E% d. Q4 B: Y+ C& Q //P以上级别才可以删除所有道具
& J' t9 x" P9 @) a% @2 C m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");* U. I* e( Q8 a4 m+ S# S+ i
}8 J) L6 k! P# a# R+ J3 P( x
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );9 ^# j- G% B# s9 c% `
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
7 [, v9 D8 _; n6 {m_wndMenu.SetFocus();8 G( w5 m0 [; J2 @
} h! ] `# h$ \: B
------------------------------------------------------------------------------------------------------------5 C/ L( _$ U$ |$ m
*************************4 K' M, I0 {" O
WndField.h文件' c( w" t# [/ s
*************************
) n' P9 N3 {2 l) U2 e/ i搜索:BOOL m_bReport;) R# f% M: U- M, O" U
其后添加:
( o9 U; v, T r( i2 aCWndMenu m_wndMenu;8 O. f( k8 {. G6 c
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);4 T& x* J% A: @" Y/ W8 p, v
其后添加:
: x# G; Q% a9 E+ w# {6 Avirtual void OnRButtonUp(UINT nFlags, CPoint point);
' { O* ]7 I3 M( n$ C ?
* c* f6 E) }* Q: b+ o$ v% I7 O$ A, B
0 |4 z, q/ p7 w( Z6 r' R |
|