|
|
源文件中_Interface文件夹下WndField.cpp文件
1 W% }# k- C# c- v3 o# _% D6 x! K搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )8 f& P& b) Z/ Q3 W; B) j
: E9 o: S, I# \: }! d# `( tstruct sItem) j, C( i Z: g( Q8 [2 u
{
. u2 A, I( J1 X G% g! eDWORD dwId;
; x+ E$ \! N' _! D8 j& m! pDWORD dwKind2;9 f! X' U" J$ C
DWORD dwItemId;2 j2 H, M, A9 I, b: m, O
BYTE nIndex;8 a/ y6 ?/ U, C$ K
sItem(){
+ _+ s9 Q% Q8 u0 \ dwId = dwKind2 = dwItemId = nIndex = 0;
# Y6 O( Z v) C# Z}
& @( c7 O& o; P0 r( K$ ibool operator < (const sItem p2)
7 l K! q" q! R R) T& }{( N9 t' N$ ]. W1 f% m0 C. x
if (dwKind2 == p2.dwKind2)3 ]5 M" c) }8 x- f! O5 \% N- s
{# a- q" N4 N" Q6 ?8 M' S, q
return dwItemId < p2.dwItemId; D# k- i+ x! _ E: s. ^4 `; s
}else{
5 R* E+ b7 } r1 h; d return dwKind2 < p2.dwKind2;
+ W& a0 v/ |+ c3 b }$ k7 |: j! K4 f+ d
}( @9 H" @( L2 @
};+ j3 F. {/ g: V6 o6 ]0 H
class CInventorySort3 i& _( W+ S! A; ^* l5 `
{
1 n; ]! o$ k2 vpublic:) u1 ?9 }" Q, h, W! g
CInventorySort(); Y0 b0 n8 K! H7 G6 L3 R. i
{$ ]7 x) A4 N7 s7 j B2 w
m_dwPos = 0;
" i0 o; |5 H! [8 C& v- c}4 L8 ?& y1 K7 ?) o& H- [/ k) P5 U
~CInventorySort(){}
+ X5 \; {6 w/ s, y& x, y8 ^private:
- k4 b$ H) Q% m' Q* D2 P* O) OsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息- D( Y) a( V2 l$ I
DWORD m_dwPos;4 q# m; G; M. _3 T' q
public:) C. L4 a1 o9 B/ p
void Add(BYTE nIndex) }4 G( [4 H; m0 U) ^
{/ _. }. ^/ ?0 L- }+ H
if (m_dwPos >= MAX_INVENTORY)
! _) o: R5 n! \. a {
, R& S& I8 `2 k2 g# D; ?. M3 c return;
4 S3 r) n- U( K3 m }8 |1 C) W7 k1 G: A9 s: z! T
m_Item[m_dwPos].nIndex = nIndex;
7 P: ~2 `4 n0 N U+ m9 Q m_Item[m_dwPos].dwId = m_dwPos;- B0 q4 q! g4 X! [ Z7 y4 w4 I" Y
m_dwPos++;9 g/ b+ O/ W" I* a. A
}
( v' y: W0 `1 a7 hBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
5 E/ f7 j6 B" C' X{( ]" N" w4 {9 z0 \8 l* R
for (int i=0;i<MAX_INVENTORY;i++)
$ R) d/ E- y; M0 B {
1 d- d% D4 a% u6 R, A9 V9 S+ P' n if (m_Item.dwId == dwId)2 ?9 z- Z# w- z% s
{
- O. \# B% a% N# l2 x3 m' B return m_Item.nIndex;7 ?3 i) _; g4 Z
}
9 i+ G) R' Q4 Q9 l2 Y( C( U }
, N) F, ^8 z) F+ f1 Q8 v; y return 255;! V; Z6 L% V0 d0 }; e
}
" Q$ g8 i) x" B, t/ Q1 X# [; fvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
- b2 b/ `: }9 c# e& Q2 a$ e{
5 ]! @4 [6 Z! `1 @% z1 }! u& B BYTE nTmp = 0;
2 o1 E4 b p* ^1 h. I6 t bool bDest = false,bSrc = false;
4 R6 B) n; A" ` for (int i=0;i<MAX_INVENTORY;i++)9 _% x( i* s. Y* t
{ g6 m5 P4 I& S/ [
if (dwSrcId == m_Item.dwId)
( q. N- B, [7 h" F& J; C {' M/ H( Z, J. B0 ]" Q
//id相等 则 改变对应的dest和src
7 h2 K! I. r: ?* T# ?8 [. o nTmp = m_Item.nIndex;
: j! E* d% Z, q! n4 e& p) ~# J m_Item.nIndex = dest;
6 Q6 R: L5 C; j/ n }
% ?+ V9 i! o1 G$ w+ J, H% A }3 c! f: V$ q6 M, \5 z# t* |$ z
//临时数据保存完毕,交换开始
$ U( |3 |! s1 [ for (int i=0;i<MAX_INVENTORY;i++)
8 H6 n( f7 b l: t! j8 G7 \. _ p" D" r {
6 V! X- a o5 R3 c if (dest == m_Item.nIndex)
; f" r6 B. [4 L5 R' k" r0 S" g {
3 Q p1 `# f7 f" q/ x //id相等 则 改变对应的dest和src: A" r, [& H3 L5 L2 l, j
m_Item.nIndex = nTmp;( q1 J# v2 Z" v/ R" s% S
}
: \6 U4 F7 U( g; B0 B+ _. Y$ {8 A }
, p- `) r, @6 ]}- f) e) Y; [ G# v8 Q1 V! g
};5 e. @$ r+ t# K5 J/ Q+ e& c
-------------------------------------------------------------------------; M) J5 G! _+ ?' _5 _4 ?
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
3 g$ W. @/ w1 a7 r" E搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
/ R& \2 r% V" x# d. _紧靠其上添加:" j8 N$ ~+ T* Y; h! G
if( pWndBase == &m_wndMenu )
' V! X: n: K' h7 p+ Z, V{
8 L6 I9 L* ]' h/ [( O switch( nID ) _6 k- Y6 V$ T: @1 x5 `. L9 U
{- v, I7 ~+ E. Y- B; G
case 2:
; X8 f5 g9 q+ }+ T* Q4 J {
9 ]' T7 j S4 b8 ~4 s d) \ //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);( u3 w5 w; I& ?2 a
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))$ W5 {& Q( s9 ^5 a5 w
{
5 F' o$ ?8 i# p5 j break;) L/ y3 q4 @$ m, `
}) E6 R% F1 v" ^
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)$ [+ F0 c. I* ?& y
{
, A8 l5 o0 }0 \* c% K, p. \$ l! p4 s CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
1 t; m+ x+ x# ~5 S* _2 ^4 h if( !pItemElem )
5 X( q1 e5 V2 N* g8 M( F continue;9 y8 @8 `% Y. {
if(pItemElem->GetExtra() > 0)
0 R, s, ^" S& s8 l: m* o continue;0 L' T+ u# D1 K7 B
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
& S+ _6 d; d7 z. R- }2 K9 k$ e continue;0 W3 Y( f9 c" v$ Z, f5 \) H& v& O9 b
if( g_pPlayer->IsUsing( pItemElem ) )0 V3 Q D; L. ^( {9 d' i
continue;
1 C1 j0 @8 o/ n# o3 I if( pItemElem->IsUndestructable() == TRUE )3 L2 ^$ x+ O9 ~' g
{
, T6 }4 J; t3 @6 F8 G g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
2 V) q* J0 O2 R4 u continue;
! k* t e2 `; ]% | }* q5 N$ n n/ u X t: q
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);1 n; R$ }1 L: K' m
}; \) e3 N# I* Y4 x" @
break;
6 C# v5 b/ `1 C }
2 _- m' m$ ?. ~% K2 V case 1:
* j7 x% w- U5 L {
9 l1 w$ f' [$ P& k& Q7 ~5 P //整理背包5 E, g; y/ {( S
//////////////////////////////////////////////////////////////////////////1 @% {. A, r0 v+ ~8 D
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );( a3 \0 p/ G& f
//////////////////////////////////////////////////////////////////////////) h2 `5 Q6 A# j) W/ D* d. j
//////////////////////////////////////////////////////////////////////////7 }+ D; \7 X: E" ^
CInventorySort* pInvSort = new CInventorySort;
' d8 R" i5 H6 J$ o2 t8 p! r vector <sItem> vItem;3 E7 ]) A/ O5 H/ J6 S3 U: D, P
vItem.resize(MAX_INVENTORY);//初始化大小: g9 F& y, E, j; n7 l
//////////////////////////////////////////////////////////////////////////
/ G. R) X* j" c8 o //填充数据
& m7 R% m4 V" M6 s# O. P for (int i=0;i<MAX_INVENTORY;i++)& A6 o& X" {- N5 F- H9 Q; ~
{
7 }4 n/ ?+ {4 q+ Q! U) E CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);; i% g8 ~0 Q% T$ f/ _
if (!pItemElem)* B/ F5 O: F' y& r* b) w3 ^" p' ~- k& ^
{3 C" }# s) j6 \5 |1 F
vItem.dwKind2 = 0xffffffff;5 I2 u7 U& c6 h1 i
vItem.dwItemId = 0xffffffff;# g! W1 T( O: g; O
vItem.nIndex = i;! G/ @. A- j$ V* u# D5 Y
}else {9 O7 w4 J5 E0 R& m* ~! A
ItemProp* pProp = pItemElem->GetProp();5 h$ a9 J2 l m3 \9 O% ?
vItem.dwKind2 = pProp->dwItemKind2;+ j! t( Q5 G0 z: c6 ^
vItem.dwItemId = pItemElem->m_dwItemId;
4 h5 W4 s8 x$ c* K vItem.nIndex = i;
- f9 Z3 f T% _4 _. b }
0 H/ Y+ H [* X+ c3 m //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);/ _+ a+ x; B7 A4 n. L* ` g- j
}% |1 H" f! ~8 g/ J4 y$ l
//////////////////////////////////////////////////////////////////////////) ]. H7 u* i% U7 N- x9 O- E
sort(vItem.begin(),vItem.end());//排序6 u6 R/ x- U4 K# z* \( I. m
//////////////////////////////////////////////////////////////////////////0 L. w, D! O# s! p! l
//交换
! P* V M7 G# v6 w7 T0 U _ for (size_t i=0;i<vItem.size();i++)( \2 x, Y2 V& J
{7 S* n( U" @& ] C+ |' G
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);; Y |% H* H: p% S; u' z
pInvSort->Add(vItem.nIndex);
1 c* P( @4 E5 Y) V% V* O% U0 ^ }8 j* Q8 f, {" J j9 I& s/ ?8 T' j/ T
BYTE nDestPos = 0;! G4 z( U' |( c( N5 i( O, l
for (int i=0;i<MAX_INVENTORY;i++)# o4 d/ k, j1 l6 Y9 U- L; t7 D/ q2 v
{
6 q6 b' Y. o# _: X CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
+ i2 n& ?$ b! p# J1 r5 d( U# q if (pItemElem)
9 C8 [6 ~ S" w; | {
/ h! ~% @$ `3 E; |1 B, _2 c, P if (IsUsingItem(pItemElem)). L. z! [$ I0 O7 B j5 j3 }
{
! B/ S2 K* R* S; c ?$ ` { //这个位置无法放9 A8 z3 S) N. u' l( b
nDestPos++;# c" }3 J9 U) l! E2 T) g* W
}
/ ]8 g3 t# n: k9 B% | }
- r: P( O- D( v3 _# |! S BYTE nSrc = pInvSort->GetItemSrc(i);
6 K9 [1 O! S' ~: h9 {; p& S) Q pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);% L- r( y& k1 M& m# b7 }; t
if (pItemElem)4 |) r' Q: s+ E4 N, \. B5 z6 G
{
/ ?; |3 d7 ?8 D0 U, |( C if (IsUsingItem(pItemElem)), U: \- B- a4 a9 y% X. \
{) x8 Y' K4 D: U9 S
//这个道具无法移动,跳过
/ H3 l0 ~9 p3 q4 u; W8 w6 {0 [ continue;
: S. Q+ o9 I6 j2 F( C% B }
5 o9 ^* k" ]6 A }else{$ x" _/ ]+ b7 |. e) c; P
//空位置 不用动2 ~. n1 [1 `& p2 D/ j6 l
continue;
# b2 W7 {4 E! c/ I1 u }/ D/ @1 r6 M4 ]7 [- v
//////////////////////////////////////////////////////////////////////////
& N; { ?/ l* e5 w7 \ //开始移动
. I/ j3 P( H9 i2 l2 m if (nSrc == nDestPos)
' c. ]' ], ~5 v& H* t6 }6 q {+ [9 C. U2 J2 p+ l/ ~
//原地不动
1 Y) S- F# x0 X: ?( O( k1 @1 d* x nDestPos++;
( t' H+ i4 P6 s. }( }2 } continue;# h( {1 q& m+ ~2 j j. E
}8 L6 d8 a/ c. A& G: S3 B% U
pInvSort->MoveItem(i,nDestPos);
- n5 b7 g( o+ ?* _9 ^3 y K g_DPlay.SendMoveItem(0,nSrc,nDestPos);
, b' K0 ]% X$ W9 E, l7 ~5 I9 s3 D Sleep(5);
. `3 T7 d) @8 @. f7 N7 e //Error("移动 - %d->%d",nSrc,nDestPos);
) ~& S! D$ z F, q# R8 r nDestPos++;* q, e" D2 A- _# x2 h s
}
+ U6 T# u2 y2 ^! M' n, {5 Z# s //取第一个元素的信息# l/ H! ^$ b8 N
/*; @1 B, T+ |# M$ j
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)# U" L7 P) C- O0 J( E
{# E+ E3 A& n2 J5 [8 |+ G, c7 E
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);7 M* u8 v0 o! ?+ S4 e5 O
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
. i* g; m3 W5 _2 ]) W6 M }
* ?$ ?0 r1 q. F) w */; t! R. ?0 |6 D2 o d Y3 F
//////////////////////////////////////////////////////////////////////////
) U& R! {+ j- S break;& x" i; p* g' @- c) c# x
}' [. S6 M7 _& d: `* m) G
}
4 {6 M- c. f5 v; k2 u}0 `& @$ E* H/ d6 `8 I8 z6 [
m_wndMenu.SetVisible(FALSE);
9 m- c6 B( {3 c8 v7 a! n2 i( T
5 Z# y( x F& }# i( | d--------------------------------------------------------------------------------------------------------% I |; Q& ~2 {0 c; e
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)9 M; m( d) F6 t, a, z
{
: z9 S7 T7 v1 @6 Z$ ?/ ]BaseMouseCursor();
3 t3 g7 f; L! p, J2 s. K+ f$ w}& j/ T, j9 v' C
在其下添加:& O* R+ O% k5 M) V* g- K
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
6 h* q* x G0 e{5 X9 U: N% y8 y4 ]/ t
m_wndMenu.DeleteAllMenu();
2 L& L1 e5 ~, S6 a! w. ]/ mm_wndMenu.CreateMenu(this);
) E( _5 K2 d4 |+ im_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
+ {6 E( x5 o3 U( ]. Y9 J( u3 H% ~* G: a" Q6 j9 D0 H
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))1 q& R7 g6 h! E5 M6 }
{$ j: w6 h3 ~- x3 B1 v! @( x
//P以上级别才可以删除所有道具
/ y& h/ N7 h2 V9 X, J m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");0 X0 X) _1 B2 v" Y, q& `. z& Z" U6 c
}
# ?0 W' |1 _6 j0 s C- w' w; R qm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );* {/ k9 |9 I ?" O4 S' o
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
# v: r9 W5 b9 N$ u, cm_wndMenu.SetFocus();* X) E5 Q1 t& B# @) q6 l
}+ B1 w" P6 N2 Q; E: w
------------------------------------------------------------------------------------------------------------; U8 t0 b. W* @+ Z) F6 ^
*************************
3 m2 M( d8 x9 V% ~* ?& ~8 JWndField.h文件
% b5 v C' |' s! K7 y% p; C, k4 P*************************8 O) q5 Y5 n/ n; C* B H
搜索:BOOL m_bReport;. J2 B# L" }3 q! f: j
其后添加:
. d$ q* s% {2 b! T+ ?/ P/ VCWndMenu m_wndMenu;
- U: C1 Q1 J% ]& ?搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);" w0 e& @- n: H
其后添加:
: Q$ ]9 L i. \/ V3 S8 gvirtual void OnRButtonUp(UINT nFlags, CPoint point);; l( g( M& W/ @5 A
, M2 ?0 s' s b
0 v' C2 N' c8 ^+ Q/ }; g! W# F |
|