Skip to content

Commit

Permalink
Use the customized voice name immediately.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyfish committed Jun 15, 2024
1 parent af8fc1a commit 8b2f8ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions EditAliasesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public EditAliasesForm(string stratagemName)
private void okButton_Click(object sender, EventArgs e)
{
StratagemManager.SetUserAlias(_stratagemName, userAliasesTextBox.Text.Trim());
DialogResult = DialogResult.OK;
Close();
}

private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
6 changes: 4 additions & 2 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ private void InitStratagemGroups()
stratagem.CheckBox = stratagemCheckBox;
root.Controls.Add(stratagemCheckBox);

stratagemCheckBox.MouseUp += (_, args) =>
stratagemCheckBox.MouseUp += async (_, args) =>
{
switch (args.Button)
{
Expand All @@ -457,7 +457,9 @@ private void InitStratagemGroups()
break;
}
case MouseButtons.Right:
new EditAliasesForm(stratagemCheckBox.Text).ShowDialog();
var result = new EditAliasesForm(stratagemCheckBox.Text).ShowDialog();
if (result == DialogResult.OK)
await ResetVoiceCommand();
break;
}
};
Expand Down
20 changes: 15 additions & 5 deletions StratagemManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private static void LoadStratagems()
private static void LoadUserAliases()
{
_userAliasesDictionary.Clear();
_userAliasStratagemDictionary.Clear();

if (!File.Exists(UserAliasesFile))
return;
Expand All @@ -88,12 +87,22 @@ private static void LoadUserAliases()
if (items.Length != 2)
throw new InvalidOperationException($"Invalid line: {line}");

if (!TryGet(items[0], out var stratagem))
continue;

_userAliasesDictionary[items[0]] = items[1];
}

UpdateUserAliases();
}

private static void UpdateUserAliases()
{
_userAliasStratagemDictionary.Clear();

foreach (var (name, aliasesString) in _userAliasesDictionary)
{
if (!TryGet(name, out var stratagem))
continue;

var aliases = items[1].Split('|').Where(item => item != "");
var aliases = aliasesString.Split('|').Where(item => item != "");
foreach (var alias in aliases)
_userAliasStratagemDictionary[alias] = stratagem;
}
Expand Down Expand Up @@ -135,6 +144,7 @@ public static void SetUserAlias(string stratagemName, string alias)
else
_userAliasesDictionary[stratagemName] = alias;

UpdateUserAliases();
SaveUserAliases();
}
}

0 comments on commit 8b2f8ae

Please sign in to comment.