Browse Source

Moved list button to main menu

pull/11/head
Anairkoen Schno 5 years ago
parent
commit
bb0784cc1a
10 changed files with 203 additions and 27 deletions
  1. +4
    -0
      BSIPA-ModList/BSIPA-ModList.csproj
  2. +5
    -15
      BSIPA-ModList/Plugin.cs
  3. +91
    -0
      BSIPA-ModList/UI/ButtonUI.cs
  4. +46
    -2
      BSIPA-ModList/UI/ModListFlowCoordinator.cs
  5. +18
    -1
      BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs
  6. +29
    -9
      BSIPA-ModList/UI/ViewControllers/ModListController.cs
  7. BIN
      Refs/BeatSaberCustomUI.dll
  8. BIN
      Refs/UnityEngine.dll
  9. +8
    -0
      Refs/UnityEngine.xml
  10. +2
    -0
      Refs/refs.txt

+ 4
- 0
BSIPA-ModList/BSIPA-ModList.csproj View File

@ -47,6 +47,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\Refs\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\Refs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
@ -63,6 +66,7 @@
<ItemGroup>
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\ButtonUI.cs" />
<Compile Include="UI\ModListFlowCoordinator.cs" />
<Compile Include="UI\ViewControllers\BackButtonNavigationController.cs" />
<Compile Include="UI\ViewControllers\ModInfoViewController.cs" />


+ 5
- 15
BSIPA-ModList/Plugin.cs View File

@ -31,13 +31,8 @@ namespace BSIPA_ModList
{
}
private MainFlowCoordinator mainFlow;
private ModListFlowCoordinator menuFlow;
private MenuButton button;
public void OnApplicationStart()
{
Logger.log.Debug("Creating Menu");
}
public void OnFixedUpdate()
@ -48,16 +43,11 @@ namespace BSIPA_ModList
{
if (scene.name == "MenuCore")
{
if (mainFlow == null)
mainFlow = Resources.FindObjectsOfTypeAll<MainFlowCoordinator>().First();
if (menuFlow == null)
menuFlow = new GameObject("BSIPA Mod List Flow Coordinator").AddComponent<ModListFlowCoordinator>();
if (button == null)
button = MenuButtonUI.AddButton("Mod List", "Look at installed mods, and control updating", () =>
{
Logger.log.Debug("Presenting own flow controller");
menuFlow.PresentOn(mainFlow);
});
if (ButtonUI.Instance == null)
{
Logger.log.Debug("Creating Menu");
new GameObject("BSIPA Mod List Object").AddComponent<ButtonUI>().Init();
}
}
}


+ 91
- 0
BSIPA-ModList/UI/ButtonUI.cs View File

@ -0,0 +1,91 @@
using CustomUI.BeatSaber;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace BSIPA_ModList.UI
{
internal class ButtonUI : MonoBehaviour
{
private const string ControllerPanel = "MainMenuViewController/SmallButtons";
private const string CopyButton = "CreditsButton";
internal static ButtonUI Instance;
public void Awake()
{
DontDestroyOnLoad(gameObject);
SceneManager.activeSceneChanged += this.SceneManager_activeSceneChanged;
}
private void SceneManager_activeSceneChanged(Scene from, Scene to)
{
if (to.name == "EmptyTransition")
{
if (Instance != null)
{
Instance.StopAllCoroutines();
Destroy(Instance.gameObject);
menuFlow = null;
}
Instance = null;
}
}
public void Init()
{
Instance = this;
Logger.log.Debug("UI Awake");
StartCoroutine(AddModListButton());
}
private static MainFlowCoordinator mainFlow;
private static ModListFlowCoordinator menuFlow;
private static readonly WaitUntil _bottomPanelExists = new WaitUntil(() => GameObject.Find(ControllerPanel) != null);
private static RectTransform panel;
private static HoverHint hintText;
private static Button button;
private static IEnumerator AddModListButton()
{
Logger.log.Debug("AddModListButton");
yield return _bottomPanelExists;
Logger.log.Debug("Adding button to main menu");
lock (Instance)
{
if (mainFlow == null)
mainFlow = Resources.FindObjectsOfTypeAll<MainFlowCoordinator>().First();
if (menuFlow == null)
menuFlow = new GameObject("BSIPA Mod List Flow Controller").AddComponent<ModListFlowCoordinator>();
if (panel == null)
panel = GameObject.Find(ControllerPanel).transform as RectTransform;
if (button == null)
{
button = BeatSaberUI.CreateUIButton(panel, CopyButton, () =>
{
Logger.log.Debug("Presenting own flow controller");
menuFlow.PresentOn(mainFlow);
}, "Mod List");
panel.Find(CopyButton).SetAsLastSibling();
hintText = BeatSaberUI.AddHintText(button.transform as RectTransform, "View and control updates for installed mods");
}
yield break;
}
}
}
}

