From af678bf9e11d4a470cc6301be1aa042e8ee0ad12 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 29 Jul 2020 03:18:13 +0500 Subject: [PATCH] mod buttons now disappear in a same way OW buttons do (#277) * mod buttons now disappear in a same way OW buttons do --- OWML.ModHelper.Menus/ModMainMenu.cs | 9 +++++++++ OWML.ModHelper.Menus/ModTitleButton.cs | 8 ++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/OWML.ModHelper.Menus/ModMainMenu.cs b/OWML.ModHelper.Menus/ModMainMenu.cs index 6d6ee75c1..d70e58201 100644 --- a/OWML.ModHelper.Menus/ModMainMenu.cs +++ b/OWML.ModHelper.Menus/ModMainMenu.cs @@ -3,6 +3,7 @@ using OWML.Common.Menus; using OWML.ModHelper.Events; using UnityEngine; +using UnityEngine.UI; namespace OWML.ModHelper.Menus { @@ -18,6 +19,7 @@ public class ModMainMenu : ModMenu, IModMainMenu public IModButton QuitButton { get; private set; } private TitleAnimationController _anim; + private TitleScreenManager _titleManager; public ModMainMenu(IModConsole console) : base(console) { @@ -26,6 +28,7 @@ public ModMainMenu(IModConsole console) : base(console) public void Initialize(TitleScreenManager titleScreenManager) { + _titleManager = titleScreenManager; _anim = titleScreenManager.GetComponent(); var menu = titleScreenManager.GetValue("_mainMenu"); Initialize(menu); @@ -50,6 +53,12 @@ public override IModButtonBase AddButton(IModButtonBase button, int index) group = x.Button.GetComponent() }); _anim.SetValue("_buttonFadeControllers", fadeControllers.ToArray()); + if (button is ModTitleButton titleButton) + { + var texts = _titleManager.GetValue("_mainMenuTextFields").ToList(); + texts.Add(titleButton.Text); + _titleManager.SetValue("_mainMenuTextFields", texts.ToArray()); + } return modButton; } diff --git a/OWML.ModHelper.Menus/ModTitleButton.cs b/OWML.ModHelper.Menus/ModTitleButton.cs index a03c2a27f..928909709 100644 --- a/OWML.ModHelper.Menus/ModTitleButton.cs +++ b/OWML.ModHelper.Menus/ModTitleButton.cs @@ -6,20 +6,20 @@ namespace OWML.ModHelper.Menus { public class ModTitleButton : ModButtonBase, IModButton { - private readonly Text _text; + internal Text Text { get; } public virtual string Title { - get => _text != null ? _text.text : ""; + get => Text != null ? Text.text : ""; set { Object.Destroy(Button.GetComponentInChildren()); - _text.text = value; + Text.text = value; } } public ModTitleButton(Button button, IModMenu menu) : base(button, menu) { - _text = Button.GetComponentInChildren(); + Text = Button.GetComponentInChildren(); } public new IModButton Copy()