-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBrowserForm.cs
1838 lines (1653 loc) · 78 KB
/
BrowserForm.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
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
using CustomControls;
using RCT2ObjectData.Drawing;
using RCT2ObjectData.Objects;
using RCT2ObjectData.Objects.Types;
using RCT2ObjectData.Objects.Types.AttractionInfo;
using RCTDataEditor.DataObjects;
using RCTDataEditor.FileIO;
using RCTDataEditor.Properties;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace RCTDataEditor {
public partial class BrowserForm : Form {
//========== CONSTANTS ===========
#region Constants
/** <summary> The list of tab names. </summary> */
string[] tabList = new string[]{
"Info",
"All",
"Attractions",
"SmallScenery",
"LargeScenery",
"Walls",
"Signs",
"Paths",
"PathAdditions",
"SceneryGroups",
"ParkEntrances",
"Water",
"ScenarioText",
"Settings"
};
/** <summary> The list of real tab names. </summary> */
string[] tabNames = new string[]{
"Information",
"All",
"Attractions",
"Small Scenery",
"Large Scenery",
"Walls",
"Banners",
"Paths",
"Path Additions",
"Scenery Groups",
"Park Entrances",
"Water",
"Scenario Text",
"Settings",
"About"
};
#endregion
//=========== MEMBERS ============
#region Members
//--------------------------------
#region Settings
/** <summary> The default directory to start in. </summary> */
string defaultDirectory = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Rollercoaster Tycoon 2\\ObjData";
/** <summary> The default number of objects to load per tick. </summary> */
int objectsPerTick = 50;
/** <summary> True if the image view should have remap options. </summary> */
bool remapImageView = false;
/** <summary> True if files are allowed to be deleted. </summary> */
bool allowDeletion = false;
/** <summary> True if files are backed up after being deleted. </summary> */
bool backupDeletion = true;
/** <summary> True if only a handful of object images are loaded. </summary> */
bool quickLoad = false;
#endregion
//--------------------------------
#region Objects
/** <summary> The current object being viewed. </summary> */
ObjectData objectData;
/** <summary> The draw settings. </summary> */
DrawSettings drawSettings;
/** <summary> The index of the object in the file directory. </summary> */
int objectIndex = 0;
/** <summary> The rotation of the object view. </summary> */
//int rotation = 0;
/** <summary> The slope of the object view. </summary> */
//int slope = -1;
/** <summary> The corner of the object view. </summary> */
//int corner = 0;
/** <summary> The elevation of the object view. </summary> */
//int elevation = 0;
/** <summary> The connections of the current path. </summary> */
//uint pathConnections = 0x00000000;
/** <summary> True if the queue path is being drawn. </summary> */
//bool queue = false;
/** <summary> The frame of the object view. </summary> */
//int frame = 0;
/** <summary> True if only viewing a dialog image. </summary> */
bool dialogView = false;
/** <summary> True if only viewing a single image. </summary> */
bool imageView = false;
/** <summary> The current color being remapped. </summary> */
int colorRemap = 0;
/** <summary> The image to draw the object to. </summary> */
Image objectImage;
PaletteImage objectPaletteImage = new PaletteImage(new Size(190, 254));
Terrain terrain = new Terrain();
#endregion
//--------------------------------
#region Tabs
/** <summary> The name of the current tab. </summary> */
string currentTab = "Info";
/** <summary> The current list containing the object. </summary> */
string currentList;
/** <summary> The list of tab sort columns. </summary> */
int[] currentColumn = new int[]{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0
};
/** <summary> The list of tab solumn sort orders. </summary> */
bool[] currentListOrder = new bool[]{
false, false, false, false, false, false, false, false, false, false, false, false, false, false
};
#endregion
//--------------------------------
#region Scanning
/** <summary> The start time of the scan. </summary> */
DateTime scanStart;
/** <summary> The current directory. </summary> */
string directory = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Rollercoaster Tycoon 2\\ObjData";
/** <summary> The list of files to load. </summary> */
string[] files = null;
/** <summary> The index of the next file in the list to load. </summary> */
int fileIndex = 0;
#endregion
//--------------------------------
#region Extracting
/** <summary> The start time of the extraction. </summary> */
DateTime extractStart;
/** <summary> The index of the next image in the list to extract. </summary> */
int extractIndex = 0;
/** <summary> The object used for extracting. </summary> */
ObjectData extractObject = null;
#endregion
//--------------------------------
#region Other
/** <summary> The sbold RCT sprite font. </summary> */
SpriteFont fontBold;
/** <summary> The palette buttons. </summary> */
Button[] paletteButtons;
/** <summary> The image lists for the palette buttons. </summary> */
ImageList[] paletteImageLists;
AboutBox aboutForm = new AboutBox();
#endregion
//--------------------------------
#endregion
//========= CONSTRUCTORS =========
#region Constructors
/** <summary> Constructs the form. </summary> */
public BrowserForm(string[] args) {
InitializeComponent();
this.fontBold = new SpriteFont(Resources.BoldFont, ' ', 'z', 10);
this.labelCurrentObject.Text = "";
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
this.currentList = "";
this.objectImage = new Bitmap(190, 254);
this.terrain.Slope = -1;
this.terrain.Origin = new Point(8, 8);
this.terrain.Size = new Size(13, 13);
this.drawSettings.Remap1 = RemapColors.IndianRed;
this.drawSettings.Remap2 = RemapColors.Gold;
this.drawSettings.Remap3 = RemapColors.Bark;
this.drawSettings.Slope = -1;
this.defaultDirectory = "";
string[] possibleDirectories = {
"%PROGRAMFILES%\\Steam\\steamapps\\common\\Rollercoaster Tycoon 2\\ObjData",
"%PROGRAMFILES%\\Infogrames\\Rollercoaster Tycoon 2\\ObjData",
"%PROGRAMFILES%\\Atari\\Rollercoaster Tycoon 2\\ObjData",
"%PROGRAMFILES(x86)%\\Steam\\steamapps\\common\\Rollercoaster Tycoon 2\\ObjData",
"%PROGRAMFILES(x86)%\\Infogrames\\Rollercoaster Tycoon 2\\ObjData",
"%PROGRAMFILES(x86)%\\Atari\\Rollercoaster Tycoon 2\\ObjData",
"%USERPROFILE%\\Desktop"
};
for (int i = 0; i < possibleDirectories.Length; i++) {
if (Directory.Exists(Environment.ExpandEnvironmentVariables(possibleDirectories[i]))) {
this.defaultDirectory = Environment.ExpandEnvironmentVariables(possibleDirectories[i]);
break;
}
}
this.textBoxDirectory.Text = this.defaultDirectory;
this.LoadSettings(null, null);
this.directory = this.defaultDirectory;
#region Palette Buttons
Bitmap paletteButton = Resources.PaletteButton;
Bitmap paletteButtonPressed = Resources.PaletteButtonPressed;
PaletteImage paleteButtonImage = new PaletteImage(12, 12);
PaletteImage paleteButtonPressedImage = new PaletteImage(12, 12);
for (int x = 0; x < 12; x++) {
for (int y = 0; y < 12; y++) {
Color c = paletteButton.GetPixel(x, y);
for (int i = 0; i < 12; i++) {
if (c == Palette.DefaultPalette.Colors[10 + i]) {
paleteButtonImage.Pixels[x, y] = (byte)(243 + i);
break;
}
}
c = paletteButtonPressed.GetPixel(x, y);
for (int i = 0; i < 12; i++) {
if (c == Palette.DefaultPalette.Colors[10 + i]) {
paleteButtonPressedImage.Pixels[x, y] = (byte)(243 + i);
break;
}
}
}
}
this.paletteButtons = new Button[32];
this.paletteImageLists = new ImageList[32];
//for (int i = 31; i >= 0; i--) {
for (int i = 0; i < 32; i++) {
ImageList imageList = new ImageList(this.components);
imageList.ColorDepth = ColorDepth.Depth24Bit;
imageList.TransparentColor = Color.Transparent;
imageList.ImageSize = new Size(12, 12);
imageList.Images.Add("PaletteButton", paleteButtonImage.CreateImage(Palette.DefaultPalette, (RemapColors)i, RemapColors.None, RemapColors.None));
imageList.Images.Add("PaletteButtonPressed", paleteButtonPressedImage.CreateImage(Palette.DefaultPalette, (RemapColors)i, RemapColors.None, RemapColors.None));
imageList.Images.Add("PaletteButtonPressed2", paleteButtonPressedImage.CreateImage(Palette.DefaultPalette, (RemapColors)i, RemapColors.None, RemapColors.None));
Button button = new Button();
button.BackColor = Color.FromArgb(79, 135, 95);
button.FlatAppearance.BorderColor = Color.FromArgb(79, 135, 95);
button.FlatAppearance.BorderSize = 0;
button.FlatAppearance.MouseDownBackColor = Color.FromArgb(79, 135, 95);
button.FlatAppearance.MouseOverBackColor = Color.FromArgb(79, 135, 95);
button.FlatStyle = FlatStyle.Flat;
button.ImageIndex = 0;
button.ImageList = imageList;
button.Location = new Point((i % 8) * 12 + 1, (i / 8) * 12 + 1);
button.Name = "buttonPaletteRemap" + (i + 1);
button.Size = new Size(13, 13);
button.TabIndex = 300 + i;
button.TabStop = false;
button.UseVisualStyleBackColor = true;
button.Click += new EventHandler(this.SelectRemapColor);
button.MouseDown += new MouseEventHandler(this.ButtonDown);
button.MouseLeave += new EventHandler(this.ButtonLeave);
button.MouseMove += new MouseEventHandler(this.ButtonHover);
button.MouseUp += new MouseEventHandler(this.ButtonUp);
this.panelColorPalette.Controls.Add(button);
this.paletteButtons[i] = button;
this.paletteImageLists[i] = imageList;
}
this.buttonRemap1.ImageList = this.paletteImageLists[(int)drawSettings.Remap1];
this.buttonRemap2.ImageList = this.paletteImageLists[(int)drawSettings.Remap2];
this.buttonRemap3.ImageList = this.paletteImageLists[(int)drawSettings.Remap3];
#endregion
if (args.Length > 0) {
this.directory = Path.GetDirectoryName(args[0]);
this.objectData = ObjectData.FromFile(args[0]);
this.UpdateImages();
this.UpdateColorRemap();
this.UpdateInfo();
string name = "Info";
currentTab = "Info";
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(name)];
this.tabInfo.ToggleTab();
this.labelCurrentObject.Text = objectData.ObjectHeader.FileName + ".DAT - " + (imageView ? "image " + drawSettings.Frame : (!dialogView ? "frame " + drawSettings.Frame : "dialog"));
}
}
private PaletteImage FromImage(Bitmap image) {
PaletteImage paletteImage = new PaletteImage(image.Width, image.Height);
Palette palette = Palette.DefaultPalette;
for (int x = 0; x < image.Width; x++) {
for (int y = 0; y < image.Height; y++) {
Color imageColor = image.GetPixel(x, y);
if (imageColor == Color.FromArgb(0, 0, 0)) {
imageColor = Color.FromArgb(0, 0, 0, 0);
}
int minDelta = GetColorDelta(imageColor, palette.Colors[0]);
int minDeltaIndex = 0;
for (int i = 0; i < 256; i++) {
int delta = GetColorDelta(imageColor, palette.Colors[i]);
if (delta < minDelta) {
minDelta = delta;
minDeltaIndex = i;
}
}
paletteImage.Pixels[x, y] = (byte)minDeltaIndex;
}
}
return paletteImage;
}
private void SavePieces(Attraction o, ulong basePieces, ulong pieces, string name) {
/*o.Source = SourceTypes.Custom;
o.ObjectHeader.FileName = name;
o.StringTable.Entries[0][Languages.British] = "A (" + pieces.ToString("X16") + ")";
o.StringTable.Entries[0][Languages.American] ="A (" + pieces.ToString("X16") + ")";
o.Header.AvailableTrackSections = (TrackSections)(basePieces | pieces);
ObjectData.WriteObject(name + ".DAT", o);*/
}
private int GetColorDelta(Color imageColor, Color paletteColor) {
return Math.Abs(imageColor.R - paletteColor.R) +
Math.Abs(imageColor.G - paletteColor.G) +
Math.Abs(imageColor.B - paletteColor.B) +
Math.Abs(imageColor.A - paletteColor.A) * 4;
}
#endregion
//=========== LOADING ============
#region Loading
/** <summary> Called when the form loads. </summary> */
private void OnFormLoad(object sender, EventArgs e) {
SetFeatureToAllControls(this.Controls);
}
/** <summary> Called to load the settings file. </summary> */
private void LoadSettings(object sender, EventArgs e) {
string pathToSettings = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Settings - Content Browser.xml");
if (File.Exists(pathToSettings)) {
XmlDocument doc = new XmlDocument();
doc.Load(pathToSettings);
XmlNodeList element;
element = doc.GetElementsByTagName("DefaultDirectory");
if (element.Count != 0) this.defaultDirectory = element[0].InnerText;
element = doc.GetElementsByTagName("ObjectsPerTick");
if (element.Count != 0) this.objectsPerTick = Int32.Parse(element[0].InnerText);
element = doc.GetElementsByTagName("QuickLoad");
if (element.Count != 0) this.quickLoad = Boolean.Parse(element[0].InnerText);
element = doc.GetElementsByTagName("RemapImage");
if (element.Count != 0) this.remapImageView = Boolean.Parse(element[0].InnerText);
element = doc.GetElementsByTagName("AllowDeletion");
if (element.Count != 0) this.allowDeletion = Boolean.Parse(element[0].InnerText);
element = doc.GetElementsByTagName("BackupDeletion");
if (element.Count != 0) this.backupDeletion = Boolean.Parse(element[0].InnerText);
this.textBoxDirectory.Text = this.defaultDirectory;
this.numericUpDownObjectsPerTick.Value = this.objectsPerTick;
this.checkBoxQuickLoad.CheckState = (this.quickLoad ? CheckState.Checked : CheckState.Unchecked);
this.checkBoxRemapImage.CheckState = (this.remapImageView ? CheckState.Checked : CheckState.Unchecked);
this.checkBoxAllowDeletions.CheckState = (this.allowDeletion ? CheckState.Checked : CheckState.Unchecked);
this.checkBoxBackupDeletions.CheckState = (this.backupDeletion ? CheckState.Checked : CheckState.Unchecked);
}
else {
SaveSettings(null, null);
}
}
/** <summary> Called to save the settings file. </summary> */
private void SaveSettings(object sender, EventArgs e) {
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null));
XmlElement settings = doc.CreateElement("Settings");
doc.AppendChild(settings);
XmlElement element = doc.CreateElement("DefaultDirectory");
settings.AppendChild(element);
element.AppendChild(doc.CreateTextNode(this.defaultDirectory));
element = doc.CreateElement("ObjectsPerTick");
settings.AppendChild(element);
element.AppendChild(doc.CreateTextNode(this.objectsPerTick.ToString()));
element = doc.CreateElement("QuickLoad");
settings.AppendChild(element);
element.AppendChild(doc.CreateTextNode(this.quickLoad.ToString()));
element = doc.CreateElement("RemapImage");
settings.AppendChild(element);
element.AppendChild(doc.CreateTextNode(this.remapImageView.ToString()));
element = doc.CreateElement("AllowDeletion");
settings.AppendChild(element);
element.AppendChild(doc.CreateTextNode(this.allowDeletion.ToString()));
element = doc.CreateElement("BackupDeletion");
settings.AppendChild(element);
element.AppendChild(doc.CreateTextNode(this.backupDeletion.ToString()));
doc.Save(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Settings - Content Browser.xml"));
}
/** <summary> Called when the browse default button is pressed. </summary> */
private void BrowseDefaultDirectory(object sender, EventArgs e) {
this.objDataBrowserDialog.SelectedPath = this.directory;
if (this.objDataBrowserDialog.ShowDialog() == DialogResult.OK) {
this.defaultDirectory = this.objDataBrowserDialog.SelectedPath;
this.textBoxDirectory.Text = this.defaultDirectory;
}
}
/** <summary> Called when the browse default button is pressed. </summary> */
private void ObjectsPerTickChanged(object sender, EventArgs e) {
this.objectsPerTick = (int)(sender as NumericUpDown).Value;
}
/** <summary> Loads objects from the directory every tick. </summary> */
private void LoadObjects(object sender, EventArgs e) {
int count = 0;
for (int i = fileIndex; i < files.Length && count < objectsPerTick; i++, fileIndex++, count++) {
if (files[i].EndsWith(".DAT", true, CultureInfo.DefaultThreadCurrentCulture)) {
ObjectDataInfo info = ObjectDataInfo.FromFile(files[i], true);
if (!info.Invalid) {
ListViewItem item = new ListViewItem();
item.ImageIndex = 1;
if (info.Source == SourceTypes.Custom) item.ImageIndex = 2;
else if (info.Source == SourceTypes.RCT2) item.ImageIndex = 0;
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Source.ToString()));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(files[i])));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Name));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Type.ToString()));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Subtype.ToString()));
this.tabGroupAll.Items.Add(item);
item = new ListViewItem();
item.ImageIndex = 1;
if (info.Source == SourceTypes.Custom) item.ImageIndex = 2;
else if (info.Source == SourceTypes.RCT2) item.ImageIndex = 0;
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Source.ToString()));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(files[i])));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Name));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Type.ToString()));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, info.Subtype.ToString()));
if (info.Type == ObjectTypes.Attraction)
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, (info.Header as AttractionHeader).TrackType.ToString()));
switch (info.Type) {
case ObjectTypes.Attraction: this.tabGroupAttractions.Items.Add(item); break;
case ObjectTypes.SmallScenery: this.tabGroupSmallScenery.Items.Add(item); break;
case ObjectTypes.LargeScenery: this.tabGroupLargeScenery.Items.Add(item); break;
case ObjectTypes.Wall: this.tabGroupWalls.Items.Add(item); break;
case ObjectTypes.PathBanner: this.tabGroupSigns.Items.Add(item); break;
case ObjectTypes.Path: this.tabGroupPaths.Items.Add(item); break;
case ObjectTypes.PathAddition: this.tabGroupPathAdditions.Items.Add(item); break;
case ObjectTypes.SceneryGroup: this.tabGroupSceneryGroups.Items.Add(item); break;
case ObjectTypes.ParkEntrance: this.tabGroupParkEntrances.Items.Add(item); break;
case ObjectTypes.Water: this.tabGroupWater.Items.Add(item); break;
case ObjectTypes.ScenarioText: this.tabGroupScenarioText.Items.Add(item); break;
}
}
else {
ListViewItem item = new ListViewItem();
item.ForeColor = Color.FromArgb(200, 0, 0);
//item.Font = new Font(item.Font, FontStyle.Bold);
item.ImageIndex = 3;
if (info.Source == SourceTypes.Custom) item.ImageIndex = 2;
else if (info.Source == SourceTypes.RCT2) item.ImageIndex = 0;
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, Path.GetFileName(files[i])));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
item.SubItems.Add(new ListViewItem.ListViewSubItem(item, ""));
this.tabGroupAll.Items.Add(item);
}
}
}
if (fileIndex >= files.Length) {
this.labelScanProgress.Text = "Scan Finished - Took " + Math.Round((DateTime.Now - this.scanStart).TotalSeconds) + " seconds";
this.timerLoadObjects.Stop();
}
else {
//this.labelScanStatus.Text = "Scanning - " + Math.Round((double)fileIndex / (double)files.Length * 100.0) + "%";
this.labelScanProgress.Text = "Scanning - " + Math.Round((double)fileIndex / (double)files.Length * 100.0) + "%";
}
this.labelObjectsScanned.Text = "Objects Scanned: " + fileIndex;
if (currentTab != "Info" && currentTab != "Settings" && currentTab != "About")
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(currentTab)] + ": " + (this.Controls.Find("tabGroup" + currentTab, true)[0] as ListView).Items.Count;
else
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(currentTab)];
}
#endregion
//=========== SORTING ============
#region Sorting
/** <summary> The class used to sort the columns. </summary> */
class ListViewItemComparer : IComparer {
private int col;
private bool reverse;
public ListViewItemComparer() {
this.col = 0;
}
public ListViewItemComparer(int column, bool reverse = false) {
this.col = column;
this.reverse = reverse;
}
public int Compare(object x, object y) {
return String.Compare(((ListViewItem)(reverse ? y : x)).SubItems[col].Text, ((ListViewItem)(reverse ? x : y)).SubItems[col].Text);
}
}
/** <summary> Sorts the specified column. </summary> */
private void ColumnSort(object sender, ColumnClickEventArgs e) {
if (e.Column != 0) {
string name = (sender as ListView).Name.Replace("tabGroup", "");
int index = 0;
//Console.WriteLine(name);
for (int i = 0; i < tabList.Length; i++) {
if (tabList[i] == name) {
index = i;
break;
}
}
//Console.WriteLine(index);
//Console.WriteLine(GetTabIndex(name));
if (e.Column == currentColumn[index]) {
currentListOrder[index] = !currentListOrder[index];
}
else {
currentColumn[index] = e.Column;
currentListOrder[index] = false;
}
//Console.WriteLine("Sort");
//currentListColumn = e.Column;
//listSortOrder = currentListOrder[index];
(sender as ListView).ListViewItemSorter = new ListViewItemComparer(e.Column, currentListOrder[index]);
(sender as ListView).Refresh();
}
}
/** <summary> Called when the browse button is pressed. </summary> */
private void BrowseDirectory(object sender, EventArgs e) {
this.objDataBrowserDialog.SelectedPath = this.directory;
if (this.objDataBrowserDialog.ShowDialog() == DialogResult.OK) {
this.directory = this.objDataBrowserDialog.SelectedPath;
this.tabGroupInfo.Items.Clear();
for (int i = 1; i < this.tabList.Length; i++) {
if (tabList[i] != "Settings")
(this.Controls.Find("tabGroup" + this.tabList[i], true)[0] as ListView).Items.Clear();
}
this.objectData = null;
this.objectIndex = 0;
this.UpdateImages();
this.UpdateInfo();
this.timerLoadObjects.Stop();
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
this.files = Directory.GetFiles(directory);
this.fileIndex = 0;
this.labelScanProgress.Text = "Ready to Scan";
this.labelObjectsScanned.Text = "Objects Scanned: 0";
if (currentTab != "Info" && currentTab != "Settings" && currentTab != "About")
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(currentTab)] + ": " + (this.Controls.Find("tabGroup" + currentTab, true)[0] as ListView).Items.Count;
else
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(currentTab)];
}
}
/** <summary> Called when the scan button is pressed. </summary> */
private void StartScan(object sender, EventArgs e) {
if (!this.timerLoadObjects.Enabled && !this.timerExtract.Enabled) {
this.tabGroupInfo.Items.Clear();
for (int i = 1; i < this.tabList.Length; i++) {
if (tabList[i] != "Settings")
(this.Controls.Find("tabGroup" + this.tabList[i], true)[0] as ListView).Items.Clear();
}
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
this.objectData = null;
this.objectIndex = 0;
this.UpdateImages();
this.UpdateInfo();
try {
this.files = Directory.GetFiles(directory);
this.fileIndex = 0;
//this.labelScanStatus.Text = "Ready to Scan";
this.labelScanProgress.Text = "Ready to Scan";
this.labelObjectsScanned.Text = "Objects Scanned: 0";
if (currentTab != "Info" && currentTab != "Settings" && currentTab != "About")
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(currentTab)] + ": " + (this.Controls.Find("tabGroup" + currentTab, true)[0] as ListView).Items.Count;
else
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(currentTab)];
this.timerLoadObjects.Start();
this.scanStart = DateTime.Now;
}
catch (Exception) {
this.labelObjectsInGroup.Text = "Please select directory";
}
}
}
#endregion
//============= TABS =============
#region Tabs
/** <summary> Called when a tab is switched to. </summary> */
private void TabDown(object sender, MouseEventArgs e) {
string name = (sender as RCTTabButton).Name.Replace("tab", "");
currentTab = name;
this.ActiveControl = (sender as RCTTabButton).TabPage;
if (currentTab != "Info" && currentTab != "Settings" && currentTab != "About") {
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(name)] + ": " + (this.Controls.Find("tabGroup" + currentTab, true)[0] as ListView).Items.Count;
//(sender as RCTTabButton).TabPage.Refresh();
}
else
this.labelObjectsInGroup.Text = tabNames[GetTabIndex(name)];
}
/** <summary> Called when an object is selected from the list. </summary> */
private void ObjectChanged(object sender, ListViewItemSelectionChangedEventArgs e) {
string name = (sender as ListView).Name.Replace("tabGroup", "");
int index = 0;
for (int i = 0; i < tabList.Length; i++) {
if (tabList[i] == name) {
index = i;
break;
}
}
if (e.Item.Selected && ((sender as ListView).SelectedItems.Count == 0 || (sender as ListView).SelectedItems[0] == e.Item)) {
currentList = name;
objectIndex = e.ItemIndex;
objectData = ObjectData.FromFile(Path.Combine(directory, e.Item.SubItems[2].Text), this.quickLoad);
drawSettings.Frame = 0;
drawSettings.CurrentCar = 0;
drawSettings.Rotation = 0;
this.UpdateImages(); this.UpdateInfo(); this.UpdateColorRemap();
this.labelCurrentObject.Text = (objectData != null ? objectData.ObjectHeader.FileName + ".DAT" : "");
if (objectData == null) {
this.labelCurrentObject.Text = "";
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
}
else {
this.labelCurrentObject.Text = objectData.ObjectHeader.FileName + ".DAT - " + (imageView ? "image " + drawSettings.Frame : (!dialogView ? "frame " + drawSettings.Frame : "dialog"));
if (this.imageView && objectData.ImageDirectory.NumEntries > 0) {
if (objectData.GraphicsData.IsPaletteImage(drawSettings.Frame)) {
this.labelImageSize.Text = "Image Size: " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).Width + ", " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).Height + "";
this.labelImageOffset.Text = "Image Offset: " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).XOffset + ", " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).YOffset + "";
}
else {
this.labelImageOffset.Text = "Num Colors: " + objectData.GraphicsData.GetPalette(drawSettings.Frame).NumColors + "";
this.labelImageSize.Text = "Palette Offset: " + objectData.GraphicsData.GetPalette(drawSettings.Frame).Offset + "";
}
}
if (this.imageView && objectData.ImageDirectory.NumEntries > 1) {
this.scrollBarImage.Enabled = true;
this.scrollBarImage.Visible = true;
this.scrollBarImage.Maximum = objectData.ImageDirectory.NumEntries - 1;
this.scrollBarImage.Value = 0;
}
else {
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
}
}
}
}
/** <summary> Called when an object is dragged from the list. </summary> */
private void ObjectDrag(object sender, ItemDragEventArgs e) {
string name = (sender as ListView).Name.Replace("tabGroup", "");
ListView listView = sender as ListView;
string[] files = new string[listView.SelectedItems.Count];
for (int i = 0; i < listView.SelectedItems.Count; i++) {
files[i] = Path.GetFullPath(directory + "/" + listView.SelectedItems[i].SubItems[2].Text);
}
if (files.Length != 0) {
DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy);
}
}
/** <summary> Cets the index of the tab name. </summary> */
private int GetTabIndex(string name) {
for (int i = 0; i < tabList.Length; i++) {
if (tabList[i] == name)
return i;
}
return 0;
}
#endregion
//========== REMAPPING ===========
#region Remapping
/** <summary> Changes the remapped color to the selected color. </summary> */
private void ChangeRemap(object sender, EventArgs e) {
string name = (sender as Button).Name.Replace("buttonRemap", "");
int newRemap = Int32.Parse(name);
if (newRemap == colorRemap) {
this.colorRemap = 0;
this.panelColorPalette.Visible = false;
}
else {
this.colorRemap = newRemap;
this.panelColorPalette.Location = new Point(
(sender as Button).Location.X - this.panelColorPalette.Width + 13,
(sender as Button).Location.Y + 13
);
this.panelColorPalette.Visible = true;
}
}
/** <summary> Changes the remapped color to the third color. </summary> */
private void SelectRemapColor(object sender, EventArgs e) {
string name = (sender as Button).Name.Replace("buttonPaletteRemap", "");
int index = Int32.Parse(name) - 1;
(Controls.Find("buttonRemap" + colorRemap, true)[0] as Button).ImageList = paletteImageLists[index];
switch (colorRemap) {
case 1: drawSettings.Remap1 = (RemapColors)index; break;
case 2: drawSettings.Remap2 = (RemapColors)index; break;
case 3: drawSettings.Remap3 = (RemapColors)index; break;
}
panelColorPalette.Visible = false;
colorRemap = 0;
UpdateImages();
}
#endregion
//=========== BUTTONS ============
#region Buttons
/** <summary> Called when the delete button is pressed. </summary> */
private void TabGroupDeleteSelection(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Delete && allowDeletion) {
DeleteObject(sender, e);
}
}
/** <summary> Deletes the selected object. </summary> */
private void DeleteObject(object sender, EventArgs e) {
ListView currentListView = (this.Controls.Find("tabGroup" + currentList, true)[0] as ListView);
if (currentListView.SelectedItems.Count != 0) {
DialogResult result = DeleteMessageBox.Show(this, (currentListView.SelectedItems.Count > 1 ? "[multiple objects]" : currentListView.SelectedItems[0].SubItems[2].Text));
bool error = false;
if (result == DialogResult.Yes) {
string backupDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Deleted Objects");
if (backupDeletion && !Directory.Exists(backupDirectory))
Directory.CreateDirectory(backupDirectory);
for (int j = currentListView.SelectedItems.Count - 1; j >= 0; j--) {
try {
if (currentListView.SelectedItems[j].SubItems.Count <= 2)
continue;
if (currentListView.SelectedItems[j].SubItems[1].Text != "Custom" && currentListView.SelectedItems[j].SubItems[1].Text != "")
continue;
string fileName = currentListView.SelectedItems[j].SubItems[2].Text;
if (backupDeletion)
File.Move(Path.Combine(this.directory, fileName), Path.Combine(backupDirectory, fileName));
else
File.Delete(Path.Combine(this.directory, fileName));
for (int i = 0; i < this.tabGroupAll.Items.Count; i++) {
if (this.tabGroupAll.Items[i].SubItems.Count > 2) {
if (fileName == this.tabGroupAll.Items[i].SubItems[2].Text) {
this.tabGroupAll.Items.RemoveAt(i);
}
}
}
ListView listView = this.tabGroupAttractions;
for (int k = 0; k < 10; k++) {
switch ((ObjectTypes)k) {
case ObjectTypes.Attraction: listView = this.tabGroupAttractions; break;
case ObjectTypes.SmallScenery: listView = this.tabGroupSmallScenery; break;
case ObjectTypes.LargeScenery: listView = this.tabGroupLargeScenery; break;
case ObjectTypes.Wall: listView = this.tabGroupWalls; break;
case ObjectTypes.PathBanner: listView = this.tabGroupSigns; break;
case ObjectTypes.Path: listView = this.tabGroupPaths; break;
case ObjectTypes.PathAddition: listView = this.tabGroupPathAdditions; break;
case ObjectTypes.SceneryGroup: listView = this.tabGroupSceneryGroups; break;
case ObjectTypes.ParkEntrance: listView = this.tabGroupParkEntrances; break;
case ObjectTypes.Water: listView = this.tabGroupWater; break;
case ObjectTypes.ScenarioText: listView = this.tabGroupScenarioText; break;
}
for (int i = 0; i < listView.Items.Count; i++) {
if (listView.Items[i].SubItems.Count > 2) {
if (fileName == listView.Items[i].SubItems[2].Text) {
listView.Items.RemoveAt(i);
}
}
}
}
}
catch (Exception) {
error = true;
}
}
}
if (error) {
ErrorForm.Show(this, "Error deleting object file!", "You may need to run as administrator.");
}
}
}
/** <summary> Opens the about window. </summary> */
private void OpenAboutForm(object sender, EventArgs e) {
if (aboutForm.IsDisposed)
aboutForm = new AboutBox();
aboutForm.ShowDialog(this);
}
/** <summary> Changes the quick load setting. </summary> */
private void QuickLoadAttractions(object sender, EventArgs e) {
this.quickLoad = (sender as RCTCheckBox).CheckState == CheckState.Checked;
}
/** <summary> Changes the remap image view setting. </summary> */
private void RemapImageView(object sender, EventArgs e) {
this.remapImageView = (sender as RCTCheckBox).CheckState == CheckState.Checked;
this.UpdateColorRemap();
if (this.imageView) {
this.UpdateImages();
}
}
/** <summary> Changes the allow deletions setting. </summary> */
private void AllowDeletions(object sender, EventArgs e) {
this.allowDeletion = (sender as RCTCheckBox).CheckState == CheckState.Checked;
}
/** <summary> Changes the backup deletions setting. </summary> */
private void BackupDeletions(object sender, EventArgs e) {
this.backupDeletion = (sender as RCTCheckBox).CheckState == CheckState.Checked;
}
/** <summary> Changes the dialog view. </summary> */
private void DialogView(object sender, EventArgs e) {
this.dialogView = (sender as RCTCheckBox).CheckState == CheckState.Checked;
drawSettings.Frame = 0;
if (this.checkBoxImageView.CheckState == CheckState.Checked) {
this.imageView = false;
this.checkBoxImageView.CheckState = CheckState.Unchecked;
}
if (objectData != null && !objectData.Invalid) {
this.labelCurrentObject.Text = objectData.ObjectHeader.FileName + ".DAT - " + (imageView ? "image " + drawSettings.Frame : (!dialogView ? "frame " + drawSettings.Frame : "dialog"));
this.UpdateImages();
}
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
this.UpdateColorRemap();
}
/** <summary> Changes the frame view. </summary> */
private void FrameView(object sender, EventArgs e) {
this.imageView = (sender as RCTCheckBox).CheckState == CheckState.Checked;
drawSettings.Frame = 0;
if (this.checkBoxDialogView.CheckState == CheckState.Checked) {
this.dialogView = false;
this.checkBoxDialogView.CheckState = CheckState.Unchecked;
}
if (objectData != null && !objectData.Invalid) {
this.labelCurrentObject.Text = objectData.ObjectHeader.FileName + ".DAT - " + (imageView ? "image " + drawSettings.Frame : (!dialogView ? "frame " + drawSettings.Frame : "dialog"));
this.UpdateImages();
if (this.imageView && objectData.ImageDirectory.NumEntries > 1) {
this.scrollBarImage.Enabled = true;
this.scrollBarImage.Visible = true;
this.scrollBarImage.Maximum = objectData.ImageDirectory.NumEntries - 1;
this.scrollBarImage.Value = 0;
}
else {
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
}
if (this.imageView && objectData.ImageDirectory.NumEntries > 0) {
if (objectData.GraphicsData.IsPaletteImage(drawSettings.Frame)) {
this.labelImageSize.Text = "Image Size: " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).Width + ", " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).Height + "";
this.labelImageOffset.Text = "Image Offset: " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).XOffset + ", " + objectData.GraphicsData.GetPaletteImage(drawSettings.Frame).YOffset + "";
}
else {
this.labelImageOffset.Text = "Num Colors: " + objectData.GraphicsData.GetPalette(drawSettings.Frame).NumColors + "";
this.labelImageSize.Text = "Palette Offset: " + objectData.GraphicsData.GetPalette(drawSettings.Frame).Offset + "";
}
}
else {
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
}
}
else {
this.scrollBarImage.Enabled = false;
this.scrollBarImage.Visible = false;
this.labelImageSize.Text = "";
this.labelImageOffset.Text = "";
}
this.UpdateColorRemap();
}
/** <summary> Rotates the object. </summary> */
private void RotateObject(object sender, EventArgs e) {
drawSettings.Rotation++;
if (objectData is Attraction) {
Attraction a = objectData as Attraction;
if (a.Header.RideCategory != RideCategories.Stall) {
if (drawSettings.Rotation > a.Header.CarTypeList[(int)drawSettings.CurrentCar].LastRotationFrame)
drawSettings.Rotation = 0;
}
else if (drawSettings.Rotation > 3) {
drawSettings.Rotation = 0;
}
}
else if (drawSettings.Rotation > 3) {
drawSettings.Rotation = 0;
}
bool validQueueConnection = true;
do {
if (drawSettings.PathConnections < 255)
drawSettings.PathConnections += 1;
else
drawSettings.PathConnections = 0;
if ((drawSettings.PathConnections & 0x0F) == drawSettings.PathConnections)
validQueueConnection = true;
int dirCount = 0;
for (int i = 0; i < 4; i++) {
if ((drawSettings.PathConnections & (1 << i)) != 0)
dirCount++;
}
if (dirCount > 2)
validQueueConnection = false;
} while (!Pathing.PathSpriteIndexes.ContainsKey(drawSettings.PathConnections) || (drawSettings.Queue && !validQueueConnection));
/*if (objectData is Attraction) {
Attraction.CarRotationFrame = (Attraction.CarRotationFrame + 1) % (objectData as Attraction).RotationFrames;
}*/
this.UpdateImages();
}
/** <summary> Rotates the slope. </summary> */
private void RotateSlope(object sender, EventArgs e) {
drawSettings.Slope++;
if (drawSettings.Slope > 3) drawSettings.Slope = -1;
this.UpdateImages();
}
/** <summary> Rotates the corner. </summary> */
private void RotateCorner(object sender, EventArgs e) {
drawSettings.Corner++;
if (drawSettings.Corner > 3) drawSettings.Corner = 0;
drawSettings.Queue = !drawSettings.Queue;
if (drawSettings.Queue) {
bool validQueueConnection = false;
if ((drawSettings.PathConnections & 0x0F) == drawSettings.PathConnections)
validQueueConnection = true;
int dirCount = 0;
for (int i = 0; i < 4; i++) {
if ((drawSettings.PathConnections & (1 << i)) != 0)
dirCount++;