|
|
源文件中_Interface文件夹下WndField.cpp文件
1 Y- n5 L5 A0 y( M7 k搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )! w3 f" y- V2 P$ L# c: h; a+ a, Y
' x& H& i1 g9 astruct sItem* m0 e+ ^2 ^4 C! t" m2 C7 @
{
1 y. t+ w$ d: f$ ?! yDWORD dwId;
6 U7 R! r% _4 N, VDWORD dwKind2;
- a# q8 G* d$ {DWORD dwItemId;9 i! W l" i5 v' y/ o' {7 ~
BYTE nIndex;
7 U \8 P4 K8 `1 _) PsItem(){' ?/ Z& G$ V( N- I' N2 `" D
dwId = dwKind2 = dwItemId = nIndex = 0;) k; G8 J$ @1 J) M& B* j, X6 V& y
}
/ u6 d4 v+ m$ ^% xbool operator < (const sItem p2)2 `: X o$ \9 H, s% l! s5 Z
{" H& `6 t2 W% T! p- V1 {, g6 i9 B
if (dwKind2 == p2.dwKind2)
8 z( i8 o8 H! |: W4 R2 S' W {! Y+ [7 d) o/ ^0 u+ {
return dwItemId < p2.dwItemId;2 ]5 u7 Q7 |" Y( M" X
}else{3 G8 A+ U, r' Z: M2 i% Q, W
return dwKind2 < p2.dwKind2;% O9 x) h2 B5 U
}% y1 Z/ `9 f7 q9 b' Z, D" c2 E
}! W* M/ R3 V2 u+ |
};- L# `. I* P+ }$ g1 J
class CInventorySort& A& ?7 N+ f# Y8 H# V
{
9 x, R5 c' D2 c$ z0 G0 Zpublic:9 z- u% q2 U' y$ l* V
CInventorySort()7 I* \: Z* R" {8 h! d
{' J$ b! L5 T* E! d
m_dwPos = 0;
0 c" a! A1 S2 j2 j( J}
; ^' v$ p% F8 K- ]# T% S~CInventorySort(){}
7 B; N/ R1 g5 g, O. Vprivate:
0 Y- V* [7 [0 H [sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
! Q" N- U+ G6 Y8 I1 P" e" M; M9 j6 p mDWORD m_dwPos;/ w8 U7 M& C* Q
public:& a O4 \) F( E
void Add(BYTE nIndex)3 y: g# u: j% @- ~, J4 p
{5 e1 k5 t* Q* S2 A$ g( Q
if (m_dwPos >= MAX_INVENTORY)& `1 J) k" ~7 Z
{; `" u, N6 F9 x
return;
' {5 T" }: F* v4 j } E$ y- V; A& c
m_Item[m_dwPos].nIndex = nIndex;
0 l! `0 P9 U& U' ?' b m_Item[m_dwPos].dwId = m_dwPos;
5 h7 j3 {( ^ K8 H9 n m_dwPos++;
) ]! B8 \9 v0 k- e% u# a}
* E; K' F# D- l6 E$ ?3 r$ d* }BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
$ g) m. w; E2 p( W{
! q% y- W- W" }! y for (int i=0;i<MAX_INVENTORY;i++)
' T* h1 n; m a W9 U2 X | {7 W% x) g: w* V7 D
if (m_Item.dwId == dwId)
; q% V. |& |8 o; W {
" e+ k- J) ]8 d) | return m_Item.nIndex;( B# [3 i6 n& v
}3 ~; \$ X& a8 U
}
" @2 h" {+ T8 F. F/ \ return 255;5 N4 T- h$ O, {* S+ a4 a
}
) V0 {7 u- Q5 r6 a) F& svoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置% |$ D" S; i+ B( g/ d' [
{
6 q: B; D$ h2 R$ r, t BYTE nTmp = 0;5 [( J! X6 o% U+ [
bool bDest = false,bSrc = false;" Q* u1 @- Y Z+ T& Q7 L
for (int i=0;i<MAX_INVENTORY;i++)
! K. V) f5 _9 X {+ r8 [# c* f' T
if (dwSrcId == m_Item.dwId)
+ k% e- S/ [; r& U {
# n- W7 G( ^ j6 |2 w0 R //id相等 则 改变对应的dest和src2 |: M- o7 Y) j; p
nTmp = m_Item.nIndex;
2 h# g( G' F7 z m_Item.nIndex = dest;
; d7 o2 o2 O8 ]/ P: z0 m }/ \3 n2 D2 Z$ k
}
: a; ^7 D+ \% T) B" B- s //临时数据保存完毕,交换开始( i" k& ^$ m, T0 F9 q2 x
for (int i=0;i<MAX_INVENTORY;i++)
, F% U l8 Q2 O+ i+ b9 f: b {5 K Y Y. Q+ M3 M) s+ `, k
if (dest == m_Item.nIndex)3 G: p8 @, ~& k* G9 H6 j) f$ N# ?
{
' P' s/ Z0 l* ^4 A+ Q" }5 ^& I //id相等 则 改变对应的dest和src" {1 T- Q5 L0 e( ?" E }: R* L
m_Item.nIndex = nTmp;
0 _2 Z2 `; j# u2 E1 \" S' } }
0 P/ o" q$ P2 K2 W) x5 y' n6 ~. b }) z( L& E- l7 w# j2 K! s$ T0 w
}& A! c4 g% \0 E! K/ o% D
};
) Y, s" w2 c2 L5 H$ V, P-------------------------------------------------------------------------7 B# [8 a/ h% p% D, d
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )2 C8 X* ?) f/ v& L1 ?: q
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
& i0 G" A2 W/ E$ z8 a! L! m紧靠其上添加:
+ J4 x1 |4 E5 f, v: Q3 xif( pWndBase == &m_wndMenu )" [- I7 A* z3 R3 I3 q& ]1 q6 N( f
{
7 u) k/ f; \3 T0 w, e. ?) Y7 F3 E9 C switch( nID )6 `6 ?" B3 ?5 x0 o/ X7 c
{" i, ]) j$ E: ?- G# w- Y w
case 2:
* g8 V: r9 Z! }" o( S" F( z {) P6 ]7 V0 n+ R" D! N
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);4 b! {& F: ?7 ?2 n
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
4 j& B" R, W- K: H {
3 Q$ |! v9 n. F, e break;
6 {& x1 t1 z* t }) [0 q# z; [. V7 {; _2 C
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++) [5 r% C* Y9 s4 K) ]
{
% h9 G g( A2 R+ h% d3 U) B+ G CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);# f" A# a, w2 u* n: B ~% C% k
if( !pItemElem )! s) ]: @& s; ?( q3 p
continue;# U* u" q- r1 v# t
if(pItemElem->GetExtra() > 0)5 s! z# v* e/ x2 ?- Q# p
continue;
6 X6 B6 N; b3 w if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 0 u0 v# t8 _3 @
continue;
, w- |9 M2 J% e& ?: @ if( g_pPlayer->IsUsing( pItemElem ) )
: r; U6 u6 `2 |+ ~2 D+ x% R; | continue;
, P4 ]0 P, A. M5 j$ {6 o' _& j, W if( pItemElem->IsUndestructable() == TRUE )2 X- j, D0 b) X7 E; z' g7 C) N* \+ Q
{
4 Z! ~3 g. M: F5 d( Y( d$ b& m, c g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
8 O4 ?( ^. m, \- E4 _ continue;
8 X, |- L; n: u: y. D# V: ~ }
+ g5 f$ E. u: R! X6 @ g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);' C9 \2 g$ n: w. A# Q/ c
}
# H' ?: c" ~, a- s: V$ B' c8 J: [ break;) N+ n1 \" C* U% K1 j+ w2 `$ a
}: Y2 z+ r; Q5 l+ k0 x2 L
case 1:. I2 a. c% o0 [& c
{
; P* B- H: f7 E( T0 b- a9 J! e% C //整理背包
: l1 h* C8 q" b, V5 a g" D //////////////////////////////////////////////////////////////////////////
9 a# W! B: B$ h" }* V //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );2 D9 o2 D9 h( B0 U2 \" ~3 Q
//////////////////////////////////////////////////////////////////////////
3 V/ a/ B, f0 M& A8 M2 U' b //////////////////////////////////////////////////////////////////////////; G2 e' S1 s0 T
CInventorySort* pInvSort = new CInventorySort;1 w, s- [8 x7 i) A9 \
vector <sItem> vItem;
$ ]7 J1 [, @$ a( a: P vItem.resize(MAX_INVENTORY);//初始化大小
8 F7 J" O2 B) T" Q+ G J) C //////////////////////////////////////////////////////////////////////////
& N" r. P% u X8 R) w3 F" W B4 I //填充数据: _; P& |, w& Q- B2 u6 T! D# G
for (int i=0;i<MAX_INVENTORY;i++)
2 A/ s n2 u# J6 T% {: h {/ h4 P7 M+ ?3 D0 f; P; j! W
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
) Q6 B# t/ }( I4 Q# t8 } if (!pItemElem) _# K. O% ?" s+ k
{0 M: j# @( Q; D. N( @
vItem.dwKind2 = 0xffffffff;& U( K6 t1 P" u
vItem.dwItemId = 0xffffffff;
4 m+ h# ?# `/ g vItem.nIndex = i;
" ~7 b) ~2 j/ v+ m% z }else {
4 L8 f# y* ?7 O% \2 H$ S ItemProp* pProp = pItemElem->GetProp();' o7 i( G) M# p
vItem.dwKind2 = pProp->dwItemKind2;5 j O& k6 e9 B6 k8 Z
vItem.dwItemId = pItemElem->m_dwItemId;
- @) \4 L# W7 l vItem.nIndex = i;
6 Z; o# `+ A! v5 i# o }
9 x% D, w1 D8 a4 z- b //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);6 o1 W% W, l# f' L! e" h: }% q( S6 y; |
}
$ R. C/ H% {5 f6 A% B //////////////////////////////////////////////////////////////////////////
# A* m" r6 \8 j7 m sort(vItem.begin(),vItem.end());//排序
( C, X u: h5 Z$ j3 J9 ?5 S# c6 w //////////////////////////////////////////////////////////////////////////% u( `2 A+ x4 i3 {% y- g5 v
//交换
9 x( E" m6 y8 j# n. `/ N# ?! {8 P# U for (size_t i=0;i<vItem.size();i++)
8 J3 t9 b4 @/ T5 q* x: A+ B {
7 f+ J/ h6 H6 t0 r1 A7 \7 k# R //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
, z* E+ R4 \: j$ m" r$ w% i pInvSort->Add(vItem.nIndex);) Y" L% {0 l$ i6 B" R5 D7 f
}* Y0 Y- j2 B, g4 [" q
BYTE nDestPos = 0;
7 U0 M/ y# q% U. [7 p, Y for (int i=0;i<MAX_INVENTORY;i++)
; A3 u' R6 ?4 L, `9 P0 b4 `' [ {
$ _4 L9 o, Q2 P2 V CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);8 z! N; ]8 x6 }
if (pItemElem)1 i8 ~" v+ W& y3 z5 [9 [
{
2 {" |' h8 K" I7 y4 D( K if (IsUsingItem(pItemElem))" L7 q% v( r* l s/ D
{' T/ s' o" j1 f% a, M6 `: {+ e
//这个位置无法放3 u9 P" E, t& E+ S! _8 n5 F
nDestPos++;$ P* G7 `1 A1 I
}
; G- Z5 a3 V( V6 W3 t& G }
+ s2 i8 e; W, O9 c' t0 g BYTE nSrc = pInvSort->GetItemSrc(i);: y9 t+ C9 B2 Y2 N: s
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);. O$ Y$ ?- Q0 t0 Z
if (pItemElem)' X% [5 o. b; [; p4 X1 V4 O
{ |: |3 A$ T. I* b2 R9 }' s0 x5 `
if (IsUsingItem(pItemElem))6 h5 Q2 G; f- K7 A
{
9 E, c6 C+ L; G! L) e5 A //这个道具无法移动,跳过; N+ L# D7 z+ M* R
continue;. ]' W; J' `* ^
}/ |4 x% V# h- r0 m- W! ?
}else{8 V; T* e+ ?& b9 \: X2 o% h
//空位置 不用动
3 m) M9 Y' b1 X7 u" b7 c2 y. q8 r1 U continue;
3 G& c2 d |$ w! a, S" R) p" u+ L }
. P9 o; i+ U$ O7 G //////////////////////////////////////////////////////////////////////////# h- X: j A3 s* [- y( ^3 w
//开始移动
; c1 v8 W# p3 R- d if (nSrc == nDestPos)
b8 |. c8 A% J# J9 I5 O9 R$ w0 J {4 U4 J. C& w) w: {
//原地不动
/ @5 b2 w' N$ O# k( x% m nDestPos++;) w- v" D+ |$ ? {
continue;
' U( E& M) p n, M } B$ _) i7 |! R5 K3 H
pInvSort->MoveItem(i,nDestPos);; x% m H1 a* i: k
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
' ~4 N: ~' J3 ~* a1 S/ ~# t Sleep(5);. u: ?! @. G- i1 H
//Error("移动 - %d->%d",nSrc,nDestPos); O* }9 g' P2 Z5 z
nDestPos++;" L8 h c6 x" s, e9 R4 j
}
1 N; i; \- ]) v6 g) y" S //取第一个元素的信息* U7 e! n3 i+ z0 [
/*' X5 R: Q. x" Q- Q
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
+ e! Z7 ?5 n) z O/ _* ^ {; x6 `) @7 l1 A. _6 G
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
6 U7 V% h) A+ a, T2 }$ N g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
) f% S3 ~* b, K7 }! M1 D/ K }
" Q: F; q, q" N8 q1 C2 \ */
+ [# P) X" K4 k* P) m /////////////////////////////////////////////////////////////////////////// h' J- u) o& l1 r( j2 ^3 c6 \
break;
8 N* N8 X1 ]7 `% J4 }! B+ ^ }
! v# R3 |) b. ?' h }
7 j# ~, K0 ~. K* j/ W% e}
* G9 b9 W3 D" um_wndMenu.SetVisible(FALSE);3 F* T* |7 q6 l5 n% f. t7 X
3 w) [# Y5 `; I7 h3 d. e--------------------------------------------------------------------------------------------------------
0 q- I/ U/ q6 w* x搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)2 ~* w* I. V0 l N9 K0 Y
{1 I# A) j/ S+ K
BaseMouseCursor();: [( ?( \+ k. j4 Y
}/ L, k. ^; ~: k7 c& p8 K8 g5 X+ u
在其下添加:! J& [6 j2 ^! P# o/ v: D
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)2 V7 f' { D8 |5 A6 W
{" S% I: W! l0 m% G& D
m_wndMenu.DeleteAllMenu();- q6 P* ~! T& R' Q% B1 H
m_wndMenu.CreateMenu(this);* I! k( [$ E8 k' \
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包"); X% F) o2 Y7 M0 P/ R
* Y0 w6 t f# b1 }
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))) J3 b0 }* h- g. J3 g
{& k( e3 G* r. q8 B& h$ X+ @
//P以上级别才可以删除所有道具
% P9 n% L M& q/ p' o m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");& d% N1 ^- W, \0 i
}
- A4 W- y$ f4 b' }, A' T) E1 `m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );) `( ?' m6 x$ T4 G) Q7 f
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
9 s9 g& s* M1 t2 l& V' H7 ]m_wndMenu.SetFocus();, F" f( ?; R: v
}& P# t0 K) ~9 d# Y
------------------------------------------------------------------------------------------------------------
0 d/ n6 g) i' i9 o% h/ }/ `************************** N+ U0 B0 }6 J8 a' Y! u
WndField.h文件8 c( k q* m I# w+ @
*************************
( M8 I& ^7 y8 n# {' s$ D8 w搜索:BOOL m_bReport;- `1 X8 i6 s) ~& q0 J3 K
其后添加:% c" D, {; b. K0 _7 W
CWndMenu m_wndMenu;
0 b7 S/ }0 n, C6 u5 ~0 R搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
/ v$ l/ l4 o8 y其后添加:
/ y U% j, X4 p0 p8 avirtual void OnRButtonUp(UINT nFlags, CPoint point);
0 f1 a/ f) {2 n5 x5 c6 g+ ~" T* k, r+ P2 E* B) u2 d( C
8 Z2 A. G, r( Z. H |
|