3
3
using System . Drawing . Drawing2D ;
4
4
using System . Drawing . Imaging ;
5
5
using System . Windows . Forms ;
6
+ using System . Collections . Generic ;
6
7
7
8
namespace INVedit
8
9
{
@@ -11,7 +12,6 @@ public class ItemSlot : CheckBox
11
12
static Font font1 = new Font ( FontFamily . GenericMonospace , 8 , FontStyle . Bold ) ;
12
13
static Font font2 = new Font ( FontFamily . GenericMonospace , 10 , FontStyle . Bold ) ;
13
14
protected static Item other = null ;
14
- ToolTip toolTip = new ToolTip ( ) { AutomaticDelay = 300 } ;
15
15
16
16
protected static event Action < ItemSlot > DragBegin = delegate { } ;
17
17
protected static event Action < ItemSlot > DragEnd = delegate { } ;
@@ -22,6 +22,7 @@ public class ItemSlot : CheckBox
22
22
public Image Default { get ; set ; }
23
23
24
24
public event Action < ItemSlot > DragDone = delegate { } ;
25
+ public event Action < ItemSlot > Changed = delegate { } ;
25
26
26
27
public ItemSlot ( byte slot )
27
28
{
@@ -63,15 +64,17 @@ protected override void OnDragOver(DragEventArgs e)
63
64
Item item = ( Item ) e . Data . GetData ( typeof ( Item ) ) ;
64
65
if ( Item != item ) {
65
66
if ( ( e . AllowedEffect & DragDropEffects . Move ) == DragDropEffects . Move ) {
66
- if ( ( e . KeyState & 8 ) == 8 ) e . Effect = DragDropEffects . Copy ;
67
- else if ( ( e . KeyState & 32 ) == 32 && item . Count > 1 ) {
67
+ if ( ( Control . ModifierKeys & Keys . Control ) == Keys . Control )
68
+ e . Effect = DragDropEffects . Copy ;
69
+ else if ( ( Control . ModifierKeys & Keys . Alt ) == Keys . Alt && item . Count > 1 ) {
68
70
if ( Item != null ) {
69
- if ( Item . ID == item . ID && item . Stackable && Item . Count < 64 )
71
+ if ( Item . ID == item . ID && Item . Count < item . Stack )
70
72
e . Effect = DragDropEffects . Link ;
71
73
else e . Effect = DragDropEffects . None ;
72
74
} else e . Effect = DragDropEffects . Link ;
73
75
} else if ( Item != null && Item . ID == item . ID &&
74
- Item . Count >= ( item . Stackable ? 64 : 1 ) ) {
76
+ Item . Damage == item . Damage &&
77
+ Item . Count + item . Count >= item . Stack ) {
75
78
e . Effect = DragDropEffects . None ;
76
79
} else e . Effect = DragDropEffects . Move ;
77
80
} else e . Effect = DragDropEffects . Copy ;
@@ -93,34 +96,46 @@ protected override void OnDragDrop(DragEventArgs e)
93
96
Item . Count = Math . Min ( ( byte ) ( count + item . Count / 2 ) , ( byte ) 64 ) ;
94
97
item . Count -= ( byte ) ( Item . Count - count ) ;
95
98
}
96
- } else if ( e . Effect == DragDropEffects . Move && Item != null && item . ID == Item . ID ) {
97
- byte count = ( byte ) Math . Min ( ( int ) Item . Count + item . Count , item . Stackable ? 64 : 1 ) ;
98
- byte over = ( byte ) Math . Max ( ( int ) Item . Count + item . Count - ( item . Stackable ? 64 : 1 ) , 0 ) ;
99
+ } else if ( e . Effect == DragDropEffects . Move && Item != null && item . ID == Item . ID && Item . Damage == item . Damage ) {
100
+ byte count = ( byte ) Math . Min ( ( int ) Item . Count + item . Count , item . Stack ) ;
101
+ byte over = ( byte ) Math . Max ( ( int ) Item . Count + item . Count - item . Stack , 0 ) ;
99
102
Item = new Item ( Item . ID , count , Slot , Item . Damage ) ;
100
- other = over > 0 ? new Item ( Item . ID , over ) : null ;
103
+ other = ( over > 0 ) ? new Item ( Item . ID , over ) : null ;
101
104
} else {
102
105
other = Item ; Item = item ;
103
106
if ( e . Effect == DragDropEffects . Copy )
104
107
Item = new Item ( Item . ID , Item . Count , Slot , Item . Damage ) ;
105
108
else Item . Slot = Slot ;
106
- toolTip . SetToolTip ( this , Item . Name ) ;
107
- toolTip . Active = true ;
108
109
}
109
110
LostFocus += OnLostFocus ;
110
111
Select ( ) ;
111
112
}
112
113
113
- public void Set ( short id , byte count , short damage )
114
+ protected override void OnMouseWheel ( MouseEventArgs e )
114
115
{
115
- Item = new Item ( id , count , Slot , damage ) ;
116
- toolTip . SetToolTip ( this , Item . Name ) ;
117
- toolTip . Active = true ;
118
- }
119
-
120
- public void Clear ( )
121
- {
122
- Item = null ;
123
- toolTip . Active = false ;
116
+ if ( Item == null ) return ;
117
+ int count = ( ( ( Control . ModifierKeys & Keys . Control ) == Keys . Control ) ? 4 : 1 ) * Math . Sign ( e . Delta ) ;
118
+ if ( ( Control . ModifierKeys & Keys . Shift ) == Keys . Shift ) {
119
+ int before = Item . Damage ;
120
+ if ( Item . MaxDamage > 0 )
121
+ Item . Damage = ( short ) Math . Min ( Math . Max ( ( int ) Item . Damage + Math . Max ( Math . Abs ( count * ( int ) Item . MaxDamage / 32 ) , 1 ) * - Math . Sign ( count ) , 0 ) , Item . MaxDamage ) ;
122
+ else if ( Item . Alternative ) {
123
+ Dictionary < short , Data . Item > items = Data . items [ Item . ID ] ;
124
+ List < short > list = new List < short > ( items . Keys ) ;
125
+ int index = list . IndexOf ( Item . Damage ) ;
126
+ if ( index == - 1 ) return ;
127
+ if ( count > 0 ) { if ( index < list . Count - 1 ) Item . Damage = list [ index + 1 ] ; }
128
+ else { if ( index > 0 ) Item . Damage = list [ index - 1 ] ; }
129
+ } if ( before == Item . Damage ) return ;
130
+ } else {
131
+ if ( Item . Stack == 1 ) return ;
132
+ int before = Item . Count ;
133
+ if ( Item . Count == 1 && count == 4 ) count = 3 ;
134
+ Item . Count = ( byte ) Math . Min ( Math . Max ( ( int ) Item . Count + count , 1 ) , Item . Stack ) ;
135
+ if ( before == Item . Count ) return ;
136
+ }
137
+ Refresh ( ) ;
138
+ Changed ( this ) ;
124
139
}
125
140
126
141
protected override void OnPaint ( PaintEventArgs e )
@@ -159,9 +174,8 @@ protected override void OnPaint(PaintEventArgs e)
159
174
string value = Item . Count . ToString ( ) ;
160
175
Color color1 = Color . Black ;
161
176
Color color2 = Color . White ;
162
- if ( Item . Count > ( Item . Stackable ? 64 : 1 ) ) {
177
+ if ( Item . Count > Item . Stack )
163
178
color1 = Color . FromArgb ( 172 , 0 , 0 ) ;
164
- }
165
179
DrawString2 ( g , color1 , 3 , 1 , value ) ;
166
180
DrawString2 ( g , color1 , 4 , 1 , value ) ;
167
181
DrawString2 ( g , color1 , 2 , 2 , value ) ;
@@ -171,7 +185,7 @@ protected override void OnPaint(PaintEventArgs e)
171
185
DrawString2 ( g , color2 , 3 , 2 , value ) ;
172
186
DrawString2 ( g , color2 , 4 , 2 , value ) ;
173
187
}
174
- if ( Item . Damage != 0 ) {
188
+ if ( ! Data . items [ Item . ID ] . ContainsKey ( Item . Damage ) ) {
175
189
if ( Item . Damage > 0 && Item . Damage <= Item . MaxDamage && Item . MaxDamage > 0 ) {
176
190
Rectangle rect = new Rectangle ( 5 , ClientSize . Height - 8 , ClientSize . Width - 10 , 3 ) ;
177
191
g . FillRectangle ( new SolidBrush ( Color . Black ) , rect ) ;
0 commit comments