Skip to content

Commit

Permalink
Added file Open Dialog and Drag&Drop support
Browse files Browse the repository at this point in the history
  • Loading branch information
SD authored and SD committed Nov 12, 2020
1 parent b33192a commit 28c7a00
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
17 changes: 15 additions & 2 deletions T2Tools/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 47 additions & 6 deletions T2Tools/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@ public MainForm()
sectionsPanel.DoubleBuffered(true);
imgPage.DoubleBuffered(true);

createHexEditor();
createHexEditor();
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(MainForm_DragEnter);
this.DragDrop += new DragEventHandler(MainForm_DragDrop);
}
void MainForm_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

void MainForm_DragDrop(object sender, DragEventArgs e) {
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
this.initForm(files[0]); // open first file
}

private void MainForm_Load(object sender, EventArgs e)
{
this.initForm("../../../game/T2.exe");
}
private void initForm(string filename)
{
#if DEBUG
game = new Game("../../../game/T2.exe");
game = new Game(filename);
#else
game = new Game("T2.exe");
#endif
Expand All @@ -49,9 +64,12 @@ private void MainForm_Load(object sender, EventArgs e)
return;
}

this.Text = "Turrican II Tools - " + filename;

tilemapMaker = new TilemapMaker(game.Assets);

// fill TOC list
fileList.Items.Clear();
foreach (var entry in game.Assets.Entries.Values)
{
fileList.Items.Add(new TOCListItem(entry));
Expand Down Expand Up @@ -122,7 +140,6 @@ private void fileSelected(TOCListItem item)
bitmapControlsPanel.Visible = false;
updateImagePreview();
break;

case TOCEntryType.AnimatedSprite:
BOBFile bobFile = new BOBFile(item.Entry.Data);
BOBDecoder decoder = new BOBDecoder();
Expand Down Expand Up @@ -201,9 +218,9 @@ private void fileSelected(TOCListItem item)

case TOCEntryType.PixelFont:
case TOCEntryType.Sound:
case TOCEntryType.DIR:
case TOCEntryType.DAT:
case TOCEntryType.Executable:
case TOCEntryType.DAT:
case TOCEntryType.DIR:
case TOCEntryType.Unknown:
default:
break;
Expand Down Expand Up @@ -544,8 +561,32 @@ private void saveTilesetButton_Click(object sender, EventArgs e)
tilesPictureBox.Image.Save(saveImageDialog.FileName);
}


#endregion


private void openButton_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
//InitialDirectory = @"D:\",
Title = "Browse Turrican EXE files",

CheckFileExists = true,
CheckPathExists = true,

DefaultExt = "exe",
Filter = "Executables (*.exe)|*.exe",
FilterIndex = 2,
RestoreDirectory = true,

ReadOnlyChecked = true,
ShowReadOnly = true
};

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
this.initForm(openFileDialog1.FileName) ;
}
}
}
}

0 comments on commit 28c7a00

Please sign in to comment.