public void AddTextItem(bool heading, string columnOne, string columnTwo, string id) { if (heading) // some spacing before headings { AddTextItem(false, " ", null, "spacing" + id); } MenuItem item = new TextMenuItem(columnOne, columnTwo, id); item.Bounds = Bounds; item.Font = heading ? MenuHeaderFont : MenuFont; item.Background = OptionSelected; item.FontColor = ItemColor; item.FontColorSelected = ItemColor; MenuItems.Add(item); }
public void InsertTextItem(int index, bool heading, string columnOne, string columnTwo, string id) { if (heading) // some spacing before headings { InsertTextItem(index++, false, " ", null, id + "spacing"); } MenuItem item = new TextMenuItem(columnOne, columnTwo, id); item.Bounds = Bounds; item.Font = heading ? MenuHeaderFont : MenuFont; item.Background = OptionSelected; item.FontColor = ItemColor; item.FontColorSelected = ItemColor; MenuItems.Insert(index, item); }
public override GameState UpdateState(GameTime gameTime) { int indexFromBack = MenuItems.Count - selectedIndex; var serverClient = gameInstance.GetService <ServerClient>(); // prepare lobby (once) if (state == State.Unconnected && serverClient.connected) { state = State.Connected; MenuItem startButton = GetMenuItem("start"); startButton.Text = "Play"; Vector2 size = GetScreenPosition(new Vector2(1f, 1.6f)); Bounds = new Rectangle(0, 0, (int)size.X, (int)size.Y); MenuItems.Remove(serverInput); MenuItem item = new TextMenuItem("Players", null, "playerHeading"); item.Background = OptionSelected; item.Font = MenuHeaderFont; item.FontColor = ItemColor; item.FontColorSelected = ItemColor; MenuItems.Insert(0, item); lobbyItems.Add(item); foreach (var menuItem in MenuItems) { menuItem.SetWidth(Bounds.Width); } startButton.Enabled = true; } else if (state == State.Connected && !serverClient.connected) { state = State.Unconnected; Vector2 size = GetScreenPosition(new Vector2(1f, 0.625f)); Bounds = new Rectangle(0, 0, (int)size.X, (int)size.Y); MenuItems.RemoveAll(i => lobbyItems.Exists(i2 => i == i2)); lobbyItems.Clear(); MenuItems.Insert(0, serverInput); } // update lobby if connected if (state == State.Connected) { var fullPlayerList = new List <Player>(serverClient.Players.Values); fullPlayerList.Add(serverClient.LocalPlayer); fullPlayerList.OrderBy(p => p.ID); int playerNumbering = 1; foreach (var player in fullPlayerList) { if (!lobbyItems.Exists(item => item.Identifier == player.PlayerName + player.ID)) { string stateText = player.State == PlayerState.Lobby ? "In Lobby" : "In Game"; MenuItem item = new TextMenuItem((playerNumbering++) + ". " + player.PlayerName, stateText, player.PlayerName + player.ID); item.Background = OptionSelected; item.Font = MenuFont; item.FontColor = ItemColor; item.FontColorSelected = ItemColor; item.SetWidth(Bounds.Width); lobbyItems.Add(item); MenuItems.Insert(MenuItems.Count - 2, item); } } } selectedIndex = MenuItems.Count - indexFromBack; return(base.UpdateState(gameTime)); }