|
|
源文件中_Interface文件夹下WndField.cpp文件/ U$ y' E2 i$ x8 f$ T) j
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )7 H; v0 T/ c; v6 _8 I) l+ J) J
A& U, i( Y* M$ B6 U( Y
struct sItem
3 P, R9 r1 l# V& s, v{
* r$ l( y7 _! u+ {" C* D" xDWORD dwId;
/ U" I' K$ k W" J, w# tDWORD dwKind2;7 T! ?; [! j, E ^+ G
DWORD dwItemId;
! F1 M/ L5 R$ O7 ]+ K% y2 C+ }BYTE nIndex;1 K1 w2 H3 G; |" s; F4 L, Z8 V4 A
sItem(){
! W2 R$ p. V/ T0 {( Y2 h dwId = dwKind2 = dwItemId = nIndex = 0;
6 P; M9 T5 d* o8 o* m0 N( z}9 Z4 q \/ Y# J
bool operator < (const sItem p2)
/ G3 v! }% o d' W! A{/ }& U3 E1 B5 Y5 Q( d$ O
if (dwKind2 == p2.dwKind2)* x1 @/ N4 ]) ?) D) C+ m' C
{
6 N! D" b, Z; P4 }0 k return dwItemId < p2.dwItemId;
. \9 z+ s+ c8 L* B& f/ g }else{
0 g7 I. b$ d6 O4 m2 n return dwKind2 < p2.dwKind2;3 r6 c' H5 v2 U+ w% \! g3 u
}
8 F7 d8 b Q& R" U% M6 y' E1 U}
/ s* @6 M( U$ D% d5 }( B};
9 `- f0 H/ @ Uclass CInventorySort* F8 Y: f8 T# r
{; U& N3 U6 q8 e: a3 s6 ?
public:
: y" Y; A# H8 l, @, N; M$ n/ LCInventorySort()
3 ~* M+ f8 |$ u, K- f{# ?! v2 v" l$ K- g
m_dwPos = 0;% A# M& K8 ^7 n. A# m+ A5 `8 l
}
6 J& {) Z7 x! U% ~~CInventorySort(){}/ B' p; V1 Y! a9 C6 ?8 Z- n8 F! D
private:9 ~( o1 ^ Z. H2 ~7 ?
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息5 i: Y* `; y& [! C. k) q" q2 ?
DWORD m_dwPos;$ V) B* M- a; ^: A. W+ a% X$ T
public:9 @9 ]& G3 ~6 |4 O# Z
void Add(BYTE nIndex); L% X+ E; Y7 j5 A- [0 z
{9 m9 M7 w9 i$ A5 a; E
if (m_dwPos >= MAX_INVENTORY)* Q. k- C8 ]) _+ D' }9 H0 Y" b# n
{+ s4 J6 v. n) a: B; O* W
return;3 `' t1 f& S0 b( M2 o% B" L. B
}
' G8 g6 k6 n2 N2 Q y( o- a m_Item[m_dwPos].nIndex = nIndex;
5 B! k& A: t8 d m_Item[m_dwPos].dwId = m_dwPos;
d1 Y) w' ^0 O. i: ` m_dwPos++;
4 S3 g. A: d5 W}
: S; e( l+ z( X7 S0 G" P* \BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列2 G2 ]: c9 X( k! v0 Z
{ ]& l1 g& P3 d' U ^4 ]
for (int i=0;i<MAX_INVENTORY;i++). ]' j( r: e, w
{
) P+ g2 F3 B9 ]$ t1 V% Q if (m_Item.dwId == dwId)
) `) y1 i0 g! y. D$ H {2 I: B" m, E6 A6 M6 F+ K( s
return m_Item.nIndex;4 ]9 r; }4 p/ t* g" H7 |) y" y2 G( u
}
" t5 k- f1 A6 x) I3 x }9 ~' I9 H/ b! L
return 255;
- b9 r/ V- E. i" h8 `; v}
3 V' \9 _- x4 p% E( `void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
* d) n2 r: ^, i{/ `9 S' K" U( j: V9 S( {
BYTE nTmp = 0;: Q3 _7 Q$ L* J2 Z- o
bool bDest = false,bSrc = false;6 b0 V0 e# G) ]" h
for (int i=0;i<MAX_INVENTORY;i++)
# f# V: l$ |' l {
, b- ]5 \) Z- s& z) e( Y1 f, X* N if (dwSrcId == m_Item.dwId)7 K: H" G. j% J) b0 A9 n
{9 {2 ]4 p% f+ X* a8 V+ P* {
//id相等 则 改变对应的dest和src5 `% z4 T, g/ A$ C# V! W
nTmp = m_Item.nIndex;4 o- U: _# Z; V
m_Item.nIndex = dest;
0 I* p$ S6 K+ t- M }% p4 S6 I/ n) M0 c8 a& a. ^. U$ c+ Z- r
}
4 j! _/ U3 O4 ^& s$ C //临时数据保存完毕,交换开始2 r: I8 k2 f% p! t' ~
for (int i=0;i<MAX_INVENTORY;i++)4 F/ G: m, ?5 V& Y6 j# l( m a
{
( I1 k3 k' i) k# _( F4 e' X if (dest == m_Item.nIndex)
/ p- S: E3 X( T6 B" W6 T {
& K4 m' w8 `0 W //id相等 则 改变对应的dest和src% u- x8 e. i5 Y$ C% ?$ q- _1 C
m_Item.nIndex = nTmp;
+ ]/ C, |: H% f8 q8 U }0 J9 O' o5 Q# J/ K- R5 `+ W/ ~
}
' `/ }/ o$ p, i% S' z, {}
3 o# ~8 k1 P" a' B7 `};
0 M% ^4 Z) d: a h2 j-------------------------------------------------------------------------
' M7 i0 \* I4 t依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
5 j. y0 k6 s. A! P% z9 j, t搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);+ `) }4 d# v- M) V
紧靠其上添加:( l3 _# q2 B( I8 y9 t3 Q
if( pWndBase == &m_wndMenu )
1 }# m8 ?. B/ y- K{9 A; q' v% R9 g3 z( `! ]( @1 P
switch( nID )
3 D9 y% }! z% E- { {! D5 E p7 ^* g: V
case 2:3 Y' R( Z; J/ I) ~& M" O
{
7 k: {$ e* }+ H: } //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
2 w" b+ k/ }& t4 o* x8 P _ if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
. }# ^" _8 R, p, B {
* j2 Y6 a% |$ w4 w+ |4 ~, [ break;& O& ^0 i% M8 ?9 w w
} S; |( @0 F' d4 H1 P+ u
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)1 I, E" Z0 J4 Y" b" T) h; l
{( R6 I! J& E9 ~8 `+ N
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
. Q# A, n1 Y; ]8 ~3 P. [ if( !pItemElem )
4 O6 ~$ E; H# m, m& r continue;
# s9 d* c, V* I2 l$ Z" A: W if(pItemElem->GetExtra() > 0) v6 ]% ^' T# n2 r: C
continue;
$ t0 a2 D" @4 Z J, n if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 8 T6 q8 ^3 ? R
continue;1 y, y' X# n0 Q
if( g_pPlayer->IsUsing( pItemElem ) )
/ T' |7 M9 Z) k! F9 k1 C, |' \) Q continue;
. m9 l- }- Q$ M if( pItemElem->IsUndestructable() == TRUE )* A5 \& C1 }) ~! M% B$ k' K
{
! N- L M9 I9 E# u! i g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
1 i2 L0 k9 H' {: x! y continue;
5 {. {8 y A1 i9 e% ] }7 i, n5 y+ l6 @1 [5 \$ f
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);$ Y- ?: B' i+ k) Y- m% e
}
5 P8 l$ N5 {/ y( s9 j5 ` break;; D+ j- D- a9 z0 \8 {
}
6 R' U( D& W! s- j/ g+ K case 1:& n7 _/ j7 b# z! E: i, H( J8 E: I
{* b3 N4 K* p0 _$ S6 K
//整理背包2 P; A8 }, o6 N
//////////////////////////////////////////////////////////////////////////
7 s7 [* L8 \; C; t //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );" k1 H5 Y O# k6 b' R
//////////////////////////////////////////////////////////////////////////
: o! Q/ K8 _8 D3 Z4 e$ y$ U! K8 F //////////////////////////////////////////////////////////////////////////
9 T( v2 n* v; C, c+ P. J K CInventorySort* pInvSort = new CInventorySort;
5 M1 }4 {- C' w9 V9 ^9 w$ h- {9 u vector <sItem> vItem;! w4 t3 B- n6 w, a X
vItem.resize(MAX_INVENTORY);//初始化大小) N p; H; X8 S( y7 a8 }, j' ^! h* a
//////////////////////////////////////////////////////////////////////////
0 J6 M/ t4 @# }; O( `/ i$ |& M9 f //填充数据9 ?. m3 L) o2 D$ m- n/ |+ B
for (int i=0;i<MAX_INVENTORY;i++)
H9 k8 z3 |3 f& i2 \" W* ] {
2 `9 }# ~! l# y- m8 b CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
( P& R! k5 ^! y% N if (!pItemElem)
% x! d1 z1 x1 b: I: O {' ]! R& X- B$ m/ [
vItem.dwKind2 = 0xffffffff;! e d/ @9 y8 w
vItem.dwItemId = 0xffffffff;' k6 y c+ W' v0 }3 ?' x
vItem.nIndex = i;, M9 X4 l1 d9 U- Y
}else {6 `5 S. R( q' m
ItemProp* pProp = pItemElem->GetProp();
. _0 U9 y- ^1 W" `8 p, r2 j vItem.dwKind2 = pProp->dwItemKind2;
) s1 U5 k" e0 C4 S m8 t vItem.dwItemId = pItemElem->m_dwItemId;
% J+ W) q: n* `" U8 d! ?8 }/ I vItem.nIndex = i;: A7 ^2 O7 A, o2 l/ I
}( S6 A6 \! O% {6 d0 N
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);1 J7 w" p; Q0 H: {6 @1 w* M
}
M* W/ k4 z) J/ R4 K //////////////////////////////////////////////////////////////////////////
7 Z2 C* D0 C8 Y3 ]* n& V sort(vItem.begin(),vItem.end());//排序8 Q' ]2 t) ?1 ^( U- Y
//////////////////////////////////////////////////////////////////////////4 [0 ]8 @. p# l. D2 \2 t
//交换 i7 {% g5 k: Q3 L' j
for (size_t i=0;i<vItem.size();i++)
4 }: O: i, Y, e" R$ E8 ?) J {, _ B* v4 ~1 S1 U8 `
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);8 t/ R+ b( L6 d$ e
pInvSort->Add(vItem.nIndex);0 d1 h S J A$ t" w, g4 C/ E
}
( _. ~3 w' g0 _, m3 { BYTE nDestPos = 0;, y8 T. v" b/ A& I
for (int i=0;i<MAX_INVENTORY;i++)' n6 |/ w: P# O# g7 |" t& V: _" n
{( i2 ?+ E6 [0 y. s
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);3 ]3 x/ o! {9 T1 i
if (pItemElem)
9 D# c! k9 S9 y% f* h( T1 ?/ x {' X" m0 {6 u$ o( m+ M
if (IsUsingItem(pItemElem))8 k$ w- q0 D; }( _6 y* T
{* [$ u' ]) i& O. G+ L% i; W0 ~) D
//这个位置无法放
0 V2 Q, ]% p) q: Q& |/ } nDestPos++;
: c: p0 m7 L* `1 f: j) a }
5 ^: {1 ?' z6 R# I/ e }
. q$ X2 C2 L0 H BYTE nSrc = pInvSort->GetItemSrc(i);; }' d. @, D) p- y4 a
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);7 a/ {. s. g! W1 L( Z2 T
if (pItemElem)
4 f" f3 v# d, ]9 A6 K6 o0 z {* Z2 ?" d1 q3 N! m) v5 e
if (IsUsingItem(pItemElem))7 d4 P: h' x7 |; O* S& c
{
* l# ?: u; q& @, l //这个道具无法移动,跳过
$ f5 V+ W. x! Y5 v& E/ d continue;
/ w4 V. K* z9 i |! y- D }$ [. V$ B5 s6 ]! K' i
}else{
( S9 r, k0 V! u" D* _! f& S //空位置 不用动: _- @! c0 Q; _8 I8 w7 P. B
continue;1 V2 T0 v5 B/ d" S% X I6 D
}
6 U [5 P2 D, o! }5 ] //////////////////////////////////////////////////////////////////////////
{$ x0 z/ I$ k) `! i //开始移动/ H) P% H$ w9 K* b, T
if (nSrc == nDestPos)
% H* d# b: T( s! E {/ H' P: m! \- z$ J9 B
//原地不动
3 k0 J) q: C; o0 A* V& L+ L( ?6 ] nDestPos++;- {1 B4 J0 `" D
continue;
# t* b4 [8 @+ N/ T" o }0 a4 E; U. J8 H' ]
pInvSort->MoveItem(i,nDestPos);
3 B) X0 k6 L$ T3 J g_DPlay.SendMoveItem(0,nSrc,nDestPos);0 q$ f4 O/ L% I% \6 U5 H
Sleep(5);
7 I0 c% w' h9 ^# w/ e9 n6 ]6 R4 v //Error("移动 - %d->%d",nSrc,nDestPos);1 B! W M9 F8 E. [2 f2 S4 I/ H7 x
nDestPos++;) z1 s3 @/ O/ R- i9 F7 I( N, U
}/ `7 L! y9 q* P( X+ o9 J# V9 P
//取第一个元素的信息
2 B; g% H' {# s /*6 Q+ G6 y3 ?" y J, P6 E, B3 G' t
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff): H% w h% |" U( O7 d
{
$ ]7 L1 \- y& A' X9 [' N" l Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
- H1 E; W3 J O: f g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
1 P6 ]: F# E" e. n8 @ }
/ Z0 K+ X' h' w9 r. \; F */3 `0 n3 q; Q. u' A* i) P
//////////////////////////////////////////////////////////////////////////
/ a$ ^8 d3 |& P3 K; d1 M break;
$ ?9 ~' v. U* j4 M3 `" w }& \& E: F- r# n: v0 F
} , [, q* t1 y5 w) Q( m5 I
}# c7 A# i. _% p2 q( j9 ~/ z7 g
m_wndMenu.SetVisible(FALSE);
. w: f; {7 s9 ^; I: e9 {; c: q6 C. d# v
--------------------------------------------------------------------------------------------------------
" I5 a3 j. H& X+ }搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
+ b _& \& M+ a: D" N{
" J! t; \& }/ f2 |5 W; {! XBaseMouseCursor();
1 j2 {+ l9 J, y( W! a4 y7 p}, ?2 g" h" D; P, C3 u; ?
在其下添加:
" g3 V. u9 |* t4 R" j0 s: e. Jvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
. M/ `; T% u$ |: ~: B7 H{
5 P! C1 N! \0 U, Q+ W) Tm_wndMenu.DeleteAllMenu();: o" H2 f' c. I: }) I! ^9 \0 v9 A
m_wndMenu.CreateMenu(this);
7 b+ B+ M3 ?/ o" T& L4 X/ |, @ om_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
0 I7 L. @! F3 p% E! \0 }4 v5 @2 }* a
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))% {# E' f- `. }% D( a# m
{* |, [+ D9 D5 @6 C9 x
//P以上级别才可以删除所有道具% j4 @, l0 b: k8 _5 h2 K+ I- A) ~8 f
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");& ^) V9 {% g6 O' T; t& e$ d1 s! J
}$ F# M/ ~, Z1 e) F
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
$ _* C8 O: |6 B( `5 V. w! E( ym_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
" X* ^7 [' V7 ]6 T# {+ Im_wndMenu.SetFocus();5 S7 o ~( K+ Z
}
* R+ o5 W6 M1 b4 q2 l1 a1 D: f------------------------------------------------------------------------------------------------------------
: n0 G) y F$ f v8 b! ^* o' i# x************************* [6 B0 T3 q0 X( l
WndField.h文件
: J. k8 O& i9 T. J" a*************************
& n: E1 C$ j. |; v搜索:BOOL m_bReport;
2 |7 t1 X4 R& Z( r其后添加:4 ?% c( f9 q; T7 B* j
CWndMenu m_wndMenu;( h+ ~, Q2 u7 ^2 M& T: q
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
$ k" H( z3 f! h( V5 g其后添加:
4 I/ }& P4 V# ^# h, M3 v0 tvirtual void OnRButtonUp(UINT nFlags, CPoint point);& T( Q! j6 c* f8 M9 ~- z$ B6 G
; M. `8 D5 v j5 z9 y! V+ t3 y \3 q4 g+ g- x. N8 e
|
|