-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
1919 lines (1737 loc) · 76 KB
/
Form1.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 System.Collections;
using System.Text;
using System.Xml;
// fix/stuff:
// fix tile picker/add label to show which tile selected/pointed at
// stcani.tbl
// undo buffer
// copy buffer -> auto paste on new map bug? (hyru)
// delete block
// fix deselecting when switching to right fg (heiler)
// popup with scrollable list of tiles (acht/heiler)
// fix pasting at < 0
// deleting / 0 tile causes popup exception?
// x newfile flag not set false after saving
// proper copy/cut/paste/select
namespace MapEditor;
public partial class Form1 : Form
{
//delegate void Temp();
System.Collections.Hashtable STCforegrounds = new Hashtable();
String darkagesPath;
//bool newFile = false;
//List<UndoItem> undoBuffer = new List<UndoItem>();
string[] titles =
{
"This shirt is \"dry-clean only\"...which means it's dirty.",
"If carrots got you drunk, rabbits would be fucked up.",
"I wish I could play little league now, I'd kick some fuckin' ass.",
"My fake plants died because I did not pretend to water them.",
"I don't have a microwave oven, but I do have a clock that occasionally cooks shit.",
"I had a parrot. The parrot talked, but it did not say \"I'm hungry,\" so it died.",
"I order the club sandwich all the time, but I'm not even a member, man. I don't know how I get away with it.",
"I saw this wino, he was eating grapes. I was like, \"Dude, you have to wait.\"",
"I'd like to make a vending machine that sells vending machines. It'd have to be real fuckin' big!",
"I'm against picketing, but I don't know how to show it.",
"I haven't slept for ten days, because that would be too long.",
"My friend asked me if I wanted a frozen banana, I said \"No, but I want a regular banana later, so ... yeah\".",
"I used to do drugs. I still do, but I used to, too.",
"I bought a seven-dollar pen because I always lose pens and I got sick of not caring.",
"I like rice. Rice is great when you're hungry and you want 2,000 of something.",
"I love my fed-ex guy cause he's a drug dealer and he doesn't even know it.",
"I got a king sized bed. I don't know any kings, but if one came over, I guess he'd be comfortable.",
"You know that word \"lull\"? That's four letters, three of them are L's, fuck!",
"They say Flintstone's vitamins are chewable. All vitamins are chewable, it's just that they taste shitty.",
"I went to a record store, they said they specialized in hard-to-find records. Nothing was alphabetized.",
"Imagine if the headless horseman had a headless horse. That would be fucking chaos.",
"A fly was very close to being called a \"land,\" cause that's what they do half the time.",
"My belt holds up my pants and my pants have belt loops that hold up the belt. What the fuck’s really goin on down there? Who is the real hero?",
"I can't tell you what hotel I'm stayin' in, but there are two trees involved.",
"Fish are always eating other fish. If fish could scream, the ocean would be loud as shit.",
"I like vending machines 'cause snacks are better when they fall.",
"This guy handed me a picture of him; he said, \"Here's a picture of me when I was younger.\" Every picture is of you when you were younger.",
"Snake eyes! That's a gambling term. Or it's an animal term too.",
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault.",
"I was walking down the street with my friend and he said, \"I hear music\", as if there is any other way you can take it in.",
};
//System.Collections.Hashtable STSforegrounds = new Hashtable();
public Form1(string openFile)
{
//Temp temp = delegate()
//{
//MessageBox.Show("Hi!");
//};
//temp.Invoke();
InitializeComponent();
pictureBox1.Image = new Bitmap(560, 480);
button10_Click(null, null); //yes
pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
pictureBox1.MouseLeave += new EventHandler(pictureBox1_MouseLeave);
pictureBox1.MouseUp += new MouseEventHandler(pictureBox1_MouseUp);
pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseDown);
pictureBox2.MouseDown += new MouseEventHandler(pictureBox2_MouseDown);
pictureBox5.MouseDown += new MouseEventHandler(pictureBox5_MouseDown);
pictureBox5.MouseMove += new MouseEventHandler(pictureBox5_MouseDown);
pictureBox6.MouseDown += new MouseEventHandler(pictureBox6_MouseDown);
pictureBox6.MouseMove += new MouseEventHandler(pictureBox6_MouseDown);
panel1.Scroll += new ScrollEventHandler(panel1_Scroll);
Resize += new EventHandler(Form1_Resize);
darkagesPath = @"C:\Program Files(x86)\KRU\Dark Ages";
WriteConfigXml();
int titleIndex = new Random((int)DateTime.Now.Ticks).Next() % titles.Length;
this.Text = titles[titleIndex];
checkPathsExist();
ToolTip toolTip1 = new ToolTip();
// Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 500;
toolTip1.ReshowDelay = 500;
// Force the ToolTip text to be displayed whether or not the form is active.
toolTip1.ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(button10, "Paint selection to map");
toolTip1.SetToolTip(button9, "Select single tile");
toolTip1.SetToolTip(button11, "Select a block of tiles");
toolTip1.SetToolTip(button12, "Select Darkages install directory");
toolTip1.SetToolTip(button13, "Open map file");
toolTip1.SetToolTip(button14, "Toggle background");
toolTip1.SetToolTip(button15, "Toggle left foreground");
toolTip1.SetToolTip(button16, "Toggle right foreground");
toolTip1.SetToolTip(button17, "Edit background");
toolTip1.SetToolTip(button18, "Edit left foreground");
toolTip1.SetToolTip(button19, "Edit right foreground");
toolTip1.SetToolTip(button20, "Edit all layers");
toolTip1.SetToolTip(button21, "Edit both foreground layers");
toolTip1.SetToolTip(button22, "Return to top of map");
toolTip1.SetToolTip(button24, "Undo [Ctrl+Z]");
toolTip1.SetToolTip(checkBox1, "If selection includes blank foregrounds, include them when pasting to map.");
toolTip1.SetToolTip(checkBox2, "Show collision points in map and foreground tiles list.");
tabControl2.SelectedIndexChanged += new EventHandler(tabControl2_SelectedIndexChanged);
DragEnter += new DragEventHandler(OnDragEnter);
DragDrop += new DragEventHandler(OnDragDrop);
//pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseOver);
//Thread t = new Thread(new ThreadStart(LoadDat));
//t.Start();
if (openFile != null)
{
openMap(openFile, false);
}
}
private void OnDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
//Debug.WriteLine("OnDragEnter");
string filename;
bool validData = GetFilename(out filename, e);
if (validData)
{
//if (lastFilename != filename)
//{
//thumbnail.Image = null;
//thumbnail.Visible = false;
//lastFilename = filename;
//getImageThread = new Thread(new ThreadStart(LoadImage));
//getImageThread.Start();
//}
//else
//{
//thumbnail.Visible = true;
//}
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
//Debug.WriteLine("OnDragDrop");
string filename;
bool validData = GetFilename(out filename, e);
if (validData)
{
//while (getImageThread.IsAlive)
//{
//Application.DoEvents();
//Thread.Sleep(0);
//}
//thumbnail.Visible = false;
//image = nextImage;
//AdjustView();
//if ((pb.Image != null) && (pb.Image != nextImage))
//{
//pb.Image.Dispose();
//}
//pb.Image = image;
openMap(filename, false);
}
}
protected bool GetFilename(out string filename, DragEventArgs e)
{
bool ret = false;
filename = String.Empty;
if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
{
Array data = ((IDataObject)e.Data).GetData("FileName") as Array;
if (data != null)
{
if ((data.Length == 1) && (data.GetValue(0) is String))
{
filename = ((string[])data)[0];
string ext = Path.GetExtension(filename).ToLower();
if ((ext == ".map"))
{
ret = true;
}
}
}
}
return ret;
}
protected override bool ProcessDialogKey(Keys keyData)
{
switch (keyData)
{
case (Keys.Control | Keys.F4):
closeMap();
return true; // Tell the caller that the key has been handled
//case (Keys.Control | Keys.F1):
//MessageBox.Show("You pressed Crtl-F1");
//return true;
case (Keys.Control | Keys.N):
newToolStripMenuItem_Click(null, null);
return true; // Tell the caller that the key has been handled
case (Keys.Control | Keys.T):
newToolStripMenuItem_Click(null, null);
return true; // Tell the caller that the key has been handled
case (Keys.Control | Keys.Z):
button24_Click(null, null);
return true; // Tell the caller that the key has been handled
};
// If the key hasn't been used by you then pass it to the base class
return base.ProcessDialogKey(keyData);
}
private void closeMap()
{
if (map == null)
{
return;
}
maps.RemoveAt(selectedTabIndex);
tabControl2.TabPages.RemoveAt(selectedTabIndex);
}
void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
{
if (maps.Count == 0)
{
return;
}
if (selectedTabIndex >= 0 && selectedTabIndex < maps.Count)
{
maps[selectedTabIndex].vscroll = Capricorn.Drawing.DAGraphics.vscroll;
maps[selectedTabIndex].hscroll = Capricorn.Drawing.DAGraphics.hscroll;
}
selectedTabIndex = tabControl2.SelectedIndex;
//MessageBox.Show("Fuck off " + selectedTabIndex + " " + maps.Count);
Capricorn.Drawing.DAGraphics.vscroll = maps[selectedTabIndex].vscroll;
Capricorn.Drawing.DAGraphics.hscroll = maps[selectedTabIndex].hscroll;
listBox1.Items.Clear();
// Add the dimensions to the GUI thingy and pick item #0 by default
for (int i = 0; i < widths.Count; i++)
{
string s = "Width: " + widths[i] + " Height: " + heights[i];
listBox1.Items.Add(s);
}
RefreshMap();
tabControl2.TabPages[tabControl2.SelectedIndex].Controls.Add(pictureBox1);
pictureBox1.Location = new Point(0, 0);
pictureBox1.Visible = true;
}
void Form1_Resize(object sender, EventArgs e)
{
if (map == null)
{
return;
}
RefreshMap();
if (Capricorn.Drawing.DAGraphics.editMode == 0)
{
RefreshTilesetBg();
}
else if (Capricorn.Drawing.DAGraphics.editMode == 1 || Capricorn.Drawing.DAGraphics.editMode == 2)
{
RefreshTilesetHpf();
}
}
void panel1_Scroll(object sender, ScrollEventArgs e)
{
if (map == null)
{
return;
}
if (Capricorn.Drawing.DAGraphics.editMode == 1 || Capricorn.Drawing.DAGraphics.editMode == 2)
{
double percent = 1.05 * (panel1.VerticalScroll.Value / (double)panel1.VerticalScroll.Maximum);//e.NewValue / 10000.0;
int newStart = (int)(maxHpf * percent);
newStart = (newStart / 6) * 6;
tileset_index = newStart;
// MessageBox.Show("Hi " + percent + " - " + maxHpf);
RefreshTilesetHpf();
}
else if (Capricorn.Drawing.DAGraphics.editMode == 0)
{
double percent = 1.05 * (panel1.VerticalScroll.Value / (double)panel1.VerticalScroll.Maximum);//e.NewValue / 10000.0;
int newStart = (int)(tiles.TileCount * percent);
newStart = (newStart / 3) * 3;
tileset_index = newStart;
// MessageBox.Show("Hi " + percent + " - " + maxHpf);
RefreshTilesetBg();
}
}
void checkPathsExist()
{
if (!darkagesPath.EndsWith("\\"))
{
darkagesPath = darkagesPath + "\\";
}
if (!File.Exists(darkagesPath + "ia.dat") || !File.Exists(darkagesPath + "seo.dat"))
{
button13.Enabled = false;
openToolStripMenuItem.Enabled = false;
}
else
{
button13.Enabled = true;
openToolStripMenuItem.Enabled = true;
}
}
public class LoadedMapInfo
{
public Capricorn.Drawing.MAPFile map;
public ArrayList widths = new ArrayList();
public ArrayList heights = new ArrayList();
public List<UndoItem> undoBuffer = new List<UndoItem>();
public int vscroll = 0;
public int hscroll = 0;
public bool newMap;
}
public Capricorn.IO.DATArchive seodat;
public Capricorn.IO.DATArchive iadat;
//lod3079.map
public List<LoadedMapInfo> maps = new List<LoadedMapInfo>();
public Capricorn.Drawing.MAPFile map
{
get {
if (selectedTabIndex >= maps.Count)
return null;
return maps[selectedTabIndex].map;
}
//set { this.m_LevPoints = value; }
}
public ArrayList widths
{
get
{
if (selectedTabIndex >= maps.Count)
return null;
return maps[selectedTabIndex].widths;
}
}
public ArrayList heights
{
get
{
if (selectedTabIndex >= maps.Count)
return null;
return maps[selectedTabIndex].heights;
}
}
public bool newFile
{
get
{
if (selectedTabIndex >= maps.Count)
return false;
return maps[selectedTabIndex].newMap;
}
set
{
if (selectedTabIndex >= maps.Count)
return;
maps[selectedTabIndex].newMap = value;
}
}
public List<UndoItem> undoBuffer
{
get
{
if (selectedTabIndex >= maps.Count)
return null;
return maps[selectedTabIndex].undoBuffer;
}
}
int selectedTabIndex = 0;
public Capricorn.Drawing.Tileset tiles;
public Capricorn.Drawing.Tileset tileas;
public Capricorn.Drawing.PaletteTable bgtable;
public Capricorn.Drawing.PaletteTable fgtable;
public int tileset_index = 0;
//now for the right menu only
//bool fgedit = false;
//0=paint, 1=drop, 2=select
//int selectedtileBG = 0;
//int selectedtileFGleft = 0;
//int selectedtileFGright = 0;
int scrollx = 0;
int scrolly = 0;
int panXStart = -1;
int panYStart = -1;
//int panXEnd = -1;
//int panYEnd = -1;
int panXScrollStart = -1;
int panYScrollStart = -1;
bool snowy = false;
//private Capricorn.Drawing.MAPFile getMap()
//{
//if (selectedTabIndex >= maps.Count)
//return null;
//return maps[selectedTabIndex];
//}
public bool LoadXmlData()
{
XmlDocument doc = new XmlDocument();
string dir = Path.GetDirectoryName(Application.ExecutablePath);
if (!dir.EndsWith("\\"))
{
dir = dir + "\\";
}
try
{
doc.Load(dir + "Config.xml");
}
catch (Exception)
{
return false;
}
XmlNodeList nodes = doc.SelectNodes("//Config");
if (nodes.Count == 0)
{
return false;
}
XmlNode config = nodes[0];
foreach (XmlNode childNode in config.ChildNodes)
{
if (childNode.Name == "DarkagesPath")
{
darkagesPath = childNode.InnerText;
}
}
return true;
}
public void WriteConfigXml()
{
string dir = Path.GetDirectoryName(Application.ExecutablePath);
if (!dir.EndsWith("\\"))
{
dir = dir + "\\";
}
FileStream stream = File.Create(dir + "Config.xml");
XmlTextWriter xml = new XmlTextWriter(stream, Encoding.ASCII);
xml.Formatting = Formatting.Indented;
xml.Indentation = 2;
xml.IndentChar = ' ';
xml.WriteStartDocument(true);
xml.WriteStartElement("Config");
xml.WriteStartElement("DarkagesPath");
xml.WriteString(darkagesPath);
xml.WriteEndElement();
xml.WriteEndElement();
xml.WriteEndDocument();
xml.Flush();
xml.Close();
}
int maxHpf;
//public void LoadFilesFromDat(string datfilename)
//{
// Capricorn.IO.DATArchive dat = Capricorn.IO.DATArchive.FromFile(datfilename);
// foreach (Capricorn.IO.DATFileEntry df in dat.Files)
// {
// if (df.Name.Contains(".hpf"))
// {
// byte[] thisHpf = dat.ExtractFile(df);
// Capricorn.Drawing.HPFImage hpf = Capricorn.Drawing.HPFImage.FromRawData(thisHpf);
// int filenum = int.Parse(df.Name.Substring(3, 5));
// if (df.Name.Contains("stc"))
// {
// STCforegrounds.Add(filenum, hpf);
// //if (filenum > maxHpf)
// //{
// //maxHpf = filenum;
// //}
// }
// }
// }
//}
private void Form1_Load(object sender, EventArgs e)
{
}
public bool IsWhole(double value)
{
return value == (double)((int)value);
}
private void openMap(string filename, bool newMap)
{
//MessageBox.Show("Opening " + newFile);
String seoFile = darkagesPath.EndsWith("\\") ? darkagesPath + "seo.dat" : darkagesPath + "\\seo.dat";
String iaFile = darkagesPath.EndsWith("\\") ? darkagesPath + "ia.dat" : darkagesPath + "\\ia.dat";
if (!File.Exists(seoFile))
{
MessageBox.Show(seoFile + " not found.");
return;
}
if (!File.Exists(iaFile))
{
MessageBox.Show(iaFile + " not found.");
return;
}
if (!stuffLoaded)
{
seodat = Capricorn.IO.DATArchive.FromFile(seoFile);
iadat = Capricorn.IO.DATArchive.FromFile(iaFile);
}
//lod3079.map
if (newMap)
tabControl2.TabPages.Add("[New]");
else
{
//string smallFn = filename;
string smallFn = filename.Substring(1 + filename.LastIndexOfAny(new char[]{'\\', '/'}));
tabControl2.TabPages.Add(smallFn);
}
tabControl2.TabPages[tabControl2.TabPages.Count - 1].Controls.Add(pictureBox1);
pictureBox1.Location = new Point(0, 0);
pictureBox1.Visible = true;
LoadedMapInfo info = new LoadedMapInfo();
info.newMap = newMap;
info.map = (Capricorn.Drawing.MAPFile.FromFile(filename));
maps.Add(info);
tabControl2.SelectedIndex = tabControl2.TabPages.Count - 1;
//map = Capricorn.Drawing.MAPFile.FromFile(filename);
double sq = Math.Sqrt((double)(map.Tiles.Length));
int start = (int)sq;
info.widths = new ArrayList();
info.heights = new ArrayList();
if (IsWhole(sq))
{
info.widths.Add((int)sq);
info.heights.Add((int)sq);
map.Height = (int)sq;
map.Width = (int)sq;
start--;
}
//get some other dimensions, start at the squarest
for (int i = start; i >= 2; i--)
{
double result = (double)(map.Tiles.Length) / (double)i;
if (i < 256 && result < 256)
{
if (IsWhole(result))
{
// add both combos
widths.Add((int)i);
heights.Add((int)result);
widths.Add((int)result);
heights.Add((int)i);
}
}
}
listBox1.Items.Clear();
// Add the dimensions to the GUI thingy and pick item #0 by default
for (int i = 0; i < widths.Count; i++)
{
string s = "Width: " + widths[i] + " Height: " + heights[i];
listBox1.Items.Add(s);
}
selectedTabIndex = tabControl2.TabPages.Count - 1;
map.Name = filename;
if (!stuffLoaded)
{
tiles = Capricorn.Drawing.Tileset.FromArchive("TILEA.BMP", seodat);
tileas = Capricorn.Drawing.Tileset.FromArchive("TILEAS.BMP", seodat);
bgtable = new Capricorn.Drawing.PaletteTable();
fgtable = new Capricorn.Drawing.PaletteTable();
fgtable.LoadPalettes("stc", iadat);
fgtable.LoadTables("stc", iadat);
bgtable.LoadPalettes("mpt", seodat);
bgtable.LoadTables("mpt", seodat);
Capricorn.Drawing.DAGraphics.sotp = iadat.ExtractFile("sotp.dat");
maxHpf = 50000;
double guessModifier = 40000;
while (guessModifier > 1)
{
Capricorn.Drawing.HPFImage hpf = Capricorn.Drawing.HPFImage.FromArchive(
"stc" + maxHpf.ToString().PadLeft(5, '0') + ".hpf", true, iadat);
if (hpf == null)
{
maxHpf -= (int)guessModifier;
}
else
{
maxHpf += (int)guessModifier;
}
guessModifier /= 1.25;
}
}
stuffLoaded = true;
Bitmap b = null;
if(snowy)
b = Capricorn.Drawing.DAGraphics.RenderMap(map, tileas, bgtable, fgtable, iadat);
else
b = Capricorn.Drawing.DAGraphics.RenderMap(map, tiles, bgtable, fgtable, iadat);
pictureBox1.Image = b;
RefreshTilesetBg();
listBox1.SelectedIndex = 0;
}
bool stuffLoaded = false;
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.Filter = "Darkages map files|*.map";
DialogResult ok = of.ShowDialog();
if (ok == DialogResult.OK)
{
newFile = false;
openMap(of.FileName, false);
}
}
public void RefreshMap()
{
if (map == null)
return;
Capricorn.Drawing.DAGraphics.displayheight = pictureBox1.Height;
Capricorn.Drawing.DAGraphics.displaywidth = pictureBox1.Width;
Bitmap b = null;
if(snowy)
b = Capricorn.Drawing.DAGraphics.RenderMap(map, tileas, bgtable, fgtable, iadat);
else
b = Capricorn.Drawing.DAGraphics.RenderMap(map, tiles, bgtable, fgtable, iadat);
pictureBox1.Image = b;
//pictureBox1.Refresh();
//scrollbars
//int totalcolumns = map.Width + map.Height - 1;
//double vssize = ((double)pictureBox1.Height) / (totalcolumns * 14);
//double hssize = ((double)pictureBox1.Width) / (totalcolumns * 28);
//int vp = (int)(vssize * pictureBox1.Height);
//int hp = (int)(hssize * pictureBox1.Width);
//int vtotal = pictureBox1.Height + vp / 4;
//int htotal = pictureBox1.Width + hp / 4;
//double hpercent = ((double)(Capricorn.Drawing.DAGraphics.hscroll/*+(totalcolumns * 28)*/) / 28.0) / (totalcolumns + 1);
//double vpercent = ((double)Capricorn.Drawing.DAGraphics.vscroll / 14.0) / (totalcolumns + 1);
//int centerx = (int)(hp / 2 + hpercent * htotal) + pictureBox1.Height / 2;
//int centery = (int)(vp / 2 + vpercent * vtotal);
//Bitmap h = new Bitmap(pictureBox1.Width, 10);
//Bitmap v = new Bitmap(10, pictureBox1.Height);
//Graphics gh = Graphics.FromImage(h);
//gh.FillRectangle(Brushes.Blue, centerx - hp, 0, hp, 10);
//Graphics gv = Graphics.FromImage(v);
//gv.FillRectangle(Brushes.Blue, 0, centery - vp / 2, 10, vp);
//pictureBox5.Image = h;
//pictureBox5.Refresh();
//pictureBox6.Image = v;
//pictureBox6.Refresh();
}
private void button5_Click(object sender, EventArgs e)
{
Capricorn.Drawing.DAGraphics.hscroll += 56;
RefreshMap();
}
private void button8_Click(object sender, EventArgs e)
{
Capricorn.Drawing.DAGraphics.vscroll += 28;
RefreshMap();
}
private void button6_Click(object sender, EventArgs e)
{
Capricorn.Drawing.DAGraphics.hscroll -= 56;
RefreshMap();
}
private void button7_Click(object sender, EventArgs e)
{
Capricorn.Drawing.DAGraphics.vscroll -= 28;
RefreshMap();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
int mx = e.X;
int my = e.Y;
if (Capricorn.Drawing.DAGraphics.editMode == 0)
{
Capricorn.Drawing.DAGraphics.selection = new Capricorn.Drawing.MapTile[1];
Capricorn.Drawing.DAGraphics.selectionWidth = 1;
ushort selectedtileBG = (ushort)(tileset_index + (my / 28) * 3 + mx / 56 + 1);
Capricorn.Drawing.DAGraphics.selection[0] = new Capricorn.Drawing.MapTile(selectedtileBG, 0, 0);
label4.Text = (selectedtileBG - 1).ToString();
RefreshTilesetBg();
}
else if (Capricorn.Drawing.DAGraphics.editMode == 1)
{
int xIndex = mx / 28;
int yIndex = tileset_index / 6;
int y = 0;
foreach (int yy in hpfHeights)
{
y += yy;
if (my > y)
{
yIndex ++;
}
}
Capricorn.Drawing.DAGraphics.selection = new Capricorn.Drawing.MapTile[1];
Capricorn.Drawing.DAGraphics.selectionWidth = 1;
ushort index = (ushort)(yIndex * 6 + xIndex);
Capricorn.Drawing.DAGraphics.selection[0] = new Capricorn.Drawing.MapTile(0, index, 0);
label4.Text = index.ToString();
RefreshTilesetHpf();
}
else if (Capricorn.Drawing.DAGraphics.editMode == 2)
{
int xIndex = mx / 28;
int yIndex = tileset_index / 6;
int y = 0;
foreach (int yy in hpfHeights)
{
y += yy;
if (my > y)
{
yIndex++;
}
}
Capricorn.Drawing.DAGraphics.selection = new Capricorn.Drawing.MapTile[1];
Capricorn.Drawing.DAGraphics.selectionWidth = 1;
ushort index = (ushort)(yIndex * 6 + xIndex);
Capricorn.Drawing.DAGraphics.selection[0] = new Capricorn.Drawing.MapTile(0, 0, index);
label4.Text = index.ToString();
RefreshTilesetHpf();
}
// ~~~ here - add click processing for foregrounds
}
void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if ((Capricorn.Drawing.DAGraphics.clickmode == 2 || Capricorn.Drawing.DAGraphics.clickmode == 3) && Capricorn.Drawing.DAGraphics.selectionXStart != -1)
{
int sxs = Capricorn.Drawing.DAGraphics.selectionXStart;
int sys = Capricorn.Drawing.DAGraphics.selectionYStart;
int sxe = Capricorn.Drawing.DAGraphics.selectionXEnd;
int sye = Capricorn.Drawing.DAGraphics.selectionYEnd;
// set selection
int xMin = sxs < sxe ? sxs : sxe;
int yMin = sys < sye ? sys : sye;
int xMax = sxs > sxe ? sxs : sxe;
int yMax = sys > sye ? sys : sye;
Capricorn.Drawing.DAGraphics.selectionWidth = xMax - xMin + 1;
int selectionHeight = yMax - yMin + 1;
if (Capricorn.Drawing.DAGraphics.clickmode == 2)
{
Capricorn.Drawing.DAGraphics.selection = new Capricorn.Drawing.MapTile[Capricorn.Drawing.DAGraphics.selectionWidth * selectionHeight];
}
// For delete
UndoItem undo = new UndoItem();
int blockWidth = (xMax - xMin + 1);
int blockHeight = (yMax - yMin + 1);
undo.bgData = new ushort[blockHeight * blockWidth];
undo.fglData = new ushort[blockHeight * blockWidth];
undo.fgrData = new ushort[blockHeight * blockWidth];
undo.width = (xMax - xMin + 1);
undo.x = xMin;
undo.y = yMin;
for (int y = yMin; y <= yMax; y++)
{
for (int x = xMin; x <= xMax; x++)
{
if (Capricorn.Drawing.DAGraphics.clickmode == 2)
{
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)] = new Capricorn.Drawing.MapTile(0, 0, 0);
if (x < map.Width && x >= 0 && y < map.Height && y >= 0)
{
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)].FloorTile = map.Tiles[y * map.Width + x].FloorTile;
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)].LeftWall = map.Tiles[y * map.Width + x].LeftWall;
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)].RightWall = map.Tiles[y * map.Width + x].RightWall;
}
}
else
{
if (x < map.Width && x >= 0 && y < map.Height && y >= 0)
{
if (Capricorn.Drawing.DAGraphics.editMode == 0 || Capricorn.Drawing.DAGraphics.editMode == 3)
{
undo.bgData[(y - yMin) * blockWidth + (x - xMin)] = map.Tiles[y * map.Width + x].FloorTile;
map.Tiles[y * map.Width + x].FloorTile = 1;
undo.bg = true;
}
if (Capricorn.Drawing.DAGraphics.editMode == 1 || Capricorn.Drawing.DAGraphics.editMode == 3 || Capricorn.Drawing.DAGraphics.editMode == 4)
{
undo.fglData[(y - yMin) * blockWidth + (x - xMin)] = map.Tiles[y * map.Width + x].LeftWall;
map.Tiles[y * map.Width + x].LeftWall = 0;
undo.fgl = true;
}
if (Capricorn.Drawing.DAGraphics.editMode == 2 || Capricorn.Drawing.DAGraphics.editMode == 3 || Capricorn.Drawing.DAGraphics.editMode == 4)
{
undo.fgrData[(y - yMin) * blockWidth + (x - xMin)] = map.Tiles[y * map.Width + x].RightWall;
map.Tiles[y * map.Width + x].RightWall = 0;
undo.fgr = true;
}
}
}
}
}
if (Capricorn.Drawing.DAGraphics.clickmode == 3)
{
undoBuffer.Add(undo);
}
}
panXStart = -1;
panYStart = -1;
Capricorn.Drawing.DAGraphics.selectionXStart = -1;
Capricorn.Drawing.DAGraphics.selectionYStart = -1;
Capricorn.Drawing.DAGraphics.selectionXEnd = -1;
Capricorn.Drawing.DAGraphics.selectionYEnd = -1;
Capricorn.Drawing.DAGraphics.MouseHoverX = -1;
Capricorn.Drawing.DAGraphics.MouseHoverY = -1;
panXScrollStart = -1;
panYScrollStart = -1;
prev_mx = -1;
prev_my = -1;
label5.Text = "";
RefreshMap();
}
void pictureBox1_MouseLeave(object sender, EventArgs e)
{
if ((Capricorn.Drawing.DAGraphics.clickmode == 2 || Capricorn.Drawing.DAGraphics.clickmode == 3) && Capricorn.Drawing.DAGraphics.selectionXStart != -1)
{
int sxs = Capricorn.Drawing.DAGraphics.selectionXStart;
int sys = Capricorn.Drawing.DAGraphics.selectionYStart;
int sxe = Capricorn.Drawing.DAGraphics.selectionXEnd;
int sye = Capricorn.Drawing.DAGraphics.selectionYEnd;
// set selection
int xMin = sxs < sxe ? sxs : sxe;
int yMin = sys < sye ? sys : sye;
int xMax = sxs > sxe ? sxs : sxe;
int yMax = sys > sye ? sys : sye;
Capricorn.Drawing.DAGraphics.selectionWidth = xMax - xMin + 1;
int selectionHeight = yMax - yMin + 1;
if (Capricorn.Drawing.DAGraphics.clickmode == 2)
{
Capricorn.Drawing.DAGraphics.selection = new Capricorn.Drawing.MapTile[Capricorn.Drawing.DAGraphics.selectionWidth * selectionHeight];
}
for (int y = yMin; y <= yMax; y++)
{
for (int x = xMin; x <= xMax; x++)
{
if (Capricorn.Drawing.DAGraphics.clickmode == 2)
{
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)] = new Capricorn.Drawing.MapTile(0, 0, 0);
if (x < map.Width && x >= 0 && y < map.Height && y >= 0)
{
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)].FloorTile = map.Tiles[y * map.Width + x].FloorTile;
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)].LeftWall = map.Tiles[y * map.Width + x].LeftWall;
Capricorn.Drawing.DAGraphics.selection[(y - yMin) * Capricorn.Drawing.DAGraphics.selectionWidth + (x - xMin)].RightWall = map.Tiles[y * map.Width + x].RightWall;
}
}
else
{
if (x < map.Width && x >= 0 && y < map.Height && y >= 0)
{
if (Capricorn.Drawing.DAGraphics.editMode == 0 || Capricorn.Drawing.DAGraphics.editMode == 3)
{
map.Tiles[y * map.Width + x].FloorTile = 1;
}
if (Capricorn.Drawing.DAGraphics.editMode == 1 || Capricorn.Drawing.DAGraphics.editMode == 3 || Capricorn.Drawing.DAGraphics.editMode == 4)
{
map.Tiles[y * map.Width + x].LeftWall = 0;
}
if (Capricorn.Drawing.DAGraphics.editMode == 2 || Capricorn.Drawing.DAGraphics.editMode == 3 || Capricorn.Drawing.DAGraphics.editMode == 4)
{
map.Tiles[y * map.Width + x].RightWall = 0;
}
}
}
}
}
}
panXStart = -1;
panYStart = -1;
Capricorn.Drawing.DAGraphics.selectionXStart = -1;
Capricorn.Drawing.DAGraphics.selectionYStart = -1;
Capricorn.Drawing.DAGraphics.selectionXEnd = -1;
Capricorn.Drawing.DAGraphics.selectionYEnd = -1;
Capricorn.Drawing.DAGraphics.MouseHoverX = -1;
Capricorn.Drawing.DAGraphics.MouseHoverY = -1;
panXScrollStart = -1;
panYScrollStart = -1;
prev_mx = -1;
prev_my = -1;
label5.Text = "";
RefreshMap();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (map == null)
return;
pictureBox1_MouseOver(sender, e);
//if (e.Button != MouseButtons.Left)
//return;
if (e.Button == MouseButtons.Right)
{
if (panXStart == -1)
{
panXStart = e.X;
panYStart = e.Y;
panXScrollStart = Capricorn.Drawing.DAGraphics.hscroll;
panYScrollStart = Capricorn.Drawing.DAGraphics.vscroll;
}
else
{
int xdiff = (e.X - panXStart)*2;
int ydiff = (e.Y - panYStart)*2;
Capricorn.Drawing.DAGraphics.hscroll = panXScrollStart - xdiff;