Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: moved input config.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed May 1, 2023
1 parent d5173c3 commit 1cfc28b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 72 deletions.
47 changes: 43 additions & 4 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
using Dalamud.Logging;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Xml.Linq;
using Dalamud.Game.ClientState.GamePad;
using Dalamud.Logging;

namespace RotationSolver.Basic.Configuration;

public class InputConfiguration
{
public Dictionary<StateCommandType, KeyRecord> KeyState { get; set; } = new Dictionary<StateCommandType, KeyRecord>();
public Dictionary<SpecialCommandType, KeyRecord> KeySpecial { get; set; } = new Dictionary<SpecialCommandType, KeyRecord>();
public KeyRecord KeyDoAction { get; set; } = null;
public Dictionary<StateCommandType, ButtonRecord> ButtonState { get; set; } = new Dictionary<StateCommandType, ButtonRecord>()
{
{StateCommandType.AutoTarget, new ButtonRecord( GamepadButtons.East, false, true) },
{StateCommandType.ManualTarget, new ButtonRecord( GamepadButtons.North, false, true) },
{StateCommandType.Cancel, new ButtonRecord( GamepadButtons.South, false, true) },
};
public Dictionary<SpecialCommandType, ButtonRecord> ButtonSpecial { get; set; } = new Dictionary<SpecialCommandType, ButtonRecord>()
{
{SpecialCommandType.EndSpecial, new ButtonRecord( GamepadButtons.West, false, true) },

{SpecialCommandType.EsunaStanceNorth, new ButtonRecord( GamepadButtons.DpadRight, false, true) },
{SpecialCommandType.MoveForward, new ButtonRecord( GamepadButtons.DpadUp, false, true) },
{SpecialCommandType.MoveBack, new ButtonRecord( GamepadButtons.DpadDown, false, true) },
{SpecialCommandType.RaiseShirk, new ButtonRecord( GamepadButtons.DpadLeft, false, true) },

{SpecialCommandType.DefenseArea, new ButtonRecord( GamepadButtons.North, true, false) },
{SpecialCommandType.DefenseSingle, new ButtonRecord( GamepadButtons.East, true, false) },
{SpecialCommandType.HealArea, new ButtonRecord( GamepadButtons.South, true, false) },
{SpecialCommandType.HealSingle, new ButtonRecord( GamepadButtons.West, true, false) },

{SpecialCommandType.Burst, new ButtonRecord( GamepadButtons.DpadDown, true, false) },
{SpecialCommandType.AntiKnockback, new ButtonRecord( GamepadButtons.DpadUp, true, false) },
};

public ButtonRecord ButtonDoAction { get; set; } = null;
}

public class OtherConfiguration
{
public static InputConfiguration InputConfig = new InputConfiguration();
public static SortedSet<uint> HostileCastingArea = new SortedSet<uint>();
public static SortedSet<uint> HostileCastingTank = new SortedSet<uint>();

Expand Down Expand Up @@ -36,6 +67,8 @@ public static void Init()
Task.Run(() => InitOne(ref HostileCastingArea, nameof(HostileCastingArea)));

Task.Run(() => InitOne(ref HostileCastingTank, nameof(HostileCastingTank)));

Task.Run(() => InitOne(ref InputConfig, nameof(InputConfig)));
}

public static void Save()
Expand All @@ -46,6 +79,12 @@ public static void Save()
SaveAnimationLockTime();
SaveHostileCastingArea();
SaveHostileCastingTank();
SaveInputConfig();
}

public static void SaveInputConfig()
{
Task.Run(() => Save(InputConfig, nameof(InputConfig)));
}

public static void SaveHostileCastingArea()
Expand Down
29 changes: 0 additions & 29 deletions RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,35 +203,6 @@ public class PluginConfiguration : IPluginConfiguration
public bool ShowCooldownWindow = false;
public float DistanceForMoving = 1.2f;

