diff --git a/Photographer.cs b/Photographer.cs index 7c169e6..c4e9e7a 100644 --- a/Photographer.cs +++ b/Photographer.cs @@ -12,7 +12,8 @@ internal static class Photographer { HWND window = default; // last param could be "FINAL FANTASY XIV", but name is changeable while (!(window = PInvoke.FindWindowEx(default, window, "FFXIVGAME", null)).IsNull) { - var windowProc = PInvoke.GetWindowThreadProcessId(window); + var windowProc = 0u; + _ = PInvoke.GetWindowThreadProcessId(window, &windowProc); if (windowProc == 0) { continue; } diff --git a/Plugin.cs b/Plugin.cs index 407b85e..a0bed2b 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -1,6 +1,7 @@ using Dalamud.IoC; using Dalamud.Plugin; using Dalamud.Plugin.Services; +using Screenie.Ui; namespace Screenie; @@ -20,19 +21,22 @@ public class Plugin : IDalamudPlugin { internal IFramework Framework { get; init; } internal Configuration Config { get; } + internal PluginUi Ui { get; } private Command Command { get; } public Plugin() { this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); + this.Ui = new PluginUi(this); this.Command = new Command(this); } + public void Dispose() { + this.Command.Dispose(); + this.Ui.Dispose(); + } + internal void SaveConfig() { this.Interface.SavePluginConfig(this.Config); } - - public void Dispose() { - this.Command.Dispose(); - } } diff --git a/Ui/PluginUi.cs b/Ui/PluginUi.cs new file mode 100644 index 0000000..72ce768 --- /dev/null +++ b/Ui/PluginUi.cs @@ -0,0 +1,101 @@ +using System.Numerics; +using Dalamud.Interface; +using Dalamud.Interface.Components; +using Dalamud.Interface.ImGuiFileDialog; +using Dalamud.Interface.Utility; +using ImGuiNET; +using Screenie.Util; + +namespace Screenie.Ui; + +internal class PluginUi : IDisposable { + private Plugin Plugin { get; } + private FileDialogManager FileDialogManager { get; } + + internal PluginUi(Plugin plugin) { + this.Plugin = plugin; + this.FileDialogManager = new FileDialogManager(); + + this.Plugin.Interface.UiBuilder.Draw += this.Draw; + } + + public void Dispose() { + this.Plugin.Interface.UiBuilder.Draw -= this.Draw; + } + + private void Draw() { + try { + this.FileDialogManager.Draw(); + } catch (Exception e) { + Plugin.Log.Error(e, "Error in FileDialogManager.Draw"); + } + + using var end = new OnDispose(ImGui.End); + + ImGui.SetNextWindowSize(new Vector2(350, 500), ImGuiCond.FirstUseEver); + if (!ImGui.Begin(Plugin.Name)) { + return; + } + + var anyChanged = false; + anyChanged |= this.DrawScreenshotsFolderInput(); + + ImGui.SetNextItemWidth(-1); + if (ImGui.BeginCombo("##file-format", Enum.GetName(this.Plugin.Config.SaveFormat))) { + using var endCombo = new OnDispose(ImGui.EndCombo); + foreach (var format in Enum.GetValues()) { + if (ImGui.Selectable(Enum.GetName(format), this.Plugin.Config.SaveFormat == format)) { + this.Plugin.Config.SaveFormat = format; + anyChanged = true; + } + } + } + + var label = this.Plugin.Config.SaveFormat switch { + Format.Jpg => "Quality", + Format.Webp => "Quality", + Format.Png => "Compression level", + _ => "Unknown", + }; + + ImGui.TextUnformatted(label); + ImGui.SetNextItemWidth(-1); + anyChanged |= ImGui.SliderInt("##format-data", ref this.Plugin.Config.SaveFormatData, 0, 100); + + if (anyChanged) { + this.Plugin.SaveConfig(); + } + } + + private bool DrawScreenshotsFolderInput() { + ImGui.TextUnformatted("Screenshots folder"); + + var changed = false; + ImGui.PushFont(UiBuilder.IconFont); + Vector2 size; + using (new OnDispose(ImGui.PopFont)) { + size = ImGuiHelpers.GetButtonSize(FontAwesomeIcon.Folder.ToIconString()); + } + + var availWidth = ImGui.GetContentRegionAvail().X; + ImGui.SetNextItemWidth(availWidth - size.X - ImGui.GetStyle().ItemSpacing.X); + if (ImGui.InputText("##save-directory", ref this.Plugin.Config.SaveDirectory, 1024, ImGuiInputTextFlags.EnterReturnsTrue)) { + changed = true; + } + + ImGui.SameLine(); + + if (ImGuiComponents.IconButton(FontAwesomeIcon.Folder)) { + this.FileDialogManager.OpenFolderDialog("Choose screenshots folder", (b, s) => { + if (!b) { + return; + } + + this.Plugin.Config.SaveDirectory = s; + this.Plugin.SaveConfig(); + }); + } + + return changed; + } +}