Skip to content

Commit 39122d2

Browse files
authored
Merge pull request #1 from stefl0n/master
Added file Open Dialog and Drag&Drop support
2 parents b33192a + 28c7a00 commit 39122d2

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

T2Tools/MainForm.Designer.cs

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

T2Tools/MainForm.cs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,28 @@ public MainForm()
3232
sectionsPanel.DoubleBuffered(true);
3333
imgPage.DoubleBuffered(true);
3434

35-
createHexEditor();
35+
createHexEditor();
36+
this.AllowDrop = true;
37+
this.DragEnter += new DragEventHandler(MainForm_DragEnter);
38+
this.DragDrop += new DragEventHandler(MainForm_DragDrop);
39+
}
40+
void MainForm_DragEnter(object sender, DragEventArgs e) {
41+
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
42+
}
43+
44+
void MainForm_DragDrop(object sender, DragEventArgs e) {
45+
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
46+
this.initForm(files[0]); // open first file
3647
}
3748

3849
private void MainForm_Load(object sender, EventArgs e)
50+
{
51+
this.initForm("../../../game/T2.exe");
52+
}
53+
private void initForm(string filename)
3954
{
4055
#if DEBUG
41-
game = new Game("../../../game/T2.exe");
56+
game = new Game(filename);
4257
#else
4358
game = new Game("T2.exe");
4459
#endif
@@ -49,9 +64,12 @@ private void MainForm_Load(object sender, EventArgs e)
4964
return;
5065
}
5166

67+
this.Text = "Turrican II Tools - " + filename;
68+
5269
tilemapMaker = new TilemapMaker(game.Assets);
5370

5471
// fill TOC list
72+
fileList.Items.Clear();
5573
foreach (var entry in game.Assets.Entries.Values)
5674
{
5775
fileList.Items.Add(new TOCListItem(entry));
@@ -122,7 +140,6 @@ private void fileSelected(TOCListItem item)
122140
bitmapControlsPanel.Visible = false;
123141
updateImagePreview();
124142
break;
125-
126143
case TOCEntryType.AnimatedSprite:
127144
BOBFile bobFile = new BOBFile(item.Entry.Data);
128145
BOBDecoder decoder = new BOBDecoder();
@@ -201,9 +218,9 @@ private void fileSelected(TOCListItem item)
201218

202219
case TOCEntryType.PixelFont:
203220
case TOCEntryType.Sound:
221+
case TOCEntryType.DIR:
222+
case TOCEntryType.DAT:
204223
case TOCEntryType.Executable:
205-
case TOCEntryType.DAT:
206-
case TOCEntryType.DIR:
207224
case TOCEntryType.Unknown:
208225
default:
209226
break;
@@ -544,8 +561,32 @@ private void saveTilesetButton_Click(object sender, EventArgs e)
544561
tilesPictureBox.Image.Save(saveImageDialog.FileName);
545562
}
546563

564+
547565
#endregion
548566

549-
567+
private void openButton_Click(object sender, EventArgs e)
568+
{
569+
OpenFileDialog openFileDialog1 = new OpenFileDialog
570+
{
571+
//InitialDirectory = @"D:\",
572+
Title = "Browse Turrican EXE files",
573+
574+
CheckFileExists = true,
575+
CheckPathExists = true,
576+
577+
DefaultExt = "exe",
578+
Filter = "Executables (*.exe)|*.exe",
579+
FilterIndex = 2,
580+
RestoreDirectory = true,
581+
582+
ReadOnlyChecked = true,
583+
ShowReadOnly = true
584+
};
585+
586+
if (openFileDialog1.ShowDialog() == DialogResult.OK)
587+
{
588+
this.initForm(openFileDialog1.FileName) ;
589+
}
590+
}
550591
}
551592
}

0 commit comments

Comments
 (0)