|
|
源文件中_Interface文件夹下WndField.cpp文件
, ^& g6 |, ?9 V/ c- a1 Q* p搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )" L( k! s& }# x: F; V! D
0 q/ }- L: X+ Z, s3 \& i+ n: \
struct sItem& _$ h1 a2 r. g5 A9 _) n
{
. {* p/ `/ B+ s% A5 `) {4 L9 eDWORD dwId;
) ?' b; }! G4 l- e* x6 ]DWORD dwKind2;. E& L& d; j' Q/ G. v* @
DWORD dwItemId;
4 E% K" v3 e: b3 L" q6 ?$ bBYTE nIndex;
* r* s' N6 ~; ^2 f# usItem(){
7 A! |- P L; w dwId = dwKind2 = dwItemId = nIndex = 0;
' k* ^7 p9 B3 s; ~}& k6 i" z+ S7 T9 `. {; k9 S. j
bool operator < (const sItem p2), G5 }. Q f' j9 N# `
{4 c! o2 Q E6 C
if (dwKind2 == p2.dwKind2)
' S' O( i0 J% f, `! e8 G k3 A {
! o( @. y% n6 a! \$ c3 n2 t return dwItemId < p2.dwItemId;
7 n8 W" y0 u/ R8 E& n }else{
: j; a+ b' ^( I( E! o return dwKind2 < p2.dwKind2;3 C% v* I) z1 i5 O; y( g* d; S
}
/ q1 @6 f# H! h}6 ~) o: d8 |5 W! E' M+ P: k+ k
};2 w, d, ~, |' [/ O: l% a
class CInventorySort
( U1 _( B I2 w- h5 p{
' T! Z8 V6 M3 M5 B0 ~5 v* K, vpublic:: ~' i) }9 M; Y @
CInventorySort()/ `0 g- Z6 k8 D, S( ]
{0 E5 C+ k, V7 v5 ^' x; e
m_dwPos = 0;$ t+ G( n( R/ g% U# A2 P. M
}- c5 ~9 n" @/ q- S: q* }+ L5 Y" j
~CInventorySort(){}
2 q2 J& {8 l) g! Zprivate:
7 i- K2 T" L# R5 p7 ]; asItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
* b% x. K4 F' P- U: {1 I& lDWORD m_dwPos;
% k. ~* M4 K, x, ?/ ]# j$ jpublic:. u) {5 J5 x* {0 ^8 {* K- Q
void Add(BYTE nIndex)
% R5 D: k! m, e8 V# U7 b{
1 s. q6 U- [% {0 n1 D8 {% ]5 m if (m_dwPos >= MAX_INVENTORY)/ B- \; l& w6 d: ~
{
( W& W3 L& @8 W+ ] return;7 @2 L4 A. ~% U" T& u# X
}/ |9 i0 c0 s# I1 ?$ Z
m_Item[m_dwPos].nIndex = nIndex;
3 S+ i( y8 ^ ~4 g m_Item[m_dwPos].dwId = m_dwPos;( `9 { B/ y' N$ m b
m_dwPos++;) S- k- m; z8 @, Q% ^
}
0 e$ r1 L, C7 V+ g; EBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
: E: u/ X6 ?. H3 ^# V{' s& ?. ~& {$ c; |0 u- e2 T
for (int i=0;i<MAX_INVENTORY;i++). G h" B9 c% N& W+ D3 o
{; I) _- a1 U( M
if (m_Item.dwId == dwId)+ s7 U, H# T2 S+ k
{
! y* I& c6 U( w) Z: v+ a3 K2 m3 @ return m_Item.nIndex;# }3 l; o0 G5 N ?# |
}0 w# P0 |4 K- j" Q. {6 i! x( J6 }
}
2 X' @. h& X4 U7 ~ return 255;9 p! x/ m: k& h; x% F. C' e
}
d& ^+ g$ j, [5 ?; v" uvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置2 k5 |7 ]) g( j2 s$ [" E+ g$ Q
{9 w/ U' z/ T2 U. a$ m
BYTE nTmp = 0;
' U& M' O4 n0 B1 K6 n, z bool bDest = false,bSrc = false;7 p& _% `* x$ W
for (int i=0;i<MAX_INVENTORY;i++)1 e% U8 S) i5 {2 k
{9 Y) [/ x& Z; F! @: ^: ^% v
if (dwSrcId == m_Item.dwId) V) Z8 C- g; g" t
{
" I$ W/ d* g% Q' x //id相等 则 改变对应的dest和src
% e7 s v6 M8 d- s4 P nTmp = m_Item.nIndex;
/ b, |# I3 y- E' _1 V/ k% j7 T5 p m_Item.nIndex = dest;3 F8 e3 J% d0 s" n
}7 Q& R1 M3 P4 H. Q
}- K ^- L+ F9 t% _- ~
//临时数据保存完毕,交换开始
8 K9 t# Y% ^. a. b9 Y. L/ B for (int i=0;i<MAX_INVENTORY;i++)4 @9 k, F; `; M5 e
{- A5 ~) `1 n- K2 Z2 c, z5 b
if (dest == m_Item.nIndex)
. R i& n' g2 [+ r {
* v' F) f1 r5 O! M2 _; d3 s //id相等 则 改变对应的dest和src
' ~8 s4 v, p/ f. a m_Item.nIndex = nTmp;6 m f& r: K0 ?5 l+ Z
}
' _6 o b) h* C4 C8 W }; G8 I% I+ \; t9 d" y3 L [
}
8 j! J! y& b2 C. b};
7 u- z, p, b5 d" s7 S; b-------------------------------------------------------------------------
( r; X' V" V( V/ j% C4 a0 h依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
k4 n6 _& f4 a: W搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);9 Q% W) k8 `4 j& h: V
紧靠其上添加:
) D8 h9 T' o! dif( pWndBase == &m_wndMenu )
# C& z+ b; e( d2 H8 E{
: v7 Y' S; _: @' n2 j2 X- A switch( nID )
% v! E9 S8 S# s8 |6 J1 k( ? {% _8 H' Y( Y8 Q8 w [/ [
case 2:$ Q% V1 g& e2 \2 D# ^% w* U
{
g- b. D; g4 g //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
8 k$ ~+ G; d8 }5 r8 h2 y if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
) e1 B l0 }, N; K: Q9 m. u {5 K7 X& h( G% B" U& ~7 S5 x* Y
break;
, q; E0 L6 B, f: [2 C }9 C" {* f! M/ Z0 j8 P$ p6 q ]
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
5 ?2 _. e, _$ S) S8 t& K {0 z- g# c- K0 H* p0 J( d
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
( c8 u+ U" R) U; o& n if( !pItemElem )
9 k5 N8 q/ |0 F N- d$ } continue;7 s$ u+ n7 }8 h- p( G/ `
if(pItemElem->GetExtra() > 0); _: X3 K& N5 c0 ~; C- J% F
continue;
5 t9 x( k+ I9 o: l: {8 k D. x. u, R if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 3 `: v4 ~$ V0 W( C o
continue;2 w) v3 C$ i' Z, _- v/ U' e
if( g_pPlayer->IsUsing( pItemElem ) )
' A0 t; z3 l6 z- N0 w9 C' `2 N2 \2 S/ C9 ` continue;7 F4 c! k) [* Z5 U' {( {: h. X1 z
if( pItemElem->IsUndestructable() == TRUE )! M( p2 `# c! e) p" g; y2 o& h
{
& M. o+ K! Y# r0 e5 e g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
8 B" `" D% N6 R- ^ \ continue;
8 T4 T+ {6 Y- D# [7 H& g4 N }- W- q' w: ~( I3 |
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);- f; o' D) l, ^8 A4 y; ]& @
}
8 d+ q' y0 |) Y' Q5 w! e/ b break;( p# k* m: r) f @) `1 N$ F
}9 m& z+ Y% W( \- f M0 N
case 1:
' ?7 S! O; S2 H/ N0 a {' j( l; g3 Q7 o
//整理背包! d5 C* ]" L6 n& }( q
//////////////////////////////////////////////////////////////////////////
0 V) x/ e; W* c; ]0 ]; H" j //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
9 O. w" X0 P4 `, t, C //////////////////////////////////////////////////////////////////////////* K( t& Q) g* f8 u6 m7 a6 B
//////////////////////////////////////////////////////////////////////////
2 b; f: Y/ o! } J, _+ b+ R CInventorySort* pInvSort = new CInventorySort;5 h, p4 A* z, S
vector <sItem> vItem;) _4 R/ y! S* d9 e! B; C0 y! B
vItem.resize(MAX_INVENTORY);//初始化大小
) i# C4 S' z% ? //////////////////////////////////////////////////////////////////////////- O0 I9 o. r! Y4 `
//填充数据, A, ` a0 W, f6 i! A
for (int i=0;i<MAX_INVENTORY;i++)# p' n% Z) H4 F
{7 A5 C' F* `, H; F
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
$ J& ]+ S/ }; k1 y" C( X, X: U* `5 R if (!pItemElem)
, L8 S) Q1 }- s {: V ^# z! E+ T! @* q8 ]
vItem.dwKind2 = 0xffffffff;
3 k3 l- e1 z( K vItem.dwItemId = 0xffffffff;
- {% Z! d( C: a* m) _0 j vItem.nIndex = i;: f+ c1 d! m u7 H8 x' P
}else {* s8 f: f6 ~6 v( M+ ?
ItemProp* pProp = pItemElem->GetProp();! ~3 l' Q: W/ w* s: f& `
vItem.dwKind2 = pProp->dwItemKind2;" G1 D6 ~- }" n: y" t' L! A: D, }: A# f
vItem.dwItemId = pItemElem->m_dwItemId;
/ B$ o0 q- [) _7 ^1 q( c vItem.nIndex = i;
( [8 y9 S3 ] u+ L2 G }
) y1 [+ s. M& b //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
1 F$ K* Y. n0 P: L1 O }6 |; f1 ^1 r8 W6 O
//////////////////////////////////////////////////////////////////////////' |2 t; N, }# ?1 F2 h/ {& t& G. Z" |
sort(vItem.begin(),vItem.end());//排序
7 Q% X) m) j- B( j' K9 a //////////////////////////////////////////////////////////////////////////
0 ^% o8 w5 |, r! V$ Y! N) q //交换
, f" W" [$ H: N5 k for (size_t i=0;i<vItem.size();i++)
: }. w, i2 n; c {% m" R* E- r- n( P# k$ u6 c( q
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
( {& ?! x' k U( Z/ H; p$ c pInvSort->Add(vItem.nIndex);8 {/ F/ M2 H4 [2 o1 R& p& L5 F0 p, L( ]
}
9 C* l( S' t% t BYTE nDestPos = 0;
8 ~- A0 T" K7 N C- Z for (int i=0;i<MAX_INVENTORY;i++)+ @9 Y; a/ j$ k4 o) G4 D
{0 k# F: H6 ]4 v* D7 b9 `$ {
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
$ t- U+ q* r, J( j3 w* i$ }( v5 q if (pItemElem)- W6 \5 N* K$ W% h5 L6 N
{8 k8 w" M/ ^, F8 p8 D
if (IsUsingItem(pItemElem))
' M9 o3 m3 x/ o. o5 ~ {
2 j, ?* |$ u1 o. S7 j* U$ b& s //这个位置无法放
( c6 w+ U- x6 A9 R nDestPos++;
- x, T. T8 P$ Y }+ z. a4 A* `4 {
}3 x% Z5 l9 f7 _/ A5 F J
BYTE nSrc = pInvSort->GetItemSrc(i);; M1 [7 I+ g y0 N4 `# `- N$ J
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
$ Q. \/ R' H0 Z. c1 u; c if (pItemElem)
& A! u) W! i% Y5 O @ {
: l8 s N( @) T" L6 T T0 F if (IsUsingItem(pItemElem)), n+ x4 E% T6 ^$ _! u3 Z
{
, l0 P& e) m l& n& a. p //这个道具无法移动,跳过
* q! a" v6 b; E& ^8 a1 j3 ~ continue;2 Y; J0 s4 x/ P: s/ d- H
}
9 Y9 D5 k; j r9 y) N% u% h }else{, C9 J5 P. N$ ~( H- L) i$ [* z
//空位置 不用动
0 O7 f3 j: G- j" i continue;
/ E# y$ H, s' d! t }
$ m0 l# x# _" s5 O+ I5 J _; K" K //////////////////////////////////////////////////////////////////////////
1 A' [6 N+ q( ~! v4 T8 T% ]9 G7 F( h //开始移动
! A. G2 X' L$ [& @9 \4 h if (nSrc == nDestPos). ?8 {& B8 n9 n' E ?% I* i
{
1 W# r! W6 Z/ {5 g8 ] //原地不动
* ]8 k3 G1 u: j: K0 y. m nDestPos++;
5 m: _4 x- C! U: m( D }2 J continue;9 r+ S8 _! M! Q7 N
}
+ _3 Y9 Q: i3 E* z6 ^+ J pInvSort->MoveItem(i,nDestPos);
/ J- S( O! u8 t' |9 o. X g_DPlay.SendMoveItem(0,nSrc,nDestPos);* A: b; ~6 b# |8 X# F# z9 [
Sleep(5);% W" E4 y' D5 S7 e7 @5 m, D+ h$ l i
//Error("移动 - %d->%d",nSrc,nDestPos); `; A. y* f9 K
nDestPos++;
- u! F0 T* n8 v# ~ X1 C }
: S: }+ n' D" e- L( { //取第一个元素的信息& M' O% I. t" O1 D2 c8 P' R- J( w
/*
% s$ F5 t+ y+ N if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)$ W6 C: \! h/ a4 U/ C( n) A
{
" x9 _' ~' Z: c+ i3 ^0 v Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
/ W7 F: o: }+ p1 n g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);/ ?) a5 z' \! I6 b% n5 s
}, I" b9 Z- r) Y
*/ ?, V5 G+ d% o( o. i5 v; @4 b* r
//////////////////////////////////////////////////////////////////////////
$ U' w2 {) q5 ? break;
8 d. i7 G4 R% C9 s }, O0 k4 X5 w" u+ t, ?7 a# E
}
" ]: A/ N9 p1 q/ r8 I! M}
4 y# w& N+ M6 ?4 l8 i3 \m_wndMenu.SetVisible(FALSE);# [( w2 B# W+ C0 i! I" t
: ~( M7 T1 N: ?" [+ U
--------------------------------------------------------------------------------------------------------
6 X/ |1 k- l% N3 T搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
6 L$ B" Z0 F# J, z{. x& V3 m" H2 U4 U* b
BaseMouseCursor();$ U4 T( w$ H. m
}$ X8 ~" j1 a! ? F6 Y7 U7 {, K
在其下添加:; t/ b3 U8 } M9 Q! c! r
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)- g9 t( V" V8 k& D( S
{! P: u8 y4 m) S- @& e
m_wndMenu.DeleteAllMenu();
: {8 c, o3 V5 F: P# L& Z% `( Im_wndMenu.CreateMenu(this);/ ^8 a. G# r Q) _
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");' `4 T7 X0 P5 M. v
) b. N+ Q8 b% R W& R/ R/ L
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))9 Z, f8 G5 X# a& T, Y8 j
{- R; x) H$ W1 }3 b# c' o* _1 p
//P以上级别才可以删除所有道具- n4 F+ t i& P+ \/ y# v- ~5 I
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
3 g3 R4 J9 T: Y! \, c+ T}
" ?5 ]6 _% L1 w6 z& Wm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );! n# Z& b- {" [7 A% U' {/ C
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
6 u- H, D$ Z4 [2 R0 Um_wndMenu.SetFocus();
D7 K3 M0 N: f+ k1 Z}
; V; m( P! n+ |$ n6 X4 ^------------------------------------------------------------------------------------------------------------$ N1 E& k% k( H) X) f* [
*************************
8 T3 D# A( }' o3 Q- e9 x' }WndField.h文件
% A/ F% a0 k0 v. L* {*************************
9 e4 j* p0 |0 X% ]4 a搜索:BOOL m_bReport;
/ q- A) \2 T/ s; j! _1 F! H其后添加:# W" \6 b& t: i4 S% G2 R$ w0 G
CWndMenu m_wndMenu;. v5 R- J+ n2 A6 z" }
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
. l# c8 ~; x3 U# c其后添加:
$ s8 e: R/ e4 t8 vvirtual void OnRButtonUp(UINT nFlags, CPoint point);
* W, j, A8 Y1 W5 U3 V/ [4 w( c9 p+ } U5 g' t: ?
1 L1 Z g2 I2 w% Q
|
|