forked from Violet-CLM/MLLE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainframe.cs
More file actions
3986 lines (3787 loc) · 218 KB
/
Copy pathMainframe.cs
File metadata and controls
3986 lines (3787 loc) · 218 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using TexLib;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using Ini;
using Un4seen.Bass;
using Extra.Collections;
namespace MLLE
{
public enum EnableableTitles { SecretLevelName, BonusLevelName, Lighting, Splitscreen, HideInHCL, Multiplayer, BoolDevelopingForPlus, UseText, SaveAndRun, SaveAndRunArgs, Illuminate, DiffLabel, Diff1, Diff2, Diff3, Diff4 }
public enum FocusedZone { None, Tileset, Level, AnimationEditing }
public enum SelectionType { New, Add, Subtract, Rectangle, HollowRectangle }
public enum AtlasID { Null, Image, Mask, EventNames, Selection, Generator, TileTypes }
public enum TilesetOverlay { None, TileTypes, Events, Masks, SmartTiles }
public partial class Mainframe : Form
{
#region variable declaration
internal TexturedJ2L J2L;
internal IniFile Settings = new IniFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MLLE.ini"));
bool SafeToDisplay = false;// ResizingOccured = false;
List<string> AllTilesets;
static string[][] DefaultHotKolors = new string[3][] { new string[3] { "32", "24", "80" }, new string[3] { "72", "48", "168" }, new string[3] { "79", "48", "168" } };
Color[] HotKolors = new Color[3];
Keys AddSelectionKey, SubtractSelectionKey;
public Dictionary<Version, string> DefaultDirectories;
public Dictionary<Version, NameAndFilename[]> AllTilesetLists = new Dictionary<Version, NameAndFilename[]> {
{Version.BC, null },
{Version.O, null },
{Version.JJ2, null },
{Version.TSF, null },
{Version.AGA, null },
{Version.GorH, null },
};
//internal int[] eventtexturenumberlist = new int[256];
internal int GeneratorOverlay, SelectionOverlay;
//internal string[][] EventsFromIni;
internal List<string[]> TextureTypes = new List<string[]>(4);
internal string[] CurrentIniLine;
//public List<TreeNode> TreeNodeList = new List<TreeNode>();
public Dictionary<Version, List<TreeNode>[]> TreeStructure = new Dictionary<Version, List<TreeNode>[]> {
{Version.BC, null },
{Version.O, null },
{Version.JJ2, null },
{Version.TSF, null },
{Version.AGA, null },
{Version.GorH, null },
};
public Dictionary<Version, List<StringAndIndex>> FlatEventLists = new Dictionary<Version, List<StringAndIndex>> {
{Version.BC, null },
{Version.O, null },
{Version.JJ2, null },
{Version.TSF, null },
{Version.AGA, null },
{Version.GorH, null },
};
//public string BonusLevelName;
public Dictionary<Version, Dictionary<EnableableTitles, string>> EnableableStrings = new Dictionary<Version, Dictionary<EnableableTitles, string>> {
{Version.BC, null },
{Version.O, null },
{Version.JJ2, null },
{Version.TSF, null },
{Version.AGA, null },
{Version.GorH, null },
};
public Dictionary<Version, Dictionary<EnableableTitles, bool>> EnableableBools = new Dictionary<Version, Dictionary<EnableableTitles, bool>> {
{Version.BC, null },
{Version.O, null },
{Version.JJ2, null },
{Version.TSF, null },
{Version.AGA, null },
{Version.GorH, null },
};
public Dictionary<Version, MemoryStream[]> AmbientSounds = new Dictionary<Version, MemoryStream[]> {
{Version.BC, null },
{Version.O, null },
{Version.JJ2, null },
{Version.TSF, null },
//{Version.AGA, null },
{Version.GorH, null },
};
public static Dictionary<Version, int> DefaultFileExtension = new Dictionary<Version, int> {
{Version.BC, 0},
{Version.O, 0 },
{Version.JJ2, 0},
{Version.TSF, 0},
{Version.AGA, 1},
{Version.GorH, 2},
};
public static Dictionary<Version, string> ProfileIniFilename = new Dictionary<Version, string> {
{Version.BC, "MLLEProfile - Battery Check"},
{Version.O, "MLLEProfile - 110o"},
{Version.JJ2, "MLLEProfile - JJ2"},
{Version.TSF, "MLLEProfile - TSF"},
{Version.AGA, "MLLEProfile - AGA"},
{Version.GorH, "MLLEProfile - 100gh"},
};
public static string[] DefaultFileExtensionStrings = new string[] { ".j2l", ".lvl", ".lev" };
public byte? GeneratorEventID = null, StartPositionEventID = null;
//int desiredindex;
byte CurrentLayerID = J2LFile.SpriteLayerID;
Layer CurrentLayer { get { return J2L.AllLayers[CurrentLayerID]; } }
byte ZoomTileSize = 32;
float ZoomTileFactor = 1;
internal bool LevelDisplayLoaded = false;
internal bool EventDisplayMode = true;
MaskMode MaskDisplayMode;
ParallaxMode ParallaxDisplayMode;
internal byte ParallaxEventDisplayType = 0;
internal bool AllowExtraZooming = false;
private bool PreviewHelpStringColors = true;
internal uint PlusTriggerZone = 0;
private bool levelHasBeenModified = false;
internal bool LevelHasBeenModified
{
get { return levelHasBeenModified; }
set
{
if (value != levelHasBeenModified)
{
UpdateTitle(value);
}
levelHasBeenModified = value;
}
}
ManualResetEvent _suspendEvent = new ManualResetEvent(true);
Stopwatch sw = new Stopwatch();
internal static Random _r = new Random();
double accumulator = 0, milliseconds = 0;
int idleCounter = 0;
float GameTime = 0;
int GameTick = 0;
int LatestFPS = 0;
public struct StringAndIndex
{
public string String;
public int Index;
public StringAndIndex(string str, int i) { String = str; Index = i; }
public override String ToString() { return String; }
}
public struct NameAndFilename
{
public string Name;
public string Filename;
public NameAndFilename(string n, string f) { Name = n; Filename = f; }
public override String ToString() { return Name; }
}
public AGAEvent ActiveEvent;
private List<string> RecentlyLoadedLevels = new List<string>();
#endregion variable declaration
#region Form Business
public Mainframe()
{
InitializeComponent();
}
private void ProcessIni(Version version)
{
IniFile ini = new IniFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ProfileIniFilename[J2L.VersionType] + ".ini"));
if (EnableableStrings[version] == null)
{
Dictionary<EnableableTitles, bool> Bools = EnableableBools[version] = new Dictionary<EnableableTitles, bool>();
Dictionary<EnableableTitles, string> Strings = EnableableStrings[version] = new Dictionary<EnableableTitles, string>();
Strings.Add(EnableableTitles.SecretLevelName, ini.IniReadValue("Enableable", "SecretLevel") ?? "");
Strings.Add(EnableableTitles.BonusLevelName, ini.IniReadValue("Enableable", "BonusLevel") ?? "");
Strings.Add(EnableableTitles.Lighting, ini.IniReadValue("Enableable", "Lighting") ?? "");
Strings.Add(EnableableTitles.Splitscreen, ini.IniReadValue("Enableable", "Splitscreen") ?? "");
Strings.Add(EnableableTitles.HideInHCL, ini.IniReadValue("Enableable", "HideInHCL") ?? "");
Strings.Add(EnableableTitles.Multiplayer, ini.IniReadValue("Enableable", "Multiplayer") ?? "");
Strings.Add(EnableableTitles.SaveAndRun, ini.IniReadValue("Enableable", "SaveAndRun") ?? "");
Strings.Add(EnableableTitles.SaveAndRunArgs, ini.IniReadValue("Enableable", "SaveAndRunArgs") ?? "");
Strings.Add(EnableableTitles.Illuminate, ini.IniReadValue("Enableable", "Illuminate") ?? "");
Strings.Add(EnableableTitles.DiffLabel, ini.IniReadValue("EventTypes", "Label") ?? "");
Strings.Add(EnableableTitles.Diff1, ini.IniReadValue("EventTypes", "0") ?? "1");
Strings.Add(EnableableTitles.Diff2, ini.IniReadValue("EventTypes", "1") ?? "2");
Strings.Add(EnableableTitles.Diff3, ini.IniReadValue("EventTypes", "2") ?? "3");
Strings.Add(EnableableTitles.Diff4, ini.IniReadValue("EventTypes", "3") ?? "4");
Bools.Add(EnableableTitles.BoolDevelopingForPlus, ini.IniReadValue("Enableable", "BoolDevelopingForPlus") != "");
Bools.Add(EnableableTitles.UseText, ini.IniReadValue("Enableable", "BoolText") != "");
}
automaskToolStripMenuItem.Enabled = imageToolStripMenuItem.Enabled = maskToolStripMenuItem.Enabled = jJ2PropertiesToolStripMenuItem.Enabled = EnableableBools[version][EnableableTitles.BoolDevelopingForPlus];
textStringsToolStripMenuItem.Enabled = EnableableBools[version][EnableableTitles.UseText];
saveRunToolStripMenuItem.Enabled = runToolStripMenuItem.Enabled = EnableableStrings[version][EnableableTitles.SaveAndRun] != "";
soundEffectsToolStripMenuItem.Enabled = (version == Version.AGA);
GeneratorEventID = ((ini.IniReadValue("Enableable", "GeneratorEvent") ?? "") != "") ? Convert.ToByte(ini.IniReadValue("Enableable", "GeneratorEvent")) : (byte?)null;
StartPositionEventID = ((ini.IniReadValue("Enableable", "StartPositionEvent") ?? "") != "") ? Convert.ToByte(ini.IniReadValue("Enableable", "StartPositionEvent")) : (byte?)null;
DropdownPlayHere.Enabled = StartPositionEventID != null;
if (AmbientSounds.ContainsKey(version) && AmbientSounds[version] == null)
{
AmbientSounds[version] = new MemoryStream[512];
}
IniFile baseIni;
{
string iniFilename = Path.ChangeExtension(Settings.IniReadValue("EventListBases", ini.IniReadValue("Events", "Base")), "ini");
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFilename);
if (File.Exists(path))
baseIni = new IniFile(path);
else
baseIni = ini;
}
TexturedJ2L.ProduceEventStringsFromIni(version, baseIni, ini);
TexturedJ2L.ProduceTypeIcons(version, ini);
bool differentEventListFromPreviousLevelInThisVersion = ProduceLevelSpecificEventStringListIfAppropriate(version);
if (!differentEventListFromPreviousLevelInThisVersion)
LevelSpecificEventStringList = TexturedJ2L.IniEventListing[version];
TexturedJ2L.ProduceEventIcons(version, LevelSpecificEventStringList, differentEventListFromPreviousLevelInThisVersion);
if ((TreeStructure[version] == null) || differentEventListFromPreviousLevelInThisVersion)
{
List<TreeNode>[] TreeNodeLists = TreeStructure[version] = new List<TreeNode>[2];
List<StringAndIndex> FlatEventList = FlatEventLists[version] = new List<StringAndIndex>();
TreeNodeLists[0] = new List<TreeNode>();
TreeNodeLists[1] = new List<TreeNode>();
for (ushort i = 0; i < 256; i++)
{
if (baseIni.IniReadValue("Categories", i.ToString()) == "") break;
else
{
CurrentIniLine = baseIni.IniReadValue("Categories", i.ToString()).Split('|');
TreeNodeLists[0].Add(new TreeNode(CurrentIniLine[0].TrimEnd()));
if (CurrentIniLine.Length == 1 || CurrentIniLine[1] == "+") TreeNodeLists[1].Add(new TreeNode(CurrentIniLine[0].TrimEnd()));
}
}
for (ushort i = 0; i < 256; i++)
{
if (baseIni.IniReadValue("Subcategories", i.ToString()) == "") break;
else
{
CurrentIniLine = baseIni.IniReadValue("Subcategories", i.ToString()).Split('|');
TreeNodeLists[0].First((TreeNode node) => { return node.Text == CurrentIniLine[2].TrimEnd(); }).Nodes.Add(CurrentIniLine[1].TrimEnd(), CurrentIniLine[0].TrimEnd());
if (CurrentIniLine.Length == 3 || CurrentIniLine[3] == "+") TreeNodeLists[1].First((TreeNode node) => { return node.Text == CurrentIniLine[2].TrimEnd(); }).Nodes.Add(CurrentIniLine[1].TrimEnd(), CurrentIniLine[0].TrimEnd());
}
}
for (ushort i = 1; i < 256; i++)
{
if (LevelSpecificEventStringList[i][2].Trim() != "")
{
FlatEventList.Add(new StringAndIndex(LevelSpecificEventStringList[i][0], i));
TreeNodeLists[0].First((TreeNode node) => { return node.Nodes.ContainsKey(LevelSpecificEventStringList[i][2].TrimEnd()); }).Nodes.Find(LevelSpecificEventStringList[i][2].TrimEnd(), false)[0].Nodes.Add(i.ToString(), LevelSpecificEventStringList[i][0].TrimEnd());
if (LevelSpecificEventStringList[i][1] == "+") TreeNodeLists[1].First((TreeNode node) => { return node.Nodes.ContainsKey(LevelSpecificEventStringList[i][2].TrimEnd()); }).Nodes.Find(LevelSpecificEventStringList[i][2].TrimEnd(), false)[0].Nodes.Add(i.ToString(), LevelSpecificEventStringList[i][0].TrimEnd());
}
}
}
TiletypeDropdown.DropDownItems.Clear();
for (byte i = 0; i < 16; i++)
{
string label = (i == 0) ? "Normal" : TexturedJ2L.TileTypeNames[version][i];
if (label != "")
{
ToolStripMenuItem option = new ToolStripMenuItem(i.ToString() + ": " + label);
option.Tag = i;
option.Size = new System.Drawing.Size(152, 22);
option.Click += new System.EventHandler(this.MenuTypeInstance_Click);
TiletypeDropdown.DropDownItems.Add(option);
}
}
TextureTypes.Clear();
for (ushort i = 0; i < 256; i++)
{
if (ini.IniReadValue("Textures", i.ToString()) == "") break;
else TextureTypes.Add(ini.IniReadValue("Textures", i.ToString()).Split('|'));
}
if (AllTilesetLists[version] == null) PopulateTilesetDropdown(version, ini);
TilesetSelection.Items.Clear();
foreach (NameAndFilename foo in AllTilesetLists[version]) TilesetSelection.Items.Add(foo);
}
string[][] LevelSpecificEventStringList;
private bool ProduceLevelSpecificEventStringListIfAppropriate(Version version)
{
string[][] defaults = TexturedJ2L.IniEventListing[version];
if (VersionIsPlusCompatible(version)) //otherwise there won't be any script file/s to worry about at all
{
var scriptFilepaths = new List<string>();
scriptFilepaths.Add(Path.ChangeExtension(J2L.FullFilePath, "j2as"));
var allIncludedLibraries = new HashSet<string>(StringComparer.OrdinalIgnoreCase); //avoid repeats, especially if a library tries to include itself recursively
allIncludedLibraries.Add(Path.GetFileName(scriptFilepaths[0])); //just to be safe
bool foundAtLeastOneLevelSpecificEventString = false;
for (int scriptID = 0; scriptID < scriptFilepaths.Count; ++scriptID)
{
string scriptFilepath = scriptFilepaths[scriptID];
if (File.Exists(scriptFilepath))
{
var fileContents = System.IO.File.ReadAllText(scriptFilepath, J2LFile.FileEncoding) + "\n";
foreach (System.Text.RegularExpressions.Match match in System.Text.RegularExpressions.Regex.Matches(fileContents, "#include\\s+(['\"])(.+?)\\1", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
if (allIncludedLibraries.Add(match.Groups[2].Value)) //haven't seen this filename before
scriptFilepaths.Add(Path.Combine(Path.GetDirectoryName(J2L.FullFilePath), match.Groups[2].Value)); //come back to this script later in the loop
foreach (System.Text.RegularExpressions.Match match in System.Text.RegularExpressions.Regex.Matches(fileContents, @"//[!/][ \t]*[\\@]Event[ \t]+(\d+)[ \t]*=([^\r\n]*)\r?\n", System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
if (!foundAtLeastOneLevelSpecificEventString)
{
LevelSpecificEventStringList = new string[256][];
foundAtLeastOneLevelSpecificEventString = true;
}
int eventID = int.Parse(match.Groups[1].ToString());
if (LevelSpecificEventStringList[eventID] == null) //first attempt to set this string wins, because the level's main script should take precedence over any included libraries
{
string result = match.Groups[2].ToString();
string[] resultSplitByPipes;
if (result.Length == 0 || (resultSplitByPipes = result.Split('|')).Length < 4)
LevelSpecificEventStringList[eventID] = TexturedJ2L.GetDontUseEventListingForEventID((byte)eventID);
else
LevelSpecificEventStringList[eventID] = resultSplitByPipes.Select(original => original.Trim()).ToArray();
}
}
}
}
if (foundAtLeastOneLevelSpecificEventString)
{
for (int i = 0; i < 256; ++i)
if (LevelSpecificEventStringList[i] == null)
LevelSpecificEventStringList[i] = defaults[i];
return true;
}
else if (LevelSpecificEventStringList != null && LevelSpecificEventStringList != defaults) //the previous level (in this version) used custom events, but this one does not
{
LevelSpecificEventStringList = defaults;
return true; //different from previous level
}
}
return false; //no change
}
private void PopulateTilesetDropdown(Version version, IniFile ini)
{
AllTilesets = (Directory.GetFiles(DefaultDirectories[version], "*.j2t").Concat(Directory.GetFiles(DefaultDirectories[version], "*.til"))).ToList<string>();
AllTilesetLists[version] = new NameAndFilename[AllTilesets.Count];
for (int i = 0; i < AllTilesets.Count; i++)
{
BinaryReader file = new BinaryReader(File.Open(AllTilesets[i], FileMode.Open, FileAccess.Read), J2File.FileEncoding);
file.ReadBytes((file.PeekChar() == 32) ? 188 : 8);
AllTilesetLists[version][i] = new NameAndFilename(new string(file.ReadChars(32)).TrimEnd('\0'), AllTilesets[i]);
file.Close();
}
}
void ProcessIniColorsIntoHotKolor(byte id, string group, string key)
{
try
{
string[] RGB = Settings.IniReadValue(group, key).Split(',');
try { Byte.Parse(RGB[0].Trim()); }
catch { RGB[0] = DefaultHotKolors[id][0]; }
try { Byte.Parse(RGB[1].Trim()); }
catch { RGB[1] = DefaultHotKolors[id][1]; }
try { Byte.Parse(RGB[2].Trim()); }
catch { RGB[2] = DefaultHotKolors[id][2]; }
HotKolors[id] = Color.FromArgb(Int32.Parse(RGB[0].Trim()), Convert.ToInt32(RGB[1].Trim()), Convert.ToInt32(RGB[2].Trim()));
}
catch { HotKolors[id] = Color.Black; }
}
private void MakeVersionChangesAvailable()
{
batteryCheckToolStripMenuItem.Enabled = Directory.Exists(Settings.IniReadValue("Paths", "BC"));
jazz2V110oToolStripMenuItem.Enabled = Directory.Exists(Settings.IniReadValue("Paths", "O"));
jazz2V123ToolStripMenuItem.Enabled = Directory.Exists(Settings.IniReadValue("Paths", "JJ2"));
jazz2V124ToolStripMenuItem.Enabled = Directory.Exists(Settings.IniReadValue("Paths", "TSF"));
animaniacsToolStripMenuItem.Enabled = Directory.Exists(Settings.IniReadValue("Paths", "AGA"));
jazz2V100ghToolStripMenuItem.Enabled = Directory.Exists(Settings.IniReadValue("Paths", "GorH"));
}
private bool SetupFolders()
{
return DirectorySetupForm.ShowForm(Settings);
}
private void Mainframe_Load(object sender, EventArgs e)
{
while (!LevelDisplayLoaded) ;
{
string X = Settings.IniReadValue("Window", "X");
string Y = Settings.IniReadValue("Window", "Y");
string Width = Settings.IniReadValue("Window", "Width");
string Height = Settings.IniReadValue("Window", "Height");
string Maximized = Settings.IniReadValue("Window", "Maximized");
int Xi, Yi, Wi, Hi; bool Mb;
if (int.TryParse(X, out Xi) && int.TryParse(Y, out Yi))
this.Location = new Point(Xi, Yi);
if (int.TryParse(Width, out Wi) && int.TryParse(Height, out Hi))
this.Size = new Size(Wi, Hi);
if (bool.TryParse(Maximized, out Mb))
this.WindowState = Mb ? FormWindowState.Maximized : FormWindowState.Normal;
}
if ((Settings.IniReadValue("Miscellaneous", "Initialized") ?? "") != "1") {
if (SetupFolders())
Settings.IniWriteValue("Miscellaneous", "Initialized", "1");
else
{
Application.Exit();
return;
}
}
MakeVersionChangesAvailable();
SetStampDimensions(1, 1);
CurrentStamp[0][0] = new TileAndEvent(0, 0);
for (int i = 1; i <= 10; ++i)
{
string recentLevel = Settings.IniReadValue("RecentLevels", i.ToString());
if (recentLevel != String.Empty)
RecentlyLoadedLevels.Add(recentLevel);
else
break;
}
DefaultDirectories = new Dictionary<Version, string> {
{Version.BC, Settings.IniReadValue("Paths","BC") },
{Version.O, Settings.IniReadValue("Paths","O") },
{Version.JJ2, Settings.IniReadValue("Paths","JJ2") },
{Version.TSF, Settings.IniReadValue("Paths","TSF") },
{Version.AGA, Settings.IniReadValue("Paths","AGA") },
{Version.GorH, Settings.IniReadValue("Paths","GorH") },
};
if (DefaultDirectories[Version.JJ2].Trim() == String.Empty)
DefaultDirectories[Version.JJ2] = DefaultDirectories[Version.TSF];
else if (DefaultDirectories[Version.TSF].Trim() == String.Empty)
DefaultDirectories[Version.TSF] = DefaultDirectories[Version.JJ2];
ProcessIniColorsIntoHotKolor(0, "Colors", "Deadspace");
ProcessIniColorsIntoHotKolor(1, "Colors", "Tile0");
ProcessIniColorsIntoHotKolor(2, "Colors", "Transparent");
TexUtil.InitTexturing();
J2L = new TexturedJ2L();
TexturedJ2L.DeadspaceColor = HotKolors[0];
TexturedJ2L.Tile0Color = HotKolors[1];
TexturedJ2L.TranspColor = HotKolors[2];
switch (Settings.IniReadValue("Miscellaneous", "DefaultGame"))
{
case "JJ2":
NewJ2L(Version.JJ2);
break;
case "TSF":
NewJ2L(Version.TSF);
break;
case "O":
NewJ2L(Version.O);
break;
case "GorH":
NewJ2L(Version.GorH);
break;
case "BC":
NewJ2L(Version.BC);
break;
case "AGA":
NewJ2L(Version.AGA);
break;
default:
MessageBox.Show("MLLE cannot run if you have none of the games it's built for!", "go download battery check or something", MessageBoxButtons.OK, MessageBoxIcon.Stop);
Settings.IniWriteValue("Miscellaneous", "Initialized", "0");
Application.Exit();
return;
}
for (ushort x = 0; x < IsEachTileSelected.Length; x++) IsEachTileSelected[x] = new bool[1026];
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.CullFace);
GeneratorOverlay = TexUtil.CreateTextureFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Generator.png"));
SelectionOverlay = TexUtil.CreateTextureFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SelectionRectangles.png"));
GL.BindTexture(TextureTarget.Texture2D, J2L.ImageAtlas);
GL.ClearColor(HotKolors[0]);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
LevelDisplay.SwapBuffers();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
TilesetOverlaySelection.SelectedIndex = 2;
(DeepEditingTool = VisibleEditingTool = PaintbrushButton).Checked = true;
Dictionary<string, Keys> StK = new Dictionary<string, Keys>
{
{"Shift", Keys.Shift},
{"Control", Keys.Control},
{"Alt", Keys.Alt}
};
try { AddSelectionKey = StK[Settings.IniReadValue("Hotkeys", "AddToSelection")]; }
catch { AddSelectionKey = Keys.Shift; }
try { SubtractSelectionKey = StK[Settings.IniReadValue("Hotkeys", "SubtractFromSelection")]; }
catch { SubtractSelectionKey = Keys.Control; }
ParallaxEventDisplayType = (Settings.IniReadValue("Miscellaneous", "EventParallaxMode") == "0") ? (byte)0 : (byte)1; eventsForemostToolStripMenuItem.Checked = ParallaxEventDisplayType == 1;
AllowExtraZooming = (Settings.IniReadValue("Miscellaneous", "ZoomingAbove100") == "1"); zoomingAbove100ToolStripMenuItem.Checked = Zoom200.Enabled = Zoom400.Enabled = AllowExtraZooming;
PreviewHelpStringColors = (Settings.IniReadValue("Miscellaneous", "PreviewHelpStringColors") != "0"); previewHelpStringColorsToolStripMenuItem.Checked = PreviewHelpStringColors;
ToolStripMenuItem[] recolorableSpriteSubcategories = { pinballToolStripMenuItem, platformsToolStripMenuItem, polesToolStripMenuItem, sceneryToolStripMenuItem };
for (int i = 0; i < RecolorableSpriteNames.Length; ++i)
{
ToolStripMenuItem toolstripitem = new ToolStripMenuItem(RecolorableSpriteNames[i]);
toolstripitem.Tag = i;
toolstripitem.Click += recolorableSpriteToolStripMenuItem_Click;
recolorableSpriteSubcategories[RecolorableSpriteCategories[i]].DropDownItems.Add(toolstripitem);
}
LevelDisplay.MouseWheel += LevelDisplay_MouseWheel;
var commands = Environment.GetCommandLineArgs();
if (commands.Length > 1) switch (Path.GetExtension(commands[1].Trim()).ToLowerInvariant())
{
case ".j2l":
case ".lev":
case ".lvl":
LoadJ2L(commands[1]);
break;
case ".j2t":
case ".til":
ChangeTileset(commands[1]);
break;
case ".mlleset":
ChangeTileset(Path.ChangeExtension(commands[1], ".j2t"));
TilesetOverlaySelection.SelectedIndex = 4;
break;
default:
break;
}
sw.Start();
DrawThread = new Thread(TimePasses);
DrawThread.IsBackground = true;
DrawThread.Start();
}
private void LevelDisplay_MouseWheel(object sender, MouseEventArgs e)
{
if (LastFocusedZone == FocusedZone.None)
return;
var scrollbarToMove = (LastFocusedZone == FocusedZone.Level) ? LDScrollV : TilesetScrollbar;
if (scrollbarToMove != TilesetScrollbar || CurrentTilesetOverlay != TilesetOverlay.SmartTiles) //no scrolling of the tileset pane allowed in smart tiles mode
MakeProposedScrollbarValueWork(scrollbarToMove, scrollbarToMove.Value - scrollbarToMove.SmallChange * e.Delta / 120);
}
private void DeleteLevelScriptIfEmpty()
{
string scriptFilePath = Path.ChangeExtension(J2L.FullFilePath, ".j2as");
if (File.Exists(scriptFilePath) && new FileInfo(scriptFilePath).Length == 0) //if you created a script for this level while editing it, but didn't write anything in the script, just delete it afterwards
File.Delete(scriptFilePath);
}
private void Mainframe_FormClosing(object sender, FormClosingEventArgs e) {
if (!PromptForSaving())
{
e.Cancel = true;
_suspendEvent.Set();
return;
}
if (DrawThread != null)
DrawThread.Abort();
DeleteLevelScriptIfEmpty();
bool windowIsMaximized = this.WindowState == FormWindowState.Maximized;
Settings.IniWriteValue("Window", "Maximized", windowIsMaximized.ToString());
if (!windowIsMaximized && this.Location.Y > -5) //otherwise something probably went wrong, so don't record these numbers
{
Settings.IniWriteValue("Window", "X", this.Location.X.ToString());
Settings.IniWriteValue("Window", "Y", this.Location.Y.ToString());
Settings.IniWriteValue("Window", "Width", this.Size.Width.ToString());
Settings.IniWriteValue("Window", "Height", this.Size.Height.ToString());
}
}
private void Mainframe_Paint(object sender, PaintEventArgs e)
{
LDScrollH.Update();
LDScrollV.Update();
TilesetScrollbar.Update();
}
internal void IdentifyTileset()
{
TilesetSelection.SelectedIndex = TilesetSelection.Items.IndexOf(AllTilesetLists[J2L.VersionType].FirstOrDefault((NameAndFilename nf) => { return Path.GetFileName(nf.Filename) == J2L.MainTilesetFilename; }));
//desiredindex = AllTilesets.FindIndex(delegate(string current) { return Path.GetFileName(current) == J2L.Tileset; });
//foreach (StringAndIndex item in TilesetSelection.Items)
//{
// if (item.Index == desiredindex) { TilesetSelection.SelectedIndex = TilesetSelection.Items.IndexOf(item); break; }
//}
}
internal void CheckCurrentVersion()
{
jazz2V110oToolStripMenuItem.Checked = J2L.VersionType == Version.O;
batteryCheckToolStripMenuItem.Checked = J2L.VersionType == Version.BC;
jazz2V123ToolStripMenuItem.Checked = J2L.VersionType == Version.JJ2;
jazz2V124ToolStripMenuItem.Checked = J2L.VersionType == Version.TSF;
animaniacsToolStripMenuItem.Checked = J2L.VersionType == Version.AGA;
jazz2V100ghToolStripMenuItem.Checked = J2L.VersionType == Version.GorH;
}
int GetLayerOrderFromDefaultLayerID(int number)
{
for (int i = 0; i < J2L.AllLayers.Count; ++i)
if (J2L.AllLayers[i].id == number)
{
return i;
}
return 0;
}
internal void ChangeLayerByDefaultLayerID(int number)
{
ChangeLayerByOrder(GetLayerOrderFromDefaultLayerID(number));
}
internal void ChangeLayerByOrder(int number)
{
CurrentLayerID = (byte)number;
CheckCurrentLayerButton();
ResizeDisplay();
}
/*internal void ReadjustScrollbars()
{
MakeProposedScrollbarValueWork(TilesetScrollbar, TilesetScrollbar.Value);
MakeProposedScrollbarValueWork(LDScrollH, LDScrollH.Value);
MakeProposedScrollbarValueWork(LDScrollV, LDScrollV.Value);
}*/
internal int MakeProposedScrollbarValueWork(ScrollBar bar, int nuVal)
{
return bar.Value = Math.Max(0, Math.Min(bar.Maximum - bar.LargeChange + 1, nuVal));
}
enum ParallaxMode { NoParallax, FullParallax, TemporaryParallax }
enum MaskMode { NoMask, FullMask, TemporaryMask }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (TilesetSelection.Focused)
return false;
switch (keyData)
{
case Keys.D1: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(0); return true; } else return false; }
case Keys.D2: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(1); return true; } else return false; }
case Keys.D3: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(2); return true; } else return false; }
case Keys.D4: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(3); return true; } else return false; }
case Keys.D5: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(4); return true; } else return false; }
case Keys.D6: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(5); return true; } else return false; }
case Keys.D7: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(6); return true; } else return false; }
case Keys.D8: { if (LastFocusedZone != FocusedZone.AnimationEditing) { ChangeLayerByDefaultLayerID(7); return true; } else return false; }
case (Keys.D1 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(0); return true; }
case (Keys.D2 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(1); return true; }
case (Keys.D3 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(2); return true; }
case (Keys.D4 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(3); return true; }
case (Keys.D5 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(4); return true; }
case (Keys.D6 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(5); return true; }
case (Keys.D7 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(6); return true; }
case (Keys.D8 | Keys.Control): { ShowLayerPropertiesByDefaultLayerID(7); return true; }
case (Keys.Shift | Keys.T): { return setTileType(1); }
case (Keys.D0 | Keys.Shift): { return setTileType(0); }
case (Keys.D1 | Keys.Shift): { return setTileType(1); }
case (Keys.D2 | Keys.Shift): { return setTileType(2); }
case (Keys.D3 | Keys.Shift): { return setTileType(3); }
case (Keys.D4 | Keys.Shift): { return setTileType(4); }
case (Keys.D5 | Keys.Shift): { return setTileType(5); }
case (Keys.D6 | Keys.Shift): { return setTileType(6); }
case (Keys.D7 | Keys.Shift): { return setTileType(7); }
case (Keys.D8 | Keys.Shift): { return setTileType(8); }
case (Keys.D9 | Keys.Shift): { return setTileType(9); }
case (Keys.Control | Keys.Subtract): { ZoomOut(); return true; }
case (Keys.Control | Keys.Add): { ZoomIn(); return true; }
case Keys.M: { if (!CurrentModifierKeys[Keys.Control]) MaskDisplayMode = MaskMode.TemporaryMask; return true; }
case Keys.P: { if (!CurrentModifierKeys[Keys.Control]) ParallaxDisplayMode = ParallaxMode.TemporaryParallax; return true; }
case (Keys.Control | Keys.Shift | Keys.R): { if (LastFocusedZone == FocusedZone.Level) PlayFromHere(); return true; }
case (Keys.Control | Keys.P): { ParallaxButton.Checked = DropdownParallax.Checked = !ParallaxButton.Checked; return true; }
case (Keys.Control | Keys.M): { MaskButton.Checked = DropdownMask.Checked = !MaskButton.Checked; return true; }
case (Keys.Control | Keys.V): { EventsButton.Checked = DropdownEvents.Checked = !EventsButton.Checked; return true; }
case Keys.Left: { if (LastFocusedZone == FocusedZone.Level) try { LDScrollH.Value -= LDScrollH.SmallChange; } catch { LDScrollH.Value = 0; } return true; }
case Keys.Right: { if (LastFocusedZone == FocusedZone.Level) LDScrollH.Value = Math.Min(LDScrollH.Value + LDScrollH.SmallChange, LDScrollH.Maximum - LDScrollH.LargeChange + 1); return true; }
case Keys.Delete:
{
if (LastFocusedZone == FocusedZone.AnimationEditing && SelectedAnimationFrame < WorkingAnimation.FrameCount) { WorkingAnimation.DeleteFrame(SelectedAnimationFrame); WorkingAnimation.JustBeenEdited(GameTick); if (AnimScrollbar.Maximum > 32) AnimScrollbar.Maximum -= 32; AnimScrollbar.Value = Math.Max(0, AnimScrollbar.Value - 32); LevelHasBeenModified = true; }
else if (LastFocusedZone == FocusedZone.Level) Clear(CurrentLayerID);
return true;
}
case Keys.F:
case (Keys.Control | Keys.F):
{
if (CurrentTilesetOverlay == TilesetOverlay.SmartTiles) { } //nothing
else if (LastFocusedZone == FocusedZone.AnimationEditing) WorkingAnimation.Sequence[SelectedAnimationFrame] ^= (ushort)J2L.MaxTiles;
else if (CurrentStamp.Length > 0)
{
TileAndEvent[][] NuStamp = new TileAndEvent[CurrentStamp.Length][];
for (ushort x = 0; x < NuStamp.Length; x++)
{
TileAndEvent[] column = NuStamp[x] = CurrentStamp[NuStamp.Length - x - 1];
for (ushort y = 0; y < column.Length; y++)
if (column[y].Tile != 0)
{
if (keyData == Keys.F)
column[y].Tile ^= (ushort)J2L.MaxTiles;
else //Ctrl+F
SmartFlipTile(ref column[y].Tile, false);
}
}
CurrentStamp = NuStamp;
}
return true;
}
case Keys.I:
case (Keys.Control | Keys.I):
{
if (VersionIsPlusCompatible(J2L.VersionType) && CurrentTilesetOverlay != TilesetOverlay.SmartTiles)
{
if (LastFocusedZone == FocusedZone.AnimationEditing) WorkingAnimation.Sequence[SelectedAnimationFrame] ^= (ushort)0x2000;
else if (CurrentStamp.Length > 0)
{
TileAndEvent[][] NuStamp = new TileAndEvent[CurrentStamp.Length][];
int height = CurrentStamp[0].Length;
for (ushort x = 0; x < NuStamp.Length; x++)
{
TileAndEvent[] column = NuStamp[x] = new TileAndEvent[height];
for (ushort y = 0; y < height; y++)
if ((column[y].Tile = CurrentStamp[x][height - y - 1].Tile) != 0)
{
if (keyData == Keys.I)
column[y].Tile ^= (ushort)0x2000;
else //Ctrl+I
SmartFlipTile(ref column[y].Tile, true);
}
}
CurrentStamp = NuStamp;
}
}
return true;
}
case (Keys.Control | Keys.E): { GrabEventAtMouse(); return true; }
case (Keys.Shift | Keys.E): { PasteEventAtMouse(); return true; }
case Keys.E: { SelectEventAtMouse(); return true; }
case Keys.Oemcomma:
case (Keys.Shift | Keys.Oemcomma):
{
uint? ev = 0;
ushort tileID = (LastFocusedZone == FocusedZone.Level) ? CurrentLayer.TileMap[MouseTileX, MouseTileY] : (ushort)MouseTile;
if (CurrentTilesetOverlay == TilesetOverlay.SmartTiles) {
if (LastFocusedZone != FocusedZone.Level)
{
if (MouseTile >= SmartTiles.Count)
return true;
if (!SmartTiles[MouseTile].Available)
return true;
ev = (uint?)tileID;
tileID = SmartTiles[(int)ev.Value].PreviewTileIDs[1];
}
else
{
int i = 0;
while (true)
{
if (SmartTiles[i].Available && SmartTiles[i].TilesICanPlace.Contains(tileID, SmartTiles[i].TilesICanPlace.Comparer))
{
ev = (uint?)i;
tileID = SmartTiles[i].PreviewTileIDs[1];
break;
}
else if (++i == SmartTiles.Count)
return true;
}
}
}
else if (keyData == (Keys.Shift | Keys.Oemcomma))
ev = MouseAGAEvent.ID;
SetStampDimensions(1, 1);
CurrentStamp[0][0] = new TileAndEvent(tileID, ev);
ShowBlankTileInStamp = true;
DeselectAll();
return true;
}
case Keys.Back: /*if (CurrentTilesetOverlay != TilesetOverlay.SmartTiles || SmartTiles[0].PreviewTileIDs == 0)*/ { ShowBlankTileInStamp = true; SetStampDimensions(1, 1); CurrentStamp[0][0] = new TileAndEvent(0, 0); DeselectAll(); } return true;
case (Keys.Control | Keys.B):
{
if (CurrentTilesetOverlay == TilesetOverlay.SmartTiles) { } //do nothing
else if (WhereSelected != FocusedZone.None && HowSelecting == FocusedZone.None) BeginSelection(SelectionType.Subtract);
else { EndSelection(); MakeSelectionIntoStamp(); if (WhereSelected == FocusedZone.Level) DeselectAll(); }
return true;
}
case (Keys.Shift | Keys.B):
{
if (CurrentTilesetOverlay == TilesetOverlay.SmartTiles) { } //do nothing
else if (LastFocusedZone == WhereSelected && HowSelecting == FocusedZone.None) BeginSelection(SelectionType.Add);
else if (HowSelecting != LastFocusedZone) BeginSelection(SelectionType.New);
else { EndSelection(); MakeSelectionIntoStamp(); if (WhereSelected == FocusedZone.Level) DeselectAll(); }
return true;
}
case Keys.B:
{
if (CurrentTilesetOverlay == TilesetOverlay.SmartTiles) { } //do nothing
else if (LastFocusedZone != HowSelecting) BeginSelection(SelectionType.New);
else { EndSelection(); MakeSelectionIntoStamp(); if (WhereSelected == FocusedZone.Level) DeselectAll(); }
return true;
}
case (Keys.Control | Keys.D):
{
DeselectAll();
return true;
}
case (Keys.Control | Keys.C):
{
if (CurrentTilesetOverlay != TilesetOverlay.SmartTiles) MakeSelectionIntoStamp();
return true;
}
case (Keys.Control | Keys.X):
{
if (CurrentTilesetOverlay != TilesetOverlay.SmartTiles) MakeSelectionIntoStamp(true);
return true;
}
default: return base.ProcessCmdKey(ref msg, keyData);
}
}
private Dictionary<Keys, bool> CurrentModifierKeys = new Dictionary<Keys, bool> { { Keys.Shift, false }, { Keys.Control, false }, { Keys.Alt, false } };
private void Mainframe_KeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
/*case Keys.Shift:
case Keys.Control:
case Keys.Alt:
CurrentModifierKeys[e.KeyData] = false;
break;*/
case Keys.M:
if (MaskDisplayMode == MaskMode.TemporaryMask) MaskDisplayMode = MaskButton.Checked ? MaskMode.FullMask : MaskMode.NoMask;
break;
case Keys.P:
if (ParallaxDisplayMode == ParallaxMode.TemporaryParallax) ParallaxDisplayMode = ParallaxButton.Checked ? ParallaxMode.FullParallax : ParallaxMode.NoParallax;
break;
default:
break;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { SafeToDisplay = false; Application.Exit(); }
private bool setTileType(byte value)
{
if (LastFocusedZone == FocusedZone.Tileset && MouseTile < J2L.TileCount && TexturedJ2L.TileTypeNames[J2L.VersionType][value] != "")
{
J2L.TileTypes[MouseTile] = value;
return RerenderTile((uint)MouseTile);
}
else return false;
}
private bool RerenderTile(uint tileID)
{
SetTextureTo(AtlasID.Image);
J2L.RerenderTile(tileID);
if (CurrentTilesetOverlay != TilesetOverlay.Masks)
RedrawTilesetHowManyTimes = 2;
LevelHasBeenModified = true;
return true;
}
private bool RerenderTileMask(uint tileID)
{
SetTextureTo(AtlasID.Mask);
J2L.RerenderTileMask(tileID);
if (CurrentTilesetOverlay == TilesetOverlay.Masks)
RedrawTilesetHowManyTimes = 2;
LevelHasBeenModified = true;
return true;
}
private void imageToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MouseTile > 0 && MouseTile < J2L.TileCount && CurrentTilesetOverlay != TilesetOverlay.SmartTiles)
{
_suspendEvent.Reset();
J2TFile J2T;
uint tileInTilesetID = J2L.getTileInTilesetID((uint)MouseTile, out J2T);
var originalTileImage = J2T.Images[J2T.ImageAddress[tileInTilesetID]];
if (new TileImageEditorForm().ShowForm(
ref J2L.PlusPropertyList.TileImages[MouseTile],
(J2T.ColorRemapping == null) ?
originalTileImage :
Enumerable.Range(0, 32 * 32).Select(val => J2T.ColorRemapping[originalTileImage[val]]).ToArray(),
J2L.Palette
))
RerenderTile((uint)MouseTile);
_suspendEvent.Set();
}
}
private void maskToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MouseTile > 0 && MouseTile < J2L.TileCount)
{
_suspendEvent.Reset();
J2TFile J2T;
uint tileInTilesetID = J2L.getTileInTilesetID((uint)MouseTile, out J2T);
if (new TileImageEditorForm().ShowForm(
ref J2L.PlusPropertyList.TileMasks[MouseTile],
J2T.Masks[J2T.MaskAddress[tileInTilesetID]],
null
))
RerenderTileMask((uint)MouseTile);
_suspendEvent.Set();
}
}
private void automaskToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MouseTile > 0 && MouseTile < J2L.TileCount)
{
J2TFile J2T;
uint tileInTilesetID = J2L.getTileInTilesetID((uint)MouseTile, out J2T);
J2L.PlusPropertyList.TileMasks[MouseTile] = (J2L.PlusPropertyList.TileImages[MouseTile] ?? J2T.Images[J2T.ImageAddress[tileInTilesetID]]).Select(val => val != 0 ? (byte)1 : (byte)0).ToArray();
RerenderTileMask((uint)MouseTile);
}
}
private void copyImageToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap result = new Bitmap(
(BottomRightSelectionCorner.X - UpperLeftSelectionCorner.X) * 32,
(BottomRightSelectionCorner.Y - UpperLeftSelectionCorner.Y) * 32,
System.Drawing.Imaging.PixelFormat.Format8bppIndexed
);
byte[] resultAsBytes = new byte[result.Width * result.Height];
for (int x = UpperLeftSelectionCorner.X; x < BottomRightSelectionCorner.X; ++x)
for (int y = UpperLeftSelectionCorner.Y; y < BottomRightSelectionCorner.Y; ++y)
if (IsEachTileSelected[x + 1][y + 1])
{
uint tileID = (uint)(y * 10 + x);
if (tileID < J2L.TileCount)
{
byte[] tileImageAsBytes = J2L.PlusPropertyList.TileImages[tileID];
if (tileImageAsBytes == null)
{
J2TFile J2T;
uint tileInTilesetID = J2L.getTileInTilesetID(tileID, out J2T);
tileImageAsBytes = J2T.Images[J2T.ImageAddress[tileInTilesetID]];
if (J2T.ColorRemapping != null)
{
tileImageAsBytes = tileImageAsBytes.Select(c => J2T.ColorRemapping[c]).ToArray();
}
}
int firstResultByteIndex = (x - UpperLeftSelectionCorner.X) * 32 + (y - UpperLeftSelectionCorner.Y) * 32 * result.Width;
for (int b = 0; b < 32 * 32; ++b)
resultAsBytes[firstResultByteIndex + (b & 31) + (b >> 5) * result.Width] = tileImageAsBytes[b];
}
}
BitmapStuff.ByteArrayToBitmap(resultAsBytes, result, true);
J2L.Palette.Apply(result);
BitmapStuff.CopyBitmapToClipboard(result);
}
private void pasteImageToolStripMenuItem_Click(object sender, EventArgs e)
{
Bitmap clipboardBitmap = BitmapStuff.GetBitmapFromClipboard(null);
if (clipboardBitmap != null)
{
int selectionWidth = (BottomRightSelectionCorner.X - UpperLeftSelectionCorner.X) * 32;
int selectionHeight = (BottomRightSelectionCorner.Y - UpperLeftSelectionCorner.Y) * 32;
_suspendEvent.Reset();
if (selectionWidth != clipboardBitmap.Width || selectionHeight != clipboardBitmap.Height)
{
if (MessageBox.Show(string.Format(
"You are pasting a {0}x{1} pixel image into an area of {4}x{5} pixels ({2}x{3} tiles). The image will be automatically resized to fit. Do you wish to continue?",
clipboardBitmap.Width,
clipboardBitmap.Height,
BottomRightSelectionCorner.X - UpperLeftSelectionCorner.X,
BottomRightSelectionCorner.Y - UpperLeftSelectionCorner.Y,
selectionWidth,
selectionHeight
), "Resizing Image", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No)
{
_suspendEvent.Set();
return;
}
}
byte[] colorRemappings = null;
if (new SpriteRecolorForm().ShowForm(J2L.Palette, clipboardBitmap.Clone() as Bitmap, ref colorRemappings, HotKolors[1]))
{
byte[] clipboardBytes = BitmapStuff.BitmapToByteArray(clipboardBitmap);
//nearest neighbor the pasted image into the selected tiles
for (int x = UpperLeftSelectionCorner.X; x < BottomRightSelectionCorner.X; ++x)
for (int y = UpperLeftSelectionCorner.Y; y < BottomRightSelectionCorner.Y; ++y)
if (IsEachTileSelected[x + 1][y + 1])
{
uint tileID = (uint)(x + y * 10);