Initial Code
This commit is contained in:
27
UI/Components/ModEntryButton.cs
Normal file
27
UI/Components/ModEntryButton.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using FMODUnity;
|
||||
using UnityEngine;
|
||||
using VMM.ModRegistry;
|
||||
|
||||
namespace VMM.UI.Components
|
||||
{
|
||||
internal class ModEntryButton : MonoBehaviour
|
||||
{
|
||||
public ModEntry mod;
|
||||
|
||||
UnityEngine.UI.Button button;
|
||||
EventReference buttonPress;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
button = GetComponent<UnityEngine.UI.Button>();
|
||||
button.onClick.AddListener(ShowModInfo);
|
||||
buttonPress = VMM.Patches.MainMenuManager.GetButtonPress(global::MainMenuManager.instance);
|
||||
}
|
||||
|
||||
void ShowModInfo()
|
||||
{
|
||||
ModInfoDisplayer.Instance.UpdateModInfo(mod);
|
||||
AudioManager.instance.PlayOneShot(buttonPress, transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
UI/Components/ModInfoDisplayer.cs
Normal file
64
UI/Components/ModInfoDisplayer.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using VMM.ModRegistry;
|
||||
|
||||
namespace VMM.UI.Components
|
||||
{
|
||||
internal class ModInfoDisplayer : MonoBehaviour
|
||||
{
|
||||
internal static ModInfoDisplayer Instance;
|
||||
|
||||
internal TextMeshProUGUI modName;
|
||||
internal TextMeshProUGUI modAuthor;
|
||||
internal TextMeshProUGUI modVersion;
|
||||
internal UnityEngine.UI.Button settingsButton;
|
||||
internal ModEntry currentMod;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
settingsButton.onClick.AddListener(OnSettingsButtonPressed);
|
||||
transform.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(this);
|
||||
Core.Logger.Warning("For some reason there were two Intances of ModInfoDisplayer???");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateModInfo(ModEntry mod)
|
||||
{
|
||||
if(mod.Settings == null)
|
||||
{
|
||||
settingsButton.gameObject.SetActive(false);
|
||||
}
|
||||
else if(mod.Settings != null && !settingsButton.gameObject.activeSelf)
|
||||
{
|
||||
settingsButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
transform.gameObject.SetActive(true);
|
||||
modName.text = $"Name: {mod.Name}";
|
||||
modAuthor.text = $"Author: {mod.Author}";
|
||||
modVersion.text = $"Version: {mod.Version}";
|
||||
currentMod = mod;
|
||||
}
|
||||
|
||||
public void HandleClose()
|
||||
{
|
||||
if(gameObject.activeSelf)
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnSettingsButtonPressed()
|
||||
{
|
||||
if(currentMod == null)
|
||||
return;
|
||||
|
||||
ModSettingsManager.Instance.OpenSettings(currentMod);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
UI/Components/ModSettingsManager.cs
Normal file
73
UI/Components/ModSettingsManager.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VMM.ModRegistry;
|
||||
using VMM.ModRegistry.Settings.Types;
|
||||
using VMM.UI.Helpers;
|
||||
|
||||
namespace VMM.UI.Components
|
||||
{
|
||||
internal class ModSettingsManager : MonoBehaviour
|
||||
{
|
||||
public static ModSettingsManager Instance;
|
||||
|
||||
public TextMeshProUGUI titleText;
|
||||
|
||||
RectTransform settingsContainer;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
settingsContainer = transform.GetChild(0).GetComponent<RectTransform>();
|
||||
settingsContainer.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Core.Logger.Warning("Form some reason there's a second instance for the ModSettingsManager");
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
ClearSettings();
|
||||
}
|
||||
|
||||
void ClearSettings()
|
||||
{
|
||||
for(int i = 0; i < settingsContainer.childCount; i++)
|
||||
{
|
||||
Destroy(settingsContainer.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenSettings(ModEntry mod)
|
||||
{
|
||||
if(mod.Settings == null)
|
||||
{
|
||||
Core.Logger.Warning($"Mod '{mod.Name}' Does not Contain Any Settings");
|
||||
return;
|
||||
}
|
||||
ClearSettings();
|
||||
var settings = mod.Settings.GetAllSettings();
|
||||
if (settings != null && settings.Count() <= 0)
|
||||
{
|
||||
Core.Logger.Warning($"Settings Reference of '{mod.Name}' were found but no Settings were found inside List");
|
||||
return;
|
||||
}
|
||||
titleText.text = $"{mod.Name} Settings";
|
||||
foreach(var setting in settings)
|
||||
{
|
||||
if(setting is SliderSetting slider)
|
||||
UIBuilder.CreateSlider("Slider Setting", settingsContainer, slider.Name, slider.Max, slider.Min, slider.Value, (float value) => slider.OnChanged.Invoke(value));
|
||||
if (setting is ToggleSetting toggle)
|
||||
UIBuilder.CreateToggle("Toggle Setting", settingsContainer, toggle.Name, toggle.Value, (bool value) => toggle.OnChanged.Invoke(value));
|
||||
}
|
||||
settingsContainer.gameObject.SetActive(true);
|
||||
UIManager.Instance.OpenSettings();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
19
UI/Components/UILayoutRebuilder.cs
Normal file
19
UI/Components/UILayoutRebuilder.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace VMM.UI.Components
|
||||
{
|
||||
internal class UILayoutRebuilder : MonoBehaviour
|
||||
{
|
||||
RectTransform parentRect;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(parentRect == null)
|
||||
{
|
||||
parentRect = transform.parent.GetComponent<RectTransform>();
|
||||
}
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(parentRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user