-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathAnimationEditForm.cs
More file actions
4183 lines (3640 loc) · 156 KB
/
Copy pathAnimationEditForm.cs
File metadata and controls
4183 lines (3640 loc) · 156 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
*
* $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.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using Ultima;
using UoFiddler.Controls.Classes;
namespace UoFiddler.Controls.Forms
{
public partial class AnimationEditForm : Form
{
private static readonly int[] _animCx = new int[5];
private static readonly int[] _animCy = new int[5];
private bool _loaded;
private int _fileType;
private int _currentAction;
private int _currentBody;
private int _currentDir;
private Point _framePoint;
private bool _showOnlyValid;
private static bool _drawEmpty;
private static bool _drawFull;
private static int _lastAddFilterIndex = 1;
private static readonly Color _whiteConvert = Color.FromArgb(255, 255, 255, 255);
private static readonly Pen _blackUnDrawTransparent = new Pen(Color.FromArgb(0, 0, 0, 0), 1);
private static readonly Pen _blackUnDrawOpaque = new Pen(Color.FromArgb(255, 0, 0, 0), 1);
private static Pen _blackUndraw = _blackUnDrawOpaque;
private static readonly SolidBrush _whiteUnDrawTransparent = new SolidBrush(Color.FromArgb(0, 255, 255, 255));
private static readonly SolidBrush _whiteUnDrawOpaque = new SolidBrush(Color.FromArgb(255, 255, 255, 255));
private static SolidBrush _whiteUnDraw = _whiteUnDrawOpaque;
public AnimationEditForm()
{
InitializeComponent();
Icon = Options.GetFiddlerIcon();
SelectFileToolStripComboBox.SelectedIndex = 0;
FramesListView.MultiSelect = true;
_fileType = 0;
_currentDir = 0;
_framePoint = new Point(AnimationPictureBox.Width / 2, AnimationPictureBox.Height / 2);
_showOnlyValid = false;
_loaded = false;
}
private readonly string[][] _animNames =
{
new string[]
{
"Walk",
"Run",
"Idle",
"Eat",
"Alert",
"Attack1",
"Attack2",
"GetHit",
"Die1",
"Idle",
"Fidget",
"LieDown",
"Die2"
}, //animal
new string[]
{
"Walk",
"Idle",
"Die1",
"Die2",
"Attack1",
"Attack2",
"Attack3",
"AttackBow",
"AttackCrossBow",
"AttackThrow",
"GetHit",
"Pillage",
"Stomp",
"Cast2",
"Cast3",
"BlockRight",
"BlockLeft",
"Idle",
"Fidget",
"Fly",
"TakeOff",
"GetHitInAir"
}, //Monster
new string[]
{
"Walk_01",
"WalkStaff_01",
"Run_01",
"RunStaff_01",
"Idle_01",
"Idle_01",
"Fidget_Yawn_Stretch_01",
"CombatIdle1H_01",
"CombatIdle1H_01",
"AttackSlash1H_01",
"AttackPierce1H_01",
"AttackBash1H_01",
"AttackBash2H_01",
"AttackSlash2H_01",
"AttackPierce2H_01",
"CombatAdvance_1H_01",
"Spell1",
"Spell2",
"AttackBow_01",
"AttackCrossbow_01",
"GetHit_Fr_Hi_01",
"Die_Hard_Fwd_01",
"Die_Hard_Back_01",
"Horse_Walk_01",
"Horse_Run_01",
"Horse_Idle_01",
"Horse_Attack1H_SlashRight_01",
"Horse_AttackBow_01",
"Horse_AttackCrossbow_01",
"Horse_Attack2H_SlashRight_01",
"Block_Shield_Hard_01",
"Punch_Punch_Jab_01",
"Bow_Lesser_01",
"Salute_Armed1h_01",
"Ingest_Eat_01"
} //human
};
private void OnLoad(object sender, EventArgs e)
{
Options.LoadedUltimaClass["AnimationEdit"] = true;
AnimationListTreeView.BeginUpdate();
try
{
AnimationListTreeView.Nodes.Clear();
if (_fileType != 0)
{
int count = Animations.GetAnimCount(_fileType);
TreeNode[] nodes = new TreeNode[count];
for (int i = 0; i < count; ++i)
{
int animLength = Animations.GetAnimLength(i, _fileType);
string type = animLength == 22 ? "H" : animLength == 13 ? "L" : "P";
TreeNode node = new TreeNode
{
Tag = i,
Text = $"{type}: {i} ({BodyConverter.GetTrueBody(_fileType, i)})"
};
bool valid = false;
for (int j = 0; j < animLength; ++j)
{
TreeNode treeNode = new TreeNode
{
Tag = j,
Text = string.Format("{0:D2} {1}", j, _animNames[animLength == 22 ? 1 : animLength == 13 ? 0 : 2][j])
};
if (AnimationEdit.IsActionDefined(_fileType, i, j))
{
valid = true;
}
else
{
treeNode.ForeColor = Color.Red;
}
node.Nodes.Add(treeNode);
}
if (!valid)
{
if (_showOnlyValid)
{
continue;
}
node.ForeColor = Color.Red;
}
nodes[i] = node;
}
AnimationListTreeView.Nodes.AddRange(nodes.Where(n => n != null).ToArray());
}
}
finally
{
AnimationListTreeView.EndUpdate();
}
if (AnimationListTreeView.Nodes.Count > 0)
{
AnimationListTreeView.SelectedNode = AnimationListTreeView.Nodes[0];
}
if (!_loaded)
{
ControlEvents.FilePathChangeEvent += OnFilePathChangeEvent;
}
_loaded = true;
}
private void OnFilePathChangeEvent()
{
if (!_loaded)
{
return;
}
_fileType = 0;
_currentDir = 0;
_currentAction = 0;
_currentBody = 0;
SelectFileToolStripComboBox.SelectedIndex = 0;
_framePoint = new Point(AnimationPictureBox.Width / 2, AnimationPictureBox.Height / 2);
_showOnlyValid = false;
ShowOnlyValidToolStripMenuItem.Checked = false;
OnLoad(null);
}
private TreeNode GetNode(int tag)
{
return _showOnlyValid
? AnimationListTreeView.Nodes.Cast<TreeNode>().FirstOrDefault(node => (int)node.Tag == tag)
: AnimationListTreeView.Nodes[tag];
}
private unsafe void SetPaletteBox()
{
if (_fileType == 0)
{
return;
}
// TODO: why is bitmapWidth constant and height is taken from picturebox?
// TODO: looks like the value is the same as array size for pallete in AnimIdx
const int bitmapWidth = 256;
int bitmapHeight = PalettePictureBox.Height;
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
Bitmap bmp = new Bitmap(bitmapWidth, bitmapHeight, PixelFormat.Format16bppArgb1555);
if (edit != null)
{
BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bitmapWidth, bitmapHeight), ImageLockMode.WriteOnly, PixelFormat.Format16bppArgb1555);
ushort* line = (ushort*)bd.Scan0;
int delta = bd.Stride >> 1;
for (int y = 0; y < bd.Height; ++y, line += delta)
{
ushort* cur = line;
for (int i = 0; i < bitmapWidth; ++i)
{
*cur++ = edit.Palette[i];
}
}
bmp.UnlockBits(bd);
}
PalettePictureBox.Image?.Dispose();
PalettePictureBox.Image = bmp;
}
private void AfterSelectTreeView(object sender, TreeViewEventArgs e)
{
if (AnimationListTreeView.SelectedNode == null)
{
return;
}
if (AnimationListTreeView.SelectedNode.Parent == null)
{
if (AnimationListTreeView.SelectedNode.Tag != null)
{
_currentBody = (int)AnimationListTreeView.SelectedNode.Tag;
}
_currentAction = 0;
}
else
{
if (AnimationListTreeView.SelectedNode.Parent.Tag != null)
{
_currentBody = (int)AnimationListTreeView.SelectedNode.Parent.Tag;
}
_currentAction = (int)AnimationListTreeView.SelectedNode.Tag;
}
FramesListView.BeginUpdate();
try
{
FramesListView.Clear();
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit != null)
{
int width = 80;
int height = 110;
Bitmap[] currentBits = edit.GetFrames();
if (currentBits != null)
{
for (int i = 0; i < currentBits.Length; ++i)
{
if (currentBits[i] == null)
{
continue;
}
ListViewItem item = new ListViewItem(i.ToString(), 0)
{
Tag = i
};
FramesListView.Items.Add(item);
if (currentBits[i].Width > width)
{
width = currentBits[i].Width;
}
if (currentBits[i].Height > height)
{
height = currentBits[i].Height;
}
}
FramesListView.TileSize = new Size(width + 5, height + 5);
FramesTrackBar.Maximum = currentBits.Length - 1;
FramesTrackBar.Value = 0;
FramesTrackBar.Invalidate();
CenterXNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.X;
CenterYNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.Y;
}
//Soulblighter Modification
else
{
FramesTrackBar.Maximum = 0;
FramesTrackBar.Value = 0;
FramesTrackBar.Invalidate();
}
//End of Soulblighter Modification
}
}
finally
{
FramesListView.EndUpdate();
}
AnimationPictureBox.Invalidate();
SetPaletteBox();
}
private void DrawFrameItem(object sender, DrawListViewItemEventArgs e)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
Bitmap[] currentBits = edit.GetFrames();
Bitmap bmp = currentBits[(int)e.Item.Tag];
var penColor = FramesListView.SelectedItems.Contains(e.Item) ? Color.Red : Color.Gray;
e.Graphics.DrawRectangle(new Pen(penColor), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);
e.Graphics.DrawImage(bmp, e.Bounds.X, e.Bounds.Y, bmp.Width, bmp.Height);
e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter);
}
private void OnAnimChanged(object sender, EventArgs e)
{
if (SelectFileToolStripComboBox.SelectedIndex == _fileType)
{
return;
}
_fileType = SelectFileToolStripComboBox.SelectedIndex;
OnLoad(this, EventArgs.Empty);
}
private void OnDirectionChanged(object sender, EventArgs e)
{
_currentDir = DirectionTrackBar.Value;
AfterSelectTreeView(null, null);
}
private void AnimationPictureBox_OnSizeChanged(object sender, EventArgs e)
{
_framePoint = new Point(AnimationPictureBox.Width / 2, AnimationPictureBox.Height / 2);
AnimationPictureBox.Invalidate();
}
//Soulblighter Modification
private void AnimationPictureBox_OnPaintFrame(object sender, PaintEventArgs e)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit == null)
{
return;
}
Bitmap[] currentBits = edit.GetFrames();
e.Graphics.Clear(Color.LightGray);
e.Graphics.DrawLine(Pens.Black, new Point(_framePoint.X, 0), new Point(_framePoint.X, AnimationPictureBox.Height));
e.Graphics.DrawLine(Pens.Black, new Point(0, _framePoint.Y), new Point(AnimationPictureBox.Width, _framePoint.Y));
if (currentBits?.Length > 0 && currentBits[FramesTrackBar.Value] != null)
{
int varW;
int varH;
if (!_drawEmpty)
{
varW = 0;
varH = 0;
}
else
{
varW = currentBits[FramesTrackBar.Value].Width;
varH = currentBits[FramesTrackBar.Value].Height;
}
int varFw;
int varFh;
if (!_drawFull)
{
varFw = 0;
varFh = 0;
}
else
{
varFw = currentBits[FramesTrackBar.Value].Width;
varFh = currentBits[FramesTrackBar.Value].Height;
}
int x = _framePoint.X - edit.Frames[FramesTrackBar.Value].Center.X;
int y = _framePoint.Y - edit.Frames[FramesTrackBar.Value].Center.Y - currentBits[FramesTrackBar.Value].Height;
using (var whiteTransparent = new SolidBrush(Color.FromArgb(160, 255, 255, 255)))
{
e.Graphics.FillRectangle(whiteTransparent, new Rectangle(x, y, varFw, varFh));
}
e.Graphics.DrawRectangle(Pens.Red, new Rectangle(x, y, varW, varH));
e.Graphics.DrawImage(currentBits[FramesTrackBar.Value], x, y);
//e.Graphics.DrawLine(Pens.Red, new Point(0, 335-(int)numericUpDown1.Value), new Point(animationPictureBox.Width, 335-(int)numericUpDown1.Value));
}
// Draw Reference Point Arrow
Point[] arrayPoints = {
new Point(418 - (int)RefXNumericUpDown.Value, 335 - (int)RefYNumericUpDown.Value),
new Point(418 - (int)RefXNumericUpDown.Value, 352 - (int)RefYNumericUpDown.Value),
new Point(422 - (int)RefXNumericUpDown.Value, 348 - (int)RefYNumericUpDown.Value),
new Point(425 - (int)RefXNumericUpDown.Value, 353 - (int)RefYNumericUpDown.Value),
new Point(427 - (int)RefXNumericUpDown.Value, 352 - (int)RefYNumericUpDown.Value),
new Point(425 - (int)RefXNumericUpDown.Value, 347 - (int)RefYNumericUpDown.Value),
new Point(430 - (int)RefXNumericUpDown.Value, 347 - (int)RefYNumericUpDown.Value)
};
e.Graphics.FillPolygon(_whiteUnDraw, arrayPoints);
e.Graphics.DrawPolygon(_blackUndraw, arrayPoints);
}
//End of Soulblighter Modification
//Soulblighter Modification
private void OnFrameCountBarChanged(object sender, EventArgs e)
{
if (_fileType == 0)
{
return;
}
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit != null && edit.Frames.Count >= FramesTrackBar.Value)
{
CenterXNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.X;
CenterYNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.Y;
}
AnimationPictureBox.Invalidate();
}
//End of Soulblighter Modification
private void OnCenterXValueChanged(object sender, EventArgs e)
{
try
{
if (_fileType == 0)
{
return;
}
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit == null || edit.Frames.Count < FramesTrackBar.Value)
{
return;
}
FrameEdit frame = edit.Frames[FramesTrackBar.Value];
if (CenterXNumericUpDown.Value == frame.Center.X)
{
return;
}
frame.ChangeCenter((int)CenterXNumericUpDown.Value, frame.Center.Y);
Options.ChangedUltimaClass["Animations"] = true;
AnimationPictureBox.Invalidate();
}
catch (NullReferenceException)
{
// TODO: add logging or fix?
// ignored
}
}
private void OnCenterYValueChanged(object sender, EventArgs e)
{
try
{
if (_fileType == 0)
{
return;
}
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit == null || edit.Frames.Count < FramesTrackBar.Value)
{
return;
}
FrameEdit frame = edit.Frames[FramesTrackBar.Value];
if (CenterYNumericUpDown.Value == frame.Center.Y)
{
return;
}
frame.ChangeCenter(frame.Center.X, (int)CenterYNumericUpDown.Value);
Options.ChangedUltimaClass["Animations"] = true;
AnimationPictureBox.Invalidate();
}
catch (NullReferenceException)
{
// TODO: add logging or fix?
// ignored
}
}
private void OnClickExtractImages(object sender, EventArgs e)
{
if (_fileType == 0)
{
return;
}
ToolStripMenuItem menu = (ToolStripMenuItem)sender;
ImageFormat format;
switch ((string)menu.Tag)
{
case ".tiff":
format = ImageFormat.Tiff;
break;
case ".png":
format = ImageFormat.Png;
break;
case ".jpg":
format = ImageFormat.Jpeg;
break;
default:
format = ImageFormat.Bmp;
break;
}
string path = Options.OutputPath;
int body;
int action;
if (AnimationListTreeView.SelectedNode.Parent == null)
{
body = (int)AnimationListTreeView.SelectedNode.Tag;
action = -1;
}
else
{
body = (int)AnimationListTreeView.SelectedNode.Parent.Tag;
action = (int)AnimationListTreeView.SelectedNode.Tag;
}
if (action == -1)
{
for (int a = 0; a < Animations.GetAnimLength(body, _fileType); ++a)
{
for (int i = 0; i < 5; ++i)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, body, a, i);
Bitmap[] bits = edit?.GetFrames();
if (bits == null)
{
continue;
}
for (int j = 0; j < bits.Length; ++j)
{
if (bits[j] is null)
{
continue;
}
string filename = string.Format("anim{5}_{0}_{1}_{2}_{3}{4}", body, a, i, j, menu.Tag, _fileType);
string file = Path.Combine(path, filename);
using (Bitmap bit = new Bitmap(bits[j]))
{
bit.Save(file, format);
}
}
}
}
}
else
{
for (int i = 0; i < 5; ++i)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, body, action, i);
Bitmap[] bits = edit?.GetFrames();
if (bits == null)
{
continue;
}
for (int j = 0; j < bits.Length; ++j)
{
if (bits[j] is null)
{
continue;
}
string filename = string.Format("anim{5}_{0}_{1}_{2}_{3}{4}", body, action, i, j, menu.Tag, _fileType);
string file = Path.Combine(path, filename);
using (Bitmap bit = new Bitmap(bits[j]))
{
bit.Save(file, format);
}
}
}
}
FileSavedDialog.Show(FindForm(), path, "Frames saved successfully.");
}
private void OnClickRemoveAction(object sender, EventArgs e)
{
if (_fileType == 0)
{
return;
}
if (AnimationListTreeView.SelectedNode.Parent == null)
{
DialogResult result = MessageBox.Show($"Are you sure to remove animation {_currentBody}", "Remove",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (result != DialogResult.Yes)
{
return;
}
AnimationListTreeView.SelectedNode.ForeColor = Color.Red;
for (int i = 0; i < AnimationListTreeView.SelectedNode.Nodes.Count; ++i)
{
AnimationListTreeView.SelectedNode.Nodes[i].ForeColor = Color.Red;
for (int d = 0; d < 5; ++d)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, i, d);
edit?.ClearFrames();
}
}
if (_showOnlyValid)
{
AnimationListTreeView.SelectedNode.Remove();
}
Options.ChangedUltimaClass["Animations"] = true;
AfterSelectTreeView(this, null);
}
else
{
DialogResult result = MessageBox.Show($"Are you sure to remove action {_currentAction}", "Remove",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (result != DialogResult.Yes)
{
return;
}
for (int i = 0; i < 5; ++i)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, i);
edit?.ClearFrames();
}
AnimationListTreeView.SelectedNode.Parent.Nodes[_currentAction].ForeColor = Color.Red;
bool valid = false;
foreach (TreeNode node in AnimationListTreeView.SelectedNode.Parent.Nodes)
{
if (node.ForeColor == Color.Red)
{
continue;
}
valid = true;
break;
}
if (!valid)
{
if (_showOnlyValid)
{
AnimationListTreeView.SelectedNode.Parent.Remove();
}
else
{
AnimationListTreeView.SelectedNode.Parent.ForeColor = Color.Red;
}
}
Options.ChangedUltimaClass["Animations"] = true;
AfterSelectTreeView(this, null);
}
}
private void OnClickSave(object sender, EventArgs e)
{
if (_fileType == 0)
{
return;
}
AnimationEdit.Save(_fileType, Options.OutputPath);
Options.ChangedUltimaClass["Animations"] = false;
MessageBox.Show($"AnimationFile saved to {Options.OutputPath}", "Saved", MessageBoxButtons.OK,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
//My Soulblighter Modification
private void OnClickRemoveFrame(object sender, EventArgs e)
{
if (FramesListView.SelectedItems.Count <= 0)
{
return;
}
int corrector = 0;
int[] frameIndex = new int[FramesListView.SelectedItems.Count];
for (int i = 0; i < FramesListView.SelectedItems.Count; i++)
{
frameIndex[i] = FramesListView.SelectedIndices[i] - corrector;
corrector++;
}
foreach (var index in frameIndex)
{
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit == null)
{
continue;
}
edit.RemoveFrame(index);
FramesListView.Items.RemoveAt(FramesListView.Items.Count - 1);
FramesTrackBar.Maximum = edit.Frames.Count != 0 ? edit.Frames.Count - 1 : 0;
FramesListView.Invalidate();
Options.ChangedUltimaClass["Animations"] = true;
}
}
//End of Soulblighter Modification
private void OnClickReplace(object sender, EventArgs e)
{
if (FramesListView.SelectedItems.Count <= 0)
{
return;
}
using (OpenFileDialog dialog = new OpenFileDialog())
{
int frameIndex = (int)FramesListView.SelectedItems[0].Tag;
dialog.Multiselect = false;
dialog.Title = $"Choose image file to replace at {frameIndex}";
dialog.CheckFileExists = true;
dialog.Filter = "Image files (*.tif;*.tiff;*.bmp;*.png)|*.tif;*.tiff;*.bmp;*.png";
if (dialog.ShowDialog() != DialogResult.OK)
{
return;
}
using (var bmpTemp = new Bitmap(dialog.FileName))
{
Bitmap bitmap = new Bitmap(bmpTemp);
if (dialog.FileName.Contains(".bmp"))
{
bitmap = ConvertBmpAnim(bitmap, (int)numericUpDownRed.Value, (int)numericUpDownGreen.Value, (int)numericUpDownBlue.Value);
}
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit == null)
{
return;
}
edit.ReplaceFrame(bitmap, frameIndex);
FramesListView.Invalidate();
Options.ChangedUltimaClass["Animations"] = true;
}
}
}
private void OnClickAdd(object sender, EventArgs e)
{
if (_fileType != 0)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
dialog.Multiselect = true;
dialog.Title = "Choose image file to add";
dialog.CheckFileExists = true;
dialog.Filter = "Gif files (*.gif;)|*.gif; |Bitmap files (*.bmp;)|*.bmp; |Tiff files (*.tif;*.tiff)|*.tif;*.tiff; |Png files (*.png;)|*.png; |Jpeg files (*.jpeg;*.jpg;)|*.jpeg;*.jpg;";
dialog.FilterIndex = _lastAddFilterIndex;
if (dialog.ShowDialog() == DialogResult.OK)
{
_lastAddFilterIndex = dialog.FilterIndex;
FramesListView.BeginUpdate();
try
{
//My Soulblighter Modifications
foreach (var fileName in dialog.FileNames)
{
using (var bmpTemp = new Bitmap(fileName))
{
Bitmap bitmap = new Bitmap(bmpTemp);
if (dialog.FileName.Contains(".bmp") || dialog.FileName.Contains(".tiff") ||
dialog.FileName.Contains(".png") || dialog.FileName.Contains(".jpeg") ||
dialog.FileName.Contains(".jpg"))
{
bitmap = ConvertBmpAnim(bitmap, (int)numericUpDownRed.Value, (int)numericUpDownGreen.Value, (int)numericUpDownBlue.Value);
//edit.GetImagePalette(bitmap);
}
AnimIdx edit = AnimationEdit.GetAnimation(_fileType, _currentBody, _currentAction, _currentDir);
if (edit == null)
{
continue;
}
//Gif Especial Properties
if (dialog.FileName.Contains(".gif"))
{
FrameDimension dimension = new FrameDimension(bitmap.FrameDimensionsList[0]);
// Number of frames
int frameCount = bitmap.GetFrameCount(dimension);
Bitmap[] bitBmp = new Bitmap[frameCount];
bitmap.SelectActiveFrame(dimension, 0);
UpdateGifPalette(bitmap, edit);
ProgressBar.Maximum = frameCount;
AddImageAtCertainIndex(frameCount, bitBmp, bitmap, dimension, edit);
ProgressBar.Value = 0;
ProgressBar.Invalidate();
SetPaletteBox();
CenterXNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.X;
CenterYNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.Y;
Options.ChangedUltimaClass["Animations"] = true;
}
//End of Soulblighter Modifications
else
{
edit.AddFrame(bitmap);
TreeNode node = GetNode(_currentBody);
if (node != null)
{
node.ForeColor = Color.Black;
node.Nodes[_currentAction].ForeColor = Color.Black;
}
int i = edit.Frames.Count - 1;
var item = new ListViewItem(i.ToString(), 0)
{
Tag = i
};
FramesListView.Items.Add(item);
int width = FramesListView.TileSize.Width - 5;
if (bitmap.Width > FramesListView.TileSize.Width)
{
width = bitmap.Width;
}
int height = FramesListView.TileSize.Height - 5;
if (bitmap.Height > FramesListView.TileSize.Height)
{
height = bitmap.Height;
}
FramesListView.TileSize = new Size(width + 5, height + 5);
FramesTrackBar.Maximum = i;
CenterXNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.X;
CenterYNumericUpDown.Value = edit.Frames[FramesTrackBar.Value].Center.Y;
Options.ChangedUltimaClass["Animations"] = true;
}
}
}
}
finally
{
FramesListView.EndUpdate();
}
FramesListView.Invalidate();
}
}
}
// Refresh List
_currentDir = DirectionTrackBar.Value;
AfterSelectTreeView(null, null);
}
private void AddImageAtCertainIndex(int frameCount, Bitmap[] bitBmp, Bitmap bmp, FrameDimension dimension, AnimIdx edit)
{
// Return an Image at a certain index
for (int index = 0; index < frameCount; index++)
{
bitBmp[index] = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format16bppArgb1555);
bmp.SelectActiveFrame(dimension, index);
bitBmp[index] = ConvertBmpAnim(bitBmp[index], (int) numericUpDownRed.Value,
(int) numericUpDownGreen.Value, (int) numericUpDownBlue.Value);
edit.AddFrame(bitBmp[index], bitBmp[index].Width / 2);
TreeNode node = GetNode(_currentBody);
if (node != null)
{
node.ForeColor = Color.Black;
node.Nodes[_currentAction].ForeColor = Color.Black;
}
int i = edit.Frames.Count - 1;
var item = new ListViewItem(i.ToString(), 0)
{
Tag = i
};
FramesListView.Items.Add(item);
int width = FramesListView.TileSize.Width - 5;
if (bmp.Width > FramesListView.TileSize.Width)
{
width = bmp.Width;
}
int height = FramesListView.TileSize.Height - 5;
if (bmp.Height > FramesListView.TileSize.Height)
{
height = bmp.Height;
}
FramesListView.TileSize = new Size(width + 5, height + 5);