Skip to content

Commit

Permalink
Add script priority field.
Browse files Browse the repository at this point in the history
  • Loading branch information
brotalnia committed Jan 3, 2022
1 parent 2315830 commit 51772b7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 53 deletions.
2 changes: 2 additions & 0 deletions ScriptEditor/DataFinderForms/FormConditionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,9 @@ private void btnEditAdd_Click(object sender, EventArgs e)
// Get the associated ConditionInfo.
ConditionInfo currentCondition = (ConditionInfo)currentItem.Tag;

dontUpdate = true;
ShowConditionSpecificForm(currentCondition);
dontUpdate = false;
}
}
else
Expand Down
35 changes: 29 additions & 6 deletions ScriptEditor/FormScriptEditor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 39 additions & 21 deletions ScriptEditor/FormScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,18 @@ private void LoadControls()
private string GenerateScriptQuery()
{
string query = "DELETE FROM `" + currentScriptTable + "` WHERE `id`=" + currentScriptId.ToString() + ";\n";
foreach (ListViewItem lvi in lstActions.Items)
query += "INSERT INTO `" + currentScriptTable + "` (`id`, `delay`, `priority`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES\n";
for (int i = 0; i < lstActions.Items.Count; i++)
{
// Get the associated ScriptAction.
ListViewItem lvi = lstActions.Items[i];
ScriptAction currentAction = (ScriptAction)lvi.Tag;

query += "INSERT INTO `" + currentScriptTable + "` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (" + currentAction.Id.ToString() + ", " + currentAction.Delay.ToString() + ", " + currentAction.Command.ToString() + ", " + currentAction.Datalong.ToString() + ", " + currentAction.Datalong2.ToString() + ", " + currentAction.Datalong3.ToString() + ", " + currentAction.Datalong4.ToString() + ", " + currentAction.TargetParam1.ToString() + ", " + currentAction.TargetParam2.ToString() + ", " + currentAction.TargetType.ToString() + ", " + currentAction.DataFlags.ToString() + ", " + currentAction.Dataint.ToString() + ", " + currentAction.Dataint2.ToString() + ", " + currentAction.Dataint3.ToString() + ", " + currentAction.Dataint4.ToString() + ", " + currentAction.X.ToString().Replace(',', '.') + ", " + currentAction.Y.ToString().Replace(',', '.') + ", " + currentAction.Z.ToString().Replace(',', '.') + ", " + currentAction.O.ToString().Replace(',', '.') + ", " + currentAction.ConditionId.ToString() + ", '" + Helpers.MySQLEscape(currentAction.Comments) + "');\n";
if (i > 0)
query += ",\n";
query += "(" + currentAction.Id.ToString() + ", " + currentAction.Delay.ToString() + ", " + currentAction.Priority.ToString() + ", " + currentAction.Command.ToString() + ", " + currentAction.Datalong.ToString() + ", " + currentAction.Datalong2.ToString() + ", " + currentAction.Datalong3.ToString() + ", " + currentAction.Datalong4.ToString() + ", " + currentAction.TargetParam1.ToString() + ", " + currentAction.TargetParam2.ToString() + ", " + currentAction.TargetType.ToString() + ", " + currentAction.DataFlags.ToString() + ", " + currentAction.Dataint.ToString() + ", " + currentAction.Dataint2.ToString() + ", " + currentAction.Dataint3.ToString() + ", " + currentAction.Dataint4.ToString() + ", " + currentAction.X.ToString().Replace(',', '.') + ", " + currentAction.Y.ToString().Replace(',', '.') + ", " + currentAction.Z.ToString().Replace(',', '.') + ", " + currentAction.O.ToString().Replace(',', '.') + ", " + currentAction.ConditionId.ToString() + ", '" + Helpers.MySQLEscape(currentAction.Comments) + "')";
}
return query;
return query + ";\n";
}

private void ResetEditorForm()
Expand Down Expand Up @@ -349,7 +353,7 @@ public void LoadScript(uint script_id, string table_name)

