|
|
源文件中_Interface文件夹下WndField.cpp文件
( j6 h) R! X* s! _: R4 R搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
$ l" e, N* T% T. q- H% [# ?! C+ ~2 I5 l4 Y9 x/ l! b4 j: ]4 w
struct sItem
8 M; h; Y5 T* H$ p, s# H2 q{
# }4 M: e* ?2 v8 X3 U2 ADWORD dwId;8 X; S$ j/ L7 I4 p
DWORD dwKind2;9 |( ?1 j8 F+ A$ ^( ]$ \* t+ I
DWORD dwItemId;
( v8 P3 q1 b& X, W) S: ?( jBYTE nIndex;
) v7 m {( b; C3 s r. wsItem(){7 d9 b( b$ p% q b8 l0 O
dwId = dwKind2 = dwItemId = nIndex = 0;$ U) z& `* [0 Z2 z9 B
}' X* t( E) o. N, d: u# t; b7 M
bool operator < (const sItem p2)
7 U. n" D5 ?8 F& W- h7 d{- X. D( u' j0 P9 b6 T7 |
if (dwKind2 == p2.dwKind2)
8 ^2 k5 X5 q- V( H( j {1 I, E5 r3 w4 R c C
return dwItemId < p2.dwItemId;/ y9 _' [% y! z* C) L& V2 j
}else{
* z. s; j4 R/ f# s return dwKind2 < p2.dwKind2;( E( `. R' h7 P; X& ~' d( r
}9 c8 [! q. s" W
}, `8 v9 | q7 f; z: E0 ~) S
};3 B9 I, o/ a+ p( g! j, P9 F
class CInventorySort! z& v, @' p; b3 t. m
{, H5 W! ]- p( d( K1 T0 {
public:- F8 v6 N" P( {0 _! E: P1 x# n
CInventorySort()
3 z" N% F. t3 J0 f- |/ a+ X{
2 E6 N, p/ H3 p3 M m_dwPos = 0;$ d$ v& P; ^9 A& \7 I
}
^6 K6 q+ e, H~CInventorySort(){}& I1 U& r6 H' e
private:# L4 K$ x9 Y N6 G7 o
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息6 @3 F- [; c' @! h4 p/ y3 ~. \& P
DWORD m_dwPos;
! Z$ z$ Z! _) ?# y- |6 U4 w& Qpublic:
. A7 E d# O1 h8 L+ @7 z6 Kvoid Add(BYTE nIndex), [ h5 u$ Z# Z" R
{
$ E( k1 n; L& U$ E* s/ q if (m_dwPos >= MAX_INVENTORY). a% O+ H1 k5 J; L \. Z3 w. S
{
% A5 K4 c& s# f7 u9 W return;
4 l# `$ i- q* P( G1 R }5 {* O6 A& e3 p6 F0 Q0 | K
m_Item[m_dwPos].nIndex = nIndex;
, G) ~! c" U4 `3 W5 O9 S1 b m_Item[m_dwPos].dwId = m_dwPos;+ M& n8 m5 W) b% [
m_dwPos++;
; K; I- I* j8 C9 @; N}! {' X3 }1 _- T5 u
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
5 C0 A1 N; {3 I8 E4 W9 c2 |{( t3 @( |# g# S5 x/ I( k
for (int i=0;i<MAX_INVENTORY;i++)
! y) y7 ~( L9 h4 S7 t( r. K {
7 _% \0 G3 P5 O% V# J8 u. g3 j ` if (m_Item.dwId == dwId)# j' A. O! {: l- N+ C, c O! t: e
{
4 x o, D3 k( _" T return m_Item.nIndex;7 p' G. P5 p* a- t
}
% X+ A' z" @" n+ X0 P9 @ }
+ U# L! Z5 t+ w& K1 h return 255;+ B# H. A! N. P# F# `( |" X8 K
}% l6 k* L1 x: w1 s- |+ D; V
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
' a$ d D! ~+ p( G6 r- U8 O1 k/ P' P{
' a# A, P' ]) r# X( F! }$ J& }/ U' U$ M BYTE nTmp = 0;
2 h/ e d7 U$ ]: w) [ S Q' E: q9 F bool bDest = false,bSrc = false;% F& c( h: q/ p( }; [
for (int i=0;i<MAX_INVENTORY;i++)+ r0 x) C2 \/ i+ h
{$ m6 C% o4 d; I( G M
if (dwSrcId == m_Item.dwId)
5 q1 P# L( c, h! @4 e( x {
- i; j: o8 \5 Q. u& y //id相等 则 改变对应的dest和src
2 Q* u' ^7 p e nTmp = m_Item.nIndex;
$ y" m8 P3 H, ^( E& l m_Item.nIndex = dest;8 V: C1 l) |$ g" h* `1 n* R# {' a
}$ Q' L9 x/ u* z9 \, l
}
! r3 |# R% o4 S9 m7 ?$ ?) d //临时数据保存完毕,交换开始
/ t1 F' V7 u9 E# _1 f% d for (int i=0;i<MAX_INVENTORY;i++)
2 S% o- ~6 B2 p; ]' m {( E- [' C( P) h1 N% i/ W; n" n
if (dest == m_Item.nIndex)4 E" j2 J3 A; K5 r j: _% [/ p g
{
6 H. W! b% V% K' h$ g% l //id相等 则 改变对应的dest和src& u+ [; K: M1 P
m_Item.nIndex = nTmp;
% u- O& _. j" D0 J: n; B1 I/ u# J, q" D# ^ }
; u' ~2 x* o4 h1 x }
, `0 F; C9 f% F' x& Y6 e6 k! ]}: V4 k4 \7 g. G
};" E7 Z+ G" ~8 H9 ]. V8 q7 M
------------------------------------------------------------------------- j* w" f1 R' I$ J; z/ g7 l! L
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
. G6 \4 ^1 L/ X% D- Z. d搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);" @' Q9 u) ]. P# ^9 o8 U
紧靠其上添加:
# J/ f9 c+ v& `& `+ tif( pWndBase == &m_wndMenu )
! N+ ^4 v0 k7 M% g* d/ O2 }6 o{' m3 B0 `1 s6 J6 _( H
switch( nID ) A3 p! W: T5 _+ B+ v% t6 h
{' u. D2 m) Q( Z
case 2:8 }; y! N4 t; {1 G! S
{
. j# ?3 F. h0 d. @. n: v6 d8 e% l //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
- D$ K. F9 i& I* k if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))& Q# S. N* g0 N$ n M6 v
{
e8 T9 F h) X- f4 k2 m break;
7 ^$ u7 _9 o- K3 W5 d. D0 g% d }
& F5 ^1 }0 s' w% |; G4 a) _9 s for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
! C T7 C3 F4 h: s* O {6 h* {( o7 U) L% [$ f
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
' b) M7 f% I- f6 t if( !pItemElem )% z2 b k: I x4 m* t% s
continue;
* U: s H* e! v% L8 a if(pItemElem->GetExtra() > 0)- i% r0 R o9 w8 O! \
continue;
7 ~' O4 T: T: r/ W if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
$ v) H7 A8 \# j) w: R continue;6 E* E. D/ O+ j/ q; k, _
if( g_pPlayer->IsUsing( pItemElem ) )
1 Y- S: }0 I# F1 s& Q3 k8 \$ K continue;
" b1 w3 W, \" Q+ ? if( pItemElem->IsUndestructable() == TRUE )( `( `8 c, R5 U& y" B7 c) ]
{
% e* Z( q3 W3 A, U8 N$ p$ Z; i" t g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );; P( M' l5 c% n4 C' y' P
continue;
$ P& e* G! }' g. v# C6 W* a }
+ H8 X c& H3 t9 }" l g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);$ z7 Q) [ I( ?/ A4 R" u; Q
}+ i% N# I/ v9 b
break;3 H b, S) v+ r( p3 Y( [5 d
}
/ X3 E" E' J- S3 x case 1:$ M8 ^: M5 b4 _* ]
{
w+ @8 g0 [% |/ ~8 [ //整理背包% O" m- [' D- }; A! x" c
//////////////////////////////////////////////////////////////////////////
( R" S4 o8 ?% {: n- b //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
& R6 B v4 p) D9 R! O //////////////////////////////////////////////////////////////////////////
K8 }+ a) M8 Q. U5 w" t //////////////////////////////////////////////////////////////////////////9 Y7 u0 y" m; y8 n% i; E! B; V
CInventorySort* pInvSort = new CInventorySort;
9 x# M8 q& ^4 E3 r vector <sItem> vItem;
C, v5 P4 N( b4 z/ F vItem.resize(MAX_INVENTORY);//初始化大小
; g7 M3 @2 Y9 i, X, s //////////////////////////////////////////////////////////////////////////
+ I/ l: g" k5 h8 N //填充数据
# K2 l: v1 h: T/ }+ G( u2 f5 O for (int i=0;i<MAX_INVENTORY;i++)
& p8 @, ~4 s+ ]/ f {# q+ z0 l" `4 l
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
+ L; R1 i# D: v7 H# r( L. ] if (!pItemElem)
8 R+ U8 x5 I% a7 T1 p& C {0 d/ T: n2 h5 q
vItem.dwKind2 = 0xffffffff;
# S, U3 N# ?: i vItem.dwItemId = 0xffffffff;0 ^/ k$ a! b W1 _# M
vItem.nIndex = i;
0 @% F" G6 F6 l: G w9 K2 z }else {
1 S4 ?- D1 r# x' Z0 ~# \$ r ItemProp* pProp = pItemElem->GetProp();
4 y; |- c% P: N+ |/ L4 p. S# @ vItem.dwKind2 = pProp->dwItemKind2;
" F7 X$ W/ [1 Q: }2 z5 y vItem.dwItemId = pItemElem->m_dwItemId;/ d5 f3 T2 n* {- y9 c z
vItem.nIndex = i;
( d9 \3 h4 j+ w* t }0 @2 C4 ^) @+ b: a# v) d
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId); r) K7 r& k# l- m' @; X
}; k( y+ v+ K; K" q
//////////////////////////////////////////////////////////////////////////; b( X5 ~( Z, k( _
sort(vItem.begin(),vItem.end());//排序
% x9 b c5 t$ D3 U Q) |! O$ I //////////////////////////////////////////////////////////////////////////
6 T- T% t O% v* M c& R/ L //交换
' `4 d4 ?8 R" K( T: S* n for (size_t i=0;i<vItem.size();i++)
0 g- a0 N8 F# t) w" } {1 F- _: Y, g3 c) M8 L
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);2 t; D1 R' J" b4 J6 [ m3 E
pInvSort->Add(vItem.nIndex);! _6 P6 N8 x: Q% |. c6 g
}3 A' V9 N( h, V
BYTE nDestPos = 0;
% d% d1 a5 f/ u# Q for (int i=0;i<MAX_INVENTORY;i++)5 @' M+ J, i; q# k4 q; B
{5 L, x0 a1 i$ y# p2 D1 o% f
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
! D% {8 ^; y/ V* y# j# n" ` if (pItemElem)
4 t5 p0 S2 z { {
6 H* g7 r9 A8 l: j2 a) k if (IsUsingItem(pItemElem))) S9 I) T2 o# O
{
% V; a& r: l# t* H //这个位置无法放6 {1 M* Q- L: _" d3 Y3 h4 u( [. ~! F
nDestPos++;
2 O7 ^; F& Y% e6 R) q( P3 i# y }% j: B* n8 |$ z! z1 @" ]$ k
}) M! l" A2 X# V9 Q
BYTE nSrc = pInvSort->GetItemSrc(i);
) m4 \8 d% T8 B. k% J9 g pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);$ _. J" @$ O0 s$ t s8 z
if (pItemElem)! l9 C. N3 |( M! S B% ?9 L
{
! o5 v& L5 V( F% R if (IsUsingItem(pItemElem))
. Y3 l7 _, \$ u0 H. A3 C7 s {: g! i1 Z+ C2 Z
//这个道具无法移动,跳过; Z4 Q$ L1 W5 f
continue;
$ W0 U: l3 J9 I" T; @$ O8 `4 m }
' R' S0 a* A P! @' m) Y }else{! k6 I2 g1 K( ?
//空位置 不用动
% S6 S9 q6 `6 A7 v continue;
! [1 q* t3 ]8 F: K( F }4 g# `0 j6 `( c, V* U
//////////////////////////////////////////////////////////////////////////# j( W7 ?3 Q( U
//开始移动7 ~5 w6 w/ w3 [6 l( k9 u4 S; I
if (nSrc == nDestPos)( o( s4 I7 S: n
{
, l; F% v9 F$ l2 z. S //原地不动
% _" L& p0 V: {* A, x% w nDestPos++;
0 v7 ]: ]; g$ r: f$ u* ` continue;* ]) _& p6 o+ y# \+ c" \
}9 D# n, y% l+ A2 X, p
pInvSort->MoveItem(i,nDestPos);
1 M5 i4 M7 L7 h2 s, _ g_DPlay.SendMoveItem(0,nSrc,nDestPos);
8 J6 r) O* I( [ Sleep(5);: H7 A; k1 q: D" f) {' F B& W
//Error("移动 - %d->%d",nSrc,nDestPos);4 N* _/ s* u; j) [* T& J6 y
nDestPos++;# E2 x/ g; |. f% N& K) [' c& m
}
% B$ P% `/ F* o: i$ g$ ?6 X //取第一个元素的信息
8 r5 I7 y" ?7 ]7 ^$ U+ t /*# g( N& R4 |) k' p; f! A" y
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
0 \2 |7 i6 a4 P {
d4 c/ ~8 c, N% S Error("Move - From:%d,To:%d",vItem[0].nIndex,x);' H9 B" C f X/ E# ]' P
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);2 R/ v( p& _' _( F6 ~1 u
} a- _/ H2 n8 Q/ ]3 X& A G2 I
*/
* [( q R, v$ O. u/ K; c6 ` //////////////////////////////////////////////////////////////////////////
# R1 D) W# ?1 m* y) i break;$ [4 _6 l8 Z0 `1 v- ^1 P
}* U, @3 q3 F0 `2 y1 n. k2 \% E
} 9 l: |' `0 Z+ A
}
4 j: N. L2 Q% {; ~" Cm_wndMenu.SetVisible(FALSE);
' q* V: u- n7 O' g
7 p1 p# \ o- ?6 P: H, b+ g--------------------------------------------------------------------------------------------------------
( g% ^3 o) J% J- B N; m搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)0 `1 r5 I6 N& T
{
9 g& X$ O# I9 o2 h# G% z( sBaseMouseCursor();
: N6 i4 [6 Q+ R+ _% Y, @8 X9 \$ M/ m5 L" I}& W T* ^5 Q! k+ `
在其下添加:
" G* @' F' h/ A6 m3 X% Hvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)8 j4 k+ ~/ {- i1 \5 ~
{
) H( n7 D7 `, C4 A, c* c. rm_wndMenu.DeleteAllMenu();* N. b i4 k7 v; H2 m
m_wndMenu.CreateMenu(this);7 f' P5 @& U# K2 [
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");! J' K b1 G, I: v2 h
8 v; [$ T' }1 B
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))5 g9 n& u/ V. N p4 { c
{, I. k$ [9 W+ r
//P以上级别才可以删除所有道具& O! {0 a) x8 u4 S1 q, Y
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");, t i4 G1 T9 [& C. R# h
}) x, D& [0 \7 ` [: E" t
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
! T! L' B" f: T2 Z# Ym_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
7 Q" D: z) ?! `6 n. [- fm_wndMenu.SetFocus();
" i0 F' h' d& J+ @' L6 E6 Y9 T}
1 H: C/ Q- U* ^* o7 Q6 Y------------------------------------------------------------------------------------------------------------. P% }3 o7 o/ h3 M$ }7 h* u
*************************
0 m* e# g/ R+ E5 C+ a6 wWndField.h文件% b; Z0 H( ?0 u; a2 a9 q
*************************# ~7 L. ]/ g( o: \& g, f5 C
搜索:BOOL m_bReport;
/ l& y J9 i, ~其后添加:
9 H' T+ H; I" O* i8 bCWndMenu m_wndMenu;
0 Y! L2 n. P" D& W* {搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
7 e: W Q0 b- i7 y: L7 Y其后添加:
3 u; y2 L, {0 Y; p. ^virtual void OnRButtonUp(UINT nFlags, CPoint point);9 ^% n* ^) G% M' F5 {+ t0 L+ I# `) H
" k/ d/ T+ _( y B n; X e) `# B* i" a" F
|
|