|
|
源文件中_Interface文件夹下WndField.cpp文件. z& ?. v, G- f1 ]( X4 P* z
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )8 _) m1 n& t' j, k. k
5 z7 i3 B: p* p
struct sItem
2 Y0 E% i( N1 e4 [/ r{1 x# T4 L K* _# n
DWORD dwId;4 N6 s& A/ k) r# e
DWORD dwKind2;+ T* \/ h7 Z% }" O; v2 ~- |# l
DWORD dwItemId;
6 l: V/ y3 C5 Q; C" ~$ cBYTE nIndex;
& A+ M6 _9 s6 x" k- IsItem(){7 A# U, b( E2 r) b2 H0 C
dwId = dwKind2 = dwItemId = nIndex = 0;
1 J% f9 U9 Y3 ^}5 u' a% Y. h& f( a
bool operator < (const sItem p2), a7 m* [1 O% l) _
{
+ s ^0 |5 y# F6 t& M9 ^+ c if (dwKind2 == p2.dwKind2)5 T8 q) E3 c6 E% w1 \
{- B: n) M$ N+ O. k
return dwItemId < p2.dwItemId;9 _% U6 `" {9 r4 w$ ~
}else{
. ?: l) m9 p- M6 _% z1 N return dwKind2 < p2.dwKind2;
) H1 M, t L9 p) N T4 @ }
- |! ]9 o2 Z- _2 y6 k: b}
2 ~) {6 d8 O9 Z/ p4 d- ^};
: U/ ?( Q3 L6 Q$ h1 T, e: M/ C3 Wclass CInventorySort
; b! i7 ^+ }* N6 f; `# Y{( g" r. ]! S: p" b
public:$ G) `9 E- p, y! h/ q
CInventorySort()
% ]" C" X' u' c* @! j+ @{; F: j! k4 i2 |8 V& N9 N
m_dwPos = 0;+ _ I0 e7 j' f: R7 P7 D
}2 x& Y X; q# H5 [; [/ Z
~CInventorySort(){}
( Y; D, V; L! }/ \private:8 Z) [: R# a! |
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息/ R! e# ?1 ]; f* d. p: D
DWORD m_dwPos;6 k2 \6 H6 [7 I2 |% x
public:
b1 H' W0 c; N7 ^void Add(BYTE nIndex)3 A: u5 h1 D6 n/ p8 i' S
{$ l; |+ L( z1 m; ?( n# H2 K
if (m_dwPos >= MAX_INVENTORY)
4 P2 g% m6 p" I; ^) t6 Q {
" |, h, Y. Z* C4 z' ]; X' _ return;! j. `4 S8 w: N |
}# Y$ Q/ b! ^- c% }$ H O
m_Item[m_dwPos].nIndex = nIndex;
) H5 B, `* G1 u; O F& ?1 d$ B& r m_Item[m_dwPos].dwId = m_dwPos;+ E7 O: q9 w1 Z g; B
m_dwPos++;
4 W+ r1 ?! U! `8 J" @6 @7 c" Y}
) `: k8 I# I, [& j7 }* a$ vBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
" C% k' b+ p6 A& t{# N9 D! _0 T. R1 M, @, t0 C
for (int i=0;i<MAX_INVENTORY;i++)
8 r+ j5 Q* o% b7 q. l0 P; m; G {
# {6 N8 L+ ]% J# p6 |, s p if (m_Item.dwId == dwId)" z* u# D/ N7 T1 L
{
b. H& y" U: T2 @+ R return m_Item.nIndex;
( d4 K, q0 t. |, }5 j }$ {9 P8 z( j7 E$ P* E
}
/ a- l. S, W; [1 K5 Z: x return 255;
2 z. E# o& @+ _9 d( C% F4 r}/ V5 ~* v! y" X3 ~- M
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
* V& h) W# P. n+ `& u" ~{; X5 A- O1 s! L- | d
BYTE nTmp = 0;: [5 w4 n: \8 E
bool bDest = false,bSrc = false;
# g- `: H8 o G# L: n, G ~ for (int i=0;i<MAX_INVENTORY;i++)# a' p r; {: C m# M
{
8 x3 O: q: Q6 ?$ a! t if (dwSrcId == m_Item.dwId)+ s3 D( Y: _8 g$ u8 R K* q3 ]
{
4 G4 d' z5 c0 w% {( {3 Q( k* Z //id相等 则 改变对应的dest和src
7 ]6 o) u6 s4 p# d nTmp = m_Item.nIndex;1 g" n y" v( B2 W" Q$ c7 t% \) ~
m_Item.nIndex = dest;* y# g1 F) f& y6 C) Z
}6 x3 H' h4 }2 }5 ]! Y& j: o7 ]
}
; U) Y# F+ M% T* ~7 `6 T; K! ?: a //临时数据保存完毕,交换开始
I c0 q X+ N' g$ ?2 c2 p for (int i=0;i<MAX_INVENTORY;i++)
) t8 c; H% F3 B$ ?' J: G3 B {
" I3 L0 g4 p0 j0 m3 [# t$ V7 \ if (dest == m_Item.nIndex)
; z5 i6 h9 I& E8 R x2 W6 c {
1 V4 `7 X# C$ a+ ` //id相等 则 改变对应的dest和src* I4 |; T1 q* `8 T4 F f$ u9 }0 _
m_Item.nIndex = nTmp;
2 x$ _5 o+ q. ~- R- M }
5 ? M6 T; [" Y7 U0 o }8 S9 O- ?% D0 Q% |. @! U9 W
}
8 Y9 L* b+ M6 B* w% o4 i' L};
0 r, a9 f* X# |6 ]* v( R; a' |-------------------------------------------------------------------------% h, o3 O" b2 C- \. Y' d; M) Q
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
+ S$ h) N4 T u/ c搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
5 a# F) p, U: P5 }- R* f紧靠其上添加:8 N: ?2 e( \# @
if( pWndBase == &m_wndMenu )* U; p5 r# N" W
{9 D) c1 L* u, D8 G: p$ G Q
switch( nID )
9 q4 }* j. d8 B4 [- m, d9 [8 d6 y {! @' n: Z$ f3 t6 C3 X; j' c. k
case 2:
{% B# p8 d% p% Z `5 q: y& r) Z {' x& i- H8 i+ |2 Z% K" E+ [
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);; A5 J$ ]4 d5 E5 f% `3 e- M" K
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
1 L0 A m; z) Q" v {
! ~, }* Y( }+ r1 v- F/ c break;
. p C7 t0 h: v4 l8 A }
8 b; L8 R& M7 F6 u' K& r' w for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)) q2 m9 C( e9 Q, F; R
{* ^; o# X$ Y4 f! b0 w B/ y
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);, U3 a6 w0 f `) a' m, o
if( !pItemElem )
% m$ J$ F }: {( m continue; o. W" W8 _5 P- R1 }% g
if(pItemElem->GetExtra() > 0)# R& h" m* b( z; Q9 M: K0 B
continue;
4 L* w& s8 Q9 ]4 g! O5 K: C! l4 @ if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
$ \5 v- d' f9 X8 x continue;
/ k/ x, Q( P' p! R% h. J+ k if( g_pPlayer->IsUsing( pItemElem ) )5 H0 _: y) r; r4 j5 ?
continue;/ ]' I K% [8 u6 j5 {
if( pItemElem->IsUndestructable() == TRUE )& ^8 m4 t3 m2 z) q1 c# E: Y4 P
{5 f) F9 | S- C8 f
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );8 D5 B# f! U$ Q: P j
continue;
% i, \4 A: n- {% j5 I" a" z' p1 i7 d }
& `% L% Q4 z. i3 y# \ g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
& W7 ?, e7 V: U }
6 W' ^3 R$ i% f6 W7 } break;- n+ d" Y+ {$ x7 `
}! l- C3 W: }+ @7 p% p/ I7 j1 L% S
case 1:
0 W- s6 D! Y) u2 w$ G" ]: n {
2 N- i! l7 v8 E2 P, O) y //整理背包
; l: F9 C+ h s5 \7 ]) X //////////////////////////////////////////////////////////////////////////
8 Z H, U5 A* z* a //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
0 V& _. i& J0 F" l& m //////////////////////////////////////////////////////////////////////////& [/ D1 V$ R: ]
//////////////////////////////////////////////////////////////////////////
$ }* p; a1 {1 v0 g CInventorySort* pInvSort = new CInventorySort;
* @9 u6 v3 D) R- H6 B4 D. N5 Q# M vector <sItem> vItem;/ S0 L: F2 R% X
vItem.resize(MAX_INVENTORY);//初始化大小 M! {0 _- c# K7 e" o) D2 z
//////////////////////////////////////////////////////////////////////////6 d) ]$ l4 \( L$ {
//填充数据
5 o. M, D0 U5 ?7 U" o9 r for (int i=0;i<MAX_INVENTORY;i++)) j. P% L5 [" ^: c+ M' [! L
{
% O6 q* H Q2 i/ `( B9 M! { CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
5 M3 Y. U1 s7 C- t7 R if (!pItemElem): S) Q( G `: v
{- R6 E1 C) O) ?% N: E
vItem.dwKind2 = 0xffffffff;
! P' g( S, S' [+ g# A+ e) i vItem.dwItemId = 0xffffffff;
$ s- \* x0 n5 W% f1 y vItem.nIndex = i;
! p3 R& F3 [$ l( c }else {8 U% T2 m/ ~" @" [
ItemProp* pProp = pItemElem->GetProp();
( z. m" O: D. M, n' U7 r vItem.dwKind2 = pProp->dwItemKind2;
G! Z( Y2 H! E/ H. k9 T- i vItem.dwItemId = pItemElem->m_dwItemId;
* F7 B& [. q/ R+ L; I vItem.nIndex = i;2 p5 M! j; T8 f
}2 w" Z2 H; O) D7 m, t
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
6 j+ ]) ^, c R5 _, H, r6 f }# K4 g4 n8 M" Q8 |3 j
//////////////////////////////////////////////////////////////////////////4 Q4 S* D3 t& J. {0 m, I9 \
sort(vItem.begin(),vItem.end());//排序
; r: @: U7 W' ^4 }' E9 o9 F+ R; ] //////////////////////////////////////////////////////////////////////////
; w0 T7 R+ w9 c* _6 l //交换; U) U4 Y+ ?# L" T
for (size_t i=0;i<vItem.size();i++)
2 A, c# s0 Q2 C! [( X9 o B {
6 M1 n2 r+ R# q2 i$ v //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
% J- d$ F+ R; z pInvSort->Add(vItem.nIndex);
2 y/ N& j0 d. i }7 I1 S9 Q6 g" ?$ j
BYTE nDestPos = 0;
. O5 z: u& X# N9 ?- Q for (int i=0;i<MAX_INVENTORY;i++)3 i. d7 S' L: ]
{
- v, l `- Q3 x8 C8 l7 ~- h CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);9 F. ]' h# d& }- a. m0 Y
if (pItemElem)
# @, p, v5 y/ B8 W/ A/ U0 T; ~ {5 w6 `* j3 \3 i
if (IsUsingItem(pItemElem))
$ V' v8 V) n5 { k) E {
8 }+ q- i" ]2 c; E: r& i- K& U% \ //这个位置无法放7 P. H: n* H; i
nDestPos++;
/ J2 F$ p* [0 Q% h! K }
9 N: y& |( C; T, L }5 u! e! y1 W- K p. P1 ]
BYTE nSrc = pInvSort->GetItemSrc(i);+ C6 B8 K6 Z5 E) X% H
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
* Z$ K4 @% W+ I- x4 v8 \8 U1 t if (pItemElem)+ [4 f9 t6 j* C, a: J$ @
{
2 n7 n# E0 a2 s h6 i: I6 l if (IsUsingItem(pItemElem))$ t5 B% `/ q* [
{+ K0 m F9 `* s9 H
//这个道具无法移动,跳过" B7 n j& {9 [
continue;
- l: ?) }6 O7 b' J D }
: _' e. P/ f0 r2 T7 \+ K }else{6 \2 b3 V! K* F, ]% A+ m( G: ~2 |
//空位置 不用动
e/ ~- j3 ]/ {2 W& z+ z continue;
, c# U1 P; U% ], `$ a% i; Y9 Z* H8 K- f }* L- x, w/ d0 y+ o" s
//////////////////////////////////////////////////////////////////////////
3 ^8 I: k6 | b' A //开始移动7 J w {# i) M/ w( c9 K
if (nSrc == nDestPos)
' B% a- z' C" p; _+ ^) n {
: j, P0 H" ^ j //原地不动
' l3 D4 A: E$ C4 D' O" W nDestPos++;
* B' z9 g# t/ ] continue;4 ?5 e0 t" m0 `5 _8 g
}
1 Z0 e' C5 U6 i; Z! h/ g- c pInvSort->MoveItem(i,nDestPos);/ ~* Y! p1 m N# f& [1 B
g_DPlay.SendMoveItem(0,nSrc,nDestPos);9 h$ i! @$ K1 {+ B; t; h1 J# b; o
Sleep(5);
! g5 D D; u- O' w+ Z //Error("移动 - %d->%d",nSrc,nDestPos);3 u6 S' I- p, G% ]; J9 g
nDestPos++;3 ?4 N) ]- o7 d
}6 Q# h/ L2 s4 m3 N0 s
//取第一个元素的信息
5 f* _$ S# V9 C Z" x$ | /*4 q6 e* ~; K+ D9 Y# d3 L* `
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)' Q( n/ b, ?' S1 y& A
{0 b2 }- C$ Q3 l- h9 t) W; ]
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);' ~; ], b% v& |; a
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
/ m: J* q# r; i }- Q9 x; [; r) O
*/! F/ v: m/ r5 T
//////////////////////////////////////////////////////////////////////////) O2 {& z: [* J8 K3 d
break;# K2 J! D# I+ R& [2 ]6 E( x+ Q
}
6 ~$ f1 U" x* P3 V! ~, H } % w! c; D) I! D& c
}1 z& @0 z( c5 }' z! H
m_wndMenu.SetVisible(FALSE);
( q4 m1 c, ~& F: k8 l6 F, A* s0 O; y* y6 H
--------------------------------------------------------------------------------------------------------
, l+ m Q/ s8 } y% I搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
; o, ~0 C7 ?) ^: X5 n{" t# N" G1 p% R+ ~* `3 d
BaseMouseCursor();5 I; J" m! y7 [! T) t
}
' J8 }( C5 Y, U/ W3 D1 L. x在其下添加:
6 \' {4 m1 ?! l$ [2 U& Zvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
6 ?; I3 `) f- Z{8 Q9 ?" j" |8 B
m_wndMenu.DeleteAllMenu();6 h: v3 V# Q% Z, L1 T
m_wndMenu.CreateMenu(this);
5 n M; L2 X8 W* q# Lm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
( {9 T; e& f5 b2 R' x+ H
5 y+ e' { ^ iif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))! s: L$ @9 a7 U/ m$ f
{
2 f& i& Y# k+ M1 H* } //P以上级别才可以删除所有道具 c8 t2 F. {" N, ?
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
4 G( t+ c6 j- Y+ w% g0 j1 O}
+ q$ a9 h, b- Y* I7 k! X1 Nm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );! z5 x4 ^% {' @ a6 `: v8 _! ]6 r
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
0 Z" A! K( t; j0 s8 q/ lm_wndMenu.SetFocus();
% K" o6 u+ l8 @9 f$ f( Y$ E6 ]4 @0 o}
2 y6 y2 a" z3 H1 h( ^ y: ?; ?) r------------------------------------------------------------------------------------------------------------- k& M: \4 [! Q C1 h: E y; W2 a
*************************7 k: [; V+ ^& z3 \! M2 g
WndField.h文件% x6 M% D6 J: C$ d: X, W$ j
*************************
. Y6 X" ~8 N6 \; _0 s+ w搜索:BOOL m_bReport;7 O1 \& w }6 N! b* x
其后添加:
7 q+ T& n7 }5 h; |CWndMenu m_wndMenu;
# X* ]7 e. P( l F3 D( y搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);4 S, ]! E+ b- @ i& A; ]9 M
其后添加:# \6 G/ Z, t' n0 b
virtual void OnRButtonUp(UINT nFlags, CPoint point);" d9 f9 B! ] |, a4 e
- R5 X% K: U) m0 m/ D+ u% W7 P. Z- }' A( b
|
|