Skip to content

Commit

Permalink
mod buttons now disappear in a same way OW buttons do (#277)
Browse files Browse the repository at this point in the history
* mod buttons now disappear in a same way OW buttons do
  • Loading branch information
TAImatem authored Jul 28, 2020
1 parent 8a44981 commit af678bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions OWML.ModHelper.Menus/ModMainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OWML.Common.Menus;
using OWML.ModHelper.Events;
using UnityEngine;
using UnityEngine.UI;

namespace OWML.ModHelper.Menus
{
Expand All @@ -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)
{
Expand All @@ -26,6 +28,7 @@ public ModMainMenu(IModConsole console) : base(console)

public void Initialize(TitleScreenManager titleScreenManager)
{
_titleManager = titleScreenManager;
_anim = titleScreenManager.GetComponent<TitleAnimationController>();
var menu = titleScreenManager.GetValue<Menu>("_mainMenu");
Initialize(menu);
Expand All @@ -50,6 +53,12 @@ public override IModButtonBase AddButton(IModButtonBase button, int index)
group = x.Button.GetComponent<CanvasGroup>()
});
_anim.SetValue("_buttonFadeControllers", fadeControllers.ToArray());
if (button is ModTitleButton titleButton)
{
var texts = _titleManager.GetValue<Text[]>("_mainMenuTextFields").ToList();
texts.Add(titleButton.Text);
_titleManager.SetValue("_mainMenuTextFields", texts.ToArray());
}
return modButton;
}

Expand Down
8 changes: 4 additions & 4 deletions OWML.ModHelper.Menus/ModTitleButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalizedText>());
_text.text = value;
Text.text = value;
}
}

public ModTitleButton(Button button, IModMenu menu) : base(button, menu)
{
_text = Button.GetComponentInChildren<Text>();
Text = Button.GetComponentInChildren<Text>();
}

public new IModButton Copy()
Expand Down

0 comments on commit af678bf

Please sign in to comment.