Skip to content

Commit

Permalink
LOCEditor - Fix resizing bug and overall errors that where occurring
Browse files Browse the repository at this point in the history
  • Loading branch information
NessieHax committed Jul 11, 2024
1 parent 384e1e2 commit 3f897be
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 85 deletions.
38 changes: 29 additions & 9 deletions PCK-Studio/Forms/Editor/LOCEditor.Designer.cs

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

51 changes: 21 additions & 30 deletions PCK-Studio/Forms/Editor/LOCEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace PckStudio.Forms.Editor
{
public partial class LOCEditor : MetroForm
{
DataTable tbl;
LOCFile currentLoc;
PckAsset _asset;

Expand All @@ -30,13 +29,6 @@ public LOCEditor(PckAsset asset)
var reader = new LOCFileReader();
currentLoc = reader.FromStream(ms);
}
tbl = new DataTable();
tbl.Columns.Add(new DataColumn("Language") { ReadOnly = true });
tbl.Columns.Add("Display Name");
dataGridViewLocEntryData.DataSource = tbl;
DataGridViewColumn column = dataGridViewLocEntryData.Columns[1];
column.Width = dataGridViewLocEntryData.Width;

saveToolStripMenuItem.Visible = !Settings.Default.AutoSaveChanges;
}

Expand All @@ -61,36 +53,39 @@ private void treeViewLocKeys_AfterSelect(object sender, TreeViewEventArgs e)

private void addDisplayIDToolStripMenuItem_Click(object sender, EventArgs e)
{
if (treeViewLocKeys.SelectedNode is TreeNode)
using (TextPrompt prompt = new TextPrompt())
using (TextPrompt prompt = new TextPrompt())
{
prompt.OKButtonText = "Add";
if (prompt.ShowDialog(this) == DialogResult.OK &&
currentLoc.AddLocKey(prompt.NewText, ""))
{
prompt.OKButtonText = "Add";
if (prompt.ShowDialog(this) == DialogResult.OK &&
!currentLoc.LocKeys.ContainsKey(prompt.NewText) &&
currentLoc.AddLocKey(prompt.NewText, ""))
{
treeViewLocKeys.Nodes.Add(prompt.NewText);
}
treeViewLocKeys.Nodes.Add(prompt.NewText);
}
}
}

private void deleteDisplayIDToolStripMenuItem_Click(object sender, EventArgs e)
{
if (treeViewLocKeys.SelectedNode is TreeNode t && currentLoc.RemoveLocKey(t.Text))
{
treeViewLocKeys.SelectedNode.Remove();
ReloadTranslationTable();
}
}

private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex != 1 ||
treeViewLocKeys.SelectedNode == null)
if (e.ColumnIndex != 1 ||
treeViewLocKeys.SelectedNode is null)
{
MessageBox.Show(this, "something went wrong");
return;
}
currentLoc.SetLocEntry(treeViewLocKeys.SelectedNode.Text, tbl.Rows[e.RowIndex][0].ToString(), tbl.Rows[e.RowIndex][1].ToString());
var row = dataGridViewLocEntryData.Rows[e.RowIndex];
string locKey = treeViewLocKeys.SelectedNode.Text;
string language = row.Cells[0].Value.ToString();
string value = row.Cells[1].Value.ToString();
currentLoc.SetLocEntry(locKey, language, value);
}

private void treeView1_KeyDown(object sender, KeyEventArgs e)
Expand All @@ -101,25 +96,21 @@ private void treeView1_KeyDown(object sender, KeyEventArgs e)

private void buttonReplaceAll_Click(object sender, EventArgs e)
{
for (int i = 0; i < tbl.Rows.Count; i++)
for (int i = 0; i < dataGridViewLocEntryData.Rows.Count; i++)
{
tbl.Rows[i][1] = textBoxReplaceAll.Text;
dataGridViewLocEntryData.Rows[i].Cells[1].Value = textBoxReplaceAll.Text;
}

currentLoc.SetLocEntry(treeViewLocKeys.SelectedNode.Text, textBoxReplaceAll.Text);
}

private void LOCEditor_Resize(object sender, EventArgs e)
{
DataGridViewColumn column = dataGridViewLocEntryData.Columns[1];
column.Width = dataGridViewLocEntryData.Width - dataGridViewLocEntryData.Columns[0].Width;
}

private void ReloadTranslationTable()
{
tbl.Rows.Clear();
dataGridViewLocEntryData.Rows.Clear();
if (treeViewLocKeys.SelectedNode is null)
return;
foreach (var l in currentLoc.GetLocEntries(treeViewLocKeys.SelectedNode.Text))
tbl.Rows.Add(l.Key, l.Value);
dataGridViewLocEntryData.Rows.Add(l.Key, l.Value);
}

private IEnumerable<string> GetAvailableLanguages()
Expand Down
Loading

0 comments on commit 3f897be

Please sign in to comment.