/* Copyright 2012 Cedric Van Goethem This file is part of AbState Editor. AbState Editor is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. AbState Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Foobar. If not, see http://www.gnu.org/licenses/. */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace ActionReader { public partial class Form1 : Form { ActionFile file; public Form1() { InitializeComponent(); } Dictionary ActID = new Dictionary(); private void Form1_Load(object sender, EventArgs e) { groupBox1.Enabled = false; } public void SetStatus(string text) { txtStatus.Text = text; } private void button1_Click(object sender, EventArgs e) { OpenFileDialog diag = new OpenFileDialog(); diag.Filter = "Action dat (*.dat)|*.dat"; diag.Title = "Select action file"; if (diag.ShowDialog() != DialogResult.OK) return; label1.Text = "Path: " + diag.FileName; file = new ActionFile(diag.FileName); ShowBlocks(); SetStatus("File opened."); } public void ShowBlocks() { listBox1.Items.Clear(); foreach (var x in file.Blocks) { listBox1.Items.Add(x); } } private void button2_Click(object sender, EventArgs e) { if (file == null) return; SaveFileDialog diag = new SaveFileDialog(); diag.Filter = "Action dat (*.dat)|*.dat"; diag.Title = "Save action file"; if (diag.ShowDialog() != DialogResult.OK) return; try { file.Save(diag.FileName); } catch (Exception ex) { SetStatus("Error while saving, report to dev: " + ex.Message); } } private void listBox1_MouseClick(object sender, MouseEventArgs e) { if (listBox1.SelectedItems.Count > 0) { groupBox1.Enabled = true; ActionBlock block = (ActionBlock)listBox1.SelectedItems[0]; txtName.Text = block.Text; txtSHNPath.Text = block.SHNPath; txtFilePath.Text = block.FilePath; nmrIntID.Value = block.ActID; txtNifanimID.Text = block.NifAnimID.ToString(); txts1.Text = block.s1; txts2.Text = block.s2; txts3.Text = block.s3; txtSound1.Text = block.Sound1; txtSound2.Text = block.Sound2; txtSig.Text = block.Signature.ToString(); groupBox1.Tag = block; } } private void button3_Click(object sender, EventArgs e) { if (txtNewName.Text == "New Action") { SetStatus("Please use another name!"); return; } if (file == null) return; ActionBlock block = new ActionBlock(); block.ActID = (short)file.Blocks.Count; block.Signature = 8; block.Text = txtNewName.Text; file.Blocks.Add(block); ShowBlocks(); } private void button4_Click(object sender, EventArgs e) { if (groupBox1.Tag == null) return; if (file == null) return; try { ActionBlock block = (ActionBlock)groupBox1.Tag; block.Text = txtName.Text; block.ActID = (short)nmrIntID.Value; block.FilePath = txtFilePath.Text; block.NifAnimID = int.Parse(txtNifanimID.Text); block.s1 = txts1.Text; block.s2 = txts2.Text; block.s3 = txts3.Text; block.SHNPath = txtSHNPath.Text; block.Signature = int.Parse(txtSig.Text); block.Sound1 = txtSound1.Text; block.Sound2 = txtSound2.Text; ShowBlocks(); SetStatus("Block edit finished."); } catch { SetStatus("Something went wrong, check all values!"); } } } }