Merge pull request #566 from daemitus/ime1

feat: coloring and row/page numbering for IME
This commit is contained in:
goaaats 2021-09-14 20:53:26 +02:00 committed by GitHub
commit b9d8a2f207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 33 deletions

View file

@ -37,13 +37,18 @@ namespace Dalamud.Game.Gui.Internal
/// </summary> /// </summary>
internal bool IsEnabled { get; private set; } internal bool IsEnabled { get; private set; }
/// <summary>
/// Gets the index of the first imm candidate in relation to the full list.
/// </summary>
internal CandidateList ImmCandNative { get; private set; } = default;
/// <summary> /// <summary>
/// Gets the imm candidates. /// Gets the imm candidates.
/// </summary> /// </summary>
internal List<string> ImmCand { get; private set; } = new(); internal List<string> ImmCand { get; private set; } = new();
/// <summary> /// <summary>
/// Gets the imm component. /// Gets the selected imm component.
/// </summary> /// </summary>
internal string ImmComp { get; private set; } = string.Empty; internal string ImmComp { get; private set; } = string.Empty;
@ -110,22 +115,25 @@ namespace Dalamud.Game.Gui.Internal
return 0; return 0;
var size = ImmGetCandidateListW(hIMC, 0, IntPtr.Zero, 0); var size = ImmGetCandidateListW(hIMC, 0, IntPtr.Zero, 0);
if (size > 0) if (size == 0)
{ break;
var candlistPtr = Marshal.AllocHGlobal((int)size); var candlistPtr = Marshal.AllocHGlobal((int)size);
size = ImmGetCandidateListW(hIMC, 0, candlistPtr, (uint)size); size = ImmGetCandidateListW(hIMC, 0, candlistPtr, (uint)size);
var candlist = Marshal.PtrToStructure<CandidateList>(candlistPtr); var candlist = this.ImmCandNative = Marshal.PtrToStructure<CandidateList>(candlistPtr);
var pageSize = candlist.PageSize; var pageSize = candlist.PageSize;
var candCount = candlist.Count; var candCount = candlist.Count;
if (pageSize > 0 && candCount > 1) if (pageSize > 0 && candCount > 1)
{ {
var dwOffsets = new int[candCount]; var dwOffsets = new int[candCount];
for (var i = 0; i < candCount; i++) for (var i = 0; i < candCount; i++)
{
dwOffsets[i] = Marshal.ReadInt32(candlistPtr + ((i + 6) * sizeof(int))); dwOffsets[i] = Marshal.ReadInt32(candlistPtr + ((i + 6) * sizeof(int)));
}
var pageStart = candlist.PageStart; var pageStart = candlist.PageStart;
// var pageEnd = pageStart + pageSize;
var cand = new string[pageSize]; var cand = new string[pageSize];
this.ImmCand.Clear(); this.ImmCand.Clear();
@ -150,7 +158,6 @@ namespace Dalamud.Game.Gui.Internal
this.ImmCand.Add(candStr); this.ImmCand.Add(candStr);
} }
} }
}
Marshal.FreeHGlobal(candlistPtr); Marshal.FreeHGlobal(candlistPtr);
} }
@ -158,12 +165,16 @@ namespace Dalamud.Game.Gui.Internal
break; break;
case IMECommand.OpenCandidate: case IMECommand.OpenCandidate:
this.ToggleWindow(true); this.ToggleWindow(true);
this.ImmCandNative = default;
this.ImmCand.Clear(); this.ImmCand.Clear();
break; break;
case IMECommand.CloseCandidate: case IMECommand.CloseCandidate:
this.ToggleWindow(false); this.ToggleWindow(false);
this.ImmCandNative = default;
this.ImmCand.Clear(); this.ImmCand.Clear();
break; break;
default: default:
break; break;
} }
@ -188,6 +199,7 @@ namespace Dalamud.Game.Gui.Internal
io.AddInputCharactersUTF8(lpstr); io.AddInputCharactersUTF8(lpstr);
this.ImmComp = string.Empty; this.ImmComp = string.Empty;
this.ImmCandNative = default;
this.ImmCand.Clear(); this.ImmCand.Clear();
this.ToggleWindow(false); this.ToggleWindow(false);
} }

View file

@ -1,6 +1,7 @@
using System.Numerics; using System.Numerics;
using Dalamud.Game.Gui.Internal; using Dalamud.Game.Gui.Internal;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing; using Dalamud.Interface.Windowing;
using ImGuiNET; using ImGuiNET;
@ -11,11 +12,13 @@ namespace Dalamud.Interface.Internal.Windows
/// </summary> /// </summary>
internal class IMEWindow : Window internal class IMEWindow : Window
{ {
private const int ImePageSize = 9;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IMEWindow"/> class. /// Initializes a new instance of the <see cref="IMEWindow"/> class.
/// </summary> /// </summary>
public IMEWindow() public IMEWindow()
: base("Dalamud IME", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoFocusOnAppearing) : base("Dalamud IME", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.AlwaysAutoResize)
{ {
this.Size = new Vector2(100, 200); this.Size = new Vector2(100, 200);
this.SizeCondition = ImGuiCond.FirstUseEver; this.SizeCondition = ImGuiCond.FirstUseEver;
@ -37,10 +40,30 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.Text(ime.ImmComp); ImGui.Text(ime.ImmComp);
ImGui.Separator(); ImGui.Separator();
var native = ime.ImmCandNative;
for (var i = 0; i < ime.ImmCand.Count; i++) for (var i = 0; i < ime.ImmCand.Count; i++)
{ {
var selected = i == (native.Selection % ImePageSize);
if (selected)
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen);
ImGui.Text($"{i + 1}. {ime.ImmCand[i]}"); ImGui.Text($"{i + 1}. {ime.ImmCand[i]}");
}
if (selected)
ImGui.PopStyleColor();
}
var totalIndex = native.Selection + 1;
var totalSize = native.Count;
var pageStart = native.PageStart;
var pageIndex = (pageStart / ImePageSize) + 1;
var pageCount = (totalSize / ImePageSize) + 1;
ImGui.Separator();
ImGui.Text($"{totalIndex}/{totalSize} ({pageIndex}/{pageCount})");
} }
} }
} }