public void DetectConflicts() { StringBuilder conflicts = new StringBuilder(); for (int i = 0; i < events.Count; ++i) { SmartEvent ev = events.GetEvent(i); for (int j = 0; j < ev.GetActions().Count; ++j) { SmartAction a1 = ev.GetAction(j); SmartAction a2 = SmartFactory.GetInstance().ActionFactory(a1.ID); a2.Copy(a1); for (int p = 0; p < 6; ++p) { if (a1.parameters[p].GetType() != a2.parameters[p].GetType()) { conflicts.AppendLine("Instead of parameter: " + a1.parameters[p].GetType() + "\nWe have: " + a2.parameters[p].GetType()); } } if (a2.ToString() != a1.ToString()) { conflicts.AppendLine("Instead of: \n " + a1.ToString() + "\nWe have:\n " + a2.ToString()); } } } if (conflicts.Length > 0) { MessageBox.Show(conflicts.ToString()); } }
public void AddAction(SmartAction smartAction) { children.Add(smartAction); actions.Add(smartAction); smartAction.parent = this; smartAction.RequestUpdate += ActionRequestUpdateCallback; }
public void InsertAction(SmartAction smartAction, int index) { children.Insert(index + conditions.Count, smartAction); actions.Insert(index, smartAction); smartAction.parent = this; smartAction.RequestUpdate += ActionRequestUpdateCallback; Invalide(); }
private void DropTarget(string str, Point mouse) { SmartEvent el = events.EventAt(mouse.X, mouse.Y); SmartAction action = (SmartAction)el.GetElementFromPos(mouse.X, mouse.Y); SmartTarget target = SmartFactory.GetInstance().TargetFactory(str); target.UpdateParams(action.Target); action.Target = target; }
private void this_pasteEvent(object sender, EventArgs e) { string[] array = Clipboard.GetText().Split('|'); if (array.Length != 15) { return; } SmartAction doc = SmartAction.DeserializeFromArray(array); InsertAction(doc, GetInsertActionIndexFromPos(mouse.X, mouse.Y)); doc.Invalide(); }
private void scratch1_MouseDown(object sender, MouseEventArgs e) { if (ModifierKeys.HasFlag(Keys.Control)) { SmartEvent selected = Selected(); if (selected != null) { SmartAction action = selected.GetSelectedAction(); if (action != null && action.ID == 80) // TRIGGER TIMED EVENT { RequestNewSAIWindow(this, new EventArgsRequestNewSAIWindow(action.parameters[0].GetValue(), SAIType.TimedActionList)); } } } }
public override List <Warning> Validate() { List <Warning> warnings = base.Validate(); for (int i = 0; i < conditions.Count; ++i) { SmartCondition condition = GetCondition(i); warnings.AddRange(condition.Validate()); } for (int i = 0; i < actions.Count; ++i) { SmartAction action = GetAction(i); warnings.AddRange(action.Validate()); } return(warnings); }
private void DropAction(string str, Point mouse) { SmartEvent el = events.EventAt(mouse.X, mouse.Y); switch (dropResult) { case DropResult.INSERT: el.InsertAction(SmartFactory.GetInstance().ActionFactory(str), el.GetInsertActionIndexFromPos(mouse.X, mouse.Y)); break; case DropResult.REPLACE: SmartAction action = (SmartAction)el.GetElementFromPos(mouse.X, mouse.Y); el.ReplaceAction(SmartFactory.GetInstance().ActionFactory(str), action); break; } }
public void ReplaceAction(SmartAction replace, SmartAction search) { replace.Copy(search); int index = children.IndexOf(search); children.Remove(search); children.Insert(index, replace); index = actions.IndexOf(search); actions.Remove(search); actions.Insert(index, replace); replace.parent = this; replace.RequestUpdate += ActionRequestUpdateCallback; Invalide(); }
public static SmartAction DeserializeFromArray(string[] array) { SmartAction action = SmartFactory.GetInstance().ActionFactory(int.Parse(array[0])); action.Target = SmartFactory.GetInstance().TargetFactory(int.Parse(array[7])); for (int i = 0; i < 6; ++i) { action.parameters[i].SetValue(int.Parse(array[i + 1])); } for (int i = 0; i < 3; ++i) { action.Target.parameters[i].SetValue(int.Parse(array[i + 8])); } for (int i = 0; i < 4; ++i) { action.Target.position[i] = float.Parse(array[i + 11]); } return(action); }
// @TODO: to rewrite ASAP!! just for test // I know, it it TOTAL MESS public void LoadFromDB(int entryorguid) { this.entryorguid = entryorguid; DBConnect connect = new DBConnect(); bool opened = connect.OpenConnection(); if (!opened) { return; } events.Clear(); MySql.Data.MySqlClient.MySqlCommand cmd = connect.Query("SELECT * FROM conditions WHERE sourceentry = " + entryorguid + " and sourceid=0 and sourcetypeorreferenceid=22"); Dictionary <int, List <SmartCondition> > conditions = new Dictionary <int, List <SmartCondition> >(); using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader()) { int prevelsegroup = 0; while (reader.Read()) { int id = Convert.ToInt32(reader["sourcegroup"]) - 1; if (!conditions.ContainsKey(id)) { conditions.Add(id, new List <SmartCondition>()); } if (Convert.ToInt32(reader["ElseGroup"]) != prevelsegroup) { conditions[id].Add(new CONDITION_LOGICAL_OR()); } SmartCondition cond = SmartFactory.GetInstance().ConditionFactory(Convert.ToInt32(reader["ConditionTypeOrReference"])); cond.UpdateParams(0, (Convert.ToInt32(reader["ConditionValue1"]))); cond.UpdateParams(1, (Convert.ToInt32(reader["ConditionValue2"]))); cond.UpdateParams(2, (Convert.ToInt32(reader["ConditionValue3"]))); cond.invert = (Convert.ToInt32(reader["NegativeCondition"]) == 1); conditions[id].Add(cond); prevelsegroup = Convert.ToInt32(reader["ElseGroup"]); } } cmd = connect.Query("SELECT * FROM smart_scripts WHERE source_type = " + (int)Type + " and entryorguid = " + entryorguid + " order by id"); SmartEvent prev = null; bool keep_legacy_comments = false; bool keep_lagacy_comments_asked = false; using (MySql.Data.MySqlClient.MySqlDataReader reader = cmd.ExecuteReader()) { int next_link = -1; while (reader.Read()) { //(`entryorguid`,`source_type`,`id`,`link`,`event_type`,`event_phase_mask`,`event_chance`,`event_flags`,`event_param1`,`event_param2`,`event_param3`,`event_param4`,`action_type`,`action_param1`,`action_param2`,`action_param3`,`action_param4`,`action_param5`,`action_param6`,`target_type`,`target_param1`,`target_param2`,`target_param3`,`target_x`,`target_y`,`target_z`,`target_o`,`comment`) int id = Convert.ToInt32(reader["id"]); int entry = Convert.ToInt32(reader["entryorguid"]); string comment = Convert.ToString(reader["comment"]); SmartAction a = SmartFactory.GetInstance().ActionFactory(Convert.ToInt32(reader["action_type"])); SmartTarget target = SmartFactory.GetInstance().TargetFactory(Convert.ToInt32(reader["target_type"])); for (int i = 0; i < 6; i++) { a.UpdateParams(i, Convert.ToInt32(reader["action_param" + (i + 1)])); } for (int i = 0; i < 3; i++) { target.UpdateParams(i, Convert.ToInt32(reader["target_param" + (i + 1)])); } target.position[0] = (float)Convert.ToDouble(reader["target_x"]); target.position[1] = (float)Convert.ToDouble(reader["target_y"]); target.position[2] = (float)Convert.ToDouble(reader["target_z"]); target.position[3] = (float)Convert.ToDouble(reader["target_o"]); a.Target = target; if (comment.IndexOf(" // ") > -1) { a.Comment = comment.Substring(comment.IndexOf(" // ") + 4); } else if (!Properties.Settings.Default.DiscardLegacyComments) { if (!keep_lagacy_comments_asked) { DialogResult res = PSTaskDialog.cTaskDialog.ShowTaskDialogBox("Legacy comments", "Legacy comments", "Visual SAI Studio has detected script you loaded doesn't have comments created with SAI Studio.\n", "", "", "Never propose keeping legacy comments", "", "Keep legacy comments|Discard legacy comments", PSTaskDialog.eTaskDialogButtons.Cancel, PSTaskDialog.eSysIcons.Question, PSTaskDialog.eSysIcons.Information); if (PSTaskDialog.cTaskDialog.VerificationChecked) { Properties.Settings.Default.DiscardLegacyComments = true; } if (PSTaskDialog.cTaskDialog.CommandButtonResult == 0) { keep_legacy_comments = true; } keep_lagacy_comments_asked = true; } if (keep_legacy_comments) { a.Comment = comment; } } if (id == next_link) { prev.AddAction(a); } else { SmartEvent ev = SmartFactory.GetInstance().EventFactory(Convert.ToInt32(reader["event_type"])); ev.chance = Convert.ToInt32(reader["event_chance"]); ev.flags = (SmartEventFlag)Convert.ToInt32(reader["event_flags"]); ev.phasemask = (SmartPhaseMask)Convert.ToInt32(reader["event_phase_mask"]); ev.UpdateParams(0, Convert.ToInt32(reader["event_param1"])); ev.UpdateParams(1, Convert.ToInt32(reader["event_param2"])); ev.UpdateParams(2, Convert.ToInt32(reader["event_param3"])); ev.UpdateParams(3, Convert.ToInt32(reader["event_param4"])); if (conditions.ContainsKey(id)) { foreach (SmartCondition cond in conditions[id]) { ev.AddCondition(cond); } } ev.AddAction(a); events.Add(ev); prev = ev; } next_link = Convert.ToInt32(reader["link"]); } } connect.CloseConnection(); scratch1.Refresh(); }