Skip to content

Commit 91bd63b

Browse files
author
Sven Braune
committed
Version 0.9.9
1 parent 81c7598 commit 91bd63b

13 files changed

+248
-121
lines changed

AboutForm.Designer.cs

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AboutForm.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@
121121
<data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
122122
<value>
123123
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
124-
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDgAA
125-
Cw4BQL7hQQAACRhJREFUWEelV2tQk+kV1g7b27rtrFVWVC4Kcr+GAAkJuXxJSCBcEgghhIRAwkUBEQmX
124+
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDQAA
125+
Cw0B7QfALAAACRhJREFUWEelV2tQk+kV1g7b27rtrFVWVC4Kcr+GAAkJuXxJSCBcEgghhIRAwkUBEQmX
126126
QLijiNYVR7B4v9bFrpfdyuw4Ha9Tp451Rtdxf/hDnXHsOqhbta52ti11n573Y7HbGUbYysyZN1/yvuc8
127127
5znPOe/H3Dk/4E+tVi+l7afJDpIdOHv27F9/wPG330oANlRUVKC0tBT0+QnZz97e6yw9UDAfsvFLly7h
128128
2bNnOHr06EN6zp7l8bffRsF+bDabB27fvo07d+7gwoULKC8v7317zz/AA4GwDg4Ovnj+/DmePn0KAsRK

Data.cs

