Пример #1
0
        private void buttonGenerateSql_Click(object sender, EventArgs e)
        {
            string sql = String.Empty;

            switch (conditions.Count)
            {
            case 0:
                MessageBox.Show("You did not save any conditions in this session yet. If you want to generate SQL for the open condition, first press the Save Condition button.", "No conditions!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

            case 1:
                sql  = "-- Conditions generated by SAI-Editor\n";
                sql += "DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=" + conditions[0].SourceTypeOrReferenceId;
                sql += " AND `SourceGroup`=" + conditions[0].SourceGroup + " AND `SourceEntry`=" + conditions[0].SourceEntry + ";\n";
                sql += "INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`NegativeCondition`,`ErrorType`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES\n";
                sql += "(" + conditions[0].SourceTypeOrReferenceId + "," + conditions[0].SourceGroup + "," + conditions[0].SourceEntry;
                sql += "," + conditions[0].SourceId + "," + conditions[0].ElseGroup + "," + conditions[0].ConditionTypeOrReference;
                sql += "," + conditions[0].ConditionTarget + "," + conditions[0].ConditionValue1;
                sql += "," + conditions[0].ConditionValue2 + "," + conditions[0].ConditionValue3;
                sql += "," + conditions[0].NegativeCondition + "," + conditions[0].ErrorType + "," + conditions[0].ErrorTextId;
                sql += "," + '"' + conditions[0].ScriptName + '"' + "," + '"' + conditions[0].Comment + '"' + ");";
                break;

            default:
                string deleteFromString = String.Empty;
                sql  = "_replaceThisWithDeleteFrom_";
                sql += "INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`NegativeCondition`,`ErrorType`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES\n";

                for (int i = 0; i < conditions.Count; ++i)
                {
                    Condition condition = conditions[i];

                    deleteFromString += "DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=" + condition.SourceTypeOrReferenceId;
                    deleteFromString += " AND `SourceGroup`=" + condition.SourceGroup + " AND `SourceEntry`=" + condition.SourceEntry + ";\n";

                    sql += "(" + condition.SourceTypeOrReferenceId + "," + condition.SourceGroup + "," + condition.SourceEntry;
                    sql += "," + condition.SourceId + "," + condition.ElseGroup + "," + condition.ConditionTypeOrReference;
                    sql += "," + condition.ConditionTarget + "," + condition.ConditionValue1;
                    sql += "," + condition.ConditionValue2 + "," + condition.ConditionValue3;
                    sql += "," + conditions[0].NegativeCondition + "," + conditions[0].ErrorType + "," + condition.ErrorTextId;
                    sql += "," + '"' + condition.ScriptName + '"' + "," + '"' + condition.Comment + '"' + ")";
                    sql += (i != conditions.Count - 1) ? ",\n" : ";\n";
                }

                sql = sql.Replace("_replaceThisWithDeleteFrom_", deleteFromString);
                break;
            }

            using (SqlOutputForm sqlOutputForm = new SqlOutputForm(sql, false))
                sqlOutputForm.ShowDialog();
        }
Пример #2
0
        private async void buttonGenerateSql_Click(object sender, EventArgs e)
        {
            if (formState != FormState.FormStateMain)
                return;

            using (SqlOutputForm sqlOutputForm = new SqlOutputForm(await GenerateSmartAiSqlFromListView(), await GenerateSmartAiRevertQuery()))
                sqlOutputForm.ShowDialog(this);
        }
Пример #3
0
        public async void TryToCreateScript(bool fromNewLine = false)
        {
            if (!pictureBoxCreateScript.Enabled || String.IsNullOrWhiteSpace(textBoxEntryOrGuid.Text) || comboBoxSourceType.SelectedIndex == -1)
                return;

            if (listViewSmartScripts.Items.Count > 0)
            {
                DialogResult dialogResult = MessageBox.Show("There is already a script loaded at this moment. Do you want to overwrite this?\n\nWarning: overwriting means local unsaved changes will also be discarded!", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogResult != DialogResult.Yes)
                    return;

                ResetFieldsToDefault();
            }

            int entryorguid = 0;

            try
            {
                entryorguid = Int32.Parse(textBoxEntryOrGuid.Text);
            }
            catch (OverflowException)
            {
                MessageBox.Show("The entryorguid is either too big or too small.", "Something went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            catch (FormatException)
            {
                MessageBox.Show("The entryorguid field does not contain a valid number.", "Something went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            lastSmartScriptIdOfScript = 0;
            int source_type = (int)GetSourceTypeByIndex();
            string sourceTypeString = GetSourceTypeString((SourceTypes)source_type);

            if (!Settings.Default.UseWorldDatabase)
                goto SkipWorldDatabaseChecks;

            string aiName = await SAI_Editor_Manager.Instance.worldDatabase.GetObjectAiName(entryorguid, source_type);
            List<SmartScript> smartScripts = await SAI_Editor_Manager.Instance.worldDatabase.GetSmartScripts(entryorguid, source_type);

            //! Allow adding new lines even if the AIName is already set
            if ((SourceTypes)source_type == SourceTypes.SourceTypeAreaTrigger)
            {
                if (aiName != String.Empty)
                {
                    string errorMessage = "This areatrigger already has its ";

                    if (aiName != "SmartTrigger")
                        errorMessage += "ScriptName set to '" + aiName + "'";
                    else
                        errorMessage += "AIName set (for SmartAI)! Do you want to load it instead?";

                    DialogResult dialogResult = MessageBox.Show(errorMessage, "Something went wrong", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (dialogResult == DialogResult.Yes)
                        TryToLoadScript();

                    return;
                }
            }
            else
            {
                if (aiName != String.Empty)
                {
                    string strAlreadyHasAiName = String.Empty;
                    bool aiNameIsSmart = SAI_Editor_Manager.Instance.IsAiNameSmartAi(aiName);

                    if (aiNameIsSmart)
                    {
                        if (smartScripts == null || smartScripts.Count == 0)
                            goto SkipWorldDatabaseChecks;

                        if (fromNewLine)
                            goto SkipAiNameAndScriptNameChecks;

                        strAlreadyHasAiName += "This " + sourceTypeString + " already has its AIName set to '" + aiName + "'";
                        strAlreadyHasAiName += "! Do you want to load it instead?";
                    }
                    else
                    {
                        strAlreadyHasAiName += "This " + sourceTypeString + " already has its AIName set to '" + aiName + "'";
                        strAlreadyHasAiName += " and can therefore not have any SmartAI. Do you want to get rid of this AIName right now?";
                    }

                    DialogResult dialogResult = MessageBox.Show(strAlreadyHasAiName, "Something went wrong", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (dialogResult == DialogResult.Yes)
                    {
                        if (!aiNameIsSmart)
                        {
                            //! We don't have to target areatrigger_scripts here, as we've already done this a few lines up
                            string sqlOutput = "UPDATE `" + GetTemplateTableBySourceType((SourceTypes)source_type) + "` SET `AIName`=" + '"' + '"' + " WHERE `entry`=" + entryorguid + ";\n";

                            using (SqlOutputForm sqlOutputForm = new SqlOutputForm(sqlOutput))
                                sqlOutputForm.ShowDialog(this);
                        }
                        else
                            TryToLoadScript();
                    }

                    return;
                }

                string scriptName = await SAI_Editor_Manager.Instance.worldDatabase.GetObjectScriptName(entryorguid, source_type);

                if (scriptName != String.Empty)
                {
                    MessageBox.Show("This " + sourceTypeString + " already has a ScriptName set (to '" + scriptName + "')!", "Something went wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

        SkipAiNameAndScriptNameChecks:

            if (smartScripts != null && smartScripts.Count > 0)
            {
                string errorMessage = "This " + sourceTypeString + " already has smart scripts";// (without its AIName set to SmartAI)! Do you want to load it instead?";

                if ((SourceTypes)source_type != SourceTypes.SourceTypeScriptedActionlist)
                    errorMessage += " (without its AIName set to SmartAI)!";
                else
                    errorMessage += "!";

                errorMessage += " Do you want to load it instead?";
                DialogResult dialogResult = MessageBox.Show(errorMessage, "Something went wrong", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dialogResult == DialogResult.Yes)
                    TryToLoadScript();

                return;
            }

        SkipWorldDatabaseChecks:
            buttonNewLine.Enabled = false;
            checkBoxListActionlistsOrEntries.Text = GetSourceTypeByIndex() == SourceTypes.SourceTypeScriptedActionlist ? "List entries too" : "List actionlists too";
            pictureBoxLoadScript.Enabled = false;
            pictureBoxCreateScript.Enabled = false;

            originalEntryOrGuidAndSourceType.entryOrGuid = entryorguid;
            originalEntryOrGuidAndSourceType.sourceType = (SourceTypes)source_type;

            listViewSmartScripts.ReplaceSmartScripts(new List<SmartScript>());

            SmartScript newSmartScript = new SmartScript();
            newSmartScript.entryorguid = entryorguid;
            newSmartScript.source_type = source_type;

            if (checkBoxLockEventId.Checked)
                newSmartScript.id = 0;
            else
                newSmartScript.id = -1;

            newSmartScript.link = XConverter.ToInt32(textBoxLinkTo.Text);
            newSmartScript.event_type = XConverter.ToInt32(textBoxEventType.Text);
            newSmartScript.event_phase_mask = XConverter.ToInt32(textBoxEventPhasemask.Text);
            newSmartScript.event_chance = XConverter.ToInt32(textBoxEventChance.Value);
            newSmartScript.event_flags = XConverter.ToInt32(textBoxEventFlags.Text);
            newSmartScript.event_param1 = XConverter.ToInt32(textBoxEventParam1.Text);
            newSmartScript.event_param2 = XConverter.ToInt32(textBoxEventParam2.Text);
            newSmartScript.event_param3 = XConverter.ToInt32(textBoxEventParam3.Text);
            newSmartScript.event_param4 = XConverter.ToInt32(textBoxEventParam4.Text);
            newSmartScript.action_type = XConverter.ToInt32(textBoxActionType.Text);
            newSmartScript.action_param1 = XConverter.ToInt32(textBoxActionParam1.Text);
            newSmartScript.action_param2 = XConverter.ToInt32(textBoxActionParam2.Text);
            newSmartScript.action_param3 = XConverter.ToInt32(textBoxActionParam3.Text);
            newSmartScript.action_param4 = XConverter.ToInt32(textBoxActionParam4.Text);
            newSmartScript.action_param5 = XConverter.ToInt32(textBoxActionParam5.Text);
            newSmartScript.action_param6 = XConverter.ToInt32(textBoxActionParam6.Text);
            newSmartScript.target_type = XConverter.ToInt32(textBoxTargetType.Text);
            newSmartScript.target_param1 = XConverter.ToInt32(textBoxTargetParam1.Text);
            newSmartScript.target_param2 = XConverter.ToInt32(textBoxTargetParam2.Text);
            newSmartScript.target_param3 = XConverter.ToInt32(textBoxTargetParam3.Text);
            newSmartScript.target_x = textBoxTargetX.Text;
            newSmartScript.target_y = textBoxTargetY.Text;
            newSmartScript.target_z = textBoxTargetZ.Text;
            newSmartScript.target_o = textBoxTargetO.Text;

            if (Settings.Default.GenerateComments && Settings.Default.UseWorldDatabase)
                newSmartScript.comment = await CommentGenerator.Instance.GenerateCommentFor(newSmartScript, originalEntryOrGuidAndSourceType);
            else if (textBoxComments.Text.Contains(" - Event - Action (phase) (dungeon difficulty)"))
                newSmartScript.comment = SAI_Editor_Manager.Instance.GetDefaultCommentForSourceType((SourceTypes)newSmartScript.source_type);
            else
                newSmartScript.comment = textBoxComments.Text;

            listViewSmartScripts.AddSmartScript(newSmartScript);

            HandleShowBasicInfo();

            listViewSmartScripts.Items[0].Selected = true;
            listViewSmartScripts.Select();

            buttonNewLine.Enabled = textBoxEntryOrGuid.Text.Length > 0;
            SetGenerateCommentsEnabled(listViewSmartScripts.Items.Count > 0 && Settings.Default.UseWorldDatabase);
            pictureBoxLoadScript.Enabled = textBoxEntryOrGuid.Text.Length > 0 && Settings.Default.UseWorldDatabase;
            pictureBoxCreateScript.Enabled = textBoxEntryOrGuid.Text.Length > 0;
        }
Пример #4
0
 private async void buttonGenerateSql_Click(object sender, EventArgs e)
 {
     using (SqlOutputForm sqlOutputForm = new SqlOutputForm(await GenerateSmartAiSqlFromListView(), true, await GenerateSmartAiRevertQuery()))
         sqlOutputForm.ShowDialog(this);
 }
Пример #5
0
        private async void generateSQLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (formState != FormState.FormStateMain)
                return;

            using (SqlOutputForm sqlOutputForm = new SqlOutputForm(await GetActiveUserControl().GenerateSmartAiSqlFromListView(), true, await GetActiveUserControl().GenerateSmartAiRevertQuery()))
                sqlOutputForm.ShowDialog(this);
        }
Пример #6
0
        private void buttonGenerateSql_Click(object sender, EventArgs e)
        {
            string sql = String.Empty;

            switch (conditions.Count)
            {
                case 0:
                    MessageBox.Show("You did not save any conditions in this session yet. If you want to generate SQL for the open condition, first press the Save Condition button.", "No conditions!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                case 1:
                    sql  = "DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=" + conditions[0].SourceTypeOrReferenceId;
                    sql += " AND `SourceGroup`=" + conditions[0].SourceGroup + " AND `SourceEntry`=" + conditions[0].SourceEntry + ";\n";
                    sql += "INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES\n";
                    sql += "(" + conditions[0].SourceTypeOrReferenceId + "," + conditions[0].SourceGroup + "," + conditions[0].SourceEntry;
                    sql += "," + conditions[0].SourceId + "," + conditions[0].ElseGroup + "," + conditions[0].ConditionTypeOrReference;
                    sql += "," + conditions[0].ConditionTarget + "," + conditions[0].ConditionValue1;
                    sql += "," + conditions[0].ConditionValue2 + "," + conditions[0].ConditionValue3 + "," + conditions[0].ErrorTextId;
                    sql += "," + '"' + conditions[0].ScriptName + '"' + "," + '"' + conditions[0].Comment + '"' + ");";
                    break;
                default:
                    string deleteFromString = String.Empty;
                    sql =  "_replaceThisWithDeleteFrom_";
                    sql += "INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES\n";

                    for (int i = 0; i < conditions.Count; ++i)
                    {
                        Condition condition = conditions[i];

                        deleteFromString += "DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=" + condition.SourceTypeOrReferenceId;
                        deleteFromString += " AND `SourceGroup`=" + condition.SourceGroup + " AND `SourceEntry`=" + condition.SourceEntry + ";\n";

                        sql += "(" + condition.SourceTypeOrReferenceId + "," + condition.SourceGroup + "," + condition.SourceEntry;
                        sql += "," + condition.SourceId + "," + condition.ElseGroup + "," + condition.ConditionTypeOrReference;
                        sql += "," + condition.ConditionTarget + "," + condition.ConditionValue1;
                        sql += "," + condition.ConditionValue2 + "," + condition.ConditionValue3 + "," + condition.ErrorTextId;
                        sql += "," + '"' + condition.ScriptName + '"' + "," + '"' + condition.Comment + '"' + ")";
                        sql += (i != conditions.Count - 1) ? ",\n" : ";\n";
                    }

                    sql = sql.Replace("_replaceThisWithDeleteFrom_", deleteFromString);
                    break;
            }

            using (SqlOutputForm sqlOutputForm = new SqlOutputForm(sql, false))
                sqlOutputForm.ShowDialog();
        }