Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions Config/UI/NModListButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public partial class NModListButton : NButton
private readonly Color _bgHover = new(0.15f, 0.15f, 0.15f, 0.5f);
private readonly Color _bgPressed = new(0.2f, 0.2f, 0.2f, 0.7f);

private TextureRect? _controllerIconRect;
// NButton has _hotkeyIcon, but it's fairly tightly coupled to having one hotkey per button; we need multiple
// buttons that share a hotkey, one at a time, so we create our own instance.
private NHotkeyIcon _customHotkeyIcon;
private readonly StringName _targetHotkey = MegaInput.cancel;
private bool _isHotkeyIconVisible = false;

public NModListButton(string modName)
Expand Down Expand Up @@ -78,26 +81,23 @@ public NModListButton(string modName)

AddChild(_label);

const float size = 48;
_controllerIconRect = new TextureRect
{
CustomMinimumSize = Vector2.One * size,
Size = Vector2.One * size,
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize,
StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered,
Visible = false
};
AddChild(_controllerIconRect);
_controllerIconRect.SetAnchorsPreset(LayoutPreset.CenterRight);
_controllerIconRect.Position = new Vector2(-size, -size/2);
const float iconSize = 48;
var iconScene = PreloadManager.Cache.GetAsset<PackedScene>(SceneHelper.GetScenePath("ui/hotkey_icon"));

_customHotkeyIcon = iconScene.Instantiate<NHotkeyIcon>();
_customHotkeyIcon.CustomMinimumSize = Vector2.One * iconSize;
_customHotkeyIcon.Size = Vector2.One * iconSize;
_customHotkeyIcon.Visible = false;
_customHotkeyIcon.SetAnchorsPreset(LayoutPreset.CenterRight);
_customHotkeyIcon.Position = new Vector2(-iconSize, -iconSize / 2);

AddChild(_customHotkeyIcon);
}

public override void _Ready()
{
ConnectSignals();

UpdateVisualState(instant: true);

if (NControllerManager.Instance != null)
{
NControllerManager.Instance.Connect(NControllerManager.SignalName.MouseDetected,
Expand All @@ -109,6 +109,7 @@ public override void _Ready()
}

RefreshIconVisibility();
UpdateVisualState(instant: true);
}

public void SetHotkeyIconVisible(bool enabled)
Expand All @@ -119,13 +120,11 @@ public void SetHotkeyIconVisible(bool enabled)

private void RefreshIconVisibility()
{
if (_controllerIconRect == null) return;

var isController = NControllerManager.Instance?.IsUsingButtonInputsCompatibility() ?? false;
_controllerIconRect.Visible = _isHotkeyIconVisible && isController;
var isDirectionNavActive = NControllerManager.Instance?.IsUsingDirectionalNavigation ?? false;
_customHotkeyIcon.Visible = _isHotkeyIconVisible && isDirectionNavActive;

if (_controllerIconRect.Visible)
_controllerIconRect.Texture = NInputManager.Instance?.GetHotkeyIcon(MegaInput.cancel);
if (_customHotkeyIcon.Visible)
_customHotkeyIcon.UpdateInput(_targetHotkey);
}

public void SetActiveState(bool isActive)
Expand Down