Feature: append missing [00 FF]

This commit is contained in:
jeffman 2015-03-25 17:19:22 -04:00
parent 334ae97781
commit 01fcc837df
2 changed files with 68 additions and 11 deletions

View File

@ -56,8 +56,9 @@
this.ebSelector = new System.Windows.Forms.RadioButton();
this.m12Selector = new System.Windows.Forms.RadioButton();
this.statusBar = new System.Windows.Forms.StatusStrip();
this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.writeLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.writeTimer = new System.Windows.Forms.Timer(this.components);
this.messageLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.previewer = new ScriptToolGui.StringPreviewer();
this.mainMenu.SuspendLayout();
this.topPanel.SuspendLayout();
@ -266,6 +267,7 @@
this.m12StringEnglish.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.m12StringEnglish.Size = new System.Drawing.Size(786, 128);
this.m12StringEnglish.TabIndex = 11;
this.m12StringEnglish.MouseClick += new System.Windows.Forms.MouseEventHandler(this.m12StringEnglish_MouseClick);
//
// lineOpsPanel
//
@ -406,17 +408,18 @@
// statusBar
//
this.statusBar.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.statusLabel});
this.writeLabel,
this.messageLabel});
this.statusBar.Location = new System.Drawing.Point(0, 720);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1026, 22);
this.statusBar.TabIndex = 7;
this.statusBar.Text = "statusStrip1";
//
// statusLabel
// writeLabel
//
this.statusLabel.Name = "statusLabel";
this.statusLabel.Size = new System.Drawing.Size(0, 17);
this.writeLabel.Name = "writeLabel";
this.writeLabel.Size = new System.Drawing.Size(0, 17);
//
// writeTimer
//
@ -424,6 +427,13 @@
this.writeTimer.Interval = 10000;
this.writeTimer.Tick += new System.EventHandler(this.writeTimer_Tick);
//
// messageLabel
//
this.messageLabel.BackColor = System.Drawing.SystemColors.Highlight;
this.messageLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.messageLabel.Name = "messageLabel";
this.messageLabel.Size = new System.Drawing.Size(0, 17);
//
// previewer
//
this.previewer.AutoScroll = true;
@ -503,7 +513,7 @@
private System.Windows.Forms.RadioButton ebSelector;
private System.Windows.Forms.RadioButton m12Selector;
private System.Windows.Forms.StatusStrip statusBar;
private System.Windows.Forms.ToolStripStatusLabel statusLabel;
private System.Windows.Forms.ToolStripStatusLabel writeLabel;
private System.Windows.Forms.Timer writeTimer;
private System.Windows.Forms.Panel textBoxPanel;
private System.Windows.Forms.TextBox ebString;
@ -516,6 +526,7 @@
private System.Windows.Forms.ComboBox collectionSelector;
private System.Windows.Forms.Button previewButton;
private StringPreviewer previewer;
private System.Windows.Forms.ToolStripStatusLabel messageLabel;
}
}

View File

@ -405,8 +405,10 @@ namespace ScriptToolGui
navigationStack.Push(previousNavigationState);
}
private void SaveCurrentState()
private async void SaveCurrentState()
{
bool insertedNewLine = false;
lock (changeLock)
{
foreach (var game in validGames)
@ -415,13 +417,39 @@ namespace ScriptToolGui
{
string oldString = stringsLookup[game][currentIndex[game]];
string newString = textboxLookup[game].Text;
stringsLookup[game][currentIndex[game]] = newString;
if (game == Game.M12English && oldString != newString)
changesMade = true;
if (game == Game.M12English)
{
if (oldString != newString)
{
changesMade = true;
}
// Special case -- for M12 English, if the line is modified,
// check for an end code and insert if it's missing
if (!newString.ToUpper().EndsWith("[00 FF]")
&& !IsJustALabel(newString))
{
newString += "[00 FF]";
insertedNewLine = true;
}
}
stringsLookup[game][currentIndex[game]] = newString;
}
}
}
if (insertedNewLine)
{
await SetMessageLabel("Missing [00 FF] appended");
}
}
public static bool IsJustALabel(string str)
{
return (str.Length > 2) && (str[0] == '^') &&
(str[str.Length - 1] == '^') && !str.Skip(1).Take(str.Length - 2).Contains('^');
}
private void WriteChanges()
@ -454,7 +482,7 @@ namespace ScriptToolGui
}
else
{
statusLabel.Text = text;
writeLabel.Text = text;
}
}
@ -578,6 +606,24 @@ namespace ScriptToolGui
{
previewer.DisplayedString = m12StringEnglish.Text;
}
private void m12StringEnglish_MouseClick(object sender, MouseEventArgs e)
{
if (ModifierKeys == Keys.Control)
{
// Insert a line break
int currentSelectionStart = m12StringEnglish.SelectionStart;
m12StringEnglish.Text = m12StringEnglish.Text.Insert(m12StringEnglish.SelectionStart, "[01 FF]");
m12StringEnglish.SelectionStart = currentSelectionStart + 7;
}
}
private async Task SetMessageLabel(string message)
{
messageLabel.Text = message;
await Task.Delay(3000);
messageLabel.Text = "";
}
}
enum Game