|
|
源文件中_Interface文件夹下WndField.cpp文件2 O# w* |( \/ z; h( x0 j1 r
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )2 G6 T: d+ V* i: n3 C
# V5 |* j0 c: V
struct sItem: W9 x; N5 B5 D4 T* X
{
2 `( `$ `* @+ x3 y% UDWORD dwId;
" R; g4 c0 F1 c* y2 I# [3 ADWORD dwKind2;
# n+ w9 S- ]/ |8 E9 hDWORD dwItemId;
+ v- K- f d+ N8 s/ J; L. b2 C3 LBYTE nIndex;9 G6 d' B" Z( p- P7 ~. G
sItem(){+ U4 q" S! v# g. _% E
dwId = dwKind2 = dwItemId = nIndex = 0;
! o% o" Q0 |, ?, m}7 C0 z8 E0 k; M; k( m0 z) c
bool operator < (const sItem p2)
+ ?8 j/ C1 ]* [1 r- ^% b6 ]{1 T: h1 ]& R: J
if (dwKind2 == p2.dwKind2)8 c( L" X4 ]! ]; c
{3 o/ Z/ G' W3 B4 i
return dwItemId < p2.dwItemId;1 b+ B+ G/ v+ G0 E% s0 C
}else{
4 l6 }1 W- y8 Y return dwKind2 < p2.dwKind2;
$ e9 t, ^ @! b }
; c$ x% z# |: d}
5 u+ f" _6 [: c};( X) z# H' F7 M1 M4 ?0 F1 Y
class CInventorySort
% j& k& k+ X+ {# Z* i{
% S. U* x, c# t% J8 a' I& [: Q# jpublic:
( h4 U, N% |: E; B# T+ wCInventorySort()- }) z, }% |* L4 R' n4 Y
{
7 F9 Y0 g) K: w: g* s/ U9 s m_dwPos = 0;
5 I y. q8 f- e& z* ] T: I}$ j1 j/ \& V% N9 h& w3 {8 c
~CInventorySort(){}( P( M* c: ^' i! A
private:
, G3 j% L8 E: psItem m_Item[MAX_INVENTORY];//存放排序好的道具信息& t* E4 j, }: `1 i7 n9 ]+ M7 a8 G
DWORD m_dwPos;) d* x. Z8 u& n
public:
6 t, b- g7 P( u- ]# fvoid Add(BYTE nIndex). l2 P+ p; v# [! w/ n
{
% x8 W! g- M$ c; f if (m_dwPos >= MAX_INVENTORY)) J) X& T7 w" s% k$ ?! F: K
{2 d- o' ?% q9 j, w* P
return;
6 }% q0 i) W7 U9 }( Q0 ]- v }
- Y$ } I+ K3 d1 C/ \) R m_Item[m_dwPos].nIndex = nIndex;3 ?6 F c+ _7 C+ e2 }& _: m
m_Item[m_dwPos].dwId = m_dwPos;1 a8 N0 [) x7 k
m_dwPos++;5 s3 U. B( @2 b. N, i
} Q3 B; s( T7 Q8 ?$ R0 l
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
. L/ C+ e; A0 S d{/ H# W. j+ `' Z8 A# a2 {. ~% o7 w! ]
for (int i=0;i<MAX_INVENTORY;i++)8 ?4 ]: D$ q/ N- a: {
{' C/ O$ I) M' w) M! V8 j) m
if (m_Item.dwId == dwId)
) n, ^9 u3 t& L# u" E. Z# [ {3 u8 A1 `% c2 [" V; R, P) H, T1 ]
return m_Item.nIndex;5 Y5 w6 j0 i3 Y- T
}
+ _& N% W/ ]4 Q }2 o& ?; L8 F1 _, b# K
return 255;- K" k. n, Q' D' D2 p% X
}
9 B* G: t! y' O; k0 w# Ovoid MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置/ b/ ]; P/ H# }2 R; t
{
: s( a5 I( L+ A1 Y7 y3 e2 ]) N" ^+ A BYTE nTmp = 0;- [5 a4 {4 d% A1 G0 R
bool bDest = false,bSrc = false;! J: g8 |( P4 u X" I/ I) G
for (int i=0;i<MAX_INVENTORY;i++)
( ~7 P# s1 d* @ {
, A5 I2 t& r5 a+ o- C6 { if (dwSrcId == m_Item.dwId)
) U$ I( R8 y; B# f& f+ d1 P' J {5 L: H2 W% B$ ]
//id相等 则 改变对应的dest和src& |$ d5 s& L" i/ G9 U
nTmp = m_Item.nIndex;2 H# y! r4 D& _, g1 v: q8 G# {
m_Item.nIndex = dest;" `/ t, Q. f- p: K2 f6 c* t
}" b) ?" p! ?: V- W$ Y* d
}
/ |$ w3 L' a6 N4 k4 Q9 ^ //临时数据保存完毕,交换开始+ F* y4 w/ u5 W4 O; L
for (int i=0;i<MAX_INVENTORY;i++)
- f4 x J8 \- ?% M1 x {9 l% f6 s4 w1 C
if (dest == m_Item.nIndex)
& t, M$ n/ P% `1 B( _ {
. s4 A) [$ q0 ]# z/ {: M //id相等 则 改变对应的dest和src
4 Z1 A" }" T6 I. ?/ e m_Item.nIndex = nTmp;
/ [: t* h2 B$ y: S }
# | n0 l4 b4 [: `2 Y }
: I; _# l) J3 T$ P5 E: B}3 y# R8 s+ ~8 q/ I$ I- P# D" B# [$ f
};5 F& ^0 ?% w9 Y
-------------------------------------------------------------------------8 r$ o" G0 i. J1 }
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
0 B9 r% @5 J( E7 ^" ^+ W0 R6 z9 m' }搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);
% M8 L+ U5 A3 X5 X# I: N$ m紧靠其上添加:+ e! G) K1 Y) T e" t* \
if( pWndBase == &m_wndMenu )
T( o& g0 f- C- [, o{, L6 M5 J4 r d, E% s p
switch( nID )' ~6 b* |/ [! V4 D% P
{
) ~. \- U' K! \3 _ case 2:- T1 z: ?% ]+ @; \# X3 ]0 G
{; g! s4 F8 l, o2 ~6 y4 s
//g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);$ L# k& y* x( p
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
3 D, x. B# A: A% G8 s' J, W2 @0 P {
3 {* [ _) p b break;
$ O" c( `+ u3 B# D+ T }
, {8 A: y& `0 p for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)* @; {, v1 @4 g6 T$ d2 u
{- y: ^2 Y {, O* F. H/ ~; ^
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
; Y9 B3 w; P" Q) e+ d if( !pItemElem )
* |( g( M8 v {5 q- {/ R continue;$ M2 T4 H/ A1 `; Q3 F, j( O
if(pItemElem->GetExtra() > 0)
, E i0 C) F) Z$ t5 _ f& F continue;
/ C7 f1 n) Q" }9 i: w if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
; p4 F: h# i7 }% J5 L& w8 B, \ continue;; y6 B- B! o9 v; ^+ E- h) r
if( g_pPlayer->IsUsing( pItemElem ) )
0 Q. H4 [5 B7 u# ?" U continue;, I: r6 e# E) r! s( Z6 g: S" B2 s `. d
if( pItemElem->IsUndestructable() == TRUE )
" S0 L0 f, Q/ k9 H4 p$ H$ [ {/ k" f" H/ c1 F& x& e' t) A( a
g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );. v4 h. I) W+ F/ r$ y$ I) Y1 |; J2 I
continue;8 |: ?% l3 M( g4 J
}
4 ~/ l7 l# A1 r" x5 | w5 V g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
# l" s8 g3 {$ _# ?; d6 `) F- D. y } m0 W' `7 w( I- E3 U+ w- ^
break;
- l; H. L2 w$ v/ E$ ^ }- w# Z9 k% U7 s* `5 r9 [. }
case 1:7 {6 \- g* `. Y1 t3 |
{+ v& b" y# T% r$ A/ ^( S% [& k) p
//整理背包) Y; v$ c( x5 o% J- G: @" A
//////////////////////////////////////////////////////////////////////////: `% L0 _" h- _. p. W1 x
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
( U( y4 U& ]- t3 t //////////////////////////////////////////////////////////////////////////! @: k: H4 o; {% a7 b) w$ w* Z4 E9 r
//////////////////////////////////////////////////////////////////////////
' [9 l# ~8 E3 q CInventorySort* pInvSort = new CInventorySort;
7 b$ w& G( j" ?" C2 h vector <sItem> vItem;6 v9 T, v8 k+ d) x# w/ r
vItem.resize(MAX_INVENTORY);//初始化大小
; C7 z2 i4 v( @+ W4 X& H" V6 W1 K+ P; A //////////////////////////////////////////////////////////////////////////
& d- L8 O9 `8 J3 d //填充数据8 f0 O. d* `' I/ [: ?0 o5 {
for (int i=0;i<MAX_INVENTORY;i++)
% D1 f$ {, k. F- c! C& @' X {! x" d k+ K6 h1 N$ [
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);& }" h8 G" y: L; d* r' `5 @
if (!pItemElem)7 z3 f- W( ]6 f
{
* O3 L5 }& r4 F s4 h vItem.dwKind2 = 0xffffffff;
% ]) ] I/ j6 C3 P! [# U" z vItem.dwItemId = 0xffffffff;6 Y* Q7 p- _0 ^+ o8 E& y
vItem.nIndex = i;+ l! [/ d! H5 I1 \+ `* W- Z& a
}else {
$ H) F& J8 a/ i$ M9 o, O ItemProp* pProp = pItemElem->GetProp(); q6 x9 B$ s [7 C& ^
vItem.dwKind2 = pProp->dwItemKind2;" t' Z$ L' c5 ]1 a+ t
vItem.dwItemId = pItemElem->m_dwItemId;& l. [1 W/ F' @$ V0 P
vItem.nIndex = i;
" `) E" u/ b# N* i* H; l }
) A% m8 X9 s% \! C7 z //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);& F, L' a7 g" G2 B
}" Q( n! M- D5 \+ I H
//////////////////////////////////////////////////////////////////////////$ m, W! P7 H; R$ Z# j& V; R) F3 f
sort(vItem.begin(),vItem.end());//排序% o* N& z! F8 ?% M% p. N
//////////////////////////////////////////////////////////////////////////* `9 P# g( f. W
//交换
, B+ Z& m T' Z for (size_t i=0;i<vItem.size();i++)
! g! Y I) e6 t8 N& Y- ` { X& F. d- c! X4 _
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);; c$ o: v4 F9 U/ e, h
pInvSort->Add(vItem.nIndex);
' r; p& A0 Q% Y' Q }
( B v) ~5 z9 _ BYTE nDestPos = 0;5 {& z# l" D9 S; p
for (int i=0;i<MAX_INVENTORY;i++) O& e V4 V! A# P
{7 L' `, g+ ~# W6 R+ o, ?. X
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
* P" s3 X) Q9 R# W# S if (pItemElem)* ~& u: Z( l( ^
{
; x* O3 P6 U6 n6 E% n! c/ @5 r if (IsUsingItem(pItemElem))
8 H1 @5 { L5 S( q( M+ A/ { {
* ?+ q3 b* g. H6 {( p- s //这个位置无法放) ?$ e% t* X+ m# ~
nDestPos++;; F1 i! H$ v6 _3 y- c( K, f
}
& f/ w: N9 F' i; a" J) v }( e9 S; z& |( A$ F2 o# a
BYTE nSrc = pInvSort->GetItemSrc(i);6 ~; ^/ a2 b! w4 {$ B @8 V* F
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);
0 a& B8 M6 u# ^8 q! Z if (pItemElem)- \( \/ V' y' J7 N* f0 V# s
{3 i0 y. Q' W. C
if (IsUsingItem(pItemElem))
% l( n! R: a; X# Q; S {
# e1 Z) \# W- N+ p' G+ w //这个道具无法移动,跳过4 ]1 j3 Z$ m3 Z. ]+ k9 @
continue;
% H: V- C7 a: w6 _; V }
$ E5 x6 p& k& h2 z4 W- d$ y }else{
: j9 l* y5 h/ a- S& L" D+ g9 u# s' S //空位置 不用动, a; C, h$ {0 d2 N. O
continue;
4 B5 C% _) N, q" H4 c- P* q, C }5 c) V: ^# A' g* F' y0 G
//////////////////////////////////////////////////////////////////////////2 D3 u3 w; @. U6 K0 f" e1 f
//开始移动
1 s0 d0 `& c0 P( m' { if (nSrc == nDestPos)+ U1 C8 ~ E7 S
{: o: F& E. i7 h6 m
//原地不动
[1 l8 R) j; n6 O2 X1 _ nDestPos++;
3 E" i7 n. E, ~# I; |9 x continue;
; Y) g8 |2 ?4 f2 E6 C ] }* j2 B. u+ k* N* |; G
pInvSort->MoveItem(i,nDestPos);
% S$ v" |0 [; `8 ~/ R- j n/ R g_DPlay.SendMoveItem(0,nSrc,nDestPos);: {: n7 P$ r7 D
Sleep(5);
: k& h4 O) W! \7 U1 G& K4 J //Error("移动 - %d->%d",nSrc,nDestPos);! V3 O @9 }0 y: ^: z
nDestPos++;
; p- P$ i0 H% D; m) }# y, q8 E, W# { }4 v* L3 Z; @9 Z6 B6 v$ \: Q
//取第一个元素的信息* e+ N `( H4 U3 j$ L2 W) i0 V
/** b# O7 b: L. U$ o0 A1 y
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)9 L4 |' a+ s. l& y, @$ C+ U
{
& G: y0 s$ W8 a2 D" I Error("Move - From:%d,To:%d",vItem[0].nIndex,x);# _6 m$ ^' D$ k$ A' F
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);- V% V$ f; I# [# J4 _( P; Z
}
L* y- q c! y; A# R */
1 E( Y. a- v, [# B6 _4 G7 x9 T8 P //////////////////////////////////////////////////////////////////////////
; I" J6 J; B L8 E break;
# m" `- B/ H/ C' t% j }* I9 U5 b/ J( P
} 6 s: J Q8 W% R, a
}9 c- \" c8 m y% `
m_wndMenu.SetVisible(FALSE);
( Z$ p$ M; @( b- a, d- [8 z8 H, {7 N# z# x* \0 t
--------------------------------------------------------------------------------------------------------# V" U, W0 G2 g: N. E/ m% n! C
搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)
# A: r4 u. {5 H3 V9 k{
. X3 ~! ? s. L* iBaseMouseCursor();
; y' s3 R5 ]* x}
, }! m3 U2 h3 G" j Q2 g在其下添加:$ J B# ~% |( L, U6 v+ t0 F
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)9 }* d! J( V7 Y1 n
{
! C5 h# w7 B& x9 Q7 X2 o6 n# tm_wndMenu.DeleteAllMenu();. Y2 T6 I4 ], k) Q T6 C
m_wndMenu.CreateMenu(this);
& |% _& w4 @0 d: I. k0 e# K& g& bm_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
$ v6 X: n2 Q: K! y% A$ U; _7 Y. e! h+ \+ c% }
if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
/ ]" d" n( C2 P, P: ?{6 ?+ X) |# L2 t; x. _4 h0 N
//P以上级别才可以删除所有道具
! V3 p/ O2 K* V1 S; m/ D m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
1 G9 b, Y; @; X. M}
( [# w& L# p2 }: [m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
* q7 j8 X2 l/ e( ?4 o+ rm_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );! D) r; k" e. w/ A7 b
m_wndMenu.SetFocus();/ L2 t$ V- P* p# _: e" D
}
1 A, F% J' Y$ p) a; C$ c------------------------------------------------------------------------------------------------------------, d. n/ Q1 H0 }. w, W
*************************
! ]5 H2 s" Z! m2 a; X- k) a! r( `" IWndField.h文件
- _$ K3 g/ n. \4 U# E& Y& J*************************
9 B% q: g/ X4 t7 ] u9 g! K" D- u搜索:BOOL m_bReport;% z: W' B9 e+ e. P# D! B+ r) j
其后添加:1 Z& G9 C& @+ s8 k: G
CWndMenu m_wndMenu;
* e/ F9 ]4 u5 J搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);
9 f* x3 v [3 A( g2 n其后添加:- s% H3 M5 }* s1 ^. V. z. q
virtual void OnRButtonUp(UINT nFlags, CPoint point);
, X& r) e4 a0 o
7 u% U d+ f' ]* Q( W+ I/ z* d0 z' a( ~4 F t. [& v, o+ u R+ N \' Z
|
|