feat: keep working on keybinds

This commit is contained in:
Anna 2024-02-18 16:31:26 -05:00
parent 65612c3ed3
commit 4b612030bd
Signed by: anna
GPG Key ID: D0943384CD9F87D1
3 changed files with 50 additions and 8 deletions

View File

@ -1,5 +1,6 @@
using System.Drawing.Imaging;
using Dalamud.Configuration;
using Dalamud.Game.ClientState.GamePad;
using Scriban;
using Scriban.Parsing;
@ -20,12 +21,14 @@ public class Configuration : IPluginConfiguration {
{{- else -}}
Main Menu or Loading Screen
{{- end -}}
{{- if area }} ({{ area }}) {{- end -}}
{{- if ward }} W{{ ward }} {{- end -}}
{{- if plot -}} P{{ plot }} {{- end -}}
""";
public GamepadButtons GamepadKeybind = GamepadButtons.L1 | GamepadButtons.Select;
private int _templateHashCode;
private Template? _template;

View File

@ -1,4 +1,6 @@
using Dalamud.IoC;
using System.Diagnostics;
using Dalamud.Game.ClientState.GamePad;
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using Screenie.Ui;
@ -56,10 +58,15 @@ public sealed class Plugin : IDalamudPlugin {
this.LinkHandlers = new LinkHandlers(this);
this.Ui = new PluginUi(this);
this.Command = new Command(this);
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;
this.Command.Dispose();
this.Ui.Dispose();
this.LinkHandlers.Dispose();
@ -70,4 +77,36 @@ public sealed class Plugin : IDalamudPlugin {
internal void SaveConfig() {
this.Interface.SavePluginConfig(this.Config);
}
internal Stopwatch GamepadKeybindTimer = new();
private GamepadButtons _buttons;
private unsafe void FrameworkUpdate(IFramework framework) {
var gamepadInput = (GamepadInput*) this.GamepadState.GamepadInputAddress;
if (this.GamepadKeybindTimer.IsRunning) {
if (this.GamepadKeybindTimer.Elapsed > TimeSpan.FromSeconds(5)) {
this._buttons = 0;
this.GamepadKeybindTimer.Reset();
return;
}
this._buttons |= (GamepadButtons) gamepadInput->ButtonsRaw;
if (gamepadInput->ButtonsRaw == 0) {
this.Config.GamepadKeybind = this._buttons;
this.SaveConfig();
this._buttons = 0;
this.GamepadKeybindTimer.Reset();
return;
}
return;
}
if (((GamepadButtons) gamepadInput->ButtonsRaw & this.Config.GamepadKeybind) != this.Config.GamepadKeybind) {
return;
}
Log.Info("pressed");
}
}

View File

@ -21,8 +21,6 @@ internal class SettingsTab : ITab {
private const int RefreshSeconds = 5;
private readonly Stopwatch _metaUpdate = Stopwatch.StartNew();
private GamepadButtons _gamepadKeybind = GamepadButtons.L1 | GamepadButtons.Select;
internal SettingsTab(Plugin plugin) {
this.Plugin = plugin;
this.FileDialogManager = new FileDialogManager();
@ -109,7 +107,7 @@ internal class SettingsTab : ITab {
var currentKeybind = new StringBuilder();
foreach (var button in Enum.GetValues<GamepadButtons>()) {
if ((this._gamepadKeybind & button) > 0) {
if ((this.Plugin.Config.GamepadKeybind & button) > 0) {
if (currentKeybind.Length > 0) {
currentKeybind.Append('+');
}
@ -120,8 +118,10 @@ internal class SettingsTab : ITab {
ImGui.TextUnformatted($"Gamepad: {currentKeybind}");
if (ImGui.Button("Change")) {
using (ImGuiHelper.WithDisabled(this.Plugin.GamepadKeybindTimer.IsRunning)) {
if (ImGui.Button("Change")) {
this.Plugin.GamepadKeybindTimer.Restart();
}
}
if (anyChanged) {