Skip to content

Commit

Permalink
Menu-framework (#65)
Browse files Browse the repository at this point in the history
* traverse menus and buttons
* lots of methods and events
  • Loading branch information
amazingalek authored Jan 18, 2020
1 parent 198712e commit 9862542
Show file tree
Hide file tree
Showing 28 changed files with 629 additions and 178 deletions.
4 changes: 3 additions & 1 deletion OWML.Common/IModHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace OWML.Common
using OWML.Common.Menus;

namespace OWML.Common
{
public interface IModHelper
{
Expand Down
11 changes: 0 additions & 11 deletions OWML.Common/IModMenu.cs

This file was deleted.

8 changes: 0 additions & 8 deletions OWML.Common/IModMenus.cs

This file was deleted.

32 changes: 32 additions & 0 deletions OWML.Common/Menus/IModButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using UnityEngine.UI;

namespace OWML.Common.Menus
{
public interface IModButton
{
event Action OnClick;
string Title { get; set; }
int Index { get; set; }
Button Button { get; }
void Initialize(IModMenu menu);

IModButton Copy();
IModButton Copy(string title);
IModButton Copy(int index);
IModButton Copy(string title, int index);

IModButton Duplicate();
IModButton Duplicate(string title);
IModButton Duplicate(int index);
IModButton Duplicate(string title, int index);

IModButton Replace();
IModButton Replace(string title);
IModButton Replace(int index);
IModButton Replace(string title, int index);

void Show();
void Hide();
}
}
16 changes: 16 additions & 0 deletions OWML.Common/Menus/IModMainMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace OWML.Common.Menus
{
public interface IModMainMenu : IModMenu
{
IModTabbedMenu OptionsMenu { get; }

IModButton ResumeExpeditionButton { get; }
IModButton NewExpeditionButton { get; }
IModButton OptionsButton { get; }
IModButton ViewCreditsButton { get; }
IModButton SwitchProfileButton { get; }
IModButton QuitButton { get; }

void Initialize(TitleScreenManager titleScreenManager);
}
}
22 changes: 22 additions & 0 deletions OWML.Common/Menus/IModMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using UnityEngine.UI;

namespace OWML.Common.Menus
{
public interface IModMenu
{
event Action OnInit;

Menu Menu { get; }
List<IModButton> Buttons { get; }
IModButton GetButton(string title);
void AddButton(IModButton button);
void AddButton(IModButton button, int index);

[Obsolete("Use Buttons instead")]
List<Button> GetButtons();
[Obsolete("Use button.Duplicate instead")]
Button AddButton(string title, int index);
}
}
8 changes: 8 additions & 0 deletions OWML.Common/Menus/IModMenus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OWML.Common.Menus
{
public interface IModMenus
{
IModMainMenu MainMenu { get; }
IModPauseMenu PauseMenu { get; }
}
}
13 changes: 13 additions & 0 deletions OWML.Common/Menus/IModPauseMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace OWML.Common.Menus
{
public interface IModPauseMenu : IModPopupMenu
{
IModTabbedMenu OptionsMenu { get; }

IModButton ResumeButton { get; }
IModButton OptionsButton { get; }
IModButton QuitButton { get; }

void Initialize(SettingsManager settingsManager);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using System;

namespace OWML.Common
namespace OWML.Common.Menus
{
public interface IModPopupMenu : IModMenu
{
Action OnOpen { get; set; }
Action OnClose { get; set; }
Action OnInit { get; set; }

bool IsOpen { get; }
string Title { get; set; }

void Open();
void Close();
void Toggle();

IModPopupMenu Copy();
IModPopupMenu Copy(string title);
void Initialize(Menu menu);

[Obsolete("Use Copy instead")]
IModPopupMenu CreateCopy(string name);
}
}
7 changes: 7 additions & 0 deletions OWML.Common/Menus/IModTabMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OWML.Common.Menus
{
public interface IModTabMenu : IModPopupMenu
{
void Initialize(TabButton tabButton);
}
}
15 changes: 15 additions & 0 deletions OWML.Common/Menus/IModTabbedMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace OWML.Common.Menus
{
public interface IModTabbedMenu : IModPopupMenu
{
IModTabMenu GameplayTab { get; }
IModTabMenu AudioTab { get; }
IModTabMenu InputTab { get; }
IModTabMenu GraphicsTab { get; }

new IModTabbedMenu Copy();

void Initialize(TabbedMenu menu);
new TabbedMenu Menu { get; }
}
}
11 changes: 8 additions & 3 deletions OWML.Common/OWML.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,22 @@
<Compile Include="IHarmonyHelper.cs" />
<Compile Include="IModAssets.cs" />
<Compile Include="IModAsset.cs" />
<Compile Include="Menus\IModButton.cs" />
<Compile Include="IModConfig.cs" />
<Compile Include="IModData.cs" />
<Compile Include="IModPopupMenu.cs" />
<Compile Include="Menus\IModMainMenu.cs" />
<Compile Include="Menus\IModPauseMenu.cs" />
<Compile Include="Menus\IModTabbedMenu.cs" />
<Compile Include="Menus\IModPopupMenu.cs" />
<Compile Include="Menus\IModTabMenu.cs" />
<Compile Include="IOwmlConfig.cs" />
<Compile Include="IModEvents.cs" />
<Compile Include="IModFinder.cs" />
<Compile Include="IModHelper.cs" />
<Compile Include="IModConsole.cs" />
<Compile Include="IModBehaviour.cs" />
<Compile Include="IModMenu.cs" />
<Compile Include="IModMenus.cs" />
<Compile Include="Menus\IModMenu.cs" />
<Compile Include="Menus\IModMenus.cs" />
<Compile Include="IModLogger.cs" />
<Compile Include="IModManifest.cs" />
<Compile Include="IModStorage.cs" />
Expand Down
2 changes: 1 addition & 1 deletion OWML.Launcher/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OWML.Launcher
{
public class App
{
private const string Version = "0.3.29";
private const string Version = "0.3.30";

private readonly IOwmlConfig _owmlConfig;
private readonly IModConsole _writer;
Expand Down
145 changes: 145 additions & 0 deletions OWML.ModHelper.Menus/ModButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using System;
using OWML.Common.Menus;
using UnityEngine;
using UnityEngine.UI;

namespace OWML.ModHelper.Menus
{
public class ModButton : IModButton
{
public event Action OnClick;

public Button Button { get; }
public IModMenu Menu { get; private set; }

private readonly Text _text;
public string Title
{
get => _text.text;
set => _text.text = value;
}

private int _index;
public int Index
{
get => Button.transform.parent == null ? _index : Button.transform.GetSiblingIndex();
set
{
_index = value;
Button.transform.SetSiblingIndex(value);
}
}

public ModButton(Button button, IModMenu menu)
{
Button = button;
Button.onClick.AddListener(() => OnClick?.Invoke());
_text = Button.GetComponentInChildren<Text>();
Initialize(menu);
}

public void Initialize(IModMenu menu)
{
Menu = menu;
}

public IModButton Copy()
{
var button = GameObject.Instantiate(Button);
GameObject.Destroy(button.GetComponent<SubmitAction>());
GameObject.Destroy(button.GetComponentInChildren<LocalizedText>());
return new ModButton(button, Menu)
{
Index = Index + 1
};
}

public IModButton Copy(string title)
{
var copy = Copy();
copy.Title = title;
return copy;
}

public IModButton Copy(int index)
{
var copy = Copy();
copy.Index = index;
return copy;
}

public IModButton Copy(string title, int index)
{
var copy = Copy(title);
copy.Index = index;
return copy;
}

public IModButton Duplicate()
{
var copy = Copy();
Menu.AddButton(copy);
return copy;
}

public IModButton Duplicate(string title)
{
var dupe = Duplicate();
dupe.Title = title;
return dupe;
}

public IModButton Duplicate(int index)
{
var dupe = Duplicate();
dupe.Index = index;
return dupe;
}

public IModButton Duplicate(string title, int index)
{
var dupe = Duplicate(title);
dupe.Index = index;
return dupe;
}

public IModButton Replace()
{
var duplicate = Duplicate();
Hide();
return duplicate;
}

public IModButton Replace(string title)
{
var replacement = Replace();
replacement.Title = title;
return replacement;
}

public IModButton Replace(int index)
{
var replacement = Replace();
replacement.Index = index;
return replacement;
}

public IModButton Replace(string title, int index)
{
var replacement = Replace(title);
replacement.Index = index;
return replacement;
}

public void Show()
{
Button.gameObject.SetActive(true);
}

public void Hide()
{
Button.gameObject.SetActive(false);
}

}
}
Loading

0 comments on commit 9862542

Please sign in to comment.