public void UpdateInfo(LobbyInfo lobby) { grpGame.Text = lobby.Name; lvwPlayers.Items.Clear(); if (lobby.Players != null) { foreach (PlayerInfo player in lobby.Players.Values) { ListViewItem lvi = new ListViewItem(); lvi.Text = player.Name; double minutes = player.Idle / 60; lvi.SubItems.Add(string.Format("{0} minute{1}", (int)minutes, minutes != 1 ? "s" : "")); string from = "Now"; if (player.From.HasValue && player.From.Value > DateTime.UtcNow) from = player.From.Value.ToLocalTime().ToShortTimeString(); lvi.SubItems.Add(from); string to = "N/A"; if (player.To.HasValue && player.To.Value > DateTime.UtcNow) to = player.To.Value.ToLocalTime().ToShortTimeString(); lvi.SubItems.Add(to); lvwPlayers.Items.Add(lvi); } } }
private void UpdateGamesSync() { lock (_SyncObject) { Dictionary<string, LobbyInfo> lobbies = Program.BotClient.GetLobbies(); string selected = gvwGame.Text; InvokeForm(delegate { _UpdatingGames = true; SetUpdateEvent(false); }); List<ListViewItem> items = new List<ListViewItem>(); foreach (JsonObject game in Program.BotClient.GetMyGames()) { string name = Dynamic.InvokeGet(game, "name"); string title = name; LobbyInfo lobby; ListViewItem lvi = new ListViewItem(); lvi.Text = name; if (!lobbies.TryGetValue(name, out lobby)) { lobby = new LobbyInfo(); lobby.Name = name; lobby.Players = new Dictionary<string, PlayerInfo>(); } lvi.SubItems.Add(lobby.Players.Count.ToString()); if (lobby.Players.ContainsKey(Properties.Settings.Default.SBFLUsername)) lvi.Checked = true; lvi.Tag = lobby; if (name == selected) { lvi.Selected = true; InvokeForm(delegate { gvwGame.UpdateInfo(lobby); }); } items.Add(lvi); } InvokeForm(delegate { lvwGames.Items.Clear(); lvwGames.Items.AddRange(items.ToArray()); SetUpdateEvent(true); _UpdatingGames = false; }); } }
public GameView(LobbyInfo lobby) { InitializeComponent(); UpdateInfo(lobby); }