protected LabelWidget(LabelWidget other) : base(other) { Text = other.Text; Align = other.Align; Bold = other.Bold; GetText = other.GetText; GetBackground = other.GetBackground; }
public DownloadPackagesLogic(Widget widget, Action afterInstall, string mirrorListUrl) { this.mirrorListUrl = mirrorListUrl; this.afterInstall = afterInstall; panel = widget.Get("INSTALL_DOWNLOAD_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); ShowDownloadDialog(); }
public D2kDownloadPackagesLogic(Widget widget, Dictionary<string,string> installData, Action afterInstall) { this.installData = installData; this.afterInstall = afterInstall; panel = widget.Get("INSTALL_DOWNLOAD_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); ShowDownloadDialog(); }
public GlobalChatLogic(Widget widget) { historyPanel = widget.Get<ScrollPanelWidget>("HISTORY_PANEL"); historyTemplate = historyPanel.Get<LabelWidget>("HISTORY_TEMPLATE"); nicknamePanel = widget.Get<ScrollPanelWidget>("NICKNAME_PANEL"); nicknameTemplate = nicknamePanel.Get("NICKNAME_TEMPLATE"); historyPanel.Bind(Game.GlobalChat.History, MakeHistoryWidget, HistoryWidgetEquals, true); nicknamePanel.Bind(Game.GlobalChat.Users, MakeUserWidget, UserWidgetEquals, false); inputBox = widget.Get<TextFieldWidget>("CHAT_TEXTFIELD"); inputBox.IsDisabled = () => Game.GlobalChat.ConnectionStatus != ChatConnectionStatus.Joined; inputBox.OnEnterKey = EnterPressed; // Set a random default nick if (Game.Settings.Chat.Nickname == new ChatSettings().Nickname) Game.Settings.Chat.Nickname += Game.CosmeticRandom.Next(100, 999); var nicknameBox = widget.Get<TextFieldWidget>("NICKNAME_TEXTFIELD"); nicknameBox.Text = Game.GlobalChat.SanitizedName(Game.Settings.Chat.Nickname); nicknameBox.OnTextEdited = () => { nicknameBox.Text = Game.GlobalChat.SanitizedName(nicknameBox.Text); }; var connectPanel = widget.Get("GLOBALCHAT_CONNECT_PANEL"); connectPanel.IsVisible = () => Game.GlobalChat.ConnectionStatus == ChatConnectionStatus.Disconnected; var disconnectButton = widget.Get<ButtonWidget>("DISCONNECT_BUTTON"); disconnectButton.OnClick = Game.GlobalChat.Disconnect; var connectAutomaticallyCheckBox = connectPanel.Get<CheckboxWidget>("CONNECT_AUTOMATICALLY_CHECKBOX"); connectAutomaticallyCheckBox.IsChecked = () => Game.Settings.Chat.ConnectAutomatically; connectAutomaticallyCheckBox.OnClick = () => { Game.Settings.Chat.ConnectAutomatically ^= true; Game.Settings.Save(); }; var connectButton = connectPanel.Get<ButtonWidget>("CONNECT_BUTTON"); connectButton.IsDisabled = () => !Game.GlobalChat.IsValidNickname(nicknameBox.Text); connectButton.OnClick = () => { Game.Settings.Chat.Nickname = nicknameBox.Text; Game.Settings.Save(); Game.GlobalChat.Connect(); }; var mainPanel = widget.Get("GLOBALCHAT_MAIN_PANEL"); mainPanel.IsVisible = () => Game.GlobalChat.ConnectionStatus != ChatConnectionStatus.Disconnected; mainPanel.Get<LabelWidget>("CHANNEL_TOPIC").GetText = () => Game.GlobalChat.Topic; if (Game.Settings.Chat.ConnectAutomatically && Game.GlobalChat.IsValidNickname(Game.Settings.Chat.Nickname)) Game.GlobalChat.Connect(); }
public CncDownloadPackagesLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] Dictionary<string,string> installData, [ObjectCreator.Param] Action continueLoading) { this.installData = installData; this.continueLoading = continueLoading; panel = widget.GetWidget("INSTALL_DOWNLOAD_PANEL"); progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL"); ShowDownloadDialog(); }
protected LabelWidget(LabelWidget other) : base(other) { Text = other.Text; Align = other.Align; Font = other.Font; TextColor = other.TextColor; Contrast = other.Contrast; ContrastColor = other.ContrastColor; WordWrap = other.WordWrap; GetText = other.GetText; GetColor = other.GetColor; GetContrastColor = other.GetContrastColor; }
public MissionBrowserLogic(Widget widget, Action onStart, Action onExit) { this.onStart = onStart; var missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST"); var template = widget.Get<ScrollItemWidget>("MISSION_TEMPLATE"); widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null; var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW"); previewWidget.Preview = () => selectedMapPreview; descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL"); description = widget.Get<LabelWidget>("MISSION_DESCRIPTION"); descriptionFont = Game.Renderer.Fonts[description.Font]; var yaml = new MiniYaml(null, Game.modData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal)).NodesDict; var missionMapPaths = yaml["Missions"].Nodes.Select(n => Path.GetFullPath(n.Key)); var maps = Game.modData.MapCache .Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Map.Path))) .Select(p => p.Map); missionList.RemoveChildren(); foreach (var m in maps) { var map = m; var item = ScrollItemWidget.Setup(template, () => selectedMapPreview != null && selectedMapPreview.Uid == map.Uid, () => SelectMap(map), StartMission); item.Get<LabelWidget>("TITLE").GetText = () => map.Title; missionList.AddChild(item); } if (maps.Any()) SelectMap(maps.First()); widget.Get<ButtonWidget>("STARTGAME_BUTTON").OnClick = StartMission; widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { Game.Disconnect(); Ui.CloseWindow(); onExit(); }; }
public DownloadPackagesLogic(Widget widget, Action afterInstall, string mirrorListUrl, string modId) { this.mirrorListUrl = mirrorListUrl; this.afterInstall = afterInstall; this.modId = modId; panel = widget.Get("INSTALL_DOWNLOAD_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); var text = "Downloading {0} assets...".F(ModMetadata.AllMods[modId].Title); panel.Get<LabelWidget>("TITLE").Text = text; ShowDownloadDialog(); }
public D2kInstallFromCDLogic(Widget widget) { panel = widget.Get("INSTALL_FROMCD_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); backButton = panel.Get<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Ui.CloseWindow; retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = CheckForDisk; installingContainer = panel.Get("INSTALLING"); insertDiskContainer = panel.Get("INSERT_DISK"); CheckForDisk(); }
public D2kExtractGameFilesLogic(Widget widget) { panel = widget.Get("EXTRACT_GAMEFILES_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); backButton = panel.Get<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Ui.CloseWindow; retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = Extract; extractingContainer = panel.Get("EXTRACTING"); copyFilesContainer = panel.Get("COPY_FILES"); Extract(); }
public InstallFromCDLogic(Widget widget, Action continueLoading) { installData = Game.ModData.Manifest.Get<ContentInstaller>(); this.continueLoading = continueLoading; panel = widget.Get("INSTALL_FROMCD_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); backButton = panel.Get<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Ui.CloseWindow; retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = CheckForDisk; installingContainer = panel.Get("INSTALLING"); insertDiskContainer = panel.Get("INSERT_DISK"); CheckForDisk(); }
public CncInstallFromCDLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] Action continueLoading) { this.continueLoading = continueLoading; panel = widget.GetWidget("INSTALL_FROMCD_PANEL"); progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL"); backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Widget.CloseWindow; retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = CheckForDisk; installingContainer = panel.GetWidget("INSTALLING"); insertDiskContainer = panel.GetWidget("INSERT_DISK"); CheckForDisk(); }
public InstallFromCDLogic(Widget widget, Action afterInstall, string modId) { this.modId = modId; installData = ModMetadata.AllMods[modId].Content; this.afterInstall = afterInstall; panel = widget.Get("INSTALL_FROMCD_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); backButton = panel.Get<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Ui.CloseWindow; retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = CheckForDisk; installingContainer = panel.Get("INSTALLING"); insertDiskContainer = panel.Get("INSERT_DISK"); CheckForDisk(); }
public ConvertGameFilesLogic(Widget widget, string[][] ExtractGameFiles, string[][] ExportToPng, string[][] ImportFromPng) { panel = widget.Get("CONVERT_ASSETS_PANEL"); progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); backButton = panel.Get<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Ui.CloseWindow; retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = Extract; extractingContainer = panel.Get("EXTRACTING"); this.ExtractGameFiles = ExtractGameFiles; this.ExportToPng = ExportToPng; this.ImportFromPng = ImportFromPng; Extract(); }
public CncInstallFromCDLogic(Widget widget, Action afterInstall, string[] filesToCopy, string[] filesToExtract) { this.afterInstall = afterInstall; this.filesToCopy = filesToCopy; this.filesToExtract = filesToExtract; panel = widget; progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); statusLabel = panel.Get<LabelWidget>("STATUS_LABEL"); backButton = panel.Get<ButtonWidget>("BACK_BUTTON"); backButton.OnClick = Ui.CloseWindow; retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON"); retryButton.OnClick = CheckForDisk; installingContainer = panel.Get("INSTALLING"); insertDiskContainer = panel.Get("INSERT_DISK"); CheckForDisk(); }
public InstallFromDiscLogic(Widget widget, ModContent content, Dictionary<string, ModContent.ModSource> sources, Action afterInstall) { this.content = content; this.sources = sources; Log.AddChannel("install", "install.log"); // this.afterInstall = afterInstall; panel = widget.Get("DISC_INSTALL_PANEL"); titleLabel = panel.Get<LabelWidget>("TITLE"); primaryButton = panel.Get<ButtonWidget>("PRIMARY_BUTTON"); secondaryButton = panel.Get<ButtonWidget>("SECONDARY_BUTTON"); // Progress view progressContainer = panel.Get("PROGRESS"); progressContainer.IsVisible = () => visible == Mode.Progress; progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR"); progressLabel = panel.Get<LabelWidget>("PROGRESS_MESSAGE"); progressLabel.IsVisible = () => visible == Mode.Progress; // Message view messageContainer = panel.Get("MESSAGE"); messageContainer.IsVisible = () => visible == Mode.Message; messageLabel = messageContainer.Get<LabelWidget>("MESSAGE_MESSAGE"); // List view listContainer = panel.Get("LIST"); listContainer.IsVisible = () => visible == Mode.List; listPanel = listContainer.Get<ScrollPanelWidget>("LIST_PANEL"); listHeaderTemplate = listPanel.Get("LIST_HEADER_TEMPLATE"); listTemplate = listPanel.Get<LabelWidget>("LIST_TEMPLATE"); listPanel.RemoveChildren(); listLabel = listContainer.Get<LabelWidget>("LIST_MESSAGE"); DetectContentDisks(); }
public MissionBrowserLogic(Widget widget, World world, Action onStart, Action onExit) { this.onStart = onStart; missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST"); headerTemplate = widget.Get<ScrollItemWidget>("HEADER"); template = widget.Get<ScrollItemWidget>("TEMPLATE"); var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE"); if (title != null) title.GetText = () => playingVideo != PlayingVideo.None ? selectedMapPreview.Title : title.Text; widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null; var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW"); previewWidget.Preview = () => selectedMapPreview; previewWidget.IsVisible = () => playingVideo == PlayingVideo.None; videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO"); widget.Get("MISSION_BIN").IsVisible = () => playingVideo != PlayingVideo.None; fullscreenVideoPlayer = Ui.LoadWidget<BackgroundWidget>("FULLSCREEN_PLAYER", Ui.Root, new WidgetArgs { { "world", world } }); descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL"); description = descriptionPanel.Get<LabelWidget>("MISSION_DESCRIPTION"); descriptionFont = Game.Renderer.Fonts[description.Font]; difficultyButton = widget.Get<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); gameSpeedButton = widget.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON"); startBriefingVideoButton = widget.Get<ButtonWidget>("START_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton = widget.Get<ButtonWidget>("STOP_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton.IsVisible = () => playingVideo == PlayingVideo.Briefing; stopBriefingVideoButton.OnClick = () => StopVideo(videoPlayer); startInfoVideoButton = widget.Get<ButtonWidget>("START_INFO_VIDEO_BUTTON"); stopInfoVideoButton = widget.Get<ButtonWidget>("STOP_INFO_VIDEO_BUTTON"); stopInfoVideoButton.IsVisible = () => playingVideo == PlayingVideo.Info; stopInfoVideoButton.OnClick = () => StopVideo(videoPlayer); var allMaps = new List<Map>(); missionList.RemoveChildren(); // Add a group for each campaign if (Game.ModData.Manifest.Missions.Any()) { var yaml = Game.ModData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal); foreach (var kv in yaml) { var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)); var maps = Game.ModData.MapCache .Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Map.Path))) .Select(p => p.Map); CreateMissionGroup(kv.Key, maps); allMaps.AddRange(maps); } } // Add an additional group for loose missions var looseMissions = Game.ModData.MapCache .Where(p => p.Status == MapStatus.Available && p.Map.Visibility.HasFlag(MapVisibility.MissionSelector) && !allMaps.Contains(p.Map)) .Select(p => p.Map); if (looseMissions.Any()) { CreateMissionGroup("Missions", looseMissions); allMaps.AddRange(looseMissions); } if (allMaps.Any()) SelectMap(allMaps.First()); var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON"); startButton.OnClick = StartMissionClicked; startButton.IsDisabled = () => selectedMapPreview == null || selectedMapPreview.RuleStatus != MapRuleStatus.Cached; widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { StopVideo(videoPlayer); Game.Disconnect(); Ui.CloseWindow(); onExit(); }; }
public MissionBrowserLogic(Widget widget, ModData modData, World world, Action onStart, Action onExit) { this.modData = modData; this.onStart = onStart; Game.BeforeGameStart += OnGameStart; missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST"); headerTemplate = widget.Get<ScrollItemWidget>("HEADER"); template = widget.Get<ScrollItemWidget>("TEMPLATE"); var title = widget.GetOrNull<LabelWidget>("MISSIONBROWSER_TITLE"); if (title != null) title.GetText = () => playingVideo != PlayingVideo.None ? selectedMap.Title : title.Text; widget.Get("MISSION_INFO").IsVisible = () => selectedMap != null; var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW"); previewWidget.Preview = () => selectedMap; previewWidget.IsVisible = () => playingVideo == PlayingVideo.None; videoPlayer = widget.Get<VqaPlayerWidget>("MISSION_VIDEO"); widget.Get("MISSION_BIN").IsVisible = () => playingVideo != PlayingVideo.None; fullscreenVideoPlayer = Ui.LoadWidget<BackgroundWidget>("FULLSCREEN_PLAYER", Ui.Root, new WidgetArgs { { "world", world } }); descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL"); description = descriptionPanel.Get<LabelWidget>("MISSION_DESCRIPTION"); descriptionFont = Game.Renderer.Fonts[description.Font]; difficultyButton = widget.Get<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); gameSpeedButton = widget.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON"); startBriefingVideoButton = widget.Get<ButtonWidget>("START_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton = widget.Get<ButtonWidget>("STOP_BRIEFING_VIDEO_BUTTON"); stopBriefingVideoButton.IsVisible = () => playingVideo == PlayingVideo.Briefing; stopBriefingVideoButton.OnClick = () => StopVideo(videoPlayer); startInfoVideoButton = widget.Get<ButtonWidget>("START_INFO_VIDEO_BUTTON"); stopInfoVideoButton = widget.Get<ButtonWidget>("STOP_INFO_VIDEO_BUTTON"); stopInfoVideoButton.IsVisible = () => playingVideo == PlayingVideo.Info; stopInfoVideoButton.OnClick = () => StopVideo(videoPlayer); var allPreviews = new List<MapPreview>(); missionList.RemoveChildren(); // Add a group for each campaign if (modData.Manifest.Missions.Any()) { var yaml = MiniYaml.Merge(modData.Manifest.Missions.Select( m => MiniYaml.FromStream(modData.DefaultFileSystem.Open(m), m))); foreach (var kv in yaml) { var missionMapPaths = kv.Value.Nodes.Select(n => Path.GetFullPath(n.Key)).ToList(); var previews = modData.MapCache .Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(p.Package.Name)) .OrderBy(p => missionMapPaths.IndexOf(p.Package.Name)); CreateMissionGroup(kv.Key, previews); allPreviews.AddRange(previews); } } // Add an additional group for loose missions var loosePreviews = modData.MapCache .Where(p => p.Status == MapStatus.Available && p.Visibility.HasFlag(MapVisibility.MissionSelector) && !allPreviews.Any(a => a.Uid == p.Uid)); if (loosePreviews.Any()) { CreateMissionGroup("Missions", loosePreviews); allPreviews.AddRange(loosePreviews); } if (allPreviews.Any()) SelectMap(allPreviews.First()); // Preload map preview and rules to reduce jank new Thread(() => { foreach (var p in allPreviews) { p.GetMinimap(); p.PreloadRules(); } }).Start(); var startButton = widget.Get<ButtonWidget>("STARTGAME_BUTTON"); startButton.OnClick = StartMissionClicked; startButton.IsDisabled = () => selectedMap == null || selectedMap.InvalidCustomRules; widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => { StopVideo(videoPlayer); Game.Disconnect(); Ui.CloseWindow(); onExit(); }; }
internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager, Action onExit, Action onStart, bool skirmishMode) { Map = MapCache.UnknownMap; lobby = widget; this.modData = modData; this.orderManager = orderManager; this.onStart = onStart; this.onExit = onExit; this.skirmishMode = skirmishMode; // TODO: This needs to be reworked to support per-map tech levels, bots, etc. this.modRules = modData.DefaultRules; shellmapWorld = worldRenderer.World; orderManager.AddChatLine += AddChatLine; Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdatePlayerList; Game.BeforeGameStart += OnGameStart; Game.ConnectionStateChanged += ConnectionStateChanged; var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME"); if (name != null) name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName; Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs { { "orderManager", orderManager }, { "lobby", this } }); UpdateCurrentMap(); var playerBin = Ui.LoadWidget("LOBBY_PLAYER_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); playerBin.IsVisible = () => panel == PanelType.Players; players = playerBin.Get<ScrollPanelWidget>("LOBBY_PLAYERS"); editablePlayerTemplate = players.Get("TEMPLATE_EDITABLE_PLAYER"); nonEditablePlayerTemplate = players.Get("TEMPLATE_NONEDITABLE_PLAYER"); emptySlotTemplate = players.Get("TEMPLATE_EMPTY"); editableSpectatorTemplate = players.Get("TEMPLATE_EDITABLE_SPECTATOR"); nonEditableSpectatorTemplate = players.Get("TEMPLATE_NONEDITABLE_SPECTATOR"); newSpectatorTemplate = players.Get("TEMPLATE_NEW_SPECTATOR"); colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER"); colorPreview.Color = Game.Settings.Player.Color; foreach (var f in modRules.Actors["world"].TraitInfos<FactionInfo>()) factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description }); var gameStarting = false; Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || !Map.RulesLoaded || Map.InvalidCustomRules || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON"); if (mapButton != null) { mapButton.IsDisabled = () => gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; mapButton.OnClick = () => { var onSelect = new Action<string>(uid => { // Don't select the same map again if (uid == Map.Uid) return; orderManager.IssueOrder(Order.Command("map " + uid)); Game.Settings.Server.Map = uid; Game.Settings.Save(); }); Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { { "initialMap", Map.Uid }, { "initialTab", MapClassification.System }, { "onExit", DoNothing }, { "onSelect", Game.IsHost ? onSelect : null }, { "filter", MapVisibility.Lobby }, }); }; } var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON"); if (slotsButton != null) { slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players || (orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) && orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) == 0); slotsButton.OnMouseDown = _ => { var botNames = Map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name); var options = new Dictionary<string, IEnumerable<DropDownOption>>(); var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots)) { var botOptions = new List<DropDownOption>() { new DropDownOption() { Title = "Add", IsSelected = () => false, OnClick = () => { foreach (var slot in orderManager.LobbyInfo.Slots) { var bot = botNames.Random(Game.CosmeticRandom); var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); if (slot.Value.AllowBots == true && (c == null || c.Bot != null)) orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot.Key, botController.Index, bot))); } } } }; if (orderManager.LobbyInfo.Clients.Any(c => c.Bot != null)) { botOptions.Add(new DropDownOption() { Title = "Remove", IsSelected = () => false, OnClick = () => { foreach (var slot in orderManager.LobbyInfo.Slots) { var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); if (c != null && c.Bot != null) orderManager.IssueOrder(Order.Command("slot_open " + slot.Value.PlayerReference)); } } }); } options.Add("Configure Bots", botOptions); } var teamCount = (orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) + 1) / 2; if (teamCount >= 1) { var teamOptions = Enumerable.Range(2, teamCount - 1).Reverse().Select(d => new DropDownOption { Title = "{0} Teams".F(d), IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString()))) }).ToList(); if (orderManager.LobbyInfo.Slots.Any(s => s.Value.AllowBots)) { teamOptions.Add(new DropDownOption { Title = "Humans vs Bots", IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams 1")) }); } teamOptions.Add(new DropDownOption { Title = "Free for all", IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams 0")) }); options.Add("Configure Teams", teamOptions); } Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; slotsButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 175, options, setupItem); }; } var optionsBin = Ui.LoadWidget("LOBBY_OPTIONS_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); optionsBin.IsVisible = () => panel == PanelType.Options; var musicBin = Ui.LoadWidget("LOBBY_MUSIC_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs { { "onExit", DoNothing }, { "world", worldRenderer.World } }); musicBin.IsVisible = () => panel == PanelType.Music; var optionsTab = lobby.Get<ButtonWidget>("OPTIONS_TAB"); optionsTab.IsHighlighted = () => panel == PanelType.Options; optionsTab.IsDisabled = () => !Map.RulesLoaded || Map.InvalidCustomRules || panel == PanelType.Kick || panel == PanelType.ForceStart; optionsTab.OnClick = () => panel = PanelType.Options; var playersTab = lobby.Get<ButtonWidget>("PLAYERS_TAB"); playersTab.IsHighlighted = () => panel == PanelType.Players; playersTab.IsDisabled = () => panel == PanelType.Kick || panel == PanelType.ForceStart; playersTab.OnClick = () => panel = PanelType.Players; var musicTab = lobby.Get<ButtonWidget>("MUSIC_TAB"); musicTab.IsHighlighted = () => panel == PanelType.Music; musicTab.IsDisabled = () => panel == PanelType.Kick || panel == PanelType.ForceStart; musicTab.OnClick = () => panel = PanelType.Music; // Force start panel Action startGame = () => { gameStarting = true; orderManager.IssueOrder(Order.Command("startgame")); }; var startGameButton = lobby.GetOrNull<ButtonWidget>("START_GAME_BUTTON"); if (startGameButton != null) { startGameButton.IsDisabled = () => configurationDisabled() || Map.Status != MapStatus.Available || orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) || (orderManager.LobbyInfo.GlobalSettings.DisableSingleplayer && orderManager.LobbyInfo.IsSinglePlayer); startGameButton.OnClick = () => { // Bots and admins don't count if (orderManager.LobbyInfo.Clients.Any(c => c.Slot != null && !c.IsAdmin && c.Bot == null && !c.IsReady)) panel = PanelType.ForceStart; else startGame(); }; } var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); forceStartBin.IsVisible = () => panel == PanelType.ForceStart; forceStartBin.Get("KICK_WARNING").IsVisible = () => orderManager.LobbyInfo.Clients.Any(c => c.IsInvalid); forceStartBin.Get<ButtonWidget>("OK_BUTTON").OnClick = startGame; forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players; // Options panel var allowCheats = optionsBin.GetOrNull<CheckboxWidget>("ALLOWCHEATS_CHECKBOX"); if (allowCheats != null) { var cheatsLocked = new CachedTransform<MapPreview, bool>( map => map.Rules.Actors["player"].TraitInfo<DeveloperModeInfo>().Locked); allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats; allowCheats.IsDisabled = () => configurationDisabled() || cheatsLocked.Update(Map); allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); } var crates = optionsBin.GetOrNull<CheckboxWidget>("CRATES_CHECKBOX"); if (crates != null) { var cratesLocked = new CachedTransform<MapPreview, bool>(map => { var crateSpawner = map.Rules.Actors["world"].TraitInfoOrDefault<CrateSpawnerInfo>(); return crateSpawner == null || crateSpawner.Locked; }); crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates; crates.IsDisabled = () => configurationDisabled() || cratesLocked.Update(Map); crates.OnClick = () => orderManager.IssueOrder(Order.Command( "crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates))); } var creeps = optionsBin.GetOrNull<CheckboxWidget>("CREEPS_CHECKBOX"); if (creeps != null) { var creepsLocked = new CachedTransform<MapPreview, bool>(map => { var mapCreeps = map.Rules.Actors["world"].TraitInfoOrDefault<MapCreepsInfo>(); return mapCreeps == null || mapCreeps.Locked; }); creeps.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Creeps; creeps.IsDisabled = () => configurationDisabled() || creepsLocked.Update(Map); creeps.OnClick = () => orderManager.IssueOrder(Order.Command( "creeps {0}".F(!orderManager.LobbyInfo.GlobalSettings.Creeps))); } var allybuildradius = optionsBin.GetOrNull<CheckboxWidget>("ALLYBUILDRADIUS_CHECKBOX"); if (allybuildradius != null) { var allyBuildRadiusLocked = new CachedTransform<MapPreview, bool>(map => { var mapBuildRadius = map.Rules.Actors["world"].TraitInfoOrDefault<MapBuildRadiusInfo>(); return mapBuildRadius == null || mapBuildRadius.AllyBuildRadiusLocked; }); allybuildradius.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius; allybuildradius.IsDisabled = () => configurationDisabled() || allyBuildRadiusLocked.Update(Map); allybuildradius.OnClick = () => orderManager.IssueOrder(Order.Command( "allybuildradius {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius))); } var shortGame = optionsBin.GetOrNull<CheckboxWidget>("SHORTGAME_CHECKBOX"); if (shortGame != null) { var shortGameLocked = new CachedTransform<MapPreview, bool>( map => map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>().ShortGameLocked); shortGame.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.ShortGame; shortGame.IsDisabled = () => configurationDisabled() || shortGameLocked.Update(Map); shortGame.OnClick = () => orderManager.IssueOrder(Order.Command( "shortgame {0}".F(!orderManager.LobbyInfo.GlobalSettings.ShortGame))); } var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); if (difficulty != null) { var mapOptions = new CachedTransform<MapPreview, MapOptionsInfo>( map => map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>()); difficulty.IsVisible = () => Map.RulesLoaded && mapOptions.Update(Map).Difficulties.Any(); difficulty.IsDisabled = () => configurationDisabled() || mapOptions.Update(Map).DifficultyLocked; difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty; difficulty.OnMouseDown = _ => { var options = mapOptions.Update(Map).Difficulties.Select(d => new DropDownOption { Title = d, IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d, OnClick = () => orderManager.IssueOrder(Order.Command("difficulty {0}".F(d))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; optionsBin.Get<LabelWidget>("DIFFICULTY_DESC").IsVisible = difficulty.IsVisible; } var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON"); if (startingUnits != null) { var startUnitsInfos = new CachedTransform<MapPreview, IEnumerable<MPStartUnitsInfo>>( map => map.Rules.Actors["world"].TraitInfos<MPStartUnitsInfo>()); var startUnitsLocked = new CachedTransform<MapPreview, bool>(map => { var spawnUnitsInfo = map.Rules.Actors["world"].TraitInfoOrDefault<SpawnMPUnitsInfo>(); return spawnUnitsInfo == null || spawnUnitsInfo.Locked; }); Func<string, string> className = c => { var selectedClass = startUnitsInfos.Update(Map).Where(s => s.Class == c).Select(u => u.ClassName).FirstOrDefault(); return selectedClass != null ? selectedClass : c; }; startingUnits.IsDisabled = () => configurationDisabled() || startUnitsLocked.Update(Map); startingUnits.GetText = () => !Map.RulesLoaded || startUnitsLocked.Update(Map) ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass); startingUnits.OnMouseDown = _ => { var classes = startUnitsInfos.Update(Map).Select(a => a.Class).Distinct(); var options = classes.Select(c => new DropDownOption { Title = className(c), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass == c, OnClick = () => orderManager.IssueOrder(Order.Command("startingunits {0}".F(c))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; startingUnits.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; optionsBin.Get<LabelWidget>("STARTINGUNITS_DESC").IsVisible = startingUnits.IsVisible; } var startingCash = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGCASH_DROPDOWNBUTTON"); if (startingCash != null) { var playerResources = new CachedTransform<MapPreview, PlayerResourcesInfo>( map => map.Rules.Actors["player"].TraitInfo<PlayerResourcesInfo>()); startingCash.IsDisabled = () => configurationDisabled() || playerResources.Update(Map).DefaultCashLocked; startingCash.GetText = () => !Map.RulesLoaded || playerResources.Update(Map).DefaultCashLocked ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash); startingCash.OnMouseDown = _ => { var options = playerResources.Update(Map).SelectableCash.Select(c => new DropDownOption { Title = "${0}".F(c), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c, OnClick = () => orderManager.IssueOrder(Order.Command("startingcash {0}".F(c))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; startingCash.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; } var techLevel = optionsBin.GetOrNull<DropDownButtonWidget>("TECHLEVEL_DROPDOWNBUTTON"); if (techLevel != null) { var mapOptions = new CachedTransform<MapPreview, MapOptionsInfo>( map => map.Rules.Actors["world"].TraitInfo<MapOptionsInfo>()); var techLevels = new CachedTransform<MapPreview, List<ProvidesTechPrerequisiteInfo>>( map => map.Rules.Actors["player"].TraitInfos<ProvidesTechPrerequisiteInfo>().ToList()); techLevel.IsVisible = () => Map.RulesLoaded && techLevels.Update(Map).Any(); var techLevelDescription = optionsBin.GetOrNull<LabelWidget>("TECHLEVEL_DESC"); if (techLevelDescription != null) techLevelDescription.IsVisible = techLevel.IsVisible; techLevel.IsDisabled = () => configurationDisabled() || mapOptions.Update(Map).TechLevelLocked; techLevel.GetText = () => !Map.RulesLoaded || mapOptions.Update(Map).TechLevelLocked ? "Not Available" : "{0}".F(orderManager.LobbyInfo.GlobalSettings.TechLevel); techLevel.OnMouseDown = _ => { var options = techLevels.Update(Map).Select(c => new DropDownOption { Title = "{0}".F(c.Name), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.TechLevel == c.Name, OnClick = () => orderManager.IssueOrder(Order.Command("techlevel {0}".F(c.Name))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; techLevel.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; } var gameSpeed = optionsBin.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON"); if (gameSpeed != null) { var speeds = modData.Manifest.Get<GameSpeeds>().Speeds; gameSpeed.IsDisabled = configurationDisabled; gameSpeed.GetText = () => { if (Map.Status != MapStatus.Available) return "Not Available"; GameSpeed speed; if (!speeds.TryGetValue(orderManager.LobbyInfo.GlobalSettings.GameSpeedType, out speed)) return "Unknown"; return speed.Name; }; gameSpeed.OnMouseDown = _ => { var options = speeds.Select(s => new DropDownOption { Title = s.Value.Name, IsSelected = () => orderManager.LobbyInfo.GlobalSettings.GameSpeedType == s.Key, OnClick = () => orderManager.IssueOrder(Order.Command("gamespeed {0}".F(s.Key))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; gameSpeed.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; } var exploredMap = optionsBin.GetOrNull<CheckboxWidget>("EXPLORED_MAP_CHECKBOX"); if (exploredMap != null) { var exploredMapLocked = new CachedTransform<MapPreview, bool>( map => map.Rules.Actors["player"].TraitInfo<ShroudInfo>().ExploredMapLocked); exploredMap.IsChecked = () => !orderManager.LobbyInfo.GlobalSettings.Shroud; exploredMap.IsDisabled = () => configurationDisabled() || exploredMapLocked.Update(Map); exploredMap.OnClick = () => orderManager.IssueOrder(Order.Command( "shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud))); } var enableFog = optionsBin.GetOrNull<CheckboxWidget>("FOG_CHECKBOX"); if (enableFog != null) { var fogLocked = new CachedTransform<MapPreview, bool>( map => map.Rules.Actors["player"].TraitInfo<ShroudInfo>().FogLocked); enableFog.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Fog; enableFog.IsDisabled = () => configurationDisabled() || fogLocked.Update(Map); enableFog.OnClick = () => orderManager.IssueOrder(Order.Command( "fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog))); } var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON"); disconnectButton.OnClick = () => { CloseWindow(); onExit(); }; if (skirmishMode) disconnectButton.Text = "Back"; var globalChat = Game.LoadWidget(null, "LOBBY_GLOBALCHAT_PANEL", lobby.Get("GLOBALCHAT_ROOT"), new WidgetArgs()); var globalChatInput = globalChat.Get<TextFieldWidget>("CHAT_TEXTFIELD"); globalChat.IsVisible = () => chatPanel == ChatPanelType.Global; var globalChatTab = lobby.Get<ButtonWidget>("GLOBALCHAT_TAB"); globalChatTab.IsHighlighted = () => chatPanel == ChatPanelType.Global; globalChatTab.OnClick = () => { chatPanel = ChatPanelType.Global; globalChatInput.TakeKeyboardFocus(); }; var globalChatLabel = globalChatTab.Text; globalChatTab.GetText = () => { if (globalChatUnreadMessages == 0 || chatPanel == ChatPanelType.Global) return globalChatLabel; return globalChatLabel + " ({0})".F(globalChatUnreadMessages); }; globalChatLastReadMessages = Game.GlobalChat.History.Count(m => m.Type == ChatMessageType.Message); var lobbyChat = lobby.Get("LOBBYCHAT"); lobbyChat.IsVisible = () => chatPanel == ChatPanelType.Lobby; chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE"); var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD"); chatTextField.TakeKeyboardFocus(); chatTextField.OnEnterKey = () => { if (chatTextField.Text.Length == 0) return true; // Always scroll to bottom when we've typed something lobbyChatPanel.ScrollToBottom(); orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text)); chatTextField.Text = ""; return true; }; chatTextField.OnTabKey = () => { var previousText = chatTextField.Text; chatTextField.Text = tabCompletion.Complete(chatTextField.Text); chatTextField.CursorPosition = chatTextField.Text.Length; if (chatTextField.Text == previousText) return SwitchTeamChat(); else return true; }; chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; }; var lobbyChatTab = lobby.Get<ButtonWidget>("LOBBYCHAT_TAB"); lobbyChatTab.IsHighlighted = () => chatPanel == ChatPanelType.Lobby; lobbyChatTab.OnClick = () => { chatPanel = ChatPanelType.Lobby; chatTextField.TakeKeyboardFocus(); }; var lobbyChatLabel = lobbyChatTab.Text; lobbyChatTab.GetText = () => { if (lobbyChatUnreadMessages == 0 || chatPanel == ChatPanelType.Lobby) return lobbyChatLabel; return lobbyChatLabel + " ({0})".F(lobbyChatUnreadMessages); }; lobbyChatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY"); chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE"); lobbyChatPanel.RemoveChildren(); var settingsButton = lobby.GetOrNull<ButtonWidget>("SETTINGS_BUTTON"); if (settingsButton != null) { settingsButton.OnClick = () => Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs { { "onExit", DoNothing }, { "worldRenderer", worldRenderer } }); } // Add a bot on the first lobbyinfo update if (skirmishMode) addBotOnMapLoad = true; }
static Widget MakeLabelWidget(LabelWidget template, object item) { var itemString = item.ToString(); var widget = (LabelWidget)template.Clone(); var font = Game.Renderer.Fonts[widget.Font]; itemString = WidgetUtils.WrapText(itemString, widget.Bounds.Width, font); widget.Bounds.Height = font.Measure(itemString).Y; widget.GetText = () => itemString; return widget; }
// This is shit void LayoutDialog(Widget bg) { foreach (var c in controls) bg.RemoveChild(c); controls.Clear(); var y = 50; var margin = 20; var labelWidth = (bg.Bounds.Width - 3 * margin) / 3; var ts = new LabelWidget { Font = "Bold", Bounds = new Rectangle(margin + labelWidth + 10, y, labelWidth, 25), Text = "Their Stance", Align = TextAlign.Left, }; bg.AddChild(ts); controls.Add(ts); var ms = new LabelWidget { Font = "Bold", Bounds = new Rectangle(margin + 2 * labelWidth + 20, y, labelWidth, 25), Text = "My Stance", Align = TextAlign.Left, }; bg.AddChild(ms); controls.Add(ms); y += 35; foreach (var p in world.Players.Where(a => a != world.LocalPlayer && !a.NonCombatant)) { var pp = p; var label = new LabelWidget { Bounds = new Rectangle(margin, y, labelWidth, 25), Text = p.PlayerName, Align = TextAlign.Left, Font = "Bold", Color = p.Color.RGB, }; bg.AddChild(label); controls.Add(label); var theirStance = new LabelWidget { Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25), Text = p.PlayerName, Align = TextAlign.Left, GetText = () => pp.Stances[ world.LocalPlayer ].ToString(), }; bg.AddChild(theirStance); controls.Add(theirStance); var myStance = new DropDownButtonWidget { Bounds = new Rectangle( margin + 2 * labelWidth + 20, y, labelWidth, 25), GetText = () => world.LocalPlayer.Stances[ pp ].ToString(), }; if (!p.World.LobbyInfo.GlobalSettings.FragileAlliances) myStance.Disabled = true; myStance.OnMouseDown = mi => ShowDropDown(pp, myStance); bg.AddChild(myStance); controls.Add(myStance); y += 35; } }
void SetupWidget(Widget widget, LabelWidget objectiveText, LabelWidget objectiveStatus, Objective objective) { var font = Game.Renderer.Fonts[objectiveText.Font]; var text = WidgetUtils.WrapText(objective.Text, objectiveText.Bounds.Width, font); widget.Bounds.Height = objectiveText.Bounds.Height = objectiveStatus.Bounds.Height = font.Measure(text).Y; objectiveText.GetText = () => text; objectiveStatus.GetText = () => GetObjectiveStatusText(objective.Status); }
internal LobbyLogic(Widget widget, WorldRenderer worldRenderer, OrderManager orderManager, Action onExit, Action onStart, bool skirmishMode, Ruleset modRules) { lobby = widget; this.orderManager = orderManager; this.onStart = onStart; this.onExit = onExit; this.skirmishMode = skirmishMode; this.modRules = modRules; shellmapWorld = worldRenderer.World; orderManager.AddChatLine += AddChatLine; Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdatePlayerList; Game.BeforeGameStart += OnGameStart; Game.ConnectionStateChanged += ConnectionStateChanged; var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME"); if (name != null) name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName; Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs { { "orderManager", orderManager }, { "lobby", this } }); UpdateCurrentMap(); players = Ui.LoadWidget<ScrollPanelWidget>("LOBBY_PLAYER_BIN", lobby.Get("PLAYER_BIN_ROOT"), new WidgetArgs()); players.IsVisible = () => panel == PanelType.Players; var playerBinHeaders = lobby.GetOrNull<ContainerWidget>("LABEL_CONTAINER"); if (playerBinHeaders != null) playerBinHeaders.IsVisible = () => panel == PanelType.Players; editablePlayerTemplate = players.Get("TEMPLATE_EDITABLE_PLAYER"); nonEditablePlayerTemplate = players.Get("TEMPLATE_NONEDITABLE_PLAYER"); emptySlotTemplate = players.Get("TEMPLATE_EMPTY"); editableSpectatorTemplate = players.Get("TEMPLATE_EDITABLE_SPECTATOR"); nonEditableSpectatorTemplate = players.Get("TEMPLATE_NONEDITABLE_SPECTATOR"); newSpectatorTemplate = players.Get("TEMPLATE_NEW_SPECTATOR"); colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER"); colorPreview.Color = Game.Settings.Player.Color; foreach (var f in modRules.Actors["world"].Traits.WithInterface<FactionInfo>()) factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description }); var gameStarting = false; Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON"); if (mapButton != null) { mapButton.IsDisabled = () => gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; mapButton.OnClick = () => { var onSelect = new Action<string>(uid => { // Don't select the same map again if (uid == Map.Uid) return; orderManager.IssueOrder(Order.Command("map " + uid)); Game.Settings.Server.Map = uid; Game.Settings.Save(); }); Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { { "initialMap", Map.Uid }, { "initialTab", MapClassification.System }, { "onExit", DoNothing }, { "onSelect", Game.IsHost ? onSelect : null }, { "filter", MapVisibility.Lobby }, }); }; } var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON"); if (slotsButton != null) { slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players || Map.RuleStatus != MapRuleStatus.Cached || !orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots || !s.LockTeam); var botNames = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name); slotsButton.OnMouseDown = _ => { var options = new Dictionary<string, IEnumerable<DropDownOption>>(); var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots)) { var botOptions = new List<DropDownOption>() { new DropDownOption() { Title = "Add", IsSelected = () => false, OnClick = () => { foreach (var slot in orderManager.LobbyInfo.Slots) { var bot = botNames.Random(Game.CosmeticRandom); var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); if (slot.Value.AllowBots == true && (c == null || c.Bot != null)) orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot.Key, botController.Index, bot))); } } } }; if (orderManager.LobbyInfo.Clients.Any(c => c.Bot != null)) { botOptions.Add(new DropDownOption() { Title = "Remove", IsSelected = () => false, OnClick = () => { foreach (var slot in orderManager.LobbyInfo.Slots) { var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); if (c != null && c.Bot != null) orderManager.IssueOrder(Order.Command("slot_open " + slot.Value.PlayerReference)); } } }); } options.Add("Configure Bots", botOptions); } var teamCount = (orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) + 1) / 2; if (teamCount >= 1) { var teamOptions = Enumerable.Range(2, teamCount - 1).Reverse().Select(d => new DropDownOption { Title = "{0} Teams".F(d), IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString()))) }).ToList(); if (orderManager.LobbyInfo.Slots.Any(s => s.Value.AllowBots)) { teamOptions.Add(new DropDownOption { Title = "Humans vs Bots", IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams 1")) }); } teamOptions.Add(new DropDownOption { Title = "Free for all", IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams 0")) }); options.Add("Configure Teams", teamOptions); } Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; slotsButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 175, options, setupItem); }; } var optionsBin = Ui.LoadWidget("LOBBY_OPTIONS_BIN", lobby, new WidgetArgs()); optionsBin.IsVisible = () => panel == PanelType.Options; var optionsButton = lobby.Get<ButtonWidget>("OPTIONS_BUTTON"); optionsButton.IsDisabled = () => Map.RuleStatus != MapRuleStatus.Cached || panel == PanelType.Kick || panel == PanelType.ForceStart; optionsButton.GetText = () => panel == PanelType.Options ? "Players" : "Options"; optionsButton.OnClick = () => panel = (panel == PanelType.Options) ? PanelType.Players : PanelType.Options; // Force start panel Action startGame = () => { gameStarting = true; orderManager.IssueOrder(Order.Command("startgame")); }; var startGameButton = lobby.GetOrNull<ButtonWidget>("START_GAME_BUTTON"); if (startGameButton != null) { startGameButton.IsDisabled = () => configurationDisabled() || Map.RuleStatus != MapRuleStatus.Cached || orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null); startGameButton.OnClick = () => { Func<KeyValuePair<string, Session.Slot>, bool> notReady = sl => { var cl = orderManager.LobbyInfo.ClientInSlot(sl.Key); // Bots and admins don't count return cl != null && !cl.IsAdmin && cl.Bot == null && !cl.IsReady; }; if (orderManager.LobbyInfo.Slots.Any(notReady)) panel = PanelType.ForceStart; else startGame(); }; } var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby, new WidgetArgs()); forceStartBin.IsVisible = () => panel == PanelType.ForceStart; forceStartBin.Get("KICK_WARNING").IsVisible = () => orderManager.LobbyInfo.Clients.Any(c => c.IsInvalid); forceStartBin.Get<ButtonWidget>("OK_BUTTON").OnClick = startGame; forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players; // Options panel var allowCheats = optionsBin.GetOrNull<CheckboxWidget>("ALLOWCHEATS_CHECKBOX"); if (allowCheats != null) { allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats; allowCheats.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Cheats.HasValue || configurationDisabled(); allowCheats.OnClick = () => orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); } var crates = optionsBin.GetOrNull<CheckboxWidget>("CRATES_CHECKBOX"); if (crates != null) { crates.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Crates; crates.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Crates.HasValue || configurationDisabled(); crates.OnClick = () => orderManager.IssueOrder(Order.Command( "crates {0}".F(!orderManager.LobbyInfo.GlobalSettings.Crates))); } var creeps = optionsBin.GetOrNull<CheckboxWidget>("CREEPS_CHECKBOX"); if (creeps != null) { creeps.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Creeps; creeps.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Creeps.HasValue || configurationDisabled(); creeps.OnClick = () => orderManager.IssueOrder(Order.Command( "creeps {0}".F(!orderManager.LobbyInfo.GlobalSettings.Creeps))); } var allybuildradius = optionsBin.GetOrNull<CheckboxWidget>("ALLYBUILDRADIUS_CHECKBOX"); if (allybuildradius != null) { allybuildradius.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius; allybuildradius.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.AllyBuildRadius.HasValue || configurationDisabled(); allybuildradius.OnClick = () => orderManager.IssueOrder(Order.Command( "allybuildradius {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllyBuildRadius))); } var fragileAlliance = optionsBin.GetOrNull<CheckboxWidget>("FRAGILEALLIANCES_CHECKBOX"); if (fragileAlliance != null) { fragileAlliance.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.FragileAlliances; fragileAlliance.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.FragileAlliances.HasValue || configurationDisabled(); fragileAlliance.OnClick = () => orderManager.IssueOrder(Order.Command( "fragilealliance {0}".F(!orderManager.LobbyInfo.GlobalSettings.FragileAlliances))); } var shortGame = optionsBin.GetOrNull<CheckboxWidget>("SHORTGAME_CHECKBOX"); if (shortGame != null) { shortGame.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.ShortGame; shortGame.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.ShortGame.HasValue || configurationDisabled(); shortGame.OnClick = () => orderManager.IssueOrder(Order.Command( "shortgame {0}".F(!orderManager.LobbyInfo.GlobalSettings.ShortGame))); } var difficulty = optionsBin.GetOrNull<DropDownButtonWidget>("DIFFICULTY_DROPDOWNBUTTON"); if (difficulty != null) { difficulty.IsVisible = () => Map.Status == MapStatus.Available && Map.Map.Options.Difficulties.Any(); difficulty.IsDisabled = () => Map.Status != MapStatus.Available || configurationDisabled(); difficulty.GetText = () => orderManager.LobbyInfo.GlobalSettings.Difficulty; difficulty.OnMouseDown = _ => { var options = Map.Map.Options.Difficulties.Select(d => new DropDownOption { Title = d, IsSelected = () => orderManager.LobbyInfo.GlobalSettings.Difficulty == d, OnClick = () => orderManager.IssueOrder(Order.Command("difficulty {0}".F(d))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; difficulty.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; optionsBin.Get<LabelWidget>("DIFFICULTY_DESC").IsVisible = difficulty.IsVisible; } var startingUnits = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGUNITS_DROPDOWNBUTTON"); if (startingUnits != null) { var startUnitsInfo = modRules.Actors["world"].Traits.WithInterface<MPStartUnitsInfo>(); var classes = startUnitsInfo.Select(a => a.Class).Distinct(); Func<string, string> className = c => { var selectedClass = startUnitsInfo.Where(s => s.Class == c).Select(u => u.ClassName).FirstOrDefault(); return selectedClass != null ? selectedClass : c; }; startingUnits.IsDisabled = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits || configurationDisabled(); startingUnits.GetText = () => Map.Status != MapStatus.Available || !Map.Map.Options.ConfigurableStartingUnits ? "Not Available" : className(orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass); startingUnits.OnMouseDown = _ => { var options = classes.Select(c => new DropDownOption { Title = className(c), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingUnitsClass == c, OnClick = () => orderManager.IssueOrder(Order.Command("startingunits {0}".F(c))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; startingUnits.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; optionsBin.Get<LabelWidget>("STARTINGUNITS_DESC").IsVisible = startingUnits.IsVisible; } var startingCash = optionsBin.GetOrNull<DropDownButtonWidget>("STARTINGCASH_DROPDOWNBUTTON"); if (startingCash != null) { startingCash.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue || configurationDisabled(); startingCash.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash); startingCash.OnMouseDown = _ => { var options = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption { Title = "${0}".F(c), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c, OnClick = () => orderManager.IssueOrder(Order.Command("startingcash {0}".F(c))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; startingCash.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; } var techLevel = optionsBin.GetOrNull<DropDownButtonWidget>("TECHLEVEL_DROPDOWNBUTTON"); if (techLevel != null) { var techTraits = modRules.Actors["player"].Traits.WithInterface<ProvidesTechPrerequisiteInfo>().ToList(); techLevel.IsVisible = () => techTraits.Count > 0; var techLevelDescription = optionsBin.GetOrNull<LabelWidget>("TECHLEVEL_DESC"); if (techLevelDescription != null) techLevelDescription.IsVisible = () => techTraits.Count > 0; techLevel.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.TechLevel != null || configurationDisabled() || techTraits.Count <= 1; techLevel.GetText = () => Map.Status != MapStatus.Available || Map.Map.Options.TechLevel != null ? "Not Available" : "{0}".F(orderManager.LobbyInfo.GlobalSettings.TechLevel); techLevel.OnMouseDown = _ => { var options = techTraits.Select(c => new DropDownOption { Title = "{0}".F(c.Name), IsSelected = () => orderManager.LobbyInfo.GlobalSettings.TechLevel == c.Name, OnClick = () => orderManager.IssueOrder(Order.Command("techlevel {0}".F(c.Name))) }); Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; techLevel.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; } var enableShroud = optionsBin.GetOrNull<CheckboxWidget>("SHROUD_CHECKBOX"); if (enableShroud != null) { enableShroud.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Shroud; enableShroud.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Shroud.HasValue || configurationDisabled(); enableShroud.OnClick = () => orderManager.IssueOrder(Order.Command( "shroud {0}".F(!orderManager.LobbyInfo.GlobalSettings.Shroud))); } var enableFog = optionsBin.GetOrNull<CheckboxWidget>("FOG_CHECKBOX"); if (enableFog != null) { enableFog.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.Fog; enableFog.IsDisabled = () => Map.Status != MapStatus.Available || Map.Map.Options.Fog.HasValue || configurationDisabled(); enableFog.OnClick = () => orderManager.IssueOrder(Order.Command( "fog {0}".F(!orderManager.LobbyInfo.GlobalSettings.Fog))); } var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON"); disconnectButton.OnClick = () => { CloseWindow(); onExit(); }; if (skirmishMode) disconnectButton.Text = "Back"; chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE"); var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD"); chatTextField.TakeKeyboardFocus(); chatTextField.OnEnterKey = () => { if (chatTextField.Text.Length == 0) return true; // Always scroll to bottom when we've typed something chatPanel.ScrollToBottom(); orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text)); chatTextField.Text = ""; return true; }; chatTextField.OnTabKey = () => { var previousText = chatTextField.Text; chatTextField.Text = tabCompletion.Complete(chatTextField.Text); chatTextField.CursorPosition = chatTextField.Text.Length; if (chatTextField.Text == previousText) return SwitchTeamChat(); else return true; }; chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; }; chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY"); chatTemplate = chatPanel.Get("CHAT_TEMPLATE"); chatPanel.RemoveChildren(); var musicButton = lobby.GetOrNull<ButtonWidget>("MUSIC_BUTTON"); if (musicButton != null) musicButton.OnClick = () => Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", DoNothing }, { "world", worldRenderer.World } }); var settingsButton = lobby.GetOrNull<ButtonWidget>("SETTINGS_BUTTON"); if (settingsButton != null) { settingsButton.OnClick = () => Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs { { "onExit", DoNothing }, { "worldRenderer", worldRenderer } }); } // Add a bot on the first lobbyinfo update if (skirmishMode) { Game.LobbyInfoChanged += WidgetUtils.Once(() => { var slot = orderManager.LobbyInfo.FirstEmptyBotSlot(); var bot = modRules.Actors["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault(); var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (slot != null && bot != null) orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot))); }); } }
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); }
Color GetStateColor(GameServer game, LabelWidget label, bool darkened) { if (game.Protected && game.State == (int)ServerState.WaitingPlayers) return darkened ? incompatibleProtectedGameColor : protectedGameColor; if (game.State == (int)ServerState.WaitingPlayers) return darkened ? incompatibleWaitingGameColor : waitingGameColor; if (game.State == (int)ServerState.GameStarted) return darkened ? incompatibleGameStartedColor : gameStartedColor; return label.TextColor; }
void AddReplay(ScrollPanelWidget list, string filename, LabelWidget template) { var entry = template.Clone() as LabelWidget; entry.Id = "REPLAY_"; entry.GetText = () => " {0}".F(Path.GetFileName(filename)); entry.GetBackground = () => (CurrentReplay == filename) ? "dialog2" : null; entry.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false; CurrentReplay = filename; return true; }; entry.IsVisible = () => true; list.AddChild(entry); }
void LayoutDialog(Widget bg) { bg.Children.RemoveAll(w => controls.Contains(w)); controls.Clear(); var y = 50; var margin = 20; var labelWidth = (bg.Bounds.Width - 3 * margin) / 3; var ts = new LabelWidget { Bold = true, Bounds = new Rectangle(margin + labelWidth + 10, y, labelWidth, 25), Text = "Their Stance", Align = LabelWidget.TextAlign.Left, }; bg.AddChild(ts); controls.Add(ts); var ms = new LabelWidget { Bold = true, Bounds = new Rectangle(margin + 2 * labelWidth + 20, y, labelWidth, 25), Text = "My Stance", Align = LabelWidget.TextAlign.Left, }; bg.AddChild(ms); controls.Add(ms); y += 35; foreach (var p in world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant)) { var pp = p; var label = new LabelWidget { Bounds = new Rectangle(margin, y, labelWidth, 25), Id = "DIPLOMACY_PLAYER_LABEL_{0}".F(p.Index), Text = p.PlayerName, Align = LabelWidget.TextAlign.Left, Bold = true, }; bg.AddChild(label); controls.Add(label); var theirStance = new LabelWidget { Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25), Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index), Text = p.PlayerName, Align = LabelWidget.TextAlign.Left, Bold = false, GetText = () => pp.Stances[ world.LocalPlayer ].ToString(), }; bg.AddChild(theirStance); controls.Add(theirStance); var myStance = new DropDownButtonWidget { Bounds = new Rectangle( margin + 2 * labelWidth + 20, y, labelWidth, 25), Id = "DIPLOMACY_PLAYER_LABEL_MY_{0}".F(p.Index), GetText = () => world.LocalPlayer.Stances[ pp ].ToString(), }; myStance.OnMouseDown = mi => { ShowDropDown(pp, myStance); return true; }; bg.AddChild(myStance); controls.Add(myStance); y += 35; } }
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; } }
internal LobbyLogic(Widget widget, ModData modData, WorldRenderer worldRenderer, OrderManager orderManager, Action onExit, Action onStart, bool skirmishMode) { Map = MapCache.UnknownMap; lobby = widget; this.modData = modData; this.orderManager = orderManager; this.onStart = onStart; this.onExit = onExit; this.skirmishMode = skirmishMode; // TODO: This needs to be reworked to support per-map tech levels, bots, etc. this.modRules = modData.DefaultRules; shellmapWorld = worldRenderer.World; orderManager.AddChatLine += AddChatLine; Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdatePlayerList; Game.BeforeGameStart += OnGameStart; Game.ConnectionStateChanged += ConnectionStateChanged; var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME"); if (name != null) name.GetText = () => orderManager.LobbyInfo.GlobalSettings.ServerName; Ui.LoadWidget("LOBBY_MAP_PREVIEW", lobby.Get("MAP_PREVIEW_ROOT"), new WidgetArgs { { "orderManager", orderManager }, { "lobby", this } }); UpdateCurrentMap(); var playerBin = Ui.LoadWidget("LOBBY_PLAYER_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); playerBin.IsVisible = () => panel == PanelType.Players; players = playerBin.Get<ScrollPanelWidget>("LOBBY_PLAYERS"); editablePlayerTemplate = players.Get("TEMPLATE_EDITABLE_PLAYER"); nonEditablePlayerTemplate = players.Get("TEMPLATE_NONEDITABLE_PLAYER"); emptySlotTemplate = players.Get("TEMPLATE_EMPTY"); editableSpectatorTemplate = players.Get("TEMPLATE_EDITABLE_SPECTATOR"); nonEditableSpectatorTemplate = players.Get("TEMPLATE_NONEDITABLE_SPECTATOR"); newSpectatorTemplate = players.Get("TEMPLATE_NEW_SPECTATOR"); colorPreview = lobby.Get<ColorPreviewManagerWidget>("COLOR_MANAGER"); colorPreview.Color = Game.Settings.Player.Color; foreach (var f in modRules.Actors["world"].TraitInfos<FactionInfo>()) factions.Add(f.InternalName, new LobbyFaction { Selectable = f.Selectable, Name = f.Name, Side = f.Side, Description = f.Description }); var gameStarting = false; Func<bool> configurationDisabled = () => !Game.IsHost || gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || !Map.RulesLoaded || Map.InvalidCustomRules || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; var mapButton = lobby.GetOrNull<ButtonWidget>("CHANGEMAP_BUTTON"); if (mapButton != null) { mapButton.IsDisabled = () => gameStarting || panel == PanelType.Kick || panel == PanelType.ForceStart || orderManager.LocalClient == null || orderManager.LocalClient.IsReady; mapButton.OnClick = () => { var onSelect = new Action<string>(uid => { // Don't select the same map again if (uid == Map.Uid) return; orderManager.IssueOrder(Order.Command("map " + uid)); Game.Settings.Server.Map = uid; Game.Settings.Save(); }); Ui.OpenWindow("MAPCHOOSER_PANEL", new WidgetArgs() { { "initialMap", Map.Uid }, { "initialTab", MapClassification.System }, { "onExit", DoNothing }, { "onSelect", Game.IsHost ? onSelect : null }, { "filter", MapVisibility.Lobby }, }); }; } var slotsButton = lobby.GetOrNull<DropDownButtonWidget>("SLOTS_DROPDOWNBUTTON"); if (slotsButton != null) { slotsButton.IsDisabled = () => configurationDisabled() || panel != PanelType.Players || (orderManager.LobbyInfo.Slots.Values.All(s => !s.AllowBots) && orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) == 0); slotsButton.OnMouseDown = _ => { var botNames = Map.Rules.Actors["player"].TraitInfos<IBotInfo>().Select(t => t.Name); var options = new Dictionary<string, IEnumerable<DropDownOption>>(); var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots)) { var botOptions = new List<DropDownOption>() { new DropDownOption() { Title = "Add", IsSelected = () => false, OnClick = () => { foreach (var slot in orderManager.LobbyInfo.Slots) { var bot = botNames.Random(Game.CosmeticRandom); var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); if (slot.Value.AllowBots == true && (c == null || c.Bot != null)) orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot.Key, botController.Index, bot))); } } } }; if (orderManager.LobbyInfo.Clients.Any(c => c.Bot != null)) { botOptions.Add(new DropDownOption() { Title = "Remove", IsSelected = () => false, OnClick = () => { foreach (var slot in orderManager.LobbyInfo.Slots) { var c = orderManager.LobbyInfo.ClientInSlot(slot.Key); if (c != null && c.Bot != null) orderManager.IssueOrder(Order.Command("slot_open " + slot.Value.PlayerReference)); } } }); } options.Add("Configure Bots", botOptions); } var teamCount = (orderManager.LobbyInfo.Slots.Count(s => !s.Value.LockTeam && orderManager.LobbyInfo.ClientInSlot(s.Key) != null) + 1) / 2; if (teamCount >= 1) { var teamOptions = Enumerable.Range(2, teamCount - 1).Reverse().Select(d => new DropDownOption { Title = "{0} Teams".F(d), IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams {0}".F(d.ToString()))) }).ToList(); if (orderManager.LobbyInfo.Slots.Any(s => s.Value.AllowBots)) { teamOptions.Add(new DropDownOption { Title = "Humans vs Bots", IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams 1")) }); } teamOptions.Add(new DropDownOption { Title = "Free for all", IsSelected = () => false, OnClick = () => orderManager.IssueOrder(Order.Command("assignteams 0")) }); options.Add("Configure Teams", teamOptions); } Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) => { var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick); item.Get<LabelWidget>("LABEL").GetText = () => option.Title; return item; }; slotsButton.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 175, options, setupItem); }; } var optionsBin = Ui.LoadWidget("LOBBY_OPTIONS_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); optionsBin.IsVisible = () => panel == PanelType.Options; var musicBin = Ui.LoadWidget("LOBBY_MUSIC_BIN", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs { { "onExit", DoNothing }, { "world", worldRenderer.World } }); musicBin.IsVisible = () => panel == PanelType.Music; var optionsTab = lobby.Get<ButtonWidget>("OPTIONS_TAB"); optionsTab.IsHighlighted = () => panel == PanelType.Options; optionsTab.IsDisabled = () => !Map.RulesLoaded || Map.InvalidCustomRules || panel == PanelType.Kick || panel == PanelType.ForceStart; optionsTab.OnClick = () => panel = PanelType.Options; var playersTab = lobby.Get<ButtonWidget>("PLAYERS_TAB"); playersTab.IsHighlighted = () => panel == PanelType.Players; playersTab.IsDisabled = () => panel == PanelType.Kick || panel == PanelType.ForceStart; playersTab.OnClick = () => panel = PanelType.Players; var musicTab = lobby.Get<ButtonWidget>("MUSIC_TAB"); musicTab.IsHighlighted = () => panel == PanelType.Music; musicTab.IsDisabled = () => panel == PanelType.Kick || panel == PanelType.ForceStart; musicTab.OnClick = () => panel = PanelType.Music; // Force start panel Action startGame = () => { gameStarting = true; orderManager.IssueOrder(Order.Command("startgame")); }; var startGameButton = lobby.GetOrNull<ButtonWidget>("START_GAME_BUTTON"); if (startGameButton != null) { startGameButton.IsDisabled = () => configurationDisabled() || Map.Status != MapStatus.Available || orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) || (!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.IsSinglePlayer); startGameButton.OnClick = () => { // Bots and admins don't count if (orderManager.LobbyInfo.Clients.Any(c => c.Slot != null && !c.IsAdmin && c.Bot == null && !c.IsReady)) panel = PanelType.ForceStart; else startGame(); }; } var forceStartBin = Ui.LoadWidget("FORCE_START_DIALOG", lobby.Get("TOP_PANELS_ROOT"), new WidgetArgs()); forceStartBin.IsVisible = () => panel == PanelType.ForceStart; forceStartBin.Get("KICK_WARNING").IsVisible = () => orderManager.LobbyInfo.Clients.Any(c => c.IsInvalid); forceStartBin.Get<ButtonWidget>("OK_BUTTON").OnClick = startGame; forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players; // Options panel var optionCheckboxes = new Dictionary<string, string>() { { "EXPLORED_MAP_CHECKBOX", "explored" }, { "CRATES_CHECKBOX", "crates" }, { "SHORTGAME_CHECKBOX", "shortgame" }, { "FOG_CHECKBOX", "fog" }, { "ALLYBUILDRADIUS_CHECKBOX", "allybuild" }, { "ALLOWCHEATS_CHECKBOX", "cheats" }, { "CREEPS_CHECKBOX", "creeps" }, }; foreach (var kv in optionCheckboxes) { var checkbox = optionsBin.GetOrNull<CheckboxWidget>(kv.Key); if (checkbox != null) { var option = new CachedTransform<Session.Global, Session.LobbyOptionState>( gs => gs.LobbyOptions[kv.Value]); var visible = new CachedTransform<Session.Global, bool>( gs => gs.LobbyOptions.ContainsKey(kv.Value)); checkbox.IsVisible = () => visible.Update(orderManager.LobbyInfo.GlobalSettings); checkbox.IsChecked = () => option.Update(orderManager.LobbyInfo.GlobalSettings).Enabled; checkbox.IsDisabled = () => configurationDisabled() || option.Update(orderManager.LobbyInfo.GlobalSettings).Locked; checkbox.OnClick = () => orderManager.IssueOrder(Order.Command( "option {0} {1}".F(kv.Value, !option.Update(orderManager.LobbyInfo.GlobalSettings).Enabled))); } } var optionDropdowns = new Dictionary<string, string>() { { "TECHLEVEL", "techlevel" }, { "STARTINGUNITS", "startingunits" }, { "STARTINGCASH", "startingcash" }, { "DIFFICULTY", "difficulty" }, { "GAMESPEED", "gamespeed" } }; var allOptions = new CachedTransform<MapPreview, LobbyOption[]>( map => map.Rules.Actors["player"].TraitInfos<ILobbyOptions>() .Concat(map.Rules.Actors["world"].TraitInfos<ILobbyOptions>()) .SelectMany(t => t.LobbyOptions(map.Rules)) .ToArray()); foreach (var kv in optionDropdowns) { var dropdown = optionsBin.GetOrNull<DropDownButtonWidget>(kv.Key + "_DROPDOWNBUTTON"); if (dropdown != null) { var optionValue = new CachedTransform<Session.Global, Session.LobbyOptionState>( gs => gs.LobbyOptions[kv.Value]); var option = new CachedTransform<MapPreview, LobbyOption>( map => allOptions.Update(map).FirstOrDefault(o => o.Id == kv.Value)); var getOptionLabel = new CachedTransform<string, string>(id => { string value; if (id == null || !option.Update(Map).Values.TryGetValue(id, out value)) return "Not Available"; return value; }); dropdown.GetText = () => getOptionLabel.Update(optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Value); dropdown.IsVisible = () => option.Update(Map) != null; dropdown.IsDisabled = () => configurationDisabled() || optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Locked; dropdown.OnMouseDown = _ => { Func<KeyValuePair<string, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (c, template) => { Func<bool> isSelected = () => optionValue.Update(orderManager.LobbyInfo.GlobalSettings).Value == c.Key; Action onClick = () => orderManager.IssueOrder(Order.Command("option {0} {1}".F(kv.Value, c.Key))); var item = ScrollItemWidget.Setup(template, isSelected, onClick); item.Get<LabelWidget>("LABEL").GetText = () => c.Value; return item; }; var options = option.Update(Map).Values; dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem); }; var label = optionsBin.GetOrNull(kv.Key + "_DESC"); if (label != null) label.IsVisible = () => option.Update(Map) != null; } } var disconnectButton = lobby.Get<ButtonWidget>("DISCONNECT_BUTTON"); disconnectButton.OnClick = () => { Ui.CloseWindow(); onExit(); }; if (skirmishMode) disconnectButton.Text = "Back"; var globalChat = Game.LoadWidget(null, "LOBBY_GLOBALCHAT_PANEL", lobby.Get("GLOBALCHAT_ROOT"), new WidgetArgs()); var globalChatInput = globalChat.Get<TextFieldWidget>("CHAT_TEXTFIELD"); globalChat.IsVisible = () => chatPanel == ChatPanelType.Global; var globalChatTab = lobby.Get<ButtonWidget>("GLOBALCHAT_TAB"); globalChatTab.IsHighlighted = () => chatPanel == ChatPanelType.Global; globalChatTab.OnClick = () => { chatPanel = ChatPanelType.Global; globalChatInput.TakeKeyboardFocus(); }; var globalChatLabel = globalChatTab.Text; globalChatTab.GetText = () => { if (globalChatUnreadMessages == 0 || chatPanel == ChatPanelType.Global) return globalChatLabel; return globalChatLabel + " ({0})".F(globalChatUnreadMessages); }; globalChatLastReadMessages = Game.GlobalChat.History.Count(m => m.Type == ChatMessageType.Message); var lobbyChat = lobby.Get("LOBBYCHAT"); lobbyChat.IsVisible = () => chatPanel == ChatPanelType.Lobby; chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE"); var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD"); chatTextField.TakeKeyboardFocus(); chatTextField.OnEnterKey = () => { if (chatTextField.Text.Length == 0) return true; // Always scroll to bottom when we've typed something lobbyChatPanel.ScrollToBottom(); orderManager.IssueOrder(Order.Chat(teamChat, chatTextField.Text)); chatTextField.Text = ""; return true; }; chatTextField.OnTabKey = () => { var previousText = chatTextField.Text; chatTextField.Text = tabCompletion.Complete(chatTextField.Text); chatTextField.CursorPosition = chatTextField.Text.Length; if (chatTextField.Text == previousText) return SwitchTeamChat(); else return true; }; chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; }; var lobbyChatTab = lobby.Get<ButtonWidget>("LOBBYCHAT_TAB"); lobbyChatTab.IsHighlighted = () => chatPanel == ChatPanelType.Lobby; lobbyChatTab.OnClick = () => { chatPanel = ChatPanelType.Lobby; chatTextField.TakeKeyboardFocus(); }; var lobbyChatLabel = lobbyChatTab.Text; lobbyChatTab.GetText = () => { if (lobbyChatUnreadMessages == 0 || chatPanel == ChatPanelType.Lobby) return lobbyChatLabel; return lobbyChatLabel + " ({0})".F(lobbyChatUnreadMessages); }; lobbyChatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY"); chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE"); lobbyChatPanel.RemoveChildren(); var settingsButton = lobby.GetOrNull<ButtonWidget>("SETTINGS_BUTTON"); if (settingsButton != null) { settingsButton.OnClick = () => Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs { { "onExit", DoNothing }, { "worldRenderer", worldRenderer } }); } // Add a bot on the first lobbyinfo update if (skirmishMode) addBotOnMapLoad = true; }