+ 46
- 2
BSIPA-ModList/UI/ModListFlowCoordinator.cs View File

@ -25,7 +25,7 @@ namespace BSIPA_ModList.UI
navigationController.didFinishEvent += backButton_DidFinish;
modList = BeatSaberUI.CreateViewController<ModListController>();
modList.Init(navigationController, PluginManager.AllPlugins, PluginLoader.ignoredPlugins, PluginManager.Plugins);
modList.Init(this, PluginManager.AllPlugins, PluginLoader.ignoredPlugins, PluginManager.Plugins);
PushViewControllerToNavigationController(navigationController, modList);
}
@ -49,10 +49,54 @@ namespace BSIPA_ModList.UI
presentFlow(main, this, finished, immediate, replaceTop);
}
public bool HasSelected { get; private set; } = false;
public void SetSelected(VRUIViewController selected, Action callback = null, bool immediate = false)
{
if (immediate)
{
if (HasSelected)
PopViewController(immediate: true);
PushViewController(selected, callback, true);
}
else
{
if (HasSelected)
PopViewController(() => PushViewController(selected, callback, immediate), immediate);
else
PushViewController(selected, callback, immediate);
}
}
public void ClearSelected(Action callback = null, bool immediate = false)
{
if (HasSelected) PopViewController(callback, immediate);
}
public void PushViewController(VRUIViewController controller, Action callback = null, bool immediate = false)
{
PushViewControllerToNavigationController(navigationController, controller, callback, immediate);
}
public void PopViewController(Action callback = null, bool immediate = false)
{
PopViewControllerFromNavigationController(navigationController, callback, immediate);
}
private delegate void DismissFlowDel(FlowCoordinator self, FlowCoordinator newF, Action finished, bool immediate);
private static DismissFlowDel dismissFlow;
private void backButton_DidFinish()
{
if (dismissFlow == null)
{
var ty = typeof(FlowCoordinator);
var m = ty.GetMethod("DismissFlowCoordinator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
dismissFlow = (DismissFlowDel)Delegate.CreateDelegate(typeof(DismissFlowDel), m);
}
MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll<MainFlowCoordinator>().First();
mainFlow.InvokeMethod("DismissFlowCoordinator", this, null, false);
dismissFlow(mainFlow, this, null, false);
}
}
}

+ 18
- 1
BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs View File

@ -4,11 +4,28 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using VRUI;
namespace BSIPA_ModList.UI
{
internal class ModInfoViewController : CustomViewController
internal class ModInfoViewController : VRUIViewController
{
private Sprite Icon;
private string Name;
private string Version;
private string Author;
private string Description;
private bool CanUpdate;
public void Init(Sprite icon, string name, string version, string author, string description, bool canUpdate)
{
Icon = icon;
Name = name;
Version = version;
Author = author;
Description = description;
CanUpdate = canUpdate;
}
}
}