+46-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class Data
1313
{
1414
static readonly Dictionary<string, Image> images = new Dictionary<string, Image>();
1515
public static readonly ImageList list = new ImageList(){ ColorDepth = ColorDepth.Depth32Bit };
16-
public static readonly Dictionary<short, Item> items = new Dictionary<short, Item>();
16+
public static readonly Items items = new Items();
1717
public static readonly Dictionary<string, Group> groups = new Dictionary<string, Group>();
1818
public static Image unknown;
1919
public static int version = int.MinValue;
@@ -22,6 +22,7 @@ public static void Init(string path)
2222
{
2323
ResourceManager resources = new ResourceManager("INVedit.Resources", typeof(Data).Assembly);
2424
unknown = (Image)resources.GetObject("unknown");
25+
list.Images.Add(unknown);
2526

2627
string[] lines = File.ReadAllLines(path);
2728
for (int i = 1; i <= lines.Length; ++i) {
@@ -50,14 +51,14 @@ public static void Init(string path)
5051
try { icon = short.Parse(split[2]); }
5152
catch (Exception e) { throw new DataException("Failed to parse column 'ICON' at line "+i+" in file '"+path+"'.", e); }
5253
if (!items.ContainsKey(icon)) throw new DataException("Invalid item id '"+icon+"' in column 'ICON' at line "+i+" in file '"+path+"'.");
53-
int imageIndex = items[icon].imageIndex;
54+
int imageIndex = items[icon][0].imageIndex;
5455
string[] l = split[3].Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);
5556
Group group = new Group(name, imageIndex);
5657
foreach (string n in l) {
5758
short s;
5859
try { s = short.Parse(n); }
5960
catch (Exception e) { throw new DataException("Failed to parse column 'ITEMS' at line "+i+" in file '"+path+"'.", e); }
60-
if (items.ContainsKey(s)) group.Add(items[s]);
61+
if (items.ContainsKey(s)) foreach (Item item in items[s].Values) group.Add(item);
6162
else MessageBox.Show("Invalid item id '"+s+"' in column 'ITEMS' at line "+i+" in file '"+path+"'.",
6263
"Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
6364
}
@@ -78,15 +79,36 @@ public static void Init(string path)
7879
} catch (Exception e) { throw new DataException("Failed to parse column 'CORDS' at line "+i+" in file '"+path+"'.", e); }
7980
if (x < 0 || y < 0 || x*16+16 > image.Width || y*16+16 > image.Height)
8081
throw new DataException("Invalid image cords "+x+","+y+" at line "+i+" in file '"+path+"'.");
81-
bool stackable = true;
82+
byte stack = 64;
83+
short damage = 0;
8284
short maxDamage = 0;
8385
if (split.Length == 5) {
84-
stackable = false;
85-
try { maxDamage = short.Parse(split[4]); }
86+
string str = split[4];
87+
char chr = ' ';
88+
if (str[0]=='+' || str[0]=='x') {
89+
chr = str[0];
90+
str = str.Substring(1, str.Length-1);
91+
}
92+
short val;
93+
try { val = short.Parse(str); }
8694
catch (Exception e) { throw new DataException("Failed to parse column 'DAMAGE' at line "+i+" in file '"+path+"'.", e); }
87-
if (maxDamage < 0) throw new DataException("Failed to parse column 'DAMAGE' at line "+i+" in file '"+path+"'.");
95+
switch (chr) {
96+
case '+':
97+
if (val <= 0) throw new DataException("Failed to parse column 'DAMAGE' at line "+i+" in file '"+path+"'.");
98+
stack = 1;
99+
maxDamage = val;
100+
break;
101+
case 'x':
102+
if (val <= 0) throw new DataException("Failed to parse column 'DAMAGE' at line "+i+" in file '"+path+"'.");
103+
if (val > 255) throw new DataException("Failed to parse column 'DAMAGE' at line "+i+" in file '"+path+"'.");
104+
stack = (byte)val;
105+
break;
106+
default:
107+
damage = val;
108+
break;
109+
}
88110
}
89-
items.Add(id, new Item(id, name, stackable, maxDamage, image, x, y));
111+
items.Add(new Item(id, name, stack, damage, maxDamage, image, x, y));
90112
}
91113
} catch (Exception e) {
92114
if (MessageBox.Show(e.Message, "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
@@ -105,19 +127,32 @@ static Image LoadImage(string path)
105127
}
106128
}
107129

130+
internal class Items : Dictionary<short, Dictionary<short, Item>>
131+
{
132+
public void Add(Item item)
133+
{
134+
Dictionary<short, Item> list;
135+
if (ContainsKey(item.id)) list = this[item.id];
136+
else { list = new Dictionary<short, Item>(); Add(item.id, list); }
137+
list.Add(item.damage, item);
138+
}
139+
}
140+
108141
internal class Item
109142
{
110143
public readonly short id;
111144
public readonly string name;
112-
public readonly bool stackable;
145+
public readonly byte stack;
146+
public readonly short damage;
113147
public readonly short maxDamage;
114148
public readonly int imageIndex;
115149

116-
internal Item(short id, string name, bool stackable, short maxDamage, Image image, int x, int y)
150+
internal Item(short id, string name, byte stack, short damage, short maxDamage, Image image, int x, int y)
117151
{
118152
this.id = id;
119153
this.name = name;
120-
this.stackable = stackable;
154+
this.stack = stack;
155+
this.damage = damage;
121156
this.maxDamage = maxDamage;
122157

123158
Bitmap b = new Bitmap(16, 16);

Inventory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class Inventory
1010
public static void Load(Tag inventory, Dictionary<byte, ItemSlot> slots)
1111
{
1212
try {
13-
foreach (ItemSlot slot in slots.Values) slot.Clear();
13+
foreach (ItemSlot slot in slots.Values) slot.Item = null;
1414
foreach (Tag tag in inventory) {
1515
short id = (short)tag["id"];
1616
byte slot = (byte)tag["Slot"];

Item.cs

+41-20
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,52 @@ namespace INVedit
55
{
66
public class Item
77
{
8+
Data.Item item {
9+
get {
10+
if (Data.items.ContainsKey(ID)) {
11+
if (Data.items[ID].ContainsKey(Damage))
12+
return Data.items[ID][Damage];
13+
else return Data.items[ID][0];
14+
} else return null;
15+
}
16+
}
17+
818
public short ID { get; set; }
919
public byte Count { get; set; }
1020
public byte Slot { get; set; }
1121
public short Damage { get; set; }
1222

13-
public bool Known { get; set; }
14-
public string Name { get; set; }
15-
public bool Stackable { get; set; }
16-
public short MaxDamage { get; set; }
17-
public Image Image { get; set; }
23+
public bool Known { get { return (item != null); } }
24+
public bool Alternative {
25+
get {
26+
if (!Known) return false;
27+
return (Data.items[ID].Count > 1);
28+
}
29+
}
30+
public string Name {
31+
get {
32+
if (!Known) return "Unknown item "+ID;
33+
return item.name;
34+
}
35+
}
36+
public byte Stack {
37+
get {
38+
if (!Known) return 64;
39+
return item.stack;
40+
}
41+
}
42+
public short MaxDamage {
43+
get {
44+
if (!Known) return 0;
45+
return item.maxDamage;
46+
}
47+
}
48+
public Image Image {
49+
get {
50+
if (!Known) return Data.unknown;
51+
return Data.list.Images[item.imageIndex];
52+
}
53+
}
1854

1955
public Item(short id)
2056
: this(id, 1, 0, 0) { }
@@ -28,21 +64,6 @@ public Item(short id, byte count, byte slot, short damage)
2864
Count = count;
2965
Slot = slot;
3066
Damage = damage;
31-
32-
if (Data.items.ContainsKey(id)) {
33-
Data.Item item = Data.items[id];
34-
Known = true;
35-
Name = item.name;
36-
Stackable = item.stackable;
37-
MaxDamage = item.maxDamage;
38-
Image = Data.list.Images[item.imageIndex];
39-
} else {
40-
Name = "Unknown item "+id;
41-
Known = false;
42-
Stackable = false;
43-
MaxDamage = 0;
44-
Image = Data.unknown;
45-
}
4667
}
4768
}
4869
}

ItemSlot.cs

+38-24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing.Drawing2D;
44
using System.Drawing.Imaging;
55
using System.Windows.Forms;
6+
using System.Collections.Generic;
67

78
namespace INVedit
89
{
@@ -11,7 +12,6 @@ public class ItemSlot : CheckBox
1112
static Font font1 = new Font(FontFamily.GenericMonospace, 8, FontStyle.Bold);
1213
static Font font2 = new Font(FontFamily.GenericMonospace, 10, FontStyle.Bold);
1314
protected static Item other = null;
14-
ToolTip toolTip = new ToolTip(){ AutomaticDelay = 300 };
1515

1616
protected static event Action<ItemSlot> DragBegin = delegate { };
1717
protected static event Action<ItemSlot> DragEnd = delegate { };
@@ -22,6 +22,7 @@ public class ItemSlot : CheckBox
2222
public Image Default { get; set; }
2323

2424
public event Action<ItemSlot> DragDone = delegate { };
25+
public event Action<ItemSlot> Changed = delegate { };
2526

2627
public ItemSlot(byte slot)
2728
{
@@ -63,15 +64,17 @@ protected override void OnDragOver(DragEventArgs e)
6364
Item item = (Item)e.Data.GetData(typeof(Item));
6465
if (Item != item) {
6566
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) {
6870
if (Item != null) {
69-
if (Item.ID == item.ID && item.Stackable && Item.Count < 64)
71+
if (Item.ID == item.ID && Item.Count < item.Stack)
7072
e.Effect = DragDropEffects.Link;
7173
else e.Effect = DragDropEffects.None;
7274
} else e.Effect = DragDropEffects.Link;
7375
} 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) {
7578
e.Effect = DragDropEffects.None;
7679
} else e.Effect = DragDropEffects.Move;
7780
} else e.Effect = DragDropEffects.Copy;
@@ -93,34 +96,46 @@ protected override void OnDragDrop(DragEventArgs e)
9396
Item.Count = Math.Min((byte)(count+item.Count/2), (byte)64);
9497
item.Count -= (byte)(Item.Count-count);
9598
}
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);
99102
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;
101104
} else {
102105
other = Item; Item = item;
103106
if (e.Effect == DragDropEffects.Copy)
104107
Item = new Item(Item.ID, Item.Count, Slot, Item.Damage);
105108
else Item.Slot = Slot;
106-
toolTip.SetToolTip(this, Item.Name);
107-
toolTip.Active = true;
108109
}
109110
LostFocus += OnLostFocus;
110111
Select();
111112
}
112113

113-
public void Set(short id, byte count, short damage)
114+
protected override void OnMouseWheel(MouseEventArgs e)
114115
{
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);
124139
}
125140

