Skip to content

Commit

Permalink
BUG/API: fix method signatures from PR #81
Browse files Browse the repository at this point in the history
  • Loading branch information
pdcook committed Jun 18, 2022
1 parent ebacf25 commit efca1f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
56 changes: 36 additions & 20 deletions UnboundLib/GameModes/GameModeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal static void Init()
SceneManager.sceneLoaded += (scene, mode) =>
{
if (scene.name != "Main") return;

// rename test gamemode object to SandboxID
GetGameMode<GM_Test>("Test").name = $"[GameMode] {SandBoxID}";

Expand Down Expand Up @@ -79,10 +79,10 @@ internal static void SetupUI()
{
var origGroupGo = origGameModeGo.transform.Find("Group");
var characterSelectGo_ = GameObject.Find("/Game/UI/UI_MainMenu/Canvas/ListSelector/CharacterSelect");
var newLocalMenu = Utils.UI.MenuHandler.CreateMenu("LOCAL",
() => { MainMenuHandler.instance.transform.Find("Canvas/ListSelector/Main/Group/Local").GetComponent<Button>().onClick.Invoke(); },
MainMenuHandler.instance.transform.Find("Canvas/ListSelector/Main").gameObject,

var newLocalMenu = Utils.UI.MenuHandler.CreateMenu("LOCAL",
() => { MainMenuHandler.instance.transform.Find("Canvas/ListSelector/Main/Group/Local").GetComponent<Button>().onClick.Invoke(); },
MainMenuHandler.instance.transform.Find("Canvas/ListSelector/Main").gameObject,
60, true, false, null, true, 1);

var content = newLocalMenu.transform.Find("Group/Grid/Scroll View/Viewport/Content");
Expand All @@ -98,7 +98,7 @@ internal static void SetupUI()
newVersusGo.name = "Versus";
var newSandboxGo = Utils.UI.MenuHandler.CreateButton("SANDBOX", newLocalMenu, () => { MainMenuHandler.instance.Close(); SetGameMode(SandBoxID); CurrentHandler.StartGame(); });
newSandboxGo.name = "Test";

// Select the local button so selection doesn't look weird
Unbound.Instance.ExecuteAfterFrames(15, () =>
{
Expand Down Expand Up @@ -159,10 +159,10 @@ internal static void SetupUI()

// create gamemode buttons alphabetically (creating them in reverse order)
// non-team gamemodes at the top, team gamemodes at the bottom
foreach (var id in handlers.Keys.Where(k => !handlers[k].OnlineOnly && handlers[k].AllowTeams).OrderByDescending(k => handlers[k].Name.ToLower()).Where(k => k!=SandBoxID && k!=ArmsRaceID))
foreach (var id in handlers.Keys.Where(k => !handlers[k].OnlineOnly && handlers[k].AllowTeams).OrderByDescending(k => handlers[k].Name.ToLower()).Where(k => k != SandBoxID && k != ArmsRaceID))
{
// create a copy of the string to give to the anonymous function
string id_ = string.Copy(id);
string id_ = string.Copy(id);
var gamemodeButtonGo = Utils.UI.MenuHandler.CreateButton(handlers[id].Name.ToUpper(), gameModeGo.gameObject, () => { characterSelectGo.GetComponent<ListMenuPage>().Open(); SetGameMode(id_); });
gamemodeButtonGo.name = id;
gamemodeButtonGo.transform.SetAsFirstSibling();
Expand All @@ -171,10 +171,10 @@ internal static void SetupUI()
// add a small separator
Utils.UI.MenuHandler.CreateText(" ", gameModeGo, out TextMeshProUGUI _, 30).transform.SetAsFirstSibling();

foreach (var id in handlers.Keys.Where(k => !handlers[k].OnlineOnly && !handlers[k].AllowTeams).OrderByDescending(k => handlers[k].Name.ToLower()).Where(k => k!=SandBoxID && k!=ArmsRaceID))
foreach (var id in handlers.Keys.Where(k => !handlers[k].OnlineOnly && !handlers[k].AllowTeams).OrderByDescending(k => handlers[k].Name.ToLower()).Where(k => k != SandBoxID && k != ArmsRaceID))
{
// create a copy of the string to give to the anonymous function
string id_ = string.Copy(id);
string id_ = string.Copy(id);
var gamemodeButtonGo = Utils.UI.MenuHandler.CreateButton(handlers[id].Name.ToUpper(), gameModeGo.gameObject, () => { characterSelectGo.GetComponent<ListMenuPage>().Open(); SetGameMode(id_); });
gamemodeButtonGo.name = id;
gamemodeButtonGo.transform.SetAsFirstSibling();
Expand Down Expand Up @@ -255,38 +255,55 @@ public static void AddOnceHook(string key, Func<IGameModeHandler, IEnumerator> a
{
return;
}
AddOnceHook(key, new GameModeHooks.Hook(action, priority));
}
/// <summary>
/// Adds a hook that is automatically removed after it's triggered once.
/// </summary>
public static void AddOnceHook(string key, GameModeHooks.Hook hook)
{
if (hook == null)
{
return;
}

// Case-insensitive keys for QoL
key = key.ToLower();

if (!onceHooks.ContainsKey(key))
{
onceHooks.Add(key, new List<GameModeHooks.Hook>{ AddHook(key, action, priority) });
onceHooks.Add(key, new List<GameModeHooks.Hook> { hook });
}
else
{
onceHooks[key].Add(AddHook(key, action, priority));
onceHooks[key].Add(hook);
}


AddHook(key, hook);
}

public static void AddHook(string key, Func<IGameModeHandler, IEnumerator> action)
{
AddHook(key, action, GameModeHooks.Priority.Normal);
}
public static GameModeHooks.Hook AddHook(string key, Func<IGameModeHandler, IEnumerator> action, int priority)
}
public static void AddHook(string key, Func<IGameModeHandler, IEnumerator> action, int priority)
{
if (action == null)
{
return null;
return;
}

AddHook(key, new GameModeHooks.Hook(action, priority));

}
public static void AddHook(string key, GameModeHooks.Hook hook)
{
if (hook == null)
{
return;
}
// Case-insensitive keys for QoL
key = key.ToLower();

GameModeHooks.Hook hook = new GameModeHooks.Hook(action, priority);

if (!hooks.ContainsKey(key))
{
hooks.Add(key, new List<GameModeHooks.Hook> { hook });
Expand All @@ -295,7 +312,6 @@ public static GameModeHooks.Hook AddHook(string key, Func<IGameModeHandler, IEnu
{
hooks[key].Add(hook);
}
return hook;
}
public static void RemoveHook(string key, GameModeHooks.Hook hook)
{
Expand Down
2 changes: 1 addition & 1 deletion UnboundLib/Unbound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Unbound : BaseUnityPlugin
{
private const string ModId = "com.willis.rounds.unbound";
private const string ModName = "Rounds Unbound";
public const string Version = "3.1.3";
public const string Version = "3.1.4";

public static Unbound Instance { get; private set; }
public static readonly ConfigFile config = new ConfigFile(Path.Combine(Paths.ConfigPath, "UnboundLib.cfg"), true);
Expand Down

0 comments on commit efca1f3

Please sign in to comment.