-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathPage.cs
138 lines (121 loc) · 4.42 KB
/
Page.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.IO;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Resources;
namespace INVedit
{
public class Page : TabPage
{
static ResourceManager resources;
static Image head, chest, pants, boots;
GroupBox boxInventory;
NumericUpDown boxDamage;
NumericUpDown boxCount;
ItemSlot selected = null;
public string file = null;
public bool world = false;
public Dictionary<byte, ItemSlot> slots = new Dictionary<byte, ItemSlot>();
public Page(string text)
{
Text = text;
UseVisualStyleBackColor = true;
if (resources == null) {
resources = new ResourceManager("INVedit.Resources", GetType().Assembly);
head = (Image)resources.GetObject("head");
chest = (Image)resources.GetObject("chest");
pants = (Image)resources.GetObject("pants");
boots = (Image)resources.GetObject("boots");
}
boxInventory = new GroupBox(){ Text = "Inventory", Location = new Point(6, 6), Size = new Size(461, 285) };
Controls.Add(boxInventory);
boxInventory.Controls.Add(new Label(){ Location = new Point(287, 19), Size = new Size(54, 20),
Text = "Damage:", TextAlign = ContentAlignment.MiddleRight });
boxInventory.Controls.Add(new Label(){ Location = new Point(287, 44), Size = new Size(54, 20),
Text = "Count:", TextAlign = ContentAlignment.MiddleRight });
boxDamage = new NumericUpDown();
boxDamage.Location = new Point(344, 21);
boxDamage.Size = new Size(57, 20);
boxDamage.Minimum = -32657;
boxDamage.Maximum = 32656;
boxDamage.TextAlign = HorizontalAlignment.Right;
boxDamage.Enabled = false;
boxInventory.Controls.Add(boxDamage);
boxCount = new NumericUpDown();
boxCount.Location = new Point(344, 46);
boxCount.Size = new Size(57, 20);
boxCount.Minimum = 0;
boxCount.Maximum = 255;
boxCount.TextAlign = HorizontalAlignment.Right;
boxCount.Enabled = false;
boxInventory.Controls.Add(boxCount);
CreateSlot(103, 7, 19, head);
CreateSlot(102, 7 + 50, 19, chest);
CreateSlot(101, 7 + 100, 19, pants);
CreateSlot(100, 7 + 150, 19, boots);
for (int i = 0; i < 9; ++i) CreateSlot((byte)(9+i), 7 + i*50, 75);
for (int i = 0; i < 9; ++i) CreateSlot((byte)(18+i), 7 + i*50, 125);
for (int i = 0; i < 9; ++i) CreateSlot((byte)(27+i), 7 + i*50, 175);
for (int i = 0; i < 9; ++i) CreateSlot((byte)i, 7 + i*50, 231);
ItemSlot panel = new DeleteItemSlot(
(Image)resources.GetObject("delete1"),
(Image)resources.GetObject("delete2")
){ Location = new Point(407, 19), UseVisualStyleBackColor = true };
boxInventory.Controls.Add(panel);
boxDamage.LostFocus += BoxLostFocus;
boxCount.LostFocus += BoxLostFocus;
boxDamage.ValueChanged += ValueChanged;
boxCount.ValueChanged += ValueChanged;
}
void CreateSlot(byte slot, int x, int y)
{
CreateSlot(slot, x, y, null);
}
void CreateSlot(byte slot, int x, int y, Image def)
{
ItemSlot itemSlot = new ItemSlot(slot){ Location = new Point(x, y), Default = def, UseVisualStyleBackColor = true };
itemSlot.GotFocus += SelectionChanged;
itemSlot.DragDone += ItemDragDrop;
boxInventory.Controls.Add(itemSlot);
slots.Add(slot, itemSlot);
}
void ItemDragDrop(ItemSlot slot)
{
if (((TabControl)Parent).SelectedTab != this)
SelectionChanged(slot, new EventArgs());
}
void BoxLostFocus(object sender, EventArgs e)
{
NumericUpDown box = (NumericUpDown)sender;
if (box.Text == "") box.Text = "0";
}
void ValueChanged(object sender, EventArgs e)
{
if (selected.Item == null) return;
NumericUpDown box = (NumericUpDown)sender;
if (box == boxDamage) selected.Item.Damage = (short)box.Value;
if (box == boxCount) selected.Item.Count = (byte)box.Value;
selected.Refresh();
}
void SelectionChanged(object sender, EventArgs e)
{
if (selected != null) {
selected.Selected = false;
selected.Refresh();
}
selected = (ItemSlot)sender;
selected.Selected = true;
boxDamage.ValueChanged -= ValueChanged;
boxCount.ValueChanged -= ValueChanged;
bool enabled = (selected.Item != null);
boxDamage.Enabled = enabled;
boxCount.Enabled = enabled;
boxDamage.Value = enabled ? selected.Item.Damage : 0;
boxCount.Minimum = enabled ? 1 : 0;
boxCount.Value = enabled ? selected.Item.Count : 0;
boxDamage.ValueChanged += ValueChanged;
boxCount.ValueChanged += ValueChanged;
}
}
}