|
|
源文件中_Interface文件夹下WndField.cpp文件
" N* V; q5 J6 u. Q8 v, ~搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )% ^* g# J9 t M6 {/ l! N' s
; [4 O" f& ]' e& }/ ^) ]" ~
struct sItem6 o3 F8 D3 U0 O* O2 e0 v2 K( `! j. s
{" }8 `2 [' g# B; O- O
DWORD dwId;
4 {* o$ s$ z8 y6 j: Z, J# ZDWORD dwKind2;
+ _, R/ `8 e$ b" dDWORD dwItemId;
0 P4 ?# i- d5 M2 C2 P3 m s$ wBYTE nIndex;
& e1 t6 L$ r. B2 \1 ysItem(){: T; g% v7 V2 I" z% D6 Z
dwId = dwKind2 = dwItemId = nIndex = 0;* Q% g: p C( }, T& q
}
6 x5 T+ h6 I5 G# z& Hbool operator < (const sItem p2)
& B- |+ }5 M1 Y" Z! C8 |{
! d, N: F" P) _4 S if (dwKind2 == p2.dwKind2)
7 q$ `! |+ H0 V3 Z6 K. r {
& E% D* \) h$ d return dwItemId < p2.dwItemId;
- u/ r9 v; L/ _% X! K/ p }else{
9 `) j* `4 H' i; n2 t. E return dwKind2 < p2.dwKind2;0 l; x/ k# B1 q6 Y/ V
}. a* R3 z7 h4 F8 Z0 {
}8 J& p- ~' D( Z1 y% o$ Q- J
};' M% c/ z; O# R$ Y
class CInventorySort) I/ v; E& J0 r+ E& X
{- o# W4 @, D( U# J- H3 d
public:6 b" u4 U+ J. b2 j8 t {
CInventorySort() V# H1 h/ c! A" J; Y! M
{# k. z% G* u' k) x; W
m_dwPos = 0;: O5 L7 x& p! y( B0 p) S% [
}4 n& v9 Y, P/ Y. w5 Z
~CInventorySort(){}2 c1 h3 S* G* A; R
private:$ m" A% `* q+ ?6 |
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息3 l! T' i' C$ v5 ~3 x Y( j! Z0 W$ \
DWORD m_dwPos;
4 T3 q( _! A' X3 A0 j& b% W1 f) u7 ipublic:
+ |' x# E+ j, Z) l' ~( ~void Add(BYTE nIndex)
4 ]! X# y, j, O+ O5 A{
8 g' ]. Z I Y" q9 r2 ^+ J6 N8 {; D0 E if (m_dwPos >= MAX_INVENTORY)
. H( U+ A% i3 n) h& u {; Z" s7 x% s Y6 O7 C1 ~9 A& b; {$ `
return;* X) z" i# L7 C' m
}
) c/ B$ p, N5 F5 P4 }8 m$ O' p2 u' r; x m_Item[m_dwPos].nIndex = nIndex;
+ }/ y3 i q+ }2 A6 Y% N" ], U m_Item[m_dwPos].dwId = m_dwPos;
9 j7 V% o+ b) Y+ X4 N; Y' | m_dwPos++;
3 N: p$ M5 K: v1 \) t0 W; O6 [}
u% e# |6 x( y8 @- R+ g$ z; lBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
, r8 s+ S/ n. ]+ a. G{) e b( P0 B+ N! l
for (int i=0;i<MAX_INVENTORY;i++)
( w2 I% g; @- K- ] {
" Z, W/ M% X8 d, V% P if (m_Item.dwId == dwId) ]$ ^" i( P" B
{; [' e* k: y% j% \) J; F0 N
return m_Item.nIndex;
8 f7 F. B# y/ L }
/ }% |: A! `" k1 {5 T# H4 V }
) ]6 p: Y1 l& ~8 y7 f( t return 255;
4 W8 F" k2 S @+ |' f) K3 p}
( p& y* s6 n$ x6 ^+ k) o: yvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
0 ?% Q$ k, ?" X' ^) Y{" F3 L9 Q& T y- C$ @ y
BYTE nTmp = 0; ^ \1 |% c8 i4 W
bool bDest = false,bSrc = false;
! L; J7 d" Q8 q! d. j) ?: B for (int i=0;i<MAX_INVENTORY;i++)
! X- t" B. R; ^: s7 n9 C {* s1 d Q: B# w" [
if (dwSrcId == m_Item.dwId)
?. C. L! B# y; v* K: T: f( ? {
0 v$ W" t* } o5 g: A3 u2 o //id相等 则 改变对应的dest和src5 u; a; L) [$ @6 K. c+ ]5 e
nTmp = m_Item.nIndex;. L- H$ l' U b( j; H7 r
m_Item.nIndex = dest;0 V# {6 e6 z3 o9 @% v2 U
}4 o. C# ~% F* y9 w
}: k) c1 X( b/ S0 \& ~
//临时数据保存完毕,交换开始
8 }8 G9 c. g8 y6 S$ ?7 f for (int i=0;i<MAX_INVENTORY;i++)
( a% a( I9 Y" W5 y {
% i+ G) I: _8 b( E6 {4 `4 ^$ I if (dest == m_Item.nIndex)
( @0 a) h* S9 [* n {
1 @9 I6 P8 T! I( J //id相等 则 改变对应的dest和src3 I/ d. `7 J7 Y3 I$ E
m_Item.nIndex = nTmp;
' S" z2 \8 G8 \) J6 u }1 P. F3 r* `& _7 l2 r8 v
}5 F% Y) d) l) g# `) f/ `! R
}4 e) S5 @ s% K W
};" U4 w# }; h. F' C" o
-------------------------------------------------------------------------, _! V7 p5 L( @( E/ d) g0 n5 k
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
( p) n% Y9 {1 H搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);' c, e- H7 \! W1 {
紧靠其上添加:1 r! o' ~ |$ V+ g/ o; t0 i) b
if( pWndBase == &m_wndMenu )
( h3 `9 u1 ]7 j3 e; O8 p# h& x$ x{
) ~9 l: D! {7 t switch( nID )
7 b* | d2 v0 \4 m {5 M/ G/ P! j9 `% J4 K5 A
case 2:: C0 a/ m. D, L r5 o& M
{5 G7 C: B7 t2 v/ n% H$ s
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);& `( Y& ^! T9 C0 J1 ^2 A+ J
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)) I% O9 h, M; C5 y/ b& d! h, @1 e( |
{
& R m" F+ c% y. u) p* z" X break;3 z/ Q; [# j4 C7 \. c
}
- n3 P' E# ^. X5 c& k! E) S for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)5 m0 B/ m+ O! {. c7 C
{
7 g7 T% g8 H1 D CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);- X: H: G( W: Z+ m q. V* \8 x
if( !pItemElem )4 G" b$ T& B$ h- _+ U
continue;' y# U8 L, z8 W7 |
if(pItemElem->GetExtra() > 0)9 T( H) {0 }1 C; o# }
continue;
' M9 Z% V, {, o+ o if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) " k% I# O+ l8 g. s# L7 r2 I7 s
continue;0 b8 G9 z' Z3 Y$ @
if( g_pPlayer->IsUsing( pItemElem ) )( U, C7 h0 T* }9 K4 F1 q: {" @( P
continue;
! L+ V5 K1 `: n; e6 l! u; k1 ]- c if( pItemElem->IsUndestructable() == TRUE )
# T% {1 h7 k% i, M* ]1 c {# G# ?, r! S o H7 P
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) ); `: ^7 f: G' I) e
continue;% O3 m* I2 v' ^: V$ x2 b/ N
}
6 L( u4 w1 O3 w: _% b/ T g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
9 y/ Q- X# ~( H2 @- d9 n }
8 F1 W+ M9 N/ S break; W6 ~+ {: {7 h
}
5 j _1 D5 w9 }5 [* h case 1:
( x1 R' |) l' J" K {
6 ?3 _0 Q( ] p. @0 W' b //整理背包3 a9 Y& j. e" H& H6 T
//////////////////////////////////////////////////////////////////////////1 S3 n1 ~1 b& T ^8 q
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
5 D, p$ U( J3 `7 ^" ?- h/ g3 _ //////////////////////////////////////////////////////////////////////////. q: Z4 y; @: S% B! G
//////////////////////////////////////////////////////////////////////////
3 v% E) m, F3 ^$ ~. D CInventorySort* pInvSort = new CInventorySort;
, r8 ?2 _% w( |' F5 X2 W; s vector <sItem> vItem;
6 e2 t) x+ ^$ B9 e. p1 Y7 x4 f vItem.resize(MAX_INVENTORY);//初始化大小
! P0 e) G. B! [. Z; ^$ p //////////////////////////////////////////////////////////////////////////: J6 r7 N K1 w4 j
//填充数据4 H* I& t2 M7 Q) d9 |: Q8 |; d
for (int i=0;i<MAX_INVENTORY;i++) [, ^1 \3 X* S4 ]
{, A+ i2 _5 ^! E7 O( _7 M) E( }
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
S" o3 m; L F* a if (!pItemElem); p; T, [$ V' O6 x
{- ` Y6 w( S7 U% n8 G$ j
vItem.dwKind2 = 0xffffffff;
$ _: M' e& z7 g7 Z/ V; k vItem.dwItemId = 0xffffffff;/ \9 l" r* z: K
vItem.nIndex = i;
3 P" l! t% o6 m$ L" N5 n }else {9 {0 i% ^/ b4 _4 L9 R$ G9 l4 E
ItemProp* pProp = pItemElem->GetProp();
( E3 V( ?+ H0 H8 y4 d' D vItem.dwKind2 = pProp->dwItemKind2;0 P' T/ q6 u# B) a1 H( }( ~
vItem.dwItemId = pItemElem->m_dwItemId;
' o5 ~$ A! L6 s vItem.nIndex = i;% i3 I1 z0 m8 u9 I X
}
, o! ]; |1 O4 C: F6 @3 o8 _% G //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
8 L8 @8 L( s; I4 C. U& n# V }6 R# j. w9 \! q% H- A) L
//////////////////////////////////////////////////////////////////////////
& g. I% H( i6 b% a- p sort(vItem.begin(),vItem.end());//排序
+ c5 L* u' D4 U3 z* m* {$ h /////////////////////////////////////////////////////////////////////////// e( l# K+ S; a6 u$ q
//交换
$ [' M# H$ Z2 I) W7 |# g. \ for (size_t i=0;i<vItem.size();i++)1 ^% e; A, J0 M. @
{& W1 d9 R: U$ Y0 e
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
9 \& g0 d. ^# T/ j pInvSort->Add(vItem.nIndex);
6 [0 d( @1 G) h6 p& _2 j" r }
6 m+ Q& H$ l% Y1 K BYTE nDestPos = 0;
3 X) g+ d( @ P( R8 {6 C" l for (int i=0;i<MAX_INVENTORY;i++)4 A2 D2 Z0 ]; a; K, Y, e
{4 ?1 R) N6 ?: c/ q5 {, `7 H
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
/ d; H; x4 Y3 M! ^) ^6 P if (pItemElem)
5 x' K+ Z$ c! w; c {
! E o( G# x3 h if (IsUsingItem(pItemElem))
& F! t+ @( K' t3 i: l1 h { {( |1 B" v5 {6 ^+ D" ]6 `
//这个位置无法放9 \) O" t# V4 _0 g; x
nDestPos++;
~( A8 I# N* | Z4 E9 D }
5 A1 f; I/ `8 E5 M5 U" | }
4 z! L( J+ u- n- } BYTE nSrc = pInvSort->GetItemSrc(i);
! u8 `! Y5 {3 j% I% j/ A pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);) l4 _. ]$ l& s3 M
if (pItemElem)3 B3 |1 x+ n U" T
{' Z* E) y. `0 h7 |. Q+ k
if (IsUsingItem(pItemElem))
; b+ b) S; n# o+ {: h {/ M/ p" P3 k2 L. o9 t9 R( t
//这个道具无法移动,跳过
1 t: ^& Z; c0 [9 ~# ?# @ continue;
/ F$ n$ q. X& c3 l4 @9 S }/ E- `! y$ X7 R9 F4 F" g
}else{
) r+ O( k1 r$ b1 d //空位置 不用动
2 F( V9 E2 N7 \/ h6 Q: l! @ continue;
k9 g5 N( b& Q3 N7 h' v }9 n% g) z: B( f* s
//////////////////////////////////////////////////////////////////////////
( z: ?. X: ?* U) n //开始移动6 o r7 L+ f; \
if (nSrc == nDestPos)4 _+ t+ {! C5 e. N
{: |- Y: |- c* N a$ \8 ~$ _
//原地不动! S* b" M( Y5 n! Q" T7 f
nDestPos++;
. F" l8 r4 e. M" g0 F; s! j continue;
5 g& j/ Z- x2 g& k J. Y" X% ? }& X# ^$ W" i v6 v
pInvSort->MoveItem(i,nDestPos);
9 }4 Q9 J0 E/ l' g! D. i g_DPlay.SendMoveItem(0,nSrc,nDestPos);6 `# o9 k" }" i# K3 X, Q
Sleep(5);7 p9 g$ E+ m$ s: ~* T
//Error("移动 - %d->%d",nSrc,nDestPos);7 @ E7 D# a$ A! c6 E0 w& Q
nDestPos++;
7 ^1 B" m/ ^( r }
. E' s% o8 V' A: S$ z" C& |6 D //取第一个元素的信息 h5 z- F" `4 H+ e2 |
/*
! v& N7 b3 V: V" K4 o* G if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)- L" s) p* w" G o
{
; G# |$ B' r$ U; @# C7 b. d Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
h7 r$ b1 J3 r3 v7 \8 n, m1 Q g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
( R% z/ ]3 a% s. S q" k }) m t n* c; V6 B! o; o4 X
*/
6 J7 k4 q) m" r, |5 r' r //////////////////////////////////////////////////////////////////////////
( t3 P. M& E6 n' } break;# T1 ^% o' P [2 n, V+ C- J0 J% ^( N) n
}
% A. K2 c% p& B2 e3 H% } }
9 ]* I- U/ c$ ]; l: F( l* v}( K# ? w: a+ ~7 Z% r1 G# r
m_wndMenu.SetVisible(FALSE);
3 ]% L( b) U8 r0 u s; J: Y
! \7 X' r G5 |' M--------------------------------------------------------------------------------------------------------% G# R9 n/ `! c$ e" R0 t
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
; ?) @' t0 [2 ?3 }& f{
8 I9 N" L/ U5 U6 WBaseMouseCursor();
9 V2 Z5 m/ N8 j3 D% r}/ w! q9 \5 B/ T7 v/ w
在其下添加:
- r( r! M5 p/ F2 v2 avoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point); P5 P1 a5 _% e v
{
; }9 Q+ ^5 W. O, M! x' P4 K. Mm_wndMenu.DeleteAllMenu();2 }7 n8 ~9 n6 q9 s8 Y& L
m_wndMenu.CreateMenu(this);
! x6 g+ J0 ]9 Im_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
! I D+ _- @# r7 r M9 S
P' X- D3 X" Z2 eif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
- F' @* |" |7 K4 s{
0 Q4 n% ?; [+ y% i //P以上级别才可以删除所有道具
; |0 X. m& `0 z, m0 ^ m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");' ?. Y" o# w3 R4 T1 q* z' A- K& f
}
% `, \4 B! j/ f' f- t. im_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );: F+ s9 ], t* M& l5 m# R* M
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );; o: g- G+ T( l; x
m_wndMenu.SetFocus();
& s6 ]* D. W+ C2 n' `2 g4 _}4 k3 c5 U" t$ j8 [$ \
------------------------------------------------------------------------------------------------------------7 {2 \6 q1 B* c/ p6 e8 ?1 v
*************************
+ R1 n. t9 z7 I6 F4 _WndField.h文件
9 T/ f2 g; j0 ~*************************
* }4 C1 t/ Q8 r% r, o搜索:BOOL m_bReport;5 j( `* t! P* W4 U1 D2 e
其后添加:
, |9 \1 X( w8 V N# ]0 J2 KCWndMenu m_wndMenu;& N& h4 D, F& A5 q- P0 K
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);# B* K r( D' l0 Y. f1 v) ]
其后添加:
* q6 x6 N# s' Z' v$ xvirtual void OnRButtonUp(UINT nFlags, CPoint point);, O0 y# H8 P* [% t2 X& C
/ `: t) ?" [% @8 q
1 d* q# `: s5 W1 X6 h9 @1 ]
|
|