|
|
源文件中_Interface文件夹下WndField.cpp文件/ n1 {4 R* Q- j) `3 O
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
7 L6 z' p$ l, y6 @* t8 g" J9 r( ^9 H0 g* T8 q8 ^4 c
struct sItem9 L8 w8 n) ~4 E! O5 ]+ J
{0 G* J" w$ p+ C: N
DWORD dwId;' P/ [. [. E& P/ t( A
DWORD dwKind2;- j* [- P I! m( r( q4 |1 [
DWORD dwItemId;
. f; q4 p9 O2 X9 |4 r- {% p7 X/ CBYTE nIndex;9 L2 {: S) j% r
sItem(){( M# w1 A0 M8 K/ G$ h
dwId = dwKind2 = dwItemId = nIndex = 0;
6 J5 u3 p0 I6 W( D4 N+ d8 m}1 s( R1 B* }1 G% T% U
bool operator < (const sItem p2)
/ E, T9 c7 U L. y{
' r/ d% u) ~; {5 o4 T) S2 ^ if (dwKind2 == p2.dwKind2)* ~* J0 R7 | m1 q( v$ b
{
, _2 c5 _; T0 D3 }( G return dwItemId < p2.dwItemId;" N" P8 E% R H5 V0 @& s+ n" G( ^
}else{
0 X6 E6 G) u; i7 n/ n/ A$ z return dwKind2 < p2.dwKind2;6 H w$ H" E) R) e" ^ U, i8 D' w+ g
}
3 i7 a, D( T$ Q6 N D}8 z9 a) ~5 [" a' y
}; _: t. T! P+ L5 P; P7 J
class CInventorySort! W: q( `, `& H, h- {" ?
{; ~; P! A" \) m1 i t2 [" Q( J
public:
2 ?. O4 O) Q8 _* `0 |# K6 BCInventorySort()
7 }! P `3 z6 K w) v/ t& C{! E$ k2 [" @) v( h) B3 p
m_dwPos = 0;
* ~' r$ U7 W5 x4 L" C}, r$ Q, | b6 j1 }7 x, M, M( d) z
~CInventorySort(){}; K% y# ^/ x" V; W# y; x& `6 U
private:3 t. e7 C9 _2 c5 u- m; W+ S
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息+ D/ o* N4 S' A s
DWORD m_dwPos;
/ H# d* G3 }" y+ E& C9 qpublic:' t U' F$ q1 e# g% W
void Add(BYTE nIndex)3 h1 x+ V% D$ ?5 l' \
{
8 ^) |% D: t3 B4 P* u& a/ t, T) j if (m_dwPos >= MAX_INVENTORY)
6 f+ @+ n% R Z1 ^; h( _* p3 B {# U5 \2 h9 l _0 i: B
return;
' ]; f9 ^, v D1 j# ` }+ T' q+ k3 ?% T4 _
m_Item[m_dwPos].nIndex = nIndex;1 ~- Q) U- _) B9 v( g
m_Item[m_dwPos].dwId = m_dwPos;
$ K; g9 ?- Z: F; l m_dwPos++;
" y4 x: j+ d5 @0 P! U+ v* k/ I0 E- }% U}4 n& |! t* W3 [0 v! d8 k
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
2 J( Y2 H# w, C4 E. X{: c1 t, {6 Z! h9 G
for (int i=0;i<MAX_INVENTORY;i++)
5 l% i3 b9 G5 ]' ] {
6 p7 A6 `* Y* ` N' F3 Q3 W, b7 F3 ] if (m_Item.dwId == dwId)
4 }# J2 u9 |2 ?8 v' M) i2 m9 d {( m9 z6 k: E3 i! n3 M6 I4 r7 {
return m_Item.nIndex;
* @. Z( w9 Z! |- Z, X( [$ U }
/ I+ \5 v% L/ k$ E% r' R. {& S }& {: J) B2 Z( O8 w4 C& h
return 255;
4 m4 z* B8 t+ A1 {: l# Z}
0 J7 H% h1 n7 e9 b1 J2 pvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置5 g9 N6 u5 `) }& i7 ^% X" {. X
{
0 d* X7 P% a' j2 p; m7 v BYTE nTmp = 0;: a- \. |% E; U0 v
bool bDest = false,bSrc = false;
/ |$ J b, C6 Y7 ^% \1 U; w. K for (int i=0;i<MAX_INVENTORY;i++)
3 t9 ]! T2 C! \" t {
! S6 n1 O8 e6 v# d2 n, e! |+ d if (dwSrcId == m_Item.dwId)
: m! ~+ r9 G3 J {
" m2 i% h+ |, d; b //id相等 则 改变对应的dest和src
, M" x* y! ]2 V, l2 m: G9 p nTmp = m_Item.nIndex;
6 L( E, S8 R! n8 ~ m_Item.nIndex = dest;
* C7 ?% ]+ [5 H; _, v }$ X: y' c3 U. q) t
}
8 V: D$ z7 D+ O& E0 n* t //临时数据保存完毕,交换开始
8 Y1 E# f3 \3 y for (int i=0;i<MAX_INVENTORY;i++)
" ^# d1 {1 Y5 l, b! }! I {0 R+ Y( c/ D/ P
if (dest == m_Item.nIndex)
^! x8 C2 v L/ ?$ f {6 _/ M8 B9 z+ y5 x8 E) ~
//id相等 则 改变对应的dest和src
& x9 l( I4 d } m_Item.nIndex = nTmp;- q3 R6 a# M2 y- T- X
}+ U2 _: w' N! K6 v1 U! c( L( I6 S
}
2 X1 G4 s) m, D7 v, L}% [+ L8 H6 ~5 W
};
6 R K0 O: B) C1 I-------------------------------------------------------------------------
" ? J. \1 ?% x% _4 B依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
4 M2 W6 h. f7 C- v! K搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);/ h4 }: w# G) D! p
紧靠其上添加:
' R* B [4 _2 X1 z i$ Sif( pWndBase == &m_wndMenu )
! @1 X% ^4 _, M0 r{
$ u! S7 z2 G m/ ]8 C switch( nID )6 W' H" m! ^$ u0 y( l: ~' S9 I6 o
{9 j, B9 c: ?. M) u; `7 k W0 q
case 2:
/ m6 B6 M9 F1 F4 o- l {+ q9 K8 k) l9 b _! ]+ Z5 x
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);" f3 H7 ~5 `1 I8 w% }
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
& A) |& _/ T7 r* c- y {
+ _4 g' k- [& l9 F* _9 n break;& e2 \& o+ I5 V n
}/ o, a" f& r* z0 s p
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
& I+ F1 l b3 M. x5 y8 A {7 L8 G' v6 z( U7 p5 E
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
* r# w: z7 }. ^( x: E if( !pItemElem )4 M U; d; J. j
continue;
; |8 p+ t! I" h7 g! D, V if(pItemElem->GetExtra() > 0)
! v6 N9 D- W B( H2 Z: X0 ^ continue;
" @# v& l7 Q. Q* h/ e if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) # Y) i3 m4 ~, j2 R" W
continue;+ p5 i3 t6 f" D: T& G
if( g_pPlayer->IsUsing( pItemElem ) )
B) Q4 ~/ z# }- t% z( C3 _2 f continue;! Y1 m- W, k5 p a2 y6 W
if( pItemElem->IsUndestructable() == TRUE )/ v0 l. k3 y8 S6 k; A4 z7 Q
{4 ^+ Y3 s2 B9 \9 L4 \7 ]
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
' G a8 c/ s' ^6 \4 d, F continue;
. C2 L a3 y q7 B: ^+ S }7 F# j) Z$ x2 C7 W# ]3 @3 E
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);9 H3 M3 E. t: P- Y
}8 h2 D7 i- p; d$ e
break;2 Y) H. d1 ?* | c- I1 Q8 \/ q) `
}
, B; X. r" O; R& Z) D9 A, J case 1:4 S) v! u7 x1 X% ~
{
% a* D+ ?: Z5 H( I0 Q+ o //整理背包. H, h; ]9 g0 a9 C3 d4 G' G4 l- {; g
//////////////////////////////////////////////////////////////////////////; q0 z6 V# I \2 V
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
# F" x/ q9 e S: c, h/ z //////////////////////////////////////////////////////////////////////////% D$ t) r, _$ G; y' k/ @
//////////////////////////////////////////////////////////////////////////
5 T& r+ c1 I; u4 y0 C k CInventorySort* pInvSort = new CInventorySort;
L% {3 f: z1 K6 d0 G; h1 Z0 O vector <sItem> vItem;
* s) e; l- [# @4 b* u# d vItem.resize(MAX_INVENTORY);//初始化大小
8 u- {8 @+ j, b8 r: b //////////////////////////////////////////////////////////////////////////
8 z' M# d' {. u' { //填充数据
+ d$ T* L3 F( @* Y2 s3 A) q6 g for (int i=0;i<MAX_INVENTORY;i++)! Y) B4 X: j/ V7 s0 |7 k
{
' u9 s- A; k, ~ \" `7 V CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
7 R1 n1 S; f9 Y if (!pItemElem)
1 t1 ~7 G5 z. I# f9 R {
. `+ I3 t/ @: \ vItem.dwKind2 = 0xffffffff;
8 K8 u) B( T; \) g. r+ T# W vItem.dwItemId = 0xffffffff;, }( y j6 ~4 a3 \; h+ s# k& @
vItem.nIndex = i;
- {) D& o8 M9 d M }else {
6 S+ M3 G0 n V7 W/ c7 { ItemProp* pProp = pItemElem->GetProp();
* B8 q/ @# e9 _4 i vItem.dwKind2 = pProp->dwItemKind2;8 z3 B! l$ A$ c: K F6 Z( @/ K
vItem.dwItemId = pItemElem->m_dwItemId;4 D( h5 Y) `/ b" Z9 v- N& f
vItem.nIndex = i;+ k* ]& D1 K1 r3 @
}* ^! Y: X! `. r, v5 Y
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);# w5 I4 e$ R0 ~+ ?
}
, m+ `+ f; }: w: o; x3 v8 W* F //////////////////////////////////////////////////////////////////////////
; G6 C) V+ l9 G( c/ s3 I sort(vItem.begin(),vItem.end());//排序
/ C/ O8 ]# P9 j7 r4 ]. r! H$ P //////////////////////////////////////////////////////////////////////////1 E( G1 e1 l- P, [7 D+ D6 q4 |- }
//交换
6 W% d, Z) k1 Y for (size_t i=0;i<vItem.size();i++) a9 R* Y3 v- J7 }3 j
{) S" a: X8 l- D1 e
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
* v4 ]. T) x$ @' l Z, U4 F pInvSort->Add(vItem.nIndex);" p4 M0 a, g3 _
}0 _2 }) Z: @, ?- l5 m$ L* q/ c
BYTE nDestPos = 0;& @8 E1 ]' A1 `/ r/ K. M
for (int i=0;i<MAX_INVENTORY;i++) u- s. i8 }: w; G4 Y# w3 O
{
9 u, V V7 j& P7 s. y CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
% u* v* M( P/ r if (pItemElem)
$ {# ?! G7 k0 f: I {
3 u" a6 }# w& k% k/ l9 m if (IsUsingItem(pItemElem))3 Q+ G+ C, _; ?/ |4 g& f
{
" Y7 Q8 V9 H/ Y% n7 n% F //这个位置无法放
o( M, q* a$ \/ U$ n nDestPos++;+ N' p. c# T+ x; N
}, \0 \0 v* a3 V( Y9 V4 ^
}0 Z1 H* i1 J8 Y* m* c( G
BYTE nSrc = pInvSort->GetItemSrc(i);
! h7 T8 m2 c5 W* [& ]. _6 Z/ M pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
0 k+ \; N9 t8 x- C if (pItemElem)
% g. I* e, Z9 D {
$ E5 ^' s3 G$ x2 c! [' \2 U if (IsUsingItem(pItemElem))( T' Z* i* Y% h2 i' B
{
; _) ]# M2 u# t+ E ?" s8 O1 K //这个道具无法移动,跳过
& c( n) _1 k5 ^; p% E7 h continue;
* w C5 |) s% U+ a% \# v. m }
! [3 Y5 u, `7 A$ w* ?0 o! D }else{
7 p3 Y9 j) i6 p! x //空位置 不用动) @6 ?3 w9 H2 H( P; k8 b1 a- j" h7 }
continue;9 d& v8 A9 P/ G5 I
}
% j4 ~ g8 d% M* ?; T //////////////////////////////////////////////////////////////////////////
( z1 Q% {8 G: j( A //开始移动
8 B' L3 J& W3 T4 X( a if (nSrc == nDestPos)8 R( g7 T [. q/ h2 L! o
{
) k5 ~; r6 ?1 u# }1 Y2 k //原地不动; \+ u4 L# R- r0 S( q3 l
nDestPos++;6 [; f4 I! t6 p# l9 J
continue;
! S* K/ U7 F, O' |! x }
) q3 l/ ^5 t4 ?7 Q pInvSort->MoveItem(i,nDestPos);
, e5 m) a' e7 M. i6 v2 J g_DPlay.SendMoveItem(0,nSrc,nDestPos);
( r4 O+ e2 }) M: b) B3 }% w Sleep(5);, y0 {4 M3 m! F
//Error("移动 - %d->%d",nSrc,nDestPos);% X; U' l# C( ] F; j# x$ c
nDestPos++;
8 e3 }, _6 F% \1 I9 N# b }
0 {" @' E7 \) ?& W: B* Z //取第一个元素的信息
/ }* P$ Z& w2 K$ ]1 c /*
: x! [& x* o% ^! f- R- {- | if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
8 y5 i4 r+ d9 ^2 p; [" J h {
' I* A% X# N R% A9 z6 @ Error("Move - From:%d,To:%d",vItem[0].nIndex,x);- H7 ^ \* p( w" E4 v: j& |, e
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);, _; f- P! p9 v t a6 K: \+ W
}
# ^' ~6 F' ^, X! ^9 Q% w6 | */" B2 B s$ x: m! r! |/ }
//////////////////////////////////////////////////////////////////////////
( n s0 L. m- C/ m/ X break;
9 o/ G$ j! |2 y N8 i0 a }9 v4 I3 P8 Q M& L0 i# f0 m
} 2 f8 O0 P' p! s5 F1 x
}6 N, @; j+ Z7 G' b5 G! M$ @2 w" H! @
m_wndMenu.SetVisible(FALSE);8 B- F" w( T7 W* V, m+ p5 C
. G$ r/ l8 N7 q& p, }7 B, M: Y4 u
--------------------------------------------------------------------------------------------------------3 V- z ^8 U/ |9 K' Y
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
' q7 j5 X1 }/ A+ ~8 A{- V7 ?/ R, p* O+ ~# a
BaseMouseCursor();
+ I' ~3 b) {/ b. \ B$ Y3 t}
f$ r; Q& m" `/ o2 P在其下添加:8 V% t$ ^% w' E: e+ q9 }
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)$ e# ~3 H2 `* a
{2 @, S8 ^4 k/ l' k+ A/ {2 G
m_wndMenu.DeleteAllMenu();
' O. p& n8 ^+ g5 qm_wndMenu.CreateMenu(this);
( P5 E2 Q0 i% S8 F1 pm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");1 W3 o4 K" f( n- z+ i+ `
# d5 Z* f& v8 O2 w7 P
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
& A7 c7 h! n' b X D{
) s5 c1 C- E$ p! { //P以上级别才可以删除所有道具
" v* i0 `7 A" ]# B" |5 L m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
: f4 A1 l6 p }3 M+ x5 t& ?7 b. h}
# [7 K# m7 o* x$ ~m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );' U+ z' q! i3 ~8 e2 I1 T: X
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
3 w1 N8 \8 D" H, T7 k2 Sm_wndMenu.SetFocus();1 B6 }- T) Q; l) v: Q
}
, K3 \" o [* g, S: P, c------------------------------------------------------------------------------------------------------------
$ w4 C$ Q' V. Z" v1 ]& H" f*************************: e, H. e. [' Q' H( ^" k$ R; \
WndField.h文件% |) k; P6 n8 Z
*************************3 P% D! I' q7 d1 E
搜索:BOOL m_bReport;
! X; V% c2 W* Y% {8 |. j4 D其后添加:
4 ^/ w7 k+ H' tCWndMenu m_wndMenu;
/ g* T) d$ q; R \搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
/ C/ l1 l1 n( F( u3 k+ E其后添加:
/ }; Q# @3 h6 L" m- x o+ K) o/ @# Nvirtual void OnRButtonUp(UINT nFlags, CPoint point);
& t( D. ?3 {8 Y* N; W2 S5 T4 Q" G3 R$ |5 b0 U& V& w8 W
& F& A; W" K2 p7 h9 I |
|