|
|
源文件中_Interface文件夹下WndField.cpp文件
9 i) b2 [$ P" L搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )5 ~% C$ i1 y7 ?; C7 l
/ R$ y8 }6 ]7 t( `6 c
struct sItem
6 U3 Y/ z$ f! z( i% W* ^. @{9 N5 F' k1 d0 I& h' M7 G2 {8 j
DWORD dwId;. j3 l% v M5 t0 b! X& k
DWORD dwKind2;
' _( H$ B1 H# p1 \! N: {DWORD dwItemId;
+ V+ D" _/ n) Y: I/ L8 o9 ^: X/ RBYTE nIndex;" L5 n0 n0 v* M. W8 N. r
sItem(){
! j2 j: t# [6 X3 v8 L4 V dwId = dwKind2 = dwItemId = nIndex = 0;
9 F& y2 d% G4 j' s, i b}
3 W- E8 f, r' ^' u5 B9 U% o; k# [bool operator < (const sItem p2)7 h8 E4 N, O! W- B4 C7 @
{
; `' K. L* {& V+ R T if (dwKind2 == p2.dwKind2)
5 C* i* V. P- Z7 f2 j. |$ k" i3 B/ O {
: R9 B9 k3 ~1 ]; ` return dwItemId < p2.dwItemId;
5 P1 i/ e: d3 d/ Y }else{ `' i4 ]- [3 i- z( k5 `5 ]
return dwKind2 < p2.dwKind2;& ^* _" m. i7 O
}2 u( \0 F x$ b. R7 q( {8 Q
}
/ e) ]( E8 A1 m4 L7 ^6 u4 Q% F};
" u! }3 W% I$ {/ c6 Lclass CInventorySort$ N2 `! x3 o% c, S
{) t1 C7 I& L" f+ \0 Q) u
public:
5 o2 N3 o: c+ R v4 m: o1 J/ p& aCInventorySort()9 v1 `- F K5 l+ i- m+ z- }3 d
{
' h0 ?0 {' z$ p1 d' E$ a m_dwPos = 0;! [: S# h$ N4 N( [( k
}
% S% x% R+ g& v w$ N/ k' \~CInventorySort(){}
. y& r& t3 Q5 P3 Kprivate:3 C4 x: I1 F7 s r' `& _
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
7 s) {9 d0 G3 ~2 `! W9 `DWORD m_dwPos;4 J, X# u" P' s' j2 Z2 ?4 ~1 `# C
public:
; {0 J' A$ t& fvoid Add(BYTE nIndex)
' s$ p1 U5 W& Z1 {; ?{
" F8 K4 [: h* l" D3 [ if (m_dwPos >= MAX_INVENTORY)% x1 s2 h5 f2 E7 d7 c5 z9 ?0 y5 F
{) |! Y' r6 G* ~- j
return; c1 X9 p7 k. d$ a
}
8 Z$ X L+ N @% F1 z( i8 k D7 v m_Item[m_dwPos].nIndex = nIndex;
5 M' j0 V# R5 l2 Y9 ] m_Item[m_dwPos].dwId = m_dwPos; s# s) f3 Y4 i: z: E
m_dwPos++;+ Z' I1 c0 X2 l& H
}
$ t: {; g& m/ x9 Z5 G& R1 e% o+ ^BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
5 }! @9 i! ?4 O9 a{
$ o6 C, d7 O# w ^- ^& }- r for (int i=0;i<MAX_INVENTORY;i++)
% H0 @) m! D0 Q7 ~3 u {
/ u6 i d1 Q1 J8 [. q6 @ if (m_Item.dwId == dwId)* S# C+ ^( V; }+ Y4 I" w& K9 b
{5 M1 ?8 I/ N+ A7 O! O0 h: B" X$ Z
return m_Item.nIndex;% l0 t' l% n% ?, E z0 c6 ?6 [$ j
}
5 G4 S# q# c/ Q5 F! y+ t0 S }5 ?! I; F [4 n
return 255;
% a# K5 ?0 I1 B/ R- R8 w}
4 S) P( d* ]. s% {void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置0 R) D" _, n' ~% U" [, {
{
+ X \7 O+ ]9 g0 c' E BYTE nTmp = 0;
& h8 J/ x3 K' N% d7 C, V9 K bool bDest = false,bSrc = false;; o2 ^) e @0 O3 `6 k: e
for (int i=0;i<MAX_INVENTORY;i++)
3 E* Q3 _" m1 f0 h5 U, D* F {
- f7 {; e3 p' v if (dwSrcId == m_Item.dwId)
q! d, s. s' e0 `- m: _; C9 j5 W, Z {; L1 g3 G* [9 f5 _ ^
//id相等 则 改变对应的dest和src4 z( q# N1 i! {
nTmp = m_Item.nIndex;& K: j# W; w3 y+ Q A5 v
m_Item.nIndex = dest;1 g; o. e6 j1 K* C9 c$ a- h; b( {) d2 e
}
& I* I, R( D8 F! Y; @3 Y }
9 p, Z; T0 O: m0 G0 N' }3 m7 }2 t( l& u //临时数据保存完毕,交换开始) O' k4 C& }$ n1 f' C
for (int i=0;i<MAX_INVENTORY;i++)8 p! |) E4 g7 K- T6 Z
{
6 z, X2 T$ d1 K/ n; l+ i" L/ f+ D: n* K if (dest == m_Item.nIndex)/ F0 W9 S5 e/ ~* ^4 @; Z, I# r- u" a
{5 _( Z; x. R( N( p* }" u* L
//id相等 则 改变对应的dest和src; t9 R7 Q3 t# k( i4 w# p6 s
m_Item.nIndex = nTmp;$ X/ Z/ L6 Y; m( q8 s- J8 ^( H6 n( d; H
}6 Q, j- U' \5 ]2 ]" v; h# D3 C2 A2 ]3 J
}* a' P0 p# |" ?
}( y& _( H+ x/ t) z4 r
};
8 i+ d7 l! U% x, ^0 M' q/ P-------------------------------------------------------------------------* _" t! [- p0 |2 O; A: L/ h
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
9 h9 T: Q4 M' A3 R9 d/ _* j* Y搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);* }- _' w, I/ L
紧靠其上添加:
1 s; Q( l6 K) E/ Nif( pWndBase == &m_wndMenu )
* E4 q5 v! h6 v6 |{
( @4 q3 {4 }4 R5 J+ ?( n) y. o" {' ] switch( nID )- R/ k4 j( d/ o) |7 [) y
{# x% G i# p5 \* [$ ^0 \' ^
case 2:7 w7 G7 K, K+ s/ `' c, f) _
{5 m: |7 n) M' I& P
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);1 Z7 _% `4 S7 A* s5 G' P {; [+ H& n) [
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
2 ^( G; i+ X0 `8 E {
( q! J6 k2 h+ A2 ~6 P5 B) g6 q) h break;
7 D/ W4 h" O+ C: @& s1 A4 ?& P }% L, R" W+ V) ~
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)# j* G2 B3 x/ ], @/ {0 ~- w
{) K- E8 l0 Y7 {3 ?3 F0 v6 I
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
+ _; o" L. E: ]" H9 a3 i if( !pItemElem )
. x0 M1 K6 I# j, S continue;4 C' |, H9 w, ~
if(pItemElem->GetExtra() > 0)6 b+ }3 }( l9 Q) j
continue;
1 h w5 J* S7 E% Y, Z/ G! @2 D& s if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
% E( \: A. `3 }! Q continue;, w8 R5 N; F M5 E1 \2 P! G
if( g_pPlayer->IsUsing( pItemElem ) )+ d; V# e! t4 x1 V* V* K' E, ?
continue;1 {9 h6 i+ V9 ]( J( |" E5 _4 t" N6 i
if( pItemElem->IsUndestructable() == TRUE )9 k" k" d9 S0 D9 u& w) F- y& v
{* ^/ ^$ Z9 I5 J( }4 t5 A0 k8 _; D: I
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
( B$ L- h4 g- B, _! w; H continue;: O# a+ g5 f$ F0 N9 U, Q2 Y
}6 V1 ]- Y, ?9 B X# f
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
5 l4 k9 s S! z2 L }' B0 `- i: Y9 u' V) ^% F% b5 @5 y: x
break;9 t. d( G. j' a! L/ u7 h& Q
}' N! u- S5 s/ k1 ^6 I" Z* y
case 1:
: n' E$ `& n1 c( p' D {+ N% m5 B4 O% t9 M5 c4 V* I
//整理背包
* y9 K/ g' [/ |# H //////////////////////////////////////////////////////////////////////////
# v- V1 u3 ?9 A r2 X( x5 c //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );' P( _+ m9 b, B2 C2 x6 R4 b
//////////////////////////////////////////////////////////////////////////
' g3 h$ X- C N8 H3 _0 z' h //////////////////////////////////////////////////////////////////////////
}: @# E5 L/ z: p. m CInventorySort* pInvSort = new CInventorySort;
( ?- p) F2 x8 w2 D9 x vector <sItem> vItem;
+ G3 o5 p1 l: S, `+ u; G- Z vItem.resize(MAX_INVENTORY);//初始化大小
9 c2 g+ V7 \; f+ ] //////////////////////////////////////////////////////////////////////////' u7 [* I* z9 ~" X5 S! Z1 F
//填充数据" P" W8 q0 v3 E8 T- Z% _+ l
for (int i=0;i<MAX_INVENTORY;i++)' J, P) a; E/ S. p6 w- F. O
{
, l# R2 G7 }% Z CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
* }; C1 u9 i$ J" d" p if (!pItemElem)( A4 `; N0 x* t' {
{; c" z* [1 z8 W0 F; @0 t
vItem.dwKind2 = 0xffffffff;
" Z% v5 P' |, z2 N vItem.dwItemId = 0xffffffff;3 }( d$ {( V* M
vItem.nIndex = i;
B* R# B2 |) k6 D, z }else {8 D+ w! a0 {6 |6 \2 x
ItemProp* pProp = pItemElem->GetProp();
R3 j4 ]# o: t( S7 O vItem.dwKind2 = pProp->dwItemKind2;0 v# s/ b% |( m( J" M
vItem.dwItemId = pItemElem->m_dwItemId;) T4 ]) P( a! T( h* w
vItem.nIndex = i;2 D5 F% Z; Z1 [3 W
}
9 p4 I ?0 v9 p* c+ H //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
4 ~4 |$ I$ ]9 y7 D% t5 r }
% e5 [/ C3 C. D1 K2 N7 p. B //////////////////////////////////////////////////////////////////////////
% \; V$ t; g, J9 m' N sort(vItem.begin(),vItem.end());//排序
: r1 c- D/ N7 D2 f7 i9 W) { U //////////////////////////////////////////////////////////////////////////
/ ^6 D& Z" o4 M7 W: H3 z //交换: G) b; C5 l' u( Z
for (size_t i=0;i<vItem.size();i++)" z- ^- G* K4 b1 y# q J
{" v$ n& n- X( q$ X' d; v4 _
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
% t( s1 |, Y! T- b3 i' q3 } pInvSort->Add(vItem.nIndex);" n: p5 X) L# j3 n, |, o7 p
}8 F- G1 ]3 j- U6 g5 N% H) y
BYTE nDestPos = 0;
! G3 A+ s$ ?: u: i& w9 F% o6 P L for (int i=0;i<MAX_INVENTORY;i++)% X* }* J: O, n
{0 _3 j8 O6 F. _
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);! z" ~: o* H1 F1 b. _
if (pItemElem)
7 w) E9 O7 N& Q1 V! a$ K+ l& c/ j {; B0 @' F- L* Y9 z
if (IsUsingItem(pItemElem))
5 [+ \9 ]5 a6 k; V& H {* M7 s; @4 S# G3 u9 L
//这个位置无法放% b* @$ X$ O7 L9 Y: ]+ M
nDestPos++;
5 n+ Z5 X# ]6 t/ E5 d }2 {) Z* z7 C: C, c P) Y" Y. H
}
! g+ a5 ^5 y- B5 M BYTE nSrc = pInvSort->GetItemSrc(i);
; d. a& d5 e3 g5 ^ pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);" L* m9 _% N7 Q
if (pItemElem)5 f8 J1 b& l& H6 Y8 n
{4 b! |$ ?; D: \. c8 W1 X
if (IsUsingItem(pItemElem))
9 t4 `. Z1 N# @, P4 Z7 \# D- z2 Z {
# g1 P* E' u' O3 J/ A: t! i //这个道具无法移动,跳过
2 q# Y$ L7 m5 e8 T( y& I continue;
$ H& O C" g. N/ n: i% m }
# z' K/ c; C7 K* f% E7 s" C }else{9 r/ a1 b. |5 z* w
//空位置 不用动
8 [$ p: P- P5 b6 z) `3 a2 t continue; D5 H7 c% v7 s% M
}! U- `1 D0 Y5 H" ]1 [- O) z
//////////////////////////////////////////////////////////////////////////
) L/ P8 u6 O8 @2 z //开始移动
# c7 m) u; \1 x4 b if (nSrc == nDestPos)7 q1 Z1 C: d! b0 X. p
{0 y3 Y. Q6 v/ w/ y2 e
//原地不动
' y. C: e. L% q3 I nDestPos++;7 ^( ]: L: N* R
continue;
) d G" K( O; ~# R. y3 b! Q4 Y }) k3 h) `' b/ D4 r; s c
pInvSort->MoveItem(i,nDestPos);. |3 i E O6 \( `
g_DPlay.SendMoveItem(0,nSrc,nDestPos);$ c0 n+ D. [& w z, z9 B3 N5 S, G
Sleep(5);
U; o& w3 R Q8 e# w) H6 V; [ //Error("移动 - %d->%d",nSrc,nDestPos);1 K0 S1 \# N+ |, h
nDestPos++;% z8 e/ a" J) { |+ V$ r. c
}
7 _* f6 D5 |- S' Z: k$ K9 w# ]. M //取第一个元素的信息
2 d# \6 l& J. R, {& m6 N+ C /*
3 a7 v8 Z" [9 Q% x0 d+ A! u if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)# `: ^3 u1 @8 q) S
{
1 H8 {6 L' Z: \3 X$ i9 U( q% A; x Error("Move - From:%d,To:%d",vItem[0].nIndex,x);0 k# w! `$ g- w0 [9 _' }3 @* U6 \
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);' C, Y/ v2 {: L7 A% V6 K# u
}
8 ]9 F. C+ u0 a$ O1 p R/ Y */
4 n7 E+ O2 L' B+ ]3 S2 }5 c //////////////////////////////////////////////////////////////////////////' E8 \; a2 V' E2 L3 l
break;5 E: V7 d! I% F) u
}
_5 y7 _( `8 l+ F } ) _" u5 h ^1 m, W" i
}
~4 M1 t* g6 S T, O1 Zm_wndMenu.SetVisible(FALSE);& _ Z( `1 ]: b4 M7 _
% u: u; k2 z+ T- c
--------------------------------------------------------------------------------------------------------
8 V* \5 j4 B+ w$ _搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
7 s3 z: E X& j6 j% o1 b{
$ }* f8 G- S0 l! M: D7 WBaseMouseCursor();* d4 G! X, r0 z3 `; g
}
: i5 d& h$ z* b5 ~1 l6 K, u4 Y: i9 I在其下添加:
" k: H5 [4 [# X4 V# ]) h8 Lvoid CWndInventory::OnRButtonUp(UINT nFlags, CPoint point): _, P- g( g9 z/ d$ {8 l3 T
{: h% ^4 p$ l) M& ]
m_wndMenu.DeleteAllMenu();+ [4 m/ ~1 F8 s7 b
m_wndMenu.CreateMenu(this);
. J/ @2 g3 ` A. {m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");1 ?- h9 o }# F. c5 n, r; X
" C# I/ B& S: p. r* r# ^
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
2 V% ^8 N) n" q- {! |{
$ T2 F! ~# E R2 g1 \. O //P以上级别才可以删除所有道具 |# I/ c" s( m5 V& y
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");# c* f0 s5 } D# a
}5 Z! O! s C0 a9 r7 }+ q0 U
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );$ F8 @3 R) i$ ?! h# I S5 d
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
' G. y- F- `) e! [m_wndMenu.SetFocus();
8 f! K4 \- }9 V! X}
$ B6 J' n% Y' J. T------------------------------------------------------------------------------------------------------------! ^6 I* q0 w# x$ |5 E0 _
*************************
: O1 f/ i0 t: O* w+ ~% D/ ~$ _* nWndField.h文件
/ D/ Y: ?$ T }+ D: G( Y*************************
4 j" B0 p0 k" v2 J搜索:BOOL m_bReport;
" }+ N& C6 U+ P9 E* G0 q: W* p其后添加:: k4 J# F$ O! j$ F& y7 e
CWndMenu m_wndMenu;
/ T1 R, {/ W9 W# h搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);+ ^$ @: P5 a; e/ H6 _7 e8 {+ B) f
其后添加:
$ V! p/ k) {$ E3 S5 Mvirtual void OnRButtonUp(UINT nFlags, CPoint point);
, @$ P" A/ ^1 ?& j0 x* r. g8 ~" \1 h+ b
' z1 P- T! U& D$ A |
|