|
|
源文件中_Interface文件夹下WndField.cpp文件
' s: O. s* _9 `* S* W( V# X( j3 ~; \搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
8 ?9 z; L6 `) v: P7 C
& M) M$ k9 I% L3 S/ rstruct sItem0 s# D: b1 o9 p# Z; Z! r
{
7 }+ ?3 U; X. O! ?DWORD dwId;
- u h5 P, _* \+ o3 H' tDWORD dwKind2;8 l: O& P" u# i9 Q8 [4 B5 J0 R0 i
DWORD dwItemId;
8 }) w* W; h; v- n: hBYTE nIndex;, {/ e. @* Y! ~
sItem(){ ]( B; U0 q( r$ Z$ q* q4 a4 G
dwId = dwKind2 = dwItemId = nIndex = 0;
9 D0 T: r$ c# H9 E d0 y; s1 }}
" O0 G1 m e8 [bool operator < (const sItem p2)
K5 o4 h8 j4 E+ _{
; _& |4 {( z/ M if (dwKind2 == p2.dwKind2)8 f: M p" W4 `. W* {
{' z& x/ s Z" L
return dwItemId < p2.dwItemId;9 c, O# D2 ]9 M: f- f6 l
}else{7 x6 C/ ?+ L) v' F' M7 J' J: l a
return dwKind2 < p2.dwKind2;
4 f+ M5 j$ Z- y0 x1 n* w }
0 ^7 J, H' Z" M: J}* n( }' f8 w! v: A0 s
};
) n/ Y2 ^* H, H# lclass CInventorySort
4 Z: L$ b' k: W' F; V4 _{6 O& s) e, z$ t% v
public:
! Q4 e' T, T1 T3 U0 r: NCInventorySort(). e( S, ^2 u: `1 ], I9 W/ H
{
$ `) |; I5 X, k& F m_dwPos = 0;0 K) V' G% j R8 |) T& @
}
) q* K( }4 o8 L+ X. N7 |$ v% q0 }~CInventorySort(){}7 H' C9 q+ J; \: A& c8 ~/ h% ?
private:' l1 h& H* d2 f4 x0 Z6 e
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
. a# [7 m& T0 ]DWORD m_dwPos;; s; S* a: a7 f, R
public:$ Q& S7 p% p9 C0 _* h
void Add(BYTE nIndex)
v9 R6 V% M. o{
: y& i( l( f Y- G3 {1 I7 e if (m_dwPos >= MAX_INVENTORY), [; r$ u' L% v5 ?4 G
{
& P# V8 f8 G: F- I X% ?" V$ L return;" k% ~% F0 r6 }
}
% B8 y n; s) V3 l* d m_Item[m_dwPos].nIndex = nIndex;& [" ~2 e. [3 E7 B3 o. T# C
m_Item[m_dwPos].dwId = m_dwPos;3 y2 O6 i- g# F* {1 A3 }
m_dwPos++;' k9 H2 Q. P2 m' e& t$ @9 f
}) s% N1 H- Y, j8 B
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列) o6 U" @" C4 e5 |( ^( v5 i) C
{+ G% j- |3 S; q. {, o/ G9 g
for (int i=0;i<MAX_INVENTORY;i++)
) ^: B0 B2 A' i9 k& c% P' K- d {; F ]: ?# ^ S$ Q+ w% O
if (m_Item.dwId == dwId)
) H+ K! s8 n c- D8 ?( i {
4 _2 [$ ^) c* X return m_Item.nIndex; A x3 g# |; b# L5 G1 a
}1 a4 ~+ }7 b6 q0 W X
}
$ Y& _$ k$ M7 H# m" Z/ E0 F0 x6 g$ d return 255;
8 T/ v* W- Q/ V& K}
$ n7 ]( @7 I& k7 n2 Rvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置 f" C$ x# r7 a8 A
{
& P) R1 F5 [) P G* d( @* F! V BYTE nTmp = 0;
/ r% z) w3 z' | R" I. A bool bDest = false,bSrc = false;
: I$ h1 A) g* Z! ^' [ for (int i=0;i<MAX_INVENTORY;i++)" j0 l) {/ ?( |, n4 x
{( E0 W2 h4 I/ Z# T, q! b3 r S
if (dwSrcId == m_Item.dwId): s2 |5 \3 n4 j6 L# |% L
{ @# q7 u, c8 L
//id相等 则 改变对应的dest和src+ i6 }" X! Q6 C, R* _5 i- D
nTmp = m_Item.nIndex;
9 B9 ]& C# D; }: K( n5 k m_Item.nIndex = dest;* E2 N& j8 n4 p
}, r& T, x' W: {$ ?
}( r: \2 K' ?6 {2 {
//临时数据保存完毕,交换开始+ u, t9 X( t9 u* a; S3 t, ?
for (int i=0;i<MAX_INVENTORY;i++)
, d5 m. ~+ B- q8 Q+ k I& i {
% T' N5 T0 y9 p7 X! n if (dest == m_Item.nIndex)! n( V0 |1 ^$ f' Y7 K! q
{
, C/ T" C" V, p' f //id相等 则 改变对应的dest和src
# W$ b& |& I$ H: l m_Item.nIndex = nTmp;
; ?( ^! c" I/ o" `. l }! m9 D& H c+ d( V8 O
}
$ H% Y4 |# |. O7 |1 R3 s! p ]}
1 X) u# s2 J9 {7 V- w' R1 e" s) U};
( A" l# |) _9 J1 W7 q9 W-------------------------------------------------------------------------0 _, p( j) p- X+ g0 S9 n
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
. {2 T x# g7 j# {4 a搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
* h, t/ y: z& w* P! t$ P" F紧靠其上添加:
+ ^. _% m. d* g: X8 b) _if( pWndBase == &m_wndMenu )
8 o: b U8 b' r& T5 s{
7 @) U/ L. y& g. N. ~; ~1 o switch( nID )+ `& }3 a3 X9 N* h
{
: @ b5 G' e/ O' G2 r$ C8 Y( w case 2:) M/ W6 L+ b: p8 K
{ x8 y/ r3 @1 i; E
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
7 W7 F: u6 D- l4 h; e( p7 \ if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
3 x+ I$ L+ W7 y9 ^5 w; e! \) R {
7 R3 S2 v3 |" F+ y- S break;9 `8 h8 }, J8 c* L* A0 t
}. w- \ E" {: W* n$ g' A
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
5 F0 H: V, Z7 x3 O- y* Z {
8 J" P, [" f; t! Y* ~" e CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
; I$ Q: y) ~% y( \' U: Q" o if( !pItemElem )' J) d# M! m' w. q; r
continue;# f& t/ K! d4 v$ ^
if(pItemElem->GetExtra() > 0)
& R3 l! }; X7 O7 ~ continue;
' ~8 H$ {) b- t/ z; c" r if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) / N8 e" ^* N" k. d
continue;
3 ?3 r8 O0 q8 k if( g_pPlayer->IsUsing( pItemElem ) )
) T/ P$ ]% _0 [- O continue;6 ]* x3 V/ ?) u
if( pItemElem->IsUndestructable() == TRUE )
. l* D/ f: [0 m$ Z {
4 c$ ?$ ]# q& V6 _ g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
$ A N0 y" {+ @* G; Y Q4 t continue;! |! @& {8 v6 j6 x3 h
}6 j! k5 K8 x8 l
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);2 k. y& U% i( l$ z9 W
}
* V- Q+ s& d( v9 \ break;( F4 f1 P# O" \. i
}
s& \: Y% j: k0 o case 1:% U" G) d* V8 S$ c2 ]% y
{
3 `. L+ F; [* [: N$ F //整理背包
/ W( v6 _9 d( p //////////////////////////////////////////////////////////////////////////9 x. V0 G; ^# o4 V- \8 `; p* {
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );3 s5 b) x* r. ~% g# k4 O
//////////////////////////////////////////////////////////////////////////
) m7 @% w* F6 n6 } //////////////////////////////////////////////////////////////////////////
7 I( [; X2 U# E. q n- x4 U CInventorySort* pInvSort = new CInventorySort;7 r" E8 [2 G* w" o0 E( q" Z1 {# B
vector <sItem> vItem;+ K% K9 J2 B/ W4 D
vItem.resize(MAX_INVENTORY);//初始化大小
, S3 j1 _0 n! w* p0 o9 ^9 B //////////////////////////////////////////////////////////////////////////
6 R% X' M: J5 k% N0 f: [ P //填充数据
& q' y; x3 Z9 @" G& x% \; [ for (int i=0;i<MAX_INVENTORY;i++)
* n X$ u2 W# H0 J* M) W; `2 ^ {- n* X" f- ? t. a' b: I5 n: s
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
' E0 R/ v2 Q8 V; Y" S0 |6 h6 M- C1 h: X if (!pItemElem)
0 X2 x+ w& d$ @) k; F1 | {
) }8 `1 n* i3 K6 S vItem.dwKind2 = 0xffffffff;4 D$ t" z# a, v# e v; p& x9 F$ v
vItem.dwItemId = 0xffffffff;
8 z8 |" b6 \8 U, W2 W vItem.nIndex = i;5 g: N" U& _( ? c+ H
}else {$ m) D/ Y, C' j/ x) U
ItemProp* pProp = pItemElem->GetProp();
' w @( r0 Z' f' E9 ]1 A; X T vItem.dwKind2 = pProp->dwItemKind2;
+ r. y' Y5 O5 G& h8 P vItem.dwItemId = pItemElem->m_dwItemId;
3 [; C8 \! A g# a3 f* _& Y$ N9 | vItem.nIndex = i;8 B/ _- K4 ?$ m3 ^' @
}9 u0 W, Z9 I2 V: U, P
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);! }# d* j5 G7 ~+ A8 a
}+ }" J6 e6 r6 ]6 t! I! M. o/ `
//////////////////////////////////////////////////////////////////////////
9 v% L7 H8 h. X% a' z8 m sort(vItem.begin(),vItem.end());//排序! S0 ?6 \0 y5 D* n+ X! j
//////////////////////////////////////////////////////////////////////////& ^3 e9 {. |) Z. O
//交换 i; D1 `% J* V
for (size_t i=0;i<vItem.size();i++)
1 l9 o6 _7 G; _7 c {$ N' J% J/ Y0 K6 I. f' G1 }! {: a5 V6 A
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
! z) U, B3 }8 b9 z& D pInvSort->Add(vItem.nIndex);
& j) `4 M2 I# Q: j# i0 i6 N }
% z6 u5 m. O2 |2 y* l" D7 i BYTE nDestPos = 0;+ E- {0 r7 z; H `. b; ]: a
for (int i=0;i<MAX_INVENTORY;i++)6 }# Z% [5 f7 U# \' Y j
{5 R, D# \* E2 `/ |0 S
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
: n/ S9 ]5 Q5 I6 s; F) G( C& C if (pItemElem)
2 J p1 e( d8 M$ v/ d7 X7 H* c! H8 t {
% o. a9 f R, t& E. b% i if (IsUsingItem(pItemElem))' ]! W5 R" k& q; [* N3 }* \5 g
{6 M% `* X1 X8 u- r
//这个位置无法放( G: {$ Y8 K6 H* X6 f4 ]/ k; V$ E
nDestPos++;
" \; o- W* N; `; ]+ Y* \8 \ }! }- @" b+ P! T% b
}, e8 a: u; k9 R7 A5 Q- g' k
BYTE nSrc = pInvSort->GetItemSrc(i);
3 Q( R: z3 C1 P# I) b! X pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);* q8 ~) J: G3 ]5 u
if (pItemElem)& t. I, h8 j+ o
{% E }9 \% l$ Q1 i% F* y
if (IsUsingItem(pItemElem)), U% Q# q u$ j+ _( h" \
{
: S3 [4 T3 w' D# y+ C& i //这个道具无法移动,跳过
! P' m/ ^4 B% C# M7 A4 c% [' c% I$ @ continue;7 y) i6 U9 i# Q) D8 I" e5 E& E
}# W# R4 r: Y$ Z* ^
}else{: g4 h4 Y! K! N- k _: _
//空位置 不用动2 d6 E2 p1 k3 ?- O; b9 D! {$ C' s
continue;4 Q; S1 `1 `# f
}+ J: p9 K, c: z
//////////////////////////////////////////////////////////////////////////
: ] K Y1 ~6 s& P. s9 Q //开始移动! g1 r8 Q& N0 s0 J
if (nSrc == nDestPos)
0 S5 F C0 E* N2 q" u& |0 o, n {+ w- ~+ J3 R7 M1 u/ L+ \
//原地不动0 l4 }5 {' p. \/ p& ~& P: ]1 S9 v
nDestPos++;- [8 Q4 R% j g# s6 b; A$ A
continue;
) m( |2 ^6 O3 ~1 }4 V }# s2 h# V: r6 m5 Y$ G) \
pInvSort->MoveItem(i,nDestPos);
/ c" I4 W; X- V) d o5 ?' F& O g_DPlay.SendMoveItem(0,nSrc,nDestPos);
* ~$ s3 D0 h7 ?- T/ G' \3 Q) o Sleep(5);1 Q8 G0 p+ R6 Y' }: u# i
//Error("移动 - %d->%d",nSrc,nDestPos);& a" D( f. C' g5 H3 z" ]. [
nDestPos++;6 C9 Z7 f; g" v2 ?3 Z7 h7 f" h
}5 \. t- V+ G" K1 |$ |, e
//取第一个元素的信息! c+ j% g$ G5 w+ b8 F
/*2 W0 T# u" J; ]# b5 D- Z: ?
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)8 N, K3 ]7 x9 Y% k$ L; |) `
{
5 F9 B+ h0 M9 y: r% ?' ~, j Error("Move - From:%d,To:%d",vItem[0].nIndex,x);6 u/ ?# [. \4 b" l5 p4 ?
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);+ H" ^9 c6 V5 V# I" ^- F) O2 {
}
3 k% d# t v/ R. A */
$ I+ y4 a' o$ ^1 e* F% Z //////////////////////////////////////////////////////////////////////////. B% h {: |9 ~* Z7 T. O
break;. ~9 X. z! K0 m* {
}4 U. r1 X1 b. x t' ~5 {* C
}
: ~, q: t7 I+ L}
; t# a7 K0 d9 q# O7 V6 J$ V; [m_wndMenu.SetVisible(FALSE);
- Q1 t4 l: u2 ^* O1 ^
( L4 Q+ e" Z! ~: T3 j$ H+ D- P/ h--------------------------------------------------------------------------------------------------------& E) D' R. r6 W+ g( x
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
7 c S7 A# B& z9 m{2 {* _ N. V& U' F& i1 d
BaseMouseCursor();
' d: o% k3 t) Q, N9 x1 f}4 _0 V& J E& U% k" p2 S
在其下添加:( [0 J ?3 T$ v" b- H
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
* r! B) ?+ ~5 b% L* ~, z{
2 n9 f& T) M8 J- rm_wndMenu.DeleteAllMenu();& [1 ]/ S& R0 W* y
m_wndMenu.CreateMenu(this);& k: O* }+ j6 p
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");' x! @( R$ ~* w) O4 Q
: ?( [8 a8 ~: Z0 @if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))9 ]! @8 Q. T. v/ y( Q
{
* F, K# ^0 ?& } //P以上级别才可以删除所有道具
G( }- ~) i4 ~" l, B* K) K m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
+ D: m: V. W4 E}3 M, z% e) V& j( E" D x$ J- O0 B4 z
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );0 f) ^" ~$ Y5 r4 O! v+ r0 J8 N, ~* {
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );3 d2 u9 ^1 A+ ?6 t% X
m_wndMenu.SetFocus();$ D% ]5 _! |/ }$ O
}; f8 q0 W+ h2 t, J u0 r: T3 M
------------------------------------------------------------------------------------------------------------9 s& J A, j2 A' @) j
************************* e$ M9 k' c' j" g+ D! A9 P/ D
WndField.h文件$ T9 x F% t: t; V8 ], `- z
*************************
$ Z" L. E8 R" j v# Z, v, _. W搜索:BOOL m_bReport;
" r& A4 O* c v4 w3 r' {) n2 ]- p其后添加:* {" o0 P# i* f {# @* ?+ I
CWndMenu m_wndMenu; A7 a, l+ d3 j) ~) S- a, K5 c
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);3 A$ \' J5 x% t9 S
其后添加:+ E y" h2 {! C% T
virtual void OnRButtonUp(UINT nFlags, CPoint point);3 A- n9 J: Q: x& T1 Y
. t) g4 Y# R7 Q+ U) E
: F P9 s' A% X2 I+ \4 ~ |
|