|
|
源文件中_Interface文件夹下WndField.cpp文件
6 O5 K3 L! V+ s7 G搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
8 }6 D' d; X& ?
* w6 Z4 m% l4 estruct sItem8 B# R3 E/ F( ^7 U7 ~/ L f' p
{8 F4 ]0 a, D- r2 p
DWORD dwId;
" O8 a1 C2 V5 ]1 }6 RDWORD dwKind2;
1 S4 b- v# q* l; x9 W4 _DWORD dwItemId;
/ h2 h2 O% P6 D7 h# u% I! T% m- pBYTE nIndex;8 Z9 b3 ?0 u, R5 g8 T4 }
sItem(){
' d ]4 U) B$ I. T- a! z% S9 A! I dwId = dwKind2 = dwItemId = nIndex = 0;
0 g6 |6 X( P! O5 l- i}* C9 \+ I7 ~6 R
bool operator < (const sItem p2)
, B& W" [8 A) C; Y* b) Z{$ f+ O' i- p" B* V0 Y
if (dwKind2 == p2.dwKind2)
4 y1 ?: a( G( ~8 a; p. U: Q {8 J9 c7 E( {; O* u) Q
return dwItemId < p2.dwItemId;
% E. ~! j! h+ ] }else{5 b+ l: G( B( b. N2 ^
return dwKind2 < p2.dwKind2;- o2 @5 `, |3 x) y) \! ?1 u& c. S
}
, e: u/ I; M' j1 W, c}* }3 o$ M3 }/ G$ u u2 {' ?
};
4 ^/ H( u! H3 T$ q9 i0 Uclass CInventorySort9 x& L: O" k) S2 \+ ^% [
{
$ }0 Q* r5 I6 k8 _' X, z9 g# Tpublic:
5 V/ q1 Q9 e2 \* X5 Z5 [CInventorySort()
3 Y7 U3 g: b L; ~- m3 X{
- i8 H, n8 |- { m_dwPos = 0;' M% M# s! P# b0 ]* Y# }
}
% o% w% h( a5 }, v, @& Z5 l~CInventorySort(){}
' Y5 Y' \ }& ~4 oprivate:1 X+ _6 F5 v& i u U2 u5 |
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息) a3 T1 n0 E( L7 t
DWORD m_dwPos;
+ ^9 L1 J) [% s: b: ~4 M: v; _public:
A. T, h2 j# v' K) [void Add(BYTE nIndex)
( c9 s8 m9 d3 _! f; @. Z" k{
+ W7 M4 t5 _. d* R$ f2 Y5 h if (m_dwPos >= MAX_INVENTORY). ?) v/ R7 @2 h* O& L" [
{
- F# g0 i' g5 |7 x" l! m) W8 F8 G return;
% F& N5 Z6 r3 ^ }
! n( `* N' h0 W8 v; I" a1 y0 t( f m_Item[m_dwPos].nIndex = nIndex;, ~: m9 I* `/ O& z7 ?1 t$ g, S* G4 H7 W
m_Item[m_dwPos].dwId = m_dwPos;9 L1 l0 ^1 W0 N
m_dwPos++;: `6 m6 R* }* B: a2 v
}
. s# S" y8 V8 J+ B. ABYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列, e0 I4 [5 ~- b6 x, p
{/ P9 O# k$ g$ @9 M1 }. l
for (int i=0;i<MAX_INVENTORY;i++)( d* U P5 P3 C8 [4 s1 b
{
, J$ E# r9 K) R. y" v+ V4 h if (m_Item.dwId == dwId) [" M4 L: A d; j. D, o0 \9 N
{
, T! a: C# q' N return m_Item.nIndex;
- w) S: r+ w2 [4 E6 Z# \ }
1 J6 ~2 r0 I' t/ o/ e) j7 q9 f3 o6 e+ L }
8 J% b1 _% d6 {5 h* x U0 I return 255;
, L5 t3 s$ h* @ t# R}
9 f- o! l/ y7 Svoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置( |1 j3 n0 p, j' {/ [- e1 p
{
1 I, c* }, g1 L2 ^ BYTE nTmp = 0;
* O( ~& \, h, X5 H$ U6 p bool bDest = false,bSrc = false;7 f/ [8 Z" {# j3 a/ a/ e
for (int i=0;i<MAX_INVENTORY;i++): M0 e) Y( B; u5 V# Q% M) p2 K
{
: b: D' {3 [' p! m& n _ if (dwSrcId == m_Item.dwId)5 s P( x p+ J- n8 O4 c6 s$ @( g
{9 N! N% W1 B" T
//id相等 则 改变对应的dest和src3 [3 r4 g) m2 }* x( a' I) o
nTmp = m_Item.nIndex;0 p$ g. F3 r" N5 B8 y5 f2 a
m_Item.nIndex = dest;
! h9 u0 g! O4 K5 [. F, @ }6 O/ Q7 o3 ~, `: T* H6 {9 Z
}
8 w! f8 }- T7 e6 A1 E/ B; W. J //临时数据保存完毕,交换开始
A7 m- c1 {' { for (int i=0;i<MAX_INVENTORY;i++)
7 @$ z0 ^5 V$ J0 S2 e6 p, R) c0 t {' i" m4 Y( z$ W" v$ D
if (dest == m_Item.nIndex)5 t, C2 U2 @9 n) {
{
0 F. S$ s) }, {7 p; @ //id相等 则 改变对应的dest和src' [' I8 g' \7 B8 W
m_Item.nIndex = nTmp;$ p/ R' l7 B7 Q/ L5 D7 Q
}6 C5 L- n/ l c" ^! ^" Y) W7 [ p
}
- Z6 W) I) V, ]6 r; d7 d, F* f @}
& M3 I1 h* F, Y) H3 v1 b! b};
V1 {% i3 ]6 ~2 x/ S3 ^, f2 A" d-------------------------------------------------------------------------- y7 y5 X( m9 r* g. A- a( G0 S8 h
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ); V! R; ]7 f8 |( R; x
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);! U f8 j1 b" S3 C
紧靠其上添加:) L) m2 P8 g% W
if( pWndBase == &m_wndMenu )
! J/ o1 _' M& n/ \ h3 p" R{
0 B! e H1 _/ c) R: K7 M9 q switch( nID )( c8 Y% _8 ]& F/ L# l2 z$ k
{
" m8 M0 W+ i4 O3 X/ n+ N& g# M case 2:
" }, n4 V D2 Y6 ? Q1 m {
; ?0 V/ S4 z6 Z+ l" X* S% v //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
" W: \4 X6 y9 h if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
# v: q! G* E+ l) \, \! y {
% \, ~( z$ }6 q. A" W6 r break;) f' b6 U! a$ n6 A8 U- d0 H
}
2 e& P/ j* `- }) w) e8 F for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
1 i$ S! G5 U2 P" N {, ~# {2 X3 n* g, ]# L4 B3 j
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);. T8 W5 J, W( E0 B6 E8 ?) A) c0 W" ^
if( !pItemElem )
" \+ {) _9 k! h7 G4 p" n continue;
8 H o8 {0 T$ O) g# ^( ` if(pItemElem->GetExtra() > 0)
$ [2 z) x2 s8 V" z7 x continue;' s Y. ?- H1 z2 ^7 h6 a
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) % | w6 F/ w% J! d& p6 g
continue;
! t( M* h# W5 c if( g_pPlayer->IsUsing( pItemElem ) )) g7 q7 A1 \- ^9 V3 X5 r
continue;/ ^8 Y4 y/ r/ }" e
if( pItemElem->IsUndestructable() == TRUE )# C C" R8 ~ k+ x. Z6 y5 K% j8 m2 ?) z
{
" k" ~$ v: o, u g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
1 D+ Q% y/ X" A8 s1 y0 c( k3 B$ d9 V( A% F$ a continue;4 s' l6 o5 X: {8 c i9 p# v) o! `
}
+ S2 A5 h. c! @, }& {& Q g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
, B3 s- ^0 l5 g6 m# o5 Q9 } }
- d3 M& Q- D) K break;
7 Q7 C5 D |5 s* O. X$ h }2 B) b& v4 A$ H4 `" Z& S9 `- ?
case 1:
2 [$ b( t* _$ M! T {
0 s/ v! U c$ s P //整理背包
3 W7 B& O0 {: H7 c8 @% W //////////////////////////////////////////////////////////////////////////% r9 b0 `3 j) V
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );; ^' \- L4 w9 F9 W8 C4 f1 V
//////////////////////////////////////////////////////////////////////////
7 V2 E3 @! _& ~/ S0 ]9 c //////////////////////////////////////////////////////////////////////////
6 }2 M4 b2 R1 `0 r* c! b1 B Z# C CInventorySort* pInvSort = new CInventorySort;
7 I8 [, z5 _$ n0 l3 _ vector <sItem> vItem;
& l/ p$ n! }' { vItem.resize(MAX_INVENTORY);//初始化大小
% _: A: o% x( W2 ` //////////////////////////////////////////////////////////////////////////8 m, }& T+ ` C4 k i) q/ J3 k
//填充数据
3 b& w" b" W* m* z for (int i=0;i<MAX_INVENTORY;i++)
9 b4 ~2 N+ s8 G {6 @5 V3 |* J4 }: {0 a3 J
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
0 F9 P; a& M7 W: S3 V if (!pItemElem)
, g9 ^ F y7 I+ F' ^6 _) `8 O- B {2 v h5 {8 Y) F' I# P& r1 r1 z& {, n" J
vItem.dwKind2 = 0xffffffff;
. e( [! H; |. `2 x! V vItem.dwItemId = 0xffffffff;3 b! Y2 `- u- R; ~% s- G. W/ u
vItem.nIndex = i;
0 ^9 w6 R' M5 }' U }else {
; R. N# F* v! d6 B ~( N ItemProp* pProp = pItemElem->GetProp();
5 A8 b/ w" v8 Y, H# X vItem.dwKind2 = pProp->dwItemKind2;
8 d0 q( x6 _6 ^8 u' [+ l, s vItem.dwItemId = pItemElem->m_dwItemId;
) S' ?' A$ R+ Q2 D+ Q( z2 }3 ] vItem.nIndex = i;
/ `. h; J8 J; w7 D6 M9 {7 ]7 B }
4 U' V( `; W5 i. E //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);- ?& D% {" g+ M$ O6 A6 w" a
}
5 o. [( K- |- A% m; a' A* s //////////////////////////////////////////////////////////////////////////% ?5 ~3 k1 T( o" v- ?, G- S
sort(vItem.begin(),vItem.end());//排序. Q- H8 u' k8 R$ w1 v" Y% W
//////////////////////////////////////////////////////////////////////////
; d f; a. p: X+ D1 D8 M& l+ u' x //交换
" y$ G% |$ Q2 V- U! b+ @- h for (size_t i=0;i<vItem.size();i++)
, N/ `2 v. @9 ^ V; f$ `$ M9 U {
2 r3 b6 O9 ~/ {% s //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);# J& S% p5 _, B2 T& T" u% G( Q
pInvSort->Add(vItem.nIndex);& D2 Y/ C) p, Q m; K
}
- h) R% v3 X' ~; b4 r2 O5 Z' k BYTE nDestPos = 0;
$ C, G7 D3 P$ n( t for (int i=0;i<MAX_INVENTORY;i++) x! W3 }3 @. M: ^9 {; `
{
1 i% S2 k; @' q- ], D CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
2 N0 {' H. n+ | if (pItemElem)
5 l9 C# p0 K$ u: Q6 J {
j0 e, ^; H. w* p if (IsUsingItem(pItemElem))
+ L# g; I% ^9 F* D9 R {
4 g0 h4 f( _% Q( y% D, b+ w: ?! I, G //这个位置无法放' r) E6 [' x2 x" H1 t
nDestPos++;
9 Z" Z# c8 h6 g6 L5 R+ k' V }1 c m% v5 Q9 N' f! q- B7 b4 _$ E
}$ ]4 ?& _9 [3 ^ ] Y
BYTE nSrc = pInvSort->GetItemSrc(i);
& Y4 ~. g" e, J: S: D pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
! }. d* d, Z& F& z4 j: W+ \ if (pItemElem)0 [9 k& S* }7 [5 G+ d
{$ C/ K& @; [3 E
if (IsUsingItem(pItemElem))/ _; ]3 L8 |. D2 D
{+ W; _% t! ^7 E3 S. M7 D
//这个道具无法移动,跳过 a3 `% O/ ^8 c1 @- l
continue;3 Z4 z3 z u1 c+ s# c
}
n, a; h1 _5 g; e5 L0 Z, G' E }else{) x+ X6 ]" P2 ?: [
//空位置 不用动1 K% e% h0 M! W& v$ ^2 x2 d' }
continue;
8 P1 Z: o+ z% x# G7 U3 ~( x" V }
* \9 e/ ]$ ? L: y //////////////////////////////////////////////////////////////////////////- a( `* A) s7 x0 I7 q" p
//开始移动# @! w* t, Y# h' R
if (nSrc == nDestPos)
3 {% E+ {! o6 v! g o6 D4 e {( A2 |3 [0 j Q2 ^+ W- w. y
//原地不动6 h' J) q, J" o
nDestPos++;* O, ]$ L; V, V8 k7 f7 J
continue;$ {* b8 u' T9 v
}; v6 }2 s. s7 v% E; W
pInvSort->MoveItem(i,nDestPos);
& H8 q' [% F* e+ T0 ~. \9 } g_DPlay.SendMoveItem(0,nSrc,nDestPos);
& s+ Z' R0 X: Z" t& [& n3 q Sleep(5);
, O! i/ _3 {0 u7 V //Error("移动 - %d->%d",nSrc,nDestPos);
: c, P$ }( v, a$ z nDestPos++;
# b0 A2 s5 R& Z; z( B7 K" z0 ~ }
- E3 n2 Z" q/ E //取第一个元素的信息3 b$ ?1 J6 e9 s7 h
/*) p4 d$ N d2 n/ |
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)6 s2 o3 |+ o8 r% I# a/ i
{
0 G& d0 ]3 N+ A4 ^* E Error("Move - From:%d,To:%d",vItem[0].nIndex,x);: ~& B3 b0 p) n" U
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
1 p1 d5 e# i" }0 Q/ I1 l- s }
% o2 Y$ K0 c& k */
9 y8 i; Q( |( D3 C1 { //////////////////////////////////////////////////////////////////////////
: t: C, B- ^( h8 f) @ break;; M4 ]: Z, v5 \, b' w$ O3 c
}
. h# C* h3 `- M7 I& C* `# ~4 p }
% z) V& \7 z( z8 r' I- A}7 c) V: S3 C( r% e4 n, n
m_wndMenu.SetVisible(FALSE);0 U1 a6 s+ ^# k6 z9 l
% U# Z4 R- |0 H$ s% f. u
-------------------------------------------------------------------------------------------------------- s# O# |$ H. c* S7 p) T& D
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)/ V6 H0 G. L* a: ^+ ]# X
{
4 Y, f1 _9 R) ^, _8 W' z% x- y* f; [BaseMouseCursor();
- f1 G$ b' e$ W# x3 @8 J}. F. N5 L+ R5 q j5 V9 E
在其下添加:
! H; z) W( p1 U/ |9 bvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)" X$ W* z9 Q9 G) H0 }- ]1 r1 i
{
, r6 h/ _+ ^2 a1 Um_wndMenu.DeleteAllMenu();* F( R% P+ }9 @$ o, n
m_wndMenu.CreateMenu(this);
4 _& N( Y* O) x% H, R8 Gm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");; U8 h8 r6 W v* b. A* Q
; R0 p/ T+ A# U) Z' hif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
0 S+ F3 p! [" _& [: |' [) H; G{4 J4 X, d( U- D8 v
//P以上级别才可以删除所有道具0 G1 C/ _, M' F& ^0 R
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");9 [8 T2 M% @6 n& t+ T1 y; H3 W
}1 [5 ~1 @ m7 x$ @3 o" r
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
2 O4 o8 }5 k1 q: |m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() ); y g9 V: I0 l l$ y) |# X
m_wndMenu.SetFocus();
7 |1 G/ \# \; x- R}
/ p/ J8 B8 I6 W! y' _------------------------------------------------------------------------------------------------------------2 L# `, B2 |6 T* l# ?
*************************. p* s# M, O0 u7 ?$ W; J6 O1 h1 r i
WndField.h文件
2 {- @" L. _+ Y9 ]0 {*************************
2 R2 F& B) t" u1 I; g' F搜索:BOOL m_bReport; v$ b* p; b( Q$ u7 R1 \- C9 Q
其后添加:
2 M. H& M: v' E' ~# q* KCWndMenu m_wndMenu;
0 d5 ?( b: |, }* s8 Q) u搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);* @: [3 d! I3 i; b
其后添加:
3 b" r0 N4 C9 ~: E2 P6 J8 L' O3 N$ jvirtual void OnRButtonUp(UINT nFlags, CPoint point);
( A0 r. h4 N; n0 D% D0 e" B" Z3 i: X! _1 O8 v l
u% O# a2 }; A1 W! b
|
|