Skip to content

Commit

Permalink
Merge pull request #3 from ModdingPink/master
Browse files Browse the repository at this point in the history
  • Loading branch information
qe201020335 authored Nov 11, 2024
2 parents 3328ec9 + 4fefea8 commit 2025a57
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 20 deletions.
1 change: 1 addition & 0 deletions SongRankedBadge/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ internal class PluginConfig
public virtual bool ModEnable { get; set; } = true;
public virtual bool DifferentText { get; set; } = true;
public virtual bool DifferentColor { get; set; } = true;
public virtual bool SettingsMenuButton { get; set; } = false;
}
}
21 changes: 21 additions & 0 deletions SongRankedBadge/Installers/MenuInstaller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using SongRankedBadge.Configuration;
using SongRankedBadge.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zenject;

namespace SongRankedBadge.Installers
{
class MenuInstaller : Installer
{
public override void InstallBindings()
{
if (!PluginConfig.Instance.SettingsMenuButton)
Container.BindInterfacesTo<ModSettings>().FromNewComponentOnRoot().AsSingle();
}
}
}
15 changes: 11 additions & 4 deletions SongRankedBadge/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using IPALogger = IPA.Logging.Logger;
using Conf = IPA.Config.Config;
using BeatSaberMarkupLanguage;
using BeatSaberMarkupLanguage.MenuButtons;
using BeatSaberMarkupLanguage.Util;
using SongRankedBadge.Installers;
using SongRankedBadge.Configuration;
using SiraUtil.Zenject;

namespace SongRankedBadge
{
Expand All @@ -26,12 +30,12 @@ public class Plugin

private readonly Harmony _harmony = new Harmony("com.github.qe201020335.SongRankedBadge");

private MenuButton MenuButton = new MenuButton("Ranked Badge", "PromoBadge? RankedBadge!", OnMenuButtonClick);
internal MenuButton MenuButton = new MenuButton("Ranked Badge", "PromoBadge? RankedBadge!", OnMenuButtonClick);

private UI.ConfigViewFlowCoordinator? _configViewFlowCoordinator;

[Init]
public void InitWithConfig(IPALogger logger, IPA.Config.Config conf)
public Plugin(IPALogger logger, Conf conf, Zenjector zenjector)
{
Instance = this;
Log = logger;
Expand All @@ -41,12 +45,15 @@ public void InitWithConfig(IPALogger logger, IPA.Config.Config conf)
Log.Debug("Config loaded");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
MainMenuAwaiter.MainMenuInitializing += OnMenuLoad;

zenjector.UseLogger(logger);
zenjector.Install<MenuInstaller>(Location.Menu);
}

private void OnMenuLoad()
{
Log.Debug("OnMenuLoad");
MenuButtons.Instance.RegisterButton(MenuButton);
if(PluginConfig.Instance.SettingsMenuButton)
MenuButtons.Instance.RegisterButton(MenuButton);
}

private static void OnMenuButtonClick()
Expand Down
36 changes: 24 additions & 12 deletions SongRankedBadge/SongRankedBadge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
<Reference Include="BGLib.Polyglot">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BGLib.Polyglot.dll</HintPath>
</Reference>
<Reference Include="BSML">
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="BSML">
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="BeatSaber.ViewSystem">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\BeatSaber.ViewSystem.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="DataModels">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\DataModels.dll</HintPath>
</Reference>
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\DataModels.dll</HintPath>
</Reference>
<Reference Include="Interactable">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Interactable.dll</HintPath>
<Private>false</Private>
Expand All @@ -43,11 +43,16 @@
<HintPath>$(BeatSaberDir)\Libs\Newtonsoft.Json.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SongCore">
<HintPath>$(BeatSaberDir)\Plugins\SongCore.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SongDetailsCache">
<Reference Include="SiraUtil">
<HintPath>$(BeatSaberDir)\Plugins\SiraUtil.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="SongCore">
<HintPath>$(BeatSaberDir)\Plugins\SongCore.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SongDetailsCache">
<HintPath>$(BeatSaberDir)\Libs\SongDetailsCache.dll</HintPath>
<Private>false</Private>
</Reference>
Expand Down Expand Up @@ -101,8 +106,15 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Zenject">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Zenject-usage">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Zenject-usage.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="manifest.json" />
<EmbeddedResource Include="UI\configMenu.bsml" />
Expand Down
3 changes: 3 additions & 0 deletions SongRankedBadge/UI/ConfigViewFlowCoordinator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BeatSaberMarkupLanguage;
using HMUI;
using SongRankedBadge.Configuration;
using System;

namespace SongRankedBadge.UI
Expand Down Expand Up @@ -41,6 +42,8 @@ protected override void BackButtonWasPressed(ViewController topController)
{
base.BackButtonWasPressed(topController);
BeatSaberUI.MainFlowCoordinator.DismissFlowCoordinator(this);
if(!PluginConfig.Instance.SettingsMenuButton)
FindObjectOfType<MenuTransitionsHelper>().RestartGame();
}
}
}
63 changes: 63 additions & 0 deletions SongRankedBadge/UI/ModSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.MenuButtons;
using BeatSaberMarkupLanguage.Settings;
using SongRankedBadge.Configuration;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Zenject;

