Exemplo n.º 1
0
        private void buttonCondition_PlayerCount_OperatorSelection_Click(object sender, EventArgs e)
        {
            int i = operators.IndexOf(((Button)sender).Text);

            i += 1;
            if (i > 4)
            {
                i = 0;
            }
            conditionOperator = (ToolCommand.Operator)i;
            buttonOperatorSelection_SetText();
        }
Exemplo n.º 2
0
        public ToolCommandEditor(ListBox listBox = null, ToolCommand command = null)
        {
            InitializeComponent();
            //autoCompleteTextBoxCommands.Values = autoCompleteTextBoxCommandsList;
            autoCompleteTextBoxCommands.HandleCreated += (o, e) =>
            {
                autoCompleteTextBoxCommands.Values = autoCompleteTextBoxCommandsList;
                //List<string> vals = new List<string>(ConsoleAutoCompleteStrings);
                //vals.AddRange((IEnumerable<string>)RuntimeCommand.RuntimeCommands);
                //autoCompleteTextBoxCommands.Values = vals.ToArray();
            };

            commandEditor = this;

            if (listBox != null)
            {
                this.listBox = listBox;
            }
            comboBoxConditionType.DataSource = Enum.GetValues(typeof(ToolCommand.TriggerType));

            if (command != null)
            {
                isEditing         = true;
                commandEditTarget = command;

                // set controls to display existing properties

                textBoxName.Text = command.Name;
                conditionType    = command.ConditionType;
                comboBoxConditionType.SelectedItem = (conditionType);
                conditionOperator = command.ConditionOperator;
                buttonOperatorSelection_SetText();
                numericUpDownThreshold.Value = command.ConditionThreshold;
                selectionRangeSliderPlayerCountRange.SelectedMin = command.PlayerCountRangeMin;
                selectionRangeSliderPlayerCountRange.SelectedMax = command.PlayerCountRangeMax;
                comboBoxDailyCommandTime.SelectedIndex           = command.RunTime;
                textBoxCustomServerCommand.Text = command.CustomServerCommand;
                textBoxCommandTag.Text          = command.Tag;

                switch (conditionType)
                {
                case ToolCommand.TriggerType.EveryXMinutes:
                    numericUpDownRunIntervalMinutes.Value = command.RunTime;
                    checkBoxGlobalCommand.Enabled         = true;
                    break;

                case ToolCommand.TriggerType.Daily:
                    comboBoxDailyCommandTime.SelectedIndex = command.RunTime;
                    checkBoxGlobalCommand.Enabled          = true;
                    break;

                default: break;
                }

                if (command.IsGlobalToolCommand)
                {
                    checkBoxGlobalCommand.Checked    = true;
                    checkBoxGlobalCommand.CheckState = CheckState.Checked;
                }

                foreach (string commandString in command.CommandStrings)
                {
                    autoCompleteTextBoxCommands.AppendText(commandString + System.Environment.NewLine);
                }
            }

            textBoxName.Select();
            textBoxName.Focus();
        }