public Dictionary<StateCommandType, KeyRecord> KeyState { get; set; } = new Dictionary<StateCommandType, KeyRecord>();
public Dictionary<SpecialCommandType, KeyRecord> KeySpecial { get; set; } = new Dictionary<SpecialCommandType, KeyRecord>();
public KeyRecord KeyDoAction { get; set; } = null;
public Dictionary<StateCommandType, ButtonRecord> ButtonState { get; set; } = new Dictionary<StateCommandType, ButtonRecord>()
{
{StateCommandType.AutoTarget, new ButtonRecord( GamepadButtons.East, false, true) },
{StateCommandType.ManualTarget, new ButtonRecord( GamepadButtons.North, false, true) },
{StateCommandType.Cancel, new ButtonRecord( GamepadButtons.South, false, true) },
};
public Dictionary<SpecialCommandType, ButtonRecord> ButtonSpecial { get; set; } = new Dictionary<SpecialCommandType, ButtonRecord>()
{
{SpecialCommandType.EndSpecial, new ButtonRecord( GamepadButtons.West, false, true) },

{SpecialCommandType.EsunaStanceNorth, new ButtonRecord( GamepadButtons.DpadRight, false, true) },
{SpecialCommandType.MoveForward, new ButtonRecord( GamepadButtons.DpadUp, false, true) },
{SpecialCommandType.MoveBack, new ButtonRecord( GamepadButtons.DpadDown, false, true) },
{SpecialCommandType.RaiseShirk, new ButtonRecord( GamepadButtons.DpadLeft, false, true) },

{SpecialCommandType.DefenseArea, new ButtonRecord( GamepadButtons.North, true, false) },
{SpecialCommandType.DefenseSingle, new ButtonRecord( GamepadButtons.East, true, false) },
{SpecialCommandType.HealArea, new ButtonRecord( GamepadButtons.South, true, false) },
{SpecialCommandType.HealSingle, new ButtonRecord( GamepadButtons.West, true, false) },

{SpecialCommandType.Burst, new ButtonRecord( GamepadButtons.DpadDown, true, false) },
{SpecialCommandType.AntiKnockback, new ButtonRecord( GamepadButtons.DpadUp, true, false) },
};

public ButtonRecord ButtonDoAction { get; set; } = null;

