Skip to content

Commit

Permalink
Mods menu (#67)
Browse files Browse the repository at this point in the history
* mods menu
* mod config UI
* menu controller support
  • Loading branch information
amazingalek authored Feb 3, 2020
1 parent 79944ff commit 2468d6d
Show file tree
Hide file tree
Showing 50 changed files with 1,321 additions and 134 deletions.
13 changes: 9 additions & 4 deletions OWML.Common/IModConfig.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace OWML.Common
{
public interface IModConfig
{
bool Enabled { get; }
bool RequireVR { get; }
Dictionary<string, object> Settings { get; }
bool Enabled { get; set; }
bool RequireVR { get; set; }
Dictionary<string, object> Settings { get; set; }
T GetSettingsValue<T>(string key);
void SetSettingsValue(string key, object value);

[Obsolete("Use GetSettingsValue instead")]
T GetSetting<T>(string key);
}
}
3 changes: 3 additions & 0 deletions OWML.Common/IModData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ public interface IModData
{
IModManifest Manifest { get; }
IModConfig Config { get; }
IModConfig DefaultConfig { get; }

void ResetConfig();
}
}
2 changes: 2 additions & 0 deletions OWML.Common/Menus/IModButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public interface IModButton

void Show();
void Hide();

void SetControllerCommand(SingleAxisCommand inputCommand);
}
}
10 changes: 10 additions & 0 deletions OWML.Common/Menus/IModConfigMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OWML.Common.Menus
{
public interface IModConfigMenu : IModPopupMenu
{
IModData ModData { get; }
IModBehaviour Mod { get; }

void Initialize(Menu modMenuCopy, IModToggleInput toggleTemplate, IModSliderInput sliderTemplate, IModTextInput textInputTemplate, IModNumberInput numberInputTemplate);
}
}
17 changes: 17 additions & 0 deletions OWML.Common/Menus/IModInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using UnityEngine;

namespace OWML.Common.Menus
{
public interface IModInput<T>
{
event Action<T> OnChange;
T Value { get; set; }
MonoBehaviour Element { get; }
string Title { get; set; }
int Index { get; set; }
void Show();
void Hide();
void Initialize(IModMenu menu);
}
}
12 changes: 12 additions & 0 deletions OWML.Common/Menus/IModInputMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace OWML.Common.Menus
{
public interface IModInputMenu : IModMenu
{
event Action<string> OnConfirm;
event Action OnCancel;
void Initialize(PopupInputMenu inputMenu);
void Open(InputType inputType, string value);
}
}
31 changes: 29 additions & 2 deletions OWML.Common/Menus/IModMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,37 @@ 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);
IModButton AddButton(IModButton button);
IModButton AddButton(IModButton button, int index);

List<IModToggleInput> ToggleInputs { get; }
IModToggleInput GetToggleInput(string title);
IModToggleInput AddToggleInput(IModToggleInput input);
IModToggleInput AddToggleInput(IModToggleInput input, int index);

List<IModSliderInput> SliderInputs { get; }
IModSliderInput GetSliderInput(string title);
IModSliderInput AddSliderInput(IModSliderInput input);
IModSliderInput AddSliderInput(IModSliderInput input, int index);

List<IModTextInput> TextInputs { get; }
IModTextInput GetTextInput(string title);
IModTextInput AddTextInput(IModTextInput input);
IModTextInput AddTextInput(IModTextInput input, int index);

List<IModNumberInput> NumberInputs { get; }
IModNumberInput GetNumberInput(string title);
IModNumberInput AddNumberInput(IModNumberInput input);
IModNumberInput AddNumberInput(IModNumberInput input, int index);

object GetInputValue(string key);
void SetInputValue(string key, object value);

void SelectFirst();
void UpdateNavigation();

[Obsolete("Use Buttons instead")]
List<Button> GetButtons();
Expand Down
2 changes: 2 additions & 0 deletions OWML.Common/Menus/IModMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public interface IModMenus
{
IModMainMenu MainMenu { get; }
IModPauseMenu PauseMenu { get; }
IModsMenu ModsMenu { get; }
IModInputMenu InputMenu { get; }
}
}
8 changes: 8 additions & 0 deletions OWML.Common/Menus/IModNumberInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OWML.Common.Menus
{
public interface IModNumberInput : IModInput<float>
{
IModNumberInput Copy();
IModNumberInput Copy(string key);
}
}
2 changes: 2 additions & 0 deletions OWML.Common/Menus/IModPopupMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UnityEngine.UI;

