|
|
源文件中_Interface文件夹下WndField.cpp文件; k$ H0 ^9 L3 k: j
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ): N: B& r# d: {( _+ D
2 t l% I$ s9 Y; d& f6 Hstruct sItem
% \, U T- K6 f4 R: c' K) G0 \/ T% M7 I{7 @8 \; ~6 t) N! b- P
DWORD dwId; h- j5 v- ^) K% B9 S
DWORD dwKind2;
- |# S" m; z/ z3 u8 zDWORD dwItemId;$ S2 ^* E' ^, @4 x
BYTE nIndex;( u- ^# z4 L6 B4 x L3 ]# d5 Y
sItem(){
1 A' { E# V m" @% ]4 F dwId = dwKind2 = dwItemId = nIndex = 0;5 ~# n7 j' O1 `, a) l
}
) D- [ J$ Y% X$ l$ g& \1 Nbool operator < (const sItem p2): q! d" B8 T9 }! z
{! W6 b6 m: z& G+ V$ v
if (dwKind2 == p2.dwKind2)9 c. _0 z' g' |0 S
{
4 p9 D$ D6 l D7 X$ s' {1 v return dwItemId < p2.dwItemId;
1 Z0 a! a6 Y# F# l3 R" U- P }else{
$ K8 K ], \# {. `- L8 f7 w& i, B return dwKind2 < p2.dwKind2;$ O) E; U0 N: {4 \
}
' u/ r4 b5 W2 K" {' `}( Z, B6 I2 M: o: n( \3 {
};+ V7 E0 l6 l9 I$ o7 I+ y" J
class CInventorySort. [8 O- M; l; W$ ]1 U( C7 D2 X; H
{: [' W) g" \: z4 \+ O
public:4 W( |. k& l3 e8 I: o
CInventorySort()
! w' O7 k( O8 A) D& d; u{
7 k- z8 r) j" X: R m_dwPos = 0;
9 s6 D- K6 H2 F2 B% @" V}
/ e1 S9 k% b! Y/ F, v7 c0 L~CInventorySort(){}6 Q5 j8 k3 l, Y! d
private:
0 M# U3 g, Y8 \ ?sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息$ B$ K3 j1 Q# u* u( I8 D
DWORD m_dwPos;
& V9 z* z. i, ^4 @, m) Qpublic:
- a2 I6 ?9 `" O" i& ~$ \void Add(BYTE nIndex)
; A. W/ C1 x' d9 q+ ~: X! D6 E{
5 M: J. F- s9 g if (m_dwPos >= MAX_INVENTORY)
. v, O! ~ v: n, p4 [0 F, Q {4 [/ h9 G+ H, }0 j
return;* }2 Y9 M& e# V" l
}
5 I8 u U% n* @: s2 ~7 _# I, B m_Item[m_dwPos].nIndex = nIndex;0 B0 ]# l4 j; z$ \- \6 q% w0 Y
m_Item[m_dwPos].dwId = m_dwPos;& r4 v$ b- |3 d* F9 e
m_dwPos++;
$ n9 x( I A4 v7 m% D}' @5 E$ _' R* S9 \8 W
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列* N: ^, `# E- |9 Z) q
{
4 r: l5 P& j* I4 t2 c1 g for (int i=0;i<MAX_INVENTORY;i++)
8 N9 R c' E# i$ c. O- n& I' Z {
1 a# } H3 j6 W1 v/ t; `) K if (m_Item.dwId == dwId)1 z" `! g5 Z: S2 [
{
1 f# V% O: J% Y Y$ ^6 D; C" t return m_Item.nIndex;
+ W/ f7 i: Y* k! u }" f* S' J3 P5 B' z+ {( E k
}9 b3 }* t, p, m0 A$ ]2 a9 J( o+ i! V
return 255;
, q+ e" w7 S0 j2 h) `}3 E7 Z/ f4 j$ Y: t4 L1 Z- D- _
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置6 `0 A. O, s) R0 d0 S
{- K5 l3 h- c6 C9 L2 c7 b" R) _! W5 X8 y
BYTE nTmp = 0;( E6 f7 b$ _. Y2 R& u
bool bDest = false,bSrc = false;
) t8 q' G( Z+ E* v1 I2 M6 e for (int i=0;i<MAX_INVENTORY;i++)
% f: Z) K7 e2 s0 _4 p$ A {
/ A; C6 w4 d* n# a! s% B! }2 Z if (dwSrcId == m_Item.dwId)# B7 Q2 p$ q5 U8 ~, j: q0 p' \/ c
{
4 j6 G4 g$ [" P; B- v, o8 E( P //id相等 则 改变对应的dest和src- j k7 o0 S j4 Q: Q6 W: S5 |
nTmp = m_Item.nIndex;
9 B/ Q% J* Q0 s# a+ H% _ m_Item.nIndex = dest;
, y9 r" t; y+ X2 N. A2 [' x( f; \7 f }7 K) d, d; V2 [5 o: c1 L
}
1 N. u* Z/ g2 V% c7 ` //临时数据保存完毕,交换开始$ i1 z- n5 W8 M7 D5 V- M% _3 q
for (int i=0;i<MAX_INVENTORY;i++)! m) V( t! u2 A2 n
{! g5 p9 v3 o7 _" f5 k, d6 z
if (dest == m_Item.nIndex): f& k6 f7 [0 [; A$ Y2 k) r
{
: i4 z- `4 H/ g$ V% L% f //id相等 则 改变对应的dest和src& x8 T! L! \7 Y" R
m_Item.nIndex = nTmp;
! m9 N# Q) Z+ w' \- I }% Q6 E" H$ e5 t+ s5 f1 o
}
: V6 p' s* a" V, k}- N3 r1 Y& D# V- i7 Y( K5 T _/ @
};
: M* q- b! \, p. h; D* [2 L-------------------------------------------------------------------------
" M( Q9 }/ S# J9 t, {- q8 d依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
$ W/ }# @5 N( B搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
# H9 V' R T* W+ r2 a紧靠其上添加:
5 ^5 \8 G0 h) W, o3 Eif( pWndBase == &m_wndMenu )
& s, W) x S/ T0 E{
- r' d+ q) H: R" E( b$ p9 { switch( nID )( ^( L( t: f: G$ X9 v
{
$ }) p5 m5 K% |/ N! B case 2:
; b y H+ R" q, a {
! S0 x; K$ B* n/ Q; a' k //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);( y5 {8 A& a! S2 j" N/ e- P- _
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))- x/ I6 f3 G9 U4 K% ?- F
{# X. D+ b$ Z& k
break;
/ M6 Y* ~% ]$ Q; T! N }$ I3 V: M' |; I/ |- e! M3 T
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)6 [2 ]! L+ J* c/ M' D# ^
{
* t5 d- I5 k# F! r CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);* {* m8 h( }# J6 z) k. F
if( !pItemElem )" H& @; q2 K, S$ [7 m/ P
continue;
3 A- q( G3 [( s if(pItemElem->GetExtra() > 0)
. r. j! S9 h& o5 q- d5 g" J6 H+ [5 {7 A continue;6 z; z7 K6 u! \# x7 X/ k! Y
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
2 M- V) Q5 [4 T4 d& a5 X Z$ { continue;$ w6 H* O: m5 ?
if( g_pPlayer->IsUsing( pItemElem ) )
- ^, v& h0 S+ m' B continue;
, d' J0 \9 H! ]3 R W; x if( pItemElem->IsUndestructable() == TRUE )
0 o1 ]9 X8 U; _1 K! h8 P6 I9 u {+ T C# O- z' o A- Y# U6 r, G" v
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );2 z# [% @) F8 E) n( n
continue;& x! s$ L% R2 g; T2 w
}
" B; ?1 ?9 s$ E* e* c$ P+ \ g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
3 j; D/ L8 s3 _( R' N& c+ G }7 D! J) q0 g- v# K% O# b
break;7 T# e5 P; L( V/ W% m
}- L S4 x0 T: U; q4 \
case 1:
! K8 p& p( y9 {' f( t% n& z {
$ Z9 t9 F2 G6 U! E! V/ ? //整理背包; [' b' z7 r4 W1 d
//////////////////////////////////////////////////////////////////////////3 f, L3 }8 I) M* @% J# c
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
% C8 F" ?, F* Q: a* W9 a //////////////////////////////////////////////////////////////////////////% H; v' ~* |' ~7 s# H
//////////////////////////////////////////////////////////////////////////6 p+ ?- X6 ~# z
CInventorySort* pInvSort = new CInventorySort;
- M4 N5 h- T/ V8 F7 ~. T; g3 _. M* u vector <sItem> vItem;* E. U$ s& N* j$ I! g! p7 U# D
vItem.resize(MAX_INVENTORY);//初始化大小
* b+ U- E. h; B( U8 c+ r, i" O# K //////////////////////////////////////////////////////////////////////////
0 B; D6 r. P, V' l //填充数据& s, I. V. [" M$ n( l2 h3 m
for (int i=0;i<MAX_INVENTORY;i++)
d, i2 y7 @; I( |+ u! x {
$ N& |8 G5 q( m: q. l: d6 |, S CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
, Z, N3 c# d) P) |5 T5 |- a2 J if (!pItemElem)
+ E- p5 [! i0 q; a {0 d' a* e& x! J3 x
vItem.dwKind2 = 0xffffffff;
$ j6 b9 _9 R4 F6 j$ H) ?2 y/ ]6 f vItem.dwItemId = 0xffffffff;6 g* W0 p# I2 X! E6 e
vItem.nIndex = i;, M3 s6 y1 ?& o2 n
}else {
: V6 n1 r0 O* g4 f) Y) v0 s5 k' n ItemProp* pProp = pItemElem->GetProp();
( i- c" M0 B* P& D* \! e8 I( j9 G vItem.dwKind2 = pProp->dwItemKind2;
/ Q, s. S5 ~& _' n vItem.dwItemId = pItemElem->m_dwItemId;* V. b- A$ o. p# p7 O1 L
vItem.nIndex = i;% C6 Q$ m- J) I( K0 B. n& C B
}
" N0 E) s4 J* N& |8 z& X m //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);, L X& ^3 _; |& a1 l
}
0 U; U; E& N3 [) y3 X0 P# P$ ?2 U //////////////////////////////////////////////////////////////////////////
, l: P* r3 @ [, J, i sort(vItem.begin(),vItem.end());//排序1 R/ R6 Y, [, R" o6 Z" I
//////////////////////////////////////////////////////////////////////////
% k4 L6 V1 r6 F7 f8 O; F/ e" V //交换
- `" p8 w b V1 B. E* j for (size_t i=0;i<vItem.size();i++)
/ \/ t" Y1 j! I {" V( {4 y% V* W* H/ `; Y S
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
' S2 ], _! ~- F! i0 r9 B pInvSort->Add(vItem.nIndex);0 {- h$ b$ ^8 M% T0 m {
}
+ Z ~ |% }, R- ^ M5 x! A BYTE nDestPos = 0;
& D9 |" T* f3 Z5 P' n for (int i=0;i<MAX_INVENTORY;i++)7 f# Z) o7 n7 g+ V5 m
{
. j7 H0 A8 i- S7 r* _% x CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
: o$ L9 V. l1 Z- p& ` if (pItemElem)- M7 v% E1 E: ~$ K6 c, v2 Z$ @4 S6 `
{
3 G+ h0 `0 Q' w9 B$ p% D if (IsUsingItem(pItemElem))* e0 D. O3 h1 ^0 h$ a$ d
{
8 J% r6 V1 ^& e! {, k$ d: ` M2 s //这个位置无法放
5 j. ?7 B3 S8 Q; c& C# Q) d nDestPos++;) n4 G2 b' G9 c+ w# `8 N
}
6 P- X, Y8 M6 @6 ~$ C. e# P }
7 l; o: X1 Z$ L( w1 Z* N BYTE nSrc = pInvSort->GetItemSrc(i);
& Q- u' f: m9 P) @0 [ pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);4 l, h8 M! ]3 {# A6 F$ S
if (pItemElem); v2 p/ o* C3 z2 V% d; r$ D
{
, u2 s7 b* ?9 b+ k% } if (IsUsingItem(pItemElem))
. g" b1 [% r$ f7 k& g {* ~: Q+ K( F. \3 q6 k4 Z
//这个道具无法移动,跳过5 c1 S. o5 X3 D" Z
continue;+ I4 t: |6 ]/ W0 `: t" ~: D
}
& T1 O" z6 ]# v3 C }else{% _8 l8 E5 ?2 m2 ^1 }. h1 F! ^
//空位置 不用动' }. }$ Z# s- w" I/ v) w6 T
continue;
3 W2 K. r5 t* @0 G ~+ N: y }% S, D8 ~7 b! y3 w7 u) S% t
//////////////////////////////////////////////////////////////////////////. |& ^* z2 g$ [7 G* r
//开始移动
' M+ K: t5 n8 ~) K; Z if (nSrc == nDestPos)7 j+ d6 [" _7 R9 Z- l
{
5 `6 `) i* [5 M5 S; ?8 R- X //原地不动: ]0 D% n% ^* K: b& J2 p
nDestPos++;
. W8 W \+ k9 H" M7 |4 B. y2 a; t continue;
, O* o5 O# f/ z5 V, R# \ }+ F. E- U6 e' m# `
pInvSort->MoveItem(i,nDestPos);
3 `4 g( ], u9 ?5 R L' k8 j g_DPlay.SendMoveItem(0,nSrc,nDestPos);( N/ E8 L w6 @& |' A
Sleep(5);$ x- H; [* D. T; K
//Error("移动 - %d->%d",nSrc,nDestPos);
6 j* N+ O/ k2 q7 m) `) U nDestPos++;
j- V+ n% V! w: e2 J3 m }* k9 p5 U* ^" V5 }$ J
//取第一个元素的信息
2 j5 w' H) ]4 ~- q7 W6 n5 t /*
8 `* e4 v' u; v0 L7 x if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff); R- K3 E2 \2 `8 W1 ]1 ^' L' a( d
{
% I! K1 ? {6 I! S Error("Move - From:%d,To:%d",vItem[0].nIndex,x);% |1 Z: Q! P/ |# `# n" S. J2 \
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
I: v! L) M5 {9 ]3 e! N }2 M# d" M2 b) G5 _
*/; A4 Q: ^' J$ l2 b
//////////////////////////////////////////////////////////////////////////
: `+ T) ~0 }$ j' I break;
! D2 n5 s/ }' j0 v- W7 ^5 ~8 F- w1 ~ }$ w' T; c3 g& ?* o+ M# u/ k8 _
}
* i6 Z A2 d/ O2 W" ~}, X( s- F! w' E0 G. K/ y2 K1 Q
m_wndMenu.SetVisible(FALSE);
3 f$ y1 \6 x/ G3 O/ s
; E: M c" ~% Y' y--------------------------------------------------------------------------------------------------------
" O1 I( X: T+ N& n* {+ R+ h搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point); N0 r" |; c/ @8 X0 ?
{
8 c/ C0 J- X( y# ^( SBaseMouseCursor();* f' |) ^& t1 ~* h/ e8 i
}/ w0 ?# g: o1 A
在其下添加:/ d7 h/ r7 |* h9 }! _3 U
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
( B2 D W9 t: h6 g7 U{
- p# v1 m8 J; ~m_wndMenu.DeleteAllMenu();: b @' p% K6 z7 k5 }
m_wndMenu.CreateMenu(this);( s0 l, e# l2 C2 H1 f+ N
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
" L7 x( }/ j+ v) y# d% J4 ?! w4 j& o- q, g a6 r4 }/ Q
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
+ }8 Q9 v0 J, \# }! |9 f, c; N, a; y{
" s$ @4 f( N1 E1 k) f) k/ W, j" ? //P以上级别才可以删除所有道具
( K' k6 V- {) ^- O3 Q m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
+ M7 z D1 Y. _}
. D2 n. P2 `6 u: q, N" K2 z) @m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
5 w- u/ j: Z: U$ H" f8 h. c! `m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
, S2 @/ E/ n5 w4 j: p& ^m_wndMenu.SetFocus();% b6 \+ |2 d* `, D1 v
}
7 z( j4 j6 T8 t X* R% N" A------------------------------------------------------------------------------------------------------------
% b# z/ W3 ^6 `( v6 s; N: t*************************
! R: ^* Q5 t) F+ a/ G; ^) }4 dWndField.h文件
5 R8 J' ~7 \ B! g) d( m: m' o1 F# F*************************5 p9 C% e7 g, J9 _3 W+ l
搜索:BOOL m_bReport;
' x; m2 c$ n0 \' j, V其后添加:4 e6 d1 J% i% @* K$ q" a5 ^ h6 T! W
CWndMenu m_wndMenu;0 B+ M7 d# p/ F% H; V; S- L
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
( ^5 Z0 O! J) F4 }7 T4 G+ Y2 e3 s其后添加:4 g7 _ t8 }& e2 s0 m: k/ A/ Q
virtual void OnRButtonUp(UINT nFlags, CPoint point);
' s8 O: V5 a/ u: x7 Q' Y4 J7 b. ?
! ?4 `( j# {4 p0 ~3 z
. M- p. r8 p( F( f3 ^9 z& ?1 ] |
|