using System; using Cthangover.Core.Games; using Cthangover.Core.Mods; using Cthangover.Core.Scenes; using Cthangover.Core.Settings; using Cthangover.Core.UI.Menu; using Godot; namespace Cthangover.BaseMenu { /// /// Registers the built-in main-menu buttons and the settings/save-load panels /// in . Runs from /// ModInitializerRegistry.NotifyResourcesReady, which fires after the /// registry itself is built, so these entries are appended to live registry /// state rather than collected from a manifest. /// public class BaseMenuInitializer : IModInitializer { private const string ModId = "menu_base"; public void OnModLoaded(string modId) { } public void OnModResourcesReady() { MenuRegistry.RegisterMenuPanel(new MenuPanelEntry { Id = "settings", ModId = ModId, ScenePath = "scenes/menu/settings_menu.tscn", Locale = "menu/settings", }); MenuRegistry.RegisterMenuPanel(new MenuPanelEntry { Id = "save_load", ModId = ModId, ScenePath = "scenes/menu/save_load_menu.tscn", }); MenuRegistry.RegisterMenuButton(new MenuButtonEntry { Id = "continue", ModId = ModId, Section = "game", Locale = "menu/continue", Variation = "primary", Index = 5, Visible = GameFlow.HasContinue, Handler = BaseMenuActions.Continue, }); MenuRegistry.RegisterMenuButton(new MenuButtonEntry { Id = "play", ModId = ModId, Section = "game", Locale = "menu/play", Variation = "primary", Index = 10, Handler = BaseMenuActions.Play, }); // A new game of the running game; from the front-end games start // from the picker instead. MenuRegistry.RegisterMenuButton(new MenuButtonEntry { Id = "new_game", ModId = ModId, Section = "game", Locale = "menu/newgame", Index = 15, Visible = () => !ActiveGame.IsFrontendOnly, Handler = BaseMenuActions.NewGame, }); MenuRegistry.RegisterMenuButton(new MenuButtonEntry { Id = "load", ModId = ModId, Section = "game", Locale = "ui/menu/load", Index = 20, Handler = BaseMenuActions.Load, }); MenuRegistry.RegisterMenuButton(new MenuButtonEntry { Id = "settings", ModId = ModId, Section = "game", Locale = "menu/settings", Index = 30, Handler = BaseMenuActions.Settings, }); MenuRegistry.RegisterMenuButton(new MenuButtonEntry { Id = "exit", ModId = ModId, Section = "exit", Locale = "menu/exit", Variation = "danger", Index = 1000, Handler = BaseMenuActions.Exit, }); } } /// /// Handlers for the built-in menu buttons. Each receives the menu root control /// so it can locate the panels instantiated as named children by /// . /// internal static class BaseMenuActions { /// /// Starts a new game at the active game's entry scene (start_scene /// when no game collection is active) through . /// public static void NewGame(Control host) { GameSession.StartNew(host); } /// Loads the last save of the last played game (restarting into it when needed). public static void Continue(Control host) => GameFlow.Continue(host); /// Opens the game picker. public static void Play(Control host) { host.GetNodeOrNull("GamePickerPanel")?.Open(); } /// Opens the save/load panel in load mode. public static void Load(Control host) { host.GetNodeOrNull("SaveLoadPanel")?.OpenForLoad(); } /// Shows the settings overlay. public static void Settings(Control host) { host.GetNodeOrNull("SettingsPanel")?.Open(); } /// Quits the application after engine mods finish their registered cleanup. public static void Exit(Control host) { Cthangover.Core.Bootstrap.ApplicationExit.Quit(host.GetTree()); } } }