|
|
源文件中_Interface文件夹下WndField.cpp文件% @. G& ~; q: ~4 {% h$ K
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
, v+ A. J8 o; n$ c/ r6 R8 r% V, P4 T3 `; T. i: c
struct sItem% ^( z8 e1 \) n* Q7 x5 M |
{9 m. W% Z, W) n4 ^6 Q
DWORD dwId;
# F N1 H5 z3 F/ A% K( F% h( uDWORD dwKind2;0 Q( Q/ `. v( \" q8 h' _
DWORD dwItemId;
5 v9 j0 ~3 ]4 Y5 a# O5 k" _BYTE nIndex;
+ a& P( ]+ r/ f7 J: V% }9 o: PsItem(){
' W$ n* t% g9 Y0 z# j V9 \) o+ ~ dwId = dwKind2 = dwItemId = nIndex = 0;& E" t% G. p& R, M+ U7 t Z! V
}; z* L$ j8 v3 M! O$ p
bool operator < (const sItem p2)
, B( B! X1 r. D% S) n& _{- h1 K. Y" ? Y4 g: _
if (dwKind2 == p2.dwKind2)
) g, H; [+ K( E3 @/ R$ u' x! r7 E {
4 O2 |% N! ~8 ` return dwItemId < p2.dwItemId;
4 K% \* Y) q: _* [. a }else{
" U6 W" S! P" F( G7 }9 C' y return dwKind2 < p2.dwKind2;9 w8 d" Q5 q- V
}0 X& N! O' x' m3 V: {0 g
}
, g# N* O1 b! J/ y3 X: V6 f+ ]};0 ]7 ?3 m4 [+ T4 l$ l7 Q
class CInventorySort
' h% s( q B% m+ S, x% S{
* g! Q& Y0 o2 Rpublic:7 J% P a! z% j1 x( Z$ B
CInventorySort()
6 k; }4 e6 I- b1 c8 a9 B{1 m" a( }$ p/ A* n1 O y- s8 p
m_dwPos = 0;
- e% C( s0 A6 p* [ y: u2 i1 Y) W" U}
; H3 P$ ~6 e! D8 q( y/ X" j~CInventorySort(){}
7 q' g. I0 P. V2 w$ {private:0 Q% y0 L# w; r. w0 N+ D
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息2 }0 R; V, q' q2 p! l) ?
DWORD m_dwPos;" I9 [: b( Q7 P, d( T
public:; M6 ~" L, P; t0 f9 `/ l2 f
void Add(BYTE nIndex)/ c. h! ~# G* }0 O! C Q
{6 n* R1 P; P+ i, J g. L
if (m_dwPos >= MAX_INVENTORY)
. j0 G& x& Y* T8 `' s. F/ g {4 c) f3 `0 \1 U: D+ ?
return;& o5 p: H0 R3 K$ z3 I V! ]
}8 g- E8 v6 Q* o
m_Item[m_dwPos].nIndex = nIndex;
; Q+ U. ]* y9 ?+ x, E8 s Y m_Item[m_dwPos].dwId = m_dwPos;$ G# f: K. T3 A1 b1 ^& e
m_dwPos++;
4 a( V y! w3 G/ H1 d. P}
' [5 F x0 R3 o6 R. qBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
4 b$ M& q; K6 a1 r' }1 y5 ~) Y{6 X& L6 G) `8 `$ W
for (int i=0;i<MAX_INVENTORY;i++)
0 f7 |' r2 j) y+ ~9 U) } k! {0 { {
" b( W1 R0 n2 R5 X4 ?1 R if (m_Item.dwId == dwId)
5 r% g8 K% D- Q& K) L {
% q/ V( Y- H% g, c; O* E& d" A* j return m_Item.nIndex;. s; `$ G- W( ?$ }
}/ t( v) [) ? G0 s
}
: S# P& D A- M' l: X% u- @) ] return 255;
. [% n% Z& T6 O3 a}) m S! X2 |8 \, k
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置- M. a6 o6 s X2 u
{9 ? m! Q0 O6 `6 k
BYTE nTmp = 0;
9 ]4 u! B4 F5 G+ I bool bDest = false,bSrc = false;
0 q/ m% y/ k0 C& T& n: d for (int i=0;i<MAX_INVENTORY;i++)
! I+ D$ D+ h9 t$ i( e1 y$ d$ [ {2 ^% b9 g2 b4 \" @5 Q" B3 A
if (dwSrcId == m_Item.dwId)1 g3 w9 \& s4 e
{
f$ L& L7 E1 Y8 u8 z //id相等 则 改变对应的dest和src
. S9 W3 x0 b" w nTmp = m_Item.nIndex;
# u( Q$ J: O7 [' s: P m_Item.nIndex = dest;
+ ~- N, Z. x; I$ E! n/ S2 }8 Z8 t4 W }7 {1 L: P' G6 @" c2 V) C
}) D- {9 [0 W! d) ]
//临时数据保存完毕,交换开始
0 d9 N* r5 c$ x6 }" k; o8 }; v% t for (int i=0;i<MAX_INVENTORY;i++)
# F; @" V" i4 E {
9 {7 t. V( p; R& d if (dest == m_Item.nIndex)0 D" R" [0 ]# V3 o5 f& F7 b2 a: i
{0 h2 A6 h% J& m7 l
//id相等 则 改变对应的dest和src
5 h8 e. K! Y' B% w& @" b m_Item.nIndex = nTmp;
+ U9 J( U0 c! i/ ?* e/ p L! _ }8 x4 ?- J2 Q+ f* N6 E/ ? ]; k
}
" M' Q' a& J+ ]( x}, `+ l7 W! }8 v
};+ T# L6 T; ?' z4 U+ u+ F
-------------------------------------------------------------------------
' v( B' ^5 `. w3 {9 { h6 C依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
4 t$ ~3 s4 D; t7 z5 n0 f7 D搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);3 R- _" m5 p% x. }* V F5 v
紧靠其上添加:, ^- K+ _. a$ D# A6 c
if( pWndBase == &m_wndMenu ) w3 b N9 k6 l) y
{
4 I r: ~$ O: P: L7 P switch( nID )
3 Z0 U+ a+ k- u {# i" s. z7 t/ S, g p2 X, M
case 2:9 [; c1 t5 E1 O1 a5 J
{ g4 k5 i% \: T- w. z ?
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
9 K; N7 J% |1 g: _5 U2 v if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
, I. [8 g+ U& u {
$ s! E1 r3 d( }5 ?/ [ break;
+ g' J( l2 a j, A- A3 r/ S! K }
l7 _$ P5 ^) t5 d2 L for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)- q' @% }/ w$ _6 ~; e! n
{9 S) T$ q' B6 F2 d+ U; v; c2 F
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);5 F% p. G9 k/ h' x% P
if( !pItemElem )
7 ?$ \; ^: P) F \# f1 z continue;
# i, `! n. F! C+ u, _- D if(pItemElem->GetExtra() > 0)/ Z: }& _( V$ g' q* ~# G; u
continue;; u, Z; w5 ~, x( ]6 N
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
8 M( |# S+ n( W) z% V continue;
- |+ e2 R. Y& h6 ]2 E7 s3 d if( g_pPlayer->IsUsing( pItemElem ) )
' y7 b/ } w. b; }! x continue;
2 H) j) V9 G( M; r' R# u if( pItemElem->IsUndestructable() == TRUE )
, |& Z2 P8 J0 G/ a, n* p# j {! g) V3 \/ s+ a& ]7 `' \- m
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );- v1 Z0 H; W6 f- _
continue;
6 m1 }) O$ K) L }
, k/ K, e' F+ R g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);( b0 w; u( C+ t; s+ f
}
& P& h1 q6 d/ \! p break;
# B+ v4 \. |2 F5 E0 l( l }
# Q5 G( ?5 u& K2 q) l; `( i case 1:
2 i: M: N. ~7 J9 b0 o1 M {: i0 t1 Y- [1 j2 d, y# b
//整理背包
4 b3 `3 Z, P4 h4 W //////////////////////////////////////////////////////////////////////////
+ q! b- e1 N0 c6 c2 B C2 l //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
( a; J% A) H* M8 y% t //////////////////////////////////////////////////////////////////////////- i& U; z- A6 b9 E; v
//////////////////////////////////////////////////////////////////////////
- W3 T+ L5 Z/ b& x9 I: U CInventorySort* pInvSort = new CInventorySort;
6 n+ |7 O2 @0 H% ^2 h G* } vector <sItem> vItem;% v* ~. X" w3 w7 I7 b3 \1 _
vItem.resize(MAX_INVENTORY);//初始化大小
! I `. x, S5 s a' o! m //////////////////////////////////////////////////////////////////////////. F. B, `6 m0 ^& C K4 n6 ~
//填充数据4 Q; K- H- }/ L" `& k6 M$ d$ q3 M
for (int i=0;i<MAX_INVENTORY;i++), W" F* D3 ^9 {
{' C/ r9 _, H E
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);& I' t. I) @: w9 X0 F
if (!pItemElem)( U3 q8 u5 d% S
{1 T. m( _7 k t8 z, E& T9 @
vItem.dwKind2 = 0xffffffff;
2 l7 ~5 G0 C4 U; ?/ a' J i, U vItem.dwItemId = 0xffffffff;9 s# f U1 l( r/ B7 E& W y+ }
vItem.nIndex = i;
4 K9 R6 w* ^0 ]1 ~! B }else {7 i# c( g& ~" g- O% p
ItemProp* pProp = pItemElem->GetProp();
/ Y9 m! h1 j- e: _ vItem.dwKind2 = pProp->dwItemKind2;
3 u4 r; W* S1 u! C% L0 @- S6 b vItem.dwItemId = pItemElem->m_dwItemId;
- d( c+ p; @5 X& q( ? vItem.nIndex = i;1 U3 L+ ?. N) ^6 s" @! A, ^& a7 Y
}
0 U. K6 j9 C! o5 `9 w //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);0 }+ M, N7 e0 K$ c9 ?+ Z: [
}
3 a$ e7 Q9 K8 |6 y //////////////////////////////////////////////////////////////////////////
L/ ~9 {) G" X9 W sort(vItem.begin(),vItem.end());//排序- p1 H" C% X G# k
//////////////////////////////////////////////////////////////////////////; Y6 k _* ~ {) p
//交换& p3 p! h: e3 p8 ]5 U/ o5 r+ a" k
for (size_t i=0;i<vItem.size();i++)( s3 J1 M/ l& S1 U# h# D( _) y
{8 D) o9 [0 J+ V& [+ I% S$ Q
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);5 X3 m+ b, o+ u4 H6 `1 f
pInvSort->Add(vItem.nIndex);5 d1 G3 G0 h L: ~& w; S
}
5 o* n" T9 Z; b: A' v) E( x# I& f BYTE nDestPos = 0;
$ @0 j/ N7 P8 Z X8 {+ E1 r3 n for (int i=0;i<MAX_INVENTORY;i++)
; Z0 s2 c. w, _8 T, F8 R4 D3 c8 C {% w% M1 h" }4 e5 }
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);8 O2 G5 e- p9 e. ^: V& g
if (pItemElem)7 w$ b" \( w/ O7 x* p
{
_+ S, y( P& s: z+ q if (IsUsingItem(pItemElem))( c& `# F' Y$ a" V
{
5 K8 F {4 U0 y1 _# a //这个位置无法放1 m4 ~# J' N3 V
nDestPos++;
' R/ N7 u" k' ?9 g }& ^6 B" ?) Y9 X ?" Z+ M+ b1 w
}
+ ~7 r4 T: P% F X BYTE nSrc = pInvSort->GetItemSrc(i);
. {( L1 u! W" l pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);& a5 X' j; X, Z- d3 {/ A
if (pItemElem)# V' u& L! H4 ~# Q1 A6 R4 R) ?
{
2 {7 `* O$ B8 v: t# [! \ if (IsUsingItem(pItemElem))$ U) D$ ~5 o8 k; l% w8 H# Y7 |8 {8 A
{
& W/ R: f n; n8 r3 z //这个道具无法移动,跳过
* P+ b9 l6 }5 V+ h7 U continue;, |; ?" z0 ~! y
}; \$ B7 N" P' d/ }9 i8 M
}else{
4 K0 Z0 I( J3 A+ ~ //空位置 不用动' L6 C% M7 g0 ]8 h
continue;3 R( ^. O: o' t2 j/ c# C8 O
} u6 W6 ~5 C' T; w
//////////////////////////////////////////////////////////////////////////$ z+ E- R+ q- F; A5 ?% C+ q5 m* e
//开始移动
( m K- e$ q' c& Y if (nSrc == nDestPos)% p! j0 M* u6 t: k
{+ f: @( z( f( I2 M( k2 o( O
//原地不动
; p8 m+ l4 ~# x nDestPos++;
2 u1 G7 ^& q7 k2 A continue;+ d7 l7 l M" [/ i5 t- \( x
}
! l4 w1 T6 `: [1 a9 s pInvSort->MoveItem(i,nDestPos);" c+ e! t- j7 j% D/ Y
g_DPlay.SendMoveItem(0,nSrc,nDestPos);/ P/ A( S W( l/ F
Sleep(5);# N' I0 u5 ^$ f( _4 `$ l( D: l ^5 D
//Error("移动 - %d->%d",nSrc,nDestPos);% t$ ~8 w6 ?$ b3 V6 Z: o- S* b4 P
nDestPos++;
1 V7 q F( C1 I3 y }
6 T i" m7 j' D s2 J4 I //取第一个元素的信息
- y% m+ U9 a9 b( B9 a4 H /*
% X+ `0 f# p7 f% u1 s7 { if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
4 N& R* a& P- K; n$ U {' } Y, h& |6 m2 @
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
9 g& h: {8 B6 x3 p2 Q g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);' u: X" |- B, A, l; J
} D+ D0 Q9 y9 M! J2 [: V
*/
1 n4 @( w" b- k6 M' X //////////////////////////////////////////////////////////////////////////
' b% }# z+ m0 M- ^% Z break;, v( h5 a( w- Y5 B' R
}
# ~* f/ S! q7 n- d% [ }
/ f! x Z5 a& t; [6 o6 K- @/ Y3 j}& s4 R" A& ~/ Y2 Q
m_wndMenu.SetVisible(FALSE);
3 x& Y5 ?( P2 M( M" j4 t8 @) E! o+ T0 y) y! }% e$ K
--------------------------------------------------------------------------------------------------------
5 q3 s8 t4 K' F9 s; r) n. b搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
3 i# n m1 J- h6 d{
i1 }* Q& k. Z' b$ mBaseMouseCursor();
# w3 t7 \- E! Z0 n( G}1 A3 G- ^$ |( `4 V
在其下添加:
/ g* a; ~5 D t3 }6 Hvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)& ?* U9 N- D% C" h0 G
{
- k) [* l+ G$ Y. G: z" {m_wndMenu.DeleteAllMenu();
3 B) ~/ { h6 K- n' E( b! k! vm_wndMenu.CreateMenu(this);
" n3 A- _- h- A5 b) T: p& B3 Em_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包"); @& i# M3 W' ?
4 D0 D1 R, `1 P# Hif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
% O! J! b1 d1 h" D1 m. n) `{
; I* R- c; n$ z. ^1 U. w5 m) U //P以上级别才可以删除所有道具
' y0 _. V7 k2 | m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");) R, x4 H0 F" I7 r9 ^
}% k+ ~% w9 X9 D9 W( W
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );( T a. x* Z: n& f8 m A
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
0 W; E' a) h. x* k( ^8 _% Pm_wndMenu.SetFocus();
9 r# K0 ?7 M0 {+ x}
% c0 Q0 p" f# J% v8 D* r------------------------------------------------------------------------------------------------------------' c3 f8 O' W9 s0 p, n
*************************
. i: D/ ^* w5 j3 K [! i# yWndField.h文件6 B3 C0 J' n9 \) q( u
*************************
& G$ p/ F) K- \6 _0 I6 O) k搜索:BOOL m_bReport;; `0 _1 X$ a9 Q \ w7 z
其后添加:
+ u0 N$ f, i- H& ~* |; D: z8 ZCWndMenu m_wndMenu;
( e. q& x/ f. i$ R9 {2 H搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);+ D) g8 ~# J. H& K
其后添加:) [2 F0 P: K; T5 F% w
virtual void OnRButtonUp(UINT nFlags, CPoint point);6 B/ N0 j6 H: w7 T; j* T
. X7 h2 h( s" G. L3 ~
d/ ^' S& L1 s3 j. V |
|