-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathItemDetailForm.cs
More file actions
279 lines (238 loc) · 8.2 KB
/
Copy pathItemDetailForm.cs
File metadata and controls
279 lines (238 loc) · 8.2 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/***************************************************************************
*
* $Author: Turley
*
* "THE BEER-WARE LICENSE"
* As long as you retain this notice you can do whatever you want with
* this stuff. If we meet some day, and you think this stuff is worth it,
* you can buy me a beer in return.
*
***************************************************************************/
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using Ultima;
using UoFiddler.Controls.Classes;
using UoFiddler.Controls.Helpers;
namespace UoFiddler.Controls.Forms
{
public partial class ItemDetailForm : Form
{
public ItemDetailForm(int i)
{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
Icon = Options.GetFiddlerIcon();
_index = i;
Data.AddBasicContextMenu();
}
private readonly int _index;
private bool _partialHue;
private bool _animate;
private Timer _animationTimer;
private int _frame;
private Animdata.AnimdataEntry _info;
private int _hue = -1;
/// <summary>
/// Sets Hue
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int Hue
{
get => _hue;
set
{
_hue = value;
if (_animate)
{
return;
}
Bitmap hueBit = new Bitmap(Art.GetStatic(_index));
if (_hue >= 0)
{
Hue hue = Hues.List[_hue];
hue.ApplyTo(hueBit, _partialHue);
}
Graphic.Tag = hueBit;
Graphic.Invalidate();
}
}
private void OnPaint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(SystemColors.Control);
if (Graphic.Tag == null)
{
return;
}
Bitmap bit = (Bitmap)Graphic.Tag;
e.Graphics.DrawImage(bit, (e.ClipRectangle.Width - bit.Width) / 2, 5);
}
private void OnLoad(object sender, EventArgs e)
{
animateToolStripMenuItem.Visible = false;
ItemData item = TileData.ItemTable[_index];
Bitmap bit = Art.GetStatic(_index);
Text = $"Item Detail 0x{_index:X} '{item.Name}'";
if (bit == null)
{
splitContainer1.SplitterDistance = 10;
}
else
{
Size = new Size(300, bit.Size.Height + Data.Size.Height + 10);
splitContainer1.SplitterDistance = bit.Size.Height + 10;
Graphic.Size = new Size(300, bit.Size.Height + 10);
Graphic.Tag = bit;
Graphic.Invalidate();
}
Data.AppendText($"Name: {item.Name}\n");
Data.AppendText(string.Format("Graphic: 0x{0:X4} ({0})\n", _index));
Data.AppendText($"Height/Capacity: {item.Height}\n");
Data.AppendText($"Weight: {item.Weight}\n");
Data.AppendText($"Animation: {item.Animation}\n");
Data.AppendText($"Quality/Layer/Light: {item.Quality}\n");
Data.AppendText($"Quantity: {item.Quantity}\n");
Data.AppendText($"Hue: {item.Hue}\n");
Data.AppendText($"StackingOffset/Unk4: {item.StackingOffset}\n");
Data.AppendText($"Flags: {item.Flags}\n");
if ((item.Flags & TileFlag.PartialHue) != 0)
{
_partialHue = true;
}
if ((item.Flags & TileFlag.Animation) == 0)
{
return;
}
_info = Animdata.GetAnimData(_index);
if (_info == null)
{
return;
}
animateToolStripMenuItem.Visible = true;
Data.AppendText($"Animation FrameCount: {_info.FrameCount} Interval: {_info.FrameInterval}\n");
}
private void AnimTick(object sender, EventArgs e)
{
++_frame;
if (_frame >= _info.FrameCount)
{
_frame = 0;
}
Bitmap animBit = new Bitmap(Art.GetStatic(_index + _info.FrameData[_frame]));
if (_hue >= 0)
{
Hue hue = Hues.List[_hue];
hue.ApplyTo(animBit, _partialHue);
}
Graphic.Tag = animBit;
Graphic.Invalidate();
}
private HuePopUpItemForm _showForm;
private void OnClick_Hue(object sender, EventArgs e)
{
if (_showForm?.IsDisposed != false)
{
_showForm = new HuePopUpItemForm(UpdateSelectedHue, Hue);
}
else
{
_showForm.SetHue(Hue);
}
_showForm.TopMost = true;
_showForm.Show();
}
private void UpdateSelectedHue(int selectedHue)
{
Hue = selectedHue;
}
private void OnClickAnimate(object sender, EventArgs e)
{
_animate = !_animate;
if (_animate)
{
_animationTimer = new Timer();
_frame = -1;
_animationTimer.Interval = 100 * _info.FrameInterval;
_animationTimer.Tick += AnimTick;
_animationTimer.Start();
}
else
{
if (_animationTimer.Enabled)
{
_animationTimer.Stop();
}
_animationTimer.Dispose();
_animationTimer = null;
Graphic.Tag = Art.GetStatic(_index);
Graphic.Invalidate();
}
}
private void OnClose(object sender, FormClosingEventArgs e)
{
if (_animationTimer != null)
{
if (_animationTimer.Enabled)
{
_animationTimer.Stop();
}
_animationTimer.Dispose();
_animationTimer = null;
}
if (_showForm?.IsDisposed == false)
{
_showForm.Close();
}
}
private void Extract_Image_ClickBmp(object sender, EventArgs e)
{
SaveImage(ImageFormat.Bmp);
}
private void Extract_Image_ClickTiff(object sender, EventArgs e)
{
SaveImage(ImageFormat.Tiff);
}
private void Extract_Image_ClickJpg(object sender, EventArgs e)
{
SaveImage(ImageFormat.Jpeg);
}
private void Extract_Image_ClickPng(object sender, EventArgs e)
{
SaveImage(ImageFormat.Png);
}
private void SaveImage(ImageFormat imageFormat)
{
if (!Art.IsValidStatic(_index))
{
return;
}
string fileExtension = Utils.GetFileExtensionFor(imageFormat);
string fileName = Path.Combine(Options.OutputPath, $"Item {Utils.FormatExportId(_index)}.{fileExtension}");
using (Bitmap bit = new Bitmap(Art.GetStatic(_index).Width, Art.GetStatic(_index).Height))
{
using (Graphics newGraphic = Graphics.FromImage(bit))
{
newGraphic.Clear(Color.Transparent);
using (Bitmap huedBitmap = new Bitmap(Art.GetStatic(_index)))
{
if (_hue > 0)
{
Hue hue = Hues.List[_hue];
hue.ApplyTo(huedBitmap, _partialHue);
}
newGraphic.DrawImage(huedBitmap, 0, 0);
}
}
bit.Save(fileName, imageFormat);
}
FileSavedDialog.Show(FindForm(), fileName, "Item image saved successfully.");
}
private void OnSizeChange(object sender, EventArgs e)
{
Graphic.Invalidate();
}
}
}