|
源文件中_Interface文件夹下WndField.cpp文件0 u! k7 h! p7 S6 V$ V
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )3 Z4 J; h8 t7 J4 Z% T
0 i/ ? S8 \" V! O. k
struct sItem" C! z% k$ b+ E1 {) D
{2 X4 z7 `2 d- m! D; q
DWORD dwId;
. U* D3 h9 a$ a7 K/ ^DWORD dwKind2;
# }# _. }( ~: U0 \! q# ~: VDWORD dwItemId;
; M# c1 c: B8 F1 T5 ? k) {BYTE nIndex;
u% U9 l# R/ a4 y2 `/ j$ |sItem(){0 \' n3 j3 Y! R$ t' G
dwId = dwKind2 = dwItemId = nIndex = 0;
6 U! |* b7 T) G: W}
" j3 I; M) E( u; _, Z2 m$ vbool operator < (const sItem p2)
6 ~8 c2 h# l# S* _6 v$ @- ]{
7 j) z5 W$ w8 F% H/ K) Y if (dwKind2 == p2.dwKind2)% `2 P( o& ~8 a: p4 \
{. a/ L% y d& L$ s; b% w+ x
return dwItemId < p2.dwItemId;
4 g( C( M0 p$ e- m& ? }else{
^5 G# j2 W0 Q0 ^; V" M return dwKind2 < p2.dwKind2;
" q+ I n8 R; U6 J# r: } } k) b, A. ?4 F. E) c1 u) p
}
9 z0 i" B( I* k8 ?' [& j s};6 d9 N8 S0 v1 b) X0 _9 l
class CInventorySort
( ]8 S+ R/ i# L, j) g& G, \{! x+ O% g9 x" x0 D$ N. l
public:
* }) A1 H6 C6 MCInventorySort()( W9 Y4 B# R Q, q, n) p
{
* r) k0 @/ Q0 F" @3 \6 t2 p m_dwPos = 0;
! e% M6 Q6 |* B; E% s0 C( X}
0 i9 M. }& S6 }0 P& X+ @' ^~CInventorySort(){}
$ |9 K3 _2 \6 H3 o. @' lprivate:+ r3 E! B0 x, L
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息- ~, F, \" n) A7 w" H
DWORD m_dwPos;
. G H) q8 f: m0 W g% w5 Dpublic:, S4 i, H. t" k( {
void Add(BYTE nIndex)
9 q$ x+ ^! W2 ^$ ~4 S6 p{
/ [# q' ^1 W- z2 f2 G- E if (m_dwPos >= MAX_INVENTORY). W/ r0 v8 _5 X9 Y0 c) J& J" h
{
8 D% d2 ]# e! K2 v return;% A; _% f% h$ O. b8 r. o* f
}
9 I1 u$ Q+ a; c( b m_Item[m_dwPos].nIndex = nIndex;7 K! E" x; s) S3 ^7 q1 i7 b
m_Item[m_dwPos].dwId = m_dwPos;" S* ^- E4 ~( o0 g6 j
m_dwPos++;
; K$ h2 Q3 n4 W; z$ x( Y}* }( u& ?8 L! e; l
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
3 k4 P% P# Y$ f# |( L{. R! A y5 E( S# d
for (int i=0;i<MAX_INVENTORY;i++): v7 m6 G6 W& m# H/ S7 F
{8 X. X- S4 l% P2 e6 [
if (m_Item.dwId == dwId); d# f! G5 W: g5 V* S% W0 T( P
{ |5 u- W% E+ n3 C% `+ d) L. x
return m_Item.nIndex;1 `% @ s8 U5 J, L7 ^8 Q3 P
}
- [0 C- A, p I: z6 ^- b7 n }3 x' j5 t3 q0 c1 |8 C
return 255;& a3 r" j( q5 N8 c/ G1 u6 Z
}/ l Y. Y1 _8 m# L
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置' }8 R3 X* N# [$ p9 M* f
{1 c/ E* S: j' M( m6 R6 `
BYTE nTmp = 0;" c; V ^0 K% p i4 s& N, R
bool bDest = false,bSrc = false;7 n! ] f% k( b" e
for (int i=0;i<MAX_INVENTORY;i++)
& J, P2 L0 o; W* ]; z. s {' E3 F7 w+ D/ G; k! `8 z T
if (dwSrcId == m_Item.dwId)+ Y$ J6 o% K5 j+ _
{' P; e# b' e! Z7 o& f/ a
//id相等 则 改变对应的dest和src
% n' p8 q% s: j6 y9 F nTmp = m_Item.nIndex;
6 C0 L" [. S" O- g! H m_Item.nIndex = dest;" D: i/ @, Z3 r7 S5 H+ I8 N
}
1 n& K; C3 a) t6 }& v }
& f/ F h* q9 z/ G2 m3 }7 x6 R7 O //临时数据保存完毕,交换开始
. O, K) q5 P& X for (int i=0;i<MAX_INVENTORY;i++)
, S& M7 g! S$ _% i- W9 `0 N1 | {
$ }: D& p* U# A' w0 h/ u5 X3 M4 Z if (dest == m_Item.nIndex)
/ }: H: }% p1 ~ {8 c5 z1 ^% z" W1 O: t
//id相等 则 改变对应的dest和src
# a& }: N$ u& G5 l- r m_Item.nIndex = nTmp;
( s- ?9 C8 \/ _7 L9 x/ S) \ }1 M4 B4 B7 }' I. t* h0 H! Z4 G1 d
}! a" I5 D. h' x) ?2 Z
}
& a- l$ G9 @9 c};7 P7 w# ]1 c$ _/ Q5 r3 p3 J! A% D
-------------------------------------------------------------------------
: H- I- T4 N; a5 T0 h依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
; |: p7 \8 i" C5 }) v+ P/ Y搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase); ~* H# \1 T' [# J! H: X! k
紧靠其上添加:! B3 i6 Z/ M6 i7 G( D9 q' O1 ? C# z) T! d
if( pWndBase == &m_wndMenu )
. U3 s- _, B1 J m, S" d+ }{, s0 a% K" W8 A- x7 P9 [6 b
switch( nID )$ d) X6 [& M% a9 k7 ?! t9 b% q0 b
{' l% F* ]1 P1 T$ x% ~1 C) m* L/ {
case 2:
1 y5 ^8 s* Z. V; B {- \( r9 D4 [% u) B% [" [6 C( c
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);7 B2 D" ~6 S% G) ]* N4 U# _. A
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
/ C8 r/ f/ [- @' u! r {/ T5 E" l* D5 o' i" k; J
break;" d- c& B0 U& F3 x X! U
}
- w5 k% e7 z" U& d2 V4 b( U for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)$ k: R( R; U* r
{
4 X& E% N- z2 M" R! K CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
# {/ @# {$ y1 U$ b3 N1 z/ C if( !pItemElem )/ j, o1 {: b+ o9 j5 q
continue;$ O Q: K/ s: U" L' P6 i, s
if(pItemElem->GetExtra() > 0); @2 K# Z# v: B: E3 k* L
continue;
) d7 g# ~0 u- N( u4 }# E, V if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ( h3 @: |7 E# B
continue;. u7 [' ?0 |* M9 ?4 j
if( g_pPlayer->IsUsing( pItemElem ) )
8 W$ O. s5 Z. i6 c( t1 P1 A continue;* w! ~- `; w* H, v' r+ ]
if( pItemElem->IsUndestructable() == TRUE )
* [5 W! M, C: n2 E F1 s) y y% ]3 C {
( ^5 b0 K' S: B g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );5 a: T2 F% x( ?) j0 D
continue;
' ?3 W, G5 f% T+ z( d; f }
5 H+ d* V. J6 T- u9 b g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
0 M5 y: S3 }( q5 w% F }
) G3 I$ z0 U5 P1 v, r5 p1 H break;7 ^- E. ]- A( ]) g: s# p. q
}( Q: W6 l7 n9 ]: N
case 1:6 K: ~, S# o% F. K' ]5 J5 y
{
1 R3 U1 f! |/ T, v* ?) ?) \ //整理背包
& X$ _, X" n4 M //////////////////////////////////////////////////////////////////////////
4 g9 S6 O- y: O, Z/ ^1 } //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );: a2 o% N" x1 j6 }$ b
//////////////////////////////////////////////////////////////////////////
5 |8 p' \) G. t, D; n //////////////////////////////////////////////////////////////////////////+ j' x! f3 j9 J7 b( \: O" h- ^* a8 w
CInventorySort* pInvSort = new CInventorySort;0 A. [( s p' ?/ g' U8 F
vector <sItem> vItem;
7 h5 ]4 n* ?- x1 h+ [ vItem.resize(MAX_INVENTORY);//初始化大小
" _5 c8 N4 T6 @% L) ?+ t //////////////////////////////////////////////////////////////////////////
8 L1 ?6 e' n. r //填充数据* Q, M- V& g7 o6 d% c% s7 {4 M4 e
for (int i=0;i<MAX_INVENTORY;i++)3 o' g' V. s! f, N$ `! S
{
! l: t l# {3 i% C CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
, z& W3 n& \: s' P if (!pItemElem)
, |9 @/ A4 t9 ?- E A4 ?: p9 v {: @& P m" p6 G1 B6 V3 R! A- c
vItem.dwKind2 = 0xffffffff;
& A. U0 x( J, S0 U% G9 v vItem.dwItemId = 0xffffffff;% {/ M: D7 b+ N9 t
vItem.nIndex = i;
2 S* ]' [4 w8 b5 x# k }else {
( i/ l9 |2 ]: z0 _7 ?! G ItemProp* pProp = pItemElem->GetProp();
: Y* `" u( A) u6 `' @+ S vItem.dwKind2 = pProp->dwItemKind2;
. S" B0 M& _. \6 P4 \% @ vItem.dwItemId = pItemElem->m_dwItemId;1 z2 T+ Y* q; s8 [) \5 h- ~2 V
vItem.nIndex = i;
3 c* j9 P$ z5 l }
G2 _9 d! J x //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
: d5 S2 A, `! ?: O/ U7 W% } }3 P0 G) o2 G+ z5 p1 Y" ?0 T# V& v
//////////////////////////////////////////////////////////////////////////) E; z9 D, C+ G3 {, d
sort(vItem.begin(),vItem.end());//排序
3 x$ @" H7 M/ b. t+ A, b0 |; m4 E //////////////////////////////////////////////////////////////////////////9 J9 e2 Z" d1 |. F
//交换
+ J- m o5 R. \, ? for (size_t i=0;i<vItem.size();i++)' A6 C0 {( H2 }8 e! w, R( z
{
8 J3 n7 X) J- H. e/ I //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
& C3 a/ u; q0 }" \6 i pInvSort->Add(vItem.nIndex);6 A4 u1 f# r% q. f
}
: F T6 k- @3 r% A, h" x0 l BYTE nDestPos = 0;$ N6 f* a5 m1 ~/ R' D3 g+ R
for (int i=0;i<MAX_INVENTORY;i++)% K- v3 V; I7 ]2 C
{" r4 e% ^" `- q# n) H
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
. l7 d* [& {8 t* M1 v if (pItemElem)
6 r6 F* j( W2 ]/ L' L {* R& Y8 v' U* e) V7 i0 s
if (IsUsingItem(pItemElem))5 v9 e& ~. \" i. U
{- d4 @( g6 b; a! F
//这个位置无法放
& q! ]8 D& j) O3 o& f nDestPos++;
( V4 ^ t/ f9 f3 \% Q! x( m, c% N }
$ j0 o z) R) |( q- g* h }0 ~! B: A; T9 a f1 Z4 E/ h
BYTE nSrc = pInvSort->GetItemSrc(i);
2 Z8 w. @' M9 _ pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
/ W& H) s- K% x/ H$ N- P' v9 i if (pItemElem)
$ ]: {8 g9 t# q, {. e {* Z/ ]6 S0 ^: D) k
if (IsUsingItem(pItemElem))
, T+ y9 x1 U7 B6 g( Y {; Q/ t8 H. h4 Z. V9 V( j2 i7 ^0 ?0 j
//这个道具无法移动,跳过
b3 K$ ?9 {0 ^( v$ d$ {* m V continue;
! E, N2 j) f! ?9 ~* e9 i1 [ }4 Z& ]4 q% y, X1 P: l; p
}else{/ l' i* N0 \8 g! C x+ G
//空位置 不用动
# |4 O" M$ y4 ~3 y& F, @- K; M! a continue;$ A7 G A4 x% t* ^. M6 t
}
6 R, w: z) k% k4 {+ |: C //////////////////////////////////////////////////////////////////////////
9 u! q5 d! V' r/ s1 ?9 {: [ //开始移动) A7 N( M* c; D, S4 ]7 e4 R) A
if (nSrc == nDestPos)
/ M1 d* O' e9 R) e3 r' G {3 _( h8 r" O; U+ F, r
//原地不动3 Y$ V# g, ^" d4 s! l. X+ e
nDestPos++;
* D# l0 d, ]( a' W4 p) o continue;8 m1 ~% [' d$ Q3 Y1 a" l2 o
}
6 V- _/ C4 ~1 { pInvSort->MoveItem(i,nDestPos);% I3 }8 V4 u3 s6 J
g_DPlay.SendMoveItem(0,nSrc,nDestPos);2 ?. K" |1 J! \8 f
Sleep(5);" F' n f1 g5 n+ D [7 l8 L
//Error("移动 - %d->%d",nSrc,nDestPos);. p6 E, N: Y; s
nDestPos++;
* D; k. x7 X& a/ F8 y5 d }; A! ?, `7 J& t* S( N U+ e
//取第一个元素的信息( y5 l; h$ j4 P9 C! n3 p; N2 q* F
/*
. g5 n. ^$ k. @( M if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
9 a9 S& m" ~3 \% f# m' b" T {) M- } |2 m2 I/ J' ?0 b$ q1 L
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
( k; h& O$ Q( m, D% M$ b8 {( V g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
, Z7 P& D3 d% w4 r }% D, P/ i2 ^% L: W1 x3 U
*/6 W0 s" J! [$ K0 \ W, B1 \
////////////////////////////////////////////////////////////////////////// w$ r4 R7 g" [
break;# z5 Z5 {9 l1 g) _5 t
}2 @3 O+ f& g; K
} ; f' k7 L: F% H- G) a2 H
}$ j. T( u' Z& ~/ |) N7 H# N1 ?
m_wndMenu.SetVisible(FALSE);5 R$ o( g2 W9 c; q8 O% k
3 A* b4 t0 U& j2 N6 t0 b: Y! z
--------------------------------------------------------------------------------------------------------
4 `' \# ^: a/ m- C. Q9 b7 ]搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)% M4 C0 \/ V% v! v% M) f. j: N
{
% y/ r, S; n, k- P" e" V4 _6 S5 Y% rBaseMouseCursor();
- Y4 T, E& C0 z}
# `- a- Z" G4 c1 J5 g* E- P在其下添加:
7 L+ i8 Y J; A# h* R! _1 Svoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
2 r4 c! D2 l/ w{
7 F/ L! n, b# J2 ^" m9 t0 [' u; |m_wndMenu.DeleteAllMenu();
$ ?, B! D% |; d: v3 }9 R1 C8 Pm_wndMenu.CreateMenu(this);: |" y3 w0 S* h* W- D5 }
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");/ y) M$ \3 h/ W w
5 }5 C" \7 q ?1 ?4 A
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)): }- X) Z# R \8 N
{
3 I. I/ [) T; b" [4 K8 t //P以上级别才可以删除所有道具
/ Q, y. T" V; P m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
' t4 z3 U: ]0 n: L3 ~}
- W0 C1 H+ L& \% O7 `+ z0 xm_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );) d- @& D( u9 f+ H( Z
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );; i, Z0 r' a5 ~3 J* B
m_wndMenu.SetFocus();. ?' W; K% I& \% l
}
6 w2 g' ^2 R8 m1 {' z% B6 [------------------------------------------------------------------------------------------------------------7 I9 u+ z J7 ^9 D
*************************
) i$ S0 C- S# uWndField.h文件1 R! ]6 K* m. z* g. b7 l
************************* T4 O- F9 s6 G/ \* i6 r% m; \ q
搜索:BOOL m_bReport;
' Y9 W4 C: ] T1 Q3 B5 B4 y& \其后添加:- A+ `+ {9 P/ ?7 v
CWndMenu m_wndMenu;
! I7 F) N' Z, V% s6 v6 W搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);- a; d, Y, o' J7 m
其后添加:. c" ]4 Y) Y5 X' f( \- D9 t
virtual void OnRButtonUp(UINT nFlags, CPoint point);
4 L' Z7 Q. }" C$ m" ~2 _) W* n m
- v) p: Z4 V, ?: O; P0 {
! _5 x. ?' A5 n/ H6 O |
|