|
|
源文件中_Interface文件夹下WndField.cpp文件
) S. E5 n% H. J! i搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
, e3 d$ [+ J$ T. L/ x
& p D: R$ s& m0 P4 g1 Istruct sItem( h! d1 Z+ x5 Q# A S; t1 }
{$ z, n. M# v. L9 w& Q6 B! e0 w
DWORD dwId;
3 ~5 p6 Z- [- Z7 ? V7 n2 rDWORD dwKind2;/ N1 U9 `, Q+ [+ H
DWORD dwItemId;1 T5 X+ S. k6 C4 v; n9 j) h0 n
BYTE nIndex;
6 l3 T( l0 T/ k" A+ I# n$ CsItem(){6 W5 p) J d( }/ N! x
dwId = dwKind2 = dwItemId = nIndex = 0; \( ]% h1 R( ?0 B( e T, G* ?( ]
}& \5 h8 T3 j4 `9 d3 h$ X/ T, U3 z
bool operator < (const sItem p2)8 r* [; z1 h5 O, W2 C
{" a+ W6 @+ l8 O4 p% A
if (dwKind2 == p2.dwKind2)5 q" R; G: f9 {
{# j' i1 q. l8 i8 x" o" ~! H
return dwItemId < p2.dwItemId;
2 |0 Q3 Z( u+ w6 ~( U1 [; v }else{
# D9 e1 X0 A8 Q& C$ o return dwKind2 < p2.dwKind2;
8 _5 W1 Q; \3 b/ ]8 ~0 p }( Y8 g% b1 e* S+ }9 A/ e _" M
}
2 F1 `5 X, n; B& f9 \, L};
7 _" u* j R9 H% o7 O3 iclass CInventorySort
6 Y7 M" B7 Y; O# \ H{$ S2 k' E+ r& X/ n+ V0 @5 `% s
public:
9 j: _: F: k2 q- \1 I: g8 h3 ?CInventorySort()4 W2 C. V9 C& m5 O1 X4 z7 R7 q) x, n
{
. U# B1 p1 G6 _2 A! ^ m_dwPos = 0;1 v- J& Q9 g* a) ?/ j# w' ]
}
' ^8 }! K4 {, S! h; a5 T0 u* ~~CInventorySort(){}& R: J, d: T- g! Z9 U! [0 A/ `
private:$ Q5 w( ~' h# @+ s5 V( d
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
/ d$ c9 W) ^+ x; YDWORD m_dwPos;
8 s5 w! V. J" P9 ^, ?public:
" X8 Z6 a" d8 q' ]& x8 p6 ?void Add(BYTE nIndex)
+ [8 Z! h' K% n: d" ^{
X( H; U L6 v3 a if (m_dwPos >= MAX_INVENTORY)
" ~6 n- [2 s+ i0 t {
4 L$ h- a8 v4 W/ [, K$ G! _2 V: U% m return; F; ^% z. t0 Q2 [- S k
} g: G/ i6 w1 Q$ q$ x/ E8 g+ h' L) P5 P& f
m_Item[m_dwPos].nIndex = nIndex;+ N% `; d5 a1 ?
m_Item[m_dwPos].dwId = m_dwPos;
# U" U4 P! o& h* g- v& A m_dwPos++;
1 B; d: L0 M+ n/ s) T}
( f; [0 ^* k" E% gBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列/ R* D+ L; i+ Y9 w+ N4 K) L
{
# \3 v' ?' I' W6 h for (int i=0;i<MAX_INVENTORY;i++)( s- t. n1 J4 m
{
2 [1 y; e) g/ O; M if (m_Item.dwId == dwId)' B! [4 \0 g" O* Z# i
{
2 O: E' Z5 c. g return m_Item.nIndex;+ C1 O- i' ~$ y
}- h! P6 m/ }* t* t6 u
}. V* H5 G4 ]; H7 c
return 255; w- e2 z1 d' V% I8 W
}# t( I: d! ]; w' |4 ]
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
6 ~0 x7 ^3 L$ R, z# I |{
3 |: `+ L( A( @- N+ J BYTE nTmp = 0;
! j5 X8 k/ q4 ^5 h) E bool bDest = false,bSrc = false;2 i2 Y3 g1 L+ [% w. ?* e8 D
for (int i=0;i<MAX_INVENTORY;i++)
. f7 J, q8 i8 Z# |- W7 ] {3 D# Z# _' p Y+ f5 @
if (dwSrcId == m_Item.dwId)
: d/ x3 O. \9 J( z* ^ {1 j" Z! ?% w0 C' u
//id相等 则 改变对应的dest和src1 W3 A/ ^+ t6 G# L* ?( E. U$ B; ^
nTmp = m_Item.nIndex; K; x7 C! a: H- y% C ]) ^ D- S
m_Item.nIndex = dest;
1 w: j/ h5 W5 C3 _ }1 e" M4 f8 l6 y: g( e
}- \+ F/ R/ N& e- A
//临时数据保存完毕,交换开始" T8 v- i. d* r# c4 V* A$ Y) d
for (int i=0;i<MAX_INVENTORY;i++)8 h9 X5 q' ]7 c! m
{
* @ p+ Y- w: I) l4 E* V% D9 ` if (dest == m_Item.nIndex)$ s% {( o* l: ?- @" @8 E8 ~
{
9 r) D: e! x3 M/ N //id相等 则 改变对应的dest和src+ K, S. \2 D" b5 R' O
m_Item.nIndex = nTmp;
4 j& j- R, h; H }& s- q3 v& i! `* e) h9 q5 T
}- ^2 w& E6 @2 ]4 @% F' G
}
: m O ~6 Q5 w: [};" q' ^1 ~# V: ~* g) K5 t
-------------------------------------------------------------------------
$ o- _! ~6 k( p! @% ?. p依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )4 k0 ]. M, A. `* G0 H: E
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);; M' H1 x/ K" N5 p9 g; Y) c
紧靠其上添加:) w; t: b0 K4 {5 Y ~+ s, c0 U
if( pWndBase == &m_wndMenu )6 n, a M M+ }/ x0 i/ D
{) K/ `+ N9 W$ V/ n2 e
switch( nID )' ]3 H+ `2 _6 m. Q# ~1 t
{
# P" l7 c1 z* T! C case 2:# B0 k' F* R" R8 ~- B/ j
{
2 N) \! y: W0 P; H x3 n //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
5 v& R( |5 G& \5 g if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))% D+ Y0 n) Y! e9 ~
{- W( u" G, v$ r" h
break;) ?6 `5 Y3 p9 Y3 w7 H4 ]
}& d* s, [6 g4 ^6 P/ F7 ], W3 g
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
/ e d2 ?2 h3 j6 L {/ Y6 [6 o4 h4 _% j# ?% h
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
8 j j) c; l- N( ?6 J# n if( !pItemElem )
7 c: n t% a: s/ u- S' L continue;
' `7 x& ~7 F& b F3 y if(pItemElem->GetExtra() > 0)9 l" ^* _" O) G* L( g
continue;
; Q+ E+ r U1 P4 r! _; ? if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ! N4 v3 V+ H! y2 \3 R1 d2 t
continue;7 d- @' ~- J0 g. F' D+ ^
if( g_pPlayer->IsUsing( pItemElem ) )
a) U/ N( U! [# v+ [+ y: H continue;3 i9 B: J* t5 H, Z7 {! a5 Y& S6 [- I
if( pItemElem->IsUndestructable() == TRUE )( D6 g0 u$ M# g# n4 h7 p5 j- m
{
. C- H+ i5 ^5 U) S; X1 z# W9 M g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );4 R) [# P) G, r$ k3 {( o
continue;2 p* Q. |0 L0 r8 g3 t( o
}
. i& v5 m5 M) j4 L( x A! P g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);& S! R; [5 h% o
}
) G$ H8 ~ C" ~! V3 ~* P" ] break;. P1 Q! K/ x+ a3 c& K
}+ X: ]/ B+ [! U
case 1:8 w1 n, F. ^# L4 S5 |2 M
{
. \/ m2 X/ F, T/ W+ J //整理背包
}. o' Z/ [8 E& b. c8 k0 Y //////////////////////////////////////////////////////////////////////////" ?2 i% f, u$ B. [# V
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
+ d/ o' U1 |, r+ M2 V+ D8 Q1 F" l //////////////////////////////////////////////////////////////////////////
6 C2 Z3 E# c, h: q //////////////////////////////////////////////////////////////////////////
1 H' ]% C9 S' r9 d5 z CInventorySort* pInvSort = new CInventorySort;
* B$ ?6 M k' z$ e5 v vector <sItem> vItem;
: m9 } H+ g7 A4 b+ X vItem.resize(MAX_INVENTORY);//初始化大小* {9 U1 c7 Y' f% m
//////////////////////////////////////////////////////////////////////////( m7 M" _; [9 d$ x2 c
//填充数据
! K# R" b/ h5 V7 J5 k% Y" o for (int i=0;i<MAX_INVENTORY;i++)' H1 g( [/ B: [/ n. x
{
8 b3 E' ?0 H6 i# c2 n: k, K CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
: v$ s( Q& @) u2 {$ W; P if (!pItemElem)
. m! [7 M7 K* K0 [( X% c {8 G" j: b) d0 U, L% {5 K
vItem.dwKind2 = 0xffffffff;
. }+ a. |5 s( X# @5 y; R$ ?9 P/ c9 e vItem.dwItemId = 0xffffffff;9 p6 g" x: w* \' p/ {0 q+ P( w
vItem.nIndex = i;
6 \7 c. @) E- G& ?5 k: U8 I }else {% S& S. M/ K: S: E
ItemProp* pProp = pItemElem->GetProp();# n# S$ _* Z3 _8 W4 e/ E
vItem.dwKind2 = pProp->dwItemKind2;
0 s" J8 z4 {* O* r; Y* I" F vItem.dwItemId = pItemElem->m_dwItemId;+ Q5 o9 p" u& L* x
vItem.nIndex = i;
/ I( W$ o% d* b" P }
* i$ O) o$ R4 K) }6 z/ N5 e+ x //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
8 X D+ y$ ~& ? }/ O* V1 R A8 X6 l" H- E: A
//////////////////////////////////////////////////////////////////////////
/ C9 a7 |" c( t- M2 n4 s7 z( h8 m sort(vItem.begin(),vItem.end());//排序* o6 w. U$ v0 |" R8 B
//////////////////////////////////////////////////////////////////////////
( h) \: K C. J* [! B0 H+ u //交换
! A" X, V! H' {, n2 G0 p for (size_t i=0;i<vItem.size();i++) w! H6 l3 ~" P
{5 Q, }; O3 l4 U5 O6 \% a1 A
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);: ]/ U. _7 x, | }1 O
pInvSort->Add(vItem.nIndex);& ^0 N [1 D4 F3 N Z
}
& h m! k; B" [1 ^! [ j! \ BYTE nDestPos = 0;! M% U0 d; K/ B& P. O( @1 M4 f
for (int i=0;i<MAX_INVENTORY;i++)5 Z, l- b; s8 @3 m1 q. }: ?
{
6 q, T+ j; z3 B& X9 X5 q8 I* k. Q CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
, F8 G* _$ D6 f. Y: v if (pItemElem)' [. A4 q) R+ D8 Q* K# ?1 w7 e
{
1 K" p6 Q& z [ if (IsUsingItem(pItemElem))
. B5 P1 F2 t# `' w {% ~$ L. I7 C2 {" c k
//这个位置无法放
h# M% r6 X% u nDestPos++;9 g2 J1 F$ A9 ~- E
}
: x8 x! ]! m+ L5 c: ^( `9 ]7 Z }9 n$ ]+ j8 h( a% `, B. T
BYTE nSrc = pInvSort->GetItemSrc(i);' [! r! _' k# n8 X
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);- z" w6 Z- C" s
if (pItemElem)
' ?, {% u: K1 s5 W {- X: w0 U# {& a ?( I
if (IsUsingItem(pItemElem))
- L, D2 u* O* G' c! } {
) r: @$ a& Q; h z# ^8 q //这个道具无法移动,跳过
5 u, ]' p1 i( Q2 i continue;
( G5 k: }9 D% F2 R) M }- ]: a% {* b( l4 p V- E: W
}else{
9 N0 l8 _" m7 Z: {; y8 T; O //空位置 不用动
/ Z8 z" U. F' ]2 [2 J5 H continue; u i. H% @; s4 g
}1 O0 d" g$ m& [( o C
//////////////////////////////////////////////////////////////////////////
; B( p2 N4 B0 V( M2 h% } //开始移动/ z H2 l$ C0 b5 @6 m
if (nSrc == nDestPos)3 Z& F7 B, F" }& x. A
{
& ]8 O% Q8 @. y+ F- _3 x5 q4 @ //原地不动- Y' z, ]+ n+ C8 _- P8 T& U5 A
nDestPos++;
$ m1 p% h2 W9 O1 ]( V continue;* `, r# b, M; _. m; T
}
% \5 I9 k, t5 i' o3 p7 Z, X# c: g1 l pInvSort->MoveItem(i,nDestPos);
* r! U3 ~8 {' O2 B( C g_DPlay.SendMoveItem(0,nSrc,nDestPos);
- _0 n8 D- Q% L3 V# h) w- B" K9 b Sleep(5);
$ y( [5 o. O" Q' M9 ]: h //Error("移动 - %d->%d",nSrc,nDestPos);
+ X, B7 E& G) ` nDestPos++;- n: c3 w( A9 x2 z ?' B- k
}+ X, x3 q+ k% \" O) Y! O
//取第一个元素的信息
2 f" K, t5 `( J9 Z6 Y /*
! e3 ~, f' L, X0 [% j. \ if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
% G! _ ^: _& P5 `5 B) H {
" s7 C, f" f$ H8 w I Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
) X. t- r: w' t g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
! u: i, U% `7 _0 y3 {$ { }. p* b3 O6 d# r- R1 ] ]3 G$ W
*/
8 D: g$ \3 I ~ //////////////////////////////////////////////////////////////////////////
6 g0 |3 O* k; S. R/ V, A" O( e break;. ]5 K9 G4 F/ ?
}! f4 |* l0 {% T5 F
}
9 Q7 E: W [: X/ |2 d}
0 D0 y& c: c) D5 Y6 Q. e+ T) tm_wndMenu.SetVisible(FALSE);+ w! W3 q: W! n4 y) j, l% H
' U$ P+ m4 O1 }
--------------------------------------------------------------------------------------------------------
! h9 h5 N3 T) r搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
, p- C0 h/ v9 J% J- q1 S! A' b3 m{
* D. w6 Z$ W5 T9 PBaseMouseCursor();* H) E. ~3 q! R: j- l0 q
}8 Z! W w. a* \1 V" d
在其下添加:
# g1 S9 V: V1 b1 Mvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)8 \# H( v. D9 G9 K# G
{
; m) r' K: m$ i" m/ Q4 R: C& Em_wndMenu.DeleteAllMenu();) o4 L% j9 e$ E7 q. H4 E
m_wndMenu.CreateMenu(this);
5 {- J& U2 c& z( |/ nm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
* e w9 m1 L" ]% r* Z# \, Z3 T: U2 x6 E* I3 |6 z) M
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))1 i) X5 }5 A5 _0 V" O* D
{$ _+ |/ D) d' q+ U0 {' a
//P以上级别才可以删除所有道具
1 M. M, C+ p' b. c. o, k, i m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");/ X" E9 k5 I0 Q, @4 I* F( K
}' N6 @& a8 M4 q) R7 Y
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );" a8 n; d! i/ Q) G3 e1 L0 o
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );" M3 ~* r* |& {* M
m_wndMenu.SetFocus();/ L7 [' E9 x* `% @1 w
}
* x9 B* m* `5 H8 z------------------------------------------------------------------------------------------------------------9 E# i3 [# [6 `: M
*************************' o. o+ L8 G( r5 f
WndField.h文件0 r* [* @; k; e. k" G0 v, }* G
*************************
* K6 ~1 L+ ~# N. M% X9 K% _搜索:BOOL m_bReport;
/ Q2 O9 _$ @* _0 I$ K其后添加:5 a5 a( s+ Y6 q" {7 F
CWndMenu m_wndMenu;
, n% y( r% T" `0 J3 D* M0 p搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
$ N6 Q& Y$ s$ z h$ U( B: z其后添加:
' S' ~$ B! l$ n7 J, L- tvirtual void OnRButtonUp(UINT nFlags, CPoint point);! V& Y3 n6 ~6 |) ]3 v* i
4 u' M( i5 u/ p2 j& Q$ J1 }8 U
; o+ w9 `1 g( ]7 j S
|
|