|
|
源文件中_Interface文件夹下WndField.cpp文件
: t* }+ V0 ~ W# P* u5 L0 H搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )+ t2 T4 a- W& T F/ Z
! W- u n! T( x. E" pstruct sItem0 P$ H" P4 Q/ _7 F8 ?7 C4 N
{& |* ^6 z% n+ y0 @8 O P
DWORD dwId;+ a N2 D6 r' R! t
DWORD dwKind2;
% `: a0 }9 v2 c% `/ h2 z- E6 }9 l& KDWORD dwItemId;5 ^& Q4 }- @/ J
BYTE nIndex;+ `1 [, T- s7 X: {, M C6 q, D. M
sItem(){
: }1 r) k+ L; ^) p; O dwId = dwKind2 = dwItemId = nIndex = 0;% }, ]8 [5 R+ i1 T$ r' ^2 O& s0 W
}' g0 q" V4 |% c
bool operator < (const sItem p2)
8 f. F" q' M# B{! I0 B* m7 m- X3 U6 t3 H# e- v
if (dwKind2 == p2.dwKind2)8 k- m5 N! \0 g$ `) i5 Y L
{
2 w: ^; A+ l1 ^8 q8 w% g8 y% z return dwItemId < p2.dwItemId;0 w6 S( X' y7 u
}else{
9 x% o$ ?/ {/ @! p! I% h return dwKind2 < p2.dwKind2;! Q, I% |6 v2 |( J
}
0 [6 Q, z' ?, |8 s3 a& V' ?2 d}
/ [0 d+ O# ^+ ]2 e};, T6 f) L7 x2 J/ S& }
class CInventorySort
2 y+ ]& f; W% N A) ]" V; s) T& q7 y{
3 T5 Q+ T2 d' m9 r0 `: vpublic:
0 q" z1 U" G2 M3 _9 l3 bCInventorySort()
3 b: w/ \0 l1 ~7 j{
( U9 I* x: D% O8 W# [0 i- @ m_dwPos = 0;
' z2 ~2 f* A5 M' B+ O) U, B}
4 m6 N% Y6 g7 w' f~CInventorySort(){}* ?0 l% c7 j2 _) {2 F8 i0 o
private:
7 v! d, r/ W2 f0 `8 G: _sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息8 Z0 R- t4 b* ^1 J4 ]( ?
DWORD m_dwPos;
3 m& L* G. I4 B8 X* [$ F4 \public:
( v! q1 J7 c* k3 Y/ J) R% j+ ^1 a4 Fvoid Add(BYTE nIndex)1 g# j) G+ N K( O" `- G! ?
{0 J- E# n/ [- i1 e. e7 `7 O
if (m_dwPos >= MAX_INVENTORY)% q9 z [6 _+ a
{
8 D' F+ i; [* v" W/ m$ u return;
- h" u+ X4 y3 q0 s8 R+ g }
; R& g/ @% d/ Z m_Item[m_dwPos].nIndex = nIndex;6 p) W& u6 p- u( }( u, x
m_Item[m_dwPos].dwId = m_dwPos;
1 T$ G" i/ S5 {: @ m_dwPos++;
0 X7 L' V0 `) C8 T' _}
$ ~' ]+ r, F! Y& f' `1 h" h/ N- F( OBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列3 \/ ]$ R$ Y/ N8 S: f
{2 R( P* C" D" Q& N' H) n7 U1 q. t
for (int i=0;i<MAX_INVENTORY;i++), E+ n& T$ G8 E1 a+ r' k3 T
{, N, L2 L; c/ h7 Y% H; O( X
if (m_Item.dwId == dwId)1 f2 Y) i: u% ~4 w
{+ g/ N1 x. Y8 m) H+ @1 z
return m_Item.nIndex; E' @" A) n7 i$ f3 F, J8 ?; A
}
; M) I* M \$ h; w }
( i: w5 \4 q3 J j% U6 g return 255;- ?1 x8 S! q! |; Z
}; S9 L( T/ I0 m2 f
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置1 W3 S6 w7 `& b$ X# p- l; S9 U
{9 `& |+ l. N7 u+ w8 W
BYTE nTmp = 0;
g; r9 T k9 l7 q) t8 d O4 a bool bDest = false,bSrc = false;& l& p9 P) A3 \& l4 v; L
for (int i=0;i<MAX_INVENTORY;i++)
8 [8 V s* Y. _; {0 N) w {, [5 W5 g' I- ]3 @, t
if (dwSrcId == m_Item.dwId)0 k% U4 `0 b7 m$ I$ U
{0 M; h9 }5 I/ t( c% {3 Z- ^2 U
//id相等 则 改变对应的dest和src
& |) {4 ]7 W; U3 b6 v: w% z nTmp = m_Item.nIndex;: ~( a0 H4 q+ L" b" l
m_Item.nIndex = dest;
! c% }# R$ p, H5 a3 r }
5 l; ?/ N, ?+ Y7 |7 D% \1 z1 ~, g }
/ ~4 l( u! A* [+ G; \ //临时数据保存完毕,交换开始
5 O }7 M! y$ w. |. r for (int i=0;i<MAX_INVENTORY;i++)
( O! z4 [1 b4 R5 U! h+ q# W {! a# E- G5 E: U* {' n
if (dest == m_Item.nIndex)
5 n* W8 s9 U3 L8 s; @& D {! M6 S( Y5 r" u- f; P6 N. s% |
//id相等 则 改变对应的dest和src: h6 T F% U/ T+ {7 W# y
m_Item.nIndex = nTmp;
6 B2 Y! M2 n) D }
4 Z$ j3 E, M/ ?& [( ^3 q }1 S- S4 L/ h t/ e- E
}
! W8 b$ {$ w: S/ J& V};. R7 L0 _, ^- _6 G: g+ N8 n! a* M
-------------------------------------------------------------------------1 {* O/ T5 J/ r$ j( \) }- T @- w
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
1 ~/ X' m y" M3 S$ b4 u6 V6 P搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
/ o5 h+ I! p9 e紧靠其上添加:
. W+ l5 s& h; E2 Fif( pWndBase == &m_wndMenu ); l% c3 Y4 m2 f- U% \$ g/ O, l) {% Y; S' ~
{5 j7 ?" h( d" t- X; Y
switch( nID )! [, z& T* D# Z; m( l4 s
{5 `* s) y! s, ]& G* I- Q3 O
case 2:7 Y) V( V5 _7 I2 S
{
0 F: K1 J3 r `/ @+ d0 m! }' ^8 s //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
9 h4 w3 v0 a2 \$ Q1 ]. u+ c if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)), [8 n/ O2 t U) ^! Q. }
{
3 u* ^5 V6 }" R' K$ h0 F1 G break;* ~3 T- I% A% a; ?
}
- _7 l2 U1 S9 T* s" V' i for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++), o4 X _+ q/ q
{
( B* n/ z* R2 R( M/ v CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
4 A Y$ N- m$ g! i* ~ if( !pItemElem )
. g+ d7 T: ?* a W [' \$ w, _ continue;! E! @, a' f% D- H# o z
if(pItemElem->GetExtra() > 0)4 ~) N8 N8 b3 R# q& j; O# m
continue;2 e, H( P: a) T* R9 @! g0 i' A4 ~
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ( u; `/ X, {7 [$ S4 ?
continue;
' o5 K) a0 @/ b$ v# f if( g_pPlayer->IsUsing( pItemElem ) )
# I9 A1 B$ r$ R continue;
2 h `6 l" x8 k! B4 t- ^. R7 U/ V* b, H if( pItemElem->IsUndestructable() == TRUE )9 j0 h, c9 M$ a- h+ G1 c
{
% T$ j" S3 u+ O1 h4 @3 k1 w8 Z8 i g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );* \" x6 T0 O e2 \$ j4 J5 h
continue;$ n& e# K. H4 a0 C! L, ^# }
}$ ], _: U8 R$ ?5 g, N9 t' L; Q$ Z
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);3 q6 m# U6 H2 G% v
}
4 w1 a. u, F' X2 l+ `& f- \ break;
+ I( A6 @- D6 ^; _ r2 c }6 b5 p! f8 y9 V- n$ d4 N+ |
case 1:
4 }7 O" o% Z( J {
: E' s: @( f; F: q4 L# j& e //整理背包
3 O: P, n/ s1 j7 }2 X //////////////////////////////////////////////////////////////////////////% v- C$ }5 u" g% v
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );0 l, n$ o) Z$ ^6 X- c$ E2 V
//////////////////////////////////////////////////////////////////////////
, ~4 X: L+ r3 L0 o) ? //////////////////////////////////////////////////////////////////////////
( d# t# ^1 Y c+ a, C6 | CInventorySort* pInvSort = new CInventorySort;
+ b& V" v% r* J# g. ~7 Z vector <sItem> vItem;( ]6 v7 B8 { e" _- x
vItem.resize(MAX_INVENTORY);//初始化大小
0 {: G" o; t/ U( C/ Z //////////////////////////////////////////////////////////////////////////
; P, b) K7 h; U1 m6 W4 q4 ~ //填充数据
/ _$ I6 b2 O! a. @2 ] for (int i=0;i<MAX_INVENTORY;i++)
' J# U. Q2 O O$ l! K/ [2 J {% |4 W; I( l" a
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
3 @0 f" I3 j$ }- N if (!pItemElem)) t8 J4 [3 C2 ~- F4 }3 ^
{
$ b: h7 j: D3 E8 l+ b& k vItem.dwKind2 = 0xffffffff;) ~9 s8 H0 X. c$ N9 Y; T
vItem.dwItemId = 0xffffffff;
7 l% p' ~& M' _5 w$ y% ] vItem.nIndex = i;
9 o" o x, A8 E( j; i" I; } }else {
Q6 y" C' B2 P" P$ \ ItemProp* pProp = pItemElem->GetProp();3 B* }9 f& Y: i7 e' }
vItem.dwKind2 = pProp->dwItemKind2;8 ~$ B" ^% w* e+ ` z
vItem.dwItemId = pItemElem->m_dwItemId;
# Y8 @* `0 ?" r, J0 j) T7 T7 z vItem.nIndex = i;
6 `1 R8 o Q( t }4 W5 _3 ?5 d; s, F
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);2 r5 J, i( R6 L& f# X7 h; A
}
0 F% R3 E; J" U4 l+ ^ //////////////////////////////////////////////////////////////////////////3 b% t" ?6 S2 X+ E$ x' K( \$ p
sort(vItem.begin(),vItem.end());//排序
, n2 u( Y+ l' ^' z0 _# i //////////////////////////////////////////////////////////////////////////! t: l* e4 {( ^# U
//交换1 G: \0 e+ S5 ^( ?9 t& M! e* O
for (size_t i=0;i<vItem.size();i++), Z7 s, N6 h8 H
{& Y5 N8 K% [ b9 s0 b
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);/ ?0 L% T. l$ I) B6 |9 T/ D
pInvSort->Add(vItem.nIndex);8 X2 R1 z; k9 S- a. g
}% f5 o; a" b4 M- J2 u2 Q
BYTE nDestPos = 0;+ \4 T- R7 _5 Y$ h, g3 K7 T
for (int i=0;i<MAX_INVENTORY;i++)
% V' ]; ?! s: |" m* a3 A, O+ a8 M {
5 P; _7 i, z+ X$ w CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
7 G. v# X* s$ w" D! y+ B if (pItemElem)
" q4 ~7 F0 C% T- g {
. M3 {# `" W3 I1 Z0 d if (IsUsingItem(pItemElem))" u* a" F0 E) S$ N; W2 h- ?) R
{
# n) i. V/ I* J# T; F5 r: N0 ~ //这个位置无法放* p8 _ I6 _( t6 c9 ~- {( T% h
nDestPos++;* t7 ^2 q6 Y' q) _6 a' f
}6 G! Y! Y: |( a! P
}
" B% m' ]) Y! O! B, U BYTE nSrc = pInvSort->GetItemSrc(i);8 `; N& F- T$ T/ g- B4 q a7 [
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);7 R5 D) I0 Q k5 n, D3 k: K- O
if (pItemElem)
4 ^; n0 u* }6 Y {
0 Y; y# d0 @: O6 s if (IsUsingItem(pItemElem))5 [; c7 d: B; c) @$ k/ p
{5 d |1 i% G% ^5 |' ~' V# p8 u4 k, P
//这个道具无法移动,跳过9 \# }7 p* x( L! H- j
continue;
6 v! w. N' }7 p! Y$ D8 _" Z- M+ W2 B I, i }4 r5 J+ g8 Z- N0 Q
}else{
2 ^$ o0 s; U( N7 z6 L1 W3 x //空位置 不用动2 y9 u" I+ x9 G# a0 i
continue;
" p- d1 s5 g7 | }; }7 B- [6 g5 r0 J
//////////////////////////////////////////////////////////////////////////1 J& z5 x7 r4 _. g2 E6 C( v
//开始移动! c d" z% a. ?* F
if (nSrc == nDestPos)# d/ m [+ `3 \) Y" q
{: B! |8 A: ]. R6 c. B4 n
//原地不动
% Z: V5 x* D$ S- G7 p nDestPos++;/ T7 }5 Z5 V( W$ C
continue;
( g" c0 @9 E4 F" c4 T$ Y5 G7 q }
+ x& x- q8 C& j9 }0 O pInvSort->MoveItem(i,nDestPos);- a; x1 H' g! j+ Z ]1 @
g_DPlay.SendMoveItem(0,nSrc,nDestPos);: n+ R( D$ j! G5 \ r/ m0 N* M5 j
Sleep(5);
& z( a( Q; K2 a T0 x //Error("移动 - %d->%d",nSrc,nDestPos);
, N$ T, e% F+ V0 ~% }! Z) S" A nDestPos++;
9 W% B \, l3 b3 X) `; R( R! f }
4 n$ e6 z: z7 B G/ F; l+ x* T* M- M //取第一个元素的信息; @+ n( O0 X& T+ a4 i" c
/*
4 Q% V n9 k" Y: p' w$ w if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)) i0 E* |5 K3 H$ j! J; d
{' m3 g0 k$ X" h- T( l
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
4 F2 g+ v+ R- W' e7 v g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
* g1 V3 H, X% [; s" [' ] }
5 a: \% U9 I) m9 T4 a- R0 b */
8 J- j0 a2 R5 R1 V S* B7 q //////////////////////////////////////////////////////////////////////////
8 s; K& G3 Q9 s3 g break;
. i" E, W( U5 W1 z/ U% n4 G+ E }
2 _" |. m8 o3 m; N+ T } 3 e5 _, N* D2 Q7 o* e
}. x" M; r& J: R* y, Y
m_wndMenu.SetVisible(FALSE);. P d' m0 x9 Z( Z) @; `+ Z
( {8 ~! R( v/ k--------------------------------------------------------------------------------------------------------; O1 k6 R( i' f3 t( T) m' l
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
9 u8 H8 C; ?' S8 Q+ j. C8 l5 J{
: a P* k$ x4 f7 a7 ]2 \ PBaseMouseCursor();) g- j/ P+ Y/ b; F$ S J5 A5 {
}7 U' B- v" C% i" m2 B; @2 Z% i
在其下添加:
. a2 A8 ^) B( N* M+ H5 ?8 g. |9 ivoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)2 y0 V+ L7 L+ l" v7 S# F) h: P
{
; t/ w {- [7 S ]8 ?4 ~ D1 rm_wndMenu.DeleteAllMenu();
* _: w( q4 I3 b; n) l4 a9 Cm_wndMenu.CreateMenu(this);
- T; Z+ X! a( Z& z6 O) v8 ` Um_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
( L4 `% Q8 x i" X
' z8 I8 c0 ^6 Q' ]3 L+ uif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))( l4 Q) y. [. V# i) j4 H9 O
{$ M/ v# L( Z4 K6 l9 p8 Z9 k
//P以上级别才可以删除所有道具- I$ L, `; g7 |# U( W1 X3 R3 s
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
& l( @1 i6 }+ v; ]1 x( M: R}0 R8 Z* [6 K" k" I
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
" P. i! \1 U- u5 ~; E) r& vm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
( W' r/ E* Q4 |5 ]) l2 Dm_wndMenu.SetFocus();
' k; f* |* w, S; }! G" K" P}1 T1 @+ l) T' @7 A& e
------------------------------------------------------------------------------------------------------------- ]8 _: ]1 n4 |6 ]% a
*************************
1 v7 R5 K! r) A8 d% i) ~4 IWndField.h文件
4 Z& S: q6 k) K- V- [# L0 g4 b2 e*************************
; |/ a/ d# ?6 K9 S- _8 b搜索:BOOL m_bReport;
$ G. z2 D) w( P% u4 V$ Q3 [其后添加:
( r: n7 N. Q) J# Y+ bCWndMenu m_wndMenu;
8 ~' V$ o: ]3 f$ C9 o0 e* R搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);( z. @0 R8 a& x# s) o' M+ E
其后添加:2 h/ \: {0 b c9 z* R( `
virtual void OnRButtonUp(UINT nFlags, CPoint point);# E- a' |' u' p: Q5 R$ ~
# e* d% ~1 Z! x* O3 `! g. Z
5 x# h9 m+ |% V, Q) j7 O, F3 j+ J |
|