public static async void LanGameOptionsMenuInit(Window window, Game game) { GameOptions = new GameOptionsUtil(window, game, "Lan"); if (game.SkirmishManager.IsHosting) { game.SkirmishManager.Settings.MapName = GameOptions.CurrentMap.Name; } // Clear chat field var textChat = (TextBox)window.Controls.FindControl(TextEntryChatPrefix); textChat.Text = string.Empty; var buttonStart = (Button)window.Controls.FindControl($"LanGameOptionsMenu.wnd:ButtonStart"); //TODO: Use the right language strings buttonStart.Text = game.SkirmishManager.IsHosting ? "Play Game" : "Accept"; //game.SkirmishManager.OnStop += () => //{ // //TODO: somehow make this work // game.Scene2D.WndWindowManager.SetWindow(@"Menus\LanLobbyMenu.wnd"); //}; if (window.Tag == NetworkUtils.OnlineTag && game.SkirmishManager.IsHosting) { var listBoxChat = (ListBox)window.Controls.FindControl(ListboxChatWindowLanGamePrefix); var listBoxItem = new ListBoxDataItem(null, new string[] { "Checking UPnP status..." }, ColorRgbaF.White); listBoxChat.Items = new[] { listBoxItem }; if (UPnP.Status == UPnPStatus.Enabled) { if (await UPnP.ForwardPortsAsync()) { listBoxItem.ColumnData[0] = $"Ports forwarded via UPnP. Your external IP is {UPnP.ExternalIP?.ToString() ?? "unknown."}"; } else { listBoxItem.ColumnData[0] = $"Failed to forward ports via UPnP. Your external IP is {UPnP.ExternalIP?.ToString() ?? "unknown."}"; } } else { listBoxItem.ColumnData[0] = "UPnP is disabled."; } } }
public static async void LanGameOptionsMenuInit(Window window, Game game) { GameOptions = new GameOptionsUtil(window, game, "Lan"); if (game.SkirmishManager.IsHosting) { game.SkirmishManager.SkirmishGame.MapName = GameOptions.CurrentMap.Name; } GameOptions.OnSlotIndexChange += (index, name, value) => { if (game?.SkirmishManager?.SkirmishGame == null) { return; } var slot = game.SkirmishManager.SkirmishGame.Slots[index]; switch (name) { case GameOptionsUtil.ComboBoxColorPrefix: Logger.Trace($"Changed the color box to {value}"); slot.ColorIndex = (byte)value; break; case GameOptionsUtil.ComboBoxPlayerPrefix: Logger.Trace($"Changed the player type box to {value}"); break; case GameOptionsUtil.ComboBoxPlayerTemplatePrefix: Logger.Trace($"Changed the faction box to {value}"); slot.FactionIndex = (byte)value; break; case GameOptionsUtil.ComboBoxTeamPrefix: Logger.Trace($"Changed the team box to {value}"); slot.Team = (byte)value; break; } }; // Clear chat field var textChat = (TextBox)window.Controls.FindControl(TextEntryChatPrefix); textChat.Text = string.Empty; var buttonStart = (Button)window.Controls.FindControl($"LanGameOptionsMenu.wnd:ButtonStart"); //TODO: Use the right language strings buttonStart.Text = game.SkirmishManager.IsHosting ? "Play Game" : "Accept"; //game.SkirmishManager.OnStop += () => //{ // //TODO: somehow make this work // game.Scene2D.WndWindowManager.SetWindow(@"Menus\LanLobbyMenu.wnd"); //}; if (window.Tag == NetworkUtils.OnlineTag && game.SkirmishManager.IsHosting) { var listBoxChat = (ListBox)window.Controls.FindControl(ListboxChatWindowLanGamePrefix); var listBoxItem = new ListBoxDataItem(null, new string[] { "Checking UPnP status..." }, ColorRgbaF.White); listBoxChat.Items = new[] { listBoxItem }; if (UPnP.Status == UPnPStatus.Enabled) { if (await UPnP.ForwardPortsAsync()) { listBoxItem.ColumnData[0] = $"Ports forwarded via UPnP. Your external IP is {UPnP.ExternalIP?.ToString() ?? "unknown."}"; } else { listBoxItem.ColumnData[0] = $"Failed to forward ports via UPnP. Your external IP is {UPnP.ExternalIP?.ToString() ?? "unknown."}"; } } else { listBoxItem.ColumnData[0] = "UPnP is disabled."; } } }
public static void LanLobbyMenuUpdate(Window window, Game game) { if (!_game.LobbyManager.Updated) { return; } // Update games var games = _game.LobbyManager.Players.Where(x => x.Value.IsHosting); var listBoxGames = (ListBox)window.Controls.FindControl(ListBoxGamesPrefix); var items = new List <ListBoxDataItem>(listBoxGames.Items); //remove items that are no longer in the list items.RemoveAll(x => games.Where(y => y.Key.Equals(((KeyValuePair <IPEndPoint, LobbyPlayer>)x.DataItem).Key)).Count() == 0); //update the items that are in the list items.ForEach(x => x.ColumnData = new[] { ((KeyValuePair <IPEndPoint, LobbyPlayer>)x.DataItem).Value.Name }); //add the missing items to the list foreach (var lobbyPlayer in games) { var existing = items.Find(x => ((KeyValuePair <IPEndPoint, LobbyPlayer>)x.DataItem).Key.Equals(lobbyPlayer.Key)); if (existing == null) { existing = new ListBoxDataItem(lobbyPlayer, new[] { lobbyPlayer.Value.Name }, listBoxGames.TextColor); items.Add(existing); } existing.ColumnData = new[] { lobbyPlayer.Value.Name }; } listBoxGames.Items = items.ToArray(); // Update players var listBoxPlayers = (ListBox)window.Controls.FindControl(ListBoxPlayersPrefix); items = new List <ListBoxDataItem>(listBoxPlayers.Items); var players = _game.LobbyManager.Players.Where(x => x.Value.IsHosting == false); //remove items that are no longer in the list items.RemoveAll(x => players.Where(y => y.Key.Equals(((KeyValuePair <IPEndPoint, LobbyPlayer>)x.DataItem).Key)).Count() == 0); //add the missing items to the list foreach (var lobbyPlayer in players) { var existing = items.Find(x => ((KeyValuePair <IPEndPoint, LobbyPlayer>)x.DataItem).Key.Equals(lobbyPlayer.Key)); if (existing == null) { existing = new ListBoxDataItem(lobbyPlayer, new[] { lobbyPlayer.Value.Name }, listBoxPlayers.TextColor); items.Add(existing); } existing.ColumnData = new[] { lobbyPlayer.Value.Name }; } listBoxPlayers.Items = items.ToArray(); game.LobbyManager.Updated = false; }