Skip to content

Commit

Permalink
Backward Combatibility fix (#194)
Browse files Browse the repository at this point in the history
* I hate it, but it works

Co-authored-by: Aleksander Waage <[email protected]>
  • Loading branch information
TAImatem and amazingalek authored Jul 13, 2020
1 parent 6a47c19 commit bcd2b16
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 94 deletions.
18 changes: 9 additions & 9 deletions OWML.Common/Menus/IModButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

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

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

IModButton Duplicate();
IModButton Duplicate(int index);

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

IModButton Replace(string title);
IModButton Replace(string title, int index);
void Show();
void Hide();
}
Expand Down
26 changes: 26 additions & 0 deletions OWML.Common/Menus/IModButtonBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using UnityEngine.UI;

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

IModButtonBase Copy();
IModButtonBase Copy(int index);

IModButtonBase Duplicate();
IModButtonBase Duplicate(int index);

IModButtonBase Replace();
IModButtonBase Replace(int index);

void Show();
void Hide();
}
}
2 changes: 1 addition & 1 deletion OWML.Common/Menus/IModFieldInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface IModFieldInput<T> : IModInput<T>
{
IModTitleButton Button { get; }
IModButton Button { get; }
}
}
2 changes: 1 addition & 1 deletion OWML.Common/Menus/IModLayoutButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace OWML.Common.Menus
{
public interface IModLayoutButton : IModButton
public interface IModLayoutButton : IModButtonBase
{
IModLayoutManager Layout { get; }
}
Expand Down
11 changes: 7 additions & 4 deletions OWML.Common/Menus/IModMainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
{
public interface IModMainMenu : IModOWMenu
{
IModTitleButton ResumeExpeditionButton { get; }
IModTitleButton NewExpeditionButton { get; }
IModTitleButton ViewCreditsButton { get; }
IModTitleButton SwitchProfileButton { get; }
new IModTabbedMenu OptionsMenu { get; }
new IModButton OptionsButton { get; }
new IModButton QuitButton { get; }
IModButton ResumeExpeditionButton { get; }
IModButton NewExpeditionButton { get; }
IModButton ViewCreditsButton { get; }
IModButton SwitchProfileButton { get; }

void Initialize(TitleScreenManager titleScreenManager);
}
Expand Down
8 changes: 5 additions & 3 deletions OWML.Common/Menus/IModMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ public interface IModMenu

Menu Menu { get; }

List<IModButtonBase> BaseButtons { get; }
List<IModButton> Buttons { get; }
List<IModTitleButton> TitleButtons { get; }
List<IModLayoutButton> LayoutButtons { get; }
List<IModPromptButton> PromptButtons { get; }

[Obsolete("Use GetTitleButton instead")]
IModTitleButton GetButton(string title);
IModTitleButton GetTitleButton(string title);
IModButton GetButton(string title);
IModButton GetTitleButton(string title);
IModPromptButton GetPromptButton(string title);

IModButton AddButton(IModButton button);
IModButton AddButton(IModButton button, int index);
IModButtonBase AddButton(IModButtonBase button);
IModButtonBase AddButton(IModButtonBase button, int index);

List<IModToggleInput> ToggleInputs { get; }
IModToggleInput GetToggleInput(string title);
Expand Down
4 changes: 2 additions & 2 deletions OWML.Common/Menus/IModOWMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public interface IModOWMenu : IModMenu
{
IModTabbedMenu OptionsMenu { get; }
IModTitleButton OptionsButton { get; }
IModTitleButton QuitButton { get; }
IModButton OptionsButton { get; }
IModButton QuitButton { get; }
}
}
5 changes: 4 additions & 1 deletion OWML.Common/Menus/IModPauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
{
public interface IModPauseMenu : IModPopupMenu, IModOWMenu
{
IModTitleButton ResumeButton { get; }
new IModTabbedMenu OptionsMenu { get; }
new IModButton OptionsButton { get; }
new IModButton QuitButton { get; }
IModButton ResumeButton { get; }

void Initialize(SettingsManager settingsManager);
}
Expand Down
2 changes: 1 addition & 1 deletion OWML.Common/Menus/IModPromptButton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace OWML.Common.Menus
{
public interface IModPromptButton : IModTitleButton
public interface IModPromptButton : IModButton
{
string DefaultTitle { get; }
ScreenPrompt Prompt { get; set; }
Expand Down
17 changes: 0 additions & 17 deletions OWML.Common/Menus/IModTitleButton.cs

This file was deleted.

4 changes: 2 additions & 2 deletions OWML.Common/Menus/IModToggleInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public interface IModToggleInput : IModInput<bool>
{
TwoButtonToggleElement Toggle { get; }
IModTitleButton YesButton { get; }
IModTitleButton NoButton { get; }
IModButton YesButton { get; }
IModButton NoButton { get; }
IModToggleInput Copy();
IModToggleInput Copy(string key);
}
Expand Down
4 changes: 2 additions & 2 deletions OWML.Common/OWML.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
<Compile Include="Menus\IModInputCombinationMenu.cs" />
<Compile Include="Menus\IModInputCombinationElement.cs" />
<Compile Include="Menus\IModConfigMenuBase.cs" />
<Compile Include="Menus\IModButton.cs" />
<Compile Include="Menus\IModButtonBase.cs" />
<Compile Include="Menus\IModLayoutButton.cs" />
<Compile Include="Menus\IModComboInput.cs" />
<Compile Include="Menus\IModOWMenu.cs" />
<Compile Include="Menus\IModPromptButton.cs" />
<Compile Include="Menus\InputType.cs" />
<Compile Include="Menus\IModTitleButton.cs" />
<Compile Include="Menus\IModButton.cs" />
<Compile Include="IModConfig.cs" />
<Compile Include="IModData.cs" />
<Compile Include="Menus\IModConfigMenu.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

Expand All @@ -27,19 +27,19 @@ public int Index

private readonly UIStyleApplier _uIStyleApplier;

protected ModButton(Button button, IModMenu menu)
protected ModButtonBase(Button button, IModMenu menu)
{
_uIStyleApplier = button.GetComponent<UIStyleApplier>();
Button = button;
Button.onClick.AddListener(() => OnClick?.Invoke());
Initialize(menu);
}

public IModButton Copy()
public IModButtonBase Copy()
{
var button = Object.Instantiate(Button);
Object.Destroy(button.GetComponent<SubmitAction>());
var modButton = (IModButton)Activator.CreateInstance(GetType(), button, Menu);
var modButton = (IModButtonBase)Activator.CreateInstance(GetType(), button, Menu);
modButton.Index = Index + 1;
return modButton;
}
Expand All @@ -49,35 +49,35 @@ public void Initialize(IModMenu menu)
Menu = menu;
}

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

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

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

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

public IModButton Replace(int index)
public IModButtonBase Replace(int index)
{
var replacement = Replace();
replacement.Index = index;
Expand Down
2 changes: 1 addition & 1 deletion OWML.ModHelper.Menus/ModFieldInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OWML.ModHelper.Menus
{
public abstract class ModFieldInput<T> : ModPopupInput<T>, IModFieldInput<T>
{
public IModTitleButton Button { get; }
public IModButton Button { get; }

protected readonly IModInputMenu InputMenu;

Expand Down
2 changes: 1 addition & 1 deletion OWML.ModHelper.Menus/ModLayoutButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace OWML.ModHelper.Menus
{
public class ModLayoutButton : ModButton, IModLayoutButton
public class ModLayoutButton : ModButtonBase, IModLayoutButton
{
public IModLayoutManager Layout { get; }

Expand Down
16 changes: 8 additions & 8 deletions OWML.ModHelper.Menus/ModMainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class ModMainMenu : ModMenu, IModMainMenu
{
public IModTabbedMenu OptionsMenu { get; }

public IModTitleButton ResumeExpeditionButton { get; private set; }
public IModTitleButton NewExpeditionButton { get; private set; }
public IModTitleButton OptionsButton { get; private set; }
public IModTitleButton ViewCreditsButton { get; private set; }
public IModTitleButton SwitchProfileButton { get; private set; }
public IModTitleButton QuitButton { get; private set; }
public IModButton ResumeExpeditionButton { get; private set; }
public IModButton NewExpeditionButton { get; private set; }
public IModButton OptionsButton { get; private set; }
public IModButton ViewCreditsButton { get; private set; }
public IModButton SwitchProfileButton { get; private set; }
public IModButton QuitButton { get; private set; }

private TitleAnimationController _anim;

Expand All @@ -42,10 +42,10 @@ public void Initialize(TitleScreenManager titleScreenManager)
InvokeOnInit();
}

public override IModButton AddButton(IModButton button, int index)
public override IModButtonBase AddButton(IModButtonBase button, int index)
{
var modButton = base.AddButton(button, index);
var fadeControllers = TitleButtons.OrderBy(x => x.Index).Select(x => new CanvasGroupFadeController
var fadeControllers = Buttons.OrderBy(x => x.Index).Select(x => new CanvasGroupFadeController
{
group = x.Button.GetComponent<CanvasGroup>()
});
Expand Down
Loading

0 comments on commit bcd2b16

Please sign in to comment.