|
|
源文件中_Interface文件夹下WndField.cpp文件1 Q! }& z/ \) N& \$ ?
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )8 c7 c% s# `* z. x1 j L0 e
6 [4 F: S r# L, e( k/ P1 h" B- p7 V
struct sItem9 d" M! z2 ~$ I: U1 L; M& v
{
4 H5 t9 L) T* D ^, ]5 A- Z e# F* TDWORD dwId;
. g) @" z, f( oDWORD dwKind2;$ X+ |. R5 T5 O3 p& O" t! M, a* v0 V
DWORD dwItemId;6 G, e5 X/ R# T9 y. K$ T7 Y
BYTE nIndex;0 L7 E; v1 o% F( Z* z* P. O
sItem(){
6 U8 [+ x k* D' e; Z+ r' `' L dwId = dwKind2 = dwItemId = nIndex = 0;1 o( E3 B# Y. f! s
}) ?$ _/ k9 ~9 y
bool operator < (const sItem p2)
6 k/ f- l" ]" b: h& V) y* b0 M6 X{
1 c0 [4 ^ n$ m2 L. S if (dwKind2 == p2.dwKind2)
6 `% w1 A# e! i% R( E {
/ ~$ [) }$ Q% s3 Q- E# D+ [( Q, p return dwItemId < p2.dwItemId;
) g3 B6 N2 V! b }else{
, }' w4 V! _. z8 y% c& b return dwKind2 < p2.dwKind2;
3 y% q; n! t* X: b" R6 V }0 z( \% R" @, G# o9 R# a
}9 i+ z H( ^2 `% D& J
};# ~% h# z) g- V8 y. t; b# Q' K
class CInventorySort& g1 r, A: h, _' L2 `; C, }
{
' x: E$ g. ]- I( ^public:
/ |. w0 t$ U# N$ UCInventorySort()7 `+ b" c3 V" R0 m, v% B
{- k: e6 @/ J: B8 b" C
m_dwPos = 0;3 @$ T" R7 ^, m1 f- q
}
, w% ]* O. I& \$ d5 I/ K2 t" Z~CInventorySort(){}
/ b5 u4 G; E: o: M! \$ e3 bprivate:
4 x% K$ F2 ]8 K dsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
) @1 g( l% N3 p' \' O) mDWORD m_dwPos;
8 V% M5 d) o) z' b1 h+ P& qpublic:: c1 z7 w6 ^, {3 c0 n3 K* x
void Add(BYTE nIndex)7 ^. s* g1 K3 S( K3 K! Z
{
R1 ^" |+ e0 Z) } if (m_dwPos >= MAX_INVENTORY)
/ ?7 Q1 U# p' n {
1 R: q' C5 ?" Q8 w+ M$ a" N7 y' O return;8 c0 u* s8 W4 C: a( D! {
}
: \2 M, n8 v7 f. n5 G m_Item[m_dwPos].nIndex = nIndex;
2 M) s$ f9 |( F m_Item[m_dwPos].dwId = m_dwPos;
0 @5 V3 K, t; c" w m_dwPos++;5 C+ p/ \$ U8 \4 \% \( d
}4 W. s2 a9 d5 m+ D- C( p/ e M/ @4 J
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列0 [% R) Z# q6 N% J& `2 D
{
1 d: V4 W3 F7 E5 o: a: M1 P for (int i=0;i<MAX_INVENTORY;i++)+ y7 }/ V. k& k3 M
{% a: I4 D8 p: x( w
if (m_Item.dwId == dwId)* q, V7 R0 q4 }. L5 B E# h
{% v0 J/ t) d. I, X; a8 a
return m_Item.nIndex;
% w1 i/ @* u/ x }: j# }1 d, e& V9 y* m, s
}
$ }3 t( R2 y" l- z. B; t2 z return 255;& g# K6 k4 O5 A$ @3 S9 m$ `
}
" E% x% d$ A9 ^8 _% T* vvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
& S- R2 H+ _, N' A( {9 Q0 J- n{- r% m& I9 v/ d) l% g
BYTE nTmp = 0;! i( a7 ]3 ^6 X: w
bool bDest = false,bSrc = false;
' `+ Q x" }" [ for (int i=0;i<MAX_INVENTORY;i++)4 j1 W" K! Z( O j8 v; R7 M( n5 j
{
) g$ Y/ \9 F- w$ N7 R( M1 L if (dwSrcId == m_Item.dwId): j. ~$ r$ ~ c" ~. k, y
{
9 `& b/ M K3 D: A+ L4 G //id相等 则 改变对应的dest和src
: T- f7 P2 B8 Z2 \/ S- M" t3 { nTmp = m_Item.nIndex;
/ b0 _9 A: y% @: c% y4 G* Q m_Item.nIndex = dest;
7 A& |# E+ b2 \ j9 W l( O7 _ }
- W+ v4 T: T6 t, ? }" d8 v& l4 k& Z) A5 U
//临时数据保存完毕,交换开始, P( w5 C/ Q1 h" U. Y C
for (int i=0;i<MAX_INVENTORY;i++)
5 ?: p2 ?. @, `% S3 N' a {" W& V* _0 ~" N" }% `0 ^1 r! M! j
if (dest == m_Item.nIndex)
2 \0 q t: ? J) x7 }9 a2 i: M5 P {
! }7 c6 p* L8 h+ C3 a //id相等 则 改变对应的dest和src$ J. u/ L0 ^2 r
m_Item.nIndex = nTmp;8 z# _1 ~* i& k5 t
}
# E/ ~4 w& b6 ] }
; i' P% d" s0 V7 V \! \}
6 h( b1 p$ l& B+ |};9 ^) F0 C6 I! r
-------------------------------------------------------------------------
8 ^: H4 m0 g/ r' w/ Q5 D依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
0 U* X* A6 a3 N5 F搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);: W5 t/ d) N: R7 T4 h
紧靠其上添加:
: d8 A: v. L) \# w, hif( pWndBase == &m_wndMenu )$ ?7 Y9 z4 w% c* u$ E/ X
{5 S; k! ~9 R+ `" q
switch( nID )6 p# A6 o9 O/ S- X2 U/ j5 X
{
( M+ ^. p' o8 m6 F case 2:
3 v3 b5 l5 K) ?2 l+ ]+ o1 ? {
9 S/ E; `6 ~4 S5 R //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
" ^ M9 z( E w; }1 f! B if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
) O2 W. _& N2 W) ?# y) s {
, @5 e4 f. ~% [# f break;
* L0 U# b8 I3 X9 M }
5 r( q8 _( y3 k/ ^: r1 b for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
% Y4 o2 m& R$ _: W# }. b {
5 e5 d# |% P6 ^* u9 r2 M/ u; k' e, F CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
8 @) ?/ `% Y, \( f. j5 d if( !pItemElem )
' D0 z/ D# _' m( Y: H continue;
; g) C7 s8 R% V, v if(pItemElem->GetExtra() > 0)
" j5 l/ W% g! D5 W continue;; }' t8 y0 Q9 [- q1 R2 g
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ) [0 @; r9 q! ~! i
continue;' G+ k2 }! {/ f1 z, f
if( g_pPlayer->IsUsing( pItemElem ) )
& X; J- \! y) m! ~ continue;
6 H9 v! u0 r1 ~1 W2 S! Z" h" | if( pItemElem->IsUndestructable() == TRUE )
: C; e/ q8 t# ^, d4 H {
$ `; l, D$ K2 S/ v9 b+ [! D Q" w g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
I" K0 c; V* J" f1 ] continue;0 ^7 v' L+ l. Q7 n
}
! D; g, {$ M% U( H+ v g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);$ c- [ y) D4 d8 v9 E8 Q1 J0 x& R
}
! v- y/ k! ^: f7 R break;
: x! V7 m1 O6 O }
$ z }! k' t$ u- v& X case 1:
( E. o- `+ p- j) G# L {. r) ^7 p, _: t3 ~$ e% z6 x9 }3 H
//整理背包
/ G( |0 M2 S! t8 c //////////////////////////////////////////////////////////////////////////
1 J5 C2 h3 ]# x8 |) w7 T) ? //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
3 G% t+ Z0 \# r9 G# M% m //////////////////////////////////////////////////////////////////////////1 D- B' g* S5 a$ v# H6 |& D( R2 l
//////////////////////////////////////////////////////////////////////////6 a; M/ a9 a, w) |9 g }
CInventorySort* pInvSort = new CInventorySort;
9 w) c3 G* @" i9 O' b vector <sItem> vItem;
- `# @/ e r- a5 I m+ ~ vItem.resize(MAX_INVENTORY);//初始化大小
5 F6 U1 o' w8 ?$ B3 Q //////////////////////////////////////////////////////////////////////////
9 s6 Q, `' y5 z* v //填充数据
/ N) W) z6 V* F for (int i=0;i<MAX_INVENTORY;i++)
6 q* S7 Z, s- F$ h {
J3 B% Y0 X& y2 z# @3 [1 _ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);5 v, c B6 ]& i8 m: ]
if (!pItemElem)
+ k: s5 y$ ^6 b3 j, [ {3 F8 m) `( |7 R1 m5 p1 {7 s" S- d9 O
vItem.dwKind2 = 0xffffffff;( }9 V4 T$ G# t; o
vItem.dwItemId = 0xffffffff;
- R3 G9 H2 J( Y V- D s vItem.nIndex = i;
" Y: d$ E, z C) y( W& ^" s0 Z5 \ e }else {
9 w1 w' t- d' P4 ?, ?+ Y9 X ItemProp* pProp = pItemElem->GetProp();
: z/ t. a( p: Y" L2 p# Y4 x) u' m) j; \ vItem.dwKind2 = pProp->dwItemKind2;
7 F x3 D8 t9 h8 w( {# E vItem.dwItemId = pItemElem->m_dwItemId;
$ F) g8 j6 f5 y; x( n6 j- q vItem.nIndex = i;
' A4 m7 H. {* j }: j- r1 w* Q7 K- w' p$ P0 d, J5 \
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId); v% T8 k) e. t: |
}/ _5 k: S0 d! ?* q9 k" L. G. c+ O
//////////////////////////////////////////////////////////////////////////
( r, }& y6 ]3 ^" [ sort(vItem.begin(),vItem.end());//排序- _+ H* f1 P+ @, S* Y0 D
//////////////////////////////////////////////////////////////////////////, O0 e& `$ H, M: ?4 V+ K
//交换
2 S8 X* a+ {* e3 P6 H+ g for (size_t i=0;i<vItem.size();i++)& @& I; ~/ u8 V# m1 x! f5 N6 D
{
9 A6 F1 |: X( f% @ //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);( K* q3 t6 J k3 Y" f" `: I9 G) _
pInvSort->Add(vItem.nIndex);, d# Q7 c9 t7 G$ G, l
}
1 _+ |: b4 A$ n BYTE nDestPos = 0;4 [) W# v! v3 w0 Z+ E' x
for (int i=0;i<MAX_INVENTORY;i++)9 ?3 ]% ^4 p" C6 m7 T
{
7 Y4 D1 A, D7 @- | CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
) u5 l7 a' L! o8 t7 y if (pItemElem) x. W2 i) X, d1 ]
{
1 D. S0 T, |* G$ E1 J" w/ k* c% M if (IsUsingItem(pItemElem))
+ o+ L" [& u- M O {
- c. B% }: S2 v" h8 B //这个位置无法放/ _! ]1 p" M+ w3 s X. f9 X& p \
nDestPos++;8 K5 v" M+ B' T9 F5 ^2 ?
}
) r, B- @" b3 z* N6 ] }+ o; ^; k" a3 d
BYTE nSrc = pInvSort->GetItemSrc(i);* o% X( P+ F0 D
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);) m, ]! L) H- t5 S" Z* F
if (pItemElem)
& e. \/ j( y! k) F* N+ }4 E+ O {' e. c2 f1 ]8 m. }1 @4 w
if (IsUsingItem(pItemElem)). \, |) A& R3 J
{
. H/ F5 M; [% y* ^ //这个道具无法移动,跳过% B3 f* `/ o$ i4 m4 n& E
continue;; s8 x% r8 F+ \$ H8 H9 ?
}# w# l7 T- _4 L! ^+ ~
}else{" s" t+ l3 o. i9 m7 B5 G, v( A
//空位置 不用动
' D) l6 M& b6 U! W continue;/ z% I% P. \/ z6 V% T- |( @
}& R! W9 J& l' @: |# d% f+ K# F
//////////////////////////////////////////////////////////////////////////
! u6 q# v$ X( B5 k. s X //开始移动
3 `4 K, E- a( c% L, d v if (nSrc == nDestPos)
+ Q ]& P8 o! R8 f. ]$ z4 J {
8 Q0 S! C5 ?0 f/ }" s3 U //原地不动
6 Z4 r0 M: D3 L' x* ^2 q8 x; T' H# I nDestPos++;( ~" \5 m, Z K* ^: ]: d# _
continue;, Y. p- ]; F/ c* f, B
}
5 M* m' a- d& p; M8 | pInvSort->MoveItem(i,nDestPos);
0 U9 H) x8 o( x G+ S g_DPlay.SendMoveItem(0,nSrc,nDestPos);- i% j3 A6 b6 I# g
Sleep(5);
/ [/ H$ O# V- d# D5 F //Error("移动 - %d->%d",nSrc,nDestPos);
O' V* l7 a1 L' K% `0 z) {0 C! x nDestPos++;0 v( I7 l3 \7 O- X
}2 r. {$ j+ {% {* ]7 A+ k0 w
//取第一个元素的信息
4 A! f( W, ^$ a' P# n6 U$ Y; _ /*6 C U- e0 M$ E- a! l9 G4 L/ }
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)8 P% M+ V7 ^- Q" N
{( e/ E) A/ Q7 `9 P% j; v3 p. R+ ?
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);# Q" c1 Q* u) R8 T1 a8 U, H
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
( W8 W6 B# f' C( s! C }
' \- u8 U3 U+ V) h# A: H; ^ */
1 q; x* t3 b: V9 L" u6 H' y5 M9 f9 K+ h //////////////////////////////////////////////////////////////////////////
$ w) Y; y: ?" n! j9 z+ V break;
& F, r! a3 \. H3 m, V( w }
/ a* c- l8 {: }; V- H& f4 H }
: ~; ?: z, B8 u1 \# J! C: B3 t, i" s}
% I5 c8 ?* r+ X4 Ym_wndMenu.SetVisible(FALSE);7 q, g9 v$ I1 C+ P
/ \! X9 y( _+ e! k; Q--------------------------------------------------------------------------------------------------------
' V& [9 h; ~/ t3 z0 l: g8 D7 ]搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point). G0 j+ c+ [4 B
{& H' r' l7 w n, r! E; `0 ]
BaseMouseCursor();
7 \) f: ^0 N: o0 n4 z}$ o' @/ B( e( Z& `" X" L9 V; t ^
在其下添加:0 W( A5 K% u# C0 P
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
* I( O y$ |, w' j& S{
9 E4 G& c- e6 E* v( dm_wndMenu.DeleteAllMenu();
* c- {! q! }" G/ S6 `$ s8 Am_wndMenu.CreateMenu(this);5 s; S& D2 V$ o6 _2 ~* d6 \7 K4 A
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
+ F6 k( n3 f" J
& c" }) r; B2 ^4 v/ \2 Q9 sif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
# Z. L& q0 F4 I( h' |{
3 R. N3 i. D* o C8 @% Y! F //P以上级别才可以删除所有道具
* [6 y+ S7 a, c! K; q. |7 q( _ m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");7 p$ ^4 y- X# Q" W6 r) n
}
T* Q D r" ^ R/ k) C! Lm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );/ w: B: }' j3 B' W+ E, a9 i& a
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
/ l; u4 p$ @* h9 ?m_wndMenu.SetFocus();- h; H2 ]/ d6 v3 {2 K: z, b( ^
}
% _, i* a. C( L3 ^5 Y------------------------------------------------------------------------------------------------------------
: `+ d. O/ t6 \*************************
: z( K B" `8 `8 gWndField.h文件8 R& B9 [8 {% B1 a# c
*************************
( _8 `+ r0 D6 I, p" |1 w搜索:BOOL m_bReport;: f3 Q7 f" L3 C& J
其后添加:
2 U0 @6 x& U5 i% ~ x$ UCWndMenu m_wndMenu;
( p+ X" U# S* c1 Y搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
, j3 s, W% B/ G) X J! O其后添加:. b& V9 n4 D: Y9 M, L9 ?
virtual void OnRButtonUp(UINT nFlags, CPoint point);
+ r" Z3 C7 i0 {; k. q, ?/ e
# R. K5 n) |8 ] C4 u+ S% w
8 k H5 I/ R" D; L" [+ `3 p* _ |
|