|
|
源文件中_Interface文件夹下WndField.cpp文件8 H/ [3 e) B5 S: @! p# A' D
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
* q4 O7 Q7 s7 V9 Q1 n7 |& D! l9 s9 h8 ^& p/ N d2 }
struct sItem5 ^( x; u( y% q# h5 w7 q. X% J8 e
{
4 D8 H6 d/ L" B: o8 }/ VDWORD dwId;
5 [( Z1 A+ M6 ODWORD dwKind2;/ C" i g( a& I$ i. P
DWORD dwItemId;: B/ W/ C! t6 F( h. C% ~" m
BYTE nIndex;
3 [& ]9 G: V/ O. P D! y: `sItem(){
' q; q1 M0 @* @) L, y' ]# q m* s dwId = dwKind2 = dwItemId = nIndex = 0;
6 A7 F9 x: @1 D f4 F}
3 @0 p# y3 i: l1 Z% R2 ]$ _bool operator < (const sItem p2)& W4 M4 u% S# }3 a
{2 f% J! z7 v$ t5 @; X9 t* I! Z1 L
if (dwKind2 == p2.dwKind2)) X4 b! ]/ Y9 R& P! \
{
& w3 I$ S5 ^4 |+ s9 B return dwItemId < p2.dwItemId;# B0 `( e) P, ~. Z d
}else{
* C1 ^, a6 K5 E- a7 r/ b+ K o return dwKind2 < p2.dwKind2;+ I: P( g3 }% e3 A/ j
}* M, p* G# H$ d% P3 H4 J
}9 h! E, X1 C/ ~; Q! k, C( I+ N
};
" T C; P* X3 u# d% bclass CInventorySort I6 N- P1 ^9 X6 B5 X: C0 n, j
{( F K/ i' Q- x7 f) _
public:
- k' N* F6 y, M( \CInventorySort()
- D! X, v# E, ?1 j{
9 S2 _; H$ q' u. z8 e9 s9 _ m_dwPos = 0;) Y" ?5 C: X M# O: B6 G3 r$ x; \. Q
}& J5 R6 Z$ ?% _; R' f* S
~CInventorySort(){}
3 M+ {# y( e9 J! o" A" cprivate:+ s; B+ r$ E- Z' d! R, m/ }
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息2 C4 z* |7 R" m. @. B) e
DWORD m_dwPos;+ D; E4 M, B+ k: ~
public:
; B% E' \' p3 X, X y+ ]void Add(BYTE nIndex)/ r" u$ V" Z( i4 U( y- Z% J
{
, z1 Y* y0 o9 x) W2 A p if (m_dwPos >= MAX_INVENTORY)
" E1 b7 p( O+ ^% _ { R! ?3 d- V9 I9 y- x/ B
return;
9 T& w% s2 w8 R F3 n }
, B+ z$ _+ r2 r' h, C4 d7 D m_Item[m_dwPos].nIndex = nIndex;6 F5 n9 `. Q1 w& O
m_Item[m_dwPos].dwId = m_dwPos;2 c$ v) K3 i4 k" P2 N
m_dwPos++;4 u; C: v: x2 |2 Z) G
}
# b+ P4 \& F- lBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
. v) c- C7 ]+ \, I# j/ f$ ]8 X4 C{1 J$ D( f9 L1 I9 o2 m9 {. B' L
for (int i=0;i<MAX_INVENTORY;i++)
: M# }$ p1 O$ ^1 O/ Y4 A) b {6 w! g5 z. u& ]( G2 T; S
if (m_Item.dwId == dwId)3 k2 e& `- l. u! ^3 @* n) {. o# ^
{% x% D2 |2 f, z
return m_Item.nIndex;+ r6 b$ G9 A, G1 [# l
}! J4 O, \! Q* F' T' c
}
6 H1 r: d5 i- t! X/ n) `# k0 i% d return 255;9 @" L" t2 ~) P7 N
}6 m/ l; m; J9 `1 _
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
8 B D, M! q. w2 s{
8 ^0 ~3 T( B! l BYTE nTmp = 0;. m& M% v9 e0 j; F
bool bDest = false,bSrc = false;' q) ?9 ?* g7 D- C. V
for (int i=0;i<MAX_INVENTORY;i++)
9 R0 G- c$ V9 U+ w9 b/ Q {
7 ^' W! L) [' K8 w if (dwSrcId == m_Item.dwId)0 y2 H+ d/ x' d! J( i
{, V. C9 W* x& I, P# A4 K
//id相等 则 改变对应的dest和src: P6 U5 \! {; h# U, I# {
nTmp = m_Item.nIndex;
, k4 G7 E. D) V4 q m_Item.nIndex = dest;
+ a- G1 ]9 x- p! G }
; Q: n6 H$ u6 h }. U! M2 Q$ K# m0 ^" B* x) h& M
//临时数据保存完毕,交换开始
. W L# r6 r6 X" T: Z Q for (int i=0;i<MAX_INVENTORY;i++)- \8 j$ H3 D+ @; z1 F1 w- R
{
8 c/ Z' [4 V' Y/ Q if (dest == m_Item.nIndex)
& h c. y& C5 o {
. F6 g, e, x0 B //id相等 则 改变对应的dest和src
" [' a, a* F& }0 R m_Item.nIndex = nTmp;
+ F7 w8 t: I# V }
0 E$ g' G( k, N7 q }% n( ^) \; w* H( Z. I) H0 G8 b6 J
}% e5 L6 M* a8 l0 g$ e7 p P
};4 R7 u) X" y' M- K* ^7 H e. D1 `: N
-------------------------------------------------------------------------
3 m: J; H8 W: F. H: H# ^+ [5 m依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )' e( `: b9 C4 M: }7 b4 k
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);6 v4 i0 e2 q6 `) r5 G
紧靠其上添加:# e. D3 X. P3 a0 p
if( pWndBase == &m_wndMenu )$ K8 y$ v2 Y6 @, ]" K
{( w4 N3 N8 }4 K0 c( ?2 c$ ~
switch( nID )- g* h3 X3 s' z3 q5 ~. c# P
{0 v H( v* H. u0 p
case 2:2 Z) ?$ t. u3 x# m1 x4 N8 _- o
{
8 m. H3 J1 E- F/ i+ A! E //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);) o' b- F6 v p7 ?& V
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))4 p* W4 G \' g% J7 L8 L$ h" A
{& ^# O% @( v3 s0 q" i
break;6 p: `/ S5 c) i
}
- h: ?# a. z1 Q for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
6 P- } G3 ^6 h1 |( ? {% {( B7 G) Y: M6 A4 H' u
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
6 O* _" } s+ W! C6 {0 m! x: b if( !pItemElem )( n4 W, L2 x5 l4 q- ~; `" ?0 Q
continue;1 e+ v8 O9 k5 W/ x& H* z X
if(pItemElem->GetExtra() > 0)
8 A. H3 p# p3 d continue;
- S. o8 A1 r7 [3 r% v. _ if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 8 I! M) N. _4 l& v& W
continue;% W% f% V) \) L! ?
if( g_pPlayer->IsUsing( pItemElem ) )
6 @3 _2 o5 G2 o8 B( N. n- A- F. l continue;3 h7 X% f( M- {7 k' I3 L$ y
if( pItemElem->IsUndestructable() == TRUE )- K8 Z3 a [: j2 ~5 }
{
8 d5 b- Y, r! J! p5 ^/ \ g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );' b& N4 X8 N! r& ?; g
continue;# I* w4 `7 ?' {5 J0 x
}# ~7 U# r! P6 h* p2 @, n* N: g
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);( m1 h) r! B$ n! C d
}
2 H+ }/ m% V( Q3 k3 Y- { break;* l8 w$ l$ S; G( N2 M2 q
}
S3 m+ V4 B4 o: W r7 g6 V3 Y case 1:
- \9 ^: o e4 g4 s9 O; g {% P! J- D( d# O
//整理背包: d9 W3 d. L5 W: O
//////////////////////////////////////////////////////////////////////////" a4 `* h( |5 E: n, }* {5 N) |0 w
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
6 b! n, h( M( ~- {0 Y- f' q% { //////////////////////////////////////////////////////////////////////////
) m& p( Q6 T5 X) ? //////////////////////////////////////////////////////////////////////////5 i2 ?" I4 {. z, U& ?! e, t
CInventorySort* pInvSort = new CInventorySort;8 f$ s7 ~: x% o
vector <sItem> vItem;
* {5 p6 j( W" o" |, W) t% l( g$ f vItem.resize(MAX_INVENTORY);//初始化大小
0 F: e" D1 ?8 p2 d //////////////////////////////////////////////////////////////////////////
6 z' L+ C) N, Y' q9 S# ? //填充数据" r# R6 V- e3 K T6 s* A+ H
for (int i=0;i<MAX_INVENTORY;i++)
$ x: ~+ h& f$ t4 T7 Y {
: e. W) \! I& T, s CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);; z( I+ X/ p! c$ A. Y& w U
if (!pItemElem)2 t0 S' x: r: ?( L
{
; r3 @$ u+ H) d- a8 V vItem.dwKind2 = 0xffffffff;
8 e. e$ b$ `6 K( U/ U w vItem.dwItemId = 0xffffffff;9 ?/ J. r5 s8 V" z
vItem.nIndex = i;
% z E% W/ z' b: f }else {) s% M) F0 I) E' F
ItemProp* pProp = pItemElem->GetProp();" [( O* C5 Q6 v* r8 N1 H; U% W
vItem.dwKind2 = pProp->dwItemKind2;
4 v0 o J$ j; h! u1 x) H, b5 A vItem.dwItemId = pItemElem->m_dwItemId;
* _* H( E& t0 n5 e# O D vItem.nIndex = i;9 `, F9 |# O$ f7 S3 t) {
}( N& _6 T+ G; a0 \
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
6 v! V8 d& f; \& \4 V, H }
/ O- L' `4 ~0 r5 ^$ k# T7 P @; | //////////////////////////////////////////////////////////////////////////
$ E/ e2 t% k' G$ Y" ^( t sort(vItem.begin(),vItem.end());//排序: d4 T J7 I S) x3 t- L
//////////////////////////////////////////////////////////////////////////
9 M+ E5 _! }% U* n. I) f //交换
, c+ i+ w* i P2 ~& c. x/ h& ^ for (size_t i=0;i<vItem.size();i++)! m3 Z9 a; t/ N/ J/ P* F3 R* ?
{
0 y( A5 v, M6 T( Q9 `+ q9 n) e //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);9 \ [9 y( Y7 w5 M/ x1 k2 J
pInvSort->Add(vItem.nIndex);" I2 F6 T G! H
} U" |) M; V% w8 ?$ v+ t4 n
BYTE nDestPos = 0;8 W. `5 o- Z( o
for (int i=0;i<MAX_INVENTORY;i++)
% `9 p6 {% k1 w0 g6 |" c. x4 C {
2 ]* C2 \5 B/ s8 K, H$ Y1 f CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);# x' ~7 |/ b; m3 }' I$ D" l
if (pItemElem)
+ J: Z6 a {. x. k0 V, l {
4 V3 q" D3 |2 D/ b. k if (IsUsingItem(pItemElem))
5 `9 K' F1 S/ R0 I8 y {" k. z: U4 w! E. T, U$ u* b! |
//这个位置无法放2 P: x' t" f0 x! c& h8 k
nDestPos++;0 b( }& s- M7 L) O9 V) I
}2 W" S5 ^& o; Y
}
* C" F3 ^8 a- x. D$ S' u3 f% a% R BYTE nSrc = pInvSort->GetItemSrc(i);
& \9 U, ]. G9 J; U$ [5 M) H pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
, G8 u' T) v( p2 O& G; X" p, C& H if (pItemElem)/ _, q& c }8 ^1 ?. T3 d, K; t
{
2 Z! i* N, O1 N1 a; a% v1 M7 { if (IsUsingItem(pItemElem))
, L, n4 d2 [* c2 p {- ^; F* t1 z" k3 t$ `, E. P
//这个道具无法移动,跳过$ ^- f0 p* n* z( n
continue;' b% B" e! V0 G1 [1 H6 G" k9 ^
}! y+ r, J$ Y9 \( j
}else{* K- D9 u0 a- |
//空位置 不用动. {5 t8 _+ ^3 ~) N" {5 s4 b
continue;4 q( `( u/ L' g/ W5 V8 N) R; _) E
}
/ i6 q; V! e* Z! w- n) Q //////////////////////////////////////////////////////////////////////////
' ~1 \9 u7 B) L* Z- Q //开始移动4 f- p/ M" }0 A* E. q' o
if (nSrc == nDestPos)5 [3 y5 W( K. {, ]! m9 a$ [
{
3 _# l# a" ?" D6 m: P3 l //原地不动
& g& w: X, H, S2 u nDestPos++;
+ N- Z1 @3 U& f" E7 `) p continue;
& @; U" c D, x Z }( v. Q# C% i, G2 c4 ]3 \4 m. Z, @. J. t
pInvSort->MoveItem(i,nDestPos);
& l7 l9 Q2 T2 T) Y/ k: k" ^5 O0 Q g_DPlay.SendMoveItem(0,nSrc,nDestPos);) b) E3 O4 M+ J0 S
Sleep(5);
) X- i9 P- _/ l0 L" ?5 A //Error("移动 - %d->%d",nSrc,nDestPos); e) F7 R" Z0 @7 g- ^: z) I
nDestPos++;4 ^7 ?: G7 b8 J/ s
}
5 o4 P7 r( I5 S$ m2 { //取第一个元素的信息
0 [/ {5 b6 Z U1 y/ B& y/ P+ W /*8 ^) f$ [7 D9 g; r# r7 W: r4 B
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
2 Z: Z1 ^# S9 O3 O0 {6 o0 a {: B; U; G! u4 ^
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);( I( B8 `% i' W3 ^2 `3 D
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
; ]+ i1 V6 Q# V }. j. B3 p% z* i/ \: K2 a N
*/- t- X' v G/ s% f0 c; J/ z
//////////////////////////////////////////////////////////////////////////6 B+ h/ k+ M3 R8 E& e
break;
0 A1 q& h( |! O) ?4 C+ v }4 q( x& w J' X
}
/ v" Y* b7 G9 n* {6 |}
/ n9 i6 t2 l# [0 v! e9 f9 xm_wndMenu.SetVisible(FALSE);
) {4 l. Z$ W I0 [; j: S
+ L+ c! C/ l( l x' t0 U--------------------------------------------------------------------------------------------------------
2 v$ ]$ w6 i; `搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
5 N' h! i; x2 Q& ~0 M! ]9 M, o{) ], ^$ ?3 b. e
BaseMouseCursor();; \9 Z) ], @5 l9 U) r% P6 j8 W% n
}1 L; B# h( {, f7 b3 w7 s* E' ]. V3 r
在其下添加:
9 N5 _( O1 A7 q5 r5 Dvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)+ J9 Y* o0 K4 X( _/ }
{
! `9 W9 w, t/ ]m_wndMenu.DeleteAllMenu();5 S4 b! o- @# l
m_wndMenu.CreateMenu(this);7 i$ e5 Q: H/ u) S! S0 E2 x
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");) R# a2 i0 ?( e' n0 X5 h; n% q) x; O
3 V0 ?5 E9 n' }2 Z1 V0 s) {( X. Vif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))0 Y9 A( c" f& B
{9 O$ X2 k' m& P$ i4 o
//P以上级别才可以删除所有道具8 v& A3 o/ { b9 h# K' C8 p
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");" l4 T) ~. m* ]# ~/ y3 u
}* e5 x6 K* ^" Y$ C/ S7 y$ [7 U
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
8 \, X# W4 L0 i! r2 p( w6 Gm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
9 M: m J: A6 W0 a* Pm_wndMenu.SetFocus();
2 M: F/ b9 j+ @% \1 `' P# t}/ Z7 L( [# z, Y1 a( |/ U0 J9 Y
------------------------------------------------------------------------------------------------------------, Q' f1 \6 E4 ^/ P, _
*************************
( b) I0 A: A! w, E% u k' R' @* pWndField.h文件
& c' k9 W; X* ^*************************0 d& k2 f6 d' ~: l7 h6 _+ J4 T- [+ {
搜索:BOOL m_bReport;
1 c I! u0 S& V; ]. O3 b6 o其后添加:
5 `) k+ o) o$ m5 S- Q( LCWndMenu m_wndMenu;% C! p& @* O( ]& a8 Z
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
4 N! x. d& |. G; e其后添加:
- h1 v5 g7 g% E. h/ ^3 S$ v, e' Bvirtual void OnRButtonUp(UINT nFlags, CPoint point);
$ G" L6 M# x/ N$ l) K' P" {& v
& R! z: `1 t7 ^* b+ F
( Z9 m$ t Y* n8 J0 \8 ?8 L' F |
|