Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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;
        }