namespace OWML.Common.Menus
{
Expand All @@ -17,6 +18,7 @@ public interface IModPopupMenu : IModMenu
IModPopupMenu Copy();
IModPopupMenu Copy(string title);
void Initialize(Menu menu);
void Initialize(Menu menu, LayoutGroup layoutGroup);

[Obsolete("Use Copy instead")]
IModPopupMenu CreateCopy(string name);
Expand Down
11 changes: 11 additions & 0 deletions OWML.Common/Menus/IModSliderInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OWML.Common.Menus
{
public interface IModSliderInput : IModInput<float>
{
float Min { get; set; }
float Max { get; set; }

IModSliderInput Copy();
IModSliderInput Copy(string title);
}
}
4 changes: 4 additions & 0 deletions OWML.Common/Menus/IModTabMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
public interface IModTabMenu : IModPopupMenu
{
void Initialize(TabButton tabButton);
TabButton TabButton { get; }
new IModTabMenu Copy();
new IModTabMenu Copy(string title);
new string Title { get; set; }
}
}
1 change: 1 addition & 0 deletions OWML.Common/Menus/IModTabbedMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface IModTabbedMenu : IModPopupMenu

void Initialize(TabbedMenu menu);
new TabbedMenu Menu { get; }
void AddTab(IModTabMenu tab);
}
}
8 changes: 8 additions & 0 deletions OWML.Common/Menus/IModTextInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace OWML.Common.Menus
{
public interface IModTextInput : IModInput<string>
{
IModTextInput Copy();
IModTextInput Copy(string key);
}
}
11 changes: 11 additions & 0 deletions OWML.Common/Menus/IModToggleInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace OWML.Common.Menus
{
public interface IModToggleInput : IModInput<bool>
{
TwoButtonToggleElement Toggle { get; }
IModButton YesButton { get; }
IModButton NoButton { get; }
IModToggleInput Copy();
IModToggleInput Copy(string key);
}
}
10 changes: 10 additions & 0 deletions OWML.Common/Menus/IModsMenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace OWML.Common.Menus
{
public interface IModsMenu : IModPopupMenu
{
void AddMod(IModData modData, IModBehaviour mod);
IModConfigMenu GetModMenu(IModBehaviour modBehaviour);
void Initialize(IModMainMenu mainMenu);
void Initialize(IModPauseMenu pauseMenu);
}
}
9 changes: 9 additions & 0 deletions OWML.Common/Menus/InputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OWML.Common.Menus
{
public enum InputType
{
Text = 0,
Number = 1
};

}
9 changes: 9 additions & 0 deletions OWML.Common/OWML.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@
<Compile Include="IHarmonyHelper.cs" />
<Compile Include="IModAssets.cs" />
<Compile Include="IModAsset.cs" />
<Compile Include="Menus\InputType.cs" />
<Compile Include="Menus\IModButton.cs" />
<Compile Include="IModConfig.cs" />
<Compile Include="IModData.cs" />
<Compile Include="Menus\IModConfigMenu.cs" />
<Compile Include="Menus\IModInput.cs" />
<Compile Include="Menus\IModInputMenu.cs" />
<Compile Include="Menus\IModMainMenu.cs" />
<Compile Include="Menus\IModPauseMenu.cs" />
<Compile Include="Menus\IModsMenu.cs" />
<Compile Include="Menus\IModTabbedMenu.cs" />
<Compile Include="Menus\IModPopupMenu.cs" />
<Compile Include="Menus\IModTabMenu.cs" />
Expand All @@ -86,6 +91,10 @@
<Compile Include="IModLogger.cs" />
<Compile Include="IModManifest.cs" />
<Compile Include="IModStorage.cs" />
<Compile Include="Menus\IModSliderInput.cs" />
<Compile Include="Menus\IModNumberInput.cs" />
<Compile Include="Menus\IModTextInput.cs" />
<Compile Include="Menus\IModToggleInput.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
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.31";
private const string Version = "0.3.32";

private readonly IOwmlConfig _owmlConfig;
private readonly IModConsole _writer;
Expand Down
14 changes: 11 additions & 3 deletions OWML.ModHelper.Menus/ModButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ public class ModButton : IModButton
private readonly Text _text;
public string Title
{
get => _text.text;
set => _text.text = value;
get => _text != null ? _text.text : "";
set
{
GameObject.Destroy(Button.GetComponentInChildren<LocalizedText>());
_text.text = value;
}
}

private int _index;
Expand Down Expand Up @@ -47,7 +51,6 @@ 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
Expand Down Expand Up @@ -141,5 +144,10 @@ public void Hide()
Button.gameObject.SetActive(false);
}

public void SetControllerCommand(SingleAxisCommand inputCommand)
{
Button.gameObject.AddComponent<ControllerButton>().Init(inputCommand);
}

}
}
Loading

0 comments on commit 2468d6d

Please sign in to comment.