feat: add ui
This commit is contained in:
parent
d2228881c5
commit
d0d717a56d
|
@ -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;
|
||||
}
|
||||
|
|
12
Plugin.cs
12
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Format>()) {
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue