|
|
源文件中_Interface文件夹下WndField.cpp文件
) m. v; o, T! K1 T# V搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
# ?9 l6 ~4 z2 A9 I+ Q6 H# C8 s7 u; [" }- ? Y6 d* X
struct sItem# Y, p7 n0 V9 Z2 P5 `- N; _* r
{1 y. Z4 c2 h6 B, p
DWORD dwId;
& e- d6 C/ G* ` BDWORD dwKind2;# `0 m, U! H$ e0 s% i5 H& J4 B
DWORD dwItemId;! j) Z3 [$ W7 U
BYTE nIndex;
6 p3 Z% G4 S5 s& O! i1 j1 asItem(){
9 A( q( |$ J3 J: g dwId = dwKind2 = dwItemId = nIndex = 0;
2 G( f# L1 Q5 Y; R) O+ u$ t}
5 v7 l' ?3 Z q3 v/ s9 B; tbool operator < (const sItem p2)
9 M0 h& O# t& |" r' i{
- v, q" v, q |; ? if (dwKind2 == p2.dwKind2)2 B; @: O9 g j) ]+ [
{2 v) [$ }" N$ F1 f }+ r
return dwItemId < p2.dwItemId;
& F$ Z d! f* D% W: Z" j* A+ n* Z }else{
# S" [9 M- D' y, Y$ M return dwKind2 < p2.dwKind2; Z' `4 u z- H
}
* }0 ~* P3 }6 b/ I+ m}
% o, u; }- P# T8 z, H% o- X};: M3 I+ c! S; J( z' X/ M8 ~
class CInventorySort+ {& d5 p6 w2 M# C/ w
{( }: ~* l* B) \
public:
1 O$ p, U2 V0 UCInventorySort()
/ H. I$ _* ^6 k6 I{
$ d: R, p% _# w5 t" o+ M: C m_dwPos = 0;+ @# g9 ^; I x4 `$ H# }' f5 W* ?0 P
}
( T7 \7 t- j+ u& ~* { U~CInventorySort(){} l6 q+ V' f" }+ Q
private:
5 l2 x6 b! H/ t2 q' SsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
! V! w5 n( a% ?4 c GDWORD m_dwPos;; s0 f: f: j8 q
public:
* B5 Y% i, P' }/ m/ u1 Nvoid Add(BYTE nIndex)6 P5 t) K, h! ^3 ` I5 u! ?% c
{
& W2 k4 u7 l9 S5 ?" a: e if (m_dwPos >= MAX_INVENTORY)( t% {, i9 O3 I
{& J+ W% s {, L7 n
return;7 x" y6 o7 l" V" v/ h, R
}2 X: N; w1 |. {/ d% H
m_Item[m_dwPos].nIndex = nIndex;
1 h5 m: ?" ~5 ^: ^8 [! r m_Item[m_dwPos].dwId = m_dwPos;; F1 c" q4 }8 N4 M% d9 W4 T
m_dwPos++;
* k+ U4 j* R& e% I# Q0 f* G2 C8 S}
+ z% g& u! `/ u& @. ~BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列9 y5 K5 a- I* i( i
{# p3 f" [9 n7 B& P1 w0 z
for (int i=0;i<MAX_INVENTORY;i++)2 E) V: _4 [ w/ ~( v) x3 b8 e4 q. h
{4 i* G- C7 T5 P# k: d2 F: L
if (m_Item.dwId == dwId)+ e/ h: E' P! x" K% `
{
7 \! H6 Q- D! I& S* e1 M: C/ B return m_Item.nIndex;, ^' P& f8 R, H$ S- K
}! N& y+ W7 C/ g% k2 j: ^( j
}
* ?# O6 q D; R) E, t! ^2 X4 \1 \2 X return 255;
- G- Q/ Z- b5 V, l& s# [}0 y) Q- l/ K& ]
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
) m5 X& H, p5 ?8 r{
! d9 M6 v9 G: x; t/ X BYTE nTmp = 0;
' L3 P: n- d" |, [ bool bDest = false,bSrc = false;
( @& P# b$ @: R2 r for (int i=0;i<MAX_INVENTORY;i++)
/ t0 q5 T" @' t7 | q6 y {( b x- f7 R! E. R1 Y
if (dwSrcId == m_Item.dwId); ~, }, `$ X. h a( k5 o& L2 a
{
2 S5 X0 K9 t1 u. D' T //id相等 则 改变对应的dest和src
! W1 T% \0 @7 I1 a' O: D1 L nTmp = m_Item.nIndex;
5 ~( t. s$ g% G5 u6 g6 V# c m_Item.nIndex = dest;
* d* a, W6 W2 o' Z: n* l }
' |. H$ P& N& y8 I }, h/ ]. S& p9 Q3 c6 H, C
//临时数据保存完毕,交换开始5 x9 F$ O6 ]- s/ S0 A5 S: O
for (int i=0;i<MAX_INVENTORY;i++)5 {5 Z! [9 h, n
{8 r# ` c L: B. O
if (dest == m_Item.nIndex)
7 h" ?# w) ~4 f& i0 x5 c7 g$ Y9 i {
% f! K k- D+ P //id相等 则 改变对应的dest和src* C; \. n( B$ e' P6 X5 @3 }! ?
m_Item.nIndex = nTmp;
* P! k9 z/ J# a0 q }
; F2 z7 m2 a% z0 P7 h, m$ | }
9 t" M7 _4 C% u2 Q}3 B" f* @+ m. m
};& G- h; u' J! y Y" H, p8 {
-------------------------------------------------------------------------% f) g! f j3 E8 u5 i+ f" |1 k) w) D
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
* B$ B$ d( ^$ R搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);( z( ?: {% J$ D; a
紧靠其上添加:$ r9 k. {7 V# z8 k" b3 c
if( pWndBase == &m_wndMenu )
! w7 C6 j2 G }% x" `5 j. M* }% W{+ E9 O* `" n8 a* \0 t r
switch( nID )
: }+ h7 B5 ?6 y$ ^' Z) ?5 K# a {' |. z7 m" W# f
case 2:
* u: |" x/ d; a# N; P7 U e, x5 b {) e5 {: J$ K5 _
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
1 L* S) g9 Q/ s' R% O, T) y if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
& P; m2 ?( U' h G {/ p1 a+ e9 c. Z+ W, ~2 v8 u
break;! s' P6 c7 O! I% O
}
b( v8 i( p7 L0 c for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
+ G# |% G" ?: n! B) u {
9 f; |- ^* k4 g [2 l# Z CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
9 H z$ N9 B, p* d9 N$ ^4 Z if( !pItemElem )
) z: _& @. g8 Q! v continue;
( i) R' W* q5 Q7 v- F2 D& g% f if(pItemElem->GetExtra() > 0)
( W6 q, B+ F- y& _! d0 c continue;
2 u. Q, R6 J+ R; t& I% P if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
% d0 |6 r/ l2 I/ s+ Q! [ continue;
$ e0 ], ?! y1 j7 ?$ X3 I# t, v' \ if( g_pPlayer->IsUsing( pItemElem ) )
! W, ]8 h' m' |5 e continue;8 ~9 }% f' @( ` I# |- I) |
if( pItemElem->IsUndestructable() == TRUE )* Y( C. f" w' l2 g$ H: @+ q
{+ k9 t8 P/ h4 d. Z- `
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
7 P8 r4 Z/ x0 R+ D8 W& M9 p6 ?+ R! ] continue;
, i$ F" M9 h% _7 R8 o0 K l% L }! G! _8 Q- V6 ^; P9 A
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);% |2 M9 P1 Z# Y" C- c3 K6 r
}) }! m/ x" G' B3 }% x+ P
break;
7 p9 i0 [/ t4 J4 x$ y, y& T }' V: s% }, u- N+ f- j& y7 I# S# V
case 1:
0 n3 {- F1 v9 }9 ~: q' e( g! x {
G5 k) x+ {; V( ?( F- J8 _ //整理背包
+ Q0 @* ?& w; W$ l$ h& D) s) I5 k' [ //////////////////////////////////////////////////////////////////////////
4 f2 q: I' e7 J+ l5 P9 z //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );5 T7 t) }% }4 @. b" U
//////////////////////////////////////////////////////////////////////////
& C4 C& Y& L: N) h //////////////////////////////////////////////////////////////////////////
4 H+ q* O2 r5 r, V0 M3 X" N3 x1 Y CInventorySort* pInvSort = new CInventorySort;
7 H h5 \) r& d6 y9 o- ~% Q vector <sItem> vItem;
5 }4 t, p, z9 V# Q' p1 Y vItem.resize(MAX_INVENTORY);//初始化大小
6 K& v! U0 I! F: s2 k //////////////////////////////////////////////////////////////////////////* N+ `) v7 G0 t& p8 \
//填充数据% q3 \$ M4 e7 F) Y: J: s- i9 d4 o
for (int i=0;i<MAX_INVENTORY;i++)& I: P- l5 x, {: _3 `
{, f% V' l8 K& i. U! @ O3 L: n
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
+ d6 m7 o7 `2 h if (!pItemElem)
' T2 E# g, X4 E1 Y6 Y6 X {
9 x% p C. s7 L5 b! R, R vItem.dwKind2 = 0xffffffff;
3 r# S; ]7 B0 t' e, z vItem.dwItemId = 0xffffffff;
) O+ z. P E) p vItem.nIndex = i;1 ~9 a+ q( p: @& c. k) j. y6 Y, A5 k) V
}else {
* ]# g5 s0 d! B3 v ItemProp* pProp = pItemElem->GetProp();; h0 g- M/ c2 b' L6 T
vItem.dwKind2 = pProp->dwItemKind2;
5 ?) m' m. L, x+ m7 W4 y vItem.dwItemId = pItemElem->m_dwItemId;4 \$ |/ W( v9 \' |# f$ M% {& b% L
vItem.nIndex = i;! |& X1 O0 J; |
}
- u1 R/ Z0 `/ q Y" v2 P //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);$ e1 k, D' u$ V
}# ]$ s* y$ K9 r" a5 N& J
//////////////////////////////////////////////////////////////////////////$ l) C. v5 g6 f' m: Q& d
sort(vItem.begin(),vItem.end());//排序
: C5 o+ t5 P! F( l& t: m& j5 ? //////////////////////////////////////////////////////////////////////////2 B+ r4 e% K3 E! |2 m% n! p+ b& S1 r
//交换, c$ h9 g. x% P2 o& t6 `6 y8 D
for (size_t i=0;i<vItem.size();i++): R- t! s5 t9 ?: W1 h
{
5 z$ e( \ }) \" _& X i5 r; m0 y1 H //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
# a' b: v' e- _3 H7 {2 T pInvSort->Add(vItem.nIndex);
2 }0 n( s* p& p: @8 H, v7 ^( | }/ k, F+ W- j. O( V* j7 S
BYTE nDestPos = 0;) a8 e1 D- _) |& A' n$ L
for (int i=0;i<MAX_INVENTORY;i++)( q0 p2 J& \ D8 x I, Q
{
5 p( ^4 o N- V9 B* \% ^ CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
% j( l( |' Y: b+ {* I# Y if (pItemElem)" l) Z/ t* u1 }" w" {
{5 _4 \. T5 @1 U; {0 U6 M5 \, D
if (IsUsingItem(pItemElem))5 u7 V2 J8 s$ y8 x8 M: a. _
{
9 V2 s2 Y' l- M+ x7 x //这个位置无法放5 L9 J1 _! t0 ^+ [3 a
nDestPos++;7 ]1 S5 O7 C( J8 c1 n5 r
}# R( y2 U9 V' k4 D
}
# M! {0 O6 W9 e) `: M& r BYTE nSrc = pInvSort->GetItemSrc(i);" v1 E, Z$ R# x3 |0 W* a; N
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);) G. [: m) Q+ d% F3 _/ {
if (pItemElem)
2 g. r% ] L4 `3 R( F {
A9 S& A6 y1 c P7 k$ h R if (IsUsingItem(pItemElem)). b* c5 d7 Q2 M& {+ ]( u2 _$ U
{4 w$ q3 j( w: z. v) K5 H2 t
//这个道具无法移动,跳过1 [4 F& K/ `) g6 T% ]( j; E
continue;
2 ~6 J" D, p/ t5 n7 I& b }
: k3 g1 g1 {3 r9 y. n }else{% \ C$ L2 ~3 ~7 I) G S) f/ @
//空位置 不用动
9 u& |; a2 J' W2 }) U continue;
' P$ {8 U1 N& X4 M8 ~ }
" }- \' R4 h/ E //////////////////////////////////////////////////////////////////////////
& M( E# q) u4 j* }4 M h2 B //开始移动
0 f0 G! ?# o7 @ [( x if (nSrc == nDestPos)! i7 y9 k+ B4 n
{/ {# Y/ `( b a) Y r5 U
//原地不动8 t% A% J6 ]1 N! V0 U* \
nDestPos++;+ @0 g& L9 Z6 x, R1 A
continue;! X7 }1 y( n U0 W( f6 w, C6 N9 O
}
6 B3 n$ o* ~* t/ @1 G f pInvSort->MoveItem(i,nDestPos);* g1 T; x* I# E2 Q
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
9 L' L4 x) r/ | Sleep(5);; D1 g2 _' H# ?
//Error("移动 - %d->%d",nSrc,nDestPos);$ Y+ L" X6 n- w3 F; K. V
nDestPos++;6 p1 q5 r/ A: a. k
}) I. X) \8 q* t0 ^8 C+ I
//取第一个元素的信息+ |% P( Y# a& {, T2 F
/*5 j3 _" @: t9 O5 {) e
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff): I8 q4 E1 {- n f7 g' J x
{1 F) G1 l/ B. C4 q- y
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);
% }- x6 }, [9 u7 u5 C! ^- q5 \6 n g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
/ X U2 k; e& L }
& m$ ^; h* X9 Z |7 K& U D2 } */8 k6 I8 P4 h/ `+ \) A0 G0 v
//////////////////////////////////////////////////////////////////////////9 m2 E0 o" g W O
break;
3 L( G+ p1 ]4 l. ~ A( B }
: O$ {% U3 \! u; t* U: u } 3 \( {4 a2 l, t' U! D% _- F3 |
}. ]( D6 _/ J9 ~2 t1 t w$ L
m_wndMenu.SetVisible(FALSE);
3 ?) B+ T8 L$ b' @" O) x/ H
3 w [! i! H e c$ @4 {--------------------------------------------------------------------------------------------------------; N; a5 |8 V+ `2 V$ q1 R
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
- K8 u' W! P; G4 [$ s. e+ z0 G{
, I1 e; Z- J3 D; _; J& K) ABaseMouseCursor();" O4 a& C$ h( ]2 q6 {; ?; R
}
. w6 f. M5 y1 ?* \% J7 [* U在其下添加:
0 W, a, E* k* m, L7 L9 |' Mvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
# d( j: _4 Q2 G9 G; q{" x1 E3 V9 i; n
m_wndMenu.DeleteAllMenu();
% Q( ]* B% {+ c" @5 W6 m# Sm_wndMenu.CreateMenu(this);
$ \/ O5 A* X. a" zm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");) M! O- N) U" f( {' y+ a: q
) i! N9 o& K q' l8 m. L
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))( h5 P8 n+ z9 l* |
{- @" X& ^6 O+ Z/ ~8 Q
//P以上级别才可以删除所有道具6 s1 {0 I) Q2 Q& n, m
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
6 b% `7 t+ q: j# O/ c/ ]}2 N$ o) ^& o, l
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );1 C9 x/ [7 g0 J# G, u* D- i
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
' k9 _4 }. [$ d, jm_wndMenu.SetFocus();6 F4 x8 l5 g( c/ |* x8 f& {4 s# D
}
! o' L9 A4 o7 F5 _------------------------------------------------------------------------------------------------------------4 N2 b0 o( v9 F. Q) x
*************************
$ \3 s8 y8 V# @' F, ~WndField.h文件8 z; i+ }( H1 B( u, K
*************************' P _: t V; p( l. T7 v
搜索:BOOL m_bReport;% i. G' z c) Y# I4 j
其后添加:
% [' F- g# B% Y/ d; V1 O) S5 OCWndMenu m_wndMenu;. C" G* E X* q" w
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
# n/ w+ q; b' N) }# w其后添加:2 Q$ h: r. C2 ^4 G
virtual void OnRButtonUp(UINT nFlags, CPoint point);9 {' ?$ ^/ t$ ^* j$ v/ N' T
# [6 F7 J1 d/ ]( ~* A i2 E; C+ q1 w) {2 m% j* Y6 Z
|
|