|
源文件中_Interface文件夹下WndField.cpp文件' p% Y g1 x6 V4 { j9 O r9 {0 d
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
& S8 R% j" k: f4 K! L. g0 O( Z" G0 t; T. B" m: n. b* h5 n
struct sItem
% x; j; l$ b. {+ a; ~{
" R- {2 u3 l) C6 I6 pDWORD dwId;
$ s: t1 {! v' rDWORD dwKind2;
/ g* q" p, R- D6 f% MDWORD dwItemId;! [! v( I6 t u: z# V( [2 K, j& z
BYTE nIndex;
7 f: M# R3 d. B+ |sItem(){' B. _' d) s7 p( L9 ^: d
dwId = dwKind2 = dwItemId = nIndex = 0;. z, I$ u* g3 g. T
}
+ ~0 I2 e9 r" N% r1 s+ T" @: E+ ybool operator < (const sItem p2); k7 y2 t7 ?6 R" k
{+ I) h. ]5 A* A! H) t. n- Y
if (dwKind2 == p2.dwKind2)1 A1 w* J3 S W" I X- ]* E" j
{
2 a; o3 p/ {5 j* a$ u return dwItemId < p2.dwItemId;
+ r. h1 P' u q& ]# ~7 V: S2 m }else{
2 i% X# [7 @5 P5 x* E- T; g p return dwKind2 < p2.dwKind2;
% |) U* Q$ ^* Q }
) `8 E5 }& W" Y% L# Y* \}
( V. E7 j( H& ?. y* c1 P! z};( Y9 X: |, A$ C" [8 C. l
class CInventorySort
$ ?+ S2 K- A; ^/ @' d$ o{
' H% l9 ~/ L+ C9 A+ ^public:& Z# } ?" T6 B. |0 Z* k
CInventorySort()
. X$ ]0 D6 q9 `. ?; T{; o" l" Z; o1 q! |$ }0 s
m_dwPos = 0;% A+ n) d% n R3 A
}0 s2 [ k- E( f- t
~CInventorySort(){}
# t1 Y5 y# }" ?* F; w" W: \0 hprivate:
0 L0 t; \1 A5 |" esItem m_Item[MAX_INVENTORY];//存放排序好的道具信息7 b% L7 }% H0 q
DWORD m_dwPos;5 u0 P$ B( u1 s" I3 ~* u
public:
' Y+ A5 Z" B8 t# l. k# cvoid Add(BYTE nIndex)
! P! @6 H: u* S& D: p{
# h- |/ v) k& {0 q2 X( ]) ~ ]6 G if (m_dwPos >= MAX_INVENTORY)) L6 A' V. Y8 h9 l
{5 n& K1 V/ }. q9 h5 p
return; U- t" I7 W( g5 S9 r+ G2 t
}
* ]2 s \1 ?; H m_Item[m_dwPos].nIndex = nIndex;8 w, f/ R6 l4 M* i0 `
m_Item[m_dwPos].dwId = m_dwPos;
0 j$ p5 r \' M, H% A$ f: J m_dwPos++;% Y% t6 E& k" q9 e+ v1 [3 r! h$ Z4 B
}8 W% H+ q( H/ \& X
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列# I3 q3 t& P9 P
{
" @9 J7 l+ x5 K# p) Z$ ~; W' U for (int i=0;i<MAX_INVENTORY;i++)) ^# E+ L/ _2 k# F
{
4 O, y9 V4 {7 |+ L if (m_Item.dwId == dwId)
2 Y" ~" o4 h& | {
2 u2 p1 } ~2 O. @1 O: p- ] return m_Item.nIndex;* F" z G0 K( q! q9 m
}# e# R* w0 e% G) i: i3 n
}
$ N( s& }/ H3 s6 b2 z; z return 255;
# C! w! J0 G* Q- G; j- G" P}, |/ `5 K3 q3 V! x+ l8 y9 {
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
% N0 p3 M: K1 h7 V8 c: v{
8 X3 h* g: ]1 ^$ C BYTE nTmp = 0;
2 y* [: p3 U y" Y* ] bool bDest = false,bSrc = false;
( h! u- t1 L4 @+ ` for (int i=0;i<MAX_INVENTORY;i++)
' C4 {" G. m( h [$ d {9 A! p0 I" e% {' J
if (dwSrcId == m_Item.dwId)7 ^" z4 h" B, e E
{; i, k3 K4 e; s* b& y8 i
//id相等 则 改变对应的dest和src! c3 _2 p) |9 H+ A: [9 g
nTmp = m_Item.nIndex;- Z! N6 I9 [* c
m_Item.nIndex = dest;
! F; ^5 m5 }7 B7 o# r9 G }7 b4 h6 D% A% K8 n" R* m
}7 X* N( y6 W. b/ K) Y1 _! ~
//临时数据保存完毕,交换开始. T$ D3 z* ~: h0 k" p( s
for (int i=0;i<MAX_INVENTORY;i++)" x3 o- O( a0 V! ^; b
{2 {, Q* v/ |- b. ?7 D. N
if (dest == m_Item.nIndex)
. v+ O' w! t, B- ]) Y {
# A/ h( ~/ y- P4 ^ //id相等 则 改变对应的dest和src7 o, ~) B2 k- S
m_Item.nIndex = nTmp;! g2 g; C I* C, I. l
}* ^ q3 P& v9 U' w w7 H' i+ D3 f
}3 V5 g! S% m* l- ]9 P! q. O3 O
}+ K# X3 b9 Y7 P5 s/ {4 y1 y# F7 S( d
};9 U7 x% }5 A4 Y Y- Q: M( V) p1 ~
-------------------------------------------------------------------------
# k* i5 r% P) {' H/ P0 D依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ) D' s" Q/ l% w9 O
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);3 |( {9 o# i9 ?+ T
紧靠其上添加:
- Y9 I2 j% V2 pif( pWndBase == &m_wndMenu )" R* W: s. q9 }! X& W7 K
{9 P! _; a) C& `2 ], ~( z; v9 i
switch( nID )
6 T H% K& M; Y1 L* a {
s( ]# }+ q% E case 2:% n1 L* x8 u/ R' C$ C1 P
{
; Z1 z( r1 U f- d6 x //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
# X( `* e8 C* a1 k; T$ ^5 f8 v+ \; O- n if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))6 i* @2 S5 ]- M& t
{
5 q- K$ S, m% }% J5 x break;
4 ]& D1 }3 P; V. m' s; W2 Q/ L }4 I% v% M+ n7 [. z, X. E7 D" T/ Y
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
0 ~- Q- _" Z d( Y2 T9 y {9 a3 i* t" h. h8 _/ T8 \
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
6 }) F' ~! W; ^1 Q% Y Y9 z+ [ if( !pItemElem )
( t0 w! T. {0 x& z! O continue;" C5 H7 b) h G0 a0 D. z2 ^
if(pItemElem->GetExtra() > 0)
' R: l+ b. m7 f5 @& r: t5 Z continue; T3 G8 F; x. T$ c& S: R4 [, t
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ' k: M8 q/ X: c
continue;
- t% @4 s; t) S! `9 z) D+ d3 ` if( g_pPlayer->IsUsing( pItemElem ) )
8 e+ `" w& W( W, j! J0 Z continue;
4 b& G# V, Z/ M if( pItemElem->IsUndestructable() == TRUE )' @. w* h+ }3 l" k
{
& x ^7 R5 j1 @3 T" [8 g g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );+ Y0 t* @2 q5 Q1 z
continue;
# u- v. r* ^$ s$ L/ ^ }
2 _% E9 n# t+ g8 m g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);' I3 n4 l6 ], ?2 L
}
* p- o( S3 V' M' M& U1 y y break;
; b7 Z: c6 f/ z# G5 T" z% I+ u" ? }
0 s# {3 ^1 i9 w case 1:
; ~. \- q7 c7 F; ] {
7 U) o! w! ^" S //整理背包/ q8 V" a0 I: R- i; v9 j9 C% _
//////////////////////////////////////////////////////////////////////////" t) r) K7 {, G9 W) e' Q0 c. P0 S4 ]
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );4 V/ J( F! H& M* m" ? |
//////////////////////////////////////////////////////////////////////////
" c5 z+ x% s2 w* V //////////////////////////////////////////////////////////////////////////
/ J4 p$ @; o$ D! w5 y CInventorySort* pInvSort = new CInventorySort;
. f: J( s7 f' r9 ?+ m0 M& R; h vector <sItem> vItem;
2 b" f" W/ i( P, k6 Y vItem.resize(MAX_INVENTORY);//初始化大小2 n. x7 X5 g$ h5 V% ^& I3 q
//////////////////////////////////////////////////////////////////////////
8 I" `) o, H Z# l1 T //填充数据8 W1 i$ D/ |& \% n) Z
for (int i=0;i<MAX_INVENTORY;i++)
6 G& O1 u5 g' F8 q- n1 k {# t9 X- G% t( K. x% t+ \, Q
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);% V0 Q9 K# q( A% G8 k9 f
if (!pItemElem)7 u5 w! E6 [0 L: \+ l |1 P3 d- R
{
0 b3 H2 Q1 q. ]6 J- t9 L vItem.dwKind2 = 0xffffffff;" W7 e! C& E0 ~2 K7 h% i
vItem.dwItemId = 0xffffffff;
: J# x9 F# Q2 P, y s1 Z9 x vItem.nIndex = i;
( a4 A9 O6 M# z ]7 N( V }else {
, L9 V& D9 p3 j( k& L( q7 Q2 O ItemProp* pProp = pItemElem->GetProp();" @; h! _" r1 H* D5 i
vItem.dwKind2 = pProp->dwItemKind2;+ B! U- b: R! [# b
vItem.dwItemId = pItemElem->m_dwItemId;
# x; B3 p; v, c6 H vItem.nIndex = i;5 r7 @3 k" z. P) m
}
' a7 D* o! n( t H //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);. k+ @/ x k" }5 `$ U
}
* B9 q8 M; v! x& ~ //////////////////////////////////////////////////////////////////////////
' W) @5 Q1 p6 L" N, U4 M sort(vItem.begin(),vItem.end());//排序
6 I& N ~1 T9 i. | //////////////////////////////////////////////////////////////////////////( e6 }5 `. C# K" Y3 ]) p: ]1 g0 S
//交换
7 n! z6 h( `/ c8 b for (size_t i=0;i<vItem.size();i++)) ?/ U/ ~0 F/ q- K( f
{
# V* d* R. Y3 p# u2 D //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);$ k$ H( O: I& H
pInvSort->Add(vItem.nIndex);
$ o0 s" n' _. Z# a+ A. a }
# Q @$ j7 F4 K- i7 e BYTE nDestPos = 0;6 D0 w1 {. B5 c+ x+ s R
for (int i=0;i<MAX_INVENTORY;i++)
$ B8 V ^( G6 {6 k, u {# p: d" L) E( q+ Y3 @& [
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);) K' u1 x6 N. q+ l O% \
if (pItemElem); }+ P$ t' ~! ^3 G
{; x, `/ y B( c
if (IsUsingItem(pItemElem))$ u' B# p2 F9 V/ @3 n
{
/ f/ @; u. W( z& |* | //这个位置无法放
6 f' N; ?6 @$ u. o) c4 ^" [ nDestPos++;
6 ^2 I& _5 B7 E } N& X( D* J" p7 G4 ^( ^
}4 @/ Q- b' Z# {* |! B% [
BYTE nSrc = pInvSort->GetItemSrc(i);
# A5 F( I% [' u1 {# E- g7 z- o pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);8 v! [5 t- }/ J9 J! |, ~4 Y
if (pItemElem)' }. n" U( T! m& T
{( Y f$ Z, _( \) M
if (IsUsingItem(pItemElem))# x' ^4 o& `5 q1 ]' R4 ]; _
{
g1 C3 @) I' ] //这个道具无法移动,跳过* b2 ?' |$ \# J9 c
continue;
+ t; E1 Y' M; l4 ^+ p }
! }' H$ O+ J! i% m }else{; D! T# y9 R4 l9 U
//空位置 不用动
3 U- F3 {9 I, {/ e continue;, @% X. z _7 O0 U
}
+ R6 ?6 F* m" n //////////////////////////////////////////////////////////////////////////9 n3 x: e5 D6 e; v7 b: d1 m) w8 W _
//开始移动
" b [5 b9 j/ ~7 E if (nSrc == nDestPos)
; `/ i v5 R, v1 i* ^5 K% E {7 s( o! @6 A4 z4 F. H3 y* X
//原地不动3 N7 Y3 P' r8 c0 f: |' Z, w1 Q+ J
nDestPos++;7 ?; i# F- {# d8 |5 F% | U
continue;+ c2 c1 E' C- m' a2 l. g, }
}
# f6 ~, S. e1 J5 | pInvSort->MoveItem(i,nDestPos);
# M' ^; O+ V" n g_DPlay.SendMoveItem(0,nSrc,nDestPos);- S5 y% T9 a: f# {7 F( \- O+ R
Sleep(5);: J' K( h8 \- ~2 R+ k, q
//Error("移动 - %d->%d",nSrc,nDestPos);6 ~+ H4 g' M( D0 V( M
nDestPos++;! U1 @/ @5 j W4 s: I
}
7 F" S# O% o- X% N) t% s //取第一个元素的信息8 @, E( u& \) H! B* x, u
/*
' w! ] o6 o( K/ p; l if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
3 f0 O7 q1 w' q. I" S9 ] {: {5 d2 A2 Y G2 h% o; u/ ?
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);0 W" T/ Z0 G$ B- q3 p0 L/ ^8 }
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);7 `! H) T' P1 y3 y
}
7 T9 M9 L. ~! |3 p8 L+ C3 R+ n */
9 y4 I/ D1 {1 @2 j7 K7 f //////////////////////////////////////////////////////////////////////////
( b$ V( M3 o j+ |) o( X break;
; s) X) D6 G6 b }
- y) @6 o1 w2 U/ Z } - h9 G6 C" ^3 D- m+ i
}' ?/ R- {! L7 }
m_wndMenu.SetVisible(FALSE);
9 S u' E" D4 Y9 j/ D, l; x$ j. S: J$ i
--------------------------------------------------------------------------------------------------------
; ~! e2 |% u! ?% S% U! u) o% m搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
2 I# f" A6 V1 a9 N5 t0 G) G{2 h2 l+ A' i* S3 i$ [ x, y0 M
BaseMouseCursor();" j/ O9 a Y5 i5 c" ]
}
1 \( p( o. S K在其下添加:
9 V& v8 A- J; C' V; z0 G# Lvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)- T9 s6 X; `. Q, [ m
{3 F, D; O! [# i& u2 w
m_wndMenu.DeleteAllMenu();. A4 ]8 w3 @* i; `1 D0 }
m_wndMenu.CreateMenu(this);
" w0 d+ ]( m$ B" l7 E* [m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
' J2 c1 N+ k' [! |5 P1 L6 W8 C" W7 U% R* S# @9 p& x" l
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)); p, R2 [1 c6 `1 _% T) X7 i
{
) B$ } K p4 `+ _$ P" Z9 { //P以上级别才可以删除所有道具4 l3 l2 J0 F" g7 D
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
, Y0 _$ P& \0 I I/ T4 ?}" j% U7 P3 m( ^3 f( N
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
. N# G, z8 W% ]9 d, F0 q# Xm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );+ p% H/ G6 V; ]
m_wndMenu.SetFocus();2 A4 R+ K3 u! Y+ A. \! c6 H
}& `6 r; ?1 g9 H2 x0 {
------------------------------------------------------------------------------------------------------------
C, \/ A* l F8 e*************************: P- S$ j0 G: X- u* p
WndField.h文件7 |$ R% V! n: y6 q0 v# X7 k* O
*************************% e1 G6 ^. y$ R8 J
搜索:BOOL m_bReport;
) m4 Y9 W- F% H- X' w其后添加:
' E! X2 l f( k4 J5 h5 gCWndMenu m_wndMenu;
$ D1 @+ S m' w- _" e& C9 A搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
5 f9 U( A3 i: r( _" t其后添加:4 l) l6 L& ^$ B
virtual void OnRButtonUp(UINT nFlags, CPoint point); u; a- h! h. g1 ^
9 d7 p. ^4 T7 h* a5 U8 i
* ]2 j/ A, ~, R m% z |
|