public MainMenuLogic(Widget widget, World world, ModData modData) { rootMenu = widget; rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = modData.Manifest.Metadata.Version; // Menu buttons var mainMenu = widget.Get("MAIN_MENU"); mainMenu.IsVisible = () => menuType == MenuType.Main; mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = () => SwitchMenu(MenuType.Singleplayer); mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => SwitchMenu(MenuType.Main) }, { "directConnectHost", null }, { "directConnectPort", 0 }, }); }; mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () => { // Switching mods changes the world state (by disposing it), // so we can't do this inside the input handler. Game.RunAfterTick(() => { Game.Settings.Game.PreviousMod = modData.Manifest.Id; Game.InitializeMod("modchooser", null); }); }; mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Main) } }); }; mainMenu.Get<ButtonWidget>("EXTRAS_BUTTON").OnClick = () => SwitchMenu(MenuType.Extras); mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit; // Singleplayer menu var singleplayerMenu = widget.Get("SINGLEPLAYER_MENU"); singleplayerMenu.IsVisible = () => menuType == MenuType.Singleplayer; var missionsButton = singleplayerMenu.Get<ButtonWidget>("MISSIONS_BUTTON"); missionsButton.OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Singleplayer) }, { "onStart", RemoveShellmapUI } }); }; var hasCampaign = modData.Manifest.Missions.Any(); var hasMissions = modData.MapCache .Any(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector)); missionsButton.Disabled = !hasCampaign && !hasMissions; singleplayerMenu.Get<ButtonWidget>("SKIRMISH_BUTTON").OnClick = StartSkirmishGame; singleplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => SwitchMenu(MenuType.Main); // Extras menu var extrasMenu = widget.Get("EXTRAS_MENU"); extrasMenu.IsVisible = () => menuType == MenuType.Extras; extrasMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Extras) }, { "onStart", RemoveShellmapUI } }); }; extrasMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Extras) }, { "world", world } }); }; extrasMenu.Get<ButtonWidget>("MAP_EDITOR_BUTTON").OnClick = () => SwitchMenu(MenuType.MapEditor); var assetBrowserButton = extrasMenu.GetOrNull<ButtonWidget>("ASSETBROWSER_BUTTON"); if (assetBrowserButton != null) assetBrowserButton.OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("ASSETBROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Extras) }, }); }; extrasMenu.Get<ButtonWidget>("CREDITS_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Extras) }, }); }; extrasMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => SwitchMenu(MenuType.Main); // Map editor menu var mapEditorMenu = widget.Get("MAP_EDITOR_MENU"); mapEditorMenu.IsVisible = () => menuType == MenuType.MapEditor; // Loading into the map editor Game.BeforeGameStart += RemoveShellmapUI; var onSelect = new Action<string>(uid => LoadMapIntoEditor(modData.MapCache[uid].Uid)); var newMapButton = widget.Get<ButtonWidget>("NEW_MAP_BUTTON"); newMapButton.OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("NEW_MAP_BG", new WidgetArgs() { { "onSelect", onSelect }, { "onExit", () => SwitchMenu(MenuType.MapEditor) } }); }; var loadMapButton = widget.Get<ButtonWidget>("LOAD_MAP_BUTTON"); loadMapButton.OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { { "initialMap", null }, { "initialTab", MapClassification.User }, { "onExit", () => SwitchMenu(MenuType.MapEditor) }, { "onSelect", onSelect }, { "filter", MapVisibility.Lobby | MapVisibility.Shellmap | MapVisibility.MissionSelector }, }); }; mapEditorMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => SwitchMenu(MenuType.Extras); var newsBG = widget.GetOrNull("NEWS_BG"); if (newsBG != null) { newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None && menuType != MenuType.SystemInfoPrompt; newsPanel = Ui.LoadWidget<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs()); newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE"); newsPanel.RemoveChild(newsTemplate); newsStatus = newsPanel.Get<LabelWidget>("NEWS_STATUS"); SetNewsStatus("Loading news"); } Game.OnRemoteDirectConnect += OnRemoteDirectConnect; // System information opt-out prompt var sysInfoPrompt = widget.Get("SYSTEM_INFO_PROMPT"); sysInfoPrompt.IsVisible = () => menuType == MenuType.SystemInfoPrompt; if (Game.Settings.Debug.SystemInformationVersionPrompt < SystemInformationVersion) { menuType = MenuType.SystemInfoPrompt; var sysInfoCheckbox = sysInfoPrompt.Get<CheckboxWidget>("SYSINFO_CHECKBOX"); sysInfoCheckbox.IsChecked = () => Game.Settings.Debug.SendSystemInformation; sysInfoCheckbox.OnClick = () => Game.Settings.Debug.SendSystemInformation ^= true; var sysInfoData = sysInfoPrompt.Get<ScrollPanelWidget>("SYSINFO_DATA"); var template = sysInfoData.Get<LabelWidget>("DATA_TEMPLATE"); sysInfoData.RemoveChildren(); foreach (var info in GetSystemInformation().Values) { var label = template.Clone() as LabelWidget; var text = info.First + ": " + info.Second; label.GetText = () => text; sysInfoData.AddChild(label); } sysInfoPrompt.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion; Game.Settings.Save(); SwitchMenu(MenuType.Main); LoadAndDisplayNews(newsBG); }; } else LoadAndDisplayNews(newsBG); }
public MainMenuLogic(Widget widget, World world) { rootMenu = widget; rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = Game.ModData.Manifest.Mod.Version; // Menu buttons var mainMenu = widget.Get("MAIN_MENU"); mainMenu.IsVisible = () => menuType == MenuType.Main; mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = () => menuType = MenuType.Singleplayer; mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => menuType = MenuType.Main }, { "directConnectHost", null }, { "directConnectPort", 0 }, }); }; mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () => { Game.Settings.Game.PreviousMod = Game.ModData.Manifest.Mod.Id; Game.InitializeMod("modchooser", null); }; mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () => { menuType = MenuType.None; Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Main } }); }; mainMenu.Get<ButtonWidget>("EXTRAS_BUTTON").OnClick = () => menuType = MenuType.Extras; mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit; // Singleplayer menu var singleplayerMenu = widget.Get("SINGLEPLAYER_MENU"); singleplayerMenu.IsVisible = () => menuType == MenuType.Singleplayer; var missionsButton = singleplayerMenu.Get<ButtonWidget>("MISSIONS_BUTTON"); missionsButton.OnClick = () => { menuType = MenuType.None; Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Singleplayer }, { "onStart", RemoveShellmapUI } }); }; var hasCampaign = Game.ModData.Manifest.Missions.Any(); var hasMissions = Game.ModData.MapCache .Any(p => p.Status == MapStatus.Available && p.Map.Visibility.HasFlag(MapVisibility.MissionSelector)); missionsButton.Disabled = !hasCampaign && !hasMissions; singleplayerMenu.Get<ButtonWidget>("SKIRMISH_BUTTON").OnClick = StartSkirmishGame; singleplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main; // Extras menu var extrasMenu = widget.Get("EXTRAS_MENU"); extrasMenu.IsVisible = () => menuType == MenuType.Extras; extrasMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, { "onStart", RemoveShellmapUI } }); }; extrasMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, { "world", world } }); }; extrasMenu.Get<ButtonWidget>("MAP_EDITOR_BUTTON").OnClick = () => menuType = MenuType.MapEditor; var assetBrowserButton = extrasMenu.GetOrNull<ButtonWidget>("ASSETBROWSER_BUTTON"); if (assetBrowserButton != null) assetBrowserButton.OnClick = () => { menuType = MenuType.None; Game.OpenWindow("ASSETBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, }); }; extrasMenu.Get<ButtonWidget>("CREDITS_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, }); }; extrasMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main; // Map editor menu var mapEditorMenu = widget.Get("MAP_EDITOR_MENU"); mapEditorMenu.IsVisible = () => menuType == MenuType.MapEditor; var onSelect = new Action<string>(uid => { RemoveShellmapUI(); LoadMapIntoEditor(Game.ModData.MapCache[uid].Map); }); var newMapButton = widget.Get<ButtonWidget>("NEW_MAP_BUTTON"); newMapButton.OnClick = () => { menuType = MenuType.None; Game.OpenWindow("NEW_MAP_BG", new WidgetArgs() { { "onSelect", onSelect }, { "onExit", () => menuType = MenuType.MapEditor } }); }; var loadMapButton = widget.Get<ButtonWidget>("LOAD_MAP_BUTTON"); loadMapButton.OnClick = () => { menuType = MenuType.None; Game.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { { "initialMap", null }, { "initialTab", MapClassification.User }, { "onExit", () => menuType = MenuType.MapEditor }, { "onSelect", onSelect }, { "filter", MapVisibility.Lobby | MapVisibility.Shellmap | MapVisibility.MissionSelector }, }); }; mapEditorMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Extras; var newsBG = widget.GetOrNull("NEWS_BG"); if (newsBG != null) { newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None; newsPanel = Ui.LoadWidget<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs()); newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE"); newsPanel.RemoveChild(newsTemplate); newsStatus = newsPanel.Get<LabelWidget>("NEWS_STATUS"); SetNewsStatus("Loading news"); var cacheFile = Platform.ResolvePath("^", "news.yaml"); var currentNews = ParseNews(cacheFile); if (currentNews != null) DisplayNews(currentNews); // Only query for new stories once per day var cacheValid = currentNews != null && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate; if (!cacheValid) new Download(Game.Settings.Game.NewsUrl, cacheFile, e => { }, (e, c) => NewsDownloadComplete(e, c, cacheFile, currentNews)); var newsButton = newsBG.GetOrNull<DropDownButtonWidget>("NEWS_BUTTON"); newsButton.OnClick = () => { newsButton.AttachPanel(newsPanel); newsHighlighted = false; }; newsButton.IsHighlighted = () => newsHighlighted && Game.LocalTick % 50 < 25; } Game.OnRemoteDirectConnect += (host, port) => { menuType = MenuType.None; Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => menuType = MenuType.Main }, { "directConnectHost", host }, { "directConnectPort", port }, }); }; }
public MainMenuLogic(Widget widget, World world) { rootMenu = widget; rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version; // Menu buttons var mainMenu = widget.Get("MAIN_MENU"); mainMenu.IsVisible = () => menuType == MenuType.Main; mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = () => menuType = MenuType.Singleplayer; mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => menuType = MenuType.Main } }); }; mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () => { Game.Settings.Game.PreviousMod = Game.modData.Manifest.Mod.Id; Game.InitializeMod("modchooser", null); }; mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () => { menuType = MenuType.None; Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Main } }); }; mainMenu.Get<ButtonWidget>("EXTRAS_BUTTON").OnClick = () => menuType = MenuType.Extras; mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit; // Singleplayer menu var singleplayerMenu = widget.Get("SINGLEPLAYER_MENU"); singleplayerMenu.IsVisible = () => menuType == MenuType.Singleplayer; var missionsButton = singleplayerMenu.Get<ButtonWidget>("MISSIONS_BUTTON"); missionsButton.OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Singleplayer }, { "onStart", RemoveShellmapUI } }); }; missionsButton.Disabled = !Game.modData.Manifest.Missions.Any(); singleplayerMenu.Get<ButtonWidget>("SKIRMISH_BUTTON").OnClick = StartSkirmishGame; singleplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main; // Extras menu var extrasMenu = widget.Get("EXTRAS_MENU"); extrasMenu.IsVisible = () => menuType == MenuType.Extras; extrasMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, { "onStart", RemoveShellmapUI } }); }; extrasMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, }); }; var assetBrowserButton = extrasMenu.GetOrNull<ButtonWidget>("ASSETBROWSER_BUTTON"); if (assetBrowserButton != null) assetBrowserButton.OnClick = () => { menuType = MenuType.None; Game.OpenWindow("ASSETBROWSER_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, }); }; extrasMenu.Get<ButtonWidget>("CREDITS_BUTTON").OnClick = () => { menuType = MenuType.None; Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs { { "onExit", () => menuType = MenuType.Extras }, }); }; extrasMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main; var newsBG = widget.GetOrNull("NEWS_BG"); if (newsBG != null) { newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None; newsPanel = Ui.LoadWidget<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs()); newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE"); newsPanel.RemoveChild(newsTemplate); newsStatus = newsPanel.Get<LabelWidget>("NEWS_STATUS"); SetNewsStatus("Loading news"); var cacheFile = Path.Combine(Platform.SupportDir, "news.yaml"); var currentNews = ParseNews(cacheFile); if (currentNews != null) DisplayNews(currentNews); // Only query for new stories once per day var cacheValid = currentNews != null && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate; if (!cacheValid) new Download(Game.Settings.Game.NewsUrl, cacheFile, e => { }, (e, c) => NewsDownloadComplete(e, c, cacheFile, currentNews)); var newsButton = newsBG.GetOrNull<DropDownButtonWidget>("NEWS_BUTTON"); newsButton.OnClick = () => { newsButton.AttachPanel(newsPanel); newsHighlighted = false; }; newsButton.IsHighlighted = () => newsHighlighted && Game.LocalTick % 50 < 25; } }