Add Keybind icons for custom buttons

This commit is contained in:
WanderingPixel authored and GitHub committed 2025-08-09 22:12:15 +01:00
1 parent 01fa1f0915
commit 513be01c02
3 files changed
+21 -1

No files matched your search

+16 -1
View File
@@ -1,11 +1,14 @@
using System;
using System.Globalization;
using System.Linq;
using MiraAPI.Events;
using MiraAPI.Events.Mira;
using MiraAPI.Keybinds;
using MiraAPI.Patches;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using Rewired;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
@@ -120,6 +123,11 @@ public abstract class CustomActionButton
/// </summary>
public ActionButton? Button { get; set; }
/// <summary>
/// Gets the gameObject used for the keybind icon.
/// </summary>
public GameObject KeybindIcon { get; set; }
/// <summary>
/// The method used to create the button.
/// </summary>
@@ -191,6 +199,13 @@ public abstract class CustomActionButton
}
}
}));
KeybindIcon = Object.Instantiate(Button.usesRemainingSprite.gameObject, Button.transform);
KeybindIcon.GetComponent<SpriteRenderer>().sprite = MiraAssets.KeybindButton.LoadAsset();
KeybindIcon.transform.GetChild(0).GetComponent<TextMeshPro>().text =
KeybindManager.GetEntries().First(x => x.Id == $"{Name}_Keybind").Key.ToString();
KeybindIcon.name = "KeybindIcon";
KeybindIcon.transform.localPosition = new(0.341f, 0.374f, -0.1f);
}
/// <summary>
@@ -558,4 +573,4 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
Target = null;
SetOutline(false);
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

+5
View File
@@ -94,4 +94,9 @@ public static class MiraAssets
/// Gets the white CategoryHeader used in the Settings Menu.
/// </summary>
public static LoadableResourceAsset CategoryHeader { get; } = new("MiraAPI.Resources.CategoryHeader.png");
/// <summary>
/// Gets the sprite used for the Keybind icons.
/// </summary>
public static LoadableResourceAsset KeybindButton { get; } = new("MiraAPI.Resources.KeybindButton.png");
}