MySqlConnection conn = new MySqlConnection(Program.connString);
MySqlCommand command = conn.CreateCommand();
command.CommandText = "SELECT id, delay, command, datalong, datalong2, datalong3, datalong4, target_param1, target_param2, target_type, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o, condition_id, comments FROM " + table_name + " WHERE id=" + script_id.ToString() + " ORDER BY delay";
command.CommandText = "SELECT id, delay, priority, command, datalong, datalong2, datalong3, datalong4, target_param1, target_param2, target_type, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o, condition_id, comments FROM " + table_name + " WHERE id=" + script_id.ToString() + " ORDER BY delay, priority";
try
{
conn.Open();
Expand All @@ -359,7 +363,7 @@ public void LoadScript(uint script_id, string table_name)
{
ListViewItem lvi = new ListViewItem();

ScriptAction action = new ScriptAction(reader.GetUInt32(0), reader.GetUInt32(1), reader.GetUInt32(2), reader.GetUInt32(3), reader.GetUInt32(4), reader.GetUInt32(5), reader.GetUInt32(6), reader.GetUInt32(7), reader.GetUInt32(8), reader.GetUInt32(9), reader.GetUInt32(10), reader.GetInt32(11), reader.GetInt32(12), reader.GetInt32(13), reader.GetInt32(14), reader.GetFloat(15), reader.GetFloat(16), reader.GetFloat(17), reader.GetFloat(18), reader.GetUInt32(19), reader[20].ToString());
ScriptAction action = new ScriptAction(reader.GetUInt32(0), reader.GetUInt32(1), reader.GetUInt32(2), reader.GetUInt32(3), reader.GetUInt32(4), reader.GetUInt32(5), reader.GetUInt32(6), reader.GetUInt32(7), reader.GetUInt32(8), reader.GetUInt32(9), reader.GetUInt32(10), reader.GetUInt32(11), reader.GetInt32(12), reader.GetInt32(13), reader.GetInt32(14), reader.GetInt32(15), reader.GetFloat(16), reader.GetFloat(17), reader.GetFloat(18), reader.GetFloat(19), reader.GetUInt32(20), reader[21].ToString());

// We show only delay, command id and comment in the listview.
lvi.Text = action.Delay.ToString();
Expand Down Expand Up @@ -439,6 +443,7 @@ private void ResetAndDisableGeneralForm()

// Text Boxes.
txtCommandDelay.Text = "";
txtCommandPriority.Text = "";
txtCommandComment.Text = "";
txtTargetParam1.Text = "";
txtTargetParam2.Text = "";
Expand Down Expand Up @@ -2190,6 +2195,7 @@ private void lstActions_SelectedIndexChanged(object sender, EventArgs e)
ScriptAction selectedAction = (ScriptAction)selectedItem.Tag;

txtCommandDelay.Text = selectedAction.Delay.ToString();
txtCommandPriority.Text = selectedAction.Priority.ToString();
txtCommandComment.Text = selectedAction.Comments;
txtTargetParam1.Text = selectedAction.TargetParam1.ToString();
txtTargetParam2.Text = selectedAction.TargetParam2.ToString();
Expand Down Expand Up @@ -2613,6 +2619,27 @@ private void txtCommandDelay_Leave(object sender, EventArgs e)
lstActions.Sort();
}
}
private void txtCommandPriority_Leave(object sender, EventArgs e)
{
if (lstActions.SelectedItems.Count > 0)
{
// Get the selected item in the listview.
ListViewItem currentItem = lstActions.SelectedItems[0];

// Get the associated ScriptAction.
ScriptAction currentAction = (ScriptAction)currentItem.Tag;

uint priority;
if (!UInt32.TryParse(txtCommandPriority.Text, out priority))
txtCommandPriority.Text = "0";

// Updating priority.
currentAction.Priority = priority;

// Update priority in listview.
lstActions.Sort();
}
}

private void btnTargetParam1_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -2719,7 +2746,7 @@ private void btnActionCopy_Click(object sender, EventArgs e)
ListViewItem newItem = new ListViewItem();

// Copy values of selected action.
ScriptAction newAction = new ScriptAction(currentScriptId, currentAction.Delay, currentAction.Command, currentAction.Datalong, currentAction.Datalong2, currentAction.Datalong3, currentAction.Datalong4, currentAction.TargetParam1, currentAction.TargetParam2, currentAction.TargetType, currentAction.DataFlags, currentAction.Dataint, currentAction.Dataint2, currentAction.Dataint3, currentAction.Dataint4, currentAction.X, currentAction.Y, currentAction.Z, currentAction.O, currentAction.ConditionId, currentAction.Comments + " - Copy");
ScriptAction newAction = new ScriptAction(currentScriptId, currentAction.Delay, currentAction.Priority, currentAction.Command, currentAction.Datalong, currentAction.Datalong2, currentAction.Datalong3, currentAction.Datalong4, currentAction.TargetParam1, currentAction.TargetParam2, currentAction.TargetType, currentAction.DataFlags, currentAction.Dataint, currentAction.Dataint2, currentAction.Dataint3, currentAction.Dataint4, currentAction.X, currentAction.Y, currentAction.Z, currentAction.O, currentAction.ConditionId, currentAction.Comments + " - Copy");

