mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Update gamemodes info panel to show mod icon
This commit is contained in:
1 parent
cd97fab3a2
commit
0141dfdea4
4 files changed
+84
-8
No files matched your search
@@ -3,9 +3,11 @@ using BepInEx.Configuration;
|
|||||||
using BepInEx.Unity.IL2CPP;
|
using BepInEx.Unity.IL2CPP;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor;
|
using Reactor;
|
||||||
using Reactor.Networking;
|
using Reactor.Networking;
|
||||||
using Reactor.Networking.Attributes;
|
using Reactor.Networking.Attributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Example;
|
namespace MiraAPI.Example;
|
||||||
|
|
||||||
@@ -18,6 +20,7 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
|||||||
{
|
{
|
||||||
public Harmony Harmony { get; } = new(Id);
|
public Harmony Harmony { get; } = new(Id);
|
||||||
public string OptionsTitleText => "Mira API\nExample Mod";
|
public string OptionsTitleText => "Mira API\nExample Mod";
|
||||||
|
public LoadableAsset<Sprite>? ModIcon => ExampleAssets.ExampleButton;
|
||||||
public ConfigFile GetConfigFile() => Config;
|
public ConfigFile GetConfigFile() => Config;
|
||||||
public override void Load()
|
public override void Load()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
|
|
||||||
@@ -76,6 +77,16 @@ public static class CustomGameModeManager
|
|||||||
/// <returns>The gamemode matching that ID.</returns>
|
/// <returns>The gamemode matching that ID.</returns>
|
||||||
public static AbstractGameMode GetMode(uint id) => IdToModeMap[id];
|
public static AbstractGameMode GetMode(uint id) => IdToModeMap[id];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Finds the parent mod of a custom gamemode.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameMode">The <see cref="AbstractGameMode"/> object.</param>
|
||||||
|
/// <returns>A <see cref="MiraPluginInfo"/> object representing the parent mod of the gamemode.</returns>
|
||||||
|
public static MiraPluginInfo? FindParentMod(AbstractGameMode gameMode)
|
||||||
|
{
|
||||||
|
return MiraPluginManager.Instance.RegisteredPlugins.FirstOrDefault(plugin => plugin.GameModes.ContainsValue(gameMode));
|
||||||
|
}
|
||||||
|
|
||||||
internal static void RegisterDefaultMode()
|
internal static void RegisterDefaultMode()
|
||||||
{
|
{
|
||||||
var defaultMode = new ClassicMode();
|
var defaultMode = new ClassicMode();
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ internal static class GameOptionsMenuPatch
|
|||||||
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<OptionBehaviour>> _gameModeOptions = new();
|
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<OptionBehaviour>> _gameModeOptions = new();
|
||||||
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<CategoryHeaderMasked>> _gameModeHeaders = new();
|
private static System.Collections.Generic.Dictionary<AbstractGameMode, System.Collections.Generic.List<CategoryHeaderMasked>> _gameModeHeaders = new();
|
||||||
private static TextMeshPro _gamemodeDescription = null!;
|
private static TextMeshPro _gamemodeDescription = null!;
|
||||||
|
private static SpriteRenderer _modIcon = null!;
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(nameof(GameOptionsMenu.Initialize))]
|
[HarmonyPatch(nameof(GameOptionsMenu.Initialize))]
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
@@ -84,6 +86,30 @@ internal static class GameOptionsMenuPatch
|
|||||||
{
|
{
|
||||||
instance.Children.Add(opt);
|
instance.Children.Add(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mod = CustomGameModeManager.FindParentMod(gameMode);
|
||||||
|
if (mod is { MiraPlugin.ModIcon: not null })
|
||||||
|
{
|
||||||
|
_modIcon.gameObject.SetActive(true);
|
||||||
|
_gamemodeDescription.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||||
|
_gamemodeDescription.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||||
|
var texture = mod.MiraPlugin.ModIcon.LoadAsset().texture;
|
||||||
|
var newSprite = Sprite.Create(
|
||||||
|
texture,
|
||||||
|
new Rect(0, 0, 128, 128),
|
||||||
|
Vector2.one / 2,
|
||||||
|
100
|
||||||
|
);
|
||||||
|
_modIcon.sprite = newSprite;
|
||||||
|
_modIcon.drawMode = SpriteDrawMode.Sliced;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gamemodeDescription.transform.localPosition = new Vector3(0f, 0, -0.01f);
|
||||||
|
_gamemodeDescription.horizontalAlignment = HorizontalAlignmentOptions.Center;
|
||||||
|
_modIcon.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
_gamemodeDescription.text = gameMode.Description;
|
_gamemodeDescription.text = gameMode.Description;
|
||||||
if (gameMode.ShowNormalGameSettings)
|
if (gameMode.ShowNormalGameSettings)
|
||||||
{
|
{
|
||||||
@@ -155,6 +181,8 @@ internal static class GameOptionsMenuPatch
|
|||||||
}
|
}
|
||||||
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void CreateSettings(GameOptionsMenu instance, Transform container)
|
private static void CreateSettings(GameOptionsMenu instance, Transform container)
|
||||||
{
|
{
|
||||||
float num = 0.713f;
|
float num = 0.713f;
|
||||||
@@ -197,16 +225,43 @@ internal static class GameOptionsMenuPatch
|
|||||||
GameModeOption.Values.ElementAt(i).Value);
|
GameModeOption.Values.ElementAt(i).Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, Vector3.zero, Quaternion.identity, container);
|
var modeInfoHolder = new GameObject("GamemodeInfo")
|
||||||
gamemodeTextObj.transform.localPosition = new Vector3(1, -0.675f, -2f);
|
{
|
||||||
gamemodeTextObj.transform.localScale = new Vector3(2.6f, 2.6f, 1);
|
transform =
|
||||||
|
{
|
||||||
|
parent = container,
|
||||||
|
localPosition = new Vector3(1.2f, -0.675f, 1),
|
||||||
|
localScale = Vector3.one,
|
||||||
|
},
|
||||||
|
layer = container.gameObject.layer,
|
||||||
|
}.transform;
|
||||||
|
|
||||||
|
var gamemodeBg = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(0).gameObject, Vector3.zero, Quaternion.identity, modeInfoHolder);
|
||||||
|
gamemodeBg.transform.localPosition = Vector3.zero;
|
||||||
|
gamemodeBg.transform.localScale = new Vector3(1.35f, 0.85f, 1);
|
||||||
|
gamemodeBg.name = "Background";
|
||||||
|
|
||||||
|
var modIconObj = new GameObject("ModIcon")
|
||||||
|
{
|
||||||
|
transform =
|
||||||
|
{
|
||||||
|
parent = modeInfoHolder,
|
||||||
|
localPosition = new Vector3(-1.75f, 0, -0.1f),
|
||||||
|
localScale = new Vector3(0.4f, 0.4f, 1),
|
||||||
|
},
|
||||||
|
layer = gamemodeBg.layer,
|
||||||
|
};
|
||||||
|
_modIcon = modIconObj.AddComponent<SpriteRenderer>();
|
||||||
|
_modIcon.sprite = MiraAssets.BlankSprite.LoadAsset();
|
||||||
|
|
||||||
|
var gamemodeTextObj = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(1).gameObject, Vector3.zero, Quaternion.identity, modeInfoHolder);
|
||||||
|
gamemodeTextObj.transform.localPosition = new Vector3(0.3f, 0, -0.01f);
|
||||||
|
gamemodeTextObj.transform.localScale = new Vector3(2.12f, 2.12f, 1);
|
||||||
_gamemodeDescription = gamemodeTextObj.GetComponentInChildren<TextMeshPro>();
|
_gamemodeDescription = gamemodeTextObj.GetComponentInChildren<TextMeshPro>();
|
||||||
_gamemodeDescription.fontSizeMin = 0.5f;
|
_gamemodeDescription.fontSizeMin = 0.65f;
|
||||||
_gamemodeDescription.fontSizeMax = 1;
|
_gamemodeDescription.fontSizeMax = 0.9f;
|
||||||
|
_gamemodeDescription.alignment = TextAlignmentOptions.Left;
|
||||||
|
|
||||||
var gamemodeBg = Object.Instantiate(GameModeOption.OptionBehaviour.transform.GetChild(0).gameObject, Vector3.zero, Quaternion.identity, gamemodeTextObj.transform);
|
|
||||||
gamemodeBg.transform.localPosition = new Vector3(0, 0, 0.01f);
|
|
||||||
gamemodeBg.transform.localScale = new Vector3(0.61f, 0.375f, 1);
|
|
||||||
num -= 1.3f;
|
num -= 1.3f;
|
||||||
AdditionalVanillaScrollNum = 0f;
|
AdditionalVanillaScrollNum = 0f;
|
||||||
foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories)
|
foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
|
using MiraAPI.Utilities.Assets;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.PluginLoading;
|
namespace MiraAPI.PluginLoading;
|
||||||
|
|
||||||
@@ -52,6 +54,11 @@ public interface IMiraPlugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual string CustomOptionMenuTwoDescription => "Apply game settings for this mod!";
|
public virtual string CustomOptionMenuTwoDescription => "Apply game settings for this mod!";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the icon of the mod.
|
||||||
|
/// </summary>
|
||||||
|
public virtual LoadableAsset<Sprite>? ModIcon => null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="ConfigFile"/> for the plugin.
|
/// Gets the <see cref="ConfigFile"/> for the plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in new issue
Block a user