Skip to content

Commit 2a4d2b2

Browse files
committed
Added bool to hide game mode in menu
1 parent 5cdd883 commit 2a4d2b2

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

PolyMod.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
https://polymod.dev/nuget/v3/index.json;
1111
</RestoreAdditionalProjectSources>
1212
<Configurations>IL2CPP</Configurations>
13-
<Version>1.2.0-pre.1</Version>
13+
<Version>1.2.0</Version>
1414
<PolytopiaVersion>2.14.1.14597</PolytopiaVersion>
1515
<Authors>PolyModdingTeam</Authors>
1616
<Description>The Battle of Polytopia's mod loader.</Description>

src/Loader.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,23 @@ internal record TypeMapping(Type type, bool shouldCreateCache = true);
194194
/// <param name="action">The action to perform when the button is clicked.</param>
195195
/// <param name="buttonIndex">The index of the button in the UI.</param>
196196
/// <param name="sprite">The sprite for the button.</param>
197-
public record GameModeButtonsInformation(int gameModeIndex, UIButtonBase.ButtonAction action, int? buttonIndex, Sprite? sprite);
197+
/// <param name="spriteName">The name of the sprite for the button.</param>
198+
public record GameModeButtonsInformation(int gameModeIndex, UIButtonBase.ButtonAction action, int? buttonIndex, Sprite? sprite, string? spriteName);
198199

199200
/// <summary>
200201
/// Adds a new game mode button.
201202
/// </summary>
202203
/// <param name="id">The unique identifier for the game mode.</param>
203204
/// <param name="action">The action to perform when the button is clicked.</param>
205+
/// <param name="shouldShowInMenu">The boolean which decides if GameMode should appear in the menu.</param>
204206
/// <param name="sprite">The sprite for the button.</param>
205-
public static void AddGameModeButton(string id, UIButtonBase.ButtonAction action, Sprite? sprite)
207+
/// <param name="spriteName">The name of the sprite for the button.</param>
208+
public static void AddGameMode(string id, UIButtonBase.ButtonAction action, bool shouldShowInMenu = true, Sprite? sprite = null, string? spriteName = null)
206209
{
207210
EnumCache<GameMode>.AddMapping(id, (GameMode)Registry.gameModesAutoidx);
208211
EnumCache<GameMode>.AddMapping(id, (GameMode)Registry.gameModesAutoidx);
209-
gamemodes.Add(new GameModeButtonsInformation(Registry.gameModesAutoidx, action, null, sprite));
212+
if(shouldShowInMenu)
213+
gamemodes.Add(new GameModeButtonsInformation(Registry.gameModesAutoidx, action, null, sprite, spriteName));
210214
Registry.gameModesAutoidx++;
211215
}
212216

src/Managers/Main.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ private static void GameModeScreen_Init(GameModeScreen __instance)
146146
var item = Loader.gamemodes[i];
147147
var button = GameObject.Instantiate(__instance.buttons[2]);
148148
list.Add(button);
149-
Loader.gamemodes[i] = new Loader.GameModeButtonsInformation(item.gameModeIndex, item.action, __instance.buttons.Length, item.sprite);
149+
Sprite? sprite = item.sprite;
150+
if (item.sprite == null && item.spriteName != null)
151+
{
152+
sprite = Registry.GetSprite(item.spriteName);
153+
}
154+
Loader.gamemodes[i] = new Loader.GameModeButtonsInformation(item.gameModeIndex, item.action, __instance.buttons.Length, sprite, item.spriteName);
150155
}
151156

152157
var newArray = list.ToArray();

0 commit comments

Comments
 (0)