|
源文件中_Interface文件夹下WndField.cpp文件
0 P4 V# U' n2 ~1 m1 E9 b; `搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
e1 u3 F3 h0 w# X7 |6 y; V3 E' y0 Z W+ W# L9 R. j. {0 z- t: ^8 o6 f
struct sItem
& v% c, E% j# t* x4 m- y{
2 ~: P& E! `. ~2 xDWORD dwId;
) k m0 }0 M4 b2 e2 ]DWORD dwKind2;2 k: f, o" ]9 n8 ~
DWORD dwItemId;0 }: r/ l# B, F# b$ e% b. ^# Q; P
BYTE nIndex;
; Z, }- u! l9 s6 msItem(){0 f. t% z7 W3 ]7 g6 D
dwId = dwKind2 = dwItemId = nIndex = 0;
& M3 r8 a% [( @/ S6 f/ o s}9 X4 H5 O; |) T [- f9 p
bool operator < (const sItem p2)* e6 K3 e( T% Q1 o
{
! f5 r3 u3 d: x* N, T/ y# q1 p D+ O if (dwKind2 == p2.dwKind2)
- D9 h% u6 G$ F) {( @& K3 ~ {% T0 x+ U: s- v8 q# J6 O8 C0 n
return dwItemId < p2.dwItemId;
/ i! d4 J6 c: S( e R5 \$ F' W }else{
! [" i( o6 b) v: D8 J return dwKind2 < p2.dwKind2;& _' q4 R" j/ `+ J M( q
}# h5 M1 A6 N1 x# |- X L
}
. A' o/ q5 a# R" `};
# d$ _9 [/ d0 Q7 V8 T$ ^3 Rclass CInventorySort
' V4 l. k. q) J) J: h{
; Q2 v8 F6 A) W! k& Z( X5 ppublic:
* `9 N' o/ G: Q6 HCInventorySort()3 V: a% g; ]$ m0 [
{) R1 ?/ y. W1 z
m_dwPos = 0;3 Y) B+ Q S# r* u* i
}& l' V8 x7 I+ j$ y1 _) c# U* K& V& T
~CInventorySort(){}
, D H J5 [9 L# n+ Bprivate:
5 I4 O" i. H3 D7 H4 ]% G5 Q4 hsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
4 Z" \) u; N6 q# n( l1 O3 J: NDWORD m_dwPos;
% ]7 U8 O$ @: Tpublic:0 D- k( E: i+ i# e4 x
void Add(BYTE nIndex), k& n: o# b" ~- I. k5 j6 }0 U
{! H6 U( x5 F5 _* {! I2 W
if (m_dwPos >= MAX_INVENTORY)% E7 H1 t6 V" C+ H
{: ]4 N- t# S/ v4 R, s2 Q' c( W; d
return;
7 `2 ?5 {% c1 d8 u; q" ^ }% i9 V7 T+ I) w, \9 o+ A8 @. ]7 o; W
m_Item[m_dwPos].nIndex = nIndex;
3 }) t5 u5 x* m4 |3 E m_Item[m_dwPos].dwId = m_dwPos;
Z, m2 k+ d, ?1 {: q1 F m_dwPos++;7 |; E$ f+ v+ M; A
}2 d& h* B8 L1 S# m* f$ F
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
4 y! i1 K! u+ y7 S" j, n$ Z" S# H{! e* }( h0 L& o
for (int i=0;i<MAX_INVENTORY;i++)
. n& Q+ W( I7 c4 ]3 h# Z/ V; W {
; }8 `0 h7 ~2 g; ` if (m_Item.dwId == dwId); Y. j* t2 x* n5 a. t* C8 Q5 h
{5 H1 {8 }" g, f/ L
return m_Item.nIndex;* Z+ N$ S0 U1 ^
}; G# z3 K/ M' P/ p) x
}! `7 d9 `& Z/ v, I
return 255;
2 U) N( P7 K) D# _6 M% h}
. n1 S- [0 D7 m( f- M4 ~. Xvoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
: h* @, J( w1 S7 H8 E+ E3 {8 L{$ A& _3 c0 j) X2 C' A4 p1 k
BYTE nTmp = 0;& p6 K7 m; F, x$ ?9 h, M/ z J- f
bool bDest = false,bSrc = false;" r/ r6 \& E. F* [" Q
for (int i=0;i<MAX_INVENTORY;i++)
. g1 ~+ K% h1 |+ ]3 W/ `( r% l3 u" M {5 X1 Q, j: @ j& M d# f
if (dwSrcId == m_Item.dwId)
9 @! D7 K& X4 z) g {8 `: A4 R: @2 e
//id相等 则 改变对应的dest和src3 u5 l. H) P$ R! a$ m: d
nTmp = m_Item.nIndex;
+ Q3 ^6 ]1 D& Y# @* a m_Item.nIndex = dest; J ]& p, A+ n$ F. d
}
4 [/ I- p: M0 j }6 A4 s5 T# c6 U& u
//临时数据保存完毕,交换开始5 f2 o" u, E# q4 w" |
for (int i=0;i<MAX_INVENTORY;i++)9 o5 @7 F3 {4 v8 U8 N0 v L7 b
{$ |' b- b, B! V9 e/ ?9 v: l; O3 P
if (dest == m_Item.nIndex)6 G' ^0 w. }6 `5 u
{
& L3 P g% g0 h, \3 D //id相等 则 改变对应的dest和src
p% q" P, B7 z" c. z S3 C m_Item.nIndex = nTmp;
9 A+ Q3 S; k9 S }
% q' S/ o X6 c }9 s1 }. C% ?0 E
}
9 a; i/ e( g- Z5 \$ a3 j' s& C+ s9 b};
: e) U! b. T" L$ S3 |7 z3 C/ e-------------------------------------------------------------------------' {& |, ^2 S3 P" h& ^+ o7 g
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )- d5 Z* u! E* D U
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase); p- J0 n4 X/ A
紧靠其上添加:
: P# m* S5 |( u% Y! hif( pWndBase == &m_wndMenu )* `0 X0 k5 h$ H, ~
{: ^8 Y+ ~) W8 u6 n3 D) ] ^
switch( nID )9 V7 u+ H! `) Q9 ?8 B# \
{
0 j& z! b0 e# v+ O7 B; g5 { case 2:
( I* q5 y, {4 q0 b% T {* e" ^; u# f5 b0 X" G
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
+ b- O6 n9 [2 @- F3 X if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))" t' S, }3 \- J
{ B8 ^- \ i0 L/ Z/ v
break;" h. W/ o1 B" \
}7 w6 P4 F/ Z3 g) w" U) V+ \
for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)' P8 g5 _$ H1 p/ E5 C
{
9 p- k; t8 ~2 f/ y7 s2 s CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
0 [/ ]5 C* p+ }2 j if( !pItemElem )4 [# P, t8 f6 m! [% G
continue;( N. V/ A4 \. Z; h
if(pItemElem->GetExtra() > 0)
% t& y! `/ _/ V- P: A continue;
: B- S+ [/ w+ b. U! U" u if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
4 I0 }# Q4 k. q* F continue;
$ S n k/ X1 Y if( g_pPlayer->IsUsing( pItemElem ) )% a3 b2 R4 m. b% Z! ^2 b0 p# e
continue;
% n$ F& V7 i" o8 F% Q+ X; `; J6 r if( pItemElem->IsUndestructable() == TRUE )1 n9 ]& o+ b. E0 E- D, g" b" }
{
i3 j) W# ^+ Z* L g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );& t6 j* @$ H$ Z6 x* l6 W4 d
continue;
m) z8 ]& l4 W* D/ h/ s }
2 g- t+ B7 r8 p/ O3 M/ H g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
% W! m8 X4 x3 @8 S T+ D/ N }
- t3 [. r. W7 S; z6 V break;
; b. L$ c( _! p- C5 \ } d" ~) }+ y; ]# O) ]2 [
case 1:% ?7 g Y. ?2 r9 s& W: r" n7 f& j
{7 I! S: i: W! W. y
//整理背包8 }- S1 w) k* { b- U7 g: X/ K
//////////////////////////////////////////////////////////////////////////
6 A5 k) |4 \3 \' R7 j( v& F //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
6 a7 Q6 g1 }0 U/ s //////////////////////////////////////////////////////////////////////////1 G. y: o! F. D) x2 ?( Z( A; x
//////////////////////////////////////////////////////////////////////////
9 ~' }& P i D CInventorySort* pInvSort = new CInventorySort;
. L8 O/ _* W4 {2 O, P3 o8 P vector <sItem> vItem; I' ^. [' @7 `0 Y4 c* ^
vItem.resize(MAX_INVENTORY);//初始化大小6 `. j! `# t6 M: T4 j
//////////////////////////////////////////////////////////////////////////0 |. @4 Y* S' \" S
//填充数据
3 `4 S0 s2 O E for (int i=0;i<MAX_INVENTORY;i++)) W( I8 v; j, v& S# ]5 ? ^
{# e Q* t- ~+ P* W* x
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
3 s0 B [5 Q' F5 F$ }) @ if (!pItemElem); V; N# \4 k" C' L" H# l1 c
{
9 a3 c2 x% q5 `6 c M! U2 H& o vItem.dwKind2 = 0xffffffff;) d* [2 N; w3 W6 y$ ? U
vItem.dwItemId = 0xffffffff;
: t, c& w8 j0 ^( q- Z. A vItem.nIndex = i;
3 Q) m' O) E% V, a, r6 _6 w }else {
0 d7 m; y2 W) x ItemProp* pProp = pItemElem->GetProp();
$ r0 O# ~( X9 q vItem.dwKind2 = pProp->dwItemKind2;
7 u& |% s4 P4 G4 u0 s vItem.dwItemId = pItemElem->m_dwItemId;
' }7 [: a3 {! \. X5 r3 L2 i vItem.nIndex = i;6 h, i* J8 ?4 W6 F
}
. H$ Q+ ]: Y( L; i& c' D$ A7 V7 q //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
U; P! @; X8 | x8 }) v }7 f: N, M" D. l3 S Q2 ?2 j
//////////////////////////////////////////////////////////////////////////. P* U& e1 H) v7 L
sort(vItem.begin(),vItem.end());//排序/ e* \. O% f8 D/ q1 s
//////////////////////////////////////////////////////////////////////////" ^; L3 S% y: d% |% q$ r) Q
//交换- z* e) a) h5 }9 p1 J; g) [1 |+ w
for (size_t i=0;i<vItem.size();i++)
) x7 f) P2 H$ r5 t {$ J+ H0 k3 p. O* e
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
5 O- m( t: D5 @' y7 _+ B- V$ K pInvSort->Add(vItem.nIndex);
8 T \& F+ |8 \1 e4 F* I1 g6 J }
7 L; p( E, j9 W3 D9 U BYTE nDestPos = 0;% x, A6 \3 s; }
for (int i=0;i<MAX_INVENTORY;i++)1 a+ m7 b/ `. G% k' [3 \
{
) s' T2 w6 x% Q q CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);, h0 L) h8 I3 D% X; c
if (pItemElem)4 h! a. G* _4 T' k/ Q
{
* e' g# b1 z( A; k! f+ e5 K2 }9 |$ H if (IsUsingItem(pItemElem))9 p2 I/ S1 _) l: `; c% t) F% ?( C
{
4 h+ g9 K4 v: t* N7 T9 M //这个位置无法放- o* _& A& [$ p' N% r& h# N
nDestPos++;
- ^( e' J9 O: d$ |3 _ Y3 p0 G }3 K* i- r5 v' O. V8 G/ `6 }, d* U
}/ p: w" D3 V; w* B# f% l1 r- U @
BYTE nSrc = pInvSort->GetItemSrc(i);- ^6 F) d# f4 U9 V9 [& b+ `
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc); _! C, p' K6 U9 u% b. g2 j6 u
if (pItemElem)
: J" m. `8 w$ ^) |$ L; A+ q' R" P! m {
$ Z Q* e$ L3 h9 D* W if (IsUsingItem(pItemElem))
0 X0 \$ Z s* r. R0 b( C4 N5 K {
( ?9 R! E( O5 _! e //这个道具无法移动,跳过
+ ?; ]$ C) Y0 F( \, f- I continue;1 S% n+ y+ f1 w8 P6 ` |- |" F1 A6 a
}& ~6 o% W! D7 O: t( d
}else{" m5 T! b3 P X5 G
//空位置 不用动5 z/ N, D: L Q/ z8 }- @ t) T
continue;
, l4 j: h. B! d% x5 ` }% F0 |4 d- |* g/ o" U3 C! r& i; @
//////////////////////////////////////////////////////////////////////////% ^4 i: F' K3 D5 m1 |! U/ `% n$ q
//开始移动
* N; X1 x* ?0 _6 f A8 \5 } if (nSrc == nDestPos)4 P# d1 _& A1 m1 J9 L# d" l
{
1 o$ `: ]& m4 i- v( s8 u //原地不动5 Y! O- l* |6 o' `8 }- ?+ @. o
nDestPos++;( H6 P O9 ^: n7 w& e" m% r [- v
continue;
4 |5 ]) U7 L N- y M }' ~% o) P6 }8 @' {- ~$ z
pInvSort->MoveItem(i,nDestPos);
8 G) t/ N5 ~" ]' b g_DPlay.SendMoveItem(0,nSrc,nDestPos);
0 H1 e" {3 A/ S: v Sleep(5);: [' P. q$ K, G6 e1 I$ E% ^
//Error("移动 - %d->%d",nSrc,nDestPos);
6 O& t5 X. h! F3 L& \/ M nDestPos++;
. G0 Y, c* g* N; Q; \. `& ^ }% w7 Y8 [7 x) f4 a
//取第一个元素的信息
" J7 _% B) p# s# t* T* V" H- \ /*
: S, ^; j# u% p7 {9 d; `8 o if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)
0 x* }# a/ t: ^1 \8 n0 q* Z {' j% l1 S; j0 z( }& E' l# c0 ^
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);- Z$ J, i; S5 Q7 ]" p
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
7 A, |3 Q) [8 N t5 Z- O }
% f5 U1 W5 ^# v& w+ F% A: `3 s6 o5 { */
3 D5 C: a* {2 L- i3 J9 M //////////////////////////////////////////////////////////////////////////3 L& i( y* ^& d# e! P1 `1 z. H+ c
break;% A- ?4 y# s' j& L1 L P
}, @ j: q. n5 [3 x T
} ! a) B* I$ `! W n' v
}0 I0 B7 D# Q2 e8 q
m_wndMenu.SetVisible(FALSE);& `+ A- r4 w% F8 D' d+ V
9 l2 a7 u$ v3 r1 Y
--------------------------------------------------------------------------------------------------------
6 W, W: J1 V* L' F V: `搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
; {5 l- d& X M3 s{
6 h. R: U4 {$ n& uBaseMouseCursor();$ f" A2 @4 y2 ^2 ~
}
: P0 A1 V& f: ^ P在其下添加:4 f( n* z2 @* e v- c5 s- Z+ C @ I
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
9 j: k4 ?, S5 O6 d/ j5 p( [{- @/ k7 x! H5 i7 C' e
m_wndMenu.DeleteAllMenu();
5 N. s( X: S* l$ I& X7 ~m_wndMenu.CreateMenu(this);
. D# f1 f; S4 m$ O9 S) [m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
0 ^1 E0 H( M8 w! P3 _) q! d' j# e
9 f/ ^' n7 o. uif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))9 k0 g; s' \' T: Q. u
{
S# J1 ?0 O/ j, A7 a, A; @ //P以上级别才可以删除所有道具$ L( K# b1 l) d
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
0 ` |, Z+ V4 b}& C9 U- e" c1 z' ?9 f6 w8 U6 u
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
: C: P- |- m6 |% |3 s" [. e: N- W, Xm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );
, Y0 Z" `' x3 k5 C% n7 Am_wndMenu.SetFocus();
# \( e; H% h' x# E}1 o' I. @8 g R; C) W
------------------------------------------------------------------------------------------------------------
; O7 ]; j4 Z. i9 F*************************
' m) |% G& I4 S$ ~& ^! rWndField.h文件1 B R5 r6 V7 T$ I; @& x
*************************
6 K+ @3 j T0 j! a6 b搜索:BOOL m_bReport;
+ R$ Q. `# r& X其后添加:
" j6 T2 n) }% J# u& QCWndMenu m_wndMenu;
! w' n* I( ~! G- z. [搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);# t/ P- I+ i7 c' @+ V4 U
其后添加:, Y# z2 D) R8 @9 h" C0 h9 k
virtual void OnRButtonUp(UINT nFlags, CPoint point);5 j, h) w! e! s9 W# v! U
4 o/ c/ d# n& D$ U8 N9 e: ^/ U# v' L& K i4 E2 R7 Y4 E, R" ~
|
|