+ 29
- 9
BSIPA-ModList/UI/ViewControllers/ModListController.cs View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using CustomUI.BeatSaber;
using CustomUI.Utilities;
@ -7,6 +8,7 @@ using IPA.Loader;
using IPA.Old;
using UnityEngine;
using VRUI;
using IPA.Loader.Features;
namespace BSIPA_ModList.UI
{
@ -31,11 +33,13 @@ namespace BSIPA_ModList.UI
}
internal PluginLoader.PluginInfo Plugin;
private ModListController list;
public BSIPAModCell(PluginLoader.PluginInfo plugin)
public BSIPAModCell(ModListController list, PluginLoader.PluginInfo plugin)
: base($"{plugin.Metadata.Name} <size=60%>v{plugin.Metadata.Version}", plugin.Metadata.Manifest.Author, null)
{
Plugin = plugin;
this.list = list;
if (plugin.Metadata.Manifest.IconPath != null)
icon = UIUtilities.LoadSpriteRaw(UIUtilities.GetResource(plugin.Metadata.Assembly, plugin.Metadata.Manifest.IconPath));
@ -45,20 +49,33 @@ namespace BSIPA_ModList.UI
Logger.log.Debug($"BSIPAModCell {plugin.Metadata.Name} {plugin.Metadata.Version}");
}
private ModInfoViewController infoView;
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected BSIPAModCell {Plugin.Metadata.Name} {Plugin.Metadata.Version}");
if (infoView == null)
{
infoView = BeatSaberUI.CreateViewController<ModInfoViewController>();
infoView.Init(icon, Plugin.Metadata.Name, Plugin.Metadata.Version.ToString(), Plugin.Metadata.Manifest.Author,
Plugin.Metadata.Manifest.Description, Plugin.Metadata.Features.FirstOrDefault(f => f is NoUpdateFeature) == null);
}
list.flow.SetSelected(infoView);
}
}
private class BSIPAIgnoredModCell : CustomCellInfo, IClickableCell
{
internal PluginLoader.PluginMetadata Plugin;
private ModListController list;
public BSIPAIgnoredModCell(PluginLoader.PluginMetadata plugin)
public BSIPAIgnoredModCell(ModListController list, PluginLoader.PluginMetadata plugin)
: base($"<color=#878787>{plugin.Name} <size=60%>v{plugin.Version}", $"{plugin.Manifest.Author} <color=#BFBFBF>- <i>Not loaded</i>", BSIPAModCell.DefaultIcon)
{
Plugin = plugin;
this.list = list;
Logger.log.Debug($"BSIPAIgnoredModCell {plugin.Name} {plugin.Version}");
}
@ -66,6 +83,7 @@ namespace BSIPA_ModList.UI
public void OnSelect(ModListController cntrl)
{
Logger.log.Debug($"Selected BSIPAIgnoredModCell {Plugin.Name} {Plugin.Version}");
}
}
@ -84,11 +102,13 @@ namespace BSIPA_ModList.UI
}
internal IPlugin Plugin;
private ModListController list;
public IPAModCell(IPlugin plugin)
public IPAModCell(ModListController list, IPlugin plugin)
: base($"{plugin.Name} <size=60%>{plugin.Version}", "<color=#BFBFBF><i>Legacy</i>", DefaultIcon)
{
Plugin = plugin;
this.list = list;
Logger.log.Debug($"IPAModCell {plugin.Name} {plugin.Version}");
}
@ -100,10 +120,10 @@ namespace BSIPA_ModList.UI
}
#pragma warning restore
private BackButtonNavigationController navigation;
private ModListFlowCoordinator flow;
#pragma warning disable CS0618
public void Init(BackButtonNavigationController navigation, IEnumerable<PluginLoader.PluginInfo> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)
public void Init(ModListFlowCoordinator flow, IEnumerable<PluginLoader.PluginInfo> bsipaPlugins, IEnumerable<PluginLoader.PluginMetadata> ignoredPlugins, IEnumerable<IPlugin> ipaPlugins)
{
Logger.log.Debug("List Controller Init");
@ -111,16 +131,16 @@ namespace BSIPA_ModList.UI
DidSelectRowEvent = DidSelectRow;
includePageButtons = true;
this.navigation = navigation;
this.flow = flow;
reuseIdentifier = "BSIPAModListTableCell";
foreach (var plugin in bsipaPlugins)
Data.Add(new BSIPAModCell(plugin));
Data.Add(new BSIPAModCell(this, plugin));
foreach (var plugin in ignoredPlugins)
Data.Add(new BSIPAIgnoredModCell(plugin));
Data.Add(new BSIPAIgnoredModCell(this, plugin));
foreach (var plugin in ipaPlugins)
Data.Add(new IPAModCell(plugin));
Data.Add(new IPAModCell(this, plugin));
}
#pragma warning restore


BIN
Refs/BeatSaberCustomUI.dll View File


BIN
Refs/UnityEngine.dll View File


+ 8
- 0
Refs/UnityEngine.xml View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<doc>
<members>
<assembly>
<name>UnityEngine</name>
</assembly>
</members>
</doc>

+ 2
- 0
Refs/refs.txt View File

@ -3,6 +3,8 @@
""Managed/
"""Assembly-CSharp.dll
"""UnityEngine.
""""dll
""""xml
""""UnityWebRequestModule.
"""""dll
"""""xml


Loading…
Cancel
Save