|
|
源文件中_Interface文件夹下WndField.cpp文件" f. l e2 s% f3 a, `% E1 R
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )$ A( ?; q* n1 P8 @ I
7 Q, G0 ?, U y, w
struct sItem
4 x9 q: O7 ^: P; j0 o6 N! Z/ h{2 ]: l. Y: U; A; {
DWORD dwId;: k: D/ o) q7 [; j; k6 Y' U
DWORD dwKind2;
e" |% L& b' i7 P/ t! x$ ODWORD dwItemId;
6 K1 Z, v) Y- j6 @. }" N, z( NBYTE nIndex;
+ ]! i4 K5 C3 c1 o: r' F: @0 ^sItem(){
/ A+ P7 p1 Z1 ] dwId = dwKind2 = dwItemId = nIndex = 0;' ~% I0 e: V; Y, z- h) p
}/ J- D, T# m6 e$ X6 D
bool operator < (const sItem p2)
3 u" j' _# @7 K$ ]; ~+ u{
$ |1 N5 w6 T; }' i" s$ ^ if (dwKind2 == p2.dwKind2)1 s& C! y$ i6 B" P
{* i, Z! M! h0 _" J* D; w& R
return dwItemId < p2.dwItemId;0 f0 i* e- G/ g; o+ O5 I# r/ _3 E( m
}else{
7 B: I) Z+ U: p1 q return dwKind2 < p2.dwKind2;
& t4 |! M5 U4 X+ W* E, O& N }
4 U- v+ t' k. ?8 R% C6 X$ {; O- w: k}: ~/ U4 ?- y/ z+ Y( K/ t* k% M
};
. @/ F) \+ C* y5 h: c1 Zclass CInventorySort
1 p0 N- A5 X% A! G+ R+ z{$ h6 s$ N; \$ Q& R; {
public:/ B( E$ X" k5 R2 z) S1 b C4 Q) K
CInventorySort(): W4 L6 K6 \+ u& N- {
{4 v5 M% W$ ], _/ N3 c7 _
m_dwPos = 0;
0 i- t: s4 Y$ _7 p& a" S}
: s6 X S7 m. i+ q~CInventorySort(){}
/ L2 o* p1 {; {& ` h. pprivate:% b9 Z) L0 g1 @1 g
sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息, m, D9 v7 T, B/ O8 [0 B
DWORD m_dwPos;
# X4 s, x2 v! ]8 C1 p; Upublic:; Q+ b$ {+ l. K; @. V$ B
void Add(BYTE nIndex)
2 E9 b: a S/ k{2 [. W `; |3 ~ c+ a1 ^0 R
if (m_dwPos >= MAX_INVENTORY)& G3 a& [0 a( D2 c5 Q1 V; G, ~ v
{" r* f9 y& |. S
return;9 {( D5 g7 a! \) q$ S4 ] Z: Y
}
0 [1 p+ l) R% _& E8 q: S6 s! B m_Item[m_dwPos].nIndex = nIndex;
& _; K: f$ S0 v# w m_Item[m_dwPos].dwId = m_dwPos;, }* S- M6 o @; c( P7 f
m_dwPos++;" d7 W1 b0 O7 R5 X# y) s
}- v! W4 A/ p& L* I F# d
BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列9 \: Y3 D4 H. ?9 @+ m$ q8 ]# H
{
# ~/ R4 M! f" s for (int i=0;i<MAX_INVENTORY;i++)
1 k7 x2 x( x9 W% h+ K$ m) |! w; k {
- ^; v& r7 T& X7 N% ]2 m% o if (m_Item.dwId == dwId)
$ {- X: r2 E7 F, O9 |0 }' s0 _; W {: o( ]9 k8 [* `" R$ M
return m_Item.nIndex;0 c; t! T. e0 j& ]
}1 H' O3 o Z7 E+ b: k
}9 ?/ e5 }# f4 t9 F. B
return 255;3 d5 y j* l0 x3 U( M: m
}
$ b- |4 T% p3 ]6 [3 X: \void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置% G3 |2 @, `# O% ]! a# P: z
{
?7 O" _; C9 D7 r2 {4 T# S* { BYTE nTmp = 0;
2 Z. t5 v' o* P# ^/ j% |* H' F bool bDest = false,bSrc = false;9 |+ N2 E7 u7 v( s( l
for (int i=0;i<MAX_INVENTORY;i++)
2 r/ W+ J2 Y; k {* d: N5 F# ?1 u- h
if (dwSrcId == m_Item.dwId)
# I( ~9 E# E) r {( ?9 W! d% v( x d- N: M; T% Y
//id相等 则 改变对应的dest和src. b8 f) z; [2 G$ O9 @. c9 i) U, Y3 N
nTmp = m_Item.nIndex;
: N2 I l1 E6 \7 |5 S7 r6 P1 H m_Item.nIndex = dest;) F$ l( W2 U( Y. W ^4 p
}* Q5 a: \5 J4 f" B# I9 U
}
' E8 S& p* W5 I0 Q4 Y //临时数据保存完毕,交换开始6 s- ]: V+ V0 J5 |1 e+ Y: k9 p C
for (int i=0;i<MAX_INVENTORY;i++)* q+ u" |1 W9 g9 @; k, O
{
2 {7 o D2 N* @3 w9 X/ V if (dest == m_Item.nIndex)
r5 q8 f3 q8 `1 n; g( s {, O9 l# t& ?. d+ y% c4 f4 J
//id相等 则 改变对应的dest和src( q; p& r5 p& I8 a ~8 r
m_Item.nIndex = nTmp;
' I2 [) Q! e) | }
% Y z5 B- l. e8 H }% Z4 W! F% E! t1 [
}+ n' `+ u, @$ A( i% u$ D7 A; S
};7 ^, \/ K1 s: R4 e1 U: x+ V
-------------------------------------------------------------------------: a9 S% q1 \% ~ J) d1 w
依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )2 x6 d- j. s9 u* y) D
搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);( h6 r/ w Q* b4 d1 v9 I* `" a g! C
紧靠其上添加:
1 v7 c7 Y5 e/ K; a8 y8 t0 D% sif( pWndBase == &m_wndMenu )" l; r/ I% Z7 e D5 B- y/ Q
{
0 t4 d. z# {9 ~6 I switch( nID )0 o1 G M) X! J5 ?4 u ~% W
{
0 Z# O% O/ b( q! I6 c5 B case 2:0 {& q8 k- [' }$ ^
{
9 Z5 w) N" X6 n, O" Y+ W //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL);
' a+ S2 m" ?" m7 p if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))* J: b" t. t" X
{; d9 \0 x4 ?0 D
break;
1 d8 t3 i3 n0 g' g0 I1 u1 I }
]5 { \2 O d0 d9 f/ b for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++)" [8 l/ B4 ^9 L- U/ [
{/ U% j u* Y, f# O3 L/ [- h
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);
) m2 W! a; D$ {1 { if( !pItemElem )
7 a1 h* L1 u- g2 m' t9 B continue;
1 |/ o9 D9 [( n- B4 W/ O if(pItemElem->GetExtra() > 0)5 e- ~$ g1 L+ i( S) \/ }% s4 |4 w/ z
continue;! d4 }# x) V! T9 B" E
if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) )
+ S. [8 s0 _1 s1 b8 A continue;
$ U# e4 B& J) X; H1 Z+ V3 P if( g_pPlayer->IsUsing( pItemElem ) )
i* t) _. r: y" Z4 T' N continue;$ `% D/ b- Z- _5 H! w- g: J
if( pItemElem->IsUndestructable() == TRUE )
9 M1 v- Z- c5 W7 I- L5 [2 J {
4 U8 `; K, V* b g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) );
9 k6 A+ g4 E M( J$ I; k continue;0 U2 v, H) i' R3 N9 Q. \4 I) L
}$ f/ O4 y! Y" P* D. W
g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum);
: c3 n( S/ ?! U. z3 Z4 _ }" k- d r( W0 Y% B
break;
8 t+ W- B- x: a2 P; `& O( ~ }
2 X/ t9 T% ]7 Y3 h5 Q. W case 1:
7 ^/ X1 c7 L& x, f% O. P, E; p {
: w9 [+ u& g g! {2 C //整理背包
- @& s9 X/ p8 q0 \! I //////////////////////////////////////////////////////////////////////////
' K/ h/ k q5 [; _ //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) );
- k( H+ W1 C9 v5 c4 h7 Z/ S' P //////////////////////////////////////////////////////////////////////////: {9 k% T/ K8 W7 z& S0 h5 z- q* Q5 B
//////////////////////////////////////////////////////////////////////////9 h ^8 V/ O( B( L
CInventorySort* pInvSort = new CInventorySort;+ w( K, W/ o7 L/ x* L9 o. x
vector <sItem> vItem;' s" i6 p! [) ~8 M2 |
vItem.resize(MAX_INVENTORY);//初始化大小1 Y, _# f* m7 |. A: G9 ~; k$ j1 s
//////////////////////////////////////////////////////////////////////////3 C6 c: }* E3 [0 W
//填充数据
' U2 _* h7 \- B( I5 u for (int i=0;i<MAX_INVENTORY;i++)0 r- M* k' ]3 G O6 a
{) w+ l8 n% U$ I: _ f/ \6 j
CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);/ [! y, i" k) K7 K; [' h
if (!pItemElem)! ], Y5 D! N ?. G# h
{
) Z' p" T' ~( h9 e vItem.dwKind2 = 0xffffffff;
3 N& {% _1 N7 o0 O3 H. \' h vItem.dwItemId = 0xffffffff;3 D6 R+ `- G! x2 ]$ u
vItem.nIndex = i;
- y! w8 Y! c: G x# w; V! D }else {. S6 ^6 D& g4 @, c& F+ o
ItemProp* pProp = pItemElem->GetProp();
0 s! B1 ?5 j+ f vItem.dwKind2 = pProp->dwItemKind2;2 u: z! s9 y& q7 [
vItem.dwItemId = pItemElem->m_dwItemId;
( n- \/ a3 [! T# w vItem.nIndex = i;5 l6 c. [ ~: U) Z0 Y
}
$ A# `# T$ k: V- G2 y8 K //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
$ k9 r0 p: X% |; _) E# S }
" g' k$ @' {" {1 A8 t1 L# v- R //////////////////////////////////////////////////////////////////////////0 m. k! H( B; b% t1 b1 |; f
sort(vItem.begin(),vItem.end());//排序
2 H3 A! _- Q" ?1 k! u9 Q //////////////////////////////////////////////////////////////////////////
% O% p6 D" k* s/ B* ]! V; V //交换- d. \4 z) V% L9 t# X( o; d0 T; u
for (size_t i=0;i<vItem.size();i++)' A9 ~* J0 I/ l8 x
{1 g, \. i" d0 L2 X+ C# I
//Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);
( | G& @+ x! M" @2 c' @& R8 i0 u3 | pInvSort->Add(vItem.nIndex); e& O2 l R! [' A5 y* N8 F8 |
}
* r/ T6 I+ R1 m2 q' B BYTE nDestPos = 0;/ v; @% L) b( c! A* F+ j; b! i) g
for (int i=0;i<MAX_INVENTORY;i++). Q' W5 h' s' r
{
: j, v& |, n L; `; j! k1 D CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);. \! l4 J- X; [; q
if (pItemElem)
/ }% N! x: i9 E+ I' a7 B9 a+ d {
7 c5 f6 ~% m; C/ p+ w, w; T* O if (IsUsingItem(pItemElem))6 @8 a$ I% |/ u! x9 e
{
6 w# j/ G3 M# _" D4 \2 z //这个位置无法放
" {" r/ W! Q2 e2 V% i% {/ N. M3 S; E nDestPos++;
" M# N5 `6 P- S# A1 N0 v; w* e }
4 p7 Z' h6 N/ x( I' ]; V% H N% t }* L- m* t& @* H
BYTE nSrc = pInvSort->GetItemSrc(i);2 k) Q+ [( ?- x2 V, H. W3 X
pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc);% |, |$ l% f h6 Q, i# f
if (pItemElem)0 F( _9 n7 r) F/ W; |# W& w
{8 L; P5 t$ \; v2 a
if (IsUsingItem(pItemElem))
% P! O7 d$ z2 r: \/ ~! | {9 z. ~) A* K# o
//这个道具无法移动,跳过
4 [0 d/ z' |/ F m! g" R& n continue;
0 `2 P" ]# x! y8 o* _ }# `" B* B5 D% K9 R: \! }
}else{4 [( ?; b; K/ ?" @
//空位置 不用动: Y; `4 d. l9 r7 R/ x( M
continue;4 E8 O; _7 {7 Y8 E# X" ?& ?
}
6 D9 c7 }* J' } //////////////////////////////////////////////////////////////////////////* i! Y. E H/ g5 ?
//开始移动0 V: Y1 i/ P) {: m3 ]
if (nSrc == nDestPos)/ g# O- F& [. b. ]3 j
{
. y: S# }* Z* _* U+ w //原地不动
( k7 m2 Y9 {0 X% H# I- v nDestPos++;7 L) Z. u0 M/ d+ h
continue;
( N6 ^2 h1 e T2 a* u }
' k1 W% x+ R# V8 i1 f! z" h4 l pInvSort->MoveItem(i,nDestPos);
3 j p& L, W ]0 ?0 l* k* N& b g_DPlay.SendMoveItem(0,nSrc,nDestPos);
2 ?3 v, t8 ?2 v0 ~* w' v: | Sleep(5);6 A# U5 t6 S1 H# Q! v \/ X0 c
//Error("移动 - %d->%d",nSrc,nDestPos);+ y& Y( g; V: g! n4 l( t3 z4 O T
nDestPos++;
7 T/ x: O& {1 N# C( X. h! } }7 S) y7 ^" k9 [+ f- @
//取第一个元素的信息
( _8 i8 V; ^+ w7 c- w /*
% Q" P2 F3 W5 `3 N# P if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)/ ]; p1 e) o9 F& N5 p
{
: D$ b4 j) M0 I Error("Move - From:%d,To:%d",vItem[0].nIndex,x);4 [* {' M4 y/ ]9 A f0 K* E; _
g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x);
' o% ^& Q5 c: T5 x5 g: L1 P; L }
! E' v9 J& {8 _0 B2 Q */, o7 F, {/ c: Q m, V9 X6 Y9 u; n- n
//////////////////////////////////////////////////////////////////////////
F& d3 Y. q8 \1 ^- ]3 N/ e( d break;& O) Z+ C4 n) A# h9 c) o
}
0 I5 ]! h3 `" P$ i; i* Y }
7 A, f% b& B% s2 O' M}
3 P9 h7 s& S1 `0 G# C Bm_wndMenu.SetVisible(FALSE);
" _5 n( v3 ^- c/ }: c
+ S! R+ G. T- ?( ? w; Q--------------------------------------------------------------------------------------------------------
8 H% r* W" z1 |& y8 Q& B搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point)) X" M0 \9 z7 M0 a" n' \! S: c- F
{1 n0 h: y% }0 ^- c% v/ b; I; y8 C7 T
BaseMouseCursor(); T- Q. I# m2 ^" }6 K, O
}- S* u) Y f" }' ]2 o
在其下添加:$ z5 n% L4 \4 T$ d+ H# ~: E
void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)9 s% z+ { ~; d- ^4 }$ d9 B5 t* t
{
. z6 j' y. k# S. V+ }m_wndMenu.DeleteAllMenu();" D7 N" h/ _% ? ?
m_wndMenu.CreateMenu(this);1 _# E5 P$ d) A9 _" A4 r1 R- X4 p
m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包");
% A2 q0 r6 j# s
6 h4 d: `- s4 L; f/ |1 w- o/ ^if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR))
! s; Q, i1 [) \{
" @' d4 v6 ^& f W; [# z //P以上级别才可以删除所有道具! z: v/ c# V2 F1 P0 f
m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");
8 G# z/ j. t7 k6 V0 H* c}$ w3 a* e9 d: ~# Z3 w. \2 X% q
m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point );* @1 @5 m) T( q' d8 h9 a
m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() );; s5 Q( T# z* \2 R1 X% F
m_wndMenu.SetFocus();
. B8 ~/ J% C* m# Z5 N}
5 |% W: |9 G" z+ p! n& E: L------------------------------------------------------------------------------------------------------------
( @; t7 g5 a& z$ E% k: Z4 A*************************6 @* y% N& I: Q- x4 c
WndField.h文件
) G1 Z4 D" ?! ^1 p*************************
# k0 f# v' G, \1 I* [" e2 I9 ~0 n3 K搜索:BOOL m_bReport;* ~- x0 v6 a1 |8 s+ H4 O; \
其后添加:
9 ]9 j; o6 X/ M5 xCWndMenu m_wndMenu;( G9 M# z: E' h* Z6 E# W2 t; x/ t ?( I
搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);5 Z; l C- M+ ~& Y4 A% v' F
其后添加:
! [* Q7 B8 A6 e1 Uvirtual void OnRButtonUp(UINT nFlags, CPoint point);
! m7 ?9 T) w/ R
: F/ C6 N- { a3 k: p8 }, v9 n5 T) b4 V @+ C
|
|