void Delete(string savePath) { try { File.Delete(savePath); } catch (Exception ex) { Game.Debug("Failed to delete save file '{0}'. See the logs for details.", savePath); Log.Write("debug", ex.ToString()); return; } if (savePath == selectedSave) { Select(null); } var item = gameList.Children .Select(c => c as ScrollItemWidget) .FirstOrDefault(c => c.ItemKey == savePath); gameList.RemoveChild(item); games.Remove(savePath); }
public void AddChatLineWrapper(TextNotification chatLine) { var chatLineToDisplay = chatLine; if (chatLine.CanIncrementOnDuplicate() && chatLine.Equals(lastLine)) { repetitions++; chatLineToDisplay = new TextNotification( chatLine.Pool, chatLine.Prefix, $"{chatLine.Text} ({repetitions + 1})", chatLine.PrefixColor, chatLine.TextColor); chatScrollPanel.RemoveChild(chatScrollPanel.Children[chatScrollPanel.Children.Count - 1]); chatOverlayDisplay?.RemoveMostRecentLine(); } else { repetitions = 0; } lastLine = chatLine; chatOverlayDisplay?.AddLine(chatLineToDisplay); // HACK: Force disable the chat notification sound for the in-menu chat dialog // This works around our inability to disable the sounds for the in-game dialog when it is hidden AddChatLine(chatLineToDisplay, chatOverlay == null); }
void ItemRemoved(EditorActionContainer editorAction) { var widget = states[editorAction]; panel.RemoveChild(widget); states.Remove(editorAction); }
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>("CONTENT_BUTTON").OnClick = () => { // Switching mods changes the world state (by disposing it), // so we can't do this inside the input handler. Game.RunAfterTick(() => { Game.InitializeMod("modcontent", new Arguments(new[] { "Content.Mod=" + modData.Manifest.Id })); }); }; 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; var newsURL = modData.Manifest.Get <WebServices>().GameNews; // 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(newsURL, newsBG); }; } else { LoadAndDisplayNews(newsURL, newsBG); } } void LoadAndDisplayNews(string newsURL, Widget newsBG) { if (newsBG != null) { var cacheFile = Platform.ResolvePath("^", "news.yaml"); var currentNews = ParseNews(cacheFile); if (currentNews != null) { DisplayNews(currentNews); } var newsButton = newsBG.GetOrNull <DropDownButtonWidget>("NEWS_BUTTON"); if (newsButton != null) { if (!fetchedNews) { // Send the mod and engine version to support version-filtered news (update prompts) newsURL += "?version={0}&mod={1}&modversion={2}".F( Uri.EscapeUriString(Game.Mods["modcontent"].Metadata.Version), Uri.EscapeUriString(Game.ModData.Manifest.Id), Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version)); // Append system profile data if the player has opted in if (Game.Settings.Debug.SendSystemInformation) { newsURL += "&sysinfoversion={0}&".F(SystemInformationVersion) + GetSystemInformation() .Select(kv => kv.Key + "=" + Uri.EscapeUriString(kv.Value.Second)) .JoinWith("&"); } new Download(newsURL, cacheFile, e => { }, e => NewsDownloadComplete(e, cacheFile, currentNews, () => newsButton.AttachPanel(newsPanel))); } newsButton.OnClick = () => newsButton.AttachPanel(newsPanel); } } } void OnRemoteDirectConnect(string host, int port) { SwitchMenu(MenuType.None); Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => SwitchMenu(MenuType.Main) }, { "directConnectHost", host }, { "directConnectPort", port }, }); } void LoadMapIntoEditor(string uid) { ConnectionLogic.Connect(IPAddress.Loopback.ToString(), Game.CreateLocalServer(uid), "", () => { Game.LoadEditor(uid); }, () => { Game.CloseServer(); SwitchMenu(MenuType.MapEditor); }); } void SetNewsStatus(string message) { message = WidgetUtils.WrapText(message, newsStatus.Bounds.Width, Game.Renderer.Fonts[newsStatus.Font]); newsStatus.GetText = () => message; }
void UpdatePlayerList() { if (orderManager.LocalClient == null) { return; } var isHost = Game.IsHost; var idx = 0; foreach (var kv in orderManager.LobbyInfo.Slots) { var key = kv.Key; var slot = kv.Value; var client = orderManager.LobbyInfo.ClientInSlot(key); Widget template = null; // get template for possible reuse if (idx < players.Children.Count) { template = players.Children[idx]; } if (client == null) { // Empty slot if (template == null || template.Id != emptySlotTemplate.Id) { template = emptySlotTemplate.Clone(); } if (isHost) { LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, worldRenderer, map); } else { LobbyUtils.SetupSlotWidget(template, slot, client); } var join = template.Get <ButtonWidget>("JOIN"); join.IsVisible = () => !slot.Closed; join.IsDisabled = () => orderManager.LocalClient.IsReady; join.OnClick = () => orderManager.IssueOrder(Order.Command("slot " + key)); } else if ((client.Index == orderManager.LocalClient.Index) || (client.Bot != null && isHost)) { // Editable player in slot if (template == null || template.Id != editablePlayerTemplate.Id) { template = editablePlayerTemplate.Clone(); } LobbyUtils.SetupLatencyWidget(template, client, orderManager); if (client.Bot != null) { LobbyUtils.SetupEditableSlotWidget(template, slot, client, orderManager, worldRenderer, map); } else { LobbyUtils.SetupEditableNameWidget(template, slot, client, orderManager, worldRenderer); } LobbyUtils.SetupEditableColorWidget(template, slot, client, orderManager, shellmapWorld, colorPreview); LobbyUtils.SetupEditableFactionWidget(template, slot, client, orderManager, factions); LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map); LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map); LobbyUtils.SetupEditableReadyWidget(template, slot, client, orderManager, map); } else { // Non-editable player in slot if (template == null || template.Id != nonEditablePlayerTemplate.Id) { template = nonEditablePlayerTemplate.Clone(); } LobbyUtils.SetupLatencyWidget(template, client, orderManager); LobbyUtils.SetupColorWidget(template, slot, client); LobbyUtils.SetupFactionWidget(template, slot, client, factions); if (isHost) { LobbyUtils.SetupEditableTeamWidget(template, slot, client, orderManager, map); LobbyUtils.SetupEditableSpawnWidget(template, slot, client, orderManager, map); LobbyUtils.SetupPlayerActionWidget(template, slot, client, orderManager, worldRenderer, lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players); } else { LobbyUtils.SetupNameWidget(template, slot, client, orderManager, worldRenderer); LobbyUtils.SetupTeamWidget(template, slot, client); LobbyUtils.SetupSpawnWidget(template, slot, client); } LobbyUtils.SetupReadyWidget(template, slot, client); } template.IsVisible = () => true; if (idx >= players.Children.Count) { players.AddChild(template); } else if (players.Children[idx].Id != template.Id) { players.ReplaceChild(players.Children[idx], template); } idx++; } // Add spectators foreach (var client in orderManager.LobbyInfo.Clients.Where(client => client.Slot == null)) { Widget template = null; var c = client; // get template for possible reuse if (idx < players.Children.Count) { template = players.Children[idx]; } // Editable spectator if (c.Index == orderManager.LocalClient.Index) { if (template == null || template.Id != editableSpectatorTemplate.Id) { template = editableSpectatorTemplate.Clone(); } LobbyUtils.SetupEditableNameWidget(template, null, c, orderManager, worldRenderer); if (client.IsAdmin) { LobbyUtils.SetupEditableReadyWidget(template, null, client, orderManager, map); } else { LobbyUtils.HideReadyWidgets(template); } } else { // Non-editable spectator if (template == null || template.Id != nonEditableSpectatorTemplate.Id) { template = nonEditableSpectatorTemplate.Clone(); } if (isHost) { LobbyUtils.SetupPlayerActionWidget(template, null, client, orderManager, worldRenderer, lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players); } else { LobbyUtils.SetupNameWidget(template, null, client, orderManager, worldRenderer); } if (client.IsAdmin) { LobbyUtils.SetupReadyWidget(template, null, client); } else { LobbyUtils.HideReadyWidgets(template); } } LobbyUtils.SetupLatencyWidget(template, c, orderManager); template.IsVisible = () => true; if (idx >= players.Children.Count) { players.AddChild(template); } else if (players.Children[idx].Id != template.Id) { players.ReplaceChild(players.Children[idx], template); } idx++; } // Spectate button if (orderManager.LocalClient.Slot != null) { Widget spec = null; if (idx < players.Children.Count) { spec = players.Children[idx]; } if (spec == null || spec.Id != newSpectatorTemplate.Id) { spec = newSpectatorTemplate.Clone(); } LobbyUtils.SetupKickSpectatorsWidget(spec, orderManager, lobby, () => panel = PanelType.Kick, () => panel = PanelType.Players, skirmishMode); var btn = spec.Get <ButtonWidget>("SPECTATE"); btn.OnClick = () => orderManager.IssueOrder(Order.Command("spectate")); btn.IsDisabled = () => orderManager.LocalClient.IsReady; btn.IsVisible = () => orderManager.LobbyInfo.GlobalSettings.AllowSpectators || orderManager.LocalClient.IsAdmin; spec.IsVisible = () => true; if (idx >= players.Children.Count) { players.AddChild(spec); } else if (players.Children[idx].Id != spec.Id) { players.ReplaceChild(players.Children[idx], spec); } idx++; } while (players.Children.Count > idx) { players.RemoveChild(players.Children[idx]); } tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList(); }
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 = OpenMultiplayerPanel; mainMenu.Get <ButtonWidget>("CONTENT_BUTTON").OnClick = () => { // Switching mods changes the world state (by disposing it), // so we can't do this inside the input handler. Game.RunAfterTick(() => { var content = modData.Manifest.Get <ModContent>(); Game.InitializeMod(content.ContentInstallerMod, new Arguments(new[] { "Content.Mod=" + modData.Manifest.Id })); }); }; 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 = OpenMissionBrowserPanel; 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; var hasMaps = modData.MapCache.Any(p => p.Visibility.HasFlag(MapVisibility.Lobby)); var skirmishButton = singleplayerMenu.Get <ButtonWidget>("SKIRMISH_BUTTON"); skirmishButton.OnClick = StartSkirmishGame; skirmishButton.Disabled = !hasMaps; var loadButton = singleplayerMenu.Get <ButtonWidget>("LOAD_BUTTON"); loadButton.IsDisabled = () => !GameSaveBrowserLogic.IsLoadPanelEnabled(modData.Manifest); loadButton.OnClick = OpenGameSaveBrowserPanel; 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 = OpenReplayBrowserPanel; 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 }, }); }; loadMapButton.Disabled = !hasMaps; 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.StartupPrompts; 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; // Check for updates in the background var webServices = modData.Manifest.Get <WebServices>(); if (Game.Settings.Debug.CheckVersion) { webServices.CheckModVersion(); } var updateLabel = rootMenu.GetOrNull("UPDATE_NOTICE"); if (updateLabel != null) { updateLabel.IsVisible = () => !newsOpen && menuType != MenuType.None && menuType != MenuType.StartupPrompts && webServices.ModVersionStatus == ModVersionStatus.Outdated; } var playerProfile = widget.GetOrNull("PLAYER_PROFILE_CONTAINER"); if (playerProfile != null) { Func <bool> minimalProfile = () => Ui.CurrentWindow() != null; Game.LoadWidget(world, "LOCAL_PROFILE_PANEL", playerProfile, new WidgetArgs() { { "minimalProfile", minimalProfile } }); } menuType = MenuType.StartupPrompts; Action onIntroductionComplete = () => { Action onSysInfoComplete = () => { LoadAndDisplayNews(webServices.GameNews, newsBG); SwitchMenu(MenuType.Main); }; if (SystemInfoPromptLogic.ShouldShowPrompt()) { Ui.OpenWindow("MAINMENU_SYSTEM_INFO_PROMPT", new WidgetArgs { { "onComplete", onSysInfoComplete } }); } else { onSysInfoComplete(); } }; if (IntroductionPromptLogic.ShouldShowPrompt()) { Game.OpenWindow("MAINMENU_INTRODUCTION_PROMPT", new WidgetArgs { { "onComplete", onIntroductionComplete } }); } else { onIntroductionComplete(); } Game.OnShellmapLoaded += OpenMenuBasedOnLastGame; } void LoadAndDisplayNews(string newsURL, Widget newsBG) { if (newsBG != null && Game.Settings.Game.FetchNews) { var cacheFile = Platform.ResolvePath(Platform.SupportDirPrefix, "news.yaml"); var currentNews = ParseNews(cacheFile); if (currentNews != null) { DisplayNews(currentNews); } var newsButton = newsBG.GetOrNull <DropDownButtonWidget>("NEWS_BUTTON"); if (newsButton != null) { if (!fetchedNews) { // Send the mod and engine version to support version-filtered news (update prompts) newsURL += "?version={0}&mod={1}&modversion={2}".F( Uri.EscapeUriString(Game.EngineVersion), Uri.EscapeUriString(Game.ModData.Manifest.Id), Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version)); // Parameter string is blank if the player has opted out newsURL += SystemInfoPromptLogic.CreateParameterString(); new Download(newsURL, cacheFile, e => { }, e => NewsDownloadComplete(e, cacheFile, currentNews, () => OpenNewsPanel(newsButton))); } newsButton.OnClick = () => OpenNewsPanel(newsButton); } } } void OpenNewsPanel(DropDownButtonWidget button) { newsOpen = true; button.AttachPanel(newsPanel, () => newsOpen = false); } void OnRemoteDirectConnect(ConnectionTarget endpoint) { SwitchMenu(MenuType.None); Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => SwitchMenu(MenuType.Main) }, { "directConnectEndPoint", endpoint }, }); } void LoadMapIntoEditor(string uid) { ConnectionLogic.Connect(Game.CreateLocalServer(uid), "", () => { Game.LoadEditor(uid); }, () => { Game.CloseServer(); SwitchMenu(MenuType.MapEditor); }); lastGameState = MenuPanel.MapEditor; } void SetNewsStatus(string message) { message = WidgetUtils.WrapText(message, newsStatus.Bounds.Width, Game.Renderer.Fonts[newsStatus.Font]); newsStatus.GetText = () => message; }
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 }, }); }; } void LoadMapIntoEditor(Map map) { ConnectionLogic.Connect(System.Net.IPAddress.Loopback.ToString(), Game.CreateLocalServer(map.Uid), "", () => { Game.LoadEditor(map.Uid); }, () => { Game.CloseServer(); menuType = MenuType.MapEditor; }); } void SetNewsStatus(string message) { message = WidgetUtils.WrapText(message, newsStatus.Bounds.Width, Game.Renderer.Fonts[newsStatus.Font]); newsStatus.GetText = () => message; }
public CustomMainMenuLogic(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 = OpenMultiplayerPanel; mainMenu.Get <ButtonWidget>("CONTENT_BUTTON").OnClick = () => { // Switching mods changes the world state (by disposing it), // so we can't do this inside the input handler. Game.RunAfterTick(() => { var content = modData.Manifest.Get <ModContent>(); Game.InitializeMod(content.ContentInstallerMod, new Arguments(new[] { "Content.Mod=" + modData.Manifest.Id })); }); }; 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 = OpenMissionBrowserPanel; 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; var hasMaps = modData.MapCache.Any(p => p.Visibility.HasFlag(MapVisibility.Lobby)); var skirmishButton = singleplayerMenu.Get <ButtonWidget>("SKIRMISH_BUTTON"); skirmishButton.OnClick = StartSkirmishGame; skirmishButton.Disabled = !hasMaps; var loadButton = singleplayerMenu.Get <ButtonWidget>("LOAD_BUTTON"); loadButton.IsDisabled = () => !GameSaveBrowserLogic.IsLoadPanelEnabled(modData.Manifest); loadButton.OnClick = OpenGameSaveBrowserPanel; 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 = OpenReplayBrowserPanel; 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 }, }); }; loadMapButton.Disabled = !hasMaps; 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.StartupPrompts; 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; // Check for updates in the background var webServices = modData.Manifest.Get <GitHubWebServices>(); if (Game.Settings.Debug.CheckVersion) { webServices.FetchRelease(() => LoadAndDisplayNews(webServices, newsBG)); } var updateLabel = rootMenu.GetOrNull("UPDATE_NOTICE"); if (updateLabel != null) { updateLabel.IsVisible = () => !newsOpen && menuType != MenuType.None && menuType != MenuType.StartupPrompts && webServices.ModVersionStatus == ModVersionStatus.Outdated; } var playerProfile = widget.GetOrNull("PLAYER_PROFILE_CONTAINER"); if (playerProfile != null) { Func <bool> minimalProfile = () => Ui.CurrentWindow() != null; Game.LoadWidget(world, "LOCAL_PROFILE_PANEL", playerProfile, new WidgetArgs() { { "minimalProfile", minimalProfile } }); } menuType = MenuType.StartupPrompts; Action onIntroductionComplete = () => { Action onSysInfoComplete = () => { SwitchMenu(MenuType.Main); }; if (SystemInfoPromptLogic.ShouldShowPrompt()) { Ui.OpenWindow("MAINMENU_SYSTEM_INFO_PROMPT", new WidgetArgs { { "onComplete", onSysInfoComplete } }); } else { onSysInfoComplete(); } }; if (IntroductionPromptLogic.ShouldShowPrompt()) { Game.OpenWindow("MAINMENU_INTRODUCTION_PROMPT", new WidgetArgs { { "onComplete", onIntroductionComplete } }); } else { onIntroductionComplete(); } Game.OnShellmapLoaded += OpenMenuBasedOnLastGame; DiscordService.UpdateStatus(DiscordState.InMenu); } void LoadAndDisplayNews(GitHubWebServices webServices, Widget newsBG) { if (newsBG != null && Game.Settings.Game.FetchNews) { var newsButton = newsBG.GetOrNull <DropDownButtonWidget>("NEWS_BUTTON"); if (newsButton != null) { DisplayNews(webServices); newsButton.OnClick = () => OpenNewsPanel(newsButton); if (webServices.NewsAlert) { OpenNewsPanel(newsButton); } } } } void DisplayNews(GitHubWebServices webServices) { newsPanel.RemoveChildren(); SetNewsStatus(""); var newsWidget = newsTemplate.Clone(); var titleLabel = newsWidget.Get <LabelWidget>("TITLE"); var newsItem = webServices.NewsItem; if (newsItem == null) { SetNewsStatus("Failed to retrieve news"); return; } titleLabel.GetText = () => newsItem.Title; var authorDateTimeLabel = newsWidget.Get <LabelWidget>("AUTHOR_DATETIME"); var authorDateTime = authorDateTimeLabel.Text.F(newsItem.Author, newsItem.DateTime.ToLocalTime()); authorDateTimeLabel.GetText = () => authorDateTime; var contentLabel = newsWidget.Get <LabelWidget>("CONTENT"); var content = newsItem.Content; content = WidgetUtils.WrapText(content, contentLabel.Bounds.Width, Game.Renderer.Fonts[contentLabel.Font]); contentLabel.GetText = () => content; contentLabel.Bounds.Height = Game.Renderer.Fonts[contentLabel.Font].Measure(content).Y; newsWidget.Bounds.Height += contentLabel.Bounds.Height; newsPanel.AddChild(newsWidget); newsPanel.Layout.AdjustChildren(); } void OpenNewsPanel(DropDownButtonWidget button) { newsOpen = true; button.AttachPanel(newsPanel, () => newsOpen = false); } void OnRemoteDirectConnect(ConnectionTarget endpoint) { SwitchMenu(MenuType.None); Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs { { "onStart", RemoveShellmapUI }, { "onExit", () => SwitchMenu(MenuType.Main) }, { "directConnectEndPoint", endpoint }, }); } void LoadMapIntoEditor(string uid) { ConnectionLogic.Connect(Game.CreateLocalServer(uid), "", () => { Game.LoadEditor(uid); }, () => { Game.CloseServer(); SwitchMenu(MenuType.MapEditor); }); DiscordService.UpdateStatus(DiscordState.InMapEditor); lastGameState = MenuPanel.MapEditor; } void SetNewsStatus(string message) { message = WidgetUtils.WrapText(message, newsStatus.Bounds.Width, Game.Renderer.Fonts[newsStatus.Font]); newsStatus.GetText = () => message; } void RemoveShellmapUI() { rootMenu.Parent.RemoveChild(rootMenu); } void StartSkirmishGame() { var map = Game.ModData.MapCache.ChooseInitialMap(Game.Settings.Server.Map, Game.CosmeticRandom); Game.Settings.Server.Map = map; Game.Settings.Save(); ConnectionLogic.Connect(Game.CreateLocalServer(map), "", OpenSkirmishLobbyPanel, () => { Game.CloseServer(); SwitchMenu(MenuType.Main); }); } void OpenMissionBrowserPanel() { SwitchMenu(MenuType.None); Game.OpenWindow("MISSIONBROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Singleplayer) }, { "onStart", () => { RemoveShellmapUI(); lastGameState = MenuPanel.Missions; } } }); } void OpenSkirmishLobbyPanel() { SwitchMenu(MenuType.None); Game.OpenWindow("SERVER_LOBBY", new WidgetArgs { { "onExit", () => { Game.Disconnect(); SwitchMenu(MenuType.Singleplayer); } }, { "onStart", () => { RemoveShellmapUI(); lastGameState = MenuPanel.Skirmish; } }, { "skirmishMode", true } }); } void OpenMultiplayerPanel() { SwitchMenu(MenuType.None); Ui.OpenWindow("MULTIPLAYER_PANEL", new WidgetArgs { { "onStart", () => { RemoveShellmapUI(); lastGameState = MenuPanel.Multiplayer; } }, { "onExit", () => SwitchMenu(MenuType.Main) }, { "directConnectEndPoint", null }, }); } void OpenReplayBrowserPanel() { SwitchMenu(MenuType.None); Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Extras) }, { "onStart", () => { RemoveShellmapUI(); lastGameState = MenuPanel.Replays; } } }); } void OpenGameSaveBrowserPanel() { SwitchMenu(MenuType.None); Ui.OpenWindow("GAMESAVE_BROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.Singleplayer) }, { "onStart", () => { RemoveShellmapUI(); lastGameState = MenuPanel.GameSaves; } }, { "isSavePanel", false }, { "world", null } }); }
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.InitializeWithMod("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"); if (Game.modData.Manifest.NewsUrl != null) { var cacheFile = GetNewsCacheFile(); var cacheValid = File.Exists(cacheFile) && DateTime.Today.ToUniversalTime() <= Game.Settings.Game.NewsFetchedDate; if (cacheValid) { DisplayNews(ReadNews(File.ReadAllBytes(cacheFile))); } else { new Download(Game.modData.Manifest.NewsUrl, e => { }, NewsDownloadComplete); } } var newsButton = newsBG.GetOrNull <DropDownButtonWidget>("NEWS_BUTTON"); newsButton.OnClick = () => { newsButton.AttachPanel(newsPanel); newsHighlighted = false; }; newsButton.IsHighlighted = () => newsHighlighted && Game.LocalTick % 50 < 25;; } }
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; 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.Type == "Mission" && !p.Map.Selectable); 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 } }); }; 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 = 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; } } void SetNewsStatus(string message) { message = WidgetUtils.WrapText(message, newsStatus.Bounds.Width, Game.Renderer.Fonts[newsStatus.Font]); newsStatus.GetText = () => message; }
public NewMainMenuLogic(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.Multiplayer); mainMenu.Get <ButtonWidget>("CONTENT_BUTTON").OnClick = () => { // Switching mods changes the world state (by disposing it), // so we can't do this inside the input handler. Game.RunAfterTick(() => { var content = modData.Manifest.Get <ModContent>(); Game.InitializeMod(content.ContentInstallerMod, new Arguments(new[] { "Content.Mod=" + modData.Manifest.Id })); }); }; 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 loadButton = singleplayerMenu.Get <ButtonWidget>("LOAD_BUTTON"); loadButton.IsDisabled = () => !GameSaveBrowserLogic.IsLoadPanelEnabled(modData.Manifest); loadButton.OnClick = OpenGameSaveBrowserPanel; var missionsButton = singleplayerMenu.Get <ButtonWidget>("MISSIONS_BUTTON"); missionsButton.OnClick = OpenMissionBrowserPanel; 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); // Multiplayer menu var multiplayerMenu = widget.Get("MULTIPLAYER_MENU"); multiplayerMenu.IsVisible = () => menuType == MenuType.Multiplayer; var onlinegameButton = multiplayerMenu.Get <ButtonWidget>("ONLINEGAME_BUTTON"); onlinegameButton.OnClick = OpenMultiplayerPanel; var worldDominationButton = multiplayerMenu.Get <ButtonWidget>("WD_BUTTON"); worldDominationButton.OnClick = OpenWorldDominationPanel; multiplayerMenu.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 = OpenReplayBrowserPanel; 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>("OTHER_TOOLS_BUTTON").OnClick = () => SwitchMenu(MenuType.OtherTools); extrasMenu.Get <ButtonWidget>("BACK_BUTTON").OnClick = () => SwitchMenu(MenuType.Main); var otherToolsMenu = widget.Get("OTHER_TOOLS_MENU"); otherToolsMenu.IsVisible = () => menuType == MenuType.OtherTools; otherToolsMenu.Get <ButtonWidget>("VOXELBROWSER_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("VXLBROWSER_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.OtherTools) }, }); }; otherToolsMenu.Get <ButtonWidget>("SOUNDPLAYER_BUTTON").OnClick = () => { SwitchMenu(MenuType.None); Game.OpenWindow("SOUND_PANEL", new WidgetArgs { { "onExit", () => SwitchMenu(MenuType.OtherTools) }, }); }; otherToolsMenu.Get <ButtonWidget>("BACK_BUTTON").OnClick = () => SwitchMenu(MenuType.Extras); // 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; // Check for updates in the background var webServices = modData.Manifest.Get <WebServices>(); if (Game.Settings.Debug.CheckVersion) { webServices.CheckModVersion(); } var updateLabel = rootMenu.GetOrNull("UPDATE_NOTICE"); if (updateLabel != null) { updateLabel.IsVisible = () => !newsOpen && menuType != MenuType.None && menuType != MenuType.SystemInfoPrompt && webServices.ModVersionStatus == ModVersionStatus.Outdated; } var playerProfile = widget.GetOrNull("PLAYER_PROFILE_CONTAINER"); if (playerProfile != null) { Func <bool> minimalProfile = () => Ui.CurrentWindow() != null; Game.LoadWidget(world, "LOCAL_PROFILE_PANEL", playerProfile, new WidgetArgs() { { "minimalProfile", minimalProfile } }); } // 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(webServices.GameNews, newsBG); }; } else { LoadAndDisplayNews(webServices.GameNews, newsBG); } Game.OnShellmapLoaded += OpenMenuBasedOnLastGame; }