|
|
源文件中_Interface文件夹下WndField.cpp文件+ K: G! {+ e6 b8 h
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
. N5 u0 ]8 E; e: R/ F7 q% S, Y3 c" n% Z& }- `
struct sItem/ a% ^" L, m4 `8 P& p2 s" k% n
{
5 O6 V# Z1 n+ J7 w- I! `8 VDWORD dwId;
M+ k7 C7 H0 W/ hDWORD dwKind2;
* a1 p0 k0 _0 v, N* D5 X% cDWORD dwItemId;
+ a* d7 F: y9 m$ E3 z. d+ E* FBYTE nIndex;0 s5 c2 f+ D. {* V$ c
sItem(){8 o3 K$ Z- S: L; f, h, d5 h2 U
dwId = dwKind2 = dwItemId = nIndex = 0;- e1 E. J& `# } d$ m5 [
}! w8 H1 [/ Y' H8 C/ f8 [
bool operator < (const sItem p2); q% o, |4 R: B. Z5 D: l5 M* m+ b6 _
{+ y2 w: z7 X; u/ u
if (dwKind2 == p2.dwKind2)
* @; }7 a/ ]- _/ o% g: c5 u {4 o% a8 a) E( c6 H5 R5 ^% K3 k
return dwItemId < p2.dwItemId;
/ K1 Z1 m' h; E# s. a" V) m }else{$ p2 l( U# T- j2 b
return dwKind2 < p2.dwKind2;
( x3 b1 a% P' C$ h }% o3 f* u9 H9 Z
}
( c4 K! C# f$ d+ D/ f};
$ M* }% X+ j/ [' o+ i: zclass CInventorySort
+ S# ` n2 z% g' m) |. E# a# x$ a{, b; `% P7 o4 E; V% Y
public:
7 E8 l/ b9 U+ ~( ^6 NCInventorySort()
' M4 h T, f2 e! @' c6 q{* m* Z/ t* j) c: M
m_dwPos = 0;$ ~8 B( H! X' E+ }2 x
}
7 A6 h C0 i; _; X8 K6 ]! z~CInventorySort(){}& f: L, J7 ]' ]! h5 p
private:
- q8 i5 v" |% F7 j9 ^4 ^sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息, b; e7 T( ^1 H3 u
DWORD m_dwPos;
0 h$ u& B3 N5 J) r6 \9 ppublic:
$ ^4 e9 T6 ~# J+ Cvoid Add(BYTE nIndex)
; c) @ U1 |6 C4 _7 v{
, D7 i- S: o/ M. @9 s |* _ if (m_dwPos >= MAX_INVENTORY)
) U8 Z- h2 ` |3 H! _7 y2 _ {0 W- v6 s. b8 w8 N; a6 U- b
return;1 f6 f* X# n0 I
}- ]5 F- M: ?; s! x' F' W6 C2 e
m_Item[m_dwPos].nIndex = nIndex;! h" R) q" m2 L d
m_Item[m_dwPos].dwId = m_dwPos;
% ~9 X8 \- @9 L9 U m_dwPos++;# T+ d, e9 n0 \& ?7 I! ]
}2 H5 z8 d9 g9 A: U5 \# n& }, C; N
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
, J5 d4 m1 N8 y{8 s6 f: F9 y' t0 W8 ^/ I
for (int i=0;i<MAX_INVENTORY;i++)* P, _7 v( {+ z6 x8 y% H! {# O
{
( L1 b- n5 p, n ?7 o if (m_Item.dwId == dwId)0 ~2 k ~ u6 B% X o
{
* \6 t9 {. t( N, I K, U$ D return m_Item.nIndex;
! l% l: ^+ e6 I }7 B: w# j E) G) _' ^
}
# r( V. W" u9 V$ _7 \ c: ~ return 255;
/ e0 g' i# W) L1 z3 R1 X}
+ P6 C: z' B3 w4 d1 Z1 U+ v9 }3 ivoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
! ?; j, X! \$ z( f: h5 F' o/ |5 [{. w6 g; J* E2 V% a
BYTE nTmp = 0;
0 C# v H5 H" D- @$ I bool bDest = false,bSrc = false;
) G( q' R( E: B b/ M9 ^: k: s; L& ^ for (int i=0;i<MAX_INVENTORY;i++)
5 ~* }$ Z& N; o: g {
1 w+ n* X S! ?5 K; H* f( g$ E if (dwSrcId == m_Item.dwId), y2 Y$ H7 W+ l; G. T
{
- o9 |/ j# ^5 {4 H) X2 _ //id相等 则 改变对应的dest和src
; }$ _% g9 Q: J& |/ g ~ nTmp = m_Item.nIndex;
, L! P' @4 \2 X m_Item.nIndex = dest;+ S& r( B9 M2 [& L- y) G. ?, _
}9 W1 \' E: b$ l0 t# l4 i) r
}
; i- t/ _2 _* K: b //临时数据保存完毕,交换开始
$ r1 W Y7 b% [# f for (int i=0;i<MAX_INVENTORY;i++)
- _9 }% o I6 |1 U/ E! `5 M6 {$ l e {' ?! G+ ~" N: b7 \9 K6 B; P
if (dest == m_Item.nIndex)- F) t4 b6 v$ X0 Q$ H# a
{* Q2 T; _7 c' ~& ]
//id相等 则 改变对应的dest和src5 ^+ }+ R- f: B9 s/ o
m_Item.nIndex = nTmp;
" Z* h6 W" P! e }: L9 t$ K6 i- x5 B' A; u
}% Q. w2 o! z) o; _; N2 {: e, J
}
, y+ ?" m2 k, {. w9 |3 H+ m};
3 ?" N4 ?- y2 H, c" O& m-------------------------------------------------------------------------
0 L/ v3 d" N' ?! m依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )0 S2 g. I! Q6 h6 E7 ]
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
9 W$ r9 `2 E1 q1 x9 B) F紧靠其上添加:
9 Z9 e+ |+ O# [ m. D) hif( pWndBase == &m_wndMenu )
9 q& e7 ]% k& u7 [3 A, Q9 U4 m$ S, H{
' }+ e) l3 U6 t7 r+ p: [( G6 w7 K switch( nID )
. e% a1 n/ N! d- {) k4 L {" t9 e7 N+ L% l! k o6 E5 Q
case 2:6 V) K' @2 Y% o! z1 R+ C- s
{
+ q3 Q- M- ~. z& `( Y //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
, E7 X/ c$ W) i5 }0 @! i( } if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))2 B! ~# S# `1 |! F0 N3 L9 q
{& y6 |- b& w( u8 } u6 r+ f* {
break;4 o$ |9 Q. q% J6 V
}
6 L5 X7 n& T a) f9 c$ b for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)5 g$ \( E& Q- S
{. v+ A- N' a9 J
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);, V1 _2 y% J% @" o
if( !pItemElem )$ a0 w& I, Z( d2 N3 p- a
continue;: H6 J8 L* n7 H/ F( |# Y3 f {
if(pItemElem->GetExtra() > 0)* o) k& P9 @8 H7 |; V/ k, j4 A) d
continue;2 F! S9 q& k9 {" v
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 5 d1 T+ ^) }! P
continue;
; t+ y o8 k9 x; l+ P/ V if( g_pPlayer->IsUsing( pItemElem ) )
0 b8 ]$ P( ~* [' c! [* ?/ L continue;
5 l/ w1 K4 N+ Z* ^! G if( pItemElem->IsUndestructable() == TRUE )
) _2 y3 N2 }% v0 r( @3 h4 J {3 e; _3 _" u5 @* S, |
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
- e- V { }: N3 Y8 j8 B continue;5 e& Q' W1 K7 r- A0 J$ Q; U; i6 i
}
" u# d4 T2 u( d$ J2 l9 T7 y g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);) c" \! j( ]* j
}$ \, l# {9 m! P9 ^" T! H% S) O8 A! g
break;2 ?! b0 |% i3 @! ?5 Q
}
: n: {6 X+ `- H/ `# {2 ?" t" C' t case 1:; \ I3 Q- g- p
{
3 t! }. ?; s* [) J //整理背包 [2 ^" u7 b7 x/ x& \$ K1 e( T
//////////////////////////////////////////////////////////////////////////
: q! `0 E/ b* ]; m //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
" O9 q2 {6 M* j //////////////////////////////////////////////////////////////////////////
; C/ u" u1 ~" d3 Z2 h; q; H //////////////////////////////////////////////////////////////////////////
' |7 b* ?/ \' x) y' G) M- @ CInventorySort* pInvSort = new CInventorySort;9 |: j$ K. Y3 T3 l0 ~
vector <sItem> vItem;9 v8 [7 I; @% V1 i
vItem.resize(MAX_INVENTORY);//初始化大小
: H D6 u$ S& t& H7 P n //////////////////////////////////////////////////////////////////////////5 r, G0 X4 k! @5 v9 O, `. r# c
//填充数据
! O' h* Y2 H5 Y6 E% p ?" ~ for (int i=0;i<MAX_INVENTORY;i++)
9 X; I/ M/ w! H+ p { R$ R! C: v8 k( W+ d+ P* g
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
# S! f. A" ^) g0 {9 a* Y# Z if (!pItemElem)( M& U& i$ j& M8 b# ?
{1 p4 ~, k6 c9 K3 w! ]
vItem.dwKind2 = 0xffffffff;; g' v- ^+ N& Y: a& s% N8 M
vItem.dwItemId = 0xffffffff;
: d) x8 v- _! K ~# z+ u( s% M vItem.nIndex = i;
$ n, [+ k4 {5 N* ?+ s }else {' F. D: e7 }) k4 ]+ J5 K) E6 `8 G
ItemProp* pProp = pItemElem->GetProp();& R8 [3 ?+ H* w" X S
vItem.dwKind2 = pProp->dwItemKind2;$ \0 W% Z3 [" h6 K& S* {# B+ O
vItem.dwItemId = pItemElem->m_dwItemId;
/ p. B/ T4 o0 O' O vItem.nIndex = i;- Z2 S0 R3 ^, U
}
4 x/ K, A0 P4 L4 ?9 A$ \ o. ` //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);5 @$ ^$ p3 e& E' ^
}1 U+ E. `. w, Z6 B6 o& U! }! f
//////////////////////////////////////////////////////////////////////////7 i5 \+ J* T% W! d( q" h
sort(vItem.begin(),vItem.end());//排序
; e& o; z! \1 F0 f% X$ y" E0 ^ //////////////////////////////////////////////////////////////////////////
! C& W+ f# j* U. R8 z //交换
' `9 U' _# m: E5 J/ s9 O for (size_t i=0;i<vItem.size();i++)
% x: o8 r g! R; \! U( j7 l {
A x" D u" y //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
, m3 j3 K) @- Y/ B9 i ? pInvSort->Add(vItem.nIndex);
, K* f5 m1 \; n2 G' [3 f }( e% {, E& `) X5 d" p
BYTE nDestPos = 0;
D: A! n8 o {) M for (int i=0;i<MAX_INVENTORY;i++)
0 x- ]8 Y$ W$ z0 H$ {6 }% o {
8 J; q4 i, e8 ^, Q o) X! g' m CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);5 l$ o3 ^3 n1 P" T
if (pItemElem) Q/ S1 C% q8 w4 x
{+ I; ]8 K( t* P& i6 Z
if (IsUsingItem(pItemElem))
$ _) A1 o5 L. L {
# r# B! L( \, u& O6 v/ | //这个位置无法放
9 `- |) t6 R1 N) V nDestPos++;5 a9 ~3 t/ o6 f* a
}
+ G8 w+ b- E. c. d$ X7 H. e }% w! j% J, b9 m3 C9 p1 A
BYTE nSrc = pInvSort->GetItemSrc(i);) e' `3 Y9 e5 }4 e
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);1 p5 e7 _0 k: a- I0 ]
if (pItemElem)
9 t3 R* O- A; f3 U4 @ {
- _! h" Q$ L+ P, I: M8 p* n, F if (IsUsingItem(pItemElem))+ J* }; P& I3 }/ a, x; x
{* L4 Z& E9 L5 d2 X. s8 A, C
//这个道具无法移动,跳过
1 b. L+ W- ~3 G: O1 H0 l) }% C( m continue;
3 }4 w1 V" s+ v }! E7 }- w) |, z9 o
}else{
7 f! t2 D9 O3 {. a( F; f( t" e //空位置 不用动
" G2 h. z* S/ u8 ~' }6 C8 E continue;
9 u0 j# R! N: Z5 ?, p% s }
5 L% E7 n% e/ ]( k1 j/ ^! S) A- q //////////////////////////////////////////////////////////////////////////- J8 W, K2 f1 D: c( |+ u) m5 E
//开始移动
0 Z7 m) p& r; @6 a$ e- Q if (nSrc == nDestPos)* p r) ^+ L2 ^) s
{% N7 [8 ^$ o3 f
//原地不动
2 y3 j% w" B g6 @( ?6 u nDestPos++;
" P1 [" ]8 X/ b: G% J+ g continue;8 }3 w0 R2 I' W j% q; B8 r
}0 `. A g; S5 Q# s' H: E6 {
pInvSort->MoveItem(i,nDestPos);7 L% n5 p2 n6 u. j, m3 A2 j
g_DPlay.SendMoveItem(0,nSrc,nDestPos);: f6 f' m8 [3 t( D9 y4 W- m1 r
Sleep(5);
/ z- H8 n* s; o& a* Y1 m- R6 I //Error("移动 - %d->%d",nSrc,nDestPos);
* D( X7 E: k7 J& @3 o e nDestPos++;4 U$ M4 Z4 O) e7 H# A& U, [5 G
}
# T; d9 }+ _$ ?# Q4 n7 ^ //取第一个元素的信息
6 q: l+ o! q2 c2 H. L; _0 c /*' u+ w- p% v5 H+ @# [; a0 a
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
* E% ^3 A' J4 }2 u" S6 P {
* _2 q: Z6 R& m* @( x: `: [' G Error("Move - From:%d,To:%d",vItem[0].nIndex,x);7 f3 ~+ p5 `; [ ^4 n6 Z
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
+ X, @6 |; ^# N" b4 t }) Q6 _3 d+ e# }
*/' @" C2 N+ x3 \# E o5 A- Z
//////////////////////////////////////////////////////////////////////////: x" v. ]; {) i) k' P
break;( W# T2 T G5 s `& {
}! j9 V& U3 r( M4 s* r
} ' \1 E3 j7 ^- |0 G
}
) o7 y' z G: b9 dm_wndMenu.SetVisible(FALSE);" _. U; K8 J+ ~ k
( T/ Y) }: i( ] R
--------------------------------------------------------------------------------------------------------$ p: Z' K+ D' `. N2 G5 r! y
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
0 x+ \5 l( V: [& B1 Q3 g E{7 i5 J4 Y5 n+ J" j- S! J# [0 K
BaseMouseCursor();9 E1 c$ }7 W P
}4 a5 ^# q4 Y2 `& C2 K+ D( n) c; }) [
在其下添加:" J/ A3 E2 K: {
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)' K" L6 V @, ^ [' g! Q
{
- T- ?: R6 ?+ n/ Wm_wndMenu.DeleteAllMenu();
* Y7 n# k' j3 j) d: c. @0 b- fm_wndMenu.CreateMenu(this);
8 y5 w ?% F% a) p0 Ym_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");3 W0 Q; w+ v# B! Q) r4 P8 m5 b% x/ U( D
" u4 ]- R5 |4 G) ~3 n6 P' W
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)) N" ?. S$ p4 b7 n+ ~
{
0 S3 e. ]' z. g( i //P以上级别才可以删除所有道具
8 \ p g/ U5 v9 m m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
/ X& l/ L- r/ e8 D7 C; q}
+ K1 b9 E# [& o+ B2 Em_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
3 g9 o, @% J, }8 x+ a% o! em_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );) \% v+ S0 U# D I
m_wndMenu.SetFocus();
' u* \/ f/ l* v/ r$ g! ^: Q}
, b- y( @5 p+ V( c3 y8 Z3 [------------------------------------------------------------------------------------------------------------
P4 t1 q7 c4 i0 ~1 A+ b*************************: ]0 {: L% A2 l- ^, e* ~
WndField.h文件! h+ A& g, }5 H2 n3 T
*************************0 H. `$ e: E9 l# {% \1 G3 A
搜索:BOOL m_bReport;4 O' Z0 B4 m! N1 G5 n% H5 G
其后添加:
4 N5 W, F) w' TCWndMenu m_wndMenu;+ q, r6 K0 s! v5 S( m* ^
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);5 n w! l4 l$ k' Q( i* ]
其后添加:
# O7 w9 Z# q! f8 C$ p, `virtual void OnRButtonUp(UINT nFlags, CPoint point);
c0 z x- E: V' @. V) {; B
% X. P% a, c# A% x
* @0 x {9 c' {9 d# R |
|