|
|
源文件中_Interface文件夹下WndField.cpp文件( f" O! t; w( k, H
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )7 j. X- T+ K: V$ `% k
# j, n2 n( H' u+ F* Xstruct sItem
# \+ H0 [3 s' I- _* ^$ J* @{" t; Z) M$ v% m' s
DWORD dwId;$ B7 C, p% c+ J
DWORD dwKind2;
8 t+ t3 F. a/ h U1 ]- qDWORD dwItemId;
' l7 Q; g9 z! K$ xBYTE nIndex;
7 k9 m! B9 l) w G. nsItem(){
4 x5 w3 f" [9 K1 H/ ] dwId = dwKind2 = dwItemId = nIndex = 0;
+ D2 Q7 R. E& l}
& ^" O5 j0 i( [bool operator < (const sItem p2)
! i* E' F% D+ Z# }{
7 A# @% r0 o0 P) ?+ s0 o if (dwKind2 == p2.dwKind2); g( U2 q' }2 |8 {% E/ m
{
7 N) T; ^9 |( h$ J; j2 f( v return dwItemId < p2.dwItemId;
1 d! {' Q$ X2 {8 o5 H }else{/ W! x$ D& I1 T" Z# t% Q
return dwKind2 < p2.dwKind2;. o: L+ l; Q( x
}# Y6 }* q$ i6 H3 @
}
6 `2 u1 |3 M$ w3 U/ y4 ~& S};
6 X* S8 p$ y9 i( N! U3 ]class CInventorySort
y+ E# L, m4 J& X, }) [{# S; w* m. U1 G& j& [- X8 \% H! _7 m
public:+ f4 C8 g) m4 ~" @& o( g( U
CInventorySort()
3 M' G3 N; \0 D; @) i{
; w; M6 j% F7 k m_dwPos = 0;% {/ [7 `0 k3 c$ t! ?3 L
}
" M& @# V2 l4 k& l( s5 D~CInventorySort(){}" f* }+ o) G% S# X
private:5 d9 }& K" ?/ ?' D" U' U1 c; n2 ?
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息1 A$ g) L3 t4 a# K0 \" m C
DWORD m_dwPos;
" l" P2 V, Z7 Z: \7 xpublic:
?5 H( _5 s7 i3 d; d5 B1 Hvoid Add(BYTE nIndex)
% q: w6 |" ^0 ?, }% ^- ?{
: l9 A2 X* {) C/ ^ if (m_dwPos >= MAX_INVENTORY)0 b7 V# p0 I1 _) f7 v2 P
{
6 x: m( y' Q! L+ f: Z return;' p* P! y5 t' e; `" s+ ]- I
}, `: z7 p \2 g- m' }7 u4 I7 W2 \
m_Item[m_dwPos].nIndex = nIndex;" E; Z8 ?) m6 @" q$ i5 r
m_Item[m_dwPos].dwId = m_dwPos;5 X9 [3 `# K6 X W, @
m_dwPos++;5 |+ V: h w9 m1 V
}
* Z; b% }- d% ]0 j- J/ BBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
" t- z+ X; W4 R{8 f1 \( T& P! }: [
for (int i=0;i<MAX_INVENTORY;i++)
' _* w$ x4 [2 M {/ e* }; n; ^1 h9 |8 z# W% m; I7 Y q
if (m_Item.dwId == dwId)' `0 p y$ y' p5 O3 y
{, ^+ ], D- J% d1 q% t
return m_Item.nIndex;
! L- E1 h5 K$ K9 i" ~3 h0 ]0 @ }
* f1 \5 B5 q# Y; k0 E& a }
9 l0 Z* B# M. E7 J( x return 255;
) C, l$ e2 `" A) M/ Y' F; {5 S/ p}; ^3 q: n. }$ T$ B" Q- A. Z' Z
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置8 C/ F0 a' f }6 g! o
{! {* H& ` \" N+ g7 K0 t$ P
BYTE nTmp = 0;/ S; `1 `2 X8 V" N- b
bool bDest = false,bSrc = false;
' b$ V( d' D0 [. V4 S/ w8 ^% F for (int i=0;i<MAX_INVENTORY;i++)3 b: o0 ^5 n+ X' h2 l( s O( _
{
" \# p Z! c- M if (dwSrcId == m_Item.dwId)
% v+ Z! S' A1 s {4 ~4 L! E9 A8 b; R5 O
//id相等 则 改变对应的dest和src
+ _# n1 D! U. w: j nTmp = m_Item.nIndex;1 n( A% G6 A6 `2 M# _8 `* w
m_Item.nIndex = dest;
; s' ?+ z% J4 B, q9 G1 L }" i7 {' K3 J5 k% p0 P
}: O4 a* Q' S" W
//临时数据保存完毕,交换开始$ s8 P9 E' c2 R* v
for (int i=0;i<MAX_INVENTORY;i++)6 l9 Q% W# w2 [
{
5 @( T6 r8 T% H ?1 t5 \9 T) x if (dest == m_Item.nIndex)8 O% O% x% T9 b1 O
{
" B3 |9 m9 i! N3 I //id相等 则 改变对应的dest和src' \6 i- }( R8 N: v2 }6 c" C4 H( c
m_Item.nIndex = nTmp;
- z+ d! J3 @6 j7 n }
! @7 z7 E* [/ ~ h2 k8 V }
7 n1 [: u5 i. B. Q7 G K}" w" a7 z4 A) a+ O* H6 ]* C
};; F- D0 P* B" B
-------------------------------------------------------------------------# O, y+ ?8 i& b4 [
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )7 o" s% f F4 `) K% W/ H6 k3 N9 j4 n" C
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);" K( O" y2 d2 o/ p
紧靠其上添加:5 V. r$ K; W" i. ~4 O9 |# ~" b" Y5 T
if( pWndBase == &m_wndMenu )2 z, I8 m* Y M, h# {! v
{
# j7 }/ ]; O9 N# Z switch( nID )) C; a/ a3 t4 k0 S8 s+ I. g5 c
{/ P, q/ n/ t/ e7 A0 ?1 T# w0 l
case 2:
5 H a" S8 U% V- E5 v: f$ k9 C B {
/ P# H0 i2 z' ^6 i //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);2 g) l3 O' |6 n
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
, i& T& ~$ p$ _: ?: e, O {) {/ y9 | b6 {" t4 I
break;
9 q0 {1 B5 y {6 Q }1 i" B1 g* O3 D& X
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
& Y P$ g3 r @ a! [ {+ R6 _7 `- a; i, ]5 t
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);; |2 `8 G7 G" ]" K$ y! H- q9 u8 [7 h
if( !pItemElem )
: H; O e5 |6 A/ y$ n! g8 P continue;7 x' \2 P( X* T/ Y. K( s
if(pItemElem->GetExtra() > 0)$ {$ x% x0 R' T) p
continue;$ d7 G# v/ W% D8 y/ ~: G7 [' o
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
& D$ i3 o: u" A2 L. L1 @ continue;0 ~8 S* e8 c! i% n* r# n5 y
if( g_pPlayer->IsUsing( pItemElem ) )
( L: V; o& f1 o0 o continue;( D; H: |) f' O+ n8 j) g
if( pItemElem->IsUndestructable() == TRUE )1 r6 ]/ `& Q! a4 O! y9 Z7 \
{
) M1 F) Q1 X/ n1 y) D" w g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) ); T4 e# v5 I0 T0 V5 ~
continue;
3 ~ s/ }( D5 s }2 C% j4 ~: D$ S' t7 `
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
6 t ]- w" Y' f- e) U3 I, \' ?- [ }
( v) `- V9 ^1 J& k4 _ break;
, x, D- ?/ n( S+ l }: B* y; C" C; K7 A- J
case 1:4 d" Q5 n5 i; s- ]; c. R# G/ g
{
( y9 f, X: D! I' z: W //整理背包4 n, c2 N2 G5 N" c( H
//////////////////////////////////////////////////////////////////////////; Z$ }* p1 {7 L$ A9 ~% O
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );5 D, X- a/ E7 E- m
//////////////////////////////////////////////////////////////////////////
; q! X# _- k2 u3 G7 E //////////////////////////////////////////////////////////////////////////
$ m3 K( m0 R; q' u CInventorySort* pInvSort = new CInventorySort;
! n- G9 N. G& X# {* H5 j vector <sItem> vItem;+ \* R9 r- D. J9 ]
vItem.resize(MAX_INVENTORY);//初始化大小2 W0 k( ~( o- a# ?
//////////////////////////////////////////////////////////////////////////% V( l6 e% v% y$ B# A4 B+ D& H
//填充数据8 z4 Z0 d) ?5 @, i5 f
for (int i=0;i<MAX_INVENTORY;i++)
* _* c, `9 {2 [! c5 d( x: h; z9 }* I {
# O; _+ ?, `' w/ c. ~3 T CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);( d* P# x3 j: _: q6 F
if (!pItemElem); Y; U: S3 m- q% U% Q) }
{
5 L6 R3 P7 h3 {+ L' `8 [) Y vItem.dwKind2 = 0xffffffff;
3 G) j! ?) }" d2 E7 h6 k vItem.dwItemId = 0xffffffff;, h0 ], w* p7 |2 V3 N, e5 h" s" a
vItem.nIndex = i;5 q' S, I0 @: p+ u. |7 C
}else {, X; T/ ~, q; c: g# W) [! c
ItemProp* pProp = pItemElem->GetProp();& k+ ~5 r) d( K! O
vItem.dwKind2 = pProp->dwItemKind2;
6 C( D+ z" X# q vItem.dwItemId = pItemElem->m_dwItemId;
4 y% w; k |5 o, @) m' n8 A6 x' F3 `0 f vItem.nIndex = i;2 ]* }3 c) A1 o7 F# C/ D- E
}
: I6 H$ p, O' N. l) W/ {# U; C, J //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
* {( j6 X: i5 s }
e3 O' v! f! Q5 J! m* u& y //////////////////////////////////////////////////////////////////////////3 J9 n2 [( n9 E
sort(vItem.begin(),vItem.end());//排序
9 u- f5 J9 p7 V& C! C0 N ////////////////////////////////////////////////////////////////////////// y. }2 a1 b' ?6 M) A: i
//交换" Q. X$ w2 h7 {8 h
for (size_t i=0;i<vItem.size();i++)
5 D0 {, i% z$ k# ]8 d! j9 @ {
, Q! y0 I$ Q7 s7 v' X //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);/ A& O! {/ t$ Y# E2 t+ l; @; g0 P" }
pInvSort->Add(vItem.nIndex);* H W# Z( L* x' K! E3 M5 B
} h7 U! I( ~3 W# d- `* G$ g4 [
BYTE nDestPos = 0;5 E5 U0 H2 i* h8 ?& S
for (int i=0;i<MAX_INVENTORY;i++)5 k9 y" ~9 ?; [" m% U
{6 _8 c* B6 o$ L- J
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);8 z. ^3 G8 U2 g5 i+ W5 E; K3 h2 ?
if (pItemElem)
( t3 C' [( z9 D; m {8 z- k G0 V5 c" w* z
if (IsUsingItem(pItemElem))- R3 s& N8 V$ {; s: M( D0 I! `
{5 W/ P; ?5 n5 C- H/ S% t. `0 K
//这个位置无法放0 D1 h F L+ t
nDestPos++;9 x: _& o) u; P, z; ^, U
}" Q* z% ~( R8 e1 P5 y
}* j! `' W3 w7 H2 X) I
BYTE nSrc = pInvSort->GetItemSrc(i);
6 D( M6 l" }! q0 v8 o pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
1 m6 \" C7 X0 j# H3 } if (pItemElem)
2 j! {4 q, w/ A- i" w+ I$ a* i; l0 u {
* e( _, d3 a& i. z4 f: Z) L( C4 U if (IsUsingItem(pItemElem))
$ N. z/ B0 G2 H3 V7 ?4 c {. u1 @4 a( E& Q S5 c- F
//这个道具无法移动,跳过( ^1 w2 e$ f6 U& i$ w' [* X
continue;
/ w3 B0 T: s6 z( t3 r" ]$ D }7 N! X3 p$ N3 J- A3 y" l. V3 N1 I
}else{
, y" n: ~& \8 G0 x( ~# x, l( ? //空位置 不用动
6 q x* s( `( Q6 @ continue;; {) |5 x8 ~" d" X
}; x8 [2 n, o: F' a' Q
/////////////////////////////////////////////////////////////////////////// J- i* W5 u( J2 |5 g [
//开始移动
2 I2 O) W. H8 w$ O+ f if (nSrc == nDestPos); g5 V% S' p5 [& Q
{) `, o n) h& w# C* n! u: k& y
//原地不动% ?8 `3 G4 A0 h6 z7 I, z
nDestPos++;
2 _4 s9 H- c! s+ q% h- H) F continue;
- K$ ~1 D x1 |9 t9 ? }
) `6 o% R6 n# F# [ `" f pInvSort->MoveItem(i,nDestPos);5 i: w9 h1 M, R1 h+ j
g_DPlay.SendMoveItem(0,nSrc,nDestPos);* C9 `% I8 [! [9 b4 b+ c4 M
Sleep(5);7 e' h0 l/ ?) _3 S
//Error("移动 - %d->%d",nSrc,nDestPos);
1 u" Y6 ~$ l6 N. L$ ^; N2 b nDestPos++;
* N' h ^& r. v6 n. Z& [ }$ [; Y( m) ]) [/ x. z/ l: }
//取第一个元素的信息
. c# v+ ^/ X8 C$ w8 G9 J /*
/ X' B* x5 d: f$ O: l if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)) e0 ^4 c* V$ X5 @4 g3 R
{% t0 ~, }- [4 i T
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);0 p$ l/ d) V$ C8 }3 K
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
( K# B A6 z5 \! r$ w }! R2 [ }- D% P+ x2 }0 D" t2 E* {7 y) c
*/
) }1 S1 d2 n7 j! _) G4 M- n //////////////////////////////////////////////////////////////////////////' r$ g* V7 [; v& j$ N. x. x
break;3 N: i3 N% G, o
}
% V* J7 l# w( L, R1 n/ e6 V }
% D. B: `: j; X3 [' C$ l}
" D' }4 {; @6 r' {! j9 ]* x8 K( dm_wndMenu.SetVisible(FALSE);
9 R J1 @* a' g; M- Q
c+ y1 S) S+ P: q# V8 Y--------------------------------------------------------------------------------------------------------
! M5 t, U5 e2 r' i7 p# \/ h' w搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
7 D; X0 o8 R) S e3 U{
; v% k$ _ v# t( _: KBaseMouseCursor();
4 ]' L+ @. x f- O+ |7 N}
0 S& {% S+ W0 E, \4 W在其下添加:: {# ~, q* i! W" I
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)3 i5 y: q- J8 q0 W
{9 u5 F' J7 R b% |9 {) U/ h& R
m_wndMenu.DeleteAllMenu();7 |1 y. p. ~9 |- t; `: }! i, |( N
m_wndMenu.CreateMenu(this);
& o( |" S% t/ W+ P8 X/ dm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
3 O7 D) s$ o9 ~: z7 Q; J8 p; ^! Q" v
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
. l+ O# j- p4 M! i* e9 o, s8 R- q{
3 g9 B5 E! ?/ ]) l& j+ q6 _ //P以上级别才可以删除所有道具& i1 `9 [1 W' d# `. P
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");, l# o* m/ S. ]6 E/ A5 [) B5 n
}
) M J7 X7 i& O; z0 {9 H) ?m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
+ s+ V; X. J# r% im_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );9 a2 x! T: R; p$ Z
m_wndMenu.SetFocus();+ E! n% s) [. @
}
v$ h( `6 f& A. Z) H) O------------------------------------------------------------------------------------------------------------ G7 \( l! f/ @, E o/ m2 [. j/ e
************************* U9 K$ e4 M: X
WndField.h文件
: t8 }4 `1 t6 T2 F6 B9 C6 C/ Y*************************
' u0 Z! z/ j3 U* Y搜索:BOOL m_bReport;
$ s7 ~1 N F9 W: `5 i' R其后添加:' s7 q c; B, b* H$ P
CWndMenu m_wndMenu;
) |0 L' l( p, a5 d3 D$ x搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);+ Q/ A* }% {1 @1 \
其后添加:
6 b! y1 S8 l& p# J% Kvirtual void OnRButtonUp(UINT nFlags, CPoint point);
5 @: |% q m7 Q1 [) _- C) ~- e$ D4 _
/ ^5 z n& `9 K& t- v8 G# i1 J' C
|
|