|
|
源文件中_Interface文件夹下WndField.cpp文件
. F9 _& Z- U4 Z/ Z7 k; m搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )2 o' M; b% g' A4 i9 F9 y) [
/ ?, n5 j, W& P: p4 m
struct sItem
+ }8 k" i$ g9 p( p{0 W( }6 X( F! i: F, U% ?# E
DWORD dwId;" O9 B) i2 r: r: l/ {, H
DWORD dwKind2;
+ Y' Q5 C. o1 T$ [6 N& vDWORD dwItemId;. b& q' h& v4 f. n& T% H! A9 R' |
BYTE nIndex;
$ Y+ ]2 M2 f) bsItem(){. ^6 [! X8 S' z! s1 `6 y
dwId = dwKind2 = dwItemId = nIndex = 0;
$ }/ @+ ]) M4 W/ \0 O& K# g* U}" o6 k; {& N/ r) g( h" ?3 o
bool operator < (const sItem p2). l: ~4 }2 W c- j
{5 D! N' h% D% E3 }) E
if (dwKind2 == p2.dwKind2)1 c Q+ y% K4 ~* N4 I$ _0 c& b6 t
{
# ]) l1 s6 G- p; `% P* B* b+ S return dwItemId < p2.dwItemId;
1 i2 B2 C) y3 {( k8 O) ]8 ] }else{: M, t1 M! E8 | c/ p
return dwKind2 < p2.dwKind2;1 G; K0 v/ O' e% @. ^9 V' l( p
}
2 N# k _4 u% v7 `/ n: ~$ D}
# [" w3 [! u) t% U9 _* C2 e};6 e7 x/ c1 W% R. o) Z& y" [+ |
class CInventorySort* W9 p$ z" M' q, P+ G0 }' X
{" D4 Y2 {' J0 v' k: R; W& S
public:: L* Y/ C, }; C7 W+ G- i
CInventorySort()
/ ~) r$ J8 i( r8 }) H0 _" E{& i+ i; X$ I1 Z
m_dwPos = 0;
* K$ v1 C+ p. j: G' C3 H7 G3 [}; D) X! H$ W& F0 b- |& A% j+ q- h) H; H
~CInventorySort(){}9 {% I+ K6 G! d/ c h, R7 x
private:
8 `& \& S5 r8 l8 D" f3 z. qsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
) d$ F! W7 E0 E: C4 cDWORD m_dwPos;
# [- {8 z! O7 A% Y9 J. \public:% z: w8 c( N& k6 E/ [
void Add(BYTE nIndex)
" c1 K3 a, ?* l O' Y& o: {; ]{
. [& g9 s" t! _/ a3 J$ b if (m_dwPos >= MAX_INVENTORY)0 k8 T3 ?& W% q/ _9 e9 r9 l
{% F" u) O* [% I/ e2 m" ^! F4 e Y
return;. A d; l" I1 _6 a8 E0 b
}
$ I7 @3 o* [- ^5 ` m_Item[m_dwPos].nIndex = nIndex;8 q3 E; }' @2 ?3 B' b) {
m_Item[m_dwPos].dwId = m_dwPos;! E- ^9 d5 R3 Z M6 I. K
m_dwPos++;
* G, f4 A' F* C( p( G' i}. J8 `+ n3 `2 V& {% c5 W6 S
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
- y l: B% [4 L{5 j9 m, P7 N5 M. d( c, a
for (int i=0;i<MAX_INVENTORY;i++)9 W3 }) y# A# D
{3 @9 u. {5 P+ Y4 ]' {0 Z4 n) \
if (m_Item.dwId == dwId) o9 M/ I7 s$ M. B/ y( {
{ N9 {: Z+ I( m6 i5 a3 B
return m_Item.nIndex;
' t3 S( I, w/ ^" W8 [% q( t& t+ g }
5 w4 A( B/ ]- S" ~5 e) X" w }
7 R3 G% Y! a: w: f5 X7 r/ s' { return 255;( K- `5 b8 i" @7 r! M! c6 I
}
$ z9 c; R. _1 W$ Uvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置5 k, C! S# h( i2 H5 V- q
{
2 n* p1 d8 K7 U BYTE nTmp = 0;# G- V: ]/ T- q4 `
bool bDest = false,bSrc = false;' U1 K; Q: i! F! B& r" F* a
for (int i=0;i<MAX_INVENTORY;i++)
& s! c/ `+ @+ T+ f1 n2 d; _8 k; Z* Z7 _ {* f3 T$ j3 @& {
if (dwSrcId == m_Item.dwId)9 {) U1 W- J1 ~, c3 `- H$ B% \
{
' D/ A6 @: ~% m$ F //id相等 则 改变对应的dest和src
) t- V& _' i( K3 e' z nTmp = m_Item.nIndex;
% x3 j, b& Z6 Q3 A) q m_Item.nIndex = dest;
: h2 u; K; `& P$ ?* U. V! c; t }7 i) ^8 ~3 C8 Q' l
}: d: K/ ~6 H# t9 F2 H; Y* J/ f
//临时数据保存完毕,交换开始( t, p! p, d! i/ P
for (int i=0;i<MAX_INVENTORY;i++)
: X4 T! B9 t# o/ e3 k0 E {: b0 L% R2 D& i4 y
if (dest == m_Item.nIndex); u; J \. [+ S" [) z0 j
{
% |3 s6 f3 X; }5 D //id相等 则 改变对应的dest和src1 j' G4 r9 R8 D; ~2 o7 g- ^
m_Item.nIndex = nTmp;
# s' o. q1 j, b( t: \; ] }9 z t$ l/ U @9 ?: o' m0 h
} A2 q2 F5 _; k' F
}8 \7 F8 q, g4 I/ y3 G! i
};
3 Q; ?; Q2 [; S2 m: I0 x; k, m-------------------------------------------------------------------------
^9 d$ q7 i- g; t依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )# Z9 Q! j0 f' T: L, E8 j( ^
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);: f6 C: n2 S) N0 ?, s4 L0 `! k
紧靠其上添加:) v" w7 P ~0 k
if( pWndBase == &m_wndMenu )
+ s1 O0 @& e9 q{
9 N! S* k, f1 e- E& t switch( nID )$ L5 f4 Y' R( a! S$ v/ H H0 Q
{
5 Y4 x" \$ E1 I0 }) Y case 2:0 H0 F( i: E* }
{( |9 h. s3 U- @/ A3 {
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
! n/ i8 C( H" T8 @ if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
/ x8 l/ v, V0 ~) @ {
/ a) g7 k1 c0 \# [2 g, I break;
7 ?8 y( V+ K! m0 k) {5 m }
/ R( a' l0 e! l j" U3 Z for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
" b* q- x5 y' U/ s9 n3 S4 b {
- P6 g3 [1 t# b9 `. {0 j+ C$ r CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);' ^8 W/ a7 p J7 y0 E* Y7 W
if( !pItemElem )5 E: }9 k4 ?9 q7 k9 P
continue;
$ \; R2 \7 M6 B# Q/ k; G if(pItemElem->GetExtra() > 0)7 F- O5 ^/ z3 x, @ [$ s
continue;; K: }" U$ |) C5 q
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
1 M5 ?) O8 Q* [ continue;
$ z7 Y/ ~$ |6 X* H1 c. m if( g_pPlayer->IsUsing( pItemElem ) )$ M. o. P6 C. @0 P
continue;
& v% Z, J6 @0 C6 c7 f+ a3 m if( pItemElem->IsUndestructable() == TRUE )5 J% ?( B# \: q. L! h. R
{
4 T9 C. p3 K2 x& U g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
6 S% q& i3 e, F0 \2 p continue;
9 y! ]8 f6 O* N( v. f& z8 y- K9 M }0 V4 b6 c; _) t& |
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);7 E: l7 D1 U- C! r, D' A" h
}
! ]1 V {+ m. m& a( Q break;- S9 V5 \ G3 m3 ^2 ~
}% Q+ [% f( Z" M8 Y- b
case 1:
9 @0 X5 F0 Z' _3 i1 R. [ X' J3 M {# U" k: A& L+ i. ~7 _* q
//整理背包0 ?) B6 n4 b8 \$ i+ ?
//////////////////////////////////////////////////////////////////////////
& l0 A# H4 N) U, {3 O //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );$ |4 ~) |) J$ z" J
//////////////////////////////////////////////////////////////////////////& z# W# p/ P) M/ f/ w1 ~
//////////////////////////////////////////////////////////////////////////0 @! `8 v7 H$ n# B
CInventorySort* pInvSort = new CInventorySort;
$ P# ~, j( n: K9 G) M8 ? vector <sItem> vItem;- X- z/ r+ a1 |
vItem.resize(MAX_INVENTORY);//初始化大小
$ j4 q6 o2 U- V, ^7 Y- M, d9 v //////////////////////////////////////////////////////////////////////////
5 e( X8 @8 h; r" j //填充数据
7 t6 U, x' \1 e# ]" } Z$ x for (int i=0;i<MAX_INVENTORY;i++)
0 P l2 [, f8 k4 f {
5 Y" n1 K/ ^1 X x7 p CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
' b+ _# Q% x8 V if (!pItemElem)+ y0 e( a0 f0 W0 l
{5 M3 V* B, J# T3 t& P2 s
vItem.dwKind2 = 0xffffffff;
I* T. X6 h9 }, [5 g7 u) ] vItem.dwItemId = 0xffffffff;* X% q2 Z* C' e( Z* u, c
vItem.nIndex = i;
# G$ g7 k2 l9 ?2 R1 v0 \+ k, u* U }else {5 L/ @, K6 R: }! |4 h
ItemProp* pProp = pItemElem->GetProp();
: }9 I* z% _( r! s! M( C3 D# D. |4 ?0 H0 v vItem.dwKind2 = pProp->dwItemKind2;. w2 ?4 v0 V9 M, j: `
vItem.dwItemId = pItemElem->m_dwItemId;
) T( Q- ]- I* l" Y vItem.nIndex = i;
5 U- ^! s# w$ f- s }
5 i z+ P' Y; x: ]( I6 b$ p //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);8 O6 k, t+ A, R. `! H( [
}
( h+ ]: Y1 e- w" q# D* K //////////////////////////////////////////////////////////////////////////- v0 ~4 O7 u$ v$ \( C5 n( {4 X
sort(vItem.begin(),vItem.end());//排序" w1 Y I# p& L) J" h5 r
//////////////////////////////////////////////////////////////////////////% y, G1 Z: S1 L. g1 y. y) J+ i8 a# g
//交换
7 q# ^3 z8 X _" G9 t for (size_t i=0;i<vItem.size();i++)& G5 U7 h9 U! Z
{5 ?8 H8 P4 m" G8 \
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);1 u% T) t: E' ?! u1 V: H
pInvSort->Add(vItem.nIndex);1 _: A# ?$ ~+ [5 [' u
}7 @9 [6 V0 ~9 v
BYTE nDestPos = 0;
" g3 G% [2 k+ Y7 Y/ P& Q& u0 ] for (int i=0;i<MAX_INVENTORY;i++), i: ]. f& _% p+ P' t/ S' C- m
{
1 f) ^' b, ]2 I; u) b( q6 y CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);/ M- o# O/ ?5 h- a6 s
if (pItemElem)
! i# s5 h: ^, }% H% { {" E6 _% c Y+ T7 J+ l5 D0 L, ^
if (IsUsingItem(pItemElem))& r5 R$ p2 T7 a' B( f5 b* B% n2 [. A9 \
{ h, | K$ x2 ] k
//这个位置无法放% X: A( T# h) ?8 {6 ~
nDestPos++;
) J$ {. E! v% ~9 ]; b9 z }
0 }8 X) |& y$ O& e7 `" ~ }
! G8 g+ U/ C$ K3 p2 B# z" B; T/ g$ O BYTE nSrc = pInvSort->GetItemSrc(i);4 N) h; g( A4 a! r
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);# U' D! x2 p7 t
if (pItemElem)
* }9 L0 z4 X. n8 [0 W4 {. } {% b" Z: K* \6 ^0 ~/ z
if (IsUsingItem(pItemElem))
! \' d! Q( g) R2 {* ^" I {! k2 ^8 F) Q3 a" x9 z$ |
//这个道具无法移动,跳过
, m! S" |3 o( ?4 ]- u: z7 Y continue;& q; M! `4 r2 P+ C1 D' ?
}
, n" G; g/ [3 i }else{
- \. z, O; w) A; T0 [ //空位置 不用动 b1 a7 K% y+ l* N a
continue;
1 w( u7 x0 ?! n/ ]- i" k4 B/ }, a+ _ }
1 W' O9 D7 k+ B! k% W% ^9 N //////////////////////////////////////////////////////////////////////////( k! M4 [$ d9 t' p1 K# y
//开始移动
0 f ^4 h9 j, O4 B9 x if (nSrc == nDestPos)- @% q4 w8 V% |" B
{8 b& G- D9 {! g7 ]; @; g/ O+ f
//原地不动
' @* t @, @: k/ I. O. L! N nDestPos++;
6 @1 p( K) `% X5 O continue;
, N$ L+ s; M) ~( ?. s/ J }' \% _" ?- ]. A# b* e
pInvSort->MoveItem(i,nDestPos);( Q, ^# K( X+ i4 \' @
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
* T0 N% c$ j) B$ W Sleep(5);/ D4 s0 C$ Q9 B* L' H$ y! A
//Error("移动 - %d->%d",nSrc,nDestPos);, ~8 y* r4 P y: Z U4 W
nDestPos++;) C. ~+ I' I/ i- {( ^9 g! K
}! A' z; a/ z2 H: x
//取第一个元素的信息
- B5 X3 u# }$ `, O /*' C2 g2 x6 B7 p* W, }3 l
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
; \% W o* a5 n. \ {6 t: p. C& r7 X
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);( A4 j" R8 E" q! t# A! e3 _
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
5 Q: N6 J5 t3 e& K" U }
1 W5 N- E" [5 t1 G4 c# B; j k */1 Z! T( I% R( I
//////////////////////////////////////////////////////////////////////////; N7 q9 C, O, `+ ?! }8 B q
break;& s. A* d( F: s; O' n( I; a
}9 Z5 T: k5 l( o0 k5 _
} , \/ o5 w) B( Q) ]
}
. s% p5 F" b) _m_wndMenu.SetVisible(FALSE);
; V' i/ J# K5 h2 b3 A) I+ U* d( a9 E6 D* T
--------------------------------------------------------------------------------------------------------% e/ c, U/ N5 S0 g
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)9 C* N2 y9 f$ G" I$ _
{ `" s5 n# |/ x5 `. _+ R
BaseMouseCursor();( W% r( M: m; s" \3 W( n: U
}
! h8 o3 O4 [1 f! L, J在其下添加:
- e0 z, R( E7 n7 T' ?void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
4 W, z% J) E4 |8 u0 k+ h4 ]" Z{
& C$ Z4 w) d/ \6 a) k& ~; Xm_wndMenu.DeleteAllMenu();+ w3 p! ~$ o9 y
m_wndMenu.CreateMenu(this);
% u0 d& j s: e g; x4 dm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");/ ], d4 d6 U8 n: s5 F
) O# |# K/ [! Y" r h4 wif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
6 ]5 R; w8 a: _/ g" J0 W2 f{) g: ~1 B! b1 r0 c! Y2 N4 P* O
//P以上级别才可以删除所有道具
, p3 B3 ^3 G' q m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");" w( ~ ?- Y7 u7 F# A
}, L- _ \) M7 z# W/ b4 |; P0 h
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
% d% K3 ^& X) J4 _$ Cm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
, }; S2 F7 _5 r1 K, M2 Z5 L8 ?& }m_wndMenu.SetFocus();5 {7 X: W; S9 k9 ~0 z8 C; T
}
# ]. p. K2 N. `; \------------------------------------------------------------------------------------------------------------5 s+ l# [0 T* B% z
*************************8 A% @& l$ F2 o5 N3 F$ e
WndField.h文件 w! L* b% Q' m
*************************9 r8 B! D# d3 I, g' d1 d8 @. P
搜索:BOOL m_bReport;
* E4 U9 F) p2 a/ b# A8 Z其后添加:
2 m( A6 C6 ]% _ t7 Q( e" o9 ECWndMenu m_wndMenu;
& r; g$ {7 u3 w* j: |2 G! w1 K搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);2 e- C4 L( W# Q# R; h5 H- _
其后添加:. K" y8 ?: O" h( D) _( ^
virtual void OnRButtonUp(UINT nFlags, CPoint point);+ d& l+ h! F5 C& P
* w0 z# G- X0 `' n! G, j2 ^7 Q4 O6 H D
|
|