|
|
源文件中_Interface文件夹下WndField.cpp文件8 F$ ?! ^# E' a
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
& R" `, `; n/ [, V
5 S" S8 b* R. W$ R5 Istruct sItem
) O3 B2 s+ S. U; m& X( g: W{
* R ]1 `- y( s) L H/ CDWORD dwId;9 U2 U) T" [) `: P
DWORD dwKind2;3 A2 J. m2 \+ N5 W
DWORD dwItemId;
# Q3 `; @/ `' [0 ~, MBYTE nIndex;4 u* N D0 ?3 Q
sItem(){
( j" H* l. P; ~8 ~5 G( S& x5 w dwId = dwKind2 = dwItemId = nIndex = 0;
6 d5 {( f$ V+ I1 u; a4 _( n) e" r/ s}
8 L' S W# K1 x7 dbool operator < (const sItem p2)
3 J4 a; ?& t9 @+ o{
4 v7 D4 }3 `9 L6 Q7 N/ a u4 s if (dwKind2 == p2.dwKind2): N" ^2 o3 w2 l3 x6 \
{
. j% \$ B! _ \6 A' G; W( B return dwItemId < p2.dwItemId;
- ^% _, |0 x1 M- d X+ C& I }else{7 { L" n2 f* t# B9 R6 G+ a( F+ }
return dwKind2 < p2.dwKind2;/ K, [+ w4 x7 S
}' R* p7 y0 ]( p% V
}
* ~* C0 g4 D) ~" o! [6 _};8 B$ ?" C9 v- ?
class CInventorySort4 p4 I4 S. P V8 |" K. M
{
# ]* j7 g* V0 I: g/ tpublic:
4 ]9 D' J' h: LCInventorySort()
# _, I0 G6 z4 n& D& j{
* { [ F, M$ y. l; W- c# f9 ~ m_dwPos = 0;
& U# g4 j2 \8 }; `/ d: s}$ k! D5 s/ Y$ X( Q* n i" ?$ ?2 L
~CInventorySort(){}
0 l$ O! W- u0 Q. ?& O4 a8 sprivate:
+ c+ K% r# L" e+ @: p3 @- ^3 esItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
/ M' I3 J$ ^0 z3 G6 TDWORD m_dwPos;
: I q4 m) x& ^9 F& U6 ?* ~public:
& s* r, b% |) m, x4 I, O4 F- Fvoid Add(BYTE nIndex)
8 }+ M+ p' O6 ~0 _8 z{7 ] |7 l+ ^' ]( P) a
if (m_dwPos >= MAX_INVENTORY)
7 {* v) \ [7 w# u6 l4 v0 N {
! g5 u3 a8 i1 k/ ~ return;
! c- @) g; A# A3 g }
* B; H; C- ^: J8 z# P m_Item[m_dwPos].nIndex = nIndex;
" W9 j/ X1 |, \" s8 ` m_Item[m_dwPos].dwId = m_dwPos;1 u. c7 C3 ?2 n. a j* ~' t4 ~, y
m_dwPos++;/ a" @4 z. h1 Y; `; L' M7 M
}9 { m9 {( g/ P3 z. T7 p9 j
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
[$ _" E3 e% E5 t{, N, L) k4 }5 v( O, [
for (int i=0;i<MAX_INVENTORY;i++)
' m# p& A1 L" v1 _! ^: p0 Q {4 l' \3 A! [) c" r( F
if (m_Item.dwId == dwId)
% w3 y* u* t6 k7 D) y! o {
! y9 c$ B6 v! `% u, _- a! P. r return m_Item.nIndex;
& `) C0 n9 a- j) @ }. E1 L2 H" {3 i m
}5 \6 K+ B6 s+ t6 c: g7 C Q0 R. }
return 255;( i$ i: e: ~7 ?0 Y0 ?8 F
}
& ?7 p( I1 M9 ~. j% w- `void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
% |! e, T3 O% \/ x{
& g/ F& I/ Q: L) f' Y5 ~ BYTE nTmp = 0;
$ F- v2 u4 E3 T bool bDest = false,bSrc = false;0 c8 ]5 a$ |5 p9 D
for (int i=0;i<MAX_INVENTORY;i++)* F; K/ i5 ]1 l5 b u) i
{
. B; d, t5 C0 N3 T! b if (dwSrcId == m_Item.dwId)
4 u* n0 Y/ A* B4 I+ O {- m4 _, P1 V: l8 ~
//id相等 则 改变对应的dest和src
$ B Q+ u' G: ?7 n, B& m' i/ @ nTmp = m_Item.nIndex;, P" y) @; I4 u1 S7 j/ `2 o
m_Item.nIndex = dest;) ?3 `: `# U W
}2 n, K: P/ S& j( x
}
g; \6 T; q$ H6 n //临时数据保存完毕,交换开始 s& j% q8 z6 B+ p7 j' P
for (int i=0;i<MAX_INVENTORY;i++)
3 j7 j% `' Z9 ^- B" {6 u! z/ h) I {( f( A ?, Y& O W$ b
if (dest == m_Item.nIndex)) c2 _2 ]( w" P5 Y
{
4 \. r. N2 z. t5 D/ j) a //id相等 则 改变对应的dest和src
# X, i8 r. X; w$ F" Q m_Item.nIndex = nTmp;! N4 A3 B6 K+ R3 A2 L% t
}
2 \2 I8 i$ W$ E. m6 k3 p/ X }
% n0 z; m5 k* E) U}7 K) m+ p& U& m2 f
};+ i( L6 N N9 D7 a5 `: i
-------------------------------------------------------------------------. ^7 o, k2 `! p/ ~% B
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
% A- m' j* y" r6 I# F( B5 ~- u/ V搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
c6 e6 Z4 I; m/ ^) D- A+ A: v- J紧靠其上添加:
5 {1 @' P* a$ h8 ^7 xif( pWndBase == &m_wndMenu )
' {" w" W9 ?7 h1 ?( Z9 k{, d$ u# X, ]) }7 l, F4 F8 Q
switch( nID )& \9 m! I8 L' W" }3 v1 l3 F
{) I) O9 ~ T6 A" n
case 2:: d$ a5 A6 ^9 o( f$ d+ D8 u
{
+ G5 \/ q& A' u3 ?% y //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
0 a) `' L' Y$ ^, ]6 a- t' ~/ w7 P if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
+ p: o+ z6 }! j% b4 ?$ z& d4 i {8 |# G8 h0 ^6 F4 x$ g: u
break;
. }$ J, U6 g' g- h }" v' d4 a2 G; ?5 i6 i1 P- [2 R. S
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)4 B) A5 b" F$ V Q* m
{1 }: m. u& ?$ W( Z* Z/ N
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);7 C8 ]/ A# L, m( u9 Y7 X5 r+ X
if( !pItemElem )/ D; Y& j2 W! x2 U7 Q% X0 l8 E
continue;2 [1 o% B& w) w' v$ A
if(pItemElem->GetExtra() > 0)
" U3 D) @& D9 U continue;
, {1 U. J8 u4 i0 q1 G if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 9 w! v2 [* L4 T0 s7 B% s) K" @
continue;0 R' I+ f5 r" d$ ^( q! p
if( g_pPlayer->IsUsing( pItemElem ) )3 {0 v; f) Z8 v
continue;
7 [/ I$ k1 z9 j' H0 q: I2 x2 ^" { if( pItemElem->IsUndestructable() == TRUE )/ y2 c6 ]8 _+ Y; S7 x1 O% ]
{
" x: o& c/ Z7 i9 ] g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
$ Z: q1 d' n+ ~ R0 r' d continue;
0 N: M; C6 H- |3 ?- c- M0 ]( y* d }
6 b& y9 d6 E" X9 F' u( K# n/ T g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);( G$ w! \5 }7 N* R1 `3 s2 H0 a
}
! m5 c) s7 X7 ]7 R& k+ F0 M7 E break;( }# W r1 P3 x7 M* X; E) x t
}' \3 X* ^2 B( u u
case 1:3 _2 T$ j" b" l: ], [2 O
{
' O* m8 O/ ]3 ^9 w //整理背包
0 K; g8 \8 i! F //////////////////////////////////////////////////////////////////////////
, b; p/ l; B; @ w //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );# T3 j9 r( _% `. G- q) w
//////////////////////////////////////////////////////////////////////////: E3 h) B. D- p' X+ F, f% X- ]
//////////////////////////////////////////////////////////////////////////' N, G9 n2 @* e8 G! c
CInventorySort* pInvSort = new CInventorySort;
. i& z4 p: ]( o* l vector <sItem> vItem;% E/ j( e. h( [. R( k7 E& l
vItem.resize(MAX_INVENTORY);//初始化大小
+ y: }% ]+ \( X. q! r9 \ //////////////////////////////////////////////////////////////////////////+ j; K1 J% L7 ~# U
//填充数据5 ~; w4 i8 w4 O Q$ u+ Q; O: `: r
for (int i=0;i<MAX_INVENTORY;i++)
: a" `% j) H% W, f {
3 O1 r8 K3 |4 s+ s! \! y8 |7 T CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);7 H4 T& s1 E" ~1 |
if (!pItemElem)$ w; e: U, X) B% Z6 @0 N, b+ b
{$ @9 S# ^# k9 T$ Q
vItem.dwKind2 = 0xffffffff;. _2 ]: S( w* b5 c; A
vItem.dwItemId = 0xffffffff;+ H* Q1 F9 J+ J6 D
vItem.nIndex = i;
5 j; X! w% m. F/ @8 ]* u, V& \ }else {
0 }* R. T. H$ F- Z7 p& y ItemProp* pProp = pItemElem->GetProp();
9 W: A6 O/ J7 @% P+ b5 Y vItem.dwKind2 = pProp->dwItemKind2;
# D3 \7 x; s0 q, Y6 K$ Q vItem.dwItemId = pItemElem->m_dwItemId;
0 ~9 L) C# `$ k& \# m vItem.nIndex = i;) Z5 x1 W" ]5 m" ?
}2 {7 w7 j; G( ~; a- J$ R4 a5 H
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
- B/ Z( B9 @+ h/ K. C }
_/ P+ i* z s% R( n+ D& h //////////////////////////////////////////////////////////////////////////# a) E6 Y, a1 n8 y% F# j% b$ i
sort(vItem.begin(),vItem.end());//排序
. N! D4 t+ D# `2 M& ] //////////////////////////////////////////////////////////////////////////
4 }7 D4 M7 C% n, l, l) i //交换
( G/ F$ E8 b, W2 w! i4 O P for (size_t i=0;i<vItem.size();i++)* w/ D9 e; E$ Z/ t1 W# }7 y0 ]
{
# I1 m6 c; @' s' F" X: J //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);0 y& J+ u' K4 a
pInvSort->Add(vItem.nIndex);4 I( z) W' Q' a2 c) G
}& }3 x% e5 m1 c. v
BYTE nDestPos = 0;1 c% g4 c/ q1 B& u7 G) G0 @& q
for (int i=0;i<MAX_INVENTORY;i++)
2 P6 }9 {& t* r {% }* }/ o1 O5 B- l
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);0 F" I5 h$ j ?, w- K
if (pItemElem)
" W: J+ T+ Q3 b( s/ @5 w; S0 ~3 }" L {. ?4 O- @, Q) R2 x4 C- ^
if (IsUsingItem(pItemElem))
& S5 w9 |- E- C0 i {
2 A' j2 |/ x( m //这个位置无法放: O9 l: U7 u& `# H+ m& @ X8 p1 q
nDestPos++;
# K2 Q1 e- a& P+ W }
- b, ]& j) I. w$ d; q }7 J3 G: ~% f, B2 t
BYTE nSrc = pInvSort->GetItemSrc(i);# o" f; g' Q% y1 ~
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
- [& l4 g& @5 Y if (pItemElem)7 i; P) @5 l7 G
{6 F' b1 f) |3 |+ d: V" L
if (IsUsingItem(pItemElem))1 b$ l: [$ c7 I
{
: n5 m( L4 e. w- ^+ a //这个道具无法移动,跳过
, T* b: i# v+ g) Z _6 U' n continue;0 z3 ?5 v9 D0 s4 X4 I6 Y
}
c% b( p o. P }else{
1 L# h/ R% [5 b+ q3 b3 @ //空位置 不用动9 k" Y3 t9 z$ @- @/ z
continue;1 R3 S I9 c$ { c) X+ D0 W
}
# d3 A8 u l# N* V, w: r% O+ ` //////////////////////////////////////////////////////////////////////////
' [; g3 Y! [/ q //开始移动
9 D. l+ i% G* j! |& `3 z if (nSrc == nDestPos)$ c6 ]6 `- G# x, k
{
( t8 V! u1 M5 V" W# O //原地不动5 I; a$ X$ ~: F; y7 X
nDestPos++;
5 T k2 b! r o( a: J continue;
" t$ W( R1 ?- D( l2 i }; Z# L: o+ T" Z0 G
pInvSort->MoveItem(i,nDestPos);
A+ b o, ~8 g8 m) _ g_DPlay.SendMoveItem(0,nSrc,nDestPos);. J" u0 d" w7 T f9 _) H
Sleep(5);
# Y- \6 O y p8 d( Q/ `1 o& X //Error("移动 - %d->%d",nSrc,nDestPos);: J7 R W( M8 [/ C4 P
nDestPos++;
* s1 ^5 K5 k- X }
9 X- {! \( x% t' a( O //取第一个元素的信息
) k) e! A7 Y8 x4 ^1 y. N) [ /*6 }/ M# M. G: o/ y1 W
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)) {( N9 T) w/ }4 k
{
6 c2 K' A$ r4 M4 o3 A2 m2 P Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
' G4 k o5 K5 p g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
+ w: f1 ^$ R( l1 K# S) K }
2 h K) `+ U# @: J; j) z, U */! o( @& G, I$ R9 M) G# h9 q0 U' Z
//////////////////////////////////////////////////////////////////////////- D+ d. Y. r' G6 g# l1 ?
break;( W; P* @1 }$ G9 [5 c+ D
}* J; t) s2 {* G! _( D7 R
}
' L+ Q8 I# c7 s! F, H6 J' q}
0 O) }' Y/ [! ]0 t$ y; X' Sm_wndMenu.SetVisible(FALSE); \" H- N3 S n* R8 O8 Z( g5 ]. c* G
/ b) O0 J/ h$ r- R; x% r9 o--------------------------------------------------------------------------------------------------------
: Y9 v+ w; Y i; f0 ~! t搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
1 n/ @9 t" g! P" l8 A% Z7 ~{. Z, v, Y) O3 T; C
BaseMouseCursor();
O- o6 K0 ]; f}
4 h( H$ D# U9 ?# y1 z* b$ S在其下添加:
/ y( X/ ?, S- [9 F; i* W x- Gvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)+ o! [( d1 D# v7 j
{$ i( j: p- J+ w
m_wndMenu.DeleteAllMenu();
1 o( `2 P% e3 ^8 N6 Y5 bm_wndMenu.CreateMenu(this);( |% B! v5 q$ w9 d7 T' n
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
X+ S9 G7 o5 C3 y0 c2 @0 @% |6 n
. o8 ]5 N% {+ W( Y" V0 K8 E9 K6 Fif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
$ I* @' L+ x( E" i- U{9 f2 Q8 `: w( Y. d7 v* ]6 J# I
//P以上级别才可以删除所有道具
' j3 L/ B3 h, H2 ]7 a# ^: z m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");9 u1 v- Y4 z8 P5 Y3 C! s, m5 d
}
$ o" h/ { |4 w( d" I8 M% a+ [m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
1 p- T! G' ]2 h$ S: v* B) R5 G: vm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
) \7 K& a+ z) ^) u$ o+ f, Wm_wndMenu.SetFocus();
3 A: j+ f/ Z) O, H% N7 z}0 _* F' E( e- I$ K: A
------------------------------------------------------------------------------------------------------------
4 K' F" U- N6 q*************************
8 K1 ]7 I4 h4 f- Z5 m6 z* f' v. I! @9 pWndField.h文件; L( t; i* Y9 W2 Z& g
*************************( {5 Q8 C% m5 X2 s" t2 ?* ~2 C$ ~
搜索:BOOL m_bReport;$ ], j" r0 B/ a$ X! a
其后添加:
5 n0 [! z" e+ T2 Y& B( rCWndMenu m_wndMenu;
9 J5 D+ L. G$ g5 o! V, f搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
! _" Z) ^: O- x% g# U其后添加:. w- m6 V `: W' p! @0 H& _1 Q* U
virtual void OnRButtonUp(UINT nFlags, CPoint point);- n. d1 [7 L% l; Q1 y0 A
! r; Q; I" A, y1 |% f( N9 K4 }! b k( [7 U$ J7 w* ?" g S- p5 m
|
|