/
formIconPicker.cs
201 lines (170 loc) · 6.28 KB
/
formIconPicker.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* EQEmuItemEditor - Application for customizing EQEmu server items
*
* By Shendare (Jon D. Jackson)
*
* Portions of this code not covered by another author's or entity's copyright are released under
* the Creative Commons Zero (CC0) public domain license.
*
* To the extent possible under law, Shendare (Jon D. Jackson) has waived all copyright and
* related or neighboring rights to this EQEmuItemEditor application.
* This work is published from: The United States.
*
* You may copy, modify, and distribute the work, even for commercial purposes, without asking permission.
*
* For more information, read the CC0 summary and full legal text here:
*
* https://creativecommons.org/publicdomain/zero/1.0/
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace EQEmuItemEditor
{
public partial class formIconPicker : Form
{
private formMain MainForm;
private int IconID = -1;
private PictureBox IconSelected = null;
public formIconPicker()
{
InitializeComponent();
}
private void formIconPicker_Load(object sender, EventArgs e)
{
MainForm = (formMain)this.Owner;
if (MainForm.itemIcons.Images.Count == 0)
{
listItemCategory.Enabled = false;
listItemCategory.Text = "No local item icons found.";
flowIcons.BackColor = SystemColors.ControlLight;
}
else
{
listItemCategory.Enabled = true;
listItemCategory.Items.AddRange(MainForm.IconCategories.ToArray());
flowIcons.SuspendLayout();
List<PictureBox> _iconcache = new List<PictureBox>();
for (int _i = 500; _i < 10000; _i++)
{
int _iconcat;
if (MainForm.CategoryOfIcon.TryGetValue(_i, out _iconcat))
{
PictureBox _icon = new PictureBox();
_icon.Name = "Icon" + _i.ToString();
_icon.Image = MainForm.IconImages[_i];
_icon.Width = 40;
_icon.Height = 40;
_icon.BackColor = SystemColors.Window;
_icon.Tag = _iconcat;
_icon.Click += pictureIcon_Click;
//new ToolTip().SetToolTip(_icon, _i.ToString());
flowIcons.Controls.Add(_icon);
_iconcache.Add(_icon);
}
}
flowIcons.ResumeLayout();
}
}
private void formTextboxNumber_Keypress(object sender, KeyPressEventArgs e)
{
int _dummy;
TextBox _tbox = sender as TextBox;
ComboBox _cbox = sender as ComboBox;
int _selstart = (_tbox != null) ? _tbox.SelectionStart : (_cbox != null) ? _cbox.SelectionStart : 0;
int _sellength = (_tbox != null) ? _tbox.SelectionLength : (_cbox != null) ? _cbox.SelectionLength : 0;
string _text = ((Control)sender).Text.Remove(_selstart, _sellength);
if (e.KeyChar == '.')
{
e.Handled = true;
}
else if (e.KeyChar == '-')
{
e.Handled = true; // _text != "";
}
else if (e.KeyChar > 31)
{
e.Handled = !int.TryParse(_text.Insert(_selstart, "" + e.KeyChar), out _dummy);
}
}
private void listItemCategory_SelectedIndexChanged(object sender, EventArgs e)
{
if (IconID != -1)
{
flowIcons.SuspendLayout();
int _cat = listItemCategory.SelectedIndex;
foreach (PictureBox _box in flowIcons.Controls)
{
_box.Visible = _cat == (int)_box.Tag;
}
flowIcons.ResumeLayout();
PictureBox _icon = (PictureBox)flowIcons.Controls["Icon" + IconID.ToString()];
if ((_icon != null) && _icon.Visible)
{
flowIcons.ScrollControlIntoView(_icon);
}
}
}
private void textIconID_TextChanged(object sender, EventArgs e)
{
int _iconID = 0;
if (int.TryParse(textIconID.Text, out _iconID))
{
if (IconSelected != null)
{
IconSelected.BackColor = SystemColors.Window;
}
IconID = _iconID;
IconSelected = (PictureBox)flowIcons.Controls["Icon" + IconID.ToString()];
if (IconSelected != null)
{
IconSelected.BackColor = SystemColors.Highlight;
}
try
{
listItemCategory.SelectedIndex = MainForm.CategoryOfIcon[IconID];
}
catch
{
listItemCategory.SelectedIndex = -1;
}
}
}
private void pictureIcon_Click(object sender, EventArgs e)
{
textIconID.Text = ((PictureBox)sender).Name.Substring(4);
}
private void buttonSelect_Click(object sender, EventArgs e)
{
MainForm.SetField("icon", textIconID.Text);
MainForm.UpdatePreviewBox(0);
this.Visible = false;
}
private void formIconPicker_VisibleChanged(object sender, EventArgs e)
{
if (this.Visible)
{
textIconID.Text = MainForm.TextField("icon");
if (MainForm.IconPickerWindowCoordsValid)
{
this.Location = MainForm.IconPickerWindowCoords;
}
}
else
{
MainForm.IconPickerWindowCoords = this.Location;
MainForm.IconPickerWindowCoordsValid = true;
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.Visible = false;
}
}
}