|
|
源文件中_Interface文件夹下WndField.cpp文件# e U3 ~/ s* v2 q0 X$ J# X0 k
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )8 I- r# r# W+ r t* g& i
! B2 `: R! h, H- n) h
struct sItem3 P0 g' S1 p3 A; z* I
{0 Z: i B' r2 F; [" Y
DWORD dwId;' G7 U5 x+ T; g) y: X
DWORD dwKind2;
; K% g T' l; r' Y9 h+ }; d" ?2 |DWORD dwItemId;- a* P3 G3 e* k7 ~# X7 I1 d
BYTE nIndex;
3 f( T5 \5 S% G+ c V6 k( ?sItem(){! D& H4 _( }. u/ U5 e9 ]
dwId = dwKind2 = dwItemId = nIndex = 0;
0 r. K# V5 m9 b1 O u% F" o6 S8 p# B}
- Q9 I( s& ^9 D2 I; m& Dbool operator < (const sItem p2)
! s+ j. |% {" G+ R$ y, Q{
9 x$ x$ U. D# d# o& N if (dwKind2 == p2.dwKind2)5 A3 ^* n/ d6 t4 ~2 W" z8 r1 U
{: t5 E/ P$ T7 _& h9 ^" ]. M
return dwItemId < p2.dwItemId;
# ~; w; l, s+ b: h8 d }else{# J. G7 F; f1 e8 e8 ?- m5 N
return dwKind2 < p2.dwKind2;
" X. J5 [; y% g: e! a3 { }
% g. e! X. c R% b}+ d0 c/ b5 Q4 e
};
: ^" {! N& L+ u$ tclass CInventorySort
8 w& w! R: B" u; ]{
5 }; ]* l5 K0 m7 ypublic:& H" L8 c& @, Z1 ?8 f4 E
CInventorySort()
2 Y8 s& ~7 |1 \9 @6 G! N{0 e, ^0 ]# _' L) u
m_dwPos = 0;" ]* h" w1 o* w: q
}
* ^% Y/ b9 N$ p; A! r' Z5 I+ s~CInventorySort(){}' A7 u( o$ w7 L; p u l
private:
9 C& R% E$ }' r# ]sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
6 M$ ~% q; |! n+ ~) RDWORD m_dwPos;
" V: x: p1 C2 s" T9 m5 }# {public:6 x/ i, U; B& t" `" b
void Add(BYTE nIndex). ]) @- g' y' e: L9 D7 T7 t
{
i# ^) K( [8 [/ | M+ v if (m_dwPos >= MAX_INVENTORY)
8 ^4 ]3 w* N& s' E& F9 b. m {
2 H; P! a1 q q" B w# l! e3 N return;2 e2 B% r9 W) |* O6 [9 \
}
0 Z2 u \* K* K& c% H8 M; X m_Item[m_dwPos].nIndex = nIndex;) O- [ Y6 f3 W$ ?1 n
m_Item[m_dwPos].dwId = m_dwPos;8 s9 P) y8 _' y* f( g: g$ r; ?: e
m_dwPos++;5 @7 O; K! c8 @4 g6 |
}
. ^0 F6 j7 ^" ~# E0 j! |BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列. M9 v l. n+ [$ [, ~4 P
{
0 q4 Y( O/ f1 U+ ^" E# v" H- ? for (int i=0;i<MAX_INVENTORY;i++)
8 C ~+ o+ S! i- U1 _3 F {
4 y7 W; o% w! r( C, z3 d& U8 _3 ? if (m_Item.dwId == dwId)
. m, S. X7 W8 t: Z3 P, K4 m5 q {
, W& s( G; Z( x) E5 I: g: I return m_Item.nIndex;# q5 S2 `. f* A
}
9 S8 D" z" U1 n' r n }
5 z8 T; {: A" S. W2 {+ t/ R9 P, D: U, E return 255;
2 R# n8 p" c8 U6 s}% \- q! S# Y; \1 b7 u* i
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
/ ?$ ~) A4 { w0 w{1 n* N5 y' N6 j; I- w
BYTE nTmp = 0;
' l) ^3 T5 Z* `. b" L bool bDest = false,bSrc = false;: T5 a8 z* `- s* |, I [) H/ M
for (int i=0;i<MAX_INVENTORY;i++)
& a9 |0 N3 O- @5 y3 O {
* e9 F9 w2 T3 J7 X if (dwSrcId == m_Item.dwId)3 o* ]6 S' ~: y5 o% F+ o& O/ j
{& r& F0 j* @6 }+ p% z7 W. e
//id相等 则 改变对应的dest和src
7 G# c6 p& ?- W9 G" T [& p nTmp = m_Item.nIndex;* o& L+ h2 n P
m_Item.nIndex = dest;
$ Z0 g/ R f1 g" Z/ K0 K& d8 ] }
X3 P H& x! T; c0 ? }* o; q3 g8 @% A+ r8 [& W4 I
//临时数据保存完毕,交换开始
7 S5 ^! i; P% W' i$ q# {; Z for (int i=0;i<MAX_INVENTORY;i++)
o- r- b9 B1 e: V% c8 x {
' S. s% h1 C8 ]. M$ |+ q if (dest == m_Item.nIndex)
" f* z: a' D; a. w {% W6 w8 s( o0 c+ {# ^% y6 D
//id相等 则 改变对应的dest和src j* `% q0 I9 ?7 l
m_Item.nIndex = nTmp;
2 [, z: @2 h! v, o9 j) l0 y+ C( v }0 j' z8 E5 W8 W8 m; R8 M$ v
}
; T8 o* g# x: A2 E% I7 X& a}
5 G$ r- k# R( l};
9 S4 ]2 [8 T4 @' r-------------------------------------------------------------------------
. U& q2 C( p, t: d( x依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
% \0 F: t( V% q3 A- e. Z搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);7 O9 b! G$ P7 s# z1 C
紧靠其上添加:
6 Y* U$ |6 c) vif( pWndBase == &m_wndMenu )1 R( X' V; h, X: m2 L
{
R$ e7 f& o O+ O; Y switch( nID )7 @6 z0 N. O! J* H6 f! e
{
( B5 g1 e6 v/ V; g' y case 2:6 @" D2 a6 Q! J( T; w8 [: y6 Z
{
" h/ ~1 F. }9 \. x //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);3 G' p5 S* ?& v8 ]4 X& Y- S
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
' [. Q$ i4 \$ C! C/ V) K! R7 Z {: L* r/ i5 [7 l) _& l
break;
! {$ J/ ~" g% } }$ L- h; K0 x3 r; j! I5 s2 n0 K; H5 J
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)1 K: ]7 V3 j$ z Q4 R( z
{
; B7 P$ i* o6 \$ y8 @ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
, R; S9 Z8 H4 I3 W if( !pItemElem )
( f7 _0 ]! w' S# E4 S+ S/ G continue;! _) f L; I! l( v: E+ W n
if(pItemElem->GetExtra() > 0)
' U- R p f- P5 K6 N) A continue;& ?6 m3 t# F' Y/ K
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) $ ^$ g+ l' b2 o6 z$ \ F9 Q0 E
continue;
4 M# j& |& ` E8 |5 z0 W' H if( g_pPlayer->IsUsing( pItemElem ) )6 u4 x; ^8 K% ^ H, r5 M, A: O
continue;; G# X! I; `6 N' R" U
if( pItemElem->IsUndestructable() == TRUE )! U6 c* i* k" o/ t6 f u
{: N: e8 A5 N* E/ i& G @; J( p
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
4 C: c% E9 z/ Q ~$ \ continue;
. Y% j0 c+ O+ e }3 I) k2 L' e* N+ s& P
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
5 v# m8 M" V+ b7 h }
; l- `& B6 W0 z9 V break;
# ]5 y, R: a' x% f' `/ A }0 y" Y& S2 N% L% Z& P9 b j
case 1:
: w* g- k3 {7 a3 i* Q {2 g2 ?" L) u8 e4 Y' o: }6 i, L
//整理背包8 X; e3 }, {! w
//////////////////////////////////////////////////////////////////////////
) ^ |* A; q5 n* C o3 H' g3 o //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
, J( A9 i& N5 x1 c* [1 e" Y: v //////////////////////////////////////////////////////////////////////////) b8 W+ ^! g/ E
//////////////////////////////////////////////////////////////////////////( c* s+ \" _0 h
CInventorySort* pInvSort = new CInventorySort;
% Q0 p( Y0 l9 N: B9 j vector <sItem> vItem;; |5 i& ~2 m. U& {6 |
vItem.resize(MAX_INVENTORY);//初始化大小' r3 j2 z/ e: d% `: K
//////////////////////////////////////////////////////////////////////////9 T: a. P2 y* y! G- h3 a3 d0 P; V6 N
//填充数据7 m, g. l9 |7 {0 D1 i. ^: l$ g
for (int i=0;i<MAX_INVENTORY;i++), U4 Q: Q+ H- R) V9 G
{$ ~# [' m, Y) |/ o& {' W, @
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);: g* D6 x9 K2 B& B3 l7 V2 f
if (!pItemElem)# ?. J4 I5 O: z& j
{3 M! l% g9 l( F+ ~2 x) P- `' ?
vItem.dwKind2 = 0xffffffff;4 W0 Q6 M) o8 D0 f
vItem.dwItemId = 0xffffffff;( |& A$ d* Z. N% |9 V& k8 N u
vItem.nIndex = i;
4 J2 h" _" F# o% F1 ~. N }else {) g! R5 L' q& r$ L$ u1 |$ M2 W
ItemProp* pProp = pItemElem->GetProp();
7 U b4 t a' v0 u vItem.dwKind2 = pProp->dwItemKind2;# @/ c" r9 j1 Y
vItem.dwItemId = pItemElem->m_dwItemId;
6 a) i4 n9 g# F* ~' T vItem.nIndex = i;
1 K- G+ W; v1 k6 ]& a# J7 L }
4 @% c$ [- j9 \6 e$ c //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
( Y' E' N% |, ]0 v; k }& p( J$ i2 T0 V- u! E# D- @( d0 l
//////////////////////////////////////////////////////////////////////////4 a; r' C% Q* m' j9 A
sort(vItem.begin(),vItem.end());//排序
0 v; H* p( R ^* }. l2 W //////////////////////////////////////////////////////////////////////////
) o. p: I; F4 t b _4 O& Z D //交换! }8 i. L# ~6 t+ }
for (size_t i=0;i<vItem.size();i++)
8 w- ]: Y& N# A {1 m; q6 L9 L$ W& i
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);3 i9 ]: Y3 Y) f: ?4 a; W0 T
pInvSort->Add(vItem.nIndex);5 U3 [. i8 ^- X8 s" u: t
}4 L/ c' V7 Y5 f6 S8 ^
BYTE nDestPos = 0;; A5 h- X$ f; h! r
for (int i=0;i<MAX_INVENTORY;i++)- L- h* |( G2 |& V- j1 |
{
y" g) e0 B- s6 M4 y* y8 G4 ^, q: a CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);' s. w5 O$ T y5 z$ |7 b5 o/ d
if (pItemElem)
" i6 _& c4 ~% v' U S+ v T n7 J# k {4 A$ Q& Y D! q/ z, O) D0 K
if (IsUsingItem(pItemElem))9 ?% g {- H6 ~$ o/ e3 d5 a
{
! h) Y0 z: k' g) F //这个位置无法放! v% @, W- r" @7 v
nDestPos++;
" w9 ~/ H+ W$ z6 `( { }
( Y* U" n5 d# }3 u0 n }
$ S6 K3 w6 K9 R3 d4 n Y, R% w BYTE nSrc = pInvSort->GetItemSrc(i);& W, j6 U& i6 S9 I- m; K$ l; P
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);: U; R* c; C" _6 M
if (pItemElem)
1 r! Q- ^+ c+ a" m) @# G# ?2 W+ e1 { {
@% S/ k& @( M) w: B if (IsUsingItem(pItemElem))
7 b8 p) L, t" z7 W1 r' u: K {) w. K+ T7 w! t2 d
//这个道具无法移动,跳过$ o! z5 p3 P7 L
continue;
1 [, l1 `' T& A% j+ c: e% l }# G% i w7 K y% u) y5 ~) n
}else{1 l5 q+ h/ ?6 a3 @. B' S
//空位置 不用动2 T! Q* I5 u5 |/ X8 k! c c, b( l
continue;
8 i9 B& m* R% @: x }. P+ I! A: @! c/ Z5 J
//////////////////////////////////////////////////////////////////////////2 h' g( q& _# \0 Q
//开始移动
: K; a. x# S+ n$ {0 _ if (nSrc == nDestPos)) R3 N# B( q7 L& P7 x: M
{% Z+ ^! O# |8 E T4 y: U; r# P, B
//原地不动
# _0 G; I$ N7 ~ nDestPos++;7 }) F9 v4 {! E* j
continue;
) I2 N6 }7 K* Q: v }0 _& k, M, Q4 U$ ?) |
pInvSort->MoveItem(i,nDestPos);
/ a0 I. m) J: [' |# S7 z4 y( I g_DPlay.SendMoveItem(0,nSrc,nDestPos);
/ ]! Q9 n, J1 T. s O* O' ^* b Sleep(5);
# [% M. V- l6 Y1 a6 w- U8 X! u5 i //Error("移动 - %d->%d",nSrc,nDestPos);
7 @ [; }$ v/ ^& S* m. l& ^ nDestPos++;0 g( u" {7 ^/ }
}
) Q2 v! y; K& C$ L) G1 S# \ g //取第一个元素的信息
2 o7 j% n. F# z* G" o /*9 P& X! O# t1 r O# U
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
% ^4 N8 O3 C4 P( C! E {. @# K' l" }1 w; D
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);: V; B4 x8 D8 S) |2 W) p
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);- ^+ i. X/ l) h. b5 T- M
}
* E6 s; s! A) _0 g' m */
4 l* i+ [3 q' n/ w& Q+ M: t //////////////////////////////////////////////////////////////////////////
- E2 V6 i& c0 M2 F% i break;
+ Y% ?& Y1 ?$ i6 J- z4 ^( F }
2 j! p3 l6 \$ H; R* G% w/ c }
3 _. G( z9 N7 K# c7 h}- _/ J$ j/ G+ P. Z+ p
m_wndMenu.SetVisible(FALSE);8 a, ^8 q" g U$ x( p: P2 t. N
c8 c% O$ H2 H--------------------------------------------------------------------------------------------------------
: T! h. n( q* X. y- l搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)/ @5 p3 f. s5 r+ z7 f3 m
{ A; L+ | T& ~
BaseMouseCursor();
8 F# H- a' k2 E% n z}
7 \; F& g( @1 u' J& Y在其下添加:
- z/ H$ [7 @% A* ]4 _8 jvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
% A- n) N- w! h' S) a{
z, I6 U/ |3 l" Y: im_wndMenu.DeleteAllMenu();5 y+ o% \: c. R5 \
m_wndMenu.CreateMenu(this);. x, ]0 e7 M" T: x5 o: M
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
* o$ K3 {% [" M/ f* h7 F/ a2 Q& ~1 k* g
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
- T k+ b" w$ z) h{
M* M) |/ G; i, {) `$ D" z //P以上级别才可以删除所有道具/ b6 m7 q& G+ P: j2 R
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
, V9 u8 O: q: a2 J2 K} ]8 E* _" E0 R* S" ~1 V
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
( W+ t7 n8 m( P) D6 Bm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
8 y: H* X( k6 k Rm_wndMenu.SetFocus();
* A7 w$ Q2 x0 H7 B! W6 u' I) G}
9 e7 P4 ?8 [" D7 i0 W# V------------------------------------------------------------------------------------------------------------
% t1 i f3 h/ A# H*************************' y0 X9 g' ]( a6 U& u* N) X" f
WndField.h文件3 F$ a5 a( D6 d& g
*************************
# q, [: y' j+ E% m& h5 X) C搜索:BOOL m_bReport;7 c- e) `/ ?! |
其后添加:
% @; ?% n4 V6 O) tCWndMenu m_wndMenu;5 f/ f1 G7 L# E3 G/ \; B" R' h
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);6 C: j2 t, G$ ^) s) Z
其后添加:
, h/ ?& C$ Y/ E# q5 Z! V1 Qvirtual void OnRButtonUp(UINT nFlags, CPoint point);
8 b0 |, }! B6 E* h4 h1 W
! E7 n0 w- c1 O/ A/ t* h
# K8 C5 S+ `- o. Z |
|