namespace SongRankedBadge.UI
{
public class ModSettings : MonoBehaviour, IInitializable, INotifyPropertyChanged
{
private static PluginConfig Config => PluginConfig.Instance;
private GameplaySetupViewController? gameplaySetupViewController;
public event PropertyChangedEventHandler PropertyChanged = null!;

[UIValue("ModEnable")]
private bool ModEnable
{
get => Config.ModEnable;
set => Config.ModEnable = value;
}

[UIValue("DiffText")]
public bool DiffText
{
get => Config.DifferentText;
set => Config.DifferentText = value;
}

[UIValue("DiffColor")]
public bool DiffColor
{
get => Config.DifferentColor;
set => Config.DifferentColor = value;
}

[UIValue("MenuSettings")]
public bool MenuSettings
{
get => Config.SettingsMenuButton;
set {
Config.SettingsMenuButton = value;

if(value)
MenuButtons.Instance.RegisterButton(Plugin.Instance.MenuButton);
else
MenuButtons.Instance.UnregisterButton(Plugin.Instance.MenuButton);
}
}

public void Initialize()
{
BSMLSettings.Instance.AddSettingsMenu("Ranked Badge", "SongRankedBadge.UI.configMenu.bsml", this);
}
}
}

16 changes: 13 additions & 3 deletions SongRankedBadge/UI/SettingMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
using BeatSaberMarkupLanguage.ViewControllers;
using SongRankedBadge.Configuration;
using TMPro;
using BeatSaberMarkupLanguage.MenuButtons;
using BeatSaberMarkupLanguage.Components;
using UnityEngine;
using UnityEngine.PlayerLoop;
using System.ComponentModel;

namespace SongRankedBadge.UI
{
Expand All @@ -12,24 +17,23 @@ namespace SongRankedBadge.UI
[ViewDefinition("SongRankedBadge.UI.configMenu.bsml")]
internal class SettingMenuController : BSMLAutomaticViewController
{

private static PluginConfig Config => PluginConfig.Instance;
public event PropertyChangedEventHandler PropertyChanged = null!;

[UIValue("ModEnable")]
private bool ModEnable
{
get => Config.ModEnable;
set => Config.ModEnable = value;
}


[UIValue("DiffText")]
public bool DiffText
{
get => Config.DifferentText;
set => Config.DifferentText = value;
}


[UIValue("DiffColor")]
public bool DiffColor
Expand All @@ -38,5 +42,11 @@ public bool DiffColor
set => Config.DifferentColor = value;
}

[UIValue("MenuSettings")]
public bool MenuSettings
{
get => Config.SettingsMenuButton;
set => Config.SettingsMenuButton = value;
}
}
}
1 change: 1 addition & 0 deletions SongRankedBadge/UI/configMenu.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<bool-setting text="Mod Enable" value="ModEnable" apply-on-change="true"/>
<bool-setting text="Different Text" value="DiffText" hover-hint="Use different badge texts for BL and SS" apply-on-change="true"/>
<bool-setting text="Different Color" value="DiffColor" hover-hint="Use different badge colors for BL and SS" apply-on-change="true"/>
<bool-setting text="Show Settings In Main Menu" value="MenuSettings" hover-hint="Show the mod settings within the Mods tab within the Main Menu" apply-on-change="true"/>
</vertical>
</settings-container>
3 changes: 2 additions & 1 deletion SongRankedBadge/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"BSIPA": "^4.2.2",
"SongDetailsCache": "^1.2.2",
"SongCore": "^3.13.0",
"BeatSaberMarkupLanguage": "^1.12.0"
"BeatSaberMarkupLanguage": "^1.12.0",
"SiraUtil": "^3.1.12"
}
}

0 comments on commit 2025a57

Please sign in to comment.