Skip to content

Commit

Permalink
Remix config menu (For pause menu text)
Browse files Browse the repository at this point in the history
I haven't done any documentation for `MusicAnnouncementsConfig.cs`, so hopefully I can get around to that later.
  • Loading branch information
SabreML committed Feb 1, 2023
1 parent 011989c commit 4b0a74c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions MusicAnnouncements.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="MusicAnnouncementsConfig.cs" />
<Compile Include="MusicAnnouncements_PauseMenu.cs" />
<Compile Include="MusicAnnouncementsMod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
81 changes: 81 additions & 0 deletions MusicAnnouncementsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Menu.Remix.MixedUI;
using UnityEngine;

namespace MusicAnnouncements
{
public class MusicAnnouncementsConfig : OptionInterface
{
public static Configurable<bool> pauseMenuText;

public MusicAnnouncementsConfig()
{
pauseMenuText = config.Bind("pauseMenuText", true, new ConfigurableInfo("Show the name of the currently playing song in the top right of the pause menu.", tags: new object[]
{
"Show currently playing song in the pause menu"
}));
}

// Called when the config menu is opened by the player. (I think)
public override void Initialize()
{
base.Initialize();
Tabs = new OpTab[]
{
new OpTab(this, "Options")
};

AddDivider(593f);
AddTitle();
AddDivider(540f);
AddCheckbox();
}

private void AddDivider(float y)
{
OpImage dividerLeft = new OpImage(new Vector2(300f, y), "LinearGradient200");
dividerLeft.sprite.SetAnchor(0.5f, 0f);
dividerLeft.sprite.rotation = 270f;

OpImage dividerRight = new OpImage(new Vector2(300f, y), "LinearGradient200");
dividerRight.sprite.SetAnchor(0.5f, 0f);
dividerRight.sprite.rotation = 90f;

Tabs[0].AddItems(new UIelement[]
{
dividerLeft,
dividerRight
});
}

private void AddTitle()
{
OpLabel title = new OpLabel(new Vector2(150f, 560f), new Vector2(300f, 30f), "Music Announcements Mod", bigText: true);
OpLabel version = new OpLabel(new Vector2(150f, 540f), new Vector2(300f, 30f), $"Version {MusicAnnouncementsMod.version}");

Tabs[0].AddItems(new UIelement[]
{
title,
version
});
}

private void AddCheckbox()
{
OpCheckBox checkbox = new OpCheckBox(pauseMenuText, new Vector2(150f, 500f))
{
description = pauseMenuText.info.description
};

OpLabel checkboxLabel = new OpLabel(150f + 40f, 500f + 2f, pauseMenuText.info.Tags[0] as string)
{
description = pauseMenuText.info.description
};

Tabs[0].AddItems(new UIelement[]
{
checkbox,
checkboxLabel
});
}
}
}
13 changes: 13 additions & 0 deletions MusicAnnouncementsMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace MusicAnnouncements
[BepInPlugin("sabreml.musicannouncements", "MusicAnnouncements", "1.1.0")]
public partial class MusicAnnouncementsMod : BaseUnityPlugin
{
// The current mod version. (Set here as a variable so that I don't have to update it in as many places.)
public static readonly string version = "1.1.0";

// The name of the song to announce. (Also used to display the track name in the pause menu)
private string songToAnnounce;

Expand All @@ -21,6 +24,9 @@ public partial class MusicAnnouncementsMod : BaseUnityPlugin

public void OnEnable()
{
On.RainWorld.OnModsInit += RainWorld_OnModsInitHK;

// In-game announcement hooks.
On.Music.Song.ctor += SongHK;
On.Music.MusicPiece.StopAndDestroy += MusicPiece_StopAndDestroyHK;
On.Music.MusicPlayer.Update += MusicPlayer_UpdateHK;
Expand All @@ -29,6 +35,13 @@ public void OnEnable()
SetupPauseMenuHooks();
}

private void RainWorld_OnModsInitHK(On.RainWorld.orig_OnModsInit orig, RainWorld self)
{
orig(self);
// Set up the remix menu.
MachineConnector.SetRegisteredOI("sabreml.musicannouncements", new MusicAnnouncementsConfig());
}

// Called when a new song is instantiated.
// If it's the correct type of song (playing as a random event ingame), `songToAnnounce` and `announceAttempts` are set.
private void SongHK(On.Music.Song.orig_ctor orig, Song self, MusicPlayer musicPlayer, string name, MusicPlayer.MusicContext context)
Expand Down
6 changes: 5 additions & 1 deletion MusicAnnouncements_PauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ private void PauseMenuHK(On.Menu.PauseMenu.orig_ctor orig, PauseMenu self, Proce
if (songToAnnounce == null)
{
return;
//songToAnnounce = "Kayava"; // Uncomment for debugging/testing.
}
if (!MusicAnnouncementsConfig.pauseMenuText.Value) // If the player has unticked `pauseMenuText` in the mod's config.
{
Debug.Log("(MusicAnnouncements) Skipping pause menu text due to config");
return;
}

float posX = game.rainWorld.options.ScreenSize.x - 10.01f;
Expand Down

0 comments on commit 4b0a74c

Please sign in to comment.