Exemplo n.º 3
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            if (textBoxName.Text == "")
            {
                MessageBox.Show("You must specify a name for the command.", "Name Required", MessageBoxButtons.OK);
                return;
            }

            ToolCommand triggerMatch = null;

            if (conditionType == ToolCommand.TriggerType.CustomServerCommand)
            {
                if (string.IsNullOrWhiteSpace(textBoxCustomServerCommand.Text))
                {
                    MessageBox.Show("You must specify text for the custom server command.", "Custom Server Command Text Required", MessageBoxButtons.OK);
                    return;
                }
                if (RuntimeCommand.RuntimeCommandAutoCompleteNames.Contains(textBoxCustomServerCommand.Text))
                {
                    MessageBox.Show(
                        "There is already a Runtime Command using that trigger, please choose a different trigger.",
                        "Custom Server Command Trigger Conflict", MessageBoxButtons.OK
                        );
                    return;
                }
                if ((currentConnection?.Settings?.Commands?.Count ?? 0) > 0)
                {
                    triggerMatch = currentConnection.Settings.Commands.DefaultIfEmpty(null).FirstOrDefault(x => x.CustomServerCommand == textBoxCustomServerCommand.Text);
                }
            }

            ToolCommand nameMatch = null;

            if (GlobalToolCommands.Value.Count > 0)
            {
                nameMatch = GlobalToolCommands.Value.DefaultIfEmpty(null).FirstOrDefault(x => x.Name == textBoxName.Text);
            }
            if (nameMatch == null && currentConnection.Settings.Commands.Count > 0)
            {
                nameMatch = currentConnection.Settings.Commands.DefaultIfEmpty(null).FirstOrDefault(x => x.Name == textBoxName.Text);
            }

            if (isEditing)
            {
                if (nameMatch != null && nameMatch != commandEditTarget)
                {
                    MessageBox.Show("The selected name is used by another conditional command, please choose a unique name.",
                                    "Unique Name Required", MessageBoxButtons.OK
                                    );
                    return;
                }
                else
                {
                    nameMatch = null;
                }

                if (conditionType == ToolCommand.TriggerType.CustomServerCommand && triggerMatch != null && triggerMatch != commandEditTarget)
                {
                    MessageBox.Show("The selected trigger is used by another command, please choose a unique trigger.",
                                    "Unique Trigger Required", MessageBoxButtons.OK
                                    );
                    return;
                }
                else
                {
                    triggerMatch = null;
                }

                if (GlobalToolCommands.Value.Contains(commandEditTarget))
                {
                    GlobalToolCommands.Value.Remove(commandEditTarget);
                }
                else if (currentConnection.Settings.Commands.Contains(commandEditTarget))
                {
                    currentConnection.Settings.Commands.Remove(commandEditTarget);
                }

                commandEditTarget.Disable();

                if (listBox != null)
                {
                    listBox.Items.Remove(listBox.SelectedItem);
                }
            }

            if (nameMatch != null)
            {
                MessageBox.Show("The selected name is used by another conditional command, please choose a unique name.", "Unique Name Required", MessageBoxButtons.OK);
                return;
            }

            if (conditionType == ToolCommand.TriggerType.CustomServerCommand && triggerMatch != null)
            {
                MessageBox.Show("The selected trigger is used by another command, please choose a unique trigger.",
                                "Unique Trigger Required", MessageBoxButtons.OK
                                );
                return;
            }

            #region Get Player Count Operator Value
            Enum.TryParse(comboBoxConditionType.SelectedValue.ToString(), out conditionType);

            switch (buttonCondition_PlayerCount_OperatorSelection.Text)
            {
            case ">": conditionOperator = ToolCommand.Operator.GreatherThan; break;

            case "<": conditionOperator = ToolCommand.Operator.LessThan; break;

            case "=": conditionOperator = ToolCommand.Operator.EqualTo; break;

            case ">=": conditionOperator = ToolCommand.Operator.GreaterThanOrEqualTo; break;

            case "<=": conditionOperator = ToolCommand.Operator.LessThanOrEqualTo; break;
            }
            #endregion

            List <string> commands = new List <string>(
                autoCompleteTextBoxCommands.Text.Split(new string[] { Environment.NewLine },
                                                       StringSplitOptions.RemoveEmptyEntries)
                );

            int runTime;
            switch (conditionType)
            {
            case ToolCommand.TriggerType.EveryXMinutes:
                runTime = (int)numericUpDownRunIntervalMinutes.Value;
                break;

            case ToolCommand.TriggerType.Daily:
                runTime = comboBoxDailyCommandTime.SelectedIndex;
                break;

            default: runTime = 0; break;
            }

            ToolCommand command =
                new ToolCommand(
                    textBoxName.Text,
                    true,
                    commands,
                    conditionType,
                    conditionOperator,
                    (int)numericUpDownThreshold.Value,
                    currentConnection.Settings,
                    textBoxCustomServerCommand.Text,
                    selectionRangeSliderPlayerCountRange.SelectedMin,
                    selectionRangeSliderPlayerCountRange.SelectedMax,
                    runTime,
                    textBoxCommandTag.Text
                    );

            if (command.IsGlobalToolCommand)
            {
                command.IsGlobalToolCommand = true;
                GlobalToolCommands.Value.Add(command);
            }
            else
            {
                currentConnection.Settings.Commands.Add(command);
                command.Initialize(currentConnection);
            }

            if (listBox != null)
            {
                listBox.Items.Add(
                    new Tuple <string, ToolCommand>(command.Name, command)
                    );
            }

            SaveSettings();

            Close();
        }