feat: add autotranslate qol features
Allow using Ctrl+# to select the first 10 results. Allow pressing Enter to select the first result. Fix the Escape key not closing the autotranslate window. Increase the window size.
This commit is contained in:
parent
13d2e7be2d
commit
7fdc1d75ff
6
ChatTwo/Resources/Language.Designer.cs
generated
6
ChatTwo/Resources/Language.Designer.cs
generated
@ -812,5 +812,11 @@ namespace ChatTwo.Resources {
|
|||||||
return ResourceManager.GetString("Options_SortAutoTranslate_Description", resourceCulture);
|
return ResourceManager.GetString("Options_SortAutoTranslate_Description", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string AutoTranslate_Completion_Key {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("AutoTranslate_Completion_Key", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -506,4 +506,7 @@
|
|||||||
<data name="Options_SortAutoTranslate_Description" xml:space="preserve">
|
<data name="Options_SortAutoTranslate_Description" xml:space="preserve">
|
||||||
<value>If this is enabled, the Auto Translate list will be sorted alphabetically.</value>
|
<value>If this is enabled, the Auto Translate list will be sorted alphabetically.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="AutoTranslate_Completion_Key" xml:space="preserve">
|
||||||
|
<value>Ctrl + {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
@ -962,7 +962,7 @@ internal sealed class ChatLog : IUiComponent {
|
|||||||
this._autoCompleteOpen = false;
|
this._autoCompleteOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.SetNextWindowSize(new Vector2(350, 250) * ImGuiHelpers.GlobalScale);
|
ImGui.SetNextWindowSize(new Vector2(400, 300) * ImGuiHelpers.GlobalScale);
|
||||||
if (!ImGui.BeginPopup(AutoCompleteId)) {
|
if (!ImGui.BeginPopup(AutoCompleteId)) {
|
||||||
if (this._activatePos == -1) {
|
if (this._activatePos == -1) {
|
||||||
this._activatePos = this._autoCompleteInfo.EndPos;
|
this._activatePos = this._autoCompleteInfo.EndPos;
|
||||||
@ -979,6 +979,31 @@ internal sealed class ChatLog : IUiComponent {
|
|||||||
this._autoCompleteList = AutoTranslate.Matching(this.Ui.Plugin.DataManager, this._autoCompleteInfo.ToComplete, this.Ui.Plugin.Config.SortAutoTranslate);
|
this._autoCompleteList = AutoTranslate.Matching(this.Ui.Plugin.DataManager, this._autoCompleteInfo.ToComplete, this.Ui.Plugin.Config.SortAutoTranslate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selected = -1;
|
||||||
|
if (ImGui.IsItemActive() && ImGui.GetIO().KeyCtrl) {
|
||||||
|
for (var i = 0; i < 10 && i < this._autoCompleteList.Count; i++) {
|
||||||
|
var num = (i + 1) % 10;
|
||||||
|
var key = (int) VirtualKey.KEY_0 + num;
|
||||||
|
var key2 = (int) VirtualKey.NUMPAD0 + num;
|
||||||
|
if (ImGui.IsKeyDown(key) || ImGui.IsKeyDown(key2)) {
|
||||||
|
selected = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemDeactivated()) {
|
||||||
|
if (ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Escape))) {
|
||||||
|
ImGui.CloseCurrentPopup();
|
||||||
|
goto End;
|
||||||
|
}
|
||||||
|
|
||||||
|
var enter = ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.Enter))
|
||||||
|
|| ImGui.IsKeyDown(ImGui.GetKeyIndex(ImGuiKey.KeyPadEnter));
|
||||||
|
if (this._autoCompleteList.Count > 0 && enter) {
|
||||||
|
selected = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui.IsWindowAppearing()) {
|
if (ImGui.IsWindowAppearing()) {
|
||||||
this._fixCursor = true;
|
this._fixCursor = true;
|
||||||
ImGui.SetKeyboardFocusHere();
|
ImGui.SetKeyboardFocusHere();
|
||||||
@ -992,7 +1017,19 @@ internal sealed class ChatLog : IUiComponent {
|
|||||||
for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
for (var i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) {
|
||||||
var entry = this._autoCompleteList[i];
|
var entry = this._autoCompleteList[i];
|
||||||
|
|
||||||
if (!ImGui.Selectable($"{entry.String}##{entry.Group}/{entry.Row}")) {
|
var clicked = ImGui.Selectable($"{entry.String}##{entry.Group}/{entry.Row}") || selected == i;
|
||||||
|
|
||||||
|
if (i < 10) {
|
||||||
|
var button = (i + 1) % 10;
|
||||||
|
var text = string.Format(Language.AutoTranslate_Completion_Key, button);
|
||||||
|
var size = ImGui.CalcTextSize(text);
|
||||||
|
ImGui.SameLine(ImGui.GetContentRegionAvail().X - size.X);
|
||||||
|
ImGui.PushStyleColor(ImGuiCol.Text, *ImGui.GetStyleColorVec4(ImGuiCol.TextDisabled));
|
||||||
|
ImGui.TextUnformatted(text);
|
||||||
|
ImGui.PopStyleColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clicked) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,6 +1046,7 @@ internal sealed class ChatLog : IUiComponent {
|
|||||||
ImGui.EndChild();
|
ImGui.EndChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
End:
|
||||||
ImGui.EndPopup();
|
ImGui.EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user