using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Bindings.ImGui;
using HSUI.Config;
using HSUI.Config.Attributes;
using HSUI.Helpers;
namespace HSUI.Interface.GeneralElements
{
/// Stores custom keybinds for controller cross bars (8 bars × 8 slots). Format: "Key:VK_X" or "Pad:South", empty = unset.
[Exportable(false)]
[Section("Controller Hotbars", true)]
[SubSection("Keybinds", 0)]
public class ControllerBarKeybindsConfig : PluginConfigObject
{
public const int Bars = 8;
public const int SlotsPerBar = 8;
public const int TotalSlots = Bars * SlotsPerBar;
/// Index = (bar-1)*8 + slot. Value = "Key:VK_1" or "Pad:South" or "" for unset.
public List KeybindStrings { get; set; } = new List();
[ManualDraw]
public bool DrawOpenKeybindsButton(ref bool changed)
{
if (ImGui.Button("Setup controller bar keybinds", new Vector2(260, 28)))
{
ConfigurationManager.Instance?.OpenControllerBarKeybindsWindow();
return false;
}
if (ImGui.IsItemHovered())
ImGui.SetTooltip("Open the keybind setup window to assign keyboard or gamepad buttons to each slot on the controller cross bars. These keybinds are independent of the game's keybind settings.");
return false;
}
public new static ControllerBarKeybindsConfig DefaultConfig() => new ControllerBarKeybindsConfig();
/// Get keybind for bar 1-8, slot 0-7. Returns "" if unset.
public string GetKeybind(int bar, int slot)
{
int idx = (bar - 1) * SlotsPerBar + slot;
if (idx < 0 || idx >= TotalSlots) return "";
EnsureCapacity();
return KeybindStrings.ElementAtOrDefault(idx) ?? "";
}
/// Set keybind for bar 1-8, slot 0-7. Value format: "Key:VK_X" or "Pad:South", or "" to clear.
public void SetKeybind(int bar, int slot, string value)
{
int idx = (bar - 1) * SlotsPerBar + slot;
if (idx < 0 || idx >= TotalSlots) return;
EnsureCapacity();
KeybindStrings[idx] = value ?? "";
}
private void EnsureCapacity()
{
while (KeybindStrings.Count < TotalSlots)
KeybindStrings.Add("");
}
}
}