|
|
源文件中_Interface文件夹下WndField.cpp文件1 H! g- z: B3 Z. M, m+ o
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )+ h1 z, Z! a! q5 @6 q8 ?
0 o8 W) C( s& x
struct sItem
# O& @( f3 {& h/ r; w- h0 t0 }6 z4 `: l{
* j& b) a, R( _, D" eDWORD dwId; e2 a/ _( R; m( l/ t/ S9 _8 [) N
DWORD dwKind2;4 y; x1 i9 a$ {
DWORD dwItemId;
8 W( D( _! S# W, s' u8 WBYTE nIndex;
* r* j, T$ E- h6 |- d( YsItem(){
5 U3 { t% b4 A4 g" W dwId = dwKind2 = dwItemId = nIndex = 0;
" s0 C- m8 k; V6 t: c: a}/ `' g: V+ e; e! E# B# e
bool operator < (const sItem p2)
/ N1 j: ^ |2 d+ X. e. n{
6 M, V; Y/ X; }( C; f1 I6 _" ~ if (dwKind2 == p2.dwKind2)
. p+ s, K- R$ d6 R. n$ c" l; A. _ {
4 s$ R8 a& @$ K6 f) w return dwItemId < p2.dwItemId;- |+ k- L/ `5 y2 @5 S" V
}else{; P" _* F4 N; O6 t' x3 v
return dwKind2 < p2.dwKind2;
/ `4 q7 ?$ l; R0 [ m( _ }
1 k8 z" e5 K1 b0 b& C}
( g, S# Y! r' r2 I. e};8 r7 `3 ]& J' k$ x; o
class CInventorySort
2 f* V- }0 R0 y8 t{
: @0 r7 R( {2 e+ npublic:8 T8 u) @4 h8 F& U9 t
CInventorySort()# Y/ z. ^# x' L* m9 ?0 f
{
. x3 w8 b6 m, v9 n$ Y! {* ` m_dwPos = 0;8 D/ X# ?' J+ W x8 ~
}3 b/ f6 z2 C( m2 H' F
~CInventorySort(){}
. m& U! S5 g8 q2 ?1 Nprivate:
0 y8 n# K6 r$ k+ l3 x0 JsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
) H! n( f' E; `9 gDWORD m_dwPos;4 r- p, f# m$ E6 z# O
public:
2 q& z4 a, p, F8 {8 u4 O8 Gvoid Add(BYTE nIndex)+ O; S: a H# B# N2 t; r% F' O& ?
{" P6 c ?% U) b4 \' E# Y
if (m_dwPos >= MAX_INVENTORY)
. e6 f% ]+ L4 o2 f3 K) S* ? {
" Y1 J, h9 C% {, ` return;* }& p, l A* ^& M9 B* F, f( f8 I
}: {1 v2 A4 _: I* h
m_Item[m_dwPos].nIndex = nIndex; A+ G/ x. o- a) d [+ y, V) `" t
m_Item[m_dwPos].dwId = m_dwPos;
/ P. z: G- Q$ d8 J* `6 t m_dwPos++;& v% i/ s/ u( Q* B$ ]# }* I# n6 z
}; A$ y+ k* v) {. w5 b j
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列' i) U$ X' o v- b
{
: e. m; D1 E# m9 o, K3 f, h. K" e for (int i=0;i<MAX_INVENTORY;i++)
$ {; H# N' k6 d P$ S; C M {
i# g" h, I: A5 g if (m_Item.dwId == dwId)
$ ?; O( {: C& Q$ J. T0 \ {
" _5 M1 u, b1 S7 c: |* k+ a" n5 W$ l return m_Item.nIndex;
4 A& H3 {3 X8 c }
, q% q `4 @! J5 M7 C5 n }5 o/ ?' R5 d+ `3 ?) g2 e/ Q6 C
return 255;
' F7 |3 u4 M7 @" q3 U' o}
4 L' _" O% G. @) \* D' i# J8 [void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置3 v, n- d4 ~: i; L% V1 ~8 k: G
{. @, d1 y; O! w
BYTE nTmp = 0;- j2 {# \9 L0 X' ?
bool bDest = false,bSrc = false;
! D9 K' C* U, { ` for (int i=0;i<MAX_INVENTORY;i++)
: l. I8 }* K1 V- M+ U4 t {0 K' l: [7 R% B$ u7 q: C9 z6 o
if (dwSrcId == m_Item.dwId)
) a' h7 E8 Y# d# K+ ~! d {
! u! z; A5 N! c$ ]- B( m //id相等 则 改变对应的dest和src6 S/ v6 `+ ^3 V4 E
nTmp = m_Item.nIndex;
$ f8 }2 z3 G+ T9 }5 T6 a o m_Item.nIndex = dest;2 Y ^7 t m" x$ Y; ]9 E, y$ H0 Y
}
3 F9 A1 h f8 U2 j I }8 W0 ?% R( `/ F: k
//临时数据保存完毕,交换开始$ D9 D# w. D- @) G
for (int i=0;i<MAX_INVENTORY;i++)) W8 d! a# ~6 ?' `' w
{* X. B3 M0 X9 M; c
if (dest == m_Item.nIndex). b8 y/ s% F# a. F% h! o
{
: u! R; J$ Z' Y2 ^: m //id相等 则 改变对应的dest和src z# F1 `, i5 G1 h1 |
m_Item.nIndex = nTmp;6 i; }$ G5 j- a& C* `
}" F: m6 O8 f2 F% X1 T- M
} k7 v0 ?- C7 p `" @/ c
}
& D) X5 d- }+ C4 \' w8 x) ~& _) h* k# p) h};
J5 Q- a: g2 ]& e9 Q% @-------------------------------------------------------------------------
' I' R, I/ f9 D3 A. u: U依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
; a. u1 `( s( o! Z3 F搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);% }+ ~6 f8 ~) t% [
紧靠其上添加:
( M0 `$ L; x, h, W/ uif( pWndBase == &m_wndMenu )
# f5 ^0 K% F& s" Q6 k) P{
2 B, Z# H: r2 o+ j3 C% g switch( nID )/ N+ _! R/ k+ p" m
{
7 r1 P9 b" Z* h% c case 2:
2 f* _, Y* A* N$ v {
; w$ X4 ?6 X9 O6 D //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);* L5 I. ^4 i$ B" p" @9 K8 t. m
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))+ V1 t: ]% X$ O' I* m) m
{7 ]' R2 P+ r7 n
break;
$ I2 U* p, x. B( ~ }' z' G! S/ G' @2 Y/ G. i2 e$ ~
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
g6 k. I, g" ^# z9 r {8 ]4 A( |) l2 q& T; n) @, s( ]
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);( o4 O g# ~3 l: T" x8 ?$ Y
if( !pItemElem )
/ Y4 ^( X, V3 v8 I5 A ~& k continue;
" F ^* b+ `7 h if(pItemElem->GetExtra() > 0)( ?. K5 [. K: Z. \
continue;
6 m, `1 s' L& C4 n3 k if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) + ~$ h" ?- `7 o) W
continue;
5 d0 n* V$ ?: y if( g_pPlayer->IsUsing( pItemElem ) )- {2 u( z1 a" O( t3 k: ]
continue;
: ]* n8 B3 i0 Z5 W) } if( pItemElem->IsUndestructable() == TRUE )! {( Z# ~ A7 H2 T; | L
{- ^- B8 p4 |5 e3 y8 r, f+ ~* o
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );6 I [/ m i: ^1 B8 d
continue;
4 c' p4 P# B `! g }
* _. e, b+ B3 f( e. C7 P3 j5 o g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);- d% n) {, V7 [* G' N8 M
}
7 q+ B' A; F% I/ R* Y; y" W break;
b {' S7 H4 O }
8 f& W: b, w' T; o) R2 x# J case 1:
# F3 U( a% M- p6 x5 \. } {
5 b* z7 p6 w$ F5 }" b6 T //整理背包
$ l5 G, A8 v; ^4 W* z8 N$ I //////////////////////////////////////////////////////////////////////////
4 K& m" f) c) P& F //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );- G. Q3 x, X* @9 w) S
//////////////////////////////////////////////////////////////////////////8 p) o2 f' K# g8 t* W' n
//////////////////////////////////////////////////////////////////////////+ V1 \7 I$ H4 J8 o. L/ ~6 c
CInventorySort* pInvSort = new CInventorySort;
3 V6 l7 o6 O- Q2 d7 I. }+ R vector <sItem> vItem;
- p$ c3 A. \$ v w9 M vItem.resize(MAX_INVENTORY);//初始化大小( A3 Q6 x% l, |- ]4 d
//////////////////////////////////////////////////////////////////////////2 _$ r6 ~' C8 ?& |2 r! b4 ^
//填充数据! @( e6 o) i3 H
for (int i=0;i<MAX_INVENTORY;i++); \/ o. p' j, O; P
{
$ O) u1 f/ G7 i4 ?/ b6 c3 R CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);+ c8 C/ F- P h) T$ q- \
if (!pItemElem)
9 L% {: f6 F m: L$ M {% _6 C% V" v9 ^5 p
vItem.dwKind2 = 0xffffffff;* g+ ?7 ^! M6 P" \7 i+ |2 k7 S
vItem.dwItemId = 0xffffffff;& e6 \" |2 u3 S+ R" P$ t
vItem.nIndex = i;' H% }: C. X, d3 l, ^" p
}else {/ A! {+ m: e! j" v
ItemProp* pProp = pItemElem->GetProp();
+ ]7 U: t7 h0 u vItem.dwKind2 = pProp->dwItemKind2;
' Y: ]1 i9 i. M- Z6 c; @+ x vItem.dwItemId = pItemElem->m_dwItemId;$ _9 H: Y0 w( g; Q, ?1 z
vItem.nIndex = i;* P' }8 C N3 f, _6 q% p
}
0 n( G' i# |% o# Y1 u2 w) s //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);. P# ]' g5 o, U3 P: |! y5 G" F
}
' p( V! [# r( E4 f/ L. R( a7 _ //////////////////////////////////////////////////////////////////////////
* C' u L, g( y4 M& H sort(vItem.begin(),vItem.end());//排序
4 u4 X! |3 |1 h$ m //////////////////////////////////////////////////////////////////////////
( J1 s0 H- U, A. X5 s" w //交换0 A; i6 b1 v9 f( f; R3 z% q
for (size_t i=0;i<vItem.size();i++)
g% M, V, d7 p: } {5 h. i. \8 @* x) Y
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);/ ?1 S( G" c4 g7 D- {
pInvSort->Add(vItem.nIndex);
3 ?# _! D' m. I- B) g }5 f0 }- ?( L# h% f; T* K
BYTE nDestPos = 0;
( r) P* r) O2 K2 X; ]2 M+ C9 n for (int i=0;i<MAX_INVENTORY;i++)
: |' @8 t; q, ` {4 Q0 J n9 `6 C" Z$ ~
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);7 {( R' o8 O4 y8 G% h
if (pItemElem)4 @: I2 x7 c3 |5 G$ v$ ^% R; ~& n
{
) x# ? |" e& l7 d' V: [7 U if (IsUsingItem(pItemElem))) y' v e4 O: Q% z, H6 ~2 e$ Q
{* ^8 `. _( Y h) s$ w2 J/ Q
//这个位置无法放
5 |$ s/ Z* m- \) Y: U5 i7 r4 T nDestPos++;, f! t/ \" b2 L8 R4 L
}9 Y, z% S6 k4 L j _1 P+ R" ^
}+ I+ f" X/ S- \6 [# m n
BYTE nSrc = pInvSort->GetItemSrc(i);
0 G# x9 R- A3 R, E# P# S pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);+ |+ z' |2 L2 I* _4 \" `: M
if (pItemElem)
2 m1 z) _- Q9 h5 D {
2 f$ l* b. D, ~$ M* o$ ~ if (IsUsingItem(pItemElem))
# W* m' M; J6 X( m {
+ H, {/ @5 L- z+ p4 E //这个道具无法移动,跳过
5 D2 ~9 n! T: }+ g5 z* e$ I) E continue;( a. J( [3 ~6 j/ r
}5 N; K0 i3 ]# \5 Y, {
}else{6 R* M6 Y& I4 S& A& v5 u) M7 s% [0 e' E' A
//空位置 不用动
+ ^$ W/ J' S, o+ Y/ y9 z continue;0 d0 G% H0 ]$ ?" q6 Q
}- `# U3 b9 F( B4 Q2 K L
//////////////////////////////////////////////////////////////////////////' f K, z3 B( X7 n
//开始移动! _9 V/ Q/ k- G
if (nSrc == nDestPos)- d9 U7 }1 j$ d
{9 Y; \& b# @! n+ l8 n) |
//原地不动
2 N5 \2 K( D" h3 E nDestPos++;
?8 j+ q0 l" M3 w+ b! ~1 \1 R continue;
: ?& @3 z2 r% l8 n8 H }
/ P5 k0 U) ~5 J4 N; n7 `; P, g pInvSort->MoveItem(i,nDestPos);
7 u* q) S' C, A4 H7 U q$ _6 w g_DPlay.SendMoveItem(0,nSrc,nDestPos);
/ _: i6 e- C X* Y. I Sleep(5);: M+ U! b; L- `
//Error("移动 - %d->%d",nSrc,nDestPos);! N9 M1 Q% L: i" X9 F' @* [
nDestPos++;
& ^3 U) g( G& L5 M1 ] }" i0 u0 B3 q" O$ d
//取第一个元素的信息; I) R3 }& {1 P
/*' K( k( M- D; z4 f$ I; H
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)' y9 C7 i0 @3 ^6 U m
{
# X4 B! V4 y/ H7 G Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
* k# m6 f8 u, j* @/ k g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
. i5 y# W: _, O }
+ S$ Q: T$ M: i9 j# ] */0 t' ], d8 k* l& ]9 y
//////////////////////////////////////////////////////////////////////////# O0 M4 v C1 |- y# s
break;6 J% \; F6 n- m* Q, \ B) t! j3 l
}0 z$ B P$ r* U" F v( r
} 6 i1 y1 v8 o9 \; s6 t# i
}1 C% U; D" W# B+ O" |( y
m_wndMenu.SetVisible(FALSE);$ H y2 c" k! p
, W- Z B3 X8 s" p
--------------------------------------------------------------------------------------------------------3 Z/ `; T$ I2 l5 s
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)1 l$ g% e, R. e, h; P1 |. f& Y
{ s1 U* _# c2 T6 J2 O8 {4 @
BaseMouseCursor();% h( G9 ~% p! G8 H/ f
}
/ b: ]1 d* d; y' c* d在其下添加:
, ~1 K. B3 t+ r e- Q6 ]5 @void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
; N) M" E. `) }$ p- h6 N# r{; ?% L4 S- V0 c
m_wndMenu.DeleteAllMenu();3 n/ y& Z: Y0 J) \6 R& ]* g8 U
m_wndMenu.CreateMenu(this);
1 K1 s1 h4 N Q( U) e" m( \$ S1 bm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
+ P+ v& W( b% x: L1 |
0 {! [* j' G$ j/ B( V9 n9 K3 C5 Yif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
& {1 ?; w, n! l" O( e{
! o* B. d1 p& I4 X" J8 k; t //P以上级别才可以删除所有道具
0 b. Q! W# S/ m m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");! Z1 p# b& v$ @! P" D6 b
}$ n+ k$ B3 N2 N* x6 v
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );/ d% I5 E: Q' J# W! t" Z7 f
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );5 \' W4 G; ?6 A, u# m, V
m_wndMenu.SetFocus();+ H8 m9 Z3 f- O' ?
}5 a3 t9 \: {9 e7 X9 T
------------------------------------------------------------------------------------------------------------
6 v1 T3 a3 r# b; t7 B* a. f*************************9 X7 P; H- \* \) ~
WndField.h文件
1 L6 x# M' t2 J: o! Z+ }*************************, \" W' h2 o6 t" x" Z2 N
搜索:BOOL m_bReport;% _- `8 }: T f" \/ H5 ?5 R. G
其后添加:6 s. M. h' o% m
CWndMenu m_wndMenu;
5 B1 W/ t) v( q: m; S6 F' I8 s搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
4 G- ]) N, z3 x, z" y: e6 ~1 N9 c其后添加:
5 S+ o* Q2 n* J% Xvirtual void OnRButtonUp(UINT nFlags, CPoint point);
1 O% X, o i# J. [1 J+ z4 D
- H/ Q. t6 m' N, u
% f8 [% f B } |
|