|
|
源文件中_Interface文件夹下WndField.cpp文件
6 O" t* Q t( t, P0 u8 x搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ): E& B+ c- ]. |# P! i
* @7 @( b* U7 F7 `# k6 ~/ t. \struct sItem
! v1 |. K( d! M8 X z{
6 z/ j3 r; e5 T8 h# ^DWORD dwId;
1 p1 ~9 N# I4 m Z" jDWORD dwKind2;1 |! e z, ^% K# z: L& Y- Z
DWORD dwItemId;3 n, Q6 ~8 s0 |. p! M) n
BYTE nIndex;
2 c: D0 w6 Q& R, r/ L* osItem(){
/ F. @ V4 G F. e2 D H dwId = dwKind2 = dwItemId = nIndex = 0;# N" s; o) Q2 O- p1 j% L
}
* C" p `0 ? a- T& y, obool operator < (const sItem p2)# |; v+ w8 `% C5 U
{- ]) E% v: b2 }# {" Q) {! h
if (dwKind2 == p2.dwKind2)
$ ~3 F3 f/ d0 A# Y0 `9 C+ e* r, _ {
+ l* o) K9 T G# i# A return dwItemId < p2.dwItemId;
3 p' E+ X# _' v( k$ k: e }else{7 J. c" m: r& m" s/ j f
return dwKind2 < p2.dwKind2;
; v; f" r* q- J# G8 ?# { }
* q+ H/ \- D+ P+ W7 P0 R} ^" m; _% n" h6 n# C
};
; j- ]& q/ l$ ~' U% P2 s! f5 D" X% Tclass CInventorySort9 _ P4 E1 V4 ^1 [6 l
{
( b! ]& V/ B" G7 d# U+ D! z# c7 k. Ypublic:
: ~% D l3 s# F# ^CInventorySort()- m# C$ ], ~0 q' S
{
! n4 r* i2 z& g: u$ }" n4 _ m_dwPos = 0;/ }/ ~" x# E) f. Q& X) A+ y
}. R$ r% A* S& v# H" z
~CInventorySort(){}9 W, y( A, ^3 Z! M
private:! T; Y" }# _( l' O
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
; p5 q, H/ b/ o2 @5 jDWORD m_dwPos;
8 y$ i" a4 m rpublic:; G' {6 N) S. N
void Add(BYTE nIndex)# a9 j( S8 K+ [" H) e3 e3 o
{
. |! G- }! `- r if (m_dwPos >= MAX_INVENTORY)
, Q r1 G: |. H {0 l3 S) @% y) U2 X
return;* n, S& K1 P2 O8 t
}
0 H8 f$ x5 ^2 S9 v1 K m_Item[m_dwPos].nIndex = nIndex;
; q+ J% l/ M% h* o8 b# u1 r0 R1 p m_Item[m_dwPos].dwId = m_dwPos;. R% J8 t; m8 M
m_dwPos++;7 s$ S6 I( y( d6 V% {/ h
}
0 C5 C2 H( H: G7 Y2 c, dBYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
: I: F2 |5 w5 @' }, a. y. c{
: t! ?# x( S2 L& }0 s! ? for (int i=0;i<MAX_INVENTORY;i++)
4 H4 |# x/ u) D {- p7 A6 t3 X. g! ?3 x2 H0 Z
if (m_Item.dwId == dwId)2 I2 _2 k3 A9 L8 c
{
# O: p/ U& @ a8 E/ S return m_Item.nIndex;, W# Z: `3 H3 v' z: B. z2 K
}
- P8 r: j, n! V# t' T' b/ i4 I | }7 S7 t9 y* s- i/ @
return 255;& N- t8 H: z1 S% F" K9 W. h7 S3 F: |7 S
}
% l! D4 @5 c4 f, b2 Xvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置1 K& q U, m4 @
{9 C+ C+ v* {5 S' A6 B$ Y: x
BYTE nTmp = 0;+ V x( r0 ^) V( x/ y, F% O' W
bool bDest = false,bSrc = false;* Z) O6 z5 \. Z9 x& e
for (int i=0;i<MAX_INVENTORY;i++), y7 H) S% u8 W; j2 n1 i
{
b- N9 b5 s1 b# W if (dwSrcId == m_Item.dwId) k; B9 E- e( [4 s! b% ] {' H* L* U
{$ \9 Y) }5 r. m) Y$ z0 w9 O' q" o
//id相等 则 改变对应的dest和src" o' |3 g [* W; h
nTmp = m_Item.nIndex;# h# F1 L+ o# C) ~
m_Item.nIndex = dest;
i7 k Z5 w+ j; i }9 T1 G' ~" \' C- v# ^, q9 K3 ]8 W
}
1 X* v9 N0 Q$ T! J) P6 ]1 R" x. P //临时数据保存完毕,交换开始
9 o1 ]) D$ a' F$ o5 Q* j# I for (int i=0;i<MAX_INVENTORY;i++)
0 q5 c9 _/ ~+ W5 G2 I {0 L: s6 r+ S& C% W0 ~1 V
if (dest == m_Item.nIndex)
1 Y( E# d J; v! A {
+ W0 v" g a* M //id相等 则 改变对应的dest和src9 }/ |( @ z! P/ f% p) [
m_Item.nIndex = nTmp;
) N& ]# S: d6 R j$ Y }
/ I6 Q @6 O* A2 ^ }
' c4 m& j Q f+ g" {9 I}
$ M, j' L9 z" M. f; J# o};8 j8 k/ n4 E+ b. L: c1 Q
-------------------------------------------------------------------------6 Z2 j, i/ Z& T/ a- l5 m; ~# O* ]
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
0 C) `# a: @6 d) A# ?% D: Y搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);+ y, A! [' w' k+ K3 W/ w1 j( T
紧靠其上添加:
1 N+ B) ~, i% s* V$ r) Cif( pWndBase == &m_wndMenu )2 b$ _/ R9 t5 @3 o- M/ [" ]
{
, d [0 V! Z0 [$ h4 Y0 N switch( nID )
1 o \# `3 c- {2 N( B7 f {
5 F% N7 D. l% C X4 o/ k case 2:3 X' _5 l9 N% x* f+ A- p4 N6 B
{
5 R+ }1 }9 V2 w( ` p) i3 ~ //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
6 H. {) Y& w' d% f: H6 G. o if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))# s: u% U8 E* @! \
{
8 r" { [2 y, l- w8 b3 P break; W2 s9 C' t: [8 I- y9 k
}2 G" f4 V, e) G6 c
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)7 p/ \8 @" M+ o
{* ]8 ?1 L2 h- W ~
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
& V- a% l; h; q/ i' ~ if( !pItemElem )
+ P. @1 F: Y% e7 \7 l continue;. n% q3 E! {( h
if(pItemElem->GetExtra() > 0)* D$ g4 w9 g1 |% Z3 E" n+ w
continue;
k- z2 H6 Z" w' e! K' Y- ?5 v+ j; Z$ P if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
! v. I) R& ?2 y8 F3 H continue;
/ t" ^1 v+ y$ t7 d! {( p4 [5 A if( g_pPlayer->IsUsing( pItemElem ) )9 M' d! P4 b/ X: t( J
continue;
3 G2 u' }$ v" s7 e7 \ if( pItemElem->IsUndestructable() == TRUE )
s, d& [' P t5 c2 U4 V {
$ f4 J; @" B& c6 e g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
8 q% {+ ]- U2 W$ e1 Q continue;
1 {! C3 M$ y' ?/ e6 I1 S }
/ r& X0 [, R- ~: F; s2 p) O g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
4 g7 h8 W" [3 l1 j- y% | Q }
1 `( U4 J" _) O. J0 D break;8 N0 Y$ N. Z+ W8 [. j
}- r/ j5 X' V" }# W9 ^4 f2 g% I! I3 V
case 1:1 K' z- r7 Q: K! A; e# u( I r8 E
{
3 j7 N/ E/ i# q% V //整理背包
0 k0 o+ S& g1 n! a. u7 P5 g( o! [ //////////////////////////////////////////////////////////////////////////
0 X* `. W1 u4 z //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
/ N4 a, z, `$ ^3 x //////////////////////////////////////////////////////////////////////////
0 @* d* U) A O/ s //////////////////////////////////////////////////////////////////////////
1 g1 B7 I. b% t) i F/ p+ s CInventorySort* pInvSort = new CInventorySort;4 S5 _9 J c- |* \! v" C" P4 Z$ w4 ]
vector <sItem> vItem;
8 b/ j& v% ?, l" E) H) ` vItem.resize(MAX_INVENTORY);//初始化大小
! O7 b- H6 Q9 H$ X B* l2 ?, u- F" M //////////////////////////////////////////////////////////////////////////
' A- e* j# ` ^ //填充数据2 c+ e/ y' Z h" B& o+ t
for (int i=0;i<MAX_INVENTORY;i++): h* t# h( K6 j, {# g# G
{
$ R$ l6 I8 p) ~/ F CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
{3 \2 ]; ^3 L _: k/ J+ v3 x( y if (!pItemElem)5 \) v! E" H" p0 A+ `) E. U& g
{
( Y0 m V w5 H7 P4 ]8 `, ] vItem.dwKind2 = 0xffffffff;
: V1 z' a$ Q% K+ k! b vItem.dwItemId = 0xffffffff;
8 x# Q8 f" L2 G vItem.nIndex = i;
$ p% Z1 h/ Q) a8 G }else {7 t- N' C0 O Z9 {& M4 \3 o9 F- W
ItemProp* pProp = pItemElem->GetProp();- n, P* O( N$ m; u. w; c/ @
vItem.dwKind2 = pProp->dwItemKind2;( P! Y9 i" X; ~: i: X$ X+ l& Q4 D
vItem.dwItemId = pItemElem->m_dwItemId;
" c+ m, J7 F- U" ^2 V vItem.nIndex = i;
+ w$ d s7 a6 N% }8 O2 B+ u }
3 s3 K! Q5 Q; W* }" { //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);- f, c* ~, w- I3 s, @, @
}* f; w0 V4 C6 ?# d. E( h! K& r; y" Y: W
//////////////////////////////////////////////////////////////////////////
5 c4 p7 C) }1 {4 P sort(vItem.begin(),vItem.end());//排序5 H9 V8 S0 N/ n$ ], J/ y
//////////////////////////////////////////////////////////////////////////# g% ]6 c$ K1 Z7 u' R* u
//交换7 T/ r* g6 z( V g5 _
for (size_t i=0;i<vItem.size();i++)
# v( y( n0 U* z4 a {
) Q( @# o: O2 O/ _ //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
4 O0 ]9 W2 W' J/ F c8 ]+ ]& y pInvSort->Add(vItem.nIndex);
G, A. }6 L; e6 O. e! h3 j }
0 s: D% c$ v4 v; |5 b9 `; r BYTE nDestPos = 0;
$ B' K) U& l1 N W" _" `/ w for (int i=0;i<MAX_INVENTORY;i++)7 t3 m; E. C1 q5 s
{# P* m" `; h8 G- y1 Z, w9 p! [
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);- u5 \5 f, h. _: L! U
if (pItemElem): m# j2 U$ W! a* g8 l
{$ o A" O" _" P: r( v1 n& C
if (IsUsingItem(pItemElem))5 ?: h2 {/ W9 k/ @; D% A! K
{! ?* [$ L% j, W! ?# W% }% m1 p% [
//这个位置无法放. `" v$ W4 ]( Q$ u/ _' W
nDestPos++;
7 D- ?# R' Y- ^7 X2 M8 k }# H8 O! }# F) H/ T
}4 Z6 w* q0 N) |! P
BYTE nSrc = pInvSort->GetItemSrc(i);) O& B4 i4 x' { n6 P' \
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
2 j2 l$ _ [4 i* T# s) r1 Y/ d if (pItemElem)
) O/ U% H6 ?' s n% n( w9 I% r& p {5 r: h4 X4 J$ R j5 N" }
if (IsUsingItem(pItemElem))
) U8 ~8 G3 O; E9 q! p { g' d" ^- v' I% Z- D1 p; g8 j
//这个道具无法移动,跳过
/ K# D ~2 `8 H: }! V continue;" }* P2 E" z8 C4 `4 M+ T" q2 b
}
5 I$ }- s* R" |1 G }else{2 c- v1 {* _: C$ z
//空位置 不用动, U1 \# ?. }1 _- f
continue;) A5 D* c) P4 `/ [. X; k3 ^
}
1 V: C5 P: `* K' g3 s' p2 v8 `" p) [ //////////////////////////////////////////////////////////////////////////
2 t4 U' p W5 H8 \$ M //开始移动1 `! }. R0 h3 u9 g5 X# j
if (nSrc == nDestPos)
; O+ v' \9 U' V+ z: v4 K5 {/ f {
3 W5 |+ A+ P/ S/ {( q //原地不动
% S, L3 S: ~$ E* u nDestPos++;) o% I6 @+ [/ x, a8 w
continue;
( U% C, t" r' A# `* e& H }- D, W$ c$ R! P: L
pInvSort->MoveItem(i,nDestPos);5 `; C: z. n4 D0 w2 Y
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
. Z* C& M! o3 R; ~" r6 } Sleep(5);, q+ G9 v5 B, g/ p: G+ w
//Error("移动 - %d->%d",nSrc,nDestPos);
Z( l3 a# S7 M3 @( ]# d* ` nDestPos++;3 v: G5 o. F; [5 i% K; b' y6 q: s1 F
}
3 }1 G; E) @, ]6 F7 W //取第一个元素的信息
1 I2 `9 b) ~! M4 k+ S /*
0 {# B* t `- p0 O) k3 ~ z5 ^ if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
0 ^8 z. J9 J9 E: y& ~6 U+ A) \: l; b {
( h. q9 ?! `& r- k Error("Move - From:%d,To:%d",vItem[0].nIndex,x);2 v* o" u" S2 D: }( S. R
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x); e5 G% L/ f5 J o" c' q s
}
8 S3 }" n& i8 C# ]$ B# L( t */
- `4 t' E7 i+ v2 D: |& \9 k9 R$ ^7 F //////////////////////////////////////////////////////////////////////////& a- D& y' K4 _) K
break;
8 k; {6 f5 a% M- M3 b }
6 j' W# l& G/ d } % ^7 v; {" q, f$ L, V% v
}
# d4 b; t6 N+ dm_wndMenu.SetVisible(FALSE);
% H: o' E9 j8 K7 e! W& M4 F
2 X" {/ Q( n1 z" v% V2 [+ d/ F--------------------------------------------------------------------------------------------------------" |- _. v7 M y4 Q' l7 g& b+ W
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
& r4 v2 s" ^7 {6 {9 ?$ c: M{6 T: q0 h0 }8 t3 K, l
BaseMouseCursor();8 b! J' K) A5 c9 a( S$ y
}9 c; Z" M# c: y' r3 S. i+ V D
在其下添加:6 ^/ X+ A3 ^ S+ q& M4 q' i4 `/ X
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
6 k6 {0 u7 I" R) V/ B6 W{* Y% W0 E$ l9 Z" Y6 u
m_wndMenu.DeleteAllMenu();
2 c( y1 l; }& H7 xm_wndMenu.CreateMenu(this);
! r; d6 C) Z Lm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
0 D- }! A" B& [) u; c' j6 g7 ~& e4 H
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
- f- u$ i4 h- g+ w0 Q: g. W0 [{
6 s: I G( \/ m! C //P以上级别才可以删除所有道具
2 H9 L0 ]' s r% U& V m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
! Q( k* o2 p2 D3 D}% f" O; K4 G; `, n$ g: _: i$ f: |* E
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
9 F# g9 ^$ f2 ~) @3 h3 Am_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
+ E: K1 a; k# A# M1 T, ]m_wndMenu.SetFocus();' V: V5 u4 I7 z& l. d" Q. {
}, p+ k) B! s( w9 B% y
------------------------------------------------------------------------------------------------------------
6 x* |& s" R3 M! [( v8 z! a9 Q3 z3 |( i*************************
* s/ G. ]! E1 i0 \1 rWndField.h文件4 R! a' d8 V1 l5 H
*************************
, ~4 I9 c. K8 J% y/ p搜索:BOOL m_bReport;
' V5 l9 ? s6 s7 g; L* t. v其后添加:" v8 ^- f) [2 E0 |
CWndMenu m_wndMenu;+ G9 i& J: x7 G5 E9 x' d+ `1 G
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);0 B, ~. T4 _. H
其后添加:, _5 }9 M k5 `5 q5 i; o
virtual void OnRButtonUp(UINT nFlags, CPoint point);2 L1 ^3 w6 F; W7 P2 ]
! q, p+ ?8 d x# ] w+ D a& P
( _. `8 R5 h) D' S) } |
|