|
源文件中_Interface文件夹下WndField.cpp文件$ p' {: O2 Z' I+ L* E, ^
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
7 n) n; m# n) {% y% N2 W% u; H1 h7 N1 i" I' t% t
struct sItem1 V( A% j; e% n7 \. z1 s" w3 t5 v
{
: ^5 u8 T3 Z; \8 u- YDWORD dwId;+ U! v! Z1 `0 w& p
DWORD dwKind2;4 g8 w2 y; W( S: d
DWORD dwItemId;8 ~" p9 n) @. j+ K% a8 |+ e2 Z
BYTE nIndex;* S& Q% n+ h9 K2 k
sItem(){" e) R7 u" s$ C. I
dwId = dwKind2 = dwItemId = nIndex = 0;2 r S% ]# n; o" g2 f
}3 X; t- c: p$ m; Z( v
bool operator < (const sItem p2)1 [. t( u3 ^0 c+ {; W
{
' e. H+ ]" D+ Y4 X0 h if (dwKind2 == p2.dwKind2)
4 d( Q; n: y/ S2 K5 B5 \: f {2 Q1 M0 k w8 w! o/ x) u
return dwItemId < p2.dwItemId;6 u( C$ _6 w* ~' K
}else{
2 |% Q" p, b% z3 Q return dwKind2 < p2.dwKind2;$ y2 T" O. [; R, j: b
}
S, V c H7 K& U- y}
" n0 |( Y# I+ r4 v" n};
S+ U5 r' n4 h' v2 dclass CInventorySort
( J- S2 L) N( p9 D x: n{) [9 U9 n% ?. b: L
public:
( _) e+ J( H" B$ @2 p- n3 L9 k# nCInventorySort()7 H5 D3 |5 c4 v( C. S% K
{) O8 G" C/ H/ k; l3 L
m_dwPos = 0;1 B" x- S: z8 I
}! L6 x2 C, l x2 L9 F
~CInventorySort(){}
6 ] d. ^" O- j) \- S4 Sprivate:
# a: i4 d5 |4 q; N7 t6 N2 I" ksItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
+ L" r! H3 f+ BDWORD m_dwPos;: R. l, U# J& ]; t
public:$ i9 i% V# |, F+ ~3 J& ^
void Add(BYTE nIndex)7 y. y5 T2 u3 F- r1 h& p7 w
{. r( S6 ]+ n0 P) f1 L4 N
if (m_dwPos >= MAX_INVENTORY)
& P2 i/ S2 L; @ {
; {+ b2 P! ~! f8 W return;
6 }4 O/ I2 D' w4 B5 s/ {9 ?% t/ d5 z }0 [1 z l+ f! r
m_Item[m_dwPos].nIndex = nIndex;
5 h8 q2 D" E0 w' |+ T, h( o% W w& | m_Item[m_dwPos].dwId = m_dwPos;/ Y& K# N: j" U3 u( z1 j
m_dwPos++;
! u6 ], J# x$ g1 v* o9 C7 d6 U} J- O O+ G, N/ |9 `! T. {
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
; r2 I) q! l* t( m! p; s{
$ k5 |& B1 |5 u. p8 P8 V- D/ @5 M for (int i=0;i<MAX_INVENTORY;i++)8 V. C. |% a- v- c9 P+ ?0 d
{* s# t5 H6 R- a6 u `0 @' T/ J
if (m_Item.dwId == dwId)- g$ R0 c; }% a3 A& F
{
8 t& k7 K5 o: E! A8 L return m_Item.nIndex;
: B6 x( N1 T: r }
4 `& F$ M2 |( v5 ], \6 k }7 n1 H; ~ f! N+ N
return 255;
5 q+ U# R' B- L) Y9 M6 @, _2 M0 r V( P}1 J& R5 T0 Z% W U5 P" u
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置0 ?6 C5 s0 E) ]1 L: z) p$ A
{
! d0 P: ^$ e7 z" {9 g$ d BYTE nTmp = 0;9 o5 a1 B) a0 z* v9 c! q
bool bDest = false,bSrc = false;
0 h% {- l# L8 O7 C, S- ?- n for (int i=0;i<MAX_INVENTORY;i++)
5 ]; ?1 A4 s ~$ G {' a% T6 N- S* T' E- g) s- K: ?
if (dwSrcId == m_Item.dwId), {1 e9 y" A* Q, ?
{
) t" _/ T0 G: _7 F: o% x //id相等 则 改变对应的dest和src
# J4 n: l$ N2 d: m nTmp = m_Item.nIndex;
8 \# x4 h3 H& |! C m_Item.nIndex = dest;7 k& K! d a$ z( p7 K2 y
}, S Z8 W. }8 N1 w3 u, I
}# w) x, E, n8 y+ i. b
//临时数据保存完毕,交换开始3 a! y% l3 F2 h. l3 t
for (int i=0;i<MAX_INVENTORY;i++)+ _2 N0 L3 v( w3 v V+ i) G: j
{
0 i7 V4 r' z8 D) T& B if (dest == m_Item.nIndex)0 R8 |+ e$ ?6 b* [
{, ~+ W! D& M' ~$ G' H
//id相等 则 改变对应的dest和src
7 c3 n! e$ t5 x3 t6 I m_Item.nIndex = nTmp;
( P4 k- q7 y+ }1 p% ]5 T }* \& v7 H, Y5 w3 A. [& V9 l
}% i; v6 B' @8 ]5 B4 d, Q: C
}
+ {- y: l& \+ f K+ `; r- g" K: }};
4 s$ y+ g" |$ w9 d3 Z. l# d-------------------------------------------------------------------------
- L1 X# J/ X% g依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
, @$ w% [9 s: L1 Z0 X搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);, s f5 M* T: f" J. A6 c
紧靠其上添加:+ [7 T8 R" t: [; V
if( pWndBase == &m_wndMenu )
$ c+ `7 J, N( g+ Q7 C{) w L2 s. ]. S! u/ n: u: u
switch( nID )
: R& q2 v5 `9 C& W. i6 Y+ h7 }1 S1 p {
* H& I) w+ e W* E, v case 2:
7 M5 j7 ~) G/ R9 ~$ X {/ I9 S/ u# b+ F' l
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);: ]# e+ x L! Q/ Q( p
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))5 G5 X+ q: l4 M/ s0 O- @) H/ }
{( J. [2 Y. w# I1 T D4 M
break;
# X; G5 V9 z& I* _6 ?: ~ }
4 e6 h2 J% Z* \; n2 l0 z/ ^9 } for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
5 [6 f( D# N% U, w$ d {5 V, l( G0 j& _3 l8 W* |% w
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);9 [4 d7 n2 w3 t
if( !pItemElem )( S; W3 U4 G! T- H5 n* U: n2 m/ }
continue;. Q& y4 C3 Q2 J3 r6 A' O& |
if(pItemElem->GetExtra() > 0)" f0 {4 t: ^2 }9 V( c% z7 j) P, D* q
continue;' j1 s0 M/ V4 N V" c) H1 }( t
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
$ X4 a' f7 k* c! Z/ `2 ~ g6 e continue;0 V9 v! P. }& A( [8 W. {
if( g_pPlayer->IsUsing( pItemElem ) )* @' J+ i' \& {1 j5 r- R k# I
continue;$ v: v, ]/ J$ X( j
if( pItemElem->IsUndestructable() == TRUE ) w) P# ]4 {& Y+ j4 U
{
; z* s4 G* ]5 u g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );: a) Z6 W8 ~$ Y
continue;0 |: e- X& m* J( ]# s) J
}; E* c7 A: ]. r, v6 E) O7 T
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);7 c! G/ n( W; h! _
}
& g4 h' l8 `( N! V) ]* ^ break;9 A' w9 F% j! k9 o: Z3 j4 V
}( E/ x# n0 G, L. C* t8 K
case 1:( t! {( F( T6 Y) }- I. M# f% `4 `& S
{" ~" j4 M) u8 Y
//整理背包7 I* v7 }& k4 z3 Z. Q- V
//////////////////////////////////////////////////////////////////////////+ i! }6 _4 F) D$ \6 N9 J
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );& n* s; {: \* Z: c. l/ o
//////////////////////////////////////////////////////////////////////////& o& d. `0 d3 w# ~
//////////////////////////////////////////////////////////////////////////' ^. d: X; S& w/ O
CInventorySort* pInvSort = new CInventorySort;5 R, t: u/ h: E3 E: {
vector <sItem> vItem;0 B- g6 \9 U. s0 {+ r
vItem.resize(MAX_INVENTORY);//初始化大小/ P, i% h0 w5 ]9 L
//////////////////////////////////////////////////////////////////////////
3 E" Z" {/ T, A, E! T //填充数据
0 B9 K5 _3 Q% X T for (int i=0;i<MAX_INVENTORY;i++)2 ^& E# |& E! g: S- H
{
+ p; f. C+ K, N7 s CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);# `! v2 o, E7 z1 }) j0 l+ h# i
if (!pItemElem): T; Z) V4 c! M! {* f
{
- k. j) e4 B- w8 U2 y; u& p vItem.dwKind2 = 0xffffffff;
1 J: J: h2 o' Z3 d0 m vItem.dwItemId = 0xffffffff;8 z5 R9 [0 Y2 B7 S6 j) G2 l
vItem.nIndex = i;) T9 Z" z' Q& m& ~. O: L
}else {2 T+ A6 R- S$ ~
ItemProp* pProp = pItemElem->GetProp();" P2 ~+ ]/ u0 W8 g H
vItem.dwKind2 = pProp->dwItemKind2;
& f* d7 l, S8 {& S7 }2 n+ {7 i2 h vItem.dwItemId = pItemElem->m_dwItemId;( {! _4 q/ t* o6 Y. w
vItem.nIndex = i;. m+ I' F0 v7 C8 T. P- ^
}: [7 L d7 x! C/ [
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);; }: M' `& w3 G
}- o! w' \4 z8 F5 m; m M% c
//////////////////////////////////////////////////////////////////////////% G5 k- n& [, \& j2 z/ ~8 N
sort(vItem.begin(),vItem.end());//排序
* R7 h6 I6 {. t" a; k# E //////////////////////////////////////////////////////////////////////////: X+ K( C! e5 C- t2 l3 o
//交换, ^1 \0 w: `( l* u/ R$ e7 v2 I
for (size_t i=0;i<vItem.size();i++)
d( X p& z7 u2 f$ ^ v1 N9 g/ a% a {
( L ^( a/ Q" g( |- ] //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);% i) U4 w8 a$ H8 [, i1 m
pInvSort->Add(vItem.nIndex);3 M4 w! X4 L& `- d* U! y# U0 t
}$ l6 Z* _. H( i5 O6 M
BYTE nDestPos = 0;
- f& A4 B* j# b8 K- Y | for (int i=0;i<MAX_INVENTORY;i++)
3 S) f" E* c$ B. G {5 G+ Q& Z9 v0 x
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);. s% B4 m/ K) a( h4 i& K0 S# e
if (pItemElem)
: Q! R" R2 |: C5 e. s& \; D {1 U' y! E0 @! _- [
if (IsUsingItem(pItemElem))* ]0 d6 s3 |5 C6 U& y7 P9 z3 u3 r
{
6 D& H! T$ t& Q* S. _& a: f7 b //这个位置无法放6 B( N3 {/ v6 Z2 [4 n
nDestPos++;
" k. E0 _$ [0 }. n }
% I5 J1 u, o: S2 q/ b+ i4 n! m }
0 W9 |, Q( T+ ~" H1 @' d BYTE nSrc = pInvSort->GetItemSrc(i);
' e( t% F/ a% v2 R3 w pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);- R8 ~( x! ~+ a* G
if (pItemElem)
& c8 y& p9 E+ c) `7 Y. x( d p {9 B9 Q$ Q3 x2 a3 y
if (IsUsingItem(pItemElem))5 f g4 {& A N
{9 R' Q7 m2 N2 r. C% L' q# l4 I
//这个道具无法移动,跳过+ ]" r1 c9 `2 q
continue;2 @4 m$ w( H- A
}. t4 I7 G. ?8 @+ v
}else{
" H9 X. e/ y2 N3 T //空位置 不用动
& L$ ? r3 u1 d$ ^1 r1 ?4 Y9 B% E continue;* H& x4 P: M, z$ s
}
$ b% d4 A/ {- m4 i0 q //////////////////////////////////////////////////////////////////////////2 r2 H, }% V5 o' U+ Q d
//开始移动! A6 m( f `4 l! }' L
if (nSrc == nDestPos)' o$ {) s( z% r8 Z
{
9 [- ]% _# _+ B //原地不动
7 \+ W [* u/ k nDestPos++;
, X+ p7 w# v; G0 ?* b m; C! A continue;
3 d% N n( b4 R' Z }
/ K6 o! Z& l8 k0 n pInvSort->MoveItem(i,nDestPos);
3 m. \9 t% k3 d1 H. l. Q4 Z g_DPlay.SendMoveItem(0,nSrc,nDestPos);
+ q0 I5 o' ?9 j9 X+ a Sleep(5);* p9 l6 M+ p2 m- s3 Q) b* X. l- N
//Error("移动 - %d->%d",nSrc,nDestPos);
/ o; x# A: J, v, @) s" n& e nDestPos++;! P7 f* c% V5 g0 U7 H. m
}- m5 X4 J" F- {8 Z% a, l3 m
//取第一个元素的信息
- i5 p: M1 y/ u- Y s, s, ] /*6 W# A5 V1 Q& C- w* \
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
1 s/ _# t+ F, }- E/ D! U {, {! `- R# @6 s
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);# b L2 p: Y, Q- H& Q
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);! L( z9 T, Q3 {: h
} R$ W5 q4 R- V* G& Z% X ~) o+ _
*// b: p0 u' {) c/ W+ ]/ K
//////////////////////////////////////////////////////////////////////////; f* j8 w2 m9 q) O# D
break;
; J+ w4 d Y" W' ] }8 P( t" N. i0 t- Z7 j
} 5 D& {9 f5 [# ]9 \" R% U& ]; [
}
1 g, e: v! k3 wm_wndMenu.SetVisible(FALSE); [) F0 e$ r9 ]4 y$ a7 }; ?# k
7 y% }+ v1 B4 y$ Y
--------------------------------------------------------------------------------------------------------/ k9 o% @9 R% I/ y( J6 S
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
: P. l6 h0 @7 v2 M{
/ w |7 B$ p X' aBaseMouseCursor();
+ V, K/ H0 H5 f% B& M/ {}% |% C/ z* ~ e2 {
在其下添加:& {; R j8 g) L( y3 T7 G- z
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
" h. l, O% ~ n! u{
/ `. ~7 g- v1 v& em_wndMenu.DeleteAllMenu();
& c, f8 E: v4 _: y* [; km_wndMenu.CreateMenu(this);; U) N2 _1 G6 _3 a O3 `' _/ W
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");2 p: G3 V7 C+ w8 V
+ o) I" A4 E9 [2 q" u, v) |# jif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))7 ]# V @* H9 ]& T5 C; q- o
{
" f4 R* S" N1 K8 f/ d //P以上级别才可以删除所有道具; o3 k+ ~0 [1 T
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
5 n4 N* L/ V2 h; I, n6 Z" J/ E& Q}
$ w: u Q; g, Q+ D1 f/ [* _0 l" _m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );% k* B9 [* Q* Z1 t. T
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );: \% a0 S/ ]4 r- P4 F6 J2 {2 H
m_wndMenu.SetFocus();1 F4 J2 U8 b" ?% T2 f0 B
}
( A1 L$ S# H( ]------------------------------------------------------------------------------------------------------------
. Z! k1 Q/ v" N& x) _6 s/ W*************************
( C, W, \ y" Z8 U3 z9 g! \WndField.h文件
3 y5 y2 [; D% R- }% J*************************7 U: U8 h3 b; \6 F( V3 ~, G
搜索:BOOL m_bReport;8 l. i5 x- f: T$ M7 U o9 o
其后添加:
1 Z6 R" O* ]+ c# W/ R, w r6 F6 P: V* SCWndMenu m_wndMenu;
- N' j) a" u* Z/ A* |2 D E搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);! R# o' [; n+ F) X: S
其后添加:
1 p8 l7 u) x3 K/ P$ c# }virtual void OnRButtonUp(UINT nFlags, CPoint point);
6 k. A. a+ X B4 j7 u ]; S+ |9 j, P1 y: W0 y; S
t& r! q$ e2 R" P1 s9 p y% i, a' D
|
|