private void PlayersOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { ProtocolProcess.RequestGameSettings(); PlayerListText.Invoke((MethodInvoker)(() => PlayerListText.Text = "")); foreach (var item in ProtocolProcess.Players) { PlayerListText.Invoke((MethodInvoker)(() => { if (PlayerListText.Lines.Length > 0) { PlayerListText.AppendText(Environment.NewLine); } try { PlayerListText.SelectionStart = PlayerListText.TextLength; PlayerListText.SelectedRtf = item.DisplayName; } catch (Exception) { // This is near-impossible to happen as of 05/10/2021, but // if somehow someone in the future manages to break rtf, // this line will send it through directly PlayerListText.AppendText($"{item.DisplayName}"); } finally { PlayerListText.AppendText($"({item.Score})"); } })); } }
private void GamePanel_Load(object sender, EventArgs e) { Text = $"{Text} ({GameServer.GameAddress}:{GameServer.GamePort})"; PlayerNameLabel.Text = PlayerSetting.Username + (PlayerSetting.IsHost ? " (Host)" : ""); MessageInputText.MaxLength = GameServer.SizeLimit / 2; ProtocolProcess.RequestGameSettings(); ProtocolProcess.OnGameSettingsReceivedEvent += delegate(object o, GameSettingsReceivedEvent ev) { if (ev.GameSettings != null) { GameNameText.Invoke((MethodInvoker)(() => GameNameText.Text = ev.GameSettings.GameName)); PlayerCountLabel.Invoke((MethodInvoker)(() => PlayerCountLabel.Text = $"PLAYERS ({ev.GameSettings.CurrentPlayers}/{ev.GameSettings.GameSize})")); StartGameButton.Invoke((MethodInvoker)(() => StartGameButton.Visible = PlayerSetting.IsHost && !ev.GameSettings.GameInProgress)); PointsRedText.Invoke((MethodInvoker)(() => PointsRedText.Text = ev.GameSettings.DefaultPointValues[0].ToString())); PointsBlueText.Invoke((MethodInvoker)(() => PointsBlueText.Text = ev.GameSettings.DefaultPointValues[1].ToString())); PointsYellowText.Invoke((MethodInvoker)(() => PointsYellowText.Text = ev.GameSettings.DefaultPointValues[2].ToString())); RefreshTimeText.Invoke((MethodInvoker)(() => RefreshTimeText.Text = ev.GameSettings.Timer)); WinPointText.Invoke((MethodInvoker)(() => WinPointText.Text = ev.GameSettings.Win)); // TODO: This line would allow for dynamic panel sizing, perhaps figure out the best way to implement this someday? // Invoke((MethodInvoker)(() => this.Size = new Size(ev.GameSettings.PanelSize.X, ev.GameSettings.PanelSize.Y))); } }; }