public void Save()
{
Service.Interface.SavePluginConfig(this);
Expand Down
35 changes: 18 additions & 17 deletions RotationSolver/UI/ControlWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Windowing;
using ImGuiScene;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
using RotationSolver.Localization;
using RotationSolver.Updaters;
Expand Down Expand Up @@ -288,13 +289,13 @@ static void DrawCommandAction(uint iconId, StateCommandType command, Vector4 col
static string GetHelp(SpecialCommandType command)
{
var help = command.ToHelp() + "\n ";
if (Service.Config.ButtonSpecial.TryGetValue(command, out var button))
if (OtherConfiguration.InputConfig.ButtonSpecial.TryGetValue(command, out var button))
{
help += "\n" + button.ToStr();
if (!Service.Config.UseGamepadCommand) help += LocalizationManager.RightLang.ConfigWindow_Control_NeedToEnable;

}
if (Service.Config.KeySpecial.TryGetValue(command, out var key))
if (OtherConfiguration.InputConfig.KeySpecial.TryGetValue(command, out var key))
{
help += "\n" + key.ToStr();
if (!Service.Config.UseKeyboardCommand) help += LocalizationManager.RightLang.ConfigWindow_Control_NeedToEnable;
Expand All @@ -305,12 +306,12 @@ static string GetHelp(SpecialCommandType command)
static string GetHelp(StateCommandType command)
{
var help = command.ToHelp() + "\n ";
if (Service.Config.ButtonState.TryGetValue(command, out var button))
if (OtherConfiguration.InputConfig.ButtonState.TryGetValue(command, out var button))
{
help += "\n" + button.ToStr();
if (!Service.Config.UseGamepadCommand) help += LocalizationManager.RightLang.ConfigWindow_Control_NeedToEnable;
}
if (Service.Config.KeyState.TryGetValue(command, out var key))
if (OtherConfiguration.InputConfig.KeyState.TryGetValue(command, out var key))
{
help += "\n" + key.ToStr();
if (!Service.Config.UseKeyboardCommand) help += LocalizationManager.RightLang.ConfigWindow_Control_NeedToEnable;
Expand Down Expand Up @@ -357,9 +358,9 @@ static void DrawIAction(nint handle, string id, float width, SpecialCommandType

if (ImGui.IsKeyPressed(ImGuiKey.LeftCtrl) && ImGui.IsMouseDown(ImGuiMouseButton.Middle))
{
Service.Config.KeySpecial.Remove(command);
Service.Config.ButtonSpecial.Remove(command);
Service.Config.Save();
OtherConfiguration.InputConfig.KeySpecial.Remove(command);
OtherConfiguration.InputConfig.ButtonSpecial.Remove(command);
OtherConfiguration.SaveInputConfig();

Service.ToastGui.ShowQuest($"Clear Recording: {command}",
new Dalamud.Game.Gui.Toast.QuestToastOptions()
Expand Down Expand Up @@ -396,9 +397,9 @@ static void DrawIAction(nint handle, string id, float width, StateCommandType co

if (ImGui.IsKeyPressed(ImGuiKey.LeftCtrl) && ImGui.IsMouseDown(ImGuiMouseButton.Middle))
{
Service.Config.KeyState.Remove(command);
Service.Config.ButtonState.Remove(command);
Service.Config.Save();
OtherConfiguration.InputConfig.KeyState.Remove(command);
OtherConfiguration.InputConfig.ButtonState.Remove(command);
OtherConfiguration.SaveInputConfig();

Service.ToastGui.ShowQuest($"Clear Recording: {command}",
new Dalamud.Game.Gui.Toast.QuestToastOptions()
Expand Down Expand Up @@ -544,15 +545,15 @@ static unsafe void DrawNextAction(float gcd, float ability, float width)
if (ImGui.IsItemHovered())
{
var help = string.Empty;
if (Service.Config.ButtonDoAction != null)
if (OtherConfiguration.InputConfig.ButtonDoAction != null)
{
help += "\n" + Service.Config.ButtonDoAction.ToStr();
help += "\n" + OtherConfiguration.InputConfig.ButtonDoAction.ToStr();
if (!Service.Config.UseGamepadCommand) help += LocalizationManager.RightLang.ConfigWindow_Control_NeedToEnable;

}
if (Service.Config.KeyDoAction != null)
if (OtherConfiguration.InputConfig.KeyDoAction != null)
{
help += "\n" + Service.Config.KeyDoAction.ToStr();
help += "\n" + OtherConfiguration.InputConfig.KeyDoAction.ToStr();
if (!Service.Config.UseKeyboardCommand) help += LocalizationManager.RightLang.ConfigWindow_Control_NeedToEnable;
}
help += "\n \n" + LocalizationManager.RightLang.ConfigWindow_Control_ResetButtonOrKeyCommand;
Expand All @@ -571,9 +572,9 @@ static unsafe void DrawNextAction(float gcd, float ability, float width)

if (ImGui.IsKeyPressed(ImGuiKey.LeftCtrl) && ImGui.IsMouseDown(ImGuiMouseButton.Middle))
{
Service.Config.KeyDoAction = null;
Service.Config.ButtonDoAction = null;
Service.Config.Save();
OtherConfiguration.InputConfig.KeyDoAction = null;
OtherConfiguration.InputConfig.ButtonDoAction = null;
OtherConfiguration.SaveInputConfig();

Service.ToastGui.ShowQuest($"Clear Recording: Do Action",
new Dalamud.Game.Gui.Toast.QuestToastOptions()
Expand Down
45 changes: 23 additions & 22 deletions RotationSolver/Updaters/InputUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.GamePad;
using Dalamud.Game.ClientState.Keys;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;

namespace RotationSolver.Updaters;
Expand Down Expand Up @@ -86,46 +87,46 @@ private static void KeyDown(KeyRecord key)
{
if (RecordingSpecialType != SpecialCommandType.None)
{
Service.Config.KeySpecial[RecordingSpecialType] = key;
OtherConfiguration.InputConfig.KeySpecial[RecordingSpecialType] = key;
Service.ToastGui.ShowQuest($"{RecordingSpecialType}: {key.ToStr()}",
QUEST);

RecordingSpecialType = SpecialCommandType.None;
Service.Config.Save();
OtherConfiguration.SaveInputConfig();
return;
}
else if (RecordingStateType != StateCommandType.None )
{
Service.Config.KeyState[RecordingStateType] = key;
OtherConfiguration.InputConfig.KeyState[RecordingStateType] = key;
Service.ToastGui.ShowQuest($"{RecordingStateType}: {key.ToStr()}",
QUEST);

RecordingStateType = StateCommandType.None;
Service.Config.Save();
OtherConfiguration.SaveInputConfig();
return;
}
else if (RecordingDoAction)
{
Service.Config.KeyDoAction = key;
OtherConfiguration.InputConfig.KeyDoAction = key;
Service.ToastGui.ShowQuest($"Do Action: {key.ToStr()}", QUEST);
RecordingDoAction = false;
Service.Config.Save();
OtherConfiguration.SaveInputConfig();
return;
}

if (!Service.Config.UseKeyboardCommand) return;

if (Service.Config.KeyState.ContainsValue(key))
if (OtherConfiguration.InputConfig.KeyState.ContainsValue(key))
{
Service.CommandManager.ProcessCommand(Service.Config.KeyState
Service.CommandManager.ProcessCommand(OtherConfiguration.InputConfig.KeyState
.FirstOrDefault(k => k.Value == key && k.Key != StateCommandType.None).Key.GetCommandStr());
}
else if (Service.Config.KeySpecial.ContainsValue(key))
else if (OtherConfiguration.InputConfig.KeySpecial.ContainsValue(key))
{
Service.CommandManager.ProcessCommand(Service.Config.KeySpecial
Service.CommandManager.ProcessCommand(OtherConfiguration.InputConfig.KeySpecial
.FirstOrDefault(k => k.Value == key && k.Key != SpecialCommandType.None).Key.GetCommandStr());
}
else if(Service.Config.KeyDoAction == key)
else if(OtherConfiguration.InputConfig.KeyDoAction == key)
{
RSCommands.DoAction();
}
Expand All @@ -135,46 +136,46 @@ private static void ButtonDown(ButtonRecord button)
{
if (RecordingSpecialType != SpecialCommandType.None)
{
Service.Config.ButtonSpecial[RecordingSpecialType] = button;
OtherConfiguration.InputConfig.ButtonSpecial[RecordingSpecialType] = button;
Service.ToastGui.ShowQuest($"{RecordingSpecialType}: {button.ToStr()}",
QUEST);

RecordingSpecialType = SpecialCommandType.None;
Service.Config.Save();
OtherConfiguration.SaveInputConfig();
return;
}
else if (RecordingStateType != StateCommandType.None)
{
Service.Config.ButtonState[RecordingStateType] = button;
OtherConfiguration.InputConfig.ButtonState[RecordingStateType] = button;
Service.ToastGui.ShowQuest($"{RecordingStateType}: {button.ToStr()}",
QUEST);

RecordingStateType = StateCommandType.None;
Service.Config.Save();
OtherConfiguration.SaveInputConfig();
return;
}
else if (RecordingDoAction)
{
Service.Config.ButtonDoAction = button;
OtherConfiguration.InputConfig.ButtonDoAction = button;
Service.ToastGui.ShowQuest($"Do Action: {button.ToStr()}", QUEST);
RecordingDoAction = false;
Service.Config.Save();
OtherConfiguration.SaveInputConfig();
return;
}

if (!Service.Config.UseGamepadCommand) return;

if (Service.Config.ButtonState.ContainsValue(button))
if (OtherConfiguration.InputConfig.ButtonState.ContainsValue(button))
{
Service.CommandManager.ProcessCommand(Service.Config.ButtonState
Service.CommandManager.ProcessCommand(OtherConfiguration.InputConfig.ButtonState
.FirstOrDefault(k => k.Value == button && k.Key != StateCommandType.None).Key.GetCommandStr());
}
else if (Service.Config.ButtonSpecial.ContainsValue(button))
else if (OtherConfiguration.InputConfig.ButtonSpecial.ContainsValue(button))
{
Service.CommandManager.ProcessCommand(Service.Config.ButtonSpecial
Service.CommandManager.ProcessCommand(OtherConfiguration.InputConfig.ButtonSpecial
.FirstOrDefault(k => k.Value == button && k.Key != SpecialCommandType.None).Key.GetCommandStr());
}
else if (Service.Config.ButtonDoAction == button)
else if (OtherConfiguration.InputConfig.ButtonDoAction == button)
{
RSCommands.DoAction();
}
Expand Down

0 comments on commit 1cfc28b

Please sign in to comment.