|
|
源文件中_Interface文件夹下WndField.cpp文件5 D/ P) l6 j/ }- l: `5 c
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )* r! G8 z# h( V+ o% p0 D) H
; X p, q0 F; }+ e% Istruct sItem! `1 W3 M3 l( N: }
{; j4 l+ B7 O) T
DWORD dwId;
) A4 G! w3 H X! J. BDWORD dwKind2;; M0 Y& e7 U2 z: l* a& A5 O
DWORD dwItemId;
3 ^4 ?) j$ n8 ?6 oBYTE nIndex;- H6 e# q4 g/ N$ C. C% Z2 v
sItem(){# j W3 a& R" S! [: \
dwId = dwKind2 = dwItemId = nIndex = 0;0 ?. W4 i; I; Q% T s
}
8 k; l1 V0 U4 [7 [bool operator < (const sItem p2)2 E: K a0 X) e* b, y, S. j
{
4 c8 e( g* e2 Z" `' S0 N9 D7 M" I7 C+ U if (dwKind2 == p2.dwKind2)) D, w) {) B+ D' ^; h
{) M. K. [$ w2 w1 J; v, K r
return dwItemId < p2.dwItemId;7 d# V, ], w# W0 {7 U# E! ?
}else{5 a/ A* m% h+ w/ T. p
return dwKind2 < p2.dwKind2;; H4 e2 |* O3 C1 b7 b
}) m0 k2 T1 D; r. D- Q# I1 O
}8 S9 {! }0 X0 [* G
};3 a F1 O1 M/ {# r
class CInventorySort
2 N4 a7 D" |8 }{3 x, z% p3 |* W0 w
public:( h. u K3 I/ C8 @+ ~' V. g, F8 V0 @7 G
CInventorySort()- [& ?& u4 v$ w1 r
{
8 d1 U3 E" _: f8 a m_dwPos = 0; G: N1 F3 i9 J# z3 [8 v
}
5 d% {8 J; ?4 K- [. n3 X2 D1 C9 G~CInventorySort(){}' l: Z4 T, H) n* _) n+ x& @# V
private:5 k K; z+ Y$ Y5 T3 P
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息3 e2 d; u+ [8 i+ `6 k0 m
DWORD m_dwPos;9 S8 Y7 ^% e4 J& }4 [ m, \
public:: X; J7 Z* `8 z9 [, E
void Add(BYTE nIndex)4 z2 O8 u. ^ x
{5 }9 Q( d4 u+ L) E& \4 u
if (m_dwPos >= MAX_INVENTORY)
; W0 u4 Y5 }& W* F. G. P {% E, }8 V, ^- w" u6 z3 S1 T$ ?
return;1 _6 \5 _# J, E7 c5 t, ]
}
5 U2 R' y- P5 ]: W m_Item[m_dwPos].nIndex = nIndex;, S) W L+ L# _% d- [3 m6 B" ^: ^
m_Item[m_dwPos].dwId = m_dwPos;
! l2 g- D+ R4 M. k+ E2 l m_dwPos++;% R/ t0 x5 A1 Q; }
}% P! G% D! E) S
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列" c3 l; W1 ~* ~. X* z; O8 b
{
$ g9 o( S5 b9 s for (int i=0;i<MAX_INVENTORY;i++), ^: {3 m4 Q$ z+ G1 Y7 ^4 x& n
{
( P6 _! w8 I% M2 y X if (m_Item.dwId == dwId)3 @" ?$ e( h, T
{8 y# }) m. B0 A: o( J
return m_Item.nIndex;
+ O, {: }6 l& p3 j E" K7 l }
; v. |6 P5 B8 x! s1 f% _2 B }9 _( L# l h+ x% _) B
return 255;
* c; n) O3 ]* M) B$ ]; H" `8 {6 g}, a% g% c' W. v4 Y5 z, P
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
6 D M6 M m5 E{
0 m, z& \# F9 M- g* l1 l, j BYTE nTmp = 0;- A. i: x/ D ?2 d; @0 U% T G
bool bDest = false,bSrc = false;2 `3 r$ {* ^" O" {3 F
for (int i=0;i<MAX_INVENTORY;i++)6 a' d- S( Z' |! r# g0 I
{9 r" a' e. q# g6 {# g" o
if (dwSrcId == m_Item.dwId)5 ~2 i( @8 c& c* p8 j" Z/ O, W
{6 C, f& Z! H, ^) |9 k5 f9 E# K2 O
//id相等 则 改变对应的dest和src
) n T) E! y, t; H9 k: ?( ~/ b nTmp = m_Item.nIndex;; o1 K0 ^9 R' J: {& E, c
m_Item.nIndex = dest;$ k1 z8 ?3 Q& o2 {- [; J
}
; X' K! P$ ?8 ?# A- Z/ @ }
1 J3 y/ |( m) ^+ o- f //临时数据保存完毕,交换开始
8 Y. J P6 s$ a6 K1 E4 ? for (int i=0;i<MAX_INVENTORY;i++)" T3 _" i ~. I6 x
{
4 l( i1 {8 d/ I9 d8 v) F! A* s if (dest == m_Item.nIndex)
& K% z5 H" w- X& A9 w0 V {) L& O- |% F5 a, ?* G% h) _
//id相等 则 改变对应的dest和src
4 Z1 d7 C& C5 h% e" h3 s m_Item.nIndex = nTmp;
4 T& Q% V7 x! x; c% b }
; E" O6 C2 e" Y$ I }
! O$ i. u% S3 c}
( I6 o) y* M. ?};* d$ V: ^/ Q3 I; e' F
-------------------------------------------------------------------------
% a' f7 M* s/ o, @* g" K( T- a依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
, l5 m' [ o0 Y" U6 }4 C: } R搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);" V# C" Y# V/ G7 y9 w( _# O
紧靠其上添加:5 n M) B' _' M0 j
if( pWndBase == &m_wndMenu )
' ?7 g- w& [2 k1 R; k9 |{
" H2 k, g" G% l0 y; J switch( nID )6 I% A4 d$ _6 N! l5 }/ E4 c
{, ^- }7 J. h8 [* _/ G3 j% k
case 2:: m* t& Q9 W' N" \
{! u; D% T! I( v! \5 k: S( L
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);/ _& i2 A+ H# m. \: |
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))" X2 D5 j6 t( l \# d
{3 b6 U4 t5 v- P8 @/ K5 w- i
break;, o! V- t% e' P' y
}+ d$ c! ?1 f- s: P
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
+ e8 W1 s1 }# A6 p& J' \ {+ p# U4 m- t! L# N' g
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
* K: ]4 Z1 b1 u if( !pItemElem )
! P8 I# P. d9 Y3 _: o+ A continue;
* ~5 E0 g) R. x$ o A P( C if(pItemElem->GetExtra() > 0); I, q7 C& q, K; T I+ r! t$ Z4 ]* {
continue;
# j( p# Z. M( \! }. l7 G if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
- C3 ~7 O* O7 Y4 X: t continue;
. t, n5 Q& S' x4 R8 u% H if( g_pPlayer->IsUsing( pItemElem ) ) g( h. a+ l( w, t& F
continue;
; C0 B, Y% F) \( V& r' o if( pItemElem->IsUndestructable() == TRUE )" Z7 H1 R+ Q2 C+ q' V
{( i- l# L$ C3 B9 t" [% _
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );/ A4 }( h/ f/ G# K6 n) I
continue;. g& d. t( r W7 L3 z
}$ o! m4 k1 a2 X7 r3 Z7 t; {
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
5 W8 Y5 N. k" v' l( n }2 C9 R* U: h! j( P& ]
break;
7 j) m8 w% O: |0 m5 h7 u }6 {8 D# b) _0 \+ Z
case 1:
% P: D& G9 l8 {1 j {
3 Z9 d U7 \/ @" C //整理背包2 [# o7 Y) ~! o# t
//////////////////////////////////////////////////////////////////////////- p$ J! `6 \) w2 H. ~
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );! K& B& R9 \- e' u) F
//////////////////////////////////////////////////////////////////////////7 }4 r$ f: H9 d$ Z$ t9 _! l
//////////////////////////////////////////////////////////////////////////, X! a1 u8 p" n# i3 l& R% h* v9 s
CInventorySort* pInvSort = new CInventorySort;
6 r7 S6 k' E1 W3 X vector <sItem> vItem;' _2 ^/ ?1 T. S& K$ w* h
vItem.resize(MAX_INVENTORY);//初始化大小% G! s9 n6 T0 b& e! T7 Q
//////////////////////////////////////////////////////////////////////////8 J2 ]2 c$ t# S& B/ m* t& X) O
//填充数据
, ]* f' s& u7 i+ I! Q for (int i=0;i<MAX_INVENTORY;i++)2 S6 Z6 t. @" i; l! {/ W
{2 ^/ R7 v" [8 _" z
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
9 x$ [. a0 A9 Y& ? if (!pItemElem)
2 g' M# ^% _4 S0 ?% ` {
5 Z; H$ i4 ], B1 k7 } vItem.dwKind2 = 0xffffffff;- K% \. Z: E6 }5 ?% L/ f
vItem.dwItemId = 0xffffffff;+ a1 k7 \' u' f8 M( [+ Z" Q
vItem.nIndex = i;
: b) D, w) k6 X! }' H }else {+ v. b& Y) W# u' c) B4 { h
ItemProp* pProp = pItemElem->GetProp();
- l, V5 \# v. ] H g$ y, r vItem.dwKind2 = pProp->dwItemKind2;7 ]: b5 S$ W1 h4 c0 q. L
vItem.dwItemId = pItemElem->m_dwItemId;
8 J( D9 y/ |" m* _: D, }- l vItem.nIndex = i;
8 _, x8 T0 a/ S0 H+ E) Y }
0 Z3 ?6 M1 q$ m) K //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
: m' M4 T! E7 y( x* ~ }7 F& ]. J+ A& i& X' J# \
//////////////////////////////////////////////////////////////////////////7 D2 x; [5 F$ ]5 O. T
sort(vItem.begin(),vItem.end());//排序( _- ?- }, g, t& f: s
//////////////////////////////////////////////////////////////////////////, W# q8 J" z* Y( o5 w
//交换: K9 K" `, d q& ]/ R1 w6 d
for (size_t i=0;i<vItem.size();i++)9 [) [) c! q% L* C, t
{: ?1 m+ {& ] b9 l' ~" D o
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);4 o: {6 g/ T b6 c# H6 h
pInvSort->Add(vItem.nIndex);
[4 B7 f+ [% t2 s }7 ~: ~$ [! I9 K# H
BYTE nDestPos = 0;
% o' f( v3 O }% ? for (int i=0;i<MAX_INVENTORY;i++)
1 u# v, O e4 G2 o6 Z: P# b {
9 c G* @$ G& J; \7 m' |5 Y6 K( k9 Q' `4 F CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
& M; Y0 c9 s d- E7 {( u if (pItemElem)( h8 c3 n/ N' D
{
& }2 ^' Y/ x e$ j! Z if (IsUsingItem(pItemElem))
' V$ y# t# f# K0 C, } {/ L* R8 g) a. a" h/ W
//这个位置无法放
- R9 h) O1 Z5 D. J nDestPos++;
4 q* X+ U" @6 `3 b' P }
: @2 n5 O/ i; f }
" C0 C" z1 o: }, r0 R7 [ BYTE nSrc = pInvSort->GetItemSrc(i);
2 s- s8 G6 N) e. U# b2 j pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
; j# l, z, | a9 L if (pItemElem)
% r/ P' I( Q! I% }: E) |. h {
1 w0 ?1 g' [4 }6 J2 R: w# Y if (IsUsingItem(pItemElem))% `- ]1 B! W2 `3 X! Z% y# c
{
$ ?" ^) ~0 B! p8 P0 x$ n& E //这个道具无法移动,跳过, u, ]2 P" i: {; A
continue;
5 `% r. E' g+ t' v+ L2 s- K }
$ Z5 t0 g- B/ D: f" V( B }else{4 o: ?; Y- @+ s7 o
//空位置 不用动1 b/ m5 C }! R; t- r
continue;
: O& H$ a) H0 j/ @ }
' e k# G2 [1 d: V$ x5 m //////////////////////////////////////////////////////////////////////////
1 m' |, Q: t" d2 u# r //开始移动# N- ~( S6 g% {
if (nSrc == nDestPos) k2 u& X" o; u' A
{
! p: u0 o4 R1 ? //原地不动
7 q, b/ _" J: r: t) Z nDestPos++;
! \* `5 J6 L; J" S continue;
# N9 ^$ ^+ J: d1 m, }7 j }: I, D4 Z+ ~$ f
pInvSort->MoveItem(i,nDestPos);* K, E8 S" I* _" Y) z
g_DPlay.SendMoveItem(0,nSrc,nDestPos);( K; y" [8 s* S b6 ~- c
Sleep(5);
( P" R3 ?, u9 n; S$ Q% d, [0 @ //Error("移动 - %d->%d",nSrc,nDestPos);, Q! D' V: O: T# h' B F! b, S
nDestPos++;
$ }$ B S, s8 G& W* t- J8 @ }, ], b. f4 K2 S* D! m' L- o# `
//取第一个元素的信息$ d. v- q _* z* g9 s3 S
/*
8 a) y3 H) a3 Q/ M2 H9 a9 G2 ` if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
. e2 _. l9 q+ U. b1 I+ o$ A6 ^ {
/ ~* U. X% C$ S! c' M6 K Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
9 r# ^2 Z+ R# w1 C( ^8 W g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
7 f: Y& M5 x' K+ v2 j }
9 u$ @' ?* o. Z* |- k */
# i3 |- Y& O1 J! K8 j2 X //////////////////////////////////////////////////////////////////////////& ~/ l. l& R( k) l. p ^
break;$ ?! Z2 M3 v+ V# o q* V* R+ h
}
O( \( b9 i2 D( w& M' o } 6 c7 P( W/ W6 [- R# r5 g( y
}+ s2 R( S( X7 G
m_wndMenu.SetVisible(FALSE);
* S9 v4 U6 s( M# F8 J8 R* B
9 C& l) L, D* i--------------------------------------------------------------------------------------------------------
! `$ q4 x0 z3 x( u2 j1 _5 t2 I搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
% N3 c8 u0 z& J# L{8 v6 T# m' c) T6 Q
BaseMouseCursor();
( j6 _; E( u# G/ v6 S& o: n}& u$ `2 T* O2 d: i) s
在其下添加:9 |$ x1 j: @% q# V4 E
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
5 n& A4 b& |5 q- m- S{
6 V* X3 m1 d# i! `2 u7 g' c* X; bm_wndMenu.DeleteAllMenu();# ]+ Z( ~2 C( \+ O
m_wndMenu.CreateMenu(this);3 C' E' d" [. _" L
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");) k7 ]. s* _0 o2 V0 H
8 M; f7 t: U$ F+ J) h& G8 a& jif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
3 l0 b. Z& Y- X" `{ s1 o) y/ U3 g& R
//P以上级别才可以删除所有道具
3 p- f- A1 G5 f, h; t! U m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
+ m5 @2 C9 K7 M}
9 P+ E+ g- d% r5 Pm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
+ G5 ^$ ?) `6 s. Xm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
: o8 q0 g. s) n9 w& @m_wndMenu.SetFocus();: _ a, X% l3 l1 k6 Y
}& D0 C9 Z) N, g# z& J
------------------------------------------------------------------------------------------------------------3 C8 P- a3 O+ T% ]+ x
*************************
# f' M( u. {$ E4 E4 BWndField.h文件
# @; e1 {! e) u*************************
0 P( P) F" Q6 B5 }% P搜索:BOOL m_bReport;
4 m# J3 j% Y; n- J* \6 g+ y% x其后添加:
. x/ B, }7 J' Q! @) q iCWndMenu m_wndMenu;1 f- Z% V1 B/ p) W5 `0 g; i
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
p7 Q: R: Q) ?1 N其后添加:
5 C* X6 n9 T: c" Tvirtual void OnRButtonUp(UINT nFlags, CPoint point);, n+ m5 E. x) ^+ x( T5 v
* S( V$ o5 y: [. Z7 T1 j
2 k9 i* b [0 c7 z/ u |
|