|
源文件中_Interface文件夹下WndField.cpp文件
" v- e. Z; @4 E& R1 T& e搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )- P! B) n" ]2 L8 j+ }( n2 ?9 h
$ ?9 R2 X! m8 I; J
struct sItem
: A+ ?3 h' B6 l( N j" M{& V0 I; F7 ]' t2 s" b I5 ?
DWORD dwId;
" L6 J9 f1 Z/ @, u- O0 {DWORD dwKind2;
* T) V5 ^' M9 Z3 Y* g, ODWORD dwItemId;
0 {$ z) y: [# B DBYTE nIndex;! V& g% ^: {) T6 ~7 b8 H
sItem(){
% \, q) h3 j f, `, |+ k8 n dwId = dwKind2 = dwItemId = nIndex = 0;* N) ]7 k( u" ?( v' |
}7 n. e% u, z) U" M- D, ?
bool operator < (const sItem p2), x' ]$ _5 l& O% R6 }4 Q9 c
{
7 E# O9 N2 f' G' x0 w8 Z5 h; ? if (dwKind2 == p2.dwKind2)
/ g a2 \, {+ } {+ d* U. o' B. T
return dwItemId < p2.dwItemId;
7 r* @+ F) E. u: } }else{9 B4 x, P# E4 e$ R7 R
return dwKind2 < p2.dwKind2;5 ? }' F0 U9 F9 F8 e$ b" L
}* y" d, d3 r+ d& p* _, _
}
" q* E: N% s8 O4 j! u};& D1 A0 }7 K) Z0 U1 ^
class CInventorySort
, s0 Z( K3 A; `8 n- r4 D{" ^) z3 c v) U: `# Y/ m: p
public:
" ]2 k# \/ s: V o& F" @$ HCInventorySort()
8 u, o3 y* j/ K{1 V5 e: B2 W# t1 B+ A) {" U
m_dwPos = 0;( \) M, ?4 l( A$ x G2 Z& O
}
* f1 _' a4 b7 l! l) D8 F* d$ K6 o~CInventorySort(){}
) w& M4 H4 @, h% r( Mprivate:/ H; B7 S% w5 M7 w8 \% Q
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息( o; i9 h: s' {2 N* V- z
DWORD m_dwPos;9 `1 F7 @# [+ b' d8 o1 t
public:
1 [& t: U' Q Z7 m6 R2 n4 y! v7 pvoid Add(BYTE nIndex)6 ~0 T% h( \/ g, c+ M* O1 X/ P; \5 b
{
1 w4 b$ f$ B' J# a$ j5 W0 E8 T if (m_dwPos >= MAX_INVENTORY)1 H1 L, Z9 \* h) o
{
# D% R2 S6 S0 Q4 n. Y return;2 E. i" ]! U- C+ n
}
: ~1 ]5 H* r+ O: |9 @ m_Item[m_dwPos].nIndex = nIndex;6 \9 U, ~, l8 p1 T1 I+ l' d7 P
m_Item[m_dwPos].dwId = m_dwPos;
* |9 q3 k- i( ?. p6 W* N7 J, W m_dwPos++;
+ y% i/ U) K5 \; R: `}
9 c$ _2 W8 @: f9 Y0 j. v6 A+ ABYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
! O# L& j4 t! X1 k8 T* G{
' ]& W* h- _3 s# r1 W& F) K for (int i=0;i<MAX_INVENTORY;i++)
: h D6 h' ?2 w' D {
% i6 ]$ M% ~" T f if (m_Item.dwId == dwId)
7 p) N0 G, J% |5 t {
$ o0 L6 O& C) X1 A0 w5 ?" p return m_Item.nIndex;3 j) ^; B, }& c) x, l
}( k( A$ h. D- u2 h& A, R& w
}
- x" s8 s. \9 J return 255;
, V( z# L6 O% J}% i9 V3 n# |' Q' Q5 ]; W6 F
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
/ g$ o% B% i. C `3 Q' E{
" T. |. w1 ?& K# W7 d# G5 d$ C BYTE nTmp = 0;. ]" g/ h! D1 z0 P2 C2 \' B4 Q
bool bDest = false,bSrc = false;
. N4 u0 V' `* O/ V7 G L' v for (int i=0;i<MAX_INVENTORY;i++)1 o: u/ A. n9 M6 p. k
{! v5 g# O. N+ @- _! F6 v
if (dwSrcId == m_Item.dwId)5 R5 \* e" u9 _$ G& X
{0 k7 x8 U) w! H; v
//id相等 则 改变对应的dest和src
. @7 J5 p# N- |/ i( G nTmp = m_Item.nIndex;
1 l5 q5 O) I- y& T/ D# N; q/ Y# r m_Item.nIndex = dest;& v/ t9 T3 U" ?4 ?5 t
}3 [2 X0 E( m/ C O9 J, `
}
6 X4 X, ?( a. G: r! G o! E //临时数据保存完毕,交换开始
5 O6 D/ F6 Q4 E* G for (int i=0;i<MAX_INVENTORY;i++)- C( N! |7 x, B/ n/ j
{0 U6 c* [5 c! b6 q- k' o
if (dest == m_Item.nIndex)
! z" d, P# J* L, g {
$ U$ C; z! H8 W: i //id相等 则 改变对应的dest和src
$ h& y* }1 l+ W m_Item.nIndex = nTmp;& y, l9 B2 Z6 H6 o) [7 M7 ?
}' d9 h8 m0 S% V
}
' {( Y; g5 w% |. V) f8 ?}4 p |; ~" l: _8 p6 `' D; x
};
% o& ~1 u# J. N- h7 g: M. j U-------------------------------------------------------------------------
: @: ^* A& g5 f: {( o$ t依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
8 K/ y Z' S6 o2 r% d搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
4 M# i/ U4 ?- q# }" j9 I* P紧靠其上添加:
; W F# X1 L! F! r. \if( pWndBase == &m_wndMenu )5 ~0 B8 [# y4 l$ O% d( v: Z
{
1 U; t5 v3 k$ t6 z# e switch( nID )
* ~5 b; l0 G# r1 Y( _2 c% ]9 i: b {
, M, E4 @# I% W case 2:
0 ~1 m/ f3 S' ?/ ^6 ]- q {
- ~6 |7 D# V0 y. [- X8 U //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
7 p( T1 @+ o1 W# b5 x6 D) V if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
^4 d4 J; A. U) g8 u1 ^ {
% R. I3 B; _$ m { E7 n8 X2 X break;4 z" D- u. F3 X! f
}
$ O* m1 y% M- A$ o for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
0 P$ k1 I: ^& ] {
( o$ V X' o6 z5 C; p% ~$ B CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);2 r( X; x7 ~$ B1 v
if( !pItemElem )
: g; F6 M+ n( s4 M9 Q t+ X; V continue;
J c* c0 _( o3 U+ v. r, C if(pItemElem->GetExtra() > 0)
- t$ Z# `2 n2 o9 S8 ? n C. d continue;- M2 \; I3 m l* k3 S+ a8 m M/ m
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
7 z+ K, b2 l5 @- v continue;
. c+ M5 G/ I+ ^7 F* Y4 _3 Z( z4 y if( g_pPlayer->IsUsing( pItemElem ) )
' W) ]9 l7 ]' ?( w) L continue;
; k5 J+ `3 w2 B2 ^9 B& h7 x if( pItemElem->IsUndestructable() == TRUE )
0 z6 [% x" ]2 _5 U: k. E {0 f$ s% v6 q% H) X* Z2 M; B
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
1 B/ h( v8 t, J* B continue;: v, `7 w; @9 `& X; |% s
}# l" I# y" X, Y4 u+ G/ Q
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);7 E. x" h5 [# e( O8 G( [: u7 J
}6 h; w, \/ U& I! @3 J* H/ S
break;1 ^! T1 ]7 _, M) p+ Q8 S
}
8 D7 n6 z2 J1 b; } g1 x case 1:8 P+ l3 h4 k+ V
{
- B4 ?( L- W$ B9 V6 f //整理背包
* f+ k- S. z" A, I& H //////////////////////////////////////////////////////////////////////////
0 j. u# q w0 u* y' [ //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );0 h: b8 S+ Z' X) }9 c/ E/ X
//////////////////////////////////////////////////////////////////////////
6 F c3 I% a5 q4 z2 F //////////////////////////////////////////////////////////////////////////
9 v6 ^4 b% V' I/ W! T- i CInventorySort* pInvSort = new CInventorySort;
5 b* Z: ~! _! l X2 g! }% u vector <sItem> vItem; H: S7 W- \, A1 x) e
vItem.resize(MAX_INVENTORY);//初始化大小
; C$ b- o/ B1 \ //////////////////////////////////////////////////////////////////////////
& W6 D1 @! d I( Z //填充数据* J% e& g. p& V! ~ w
for (int i=0;i<MAX_INVENTORY;i++)
! s* O: d5 \) F2 k l$ [+ p3 F {
& A! w, `9 A8 ~, z4 o* b CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);% ]/ B, n+ L2 W$ d; `* g, F- g, X+ z
if (!pItemElem)$ e/ M: x: X6 Y9 L3 V
{' D$ q$ q' v. h, @4 a+ ]
vItem.dwKind2 = 0xffffffff;
5 ~, f+ R3 c" {7 f/ k4 m: ?5 J vItem.dwItemId = 0xffffffff;* y2 Q. E# E* g% R5 X
vItem.nIndex = i;
7 C$ h5 O/ S2 O! d) ] }else {
5 L: R' R# c$ y$ } ItemProp* pProp = pItemElem->GetProp();
6 H U& C% W. g( A% w vItem.dwKind2 = pProp->dwItemKind2;
+ Z+ N$ ?, W5 T+ Y vItem.dwItemId = pItemElem->m_dwItemId;
8 ^' F1 }$ h( f+ P* S0 b vItem.nIndex = i;* @7 S: m$ F! j t2 A$ N4 W
}
& i2 @8 n! l' C& f5 y //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);' w+ h8 _& s( {$ `
}+ V$ [- b. B7 K
//////////////////////////////////////////////////////////////////////////
: k$ l- s9 a5 a sort(vItem.begin(),vItem.end());//排序3 h u5 @! S( T& Q- e' I, X
//////////////////////////////////////////////////////////////////////////
5 o7 T/ I; k2 V$ W, J4 m //交换! L1 t8 y2 w( y6 e
for (size_t i=0;i<vItem.size();i++): x. C7 [$ R* }. u Y9 k
{
6 ^- Q( y8 @7 _) K. j //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
$ K0 n+ j, O) a! y; ~4 T/ }. z4 r pInvSort->Add(vItem.nIndex);% |6 `- ~2 q; Q" W. [5 z- f9 i9 f
}
) w1 |# }; k. x$ s BYTE nDestPos = 0;" k' _* T) n9 Z( g/ n4 u
for (int i=0;i<MAX_INVENTORY;i++)$ U! |2 b4 z3 g# O
{
7 x5 U3 K+ ^) ]9 ^& j0 U5 J CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
* q; W' ?0 T1 B" \( v+ W* K, s if (pItemElem)0 [. }0 z5 Z( E& a/ }
{
+ L, K7 b* B+ G( D$ X0 b, j* Q- c' G if (IsUsingItem(pItemElem))
9 O$ C# y$ W* Z8 F+ E {
+ M; D2 }) \4 t7 n" O0 G //这个位置无法放/ G7 ?# ]# I1 t7 ~5 k+ l
nDestPos++;9 K0 V8 l5 ]5 L" Y2 t! {
}
5 W; W8 u# ~6 N/ _6 m/ ^ }/ P. q3 s/ M8 d
BYTE nSrc = pInvSort->GetItemSrc(i);
+ U1 R' d, f) H9 G# U7 X7 C9 F pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
3 d) r' H6 N% I7 i4 ^( J% [8 W% { if (pItemElem)
3 d/ B3 [$ K d) k/ b7 z J {9 D5 d' @" q F& a5 q
if (IsUsingItem(pItemElem))
E7 W J1 [* e5 K5 r: C {
" j) f) ~7 Q: d5 s8 k4 Q8 x5 n //这个道具无法移动,跳过9 ]* z3 }) k) O( u6 ?* f, R& v
continue;* Z* |" n5 @ {
}
6 }& W/ j0 h& P8 f }else{
) q M+ b/ ~3 I7 `, U //空位置 不用动1 m) ~6 g1 c' o% r, \
continue;' _; C3 z' B" B) |
}6 u5 T$ g7 `% ^3 B9 Z9 v" X3 |" p2 J
//////////////////////////////////////////////////////////////////////////6 ]& H& T! Y0 F4 G
//开始移动
0 [& F( H; L4 L! T2 k8 [& Y# ^ if (nSrc == nDestPos)' e: ?0 W. E0 H: `, {5 R- s) r3 R
{/ Z$ d, F3 Q0 L# ?) Q; T
//原地不动9 B3 t3 F, L& j& O; E
nDestPos++;- e+ d8 y- u& j& \: x
continue;' Z" x" c* c6 s6 ]& Y- @
}
6 z; R1 x+ k0 M# ]. s/ H6 g# C pInvSort->MoveItem(i,nDestPos);+ U M8 l: ~ p+ c7 V
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
3 w% O& ]. X) m0 V" ?- R0 A4 x0 R Sleep(5);
' T6 \6 v5 F' C1 m3 z& r) y //Error("移动 - %d->%d",nSrc,nDestPos);
6 [/ R0 j- P& d7 D- _7 n3 W9 B nDestPos++;8 ~. ~2 j K# i, A5 E
}( r8 b# N5 L# H( x, [6 ]1 ?% `# ^" |# p
//取第一个元素的信息
/ n2 O+ w( u" M( v# J, z) [0 ^ /*
; D+ s% ^/ C! j# q1 E2 B if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
* J$ \3 s; F' ?2 I- P/ O! V5 T {
3 Q: W( ] A# Q7 I Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
% O6 W7 _: N9 ~! R, } g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
/ P( Y5 V% T+ g3 k9 P }4 ]9 E9 w' K9 h& M) u
*/* V G$ F% c6 A
//////////////////////////////////////////////////////////////////////////$ \" p7 F& z6 w; J
break;5 A! z$ @% n8 c' i: v4 l
}
/ ]( U k Z9 B# @ } ' ~' C; Q- g! |/ W4 ]
}
6 {$ ]$ x1 U# u, N, i% Gm_wndMenu.SetVisible(FALSE);
/ Z5 u* Q* R3 e5 w: b* L8 |2 v0 ^% c7 x& H7 l
--------------------------------------------------------------------------------------------------------# r V A5 @# U
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
: \4 l# M! C! u{5 m" u. c0 \5 N) {) u" }
BaseMouseCursor();" F' D7 x! Y3 N: u3 @( I
}
& S1 X5 W, K3 Z, i& p在其下添加:
w! V# K' V. Bvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
4 S5 D. I) u& H( o: y. f1 r{: H2 M* b0 y/ `% u# ^$ Y
m_wndMenu.DeleteAllMenu();
9 o$ [2 `: G' {% r8 Z& _0 z# Pm_wndMenu.CreateMenu(this);7 T! U1 C& L3 e: o# O w7 O+ z
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
7 j% ]& p5 T, {2 W6 _ K
& k* I2 |3 v6 e1 S+ Mif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))# h3 T1 o, E4 r6 e- |. Z! h
{
5 G4 `( F( O" _! L //P以上级别才可以删除所有道具! i7 b' _! ?' Y1 x/ \ E6 x' r
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
1 }6 k/ O& K$ Q e& [: s b! \}; C$ X, f2 K" Y' R+ K# S2 t+ I
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
* O) C1 i5 i, B8 N# Z. jm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
1 b' }- L, Z* b. H8 i2 xm_wndMenu.SetFocus();
$ i; Y' s8 x. B4 Q}+ r# F7 {& {8 u5 a/ r% x; g
------------------------------------------------------------------------------------------------------------0 i1 r$ _' w$ j1 F/ z9 h- U5 {0 n, s
*************************
- M/ A- Y+ f% A0 WWndField.h文件
+ M( e" Q( a& I, I/ G*************************; J0 u; S5 e: p8 l) Y3 c! ]4 p/ ?
搜索:BOOL m_bReport;% I4 G' E) w5 @! p) h2 K4 P
其后添加:" K# R! ~. [0 w6 I7 M+ `$ `) ~/ r
CWndMenu m_wndMenu; w7 Y) [) \+ g: B) \/ e
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
; M% \' L4 ]) y4 M9 i其后添加:# ~+ u9 E) }" h- x$ ?; G% J
virtual void OnRButtonUp(UINT nFlags, CPoint point);8 n3 ~( X$ D" y) Y0 [
0 _0 c9 I' p# w% j' Z, k: C% X. H) k: f1 y
|
|