|
|
源文件中_Interface文件夹下WndField.cpp文件$ N! t8 E# g) ^0 v
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )+ D$ _4 o: W3 b3 p l: `
K3 l& I, C3 j6 Q8 V
struct sItem
) X1 [$ Y. K% H0 u2 q{
5 U1 k$ N/ [3 fDWORD dwId;; p/ T% h2 _ R. d6 [# u1 u
DWORD dwKind2;& D. f% N9 I. k3 H2 F# I. L% j
DWORD dwItemId;, v: f7 H H/ G5 K( D! f! _8 g
BYTE nIndex;& b# M J" n9 e
sItem(){/ {4 J9 |, g. q+ _ \
dwId = dwKind2 = dwItemId = nIndex = 0;
0 A6 Q( I# b5 ^9 A# H}
% A6 k2 L4 z4 tbool operator < (const sItem p2)
* K' O1 D4 f; N$ M' _+ R{
7 m7 Z6 E5 F; X: K& ] if (dwKind2 == p2.dwKind2)
" \5 [2 f0 p! j% F7 _- M5 h {/ I! [( Y- a- ~8 u4 a
return dwItemId < p2.dwItemId;, m: b5 M* L+ l; k. [
}else{/ }7 {9 p: c8 f0 P }
return dwKind2 < p2.dwKind2;6 b$ a1 F c3 t/ n& `3 h
}+ l4 q9 k' v3 x+ A
}
^4 I4 K6 K1 z- X2 N5 ?3 k5 v};
6 F" q( E; _, bclass CInventorySort- k/ l4 v1 S# ]$ B* s# M0 O$ q
{
0 l+ E5 e* }+ N, }public:
% c0 l2 K9 I! F& Q% e% F3 z) iCInventorySort()
/ Q% p* [0 r- ]# Y- P{8 G. L3 z3 ~) V# N4 H
m_dwPos = 0;$ X2 A% Z% B$ [2 h; e( D- Y
}- S6 I2 l6 s+ k- o& B- ?! e; P/ L
~CInventorySort(){}
( I; V C6 M k7 ^private:
0 B2 i! [7 s7 ?* w) tsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息( q N) i! |, V$ B' o
DWORD m_dwPos;
3 E; j5 w. k9 @" V: J9 ?) ppublic:+ K, u3 R8 N% ^: |6 T" G1 o+ {( U
void Add(BYTE nIndex)
) h4 J: w1 N7 Y$ t{# P, G2 q: e0 s- b. G
if (m_dwPos >= MAX_INVENTORY)
3 j1 @8 s8 Y; x4 z6 O9 p {7 c# u/ R2 H+ h8 v; D
return;
( \: n) d8 C) v: x- w0 J& s }' M" }; M- t" G7 B5 r; N
m_Item[m_dwPos].nIndex = nIndex;9 c2 P. N2 _2 x* i/ S7 m
m_Item[m_dwPos].dwId = m_dwPos;3 }. d# v% J B. Z9 K
m_dwPos++;
% F) F2 K& ]$ |, U}
/ W# G. ^9 \" m* ZBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列- Z% F3 J- i5 M+ b. A" _
{0 t0 _3 f' R4 i% h: ~: u
for (int i=0;i<MAX_INVENTORY;i++)7 a- R# P& S: r
{
0 J2 `/ v# `& `+ T' U) e, S if (m_Item.dwId == dwId)
; v0 G7 u* V; x; l2 ]8 b {
. q" B& @. {- d& u return m_Item.nIndex;
2 Y0 V/ F8 D0 d& |+ {* b( O }
E h. m" |! l5 n% T }
9 P5 ^( l; W( M9 A return 255;
J1 r. @; R$ x. R( U9 b# [. \8 L$ ^# U}! E6 H" ~' c. ~5 p e4 u
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置/ ^1 A/ c. ~: T) x& C7 k
{7 {# e$ g& e; |7 @+ \; z7 z9 X; a
BYTE nTmp = 0;8 N, h, \- s- j, N H! A
bool bDest = false,bSrc = false;
9 [0 ], `6 D" v$ o5 E# s for (int i=0;i<MAX_INVENTORY;i++)
1 ], A- w# t& s/ L* z% \) z {6 S v% F! ]+ l: h1 C% G9 u
if (dwSrcId == m_Item.dwId)
( U3 F* N7 P: W4 Q% ~. v0 h( Q% L {/ {8 {; O! F( [, y
//id相等 则 改变对应的dest和src' E. L* f( a6 A1 W6 |6 Y0 ^9 f. s
nTmp = m_Item.nIndex;
; X! C1 q% z6 p7 t5 m9 D, y7 ` m_Item.nIndex = dest;
6 d6 h7 d8 e$ U2 r }
& {0 B8 L7 y, w! u1 x4 t7 u6 E4 F! [ }' b, E1 ^. ~) f, G! f+ ^/ X1 s5 ]
//临时数据保存完毕,交换开始" l9 Y! Y4 p* N* o) ?$ s
for (int i=0;i<MAX_INVENTORY;i++)% h' M- w( I+ T9 T9 Q R
{
0 r& H. u, q" \9 [) J4 W if (dest == m_Item.nIndex)3 ]5 i' P4 K8 t8 [. o
{+ w3 H" ^4 T) L$ l
//id相等 则 改变对应的dest和src- z9 N- [6 y! p) e, `
m_Item.nIndex = nTmp;
- U' Z- x% X" _; Z3 ?6 R- `- d }* R' A, k" b+ M! u% x# @2 Y
}
1 K. {+ B/ E4 J8 z}7 ?, Q3 S9 f7 r m9 n
};, \& f @8 s0 z4 A% W7 p
-------------------------------------------------------------------------
% u# S* A! V- F& B0 w依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )2 c8 x: O# T4 V" d
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
; L/ z. _ _9 G$ a+ o紧靠其上添加:
/ F a: \1 D: `8 ?( d+ ~/ t/ H4 Sif( pWndBase == &m_wndMenu )5 ?+ E' ^8 H n2 r0 P) H
{- }+ F, n2 q m9 E/ S; v6 v
switch( nID )0 Y" c& [& s/ t" b; @+ W
{ y) k$ C" P7 M# f3 L
case 2:' d/ ]$ @2 p9 ~# o5 d; M
{3 k; j" v1 A* i' q, x
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);% Q; l5 ^. z- A) o6 ?
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
! |2 L3 f( h; }9 `, F {# r0 }5 m9 ]0 u, o
break;
) d4 T% z% `( o }. o+ o5 t$ {8 ~/ z2 M
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)/ k( V7 X5 s9 w( t( x
{7 g" z8 x b' s, o+ ?
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
. Y! _$ ~9 [6 }; k% F, e( W if( !pItemElem )
# @5 ~) w- C; c4 | @0 w/ ^ continue;
/ Y8 ?8 ~3 b! u: S: A. P6 i: o: F if(pItemElem->GetExtra() > 0). h' Y- [; `! n3 H
continue;
4 ^+ o( W: ?, O+ p if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) * m9 a" {" t3 e, C" s
continue;
, f; F- M. [$ @& [" O) w if( g_pPlayer->IsUsing( pItemElem ) )& g+ y( n/ Z. }/ O
continue;
& p7 y5 _& g+ n) d1 U6 `5 } if( pItemElem->IsUndestructable() == TRUE )% I* H- v3 [/ O; @8 e
{
& ?# J2 b& h& y l7 T7 C3 Q g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
( W8 w4 p0 ], A* n k. b5 O continue;
, I/ V, ~- B2 W }: x" A% N3 Q# R: ?8 m( t1 |
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
5 d @4 a% D; z+ I( `1 Q, D }
0 o R% ]. m* ]4 r( a break;/ Y/ L% ^6 b: P, C# C3 C# V
}" K! y1 w5 x% l/ a8 T5 `
case 1:
! m. ?) S% [7 u( S {$ R/ F# r$ H' R9 b
//整理背包
% X4 |* k8 s6 t7 r# [; W //////////////////////////////////////////////////////////////////////////- {! t. P, I0 V2 v( _
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );7 R5 y1 J) F5 h+ |, k! `
//////////////////////////////////////////////////////////////////////////
7 S0 w, ^: q" A, ^+ r- y7 d //////////////////////////////////////////////////////////////////////////
+ w6 j( l7 i1 x8 Q# A5 x4 X CInventorySort* pInvSort = new CInventorySort;
/ D: m. |# m- T vector <sItem> vItem;
! k# R1 k1 j+ X- O/ `2 ~. l vItem.resize(MAX_INVENTORY);//初始化大小* E; V1 J1 O/ p" d* W
//////////////////////////////////////////////////////////////////////////
& t* n! P+ v0 [/ V# a* N; A3 a //填充数据
% u$ i( r+ P! \. B7 E$ V/ L for (int i=0;i<MAX_INVENTORY;i++)+ l+ z# M3 T' {* e8 ]
{( R) Q- }- Z# I/ d, I/ ]
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
$ ?2 T) U* l2 s if (!pItemElem)
) \ p' F- B6 D/ `( P- ] {
. g6 E% F! d; W7 E9 _0 x vItem.dwKind2 = 0xffffffff;1 R0 [% W R# R: p J z
vItem.dwItemId = 0xffffffff;$ P& y. U2 l/ O, t3 J( ?* Z
vItem.nIndex = i;
: d# L* d) X2 v( C- W% d }else {$ }. _" q" q! \+ r$ U0 q* J
ItemProp* pProp = pItemElem->GetProp();" C3 ?+ E( Y' q- v, w9 g# P, r
vItem.dwKind2 = pProp->dwItemKind2;8 e- q3 s# s! @, H" e2 Q% c& n* ~/ L, u
vItem.dwItemId = pItemElem->m_dwItemId;
- t; z: k u# g# F4 V# I6 q: d vItem.nIndex = i;; Z, ^* d& L4 @7 Z$ V9 o6 N
}8 T# a% }# G# T4 y+ }# V# W, W
//Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);/ l; D% f% ?7 ~3 |& F% D
}6 n5 s9 `, ?1 b0 s
//////////////////////////////////////////////////////////////////////////
* ^! s6 D5 i% x) [ sort(vItem.begin(),vItem.end());//排序
2 c% ^3 k0 x7 Y; n2 q //////////////////////////////////////////////////////////////////////////, Q6 Q2 T `; Q0 g! e8 Z# j- [6 z5 w- G
//交换- v4 q: R* V8 i& h7 }4 t3 w
for (size_t i=0;i<vItem.size();i++)
; I6 H: G) H5 \2 w/ h5 b1 ~3 B) w {
* ?8 k' f% u' |. ?# Q9 E3 m //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);" R. r t( [# I- S c- k
pInvSort->Add(vItem.nIndex);1 i% R: \8 } ^$ t
}- W; X- S0 s3 `1 |! g3 C
BYTE nDestPos = 0;$ {" ]1 B. E- H, I7 m2 A8 I) S
for (int i=0;i<MAX_INVENTORY;i++)
# P1 b! k# ? |( q6 e$ g" B {
. L) r% |) o6 R8 t5 b5 h! K" k CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
1 \! @! E2 k' Q/ V3 Z if (pItemElem)7 F' \* P3 {' N9 {3 j) X
{ `& C! T. t4 g' ~7 }& t7 S
if (IsUsingItem(pItemElem))
, U k1 J' K! G1 m1 L! u& s$ Y% C {/ E8 W: \! x4 A
//这个位置无法放1 p# W: g: J8 E4 Y& N
nDestPos++;, S, n X) h a
}: a4 d8 C- x; M% C4 v
}
& V6 l, f4 u2 l0 }9 a7 d* p' h BYTE nSrc = pInvSort->GetItemSrc(i);
$ G1 u! X" E+ P) n, _ pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);# K! j5 c1 o4 Z# B$ _% T3 L3 M
if (pItemElem)9 j* d1 E8 p# s, _ b* S" @
{* q2 }0 b# }- F9 V* J( `
if (IsUsingItem(pItemElem))8 |! N7 _) m% ^* q
{
" q& N2 \2 x) g //这个道具无法移动,跳过; O W+ D4 T! Y$ i/ x! A# G0 R
continue;
( i1 v, J9 M6 u+ F6 c; ~ }
+ M# P, m7 T, c V2 ~0 D; E }else{" {: s. H- c6 A7 i; B4 j
//空位置 不用动' z6 w. o1 z7 d5 a
continue;/ r" ^2 U2 h; p2 {
}+ c8 ~: C( r% P) O1 u
//////////////////////////////////////////////////////////////////////////
+ g6 b* s$ T1 `$ d5 V$ A2 n //开始移动
' R- x, B3 N# h. h- a* g if (nSrc == nDestPos)
; S9 p& q7 a5 q( A {
/ [% B" E/ ]6 ~, ~! ]7 k- t. B //原地不动! b' F9 H K0 m/ G/ U7 r/ N% E
nDestPos++;
- T q: j# `, ~) k continue;/ z( h) J- E- {( Q" B3 Y, l1 L
}) X! W3 ]0 H h* y; X( h
pInvSort->MoveItem(i,nDestPos);
6 ~' b$ B! d2 q# {1 Y* k# G: K g_DPlay.SendMoveItem(0,nSrc,nDestPos);
- L& q% ?, s9 y* p Sleep(5);8 A1 r. O9 t1 g9 }5 X
//Error("移动 - %d->%d",nSrc,nDestPos);: U& @0 t8 \+ D
nDestPos++;
4 |6 _8 }: x7 \. q7 d+ m3 ~7 t }( X1 {. H; j( ^- q; X
//取第一个元素的信息
7 k/ c4 T$ T2 h" {5 g" z /*
( V. i; D+ G1 c$ o6 [5 B( Q/ K/ G$ m if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff), X' J. d% E _/ H4 T! ~" N
{9 l8 Y x& q! |/ r& Y
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);0 Z& a: N- c- L
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
' H- @' H) w+ T: T( l8 ]. J2 Z+ v }" I$ q" |( Z) _ W/ ?1 H
*/
! D7 z2 ^9 L7 D //////////////////////////////////////////////////////////////////////////
$ Y; P( U9 n7 X; \( w4 u% |6 q% J break;
/ A$ t5 Z3 ~0 E }% k$ W) y' `; V! L3 K2 T5 ~7 f
} / M* ^* r9 o" ~ E
}/ G! r3 Y# ?( h
m_wndMenu.SetVisible(FALSE);
; z4 u, h. [7 b7 g6 H
7 E$ X; s6 v: _; g* b--------------------------------------------------------------------------------------------------------# r) i8 s: y( H- b7 E! U* w
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
' D' ^$ H) h$ q; W0 j; Z# _{
4 ]5 X) k* f* \7 f1 iBaseMouseCursor();
3 Z1 Q9 D5 V. w3 n, C8 v6 t E}
1 t: s0 G3 ^# \& k0 J8 I) ]在其下添加:
( O; h1 R" ?; q1 B* @void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)- {; O- Z( ? u' ]
{3 R' F5 k) y3 F8 o
m_wndMenu.DeleteAllMenu();
$ w- Z5 n3 X& h' {m_wndMenu.CreateMenu(this);
, I* P6 t' n. }% em_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
" Y: m( v# Y* @/ l/ K
# n9 e; r1 S9 t3 O- E. I Y2 Qif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
4 L* }* V& U& U" l1 g{, p' e' m* H+ w
//P以上级别才可以删除所有道具
/ ^1 Z: Z. n% ]: h& K7 o( D2 U1 B m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
* V1 I& l: g) y* q}. Z3 E3 u. `' K) X# D
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
) k) z; p/ G* w- O gm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );" k" ?$ w$ m" ~1 g+ E- ~
m_wndMenu.SetFocus();- K- S8 l( `5 b$ O: `% a! B8 Z
}
# y8 {/ G7 |. O$ M------------------------------------------------------------------------------------------------------------
) ?. h* R3 o6 w/ J*************************
. w: J% I4 e9 D3 j3 k* Z3 S. tWndField.h文件" b, P! ?5 t0 }: ^# G; M9 N
*************************
; j1 w, P" ^' `搜索:BOOL m_bReport;
4 F: K7 ]) S' u0 b7 X6 P8 x! o其后添加:
4 `: l; I/ v" L' X( j6 M7 NCWndMenu m_wndMenu;# B: |/ f% J1 H3 }4 R' [
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
: P9 j. r5 e* V4 Q* }8 y其后添加:1 x: e' e& c# e' j
virtual void OnRButtonUp(UINT nFlags, CPoint point);$ Z5 V5 E/ \: b* `
( p' P% \4 T, E4 N
4 U, g& e+ j' h% o$ D3 f1 D$ l
|
|