feat: add keyboard keybinds
This commit is contained in:
parent
12996e5ea3
commit
9f86f7fecb
|
@ -1,6 +1,7 @@
|
|||
using System.Drawing.Imaging;
|
||||
using Dalamud.Configuration;
|
||||
using Dalamud.Game.ClientState.GamePad;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using Scriban;
|
||||
using Scriban.Parsing;
|
||||
|
||||
|
@ -28,6 +29,7 @@ public class Configuration : IPluginConfiguration {
|
|||
""";
|
||||
|
||||
public GamepadButtons GamepadKeybind = GamepadButtons.L1 | GamepadButtons.Start;
|
||||
public List<SeVirtualKey> KeyboardKeybind = [SeVirtualKey.PRINT];
|
||||
public bool DisableNativeScreenshots = true;
|
||||
|
||||
private int _templateHashCode;
|
||||
|
|
75
Plugin.cs
75
Plugin.cs
|
@ -8,6 +8,7 @@ using Dalamud.Game.Text.SeStringHandling.Payloads;
|
|||
using Dalamud.IoC;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using Newtonsoft.Json;
|
||||
using Screenie.Ui;
|
||||
using WebP.Net;
|
||||
|
@ -74,7 +75,7 @@ public sealed class Plugin : IDalamudPlugin {
|
|||
this.Framework!.Update += this.FrameworkUpdate;
|
||||
}
|
||||
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
public void Dispose() {
|
||||
this.Framework!.Update -= this.FrameworkUpdate;
|
||||
|
@ -91,17 +92,71 @@ public sealed class Plugin : IDalamudPlugin {
|
|||
this.Interface.SavePluginConfig(this.Config);
|
||||
}
|
||||
|
||||
internal Stopwatch GamepadKeybindTimer = new();
|
||||
internal readonly Stopwatch GamepadKeybindTimer = new();
|
||||
internal readonly Stopwatch KeyboardKeybindTimer = new();
|
||||
private GamepadButtons _buttons;
|
||||
private readonly HashSet<SeVirtualKey> _kb = [];
|
||||
private bool _pressAck;
|
||||
private unsafe void FrameworkUpdate(IFramework framework) {
|
||||
private void FrameworkUpdate(IFramework framework) {
|
||||
var gamepad = this.IsGamepadPressed();
|
||||
var keyboard = this.IsKeyboardPressed();
|
||||
|
||||
if (gamepad || keyboard) {
|
||||
this.SaveScreenshot();
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe bool IsKeyboardPressed() {
|
||||
var input = UIInputData.Instance();
|
||||
|
||||
if (this.KeyboardKeybindTimer.IsRunning) {
|
||||
if (this.KeyboardKeybindTimer.Elapsed > TimeSpan.FromSeconds(5)) {
|
||||
this._kb.Clear();
|
||||
this.KeyboardKeybindTimer.Reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
var anyDown = false;
|
||||
foreach (var button in Enum.GetValues<SeVirtualKey>()) {
|
||||
if (input->IsKeyDown(button)) {
|
||||
anyDown = true;
|
||||
this._kb.Add(button);
|
||||
}
|
||||
}
|
||||
|
||||
if (!anyDown && this._kb.Count > 0) {
|
||||
this.Config.KeyboardKeybind = [.. this._kb.OrderBy(k => k)];
|
||||
this.SaveConfig();
|
||||
this._kb.Clear();
|
||||
this.KeyboardKeybindTimer.Reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.Config.KeyboardKeybind.All(input->IsKeyDown)) {
|
||||
this._pressAck = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._pressAck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._pressAck = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private unsafe bool IsGamepadPressed() {
|
||||
var gamepadInput = (GamepadInput*) this.GamepadState.GamepadInputAddress;
|
||||
|
||||
if (this.GamepadKeybindTimer.IsRunning) {
|
||||
if (this.GamepadKeybindTimer.Elapsed > TimeSpan.FromSeconds(5)) {
|
||||
this._buttons = 0;
|
||||
this.GamepadKeybindTimer.Reset();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
this._buttons |= (GamepadButtons) gamepadInput->ButtonsRaw;
|
||||
|
@ -111,25 +166,23 @@ public sealed class Plugin : IDalamudPlugin {
|
|||
this.SaveConfig();
|
||||
this._buttons = 0;
|
||||
this.GamepadKeybindTimer.Reset();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (((GamepadButtons) gamepadInput->ButtonsRaw & this.Config.GamepadKeybind) != this.Config.GamepadKeybind) {
|
||||
this._pressAck = false;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._pressAck) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
this._pressAck = true;
|
||||
|
||||
Log.Info("pressed");
|
||||
this.SaveScreenshot();
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void SaveScreenshot() {
|
||||
|
|
|
@ -105,11 +105,40 @@ internal class SettingsTab : ITab {
|
|||
new Vector2(-1, 1)
|
||||
);
|
||||
|
||||
this.DrawGamepadKeybind();
|
||||
|
||||
anyChanged |= ImGui.Checkbox("Disable vanilla in-game screenshots", ref this.Plugin.Config.DisableNativeScreenshots);
|
||||
|
||||
if (anyChanged) {
|
||||
this.Plugin.SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawKeyboardKeybind() {
|
||||
var currentKeybind = new StringBuilder();
|
||||
foreach (var button in this.Plugin.Config.KeyboardKeybind) {
|
||||
if (currentKeybind.Length > 0) {
|
||||
currentKeybind.Append(" + ");
|
||||
}
|
||||
|
||||
currentKeybind.Append(Enum.GetName(button));
|
||||
}
|
||||
|
||||
ImGui.TextUnformatted($"Keyboard: {currentKeybind}");
|
||||
|
||||
using (ImGuiHelper.WithDisabled(this.Plugin.KeyboardKeybindTimer.IsRunning)) {
|
||||
if (ImGui.Button("Change##kb-keybind")) {
|
||||
this.Plugin.KeyboardKeybindTimer.Restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGamepadKeybind() {
|
||||
var currentKeybind = new StringBuilder();
|
||||
foreach (var button in Enum.GetValues<GamepadButtons>()) {
|
||||
if ((this.Plugin.Config.GamepadKeybind & button) > 0) {
|
||||
if (currentKeybind.Length > 0) {
|
||||
currentKeybind.Append('+');
|
||||
currentKeybind.Append(" + ");
|
||||
}
|
||||
|
||||
currentKeybind.Append(Enum.GetName(button));
|
||||
|
@ -119,16 +148,10 @@ internal class SettingsTab : ITab {
|
|||
ImGui.TextUnformatted($"Gamepad: {currentKeybind}");
|
||||
|
||||
using (ImGuiHelper.WithDisabled(this.Plugin.GamepadKeybindTimer.IsRunning)) {
|
||||
if (ImGui.Button("Change")) {
|
||||
if (ImGui.Button("Change##gp-keybind")) {
|
||||
this.Plugin.GamepadKeybindTimer.Restart();
|
||||
}
|
||||
}
|
||||
|
||||
anyChanged |= ImGui.Checkbox("Disable vanilla in-game screenshots", ref this.Plugin.Config.DisableNativeScreenshots);
|
||||
|
||||
if (anyChanged) {
|
||||
this.Plugin.SaveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private bool DrawScreenshotsFolderInput() {
|
||||
|
|
Loading…
Reference in New Issue