|
|
源文件中_Interface文件夹下WndField.cpp文件
# ~$ }1 [8 {+ g4 Y% w搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
% Z" F( g0 c; z2 v0 C4 Z& N8 \7 m2 o2 k! \* X Y/ T- {. j
struct sItem# s% z1 }5 y. T& u1 E. @
{; q5 n1 k _3 h, h$ E, a# W
DWORD dwId;+ Q& J0 _6 @6 m" b5 C
DWORD dwKind2;. p/ m6 Q9 n1 Z7 m- m
DWORD dwItemId;
: s `- D6 I) y- xBYTE nIndex;
6 X5 W0 @' U* X- B$ TsItem(){
# L% }$ j+ s: @ dwId = dwKind2 = dwItemId = nIndex = 0;. S; T+ H! N; L! d% _7 z
}- R3 G4 H$ X! z" r4 F* L
bool operator < (const sItem p2)
5 z% q7 @ b, w+ B7 c{/ f* J+ o, L8 `" ~( Q$ L7 |, W
if (dwKind2 == p2.dwKind2)
9 G& e: o8 ~$ a+ M3 } {
M& W! d% G( d4 E1 ~# q3 J0 V: x& c return dwItemId < p2.dwItemId;
' x; L( T4 B4 @9 @3 ~, A& K }else{$ a, ^+ W' d+ c% \: s, @
return dwKind2 < p2.dwKind2;: ]7 g3 g1 D8 R: r+ r
}3 Z' K- a6 Y2 T5 O
}
. E0 J- P- \# B0 B: u};
2 y2 o% y% T5 c8 G& w0 Q* h, G; u4 Aclass CInventorySort
0 Z- y3 R# m2 E" d2 d{ \. i7 I1 b8 X% p: M7 ~
public:* h# Z8 A* p6 K* i; J7 B. K
CInventorySort()/ U- ?- l, Z; R% P& ~4 d6 B) _
{) u3 {1 ]% [( @' G( C
m_dwPos = 0;5 l: V# x4 I! r
}
' S0 D5 U0 g2 i7 s! V4 T( h7 K~CInventorySort(){}
$ G/ X8 J. v/ L7 `/ Mprivate:6 F# @* N0 L) d8 z7 @1 o! e
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息2 Z+ k5 S0 h& `
DWORD m_dwPos;% L% f7 L+ ^! }9 i; C! D- U8 a
public:1 i* L; X- X' t+ s1 s0 W# j3 t. G; [
void Add(BYTE nIndex)
1 F3 s q4 f) x6 R7 ~$ j{. A W# n. H0 X0 ~3 x9 R
if (m_dwPos >= MAX_INVENTORY)( t+ G- A# N/ D0 y" t& P. ^
{
) E0 W1 H$ M+ B3 e return;1 d0 i9 Q# d' Z7 B/ E; m+ R
}9 b; N6 m7 D9 w$ }; H9 c
m_Item[m_dwPos].nIndex = nIndex;- P6 w' a K- k: u3 k
m_Item[m_dwPos].dwId = m_dwPos;
- |& l" V6 q v; D: I1 H6 c+ ] m_dwPos++;2 j+ ^3 A9 n1 ]- ~8 N
}/ Z# t; x* L1 o9 |
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列2 m2 B9 m6 a' f0 J
{* e9 y- }1 E) `! Y+ H- f& m$ T2 m
for (int i=0;i<MAX_INVENTORY;i++)
, ~' U' B% \5 s3 ?; _+ V, w" R- v {$ L/ M( @/ ]4 v/ P1 b* A# Z
if (m_Item.dwId == dwId)6 D, N5 p* f+ j* X( K# a% m, W
{" v* S q; o Z! C1 [. _
return m_Item.nIndex;
$ M% T+ r+ u, s5 }1 S. [8 z! I' b7 [$ J1 h% K }' } q5 a8 _# w: @
}
4 w1 n. s) f& Z# o return 255;1 B2 g; O, B/ J1 z ^. X/ t
}) t' w6 W. g, h
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
9 I# r4 f# m# f. ~6 |) B$ d9 s9 o: T{
; q2 y- e; K x. X1 B9 ?( E/ d* c BYTE nTmp = 0;9 {' i7 U L2 J/ B* @: T* T( m% _( r
bool bDest = false,bSrc = false;
+ J& h. H' T5 Y7 o4 e4 M. v0 ` for (int i=0;i<MAX_INVENTORY;i++) v; n. p9 D- F( x0 K7 |6 O8 o
{
# |# K9 @ J' g" a2 g" R; M! h3 L1 v if (dwSrcId == m_Item.dwId)
" e+ k" Z. `9 \: F1 M {
6 U1 o9 H4 f) F! r3 D //id相等 则 改变对应的dest和src
! C( R* {! z" Y0 M9 e nTmp = m_Item.nIndex;
9 P4 F% R9 [* Q( Y. s; L m_Item.nIndex = dest;
" J* t( s1 E9 B& [+ b }' l% }- R7 l. E5 t) g: V( }
}
( r6 ?, t9 i1 [7 ~8 j //临时数据保存完毕,交换开始
# g% h/ k/ l- |! ^ for (int i=0;i<MAX_INVENTORY;i++)" L1 h! M/ x/ F8 C3 j" q
{' Y. C) a- p( i. v9 ^. G8 `1 U
if (dest == m_Item.nIndex)
+ J1 J$ x1 h/ r9 Y {* G: d. _) j$ ?5 P
//id相等 则 改变对应的dest和src! |+ H' f F7 w+ S2 w
m_Item.nIndex = nTmp;7 G3 r# F! w9 {* h, t# L9 }( o
}5 l$ G! w+ |7 |7 G; D+ k3 w
}8 i8 j" C! @( o' e: H7 F! h1 q% Y
}
# s1 U$ g+ {; ?7 A3 b};
# v0 N2 C& U; x* {9 u! ]4 Y-------------------------------------------------------------------------
+ K( |. ^4 _' S# Z依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )# i- M) m" E3 A# n6 E
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);5 I- a8 Z/ W' b/ Z* X
紧靠其上添加:
0 U0 ?( U; d4 ]6 v( t. hif( pWndBase == &m_wndMenu )
4 d" `7 H( c, g# b Y0 o{0 `8 ~2 Q" F* `5 d! C
switch( nID )
- n* w$ [: ?* e4 }0 T7 A4 [% B {
5 a- I7 K" t# b5 B9 ^ case 2:/ [' \! M8 }1 H. B* q
{# Y7 j4 J) J7 [) ]6 e2 ~& X: b/ G
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
5 i* o& E. O1 H5 q: @5 N7 B if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
: Y0 W/ l: s' _( M8 F {/ K% ^" W2 D7 B. u3 D
break;8 h$ Z. J, |3 z8 c* o! E( Q
}! Z9 t+ k Z4 u2 |* P
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)$ ^. c. g0 W) f" B6 T: G% }
{
3 ^9 Q9 }6 t' a, ^$ O5 i# ` CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
6 }5 z2 d B1 O" s" W7 p if( !pItemElem )
! ? Y! d) U& W* Y, L2 A continue;
) }$ J" e/ C% K1 a if(pItemElem->GetExtra() > 0)
3 ]3 s0 O9 h/ N/ C) e2 A! g7 @ continue;- ]" t5 ^* Q0 b* `2 N
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
# j$ E2 u0 j) p1 ]2 w6 R4 D continue;
* F( I! M: m9 {8 @: N& N if( g_pPlayer->IsUsing( pItemElem ) )9 `5 |) T! T; t! P: w, ]
continue;
, n2 h6 ~$ R2 c# V$ N" z if( pItemElem->IsUndestructable() == TRUE )
& i& l' m- X! b1 c {
, Q& y' R W/ V% G) E: I$ i: X7 t; ~ g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
( \; a! x2 X" u( a* v continue;6 c; l* {2 B$ h
}
9 Z9 g: W7 b: u2 s g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
5 C y: q' p# ?7 e7 |/ a1 Q& y V }( L1 ]' G( y& e# D2 L
break;
9 v& i4 N1 {: S6 N }6 M. Y; W* W$ D1 a/ E' q$ B( \: r
case 1:# ?" }/ R, `; I4 {. m g
{+ S7 E7 w8 @( X9 y) h. [% s3 w- ], ~
//整理背包
9 g0 Q! v; c- |% I$ i- E+ K //////////////////////////////////////////////////////////////////////////
5 ?! W: Q9 n( x //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
' R! E* z6 `7 D& t+ v) E! g0 k& x //////////////////////////////////////////////////////////////////////////% W- g8 c- `, |! S
//////////////////////////////////////////////////////////////////////////
& r' Y, H5 h4 p. w+ s8 p- K CInventorySort* pInvSort = new CInventorySort;6 u' k0 ^* k) ` |' J! j
vector <sItem> vItem;
3 L4 Q6 T# c" b$ G vItem.resize(MAX_INVENTORY);//初始化大小
1 y1 L' H {& Y0 g$ S | b /////////////////////////////////////////////////////////////////////////// T9 c' F' M, Q+ ?7 Y$ x- W6 ?
//填充数据
) l0 t5 ^/ K0 H% u. g4 p0 W for (int i=0;i<MAX_INVENTORY;i++)
, H+ a- Q) W; z& [1 A1 O {' D' i+ l* V: O9 n1 y" X
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
; G8 X6 K3 Z" I$ g0 ~ if (!pItemElem)
" V, \0 o6 X5 |9 ^$ c {
9 @% N! F- t u J$ d vItem.dwKind2 = 0xffffffff;
2 \2 H$ @4 U9 Q+ }' M: I* H6 c vItem.dwItemId = 0xffffffff;
) E9 G' Q9 d- N" |/ F" w vItem.nIndex = i;# _* Q/ @* h4 i% r
}else {
* i; y& x( w" G- X# l* E ItemProp* pProp = pItemElem->GetProp();
- }& u- K! N# q X3 D7 m vItem.dwKind2 = pProp->dwItemKind2;
9 Z. Z8 S4 m% @1 D$ D9 p9 [ vItem.dwItemId = pItemElem->m_dwItemId;* r" X2 a1 X) ]( ?9 o8 s
vItem.nIndex = i;
$ V1 ?! T5 K5 d, W4 K. N) a( ~ }
5 M, _0 B6 W6 A; }2 ] //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);- p, ?1 z1 d# U" J
}2 b# f! R+ U- v3 G. G
//////////////////////////////////////////////////////////////////////////8 ^1 I+ B% ` D/ d
sort(vItem.begin(),vItem.end());//排序6 [/ p7 R$ v- d
////////////////////////////////////////////////////////////////////////// ]- ^! |/ Q: X% D% U" ^- r
//交换
0 O. Z. p+ m# d, A for (size_t i=0;i<vItem.size();i++)1 g% y- x4 c- H# \4 Y( u2 c
{/ R! x3 M) n1 H' |/ n
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
. C x8 E" `( k2 B pInvSort->Add(vItem.nIndex);
2 I! T3 L4 m+ Y2 f- H1 ] }2 X$ n4 B, X% u% }4 {, v
BYTE nDestPos = 0;
/ C& l" {+ q% n/ A+ s3 B. U4 F# Z: y for (int i=0;i<MAX_INVENTORY;i++)# O, }# G6 J* X) E4 |
{
# p! T0 M) \0 f+ g CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
9 g; o! |+ T' [ if (pItemElem)5 R/ d- H% M; a# d% ~2 P; D1 s7 m
{
8 W1 O8 [: }% R& N+ N' c1 W5 \ if (IsUsingItem(pItemElem))! b+ I) q7 B n( x" r* J
{/ D' v6 w h0 V/ }5 E
//这个位置无法放
( }1 m g; e6 M& R- k! q3 g- {5 f nDestPos++;
) N& `# ]8 i+ k% T }
# v s5 D& ^2 g _ }8 I7 o; q- N$ {$ Q
BYTE nSrc = pInvSort->GetItemSrc(i);, @! @% x! `* E0 b( @5 ^
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
. D" v- u) @, z( y& ^ if (pItemElem): `, @5 }' q$ M6 h# }6 w
{, P" v* [( F( c3 u9 F' K
if (IsUsingItem(pItemElem))" o( z$ ^* L6 g
{+ } f _. S# D. T3 i# y
//这个道具无法移动,跳过) `' X! ~' x. b
continue;6 P* p' u- I5 a V% U1 L9 E6 J* O
}
# {& t$ ~$ N9 f5 n8 u# M0 B$ T }else{, d1 z0 W+ `2 \6 l1 @
//空位置 不用动
3 z; j N0 J$ H8 c continue;
b' x' o& ^9 ^) E) G0 k5 ^& K4 s }
_& i& a4 V d$ |& G //////////////////////////////////////////////////////////////////////////
7 A2 |6 Q7 I# @6 [; G% T2 B7 v //开始移动
) z) S( J, \: q/ M$ [7 c5 l if (nSrc == nDestPos)! c) ^( G4 c& b; K/ T
{' [2 g7 A5 ?2 |5 N. r" K/ y" H( O
//原地不动
: G+ A" [3 i& Z6 V nDestPos++;( Y2 I; ]# U+ w4 {% ^1 \8 K
continue;
6 [* S! q! H! L" b5 F1 t }
5 D$ Q! r/ E3 o( \& n1 ?" @ pInvSort->MoveItem(i,nDestPos);
g5 m1 \0 P, X g_DPlay.SendMoveItem(0,nSrc,nDestPos);* k: W+ B$ }) \+ A2 t0 }
Sleep(5);1 h" U" z8 b9 i# d( W
//Error("移动 - %d->%d",nSrc,nDestPos);
# ?1 D4 c2 ]. q" V! E- B nDestPos++;
2 ^7 o. q8 o# B' r$ c: ?7 D7 h2 q }
0 X, d, E1 G4 I //取第一个元素的信息
: S, W) C! s+ b /*1 k7 A! _/ }: L3 X s6 Z2 Q
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)' w- M9 P0 u1 c
{
- a1 ^0 W9 f) O: B Error("Move - From:%d,To:%d",vItem[0].nIndex,x);6 f5 [+ f: [( ?
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);. h. W" K/ r' N3 f$ ^" P l3 [
}
% j0 U( x4 Q6 D" e N */* x; X$ K5 \, k" d
//////////////////////////////////////////////////////////////////////////
5 \, B3 W( |3 o. E8 F; |1 b break;, x8 N7 y1 p7 g/ y3 P) s3 h
}
( e& h- f Q0 s! y! x1 K; P+ ?. g }
& o& Y- k5 g1 a5 o% \* K}
# T) @5 V3 D* B9 a4 M+ Bm_wndMenu.SetVisible(FALSE);! Q& ?, j4 Y3 u, [( d
$ j( o) P) D2 v: W
--------------------------------------------------------------------------------------------------------
" \5 U# }" k* s5 }% \9 [0 D2 l- a搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)$ x) q% o" I* P( I
{
7 K% ~6 }6 m: O7 R1 EBaseMouseCursor();; \/ N# F) {/ z! Q
} y. z" f7 d. _ V7 w' {
在其下添加:
% L( Q* {5 L7 o1 g p+ wvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point) |1 T. y" c* A; d
{ Z6 [- B9 k4 O' z
m_wndMenu.DeleteAllMenu();2 W) [& x& ?# x6 C" p( a
m_wndMenu.CreateMenu(this);& w3 Q- _0 `) g2 r
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
0 k5 e$ T& ]9 J$ k( u* f0 ^! X2 F
% @7 M; b: \, {3 W5 [& t% oif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))6 p3 S; R/ _ X3 \# l, U
{8 Z' r$ {; `" H/ k" e5 I5 O
//P以上级别才可以删除所有道具
2 T& V; x% M! j" |$ G t$ T# B. c m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
' G6 X- F* L. @2 l}, R3 o; Z* Q) [
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );9 X# O4 B) j9 J3 }9 ^
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
) u% C7 R+ W# j5 I. q) K! g) bm_wndMenu.SetFocus();
- W& f F D6 [6 q8 j$ b}3 Q( m; T" Q9 ]
------------------------------------------------------------------------------------------------------------
/ E: D2 Z T* p3 y) R: Q6 {' K*************************
4 L5 e) M1 a/ t6 m+ |WndField.h文件& U3 J( S- [) f" }1 t
*************************( K; A1 ]% N3 `3 a- b
搜索:BOOL m_bReport;
* Q2 v. l5 r. q- \1 |% S其后添加:
( N% f3 s8 [* y, ?2 l. dCWndMenu m_wndMenu;2 D0 F# @' k1 u% O
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
) c f2 d3 l0 Y m8 d# [# w其后添加:
# [8 |8 U% e; V2 `1 ovirtual void OnRButtonUp(UINT nFlags, CPoint point);( h+ x. W- L# ]( _) y5 R9 w4 o5 ^9 M
) s. k. w, N: R5 I" r
0 {# H1 P. }* m* i6 z& s3 v' [ |
|