126141
protected override void OnPaint(PaintEventArgs e)
@@ -159,9 +174,8 @@ protected override void OnPaint(PaintEventArgs e)
159174
string value = Item.Count.ToString();
160175
Color color1 = Color.Black;
161176
Color color2 = Color.White;
162-
if (Item.Count > (Item.Stackable ? 64 : 1)) {
177+
if (Item.Count > Item.Stack)
163178
color1 = Color.FromArgb(172, 0, 0);
164-
}
165179
DrawString2(g, color1, 3, 1, value);
166180
DrawString2(g, color1, 4, 1, value);
167181
DrawString2(g, color1, 2, 2, value);
@@ -171,7 +185,7 @@ protected override void OnPaint(PaintEventArgs e)
171185
DrawString2(g, color2, 3, 2, value);
172186
DrawString2(g, color2, 4, 2, value);
173187
}
174-
if (Item.Damage != 0) {
188+
if (!Data.items[Item.ID].ContainsKey(Item.Damage)) {
175189
if (Item.Damage > 0 && Item.Damage <= Item.MaxDamage && Item.MaxDamage > 0) {
176190
Rectangle rect = new Rectangle(5, ClientSize.Height-8, ClientSize.Width-10, 3);
177191
g.FillRectangle(new SolidBrush(Color.Black), rect);

0 commit comments

Comments
 (0)