|
|
源文件中_Interface文件夹下WndField.cpp文件0 g: M l2 {9 H& y' f, M5 c5 Z
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
7 R, `& l& _* x# ]4 X; y0 H1 ?4 b5 R
# P$ s6 A* P% ^) Ystruct sItem$ m1 j; r; }# D) R
{4 p2 P; V& {. V) T# @" J6 X
DWORD dwId;0 k6 Z$ }! l6 u1 W6 t% B2 d: K
DWORD dwKind2;% |& M" \ } o) o2 x
DWORD dwItemId;9 a. Z! ~, Q$ @
BYTE nIndex;
" ?) S8 [6 q, [1 o+ Y1 C0 PsItem(){
9 B% D" ]. v$ D9 z, T( d0 P8 _ dwId = dwKind2 = dwItemId = nIndex = 0;6 v1 R; h9 h" I$ l {# B" u
}: G! F0 C/ K, \5 R+ x. p( u% y% T
bool operator < (const sItem p2)1 H0 I: ?1 u" ]; p1 \3 s4 U
{
+ l' B6 C9 N+ T: Y if (dwKind2 == p2.dwKind2)) ] W: B7 Y( W/ N( u3 Y
{
+ O: \, A/ z' i( L1 | return dwItemId < p2.dwItemId;6 ^: q8 f. O! `6 \3 Y% {! F. j
}else{
5 ^$ C% \9 K5 A0 q; u2 U" w4 M# l return dwKind2 < p2.dwKind2;
1 N+ p4 j+ ]4 N# | } U1 L# s3 `8 A2 S9 l( R
}
) Q8 `7 e3 j( d3 K: }9 p1 P};3 w( m0 S6 t5 N( L
class CInventorySort
4 d* k: [5 `( B+ u{) @7 @! _: U! w2 X$ |' @. p d. \
public:6 J7 ]8 Y0 |% a# H
CInventorySort()5 B5 @- n: n( p! j
{
. X2 g; |* q, _; Q4 O2 q m_dwPos = 0;
; `' H0 k7 Z" O8 L& b}
* R0 ~* E2 g z2 U; J+ a' t% @: M~CInventorySort(){}+ v3 {: M0 O5 x6 e4 B+ J4 P( Z
private:3 Q; t7 F) I# r8 {- V
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息7 x$ w7 Z7 S3 m" h4 z" j
DWORD m_dwPos;
' D9 z' M: U# h# M2 U ?: Dpublic:, ^. w3 _; j" t3 Z
void Add(BYTE nIndex)
3 N v. n3 I L ]) R{
! Y+ ^0 ~+ g1 Q. _- [( ?; _. G: [ if (m_dwPos >= MAX_INVENTORY)
! c) t6 J* P- M& S {* |& ]5 V' B+ K3 |6 B/ K
return;
$ p( L8 ~, n L4 P; a }3 h/ X) S S! |; ^/ C t
m_Item[m_dwPos].nIndex = nIndex;
) N. A2 m1 U: } m_Item[m_dwPos].dwId = m_dwPos;
3 z; b# I" ]# Q; Q m_dwPos++;* {& n: l4 X0 h2 T$ q' N
}
% F5 t# w# J) r2 {4 Q2 HBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
4 K$ I) \% d6 E0 Z' F# a{
* }6 B Z) [- y for (int i=0;i<MAX_INVENTORY;i++)
0 U+ b( t D& X, A {
+ Q3 y. p ^2 v1 x if (m_Item.dwId == dwId)
. B& ^0 P6 r1 s. f, O1 O1 F: V {: |: B( u+ i& _/ _3 N
return m_Item.nIndex;+ Y S+ s; T7 z: b
}6 m: h: @0 V0 E; F$ y
}
\5 c6 X8 {- `* n return 255;
/ z% P* }0 j1 c6 P7 y6 f}5 J/ h8 o! M* t
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置7 p9 T6 M1 `5 g$ _' Q$ A
{, W8 g3 W; w5 [/ G# l. D
BYTE nTmp = 0;
9 u6 B" z5 N1 z! j$ v bool bDest = false,bSrc = false;
; L/ N& j' s( N! ^ G0 d s0 } for (int i=0;i<MAX_INVENTORY;i++)
- K8 Y* G& I, _) ] {
0 W0 c9 g) l( |) v3 F- \ if (dwSrcId == m_Item.dwId): b4 s( j& R2 x
{1 `/ j2 \$ j; E. z2 f; J. W1 p, q
//id相等 则 改变对应的dest和src! D! N8 O% V2 O
nTmp = m_Item.nIndex;% c0 S: o0 x# w8 Q- g+ R
m_Item.nIndex = dest;
9 Q0 y0 k \) o4 h, a }
: g) \" i, u5 x' v' K }
~7 I: ^4 V' x( C- o* t% q c //临时数据保存完毕,交换开始) N! b) N; M4 H. n* p* Z6 \: {
for (int i=0;i<MAX_INVENTORY;i++)9 l/ f0 [& ] y; F7 l
{% a, I% H) ]+ B! s/ Y% H
if (dest == m_Item.nIndex)- a1 t W Q, o; y% v. N9 G6 l
{
) F6 y& L7 b' M9 u' G //id相等 则 改变对应的dest和src4 o1 `) b! o" h8 K# g' f, X
m_Item.nIndex = nTmp;* q# y* q: ?& t ?2 B
}
$ }+ X6 e# H0 j }6 X; ^$ p# v e/ j: U* u6 D
}# x9 M4 Y& l1 _* w
};1 l' P2 ?0 B3 m; ~! h
-------------------------------------------------------------------------
# e0 H; U- O+ {1 v依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )/ z$ n$ u3 u! E
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);8 }9 D1 j, u5 ^( j2 A
紧靠其上添加:
! g4 L% v% y) S& e7 v1 B2 s& }if( pWndBase == &m_wndMenu )0 a U, x8 t, X3 R3 O
{8 [- G5 Z$ m" y6 ^/ I; z
switch( nID )* x9 s! F; ~: Y( \! r
{; y5 H2 |% L _3 f* F0 X/ n8 P7 X
case 2:7 C/ S9 C( F1 `; l. ~, c8 i- h
{
4 c* n" Q6 Y4 b4 X8 z& z //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
# Y: K$ I( ]( ~+ `: ^ if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))$ A% t3 Y" J, ~
{: f* X5 b# m0 B
break;
$ V+ x8 q! c8 B3 [8 A& ] }
& X6 r" V" n5 Z |- G for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
. }9 t9 f3 \$ n4 [ ]: K6 g3 K4 ? {
. T8 p9 o5 {3 W1 r! J CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);3 P/ X& @7 ?; K" ]# |
if( !pItemElem ) X1 V: L- M$ c6 x9 H
continue;5 P: u& f6 f3 O6 R2 n: ? A
if(pItemElem->GetExtra() > 0)
6 A& O% A0 K& S0 O5 W9 f1 B continue;
8 |1 j' {8 s, `: K( {" f! k5 A8 _ if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
- @' x! ]4 U. J) t { continue;
5 q/ [! ?1 l0 Q* p# H0 A if( g_pPlayer->IsUsing( pItemElem ) )
8 w& b# i# C5 ?1 ~ c0 ^: P continue;
) V* s" a" W' T if( pItemElem->IsUndestructable() == TRUE )8 O! b6 U. o5 F7 k7 k
{
5 Y' I) A3 ]0 z2 C' ~4 \ g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );3 D- l( R3 L# ~) }
continue;! L5 F3 {) Y" C7 W: o4 U4 @0 z2 i8 a* v
} a0 v/ \+ Y% K5 x
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);9 L. U, n" s! r+ K6 k- M% @
}
4 z' Y. q1 f8 r; d break;; ]- B7 U" }3 u' j$ c5 t
}
1 A! I3 F& ?0 V( e9 L+ q$ G case 1:/ V, z7 r$ H7 }+ J! l" s+ J
{% B* C0 t0 N3 D; j. J/ W1 _% k+ |
//整理背包! H( B8 N' G0 k1 K C. `
//////////////////////////////////////////////////////////////////////////7 \3 B9 A# o( n+ N5 ]
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
8 p: p1 ~9 {5 F4 b0 L //////////////////////////////////////////////////////////////////////////5 P( U3 b# Z5 i8 g* W
//////////////////////////////////////////////////////////////////////////
0 Z/ ]0 u8 o8 u" d CInventorySort* pInvSort = new CInventorySort;! n/ K3 N+ }( t/ `8 s* h) e2 q+ o9 A# L5 [
vector <sItem> vItem;
1 o# c) F. }* D vItem.resize(MAX_INVENTORY);//初始化大小$ Z) p2 U( Q+ f; m- V4 c& v
//////////////////////////////////////////////////////////////////////////: U1 Z; E, y+ |* e5 O% ~
//填充数据
. q0 W3 u1 }5 v2 s8 _ for (int i=0;i<MAX_INVENTORY;i++): S4 K. @1 W3 H. F* f8 ]
{1 i, I4 p V; H7 R
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
. V$ Y4 |. O: M9 F if (!pItemElem)# F/ ^7 B4 v7 Z$ Q6 B
{, H O1 ], u8 ~- N1 k
vItem.dwKind2 = 0xffffffff;
- C, ?8 l `; O s6 v" f+ e vItem.dwItemId = 0xffffffff;: G3 S; U; e {4 J. z- }, n1 ] T, V/ B
vItem.nIndex = i;& Z$ [8 f1 ~, i' E% \( Q
}else {
6 [" E0 _4 \" m( T ItemProp* pProp = pItemElem->GetProp();
' f' n( A& p0 j& ~% s' x: I2 o vItem.dwKind2 = pProp->dwItemKind2;
0 F/ k$ _( D1 E+ S vItem.dwItemId = pItemElem->m_dwItemId;
& i0 F- F w5 b7 @. \1 b/ N vItem.nIndex = i;
* `& k1 T- K$ W) x R9 ~5 n. m" g } }% \" [$ X$ n- Z5 B
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
P$ [; C( d# y$ V; c/ J" [ }0 B" T; Y! c) H" q
//////////////////////////////////////////////////////////////////////////
$ r. H5 D3 V, c/ i sort(vItem.begin(),vItem.end());//排序
( X, K" ~4 M1 t; n //////////////////////////////////////////////////////////////////////////
5 u/ a3 b! } l //交换5 B* `9 \% d, F: s, P# Y
for (size_t i=0;i<vItem.size();i++)7 X6 q( ?# d. T1 [* j' N
{
) j: Y" g: s \! r; a# D //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);# i& G7 b" m# c; ~1 a
pInvSort->Add(vItem.nIndex);
5 q: V1 [, i" r& d" V* A; N }& D2 R2 O+ A% \( O, Z8 W& \
BYTE nDestPos = 0;
" U7 C9 T4 n5 @5 \+ C& }, o8 o for (int i=0;i<MAX_INVENTORY;i++)9 O; X4 A- A( V" [# M& O
{2 h* H9 v. v' l- n7 a; z. R
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);- M, y$ S/ i8 Y% f. b& n
if (pItemElem)
; t3 e! Q! q, B m# ^* L; \1 u {) C6 |$ H% y9 y( r
if (IsUsingItem(pItemElem))
. U- K( Q: T2 r0 `4 l6 f {# {3 K/ |0 O4 `- T
//这个位置无法放
) e$ S' I" }" C. {5 z nDestPos++;
) ?3 g: S. s' }6 I6 y }% @+ n$ q* k8 Z: ~8 F5 _
}% \; ]! B* g/ J4 w9 {* L$ ^
BYTE nSrc = pInvSort->GetItemSrc(i);' X8 }9 p6 Z: N# s; ?
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);' b- _5 y# U! J, z
if (pItemElem)
" @5 b3 s+ q$ K( m# } {# S& n7 x9 U) e5 J
if (IsUsingItem(pItemElem))! o9 s6 G; C2 f2 @+ x0 x
{2 @# F4 f2 N4 |# o
//这个道具无法移动,跳过
! V4 Z/ ^& h7 `7 P/ B; _5 }- w* w continue;) p H7 H3 c' g9 M, W. |
}) T5 G8 b" f( X
}else{3 i/ [4 N; a0 q! t& m2 Y7 R
//空位置 不用动" w' Q' z" t5 |$ L9 \
continue;' h4 K8 [! F! }# s3 L
} m+ }) c$ f" R% @+ O
//////////////////////////////////////////////////////////////////////////
% g3 e9 X, n/ c1 g, i //开始移动. E) L! x0 f/ D
if (nSrc == nDestPos): V2 k( r: c! }( }
{
* R. Q2 D7 J& E5 Y- k //原地不动4 _3 C" P! x3 c. M
nDestPos++;
' J5 |$ G( K, n, W( D. Z9 b continue;
3 z* w! I- A) F9 M. l4 P- h }
& ?& r2 F: F0 R9 ?1 H" k: G pInvSort->MoveItem(i,nDestPos);
( J A2 }; a5 [7 _7 c! B3 O& ?% R g_DPlay.SendMoveItem(0,nSrc,nDestPos);
# `" U! a: c' {* g7 m6 ?/ } Sleep(5);7 h7 k% B3 o& e/ [9 x1 G& S
//Error("移动 - %d->%d",nSrc,nDestPos);
7 g L1 [% X" X' N nDestPos++;/ e' W8 _* L* j; m
}
5 F5 Z: \, @# f9 S ^$ Z: {" @0 k //取第一个元素的信息
& @2 o* K1 w" @6 Z$ m /*- Z; R) {* l' X9 p+ t2 q5 A- d* j2 N
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
7 c6 t* {8 \' Y4 ? {
7 H) a3 I3 L& L# }, _! B3 Q9 f8 ^ Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
) w6 ?( m* s1 B2 L! Z# p$ b8 f) _ g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);1 l2 M5 ?+ b6 E
}
2 O* m8 i! l& Q; t7 L4 H */
1 q* h" k; B5 H/ k6 l; u# s1 P. \ //////////////////////////////////////////////////////////////////////////- u8 r4 B' R: |, e+ f k/ R$ {
break;4 \! U" T. ] }, w
}
- d- p2 k+ g. [; v G }
2 j3 V* Z. u1 I# ]4 U9 N4 }5 E}
) H$ g% a, d- w$ m7 _$ ~6 mm_wndMenu.SetVisible(FALSE);
. ]0 v* Q. j% n( C; M/ M- [) d
* I6 f6 \1 {" P$ g' y--------------------------------------------------------------------------------------------------------' i! t4 p. o4 b- @( i! S9 X+ [) f& z
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)! I6 g1 Z. ?& }' P! d1 W
{
0 g7 |9 R, R& H; L' p jBaseMouseCursor();
/ V. ?3 X2 c& V}
# r1 ]' T4 F' w9 _' t X在其下添加:
$ z3 t2 |+ k- Z$ G4 D) ?/ E7 Z0 Svoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
, \- o* j* q; H4 t5 [) U: r! ?{# z# N% t# T% n6 r
m_wndMenu.DeleteAllMenu();
+ m, h2 d3 r: S9 I7 f K. [m_wndMenu.CreateMenu(this);
! k, _- g2 `" T7 Pm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
- @4 \# W% X+ o$ s. N
+ p2 N# b. [; q0 E3 `8 |7 ]0 s% i2 zif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
& |9 N$ ]1 v# T3 b# l, O{: c) w$ u$ Z* f8 y
//P以上级别才可以删除所有道具" V/ V8 {6 n6 y
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
7 G8 r- F+ ^* B0 \ p( p}
) _; a0 `$ }' f0 M" Nm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );6 |0 y/ d* r$ c
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );: h4 C m5 {, q% M) F# O
m_wndMenu.SetFocus();
9 V/ p) x3 \9 ~8 L' x. e}( y6 W5 P( I& ?# S
------------------------------------------------------------------------------------------------------------
" L0 l5 S0 ^9 f5 x# q) `5 h+ i*************************
1 k' e; ~6 Z$ v! F8 H* RWndField.h文件
) | l. |7 e: E" S*************************6 z7 w# B7 L0 q. [3 d
搜索:BOOL m_bReport;
{( D# ` p" x* U其后添加:
; z5 k8 e2 o6 @0 Z" D0 g0 E7 pCWndMenu m_wndMenu;
- d' i1 D. x( ]" {3 C) w搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);5 K' s# D8 Q' \
其后添加:5 e/ ~. j1 m2 W
virtual void OnRButtonUp(UINT nFlags, CPoint point);
: U" i" T0 W" O+ q" c4 X
& L6 C' V, O, k8 t
; R0 l( k `7 U- I9 B0 V |
|