/// <summary> /// removes the whole player from game. /// </summary> /// <param name="player"></param> private void removePlayer(PlayerInfoFilename player) { // Remove from List if (players.Contains(player)) { players.Remove(player); } // Remove from known players players.Remove(player); config.knownPlayer.Remove(player.GetHashCode()); // Remove from teams for (int i = 0; i < config.teams.Length; i++) { for (int j = 0; j < config.teams[i].Players.Count; j++) { PlayerItem item = config.teams[i].Players[j]; if (item.FileName == player.File && item.ClassName == player.ClassName) { config.teams[i].Players.Remove(item); j--; } } } // Remove known files, if no more players enabled bool hit = false; for (int i = 0; i < players.Count; i++) { if (players[i].File == player.File) { hit = true; break; } } if (!hit) { config.knownPlayerFiles.Remove(player.File); } UpdatePanel(); }
/// <summary> /// Updates the view. /// </summary> public void UpdatePanel() { if (ignoreUpdates) { return; } ignoreUpdates = true; settingsLabel.Text = config.configuration.Settings.SettingsName; #region playerListUpdate // Delete items for (int i = 0; i < playerListView.Items.Count; i++) { if (!players.Contains((PlayerInfoFilename)playerListView.Items[i].Tag)) { playerListView.Items.RemoveAt(i); i--; } } // Create new items ListViewGroup staticGroup = playerListView.Groups["staticGroup"]; ListViewGroup nonstaticGroup = playerListView.Groups["nonStaticGroup"]; for (int i = 0; i < players.Count; i++) { PlayerInfoFilename info = players[i]; if (!playerListView.Items.ContainsKey(info.GetHashCode().ToString())) { ListViewItem item = playerListView.Items.Add(info.GetHashCode().ToString(), info.ColonyName, 0); item.Tag = info; item.Group = info.Static ? staticGroup : nonstaticGroup; item.SubItems.Add( string.Format(Resource.SimulatorPluginAntPropertiesAuthorFormat, info.FirstName, info.LastName)); } } // Update Icon foreach (ListViewItem listViewItem in playerListView.Items) { // collect infos PlayerInfoFilename playerInfo = (PlayerInfoFilename)listViewItem.Tag; bool playerStatic = playerInfo.Static; bool playerEnabled = true; bool playerSecure = RightsRequest.RequestRights(playerInfo); string hintText = string.Empty; if (!RightsRequest.IsValidPlayer(playerInfo)) { playerEnabled = false; hintText = RightsRequest.GetRuleViolationMessage(playerInfo); } else if (RightsRequest.LockedRights(config, playerInfo)) { playerEnabled = false; hintText = RightsRequest.RequiredRightsList(config, playerInfo); } // Set Information to Item listViewItem.ImageKey = (playerStatic ? "static" : "nonstatic") + (!playerEnabled ? "_disabled" : string.Empty) + (playerSecure ? "_secure" : string.Empty); listViewItem.ToolTipText = hintText; } #endregion #region teamListUpdate // Kick player List <string> kickedPlayer = new List <string>(); for (int i = 0; i < teamListView.Items.Count; i++) { PlayerItem player = (PlayerItem)teamListView.Items[i].Tag; if (!config.teams[0].Players.Contains(player) && !config.teams[1].Players.Contains(player) && !config.teams[2].Players.Contains(player) && !config.teams[3].Players.Contains(player) && !config.teams[4].Players.Contains(player) && !config.teams[5].Players.Contains(player) && !config.teams[6].Players.Contains(player) && !config.teams[7].Players.Contains(player)) { teamListView.Items.RemoveAt(i); i--; continue; } for (int j = 0; j < 8; j++) { if (config.teams[j].Players.Contains(player)) { if (!RightsRequest.IsValidPlayer(player.PlayerInfo) || RightsRequest.LockedRights(config, player.PlayerInfo)) { kickedPlayer.Add( string.Format( Resource.SimulationPluginKicklistEntry, player.ColonyName, player.FileName, player.ClassName, player.AuthorName)); teamListView.Items.RemoveAt(i); config.teams[j].Players.Remove(player); i--; } break; } } } if (kickedPlayer.Count > 0) { MessageBox.Show( this, Resource.SimulationPluginKicklistHead + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, kickedPlayer.ToArray()), Resource.SimulationPluginMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } // Create new items and update Context-menues for (int i = 0; i < config.teams.Length; i++) { ListViewGroup group = teamListView.Groups["teamGroup" + i]; for (int j = 0; j < config.teams[i].Players.Count; j++) { PlayerItem player = config.teams[i].Players[j]; if (teamListView.Items.ContainsKey(player.Guid.ToString())) { ListViewItem item = teamListView.Items[player.Guid.ToString()]; if (item.Group != group) { item.Group = group; } } else { ListViewItem item = teamListView.Items.Add( player.Guid.ToString(), player.ColonyName, (player.PlayerInfo.Static ? "static" : "nonstatic")); item.SubItems.Add(player.AuthorName); item.Tag = player; item.Group = group; } } } // Update Team-Lists in Context-Menues newTeamMenuItem.Enabled = (config.teams[7].Players.Count == 0); chooseTeam1MenuItem.Visible = (config.teams[0].Players.Count > 0); chooseTeam2MenuItem.Visible = (config.teams[1].Players.Count > 0); chooseTeam3MenuItem.Visible = (config.teams[2].Players.Count > 0); chooseTeam4MenuItem.Visible = (config.teams[3].Players.Count > 0); chooseTeam5MenuItem.Visible = (config.teams[4].Players.Count > 0); chooseTeam6MenuItem.Visible = (config.teams[5].Players.Count > 0); chooseTeam7MenuItem.Visible = (config.teams[6].Players.Count > 0); chooseTeam8MenuItem.Visible = (config.teams[7].Players.Count > 0); moveNewTeamMenuItem.Enabled = (config.teams[7].Players.Count == 0); moveTeam1MenuItem.Visible = (config.teams[0].Players.Count > 0); moveTeam2MenuItem.Visible = (config.teams[1].Players.Count > 0); moveTeam3MenuItem.Visible = (config.teams[2].Players.Count > 0); moveTeam4MenuItem.Visible = (config.teams[3].Players.Count > 0); moveTeam5MenuItem.Visible = (config.teams[4].Players.Count > 0); moveTeam6MenuItem.Visible = (config.teams[5].Players.Count > 0); moveTeam7MenuItem.Visible = (config.teams[6].Players.Count > 0); moveTeam8MenuItem.Visible = (config.teams[7].Players.Count > 0); #endregion ignoreUpdates = false; }
/// <summary> /// Loads all players from filename and add them to the global player-list. /// </summary> /// <param name="filename">filename</param> /// <param name="knownOnly">if only known players should be added</param> /// <returns>true, if there was no Exception</returns> /// <param name="silent">starts silent start without error-messages</param> private List <PlayerInfoFilename> loadPlayerFile(string filename, bool knownOnly, bool silent) { List <PlayerInfo> foundPlayers = new List <PlayerInfo>(); List <PlayerInfoFilename> output = new List <PlayerInfoFilename>(); try { FileInfo file = new FileInfo(filename.ToLower()); // Load playerinfo try { foundPlayers.AddRange(AiAnalysis.Analyse(file.FullName, false)); } catch (Exception ex) { if (!silent) { showException(ex); } return(output); } // Add found players if (foundPlayers.Count > 0) { if (!config.knownPlayerFiles.Contains(file.FullName)) { config.knownPlayerFiles.Add(file.FullName); } bool found = false; foreach (PlayerInfo playerInfo in foundPlayers) { PlayerInfoFilename info = new PlayerInfoFilename(playerInfo, file.FullName); output.Add(info); if (!players.Contains(info)) { if (knownOnly) { if (!config.knownPlayer.Contains(info.GetHashCode())) { continue; } } else { if (!config.knownPlayer.Contains(info.GetHashCode())) { config.knownPlayer.Add(info.GetHashCode()); } } players.Add(info); found = true; } } if (!found && !knownOnly && !silent) { MessageBox.Show( this, string.Format(Resource.SimulatorPluginTeamSetupStillLoaded, file.FullName), Resource.SimulationPluginMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (!silent) { MessageBox.Show( this, string.Format(Resource.SimulatorPluginTeamSetupNoFolksFound, file.FullName), Resource.SimulationPluginMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { showException( new Exception( string.Format( Resource.SimulatorPluginTeamSetupFileloadException, filename, ex.Message), ex)); } UpdatePanel(); return(output); }
private void UpdateList() { players.Clear(); foreach (var player in PlayerStore.Instance.KnownPlayer) { players.Add(player as PlayerInfoFilename); } // Delete items for (int i = 0; i < playerListView.Items.Count; i++) { if (!players.Contains((PlayerInfoFilename)playerListView.Items[i].Tag)) { playerListView.Items.RemoveAt(i); i--; } } // Create new items ListViewGroup staticGroup = playerListView.Groups["staticGroup"]; ListViewGroup nonstaticGroup = playerListView.Groups["nonStaticGroup"]; for (int i = 0; i < players.Count; i++) { PlayerInfoFilename info = players[i]; if (!playerListView.Items.ContainsKey(info.GetHashCode().ToString())) { ListViewItem item = playerListView.Items.Add(info.GetHashCode().ToString(), info.ColonyName, 0); item.Tag = info; item.Group = info.Static ? staticGroup : nonstaticGroup; item.SubItems.Add( string.Format(Resource.AntPropertiesAuthorFormat, info.FirstName, info.LastName)); } } // Update Icon foreach (ListViewItem listViewItem in playerListView.Items) { // collect infos PlayerInfoFilename playerInfo = (PlayerInfoFilename)listViewItem.Tag; bool playerStatic = playerInfo.Static; bool playerEnabled = true; bool playerSecure = RightsRequest.RequestRights(playerInfo); string hintText = string.Empty; if (!RightsRequest.IsValidPlayer(playerInfo)) { playerEnabled = false; hintText = RightsRequest.GetRuleViolationMessage(playerInfo); } //else if (RightsRequest.LockedRights(config, playerInfo)) //{ // playerEnabled = false; // hintText = RightsRequest.RequiredRightsList(config, playerInfo); //} // Set Information to Item listViewItem.ImageKey = (playerStatic ? "static" : "nonstatic") + (!playerEnabled ? "_disabled" : string.Empty) + (playerSecure ? "_secure" : string.Empty); listViewItem.ToolTipText = hintText; } }