/// <summary> /// Registeres a new File to the Storage. /// </summary> /// <param name="file"></param> public void RegisterFile(string file) { lock (this) { if (scannedFiles.Contains(file.ToLower())) { return; } // Kick den alten if (configuration.KnownFiles.Contains(file.ToLower())) { UnregisterFile(file); } var result = AiAnalysis.Analyse(file, true); if (result.Count > 0) { configuration.KnownFiles.Add(file.ToLower()); foreach (var player in result) { var playerInfo = new PlayerInfoFilename(player, file.ToLower()); knownPlayer.Add(playerInfo); } } SaveConfiguration(); } }
/// <summary> /// Adds a player to a team. /// </summary> /// <param name="info">player</param> /// <param name="team">team</param> private void addPlayerToTeam(PlayerInfoFilename info, TeamItem team) { if (ReadyCheck(info, false, false)) { addPlayerToTeam(new PlayerItem[] { new PlayerItem(info) }, team); } }
/// <summary> /// Creates a new instance of PlayerItem. /// </summary> /// <param name="info">base <see cref="PlayerInfoFilename"/></param> public PlayerItem(PlayerInfoFilename info) { PlayerInfo = info; ColonyName = info.ColonyName; FileName = info.File; ClassName = info.ClassName; AuthorName = string.Format(Resource.AntPropertiesAuthorFormat, info.FirstName, info.LastName); }
private void button_antProperties(object sender, EventArgs e) { if (playerListView.SelectedItems.Count > 0) { PlayerInfoFilename info = (PlayerInfoFilename)playerListView.SelectedItems[0].Tag; playerProperties(info); } }
private void button_remove(object sender, EventArgs e) { foreach (ListViewItem listViewItem in playerListView.SelectedItems) { PlayerInfoFilename info = (PlayerInfoFilename)listViewItem.Tag; removePlayer(info); } }
private void info(PlayerInfoFilename info) { if (info == null) { return; } using (AntProperties properties = new AntProperties(info)) { properties.ShowDialog(this); } }
private void button_newTeam8(object sender, EventArgs e) { if (playerListView.SelectedItems.Count > 0) { foreach (ListViewItem item in playerListView.SelectedItems) { PlayerInfoFilename info = (PlayerInfoFilename)item.Tag; addPlayerToTeam(info, config.teams[7]); } } }
private void button_newTeam(object sender, EventArgs e) { if (playerListView.SelectedItems.Count > 0) { PlayerInfoFilename[] selectedPlayer = new PlayerInfoFilename[playerListView.SelectedItems.Count]; for (int i = 0; i < playerListView.SelectedItems.Count; i++) { selectedPlayer[i] = (PlayerInfoFilename)playerListView.SelectedItems[i].Tag; } addPlayerToTeam(selectedPlayer, false); } }
private void drag_playerList(object sender, ItemDragEventArgs e) { if (e.Button == MouseButtons.Left) { PlayerInfoFilename[] player = new PlayerInfoFilename[playerListView.SelectedItems.Count]; for (int i = 0; i < playerListView.SelectedItems.Count; i++) { player[i] = (PlayerInfoFilename)playerListView.SelectedItems[i].Tag; } DoDragDrop(player, DragDropEffects.Copy); } }
private void playerListView_SelectedIndexChanged(object sender, EventArgs e) { if (playerListView.SelectedItems.Count > 0) { SelectedPlayer = playerListView.SelectedItems[0].Tag as PlayerInfoFilename; } else { SelectedPlayer = null; } UpdateSelection(); }
private void playerListView_DoubleClick(object sender, EventArgs e) { if (playerListView.SelectedItems.Count > 0) { SelectedPlayer = playerListView.SelectedItems[0].Tag as PlayerInfoFilename; } else { SelectedPlayer = null; } UpdateSelection(); DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
/// <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> /// Checks the given player for match-readyness. /// </summary> /// <param name="player">requested player</param> /// <param name="silent">shows no messageboxes and requests</param> /// <param name="secure">asume, that the testet player is secure</param> /// <returns>true, if everything is fine</returns> private bool ReadyCheck(PlayerInfoFilename player, bool silent, bool secure) { // Rulevalidation if (!RightsRequest.IsValidPlayer(player)) { // Messagebox, if not silent if (!silent) { MessageBox.Show( this, RightsRequest.GetRuleViolationMessage(player), Resource.SimulationPluginMessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(false); } // if colony is ready to start without request, do that if (!RightsRequest.RequestRights(player)) { return(true); } // Security-override if (secure && !RightsRequest.LockedRights(config, player)) { return(true); } // Ask for request RightsRequest form = new RightsRequest(config, player); if (!silent && form.ShowDialog(this) == DialogResult.Yes) { return(true); } return(false); }
private void playerPanel_Click(object sender, EventArgs e) { PlayerInfoFilename playerInfo = null; using (PlayerSelector selector = new PlayerSelector()) { if (selector.ShowDialog(this) == DialogResult.OK) { playerInfo = selector.SelectedPlayer; } } if (playerInfo != null) { setup.PlayerInfo = playerInfo; setup.Filename = playerInfo.File; setup.Typename = playerInfo.ClassName; } UpdateControls(); listingPlayer = playerInfo; needHighscoreUpdate = true; }
public RightsRequest(SimulationPluginConfiguration config, PlayerInfoFilename player) { playerInfo = player; InitializeComponent(); yesButton.Enabled = acceptCheckBox.Checked; colonyLabel.Text = player.ColonyName; authorLabel.Text = string.Format(Resource.SimulatorPluginAntPropertiesAuthorFormat, player.FirstName, player.LastName); if (player.RequestFileAccess) { if (config.configuration.AllowFileAccess) { rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesIoAccess, open); } else { locked = true; rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesIoAccess, closed); } } if (player.RequestDatabaseAccess) { if (config.configuration.AllowDatabaseAccess) { rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesDbAccess, open); } else { locked = true; rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesDbAccess, closed); } } if (player.RequestReferences) { if (config.configuration.AllowReferences) { rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesRefAccess, open); } else { locked = true; rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesRefAccess, closed); } } if (player.RequestUserInterfaceAccess) { if (config.configuration.AllowUserinterfaceAccess) { rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesUiAccess, open); } else { locked = true; rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesUiAccess, closed); } } if (player.RequestNetworkAccess) { if (config.configuration.AllowNetworkAccess) { rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesNetAccess, open); } else { locked = true; rightsListView.Items.Add(Resource.SimulatorPluginAntPropertiesNetAccess, closed); } } if (locked) { sorryPanel.Visible = true; acceptPanel.Visible = false; AcceptButton = closeButton; CancelButton = closeButton; } else { sorryPanel.Visible = false; acceptPanel.Visible = true; AcceptButton = yesButton; CancelButton = noButton; } }
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; } }
/// <summary> /// Shows the property-window for ants. /// </summary> /// <param name="player">target player</param> private void playerProperties(PlayerInfoFilename player) { AntProperties properties = new AntProperties(player); properties.ShowDialog(this); }
public AntProperties(PlayerInfoFilename playerInfo) { player = playerInfo; InitializeComponent(); // Daten einfüllen kiNameLabel1.Text = player.ColonyName; kiNameLabel3.Text = player.ColonyName; kiNameLabel2.Text = player.ColonyName; Text = string.Format(Resource.SimulatorPluginAntPropertiesTitle, player.ColonyName); autorLabel.Text = string.Format(Resource.SimulatorPluginAntPropertiesAuthorFormat, player.FirstName, player.LastName); versionLabel.Text = player.SimulationVersion.ToString(); spracheLabel.Text = player.Language.ToString(); statischLabel.Text = player.Static ? Resource.Yes : Resource.No; debugLabel.Text = player.HasDebugInformation ? Resource.Yes : Resource.No; klassennameTextBox.Text = player.ClassName; dateinameTextBox.Text = player.File; try { FileInfo info = new FileInfo(player.File); dateigrößeLabel.Text = info.Length + " Byte"; datumLabel.Text = info.CreationTime.ToLongDateString() + " " + info.CreationTime.ToShortTimeString(); } catch { dateigrößeLabel.Text = Resource.SimulatorPluginAntPropertiesUnknown; datumLabel.Text = Resource.SimulatorPluginAntPropertiesUnknown; } // Ameisenkasten einfügen castesListView.Items.Clear(); foreach (CasteInfo info in player.Castes) { ListViewItem item = castesListView.Items.Add(info.Name, "ant"); item.Tag = info; } select_caste(null, null); // Sicherheitsliste int count = 0; if (player.RequestFileAccess) { rechteListView.Items.Add(Resource.SimulatorPluginAntPropertiesIoAccess, "security_closed"); count++; } if (player.RequestDatabaseAccess) { rechteListView.Items.Add(Resource.SimulatorPluginAntPropertiesDbAccess, "security_closed"); count++; } if (player.RequestReferences) { rechteListView.Items.Add(Resource.SimulatorPluginAntPropertiesRefAccess, "security_closed"); count++; } if (player.RequestUserInterfaceAccess) { rechteListView.Items.Add(Resource.SimulatorPluginAntPropertiesUiAccess, "security_closed"); count++; } if (player.RequestNetworkAccess) { rechteListView.Items.Add(Resource.SimulatorPluginAntPropertiesNetAccess, "security_closed"); count++; } if (count == 0) { rechteListView.Items.Add(Resource.SimulatorPluginAntPropertiesNoAccess, "security_closed"); } zusatzinfosTextBox.Text = player.RequestInformation == string.Empty ? Resource.SimulatorPluginAntPropertiesNoAdditionalInfos : player.RequestInformation; }
/// <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); }
/// <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; }