// We show only delay, command id and comment in the listview.
newItem.Text = newAction.Delay.ToString();
Expand Down Expand Up @@ -3155,7 +3182,7 @@ private void Command4SetCheckboxNamesBasedOnFieldIndex(int field)
{
chkModifyFlags1.Text = "UNK_0";
chkModifyFlags1.Visible = true;
chkModifyFlags2.Text = "NON_ATTACKABLE";
chkModifyFlags2.Text = "SPAWNING";
chkModifyFlags2.Visible = true;
chkModifyFlags4.Text = "DISABLE_MOVE";
chkModifyFlags4.Visible = true;
Expand Down Expand Up @@ -4813,8 +4840,6 @@ private void chkJoinCreatureGroup128_CheckedChanged(object sender, EventArgs e)
// Sorts items in the script actions listbox by delay.
class ActionSorter : System.Collections.IComparer
{
public int Column = 0;
public System.Windows.Forms.SortOrder Order = SortOrder.Ascending;
public int Compare(object x, object y) // IComparer Member
{
if (!(x is ListViewItem))
Expand All @@ -4825,20 +4850,13 @@ public int Compare(object x, object y) // IComparer Member
ListViewItem l1 = (ListViewItem)x;
ListViewItem l2 = (ListViewItem)y;

int value1;
int value2;
ScriptAction action1 = (ScriptAction)l1.Tag;
ScriptAction action2 = (ScriptAction)l2.Tag;

Int32.TryParse(l1.SubItems[Column].Text, out value1);
Int32.TryParse(l2.SubItems[Column].Text, out value2);
if (action1.Delay == action2.Delay)
return action1.Priority.CompareTo(action2.Priority);

if (Order == SortOrder.Ascending)
{
return value1.CompareTo(value2);
}
else
{
return value2.CompareTo(value1);
}
return action1.Delay.CompareTo(action2.Delay);
}
}
}
22 changes: 0 additions & 22 deletions ScriptEditor/GameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,28 +865,6 @@ static GameData()
{
// Add update field ids to a list.
UpdateFieldsList.Add(new ComboboxPair("OBJECT_FIELD_SCALE_X", 4));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_OWNER", 6));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_CONTAINED", 8));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_CREATOR", 10));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_GIFTCREATOR", 12));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_STACK_COUNT", 14));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_DURATION", 15));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_SPELL_CHARGES", 16));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_SPELL_CHARGES_01", 17));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_SPELL_CHARGES_02", 18));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_SPELL_CHARGES_03", 19));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_SPELL_CHARGES_04", 20));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_FLAGS", 21));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_ENCHANTMENT", 22));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_PROPERTY_SEED", 43));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_RANDOM_PROPERTIES_ID", 44));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_ITEM_TEXT_ID", 45));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_DURABILITY", 46));
UpdateFieldsList.Add(new ComboboxPair("ITEM_FIELD_MAXDURABILITY", 47));
UpdateFieldsList.Add(new ComboboxPair("CONTAINER_FIELD_NUM_SLOTS", 48));
UpdateFieldsList.Add(new ComboboxPair("CONTAINER_ALIGN_PAD", 49));
UpdateFieldsList.Add(new ComboboxPair("CONTAINER_FIELD_SLOT_1", 50));
UpdateFieldsList.Add(new ComboboxPair("CONTAINER_FIELD_SLOT_LAST", 104));
UpdateFieldsList.Add(new ComboboxPair("UNIT_FIELD_CHARM", 6));
UpdateFieldsList.Add(new ComboboxPair("UNIT_FIELD_SUMMON", 8));
UpdateFieldsList.Add(new ComboboxPair("UNIT_FIELD_CHARMEDBY", 10));
Expand Down
6 changes: 3 additions & 3 deletions ScriptEditor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Vanilla MaNGOS")]
[assembly: AssemblyProduct("ScriptEditor")]
[assembly: AssemblyCopyright("Copyright © brotalnia 2021")]
[assembly: AssemblyCopyright("Copyright © brotalnia 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("8.1.0.0")]
[assembly: AssemblyFileVersion("8.1.0.0")]
[assembly: AssemblyVersion("8.2.0.0")]
[assembly: AssemblyFileVersion("8.2.0.0")]
Loading

0 comments on commit 51772b7

Please sign in to comment.