|
|
源文件中_Interface文件夹下WndField.cpp文件
* H- c! l! ?& }" A9 e/ w5 y搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )! h/ c$ l) d; c7 {: t3 W
2 [ n( c* p! L% e, X
struct sItem
3 i1 t5 R, p$ s6 U{4 ?7 d2 j$ @- f' u
DWORD dwId;9 y V4 g7 r8 p1 J8 V
DWORD dwKind2;
1 u1 Z; h# o4 V3 }+ |- GDWORD dwItemId;
4 C) y0 T' l; `% f$ ~6 l" e- MBYTE nIndex;2 t+ d8 o! n+ G0 [% Z
sItem(){
& U0 x- g2 K1 g0 x dwId = dwKind2 = dwItemId = nIndex = 0;9 z/ N. a/ L% B0 b9 v/ X# t# l
}
- l: ~. h0 W+ | i' Y7 Vbool operator < (const sItem p2)
: z3 g/ P6 c! f$ l' C! x{
; r0 A0 u7 _, G- S% ?0 h2 a. x4 u if (dwKind2 == p2.dwKind2)4 n. l* U7 `* v+ U; n
{* Q2 I" l* F0 y3 b# T# B
return dwItemId < p2.dwItemId;( a5 z( G% y) W% ^, c
}else{
( \- c# Z& {0 l5 D return dwKind2 < p2.dwKind2;' |& `" W3 V1 y6 W. {1 Z
}0 t% A4 V. D. m2 f8 H# z
}5 M9 _5 b1 ]2 c6 J$ S) p
};2 f# x1 b/ z6 b C& s) G
class CInventorySort
7 Q8 q7 i$ a, c; y% R{
. s7 R0 |; n3 W) S4 C2 ~ fpublic:
4 E( V, }& Q1 E- p8 j+ F# SCInventorySort()( n1 `! D! U s E: W7 z6 g3 c
{5 k% E7 d Q8 _! u# R: N8 ]
m_dwPos = 0;
1 K* D8 k5 i6 D* A2 h$ b}
5 u+ u1 F, a* K/ h~CInventorySort(){}& x N1 k" `6 K1 g2 i2 c/ c
private:
+ d# [/ c6 S% ?( X' t* [8 G" gsItem m_Item[MAX_INVENTORY];//存放排序好的道具信息
M1 d5 }. ]1 }/ s, w+ z7 c" WDWORD m_dwPos;% r1 g9 u) u/ D5 i. P( L& F" _
public:
, k9 `$ w( r/ P6 t1 [void Add(BYTE nIndex)! ]4 `1 {" X {0 d1 [: y3 u
{
' }+ m) e3 T+ {; n if (m_dwPos >= MAX_INVENTORY)1 h2 Z: T% c/ }# v" m
{
& `. v0 s; J- m6 W0 n' h return;5 o) s( V, P; |: Q
}
- C( u# L( V' {5 L1 t, y- B8 Z0 x Q0 i m_Item[m_dwPos].nIndex = nIndex;9 ]5 K4 `2 d4 |1 ?, i! }
m_Item[m_dwPos].dwId = m_dwPos;# d$ j( N; s" N x& C
m_dwPos++;
# g2 ?% }1 C9 A' l! S- b}# r2 |9 x3 T0 U z; f* \
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列
5 ]! ?* j/ {$ }{
1 | X: h* y7 L0 M for (int i=0;i<MAX_INVENTORY;i++)" P3 Y- @5 W. ]( D# r
{7 |+ p* ?3 Z) t3 a1 K
if (m_Item.dwId == dwId); {+ {! ~8 J& T5 P" w f
{
* |7 ^9 O3 e+ B7 _; ^ return m_Item.nIndex;! t. R, j3 }7 y3 y$ h1 \
}
6 B; r' K7 l7 R }( A1 _& k9 H( ]( H' t2 q% N
return 255;
2 B' U$ y+ c' l8 Y}, O! s' m( S- i& D: f4 D
void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置
* \: O& \# _. N7 I: b! G, e4 t7 X+ H{; { R N" W5 |, X. ~5 D# @" D
BYTE nTmp = 0;
" {+ y# G2 d) ^7 C bool bDest = false,bSrc = false;0 E9 k6 x, O9 t8 I2 l0 Z! z0 n& a
for (int i=0;i<MAX_INVENTORY;i++)8 }. p$ N0 A% C7 f u
{
( s1 h; c& o! h" q' Y0 K if (dwSrcId == m_Item.dwId)
! j- U3 A6 y9 o- b( f8 J {, o1 o7 A/ h3 D' ^2 o+ a
//id相等 则 改变对应的dest和src' v7 X! o6 O3 D7 N! a
nTmp = m_Item.nIndex;5 P2 F% T) y# j4 @, {
m_Item.nIndex = dest;
2 i# ?9 _7 N' W& j: z% X9 [3 M }
1 a& U) a6 {" `5 e( T, f }8 M) }0 m; C+ H6 f
//临时数据保存完毕,交换开始
1 c {4 g* n; L for (int i=0;i<MAX_INVENTORY;i++)9 ~, K1 Z+ Y! x
{5 i3 ?5 k; A7 S$ P4 o1 B
if (dest == m_Item.nIndex)
5 ?+ @( z# `6 X# T! X d2 } {2 u$ ` k; U+ L6 L
//id相等 则 改变对应的dest和src
! @. M( k. c. H6 U$ h3 j/ j m_Item.nIndex = nTmp;. y4 U- m; Y: {# C
}* I* ^$ G1 X8 Q4 g7 B8 w: [
}# m' X* U7 \3 W9 _% x6 D
}. P& j, q8 u# C2 g6 z6 x6 H- Y1 p
};
; }# ?) o1 N- ^* q& B. o-------------------------------------------------------------------------# U4 L0 d5 o# g8 K
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )
) A, w. e+ b9 h9 r* n: D' }% _搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);/ y4 W# N$ [9 p i% P- u3 T
紧靠其上添加:4 E( B7 \( x/ s* B( w
if( pWndBase == &m_wndMenu )
1 ^$ h' u. L. x/ U% h{/ G2 d( p8 t: \# `% [1 P1 ^
switch( nID )
0 V! k6 J) R. B- t# U$ g {
6 K7 Q) n3 i5 p4 h, B& ] case 2:, z" }" P( ^% }6 U7 {# x
{
" j1 w; A3 f! b3 u //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);( q7 M% w8 y4 E9 ^( Z3 j Q
if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
: x0 O. n5 p( q/ r7 Y { I) r6 d0 y9 ^! h
break;* ]' F; {. }! V
}
- Z0 g' c2 y1 q( P! R" R for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)
1 I. c1 X' `) L {# X0 T+ O4 c- d/ s( {
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
( [3 w2 X0 |9 F# _ if( !pItemElem ) P; _( J4 G" h! n( d
continue;
/ G1 Q( b- b% Y9 f) L2 [, |: ~( R if(pItemElem->GetExtra() > 0)/ r% K( t& J) Y- h. L) {
continue;
) e4 _1 c* ~$ k# [% S0 x6 Q P9 H if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) 4 r- W4 a$ p, {7 |% L& p0 e4 R
continue;, ?4 {1 l6 X; A
if( g_pPlayer->IsUsing( pItemElem ) )
. E8 m* T8 ?" x5 s$ R5 l( F) x continue;
( M9 S/ ^9 t% n if( pItemElem->IsUndestructable() == TRUE )& p3 ^7 w" }: l8 a$ y1 T
{
: S/ z; H+ I7 w3 s" O* I3 ]- c0 o g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );' v3 J" V/ F8 H2 y' t( \
continue;
, S% z; u2 n+ c+ M" [: U: b }% y/ s4 y) D# ?* }
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);9 N+ p; |9 J/ S! g7 S
}
" f5 f& w, Z1 \2 F. T# x$ \ break;' s( N; G7 d2 y( u* N3 H
}
2 J- \, {; o L% o/ g case 1:
6 o. m# y! ^& T# K+ z {
; D/ ^) ^. w3 _2 } //整理背包
2 n5 A) U. p; Z //////////////////////////////////////////////////////////////////////////; E, D6 \+ g# ]) s
//g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
4 E, P# j a0 y' a //////////////////////////////////////////////////////////////////////////
2 o3 n$ w% c; R6 `' c* ]. G9 m //////////////////////////////////////////////////////////////////////////9 x+ }; \1 w3 q( h F1 \; T: ^
CInventorySort* pInvSort = new CInventorySort;7 |; X( I' }1 _
vector <sItem> vItem;: n( T' g( f7 m
vItem.resize(MAX_INVENTORY);//初始化大小
: r& ^) y0 r; L7 p2 C2 u7 r6 K //////////////////////////////////////////////////////////////////////////
2 T" l Y1 f3 g: R0 ~ //填充数据
) d9 J+ B( f1 E0 b: U for (int i=0;i<MAX_INVENTORY;i++)% U, V' S- f- X" F/ o* x; l* ?" [- o; h
{7 ?- K# y8 D1 Z0 _4 x
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
$ U) p# _( F) ~) C if (!pItemElem)! j- U! V; j3 z3 O+ {+ k
{8 x" k+ O/ t* q6 Y
vItem.dwKind2 = 0xffffffff;
! s* T7 ~, h0 B. ^& q vItem.dwItemId = 0xffffffff;
8 j& K2 U' Z1 A7 B; K: |+ k& M vItem.nIndex = i;3 a* _* f5 ?/ T4 T& A
}else {
. W/ k: n# z% Y- T; t3 ^' X. q) Z ItemProp* pProp = pItemElem->GetProp();! I4 Q! _% X7 w
vItem.dwKind2 = pProp->dwItemKind2; [! S% X& I7 Y w( E. K }5 T
vItem.dwItemId = pItemElem->m_dwItemId;
# B. j% E) l+ [3 S vItem.nIndex = i;
$ r J. L- U; ~ }
" D: }. m( ?7 }' H //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
, U; Z( I/ x* P }
a* t3 ~$ }0 U //////////////////////////////////////////////////////////////////////////1 y( _5 U) |; G/ G
sort(vItem.begin(),vItem.end());//排序
. |7 e, b) |# Y# E //////////////////////////////////////////////////////////////////////////( ~+ l8 S# c- @% |) {
//交换# f) s; I( X- z4 H
for (size_t i=0;i<vItem.size();i++), @) p3 G) Y! z- P
{2 ]/ r$ [3 y! h3 P5 c7 a
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);* J' W& L; ]7 t, _) q
pInvSort->Add(vItem.nIndex);
+ h; R9 D ]( f7 H' V' ~4 ~' } }! h1 {2 p. L; n8 L
BYTE nDestPos = 0;( z; C* m+ y: @8 h
for (int i=0;i<MAX_INVENTORY;i++)
- C8 c: N2 F' L, l# ]0 s! B) D' @& P {" H3 f) U6 @2 }5 L- |! G
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);
. K7 z* X V. w7 Z" E if (pItemElem)3 o4 i% U! D6 |7 C- G4 K
{
: Y( l9 [* V5 \' } if (IsUsingItem(pItemElem))
# n0 @# s2 E: [) w& H, S9 F3 f {7 G5 Y3 i" ?7 `- e5 f5 |' t
//这个位置无法放
8 `" p3 m9 R6 H. h) S2 a3 l9 S; { nDestPos++;
( G- s/ q+ u4 S# U/ e) {1 T4 [- F( N: x }: t: d' U# `/ p/ l" h% m; ^
}
" _8 i/ r/ Z/ K0 n# \, \ BYTE nSrc = pInvSort->GetItemSrc(i);
5 Y, Q. L: f4 a. p% B pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);( h" `; }4 u% B: }6 r
if (pItemElem)
: F0 j# v# ^/ j- m {
3 P1 L U0 V8 B4 f5 b6 { if (IsUsingItem(pItemElem))
, ~8 T$ {8 _$ L8 m1 N( m/ p; i* e, u {
. n& I4 r. r& S' X0 v //这个道具无法移动,跳过
* _5 C2 H5 k& y# s continue;
9 E6 w/ I2 |7 ?9 k; j+ g# b }
' ]+ ^" z# e* H- F' N }else{
+ J8 r# K) d5 S* l6 U //空位置 不用动0 V3 V, u& b2 C
continue;( @+ J% ~# a$ u, m/ ^
}
% u9 z* f5 T" O( N; \. _ //////////////////////////////////////////////////////////////////////////
! u4 r% Z* \6 Z2 ] //开始移动
2 {; R( L$ l5 @+ Y+ ?& d6 | if (nSrc == nDestPos)
* ]7 w/ i8 h2 j {
$ ?4 ~* _, F+ j6 u0 H //原地不动
6 P' H! H% }% m6 Z nDestPos++;% u; A0 F1 ~# p. f1 U
continue;
, p+ D& f3 [5 m/ D- |+ M }6 u& h" s$ t0 L, n
pInvSort->MoveItem(i,nDestPos);/ z* E) Z% V& O
g_DPlay.SendMoveItem(0,nSrc,nDestPos);
, M& j5 h T3 I Sleep(5);5 q; t! q0 e! }1 N2 K
//Error("移动 - %d->%d",nSrc,nDestPos);
4 T! | J# c6 K" J; v! Y/ L nDestPos++;
& G/ d, {; \9 E# o6 T& T }
" D! {" r8 x$ E //取第一个元素的信息7 A9 [8 h+ y8 `5 N% o
/*& K! Q+ C7 I( s' z; i1 z9 ^
if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)* N* ~6 n j2 M
{8 ?, H: H3 m, C" z3 S/ }
Error("Move - From:%d,To:%d",vItem[0].nIndex,x);/ A8 f# ~6 p. b, |( j
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);7 d- o- B0 _' K8 @+ a4 u
}
! ~0 H1 [ {2 X- C* p */% w3 G/ ~9 ^' u: d. p. o$ {
//////////////////////////////////////////////////////////////////////////* w4 h* N" U7 C% z
break;
, L+ U* H. t- \; N4 x }
+ Z* o, ]# O- w: d1 P- R/ t; ~' e3 v } : U1 T9 f7 d* m5 U# l" C% X% a
}* p3 s7 _4 l0 p' ?
m_wndMenu.SetVisible(FALSE);
( O* q% u; Y$ J G( w7 V
+ D, @3 ]3 h# ]! D, g--------------------------------------------------------------------------------------------------------
* f7 }5 @# K1 a$ Y }/ B搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)9 _, A6 M8 E q) J% F
{) _* w* V1 e4 ?7 W$ v
BaseMouseCursor();
! x7 \( F' b, j- \3 Z$ u* L: J# ?! k}( M$ I" |; n4 h6 _- o
在其下添加:# H9 g7 y8 g0 \
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)
% w @* z& `& l{' a+ ]3 L6 s+ d$ c- _) o/ w. \
m_wndMenu.DeleteAllMenu();
+ W: o* U6 L* M7 l! S) `. p) Mm_wndMenu.CreateMenu(this);$ Q# ~; [0 D* V9 d5 w
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
" L* g- P9 ?1 H4 S
' U# X% u5 j3 Z& k" Dif (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))$ p( Z' P* f8 x9 ?" }, R" Z
{
& o* Y, T& `+ N/ e( S/ U //P以上级别才可以删除所有道具
, s$ O3 y' S* b8 n m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");- |. d/ s* A$ L; p+ L y
}. d9 n" {8 L7 m6 _, V) y! s- T
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );
) A; X }5 Y: ~/ L) im_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );' A ^/ H5 O9 V3 U0 L
m_wndMenu.SetFocus();( p2 R! ]/ Z6 k2 V
}) {* D! D& S0 `1 d8 Y4 L
------------------------------------------------------------------------------------------------------------0 a% i! X- ~% j# h! W; ?
*************************
9 ]5 u- P9 I3 @7 nWndField.h文件0 j4 t$ L% w- Y, n
*************************3 D. Q7 u. a) F5 V
搜索:BOOL m_bReport;, r, k! b6 W( m( A
其后添加:9 }. a; Y% s3 A8 n @9 G/ y3 D
CWndMenu m_wndMenu;# q0 y, h5 \6 y+ ^/ R" `
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);( R! k4 C9 W: C: ?! l
其后添加:7 f3 g$ K7 g8 Z+ Z6 |/ y( L
virtual void OnRButtonUp(UINT nFlags, CPoint point);
7 r' k* h3 Z' q% v8 V
& b; {3 Z, p3 o) b' ~' p# J3 D
+ }& u8 l7 L8 G6 { |
|