private static void SelectSetValue(VarOperation op, string value, Action updateAction) { if (value == null) { updateAction.Invoke(); return; } if (value.Equals("{NUMBER}")) { // Vars doesnt localize new QuestEditorTextEdit( new StringKey("val", "X_COLON", CommonStringKeys.NUMBER), "", s => SetNumValue(op, s, updateAction)).EditText(); } else { op.value = value; updateAction.Invoke(); } }
public static HashSet <string> ExtractVarsFromEvent(QuestData.Event e) { HashSet <string> vars = new HashSet <string>(); foreach (VarOperation op in e.operations) { vars.Add(op.var); if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } if (e.tests == null) { return(vars); } foreach (VarTestsComponent tc in e.tests.VarTestsComponents) { if (tc is VarOperation) { VarOperation op = (VarOperation)tc; if (op.var.Length > 0 && op.var[0] != '#') { vars.Add(op.var); } if (op.value.Length > 0 && op.value[0] != '#' && !char.IsNumber(op.value[0]) && op.value[0] != '-' && op.value[0] != '.') { vars.Add(op.value); } } } if (!string.IsNullOrEmpty(e.quotaVar) && e.quotaVar[0] != '#') { vars.Add(e.quotaVar); } return(vars); }
public static QuestButtonData FromSingleString(StringKey labelKey, string eventDataString) { if (string.IsNullOrWhiteSpace(eventDataString)) { return(new QuestButtonData(labelKey)); } // Extract event names var strings = eventDataString.Split(EVENT_PARAMETER_SEPARATOR); if (strings.Length <= 0) { return(new QuestButtonData(labelKey)); } var questNames = strings[0].Split(EVENT_NAME_SEPARATOR, StringSplitOptions.RemoveEmptyEntries); // Backward compatibility with unreleased 2.4.11a // Skip conditional event parameters if not all parameters are present if (strings.Length < 4) { return(new QuestButtonData(labelKey, questNames.ToList())); } var conditionString = string.Join(",", strings[1], strings[2], strings[3]); VarOperation condition = new VarOperation(conditionString); var varTests = new VarTests(); varTests.Add(condition); // Optional ButtonAction parameter (defaults to DISABLE, but can be HIDE or NONE as well) if (strings.Length > 4 && Enum.TryParse(strings[4], true, out QuestButtonAction action)) { return(new QuestButtonData(labelKey, questNames.ToList(), varTests, action)); } return(new QuestButtonData(labelKey, questNames.ToList(), varTests)); }
public void SelectAddOp(string var, bool test = true) { VarOperation op = new VarOperation(); op.var = var; op.operation = "="; if (test) { op.operation = ">"; } op.value = "0"; if (op.var.Equals("{NEW}")) { // Var name doesn localize varText = new QuestEditorTextEdit(VAR_NAME, "", delegate { NewVar(op, test); }); varText.EditText(); } else { if (test) { if (component.tests.VarTestsComponents.Count == 0) { component.tests.Add(op); } else { component.tests.Add(new VarTestsLogicalOperator()); component.tests.Add(op); } } else { component.operations.Add(op); } Update(); } }
public bool Test(VarOperation op) { float value = GetOpValue(op); if (op.operation.Equals("==")) { return(vars[op.var] == value); } if (op.operation.Equals("!=")) { return(vars[op.var] != value); } if (op.operation.Equals(">=")) { return(vars[op.var] >= value); } if (op.operation.Equals("<=")) { return(vars[op.var] <= value); } if (op.operation.Equals(">")) { return(vars[op.var] > value); } if (op.operation.Equals("<")) { return(vars[op.var] < value); } // unknown tests fail return(false); }
private static void NewVar(string value, VarOperation op, bool test, ITestable testable, Action updateAction) { op.var = System.Text.RegularExpressions.Regex.Replace(value, "[^A-Za-z0-9_]", ""); if (op.var.Length > 0) { if (value[0] == '%') { op.var = '%' + op.var; } if (value[0] == '@') { op.var = '@' + op.var; } if (char.IsNumber(op.var[0]) || op.var[0] == '-' || op.var[0] == '.') { op.var = "var" + op.var; } if (test) { if (testable.Tests.VarTestsComponents.Count == 0) { testable.Tests.Add(op); } else { testable.Tests.Add(new VarTestsLogicalOperator()); testable.Tests.Add(op); } } else { testable.Operations.Add(op); } } updateAction.Invoke(); }
public void NewVar(VarOperation op, bool test) { op.var = System.Text.RegularExpressions.Regex.Replace(varText.value, "[^A-Za-z0-9_]", ""); if (op.var.Length > 0) { if (varText.value[0] == '%') { op.var = '%' + op.var; } if (varText.value[0] == '@') { op.var = '@' + op.var; } if (char.IsNumber(op.var[0]) || op.var[0] == '-' || op.var[0] == '.') { op.var = "var" + op.var; } if (test) { if (component.tests.VarTestsComponents.Count == 0) { component.tests.Add(op); } else { component.tests.Add(new VarTestsLogicalOperator()); component.tests.Add(op); } } else { component.operations.Add(op); } } Update(); }
public static float AddEventVarConditionComponents(Transform parentTransform, float xOffset, float yOffset, ITestable testable, Action updateAction) { UIElement ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 18, 1); ui.SetText(new StringKey("val", "X_COLON", CommonStringKeys.TESTS)); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 18f, yOffset, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { AddTestOp(testable, updateAction); }); new UIElementBorder(ui, Color.green); if (testable.Tests.VarTestsComponents.Count > 0) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { SelectAddParenthesis(testable, updateAction); }); new UIElementBorder(ui, Color.green); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1.0f, yOffset, 2, 1); ui.SetText("(...)"); } yOffset++; int component_index = 0; foreach (VarTestsComponent tc in testable.Tests.VarTestsComponents) { if (tc is VarOperation) { int tmp_index = component_index; // only display arrows if item can be moved if (component_index != (testable.Tests.VarTestsComponents.Count - 1) && testable.Tests.VarTestsComponents.Count > 1 && testable.Tests.VarTestsComponents.FindIndex(component_index + 1, x => x.GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) != -1 ) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, false); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } if (component_index != 0 && testable.Tests.VarTestsComponents.FindLastIndex(component_index - 1, x => x.GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) != -1 ) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1.0f, yOffset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, true); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } VarOperation tmp = (VarOperation)tc; ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 2f, yOffset, 8.5f, 1); ui.SetText(tmp.var); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 10.5f, yOffset, 2, 1); ui.SetText(tmp.operation); ui.SetButton(delegate { SetTestOpp(tmp, updateAction); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 12.5f, yOffset, 5.5f, 1); ui.SetText(tmp.value); ui.SetButton(delegate { SetValue(tmp, updateAction); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 18f, yOffset++, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { RemoveOp(testable.Tests, tmp_index, updateAction); }); new UIElementBorder(ui, Color.red); } if (tc is VarTestsLogicalOperator) { VarTestsLogicalOperator tmp = (VarTestsLogicalOperator)tc; ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 9.5f, yOffset, 4, 1); if (tmp.op.Equals("AND")) { ui.SetText(CommonStringKeys.AND); } else if (tmp.op.Equals("OR")) { ui.SetText(CommonStringKeys.OR); } ui.SetButton(delegate { tmp.NextLogicalOperator(); updateAction.Invoke(); }); new UIElementBorder(ui); yOffset++; } if (tc is VarTestsParenthesis) { int tmp_index = component_index; VarTestsParenthesis tp = (VarTestsParenthesis)tc; if (component_index != (testable.Tests.VarTestsComponents.Count - 1) && testable.Tests.VarTestsComponents.FindIndex(component_index + 1, x => x.GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) != -1 ) { if (tp.parenthesis == "(") { int valid_index = testable.Tests.FindNextValidPosition(component_index, false); if (valid_index != -1 && testable.Tests.FindClosingParenthesis(valid_index) != -1) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, false); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } } else if (tp.parenthesis == ")") { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset, yOffset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, false); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } } if (component_index != 0 && testable.Tests.VarTestsComponents.FindLastIndex(component_index - 1, x => x.GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) != -1 ) { if (tp.parenthesis == "(") { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1f, yOffset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, true); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } else if (tp.parenthesis == ")") { int valid_index = testable.Tests.FindNextValidPosition(component_index, true); if (valid_index != -1 && testable.Tests.FindOpeningParenthesis(valid_index) != -1) { ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 1f, yOffset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { testable.Tests.moveComponent(tmp_index, true); updateAction.Invoke(); }); new UIElementBorder(ui, Color.yellow); } } } ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 2f, yOffset, 2, 1); ui.SetText(tp.parenthesis); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, parentTransform); ui.SetLocation(xOffset + 4f, yOffset, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { testable.Tests.Remove(tmp_index); updateAction.Invoke(); }); new UIElementBorder(ui, Color.red); yOffset++; } component_index++; } return(yOffset + 1); }
/// <summary> Search for the next valid position for parenthesis or varOperation </summary> /// <param name="index">index of current item to move</param> /// <param name="up">direction of requested movement (visually on UI)</param> /// <returns> index of next position</returns> public int FindNextValidPosition(int index, bool up) { if (VarTestsComponents[index].GetClassVarTestsComponentType() != VarTestsParenthesis.GetVarTestsComponentType() && VarTestsComponents[index].GetClassVarTestsComponentType() != VarOperation.GetVarTestsComponentType()) { return(-1); } int i = index; if (up) { i--; } else { i++; } if (VarTestsComponents[index].GetClassVarTestsComponentType() == VarTestsParenthesis.GetVarTestsComponentType()) { VarTestsParenthesis tmp = (VarTestsParenthesis)VarTestsComponents[index]; while (i >= 0 && i <= VarTestsComponents.Count - 1) { if ( // "(" should be before a varOperation or at the beginning a&(b a&((b (a&b (tmp.parenthesis == "(" && VarTestsComponents[i].GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) || // ")" should be before a LogicalOperator or at the end a)&b a))&b a&b) (tmp.parenthesis == ")" && VarTestsComponents[i].GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) ) { if (up) { return(i); } else if (i != index + 1)// if going down, ignore first item found { return(i - 1); } } if (up) { i--; } else { i++; } } if (i >= VarTestsComponents.Count && tmp.parenthesis == ")") { return(VarTestsComponents.Count - 1); } else if (i <= 0 && tmp.parenthesis == "(") { return(0); } } else if (VarTestsComponents[index].GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) { while (i >= 0 && i <= VarTestsComponents.Count - 1) { // varOperation should take the place of another varOperation if (VarTestsComponents[i].GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) { return(i); } if (up) { i--; } else { i++; } } } if (i < 0 || i >= VarTestsComponents.Count) { return(-1); } // this should not happen ValkyrieDebug.Log("Invalid test position"); return(-1); }
public void SelectSetOp(VarOperation op, string operation) { op.operation = operation; Update(); }
virtual public float AddEventVarConditionComponents(float offset) { UIElement ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 18, 1); ui.SetText(new StringKey("val", "X_COLON", TESTS)); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(18.5f, offset, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { AddTestOp(); }); new UIElementBorder(ui, Color.green); if (component.tests.VarTestsComponents.Count > 0) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 1, 1); ui.SetText(CommonStringKeys.PLUS, Color.green); ui.SetButton(delegate { SelectAddParenthesis(); }); new UIElementBorder(ui, Color.green); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(1.5f, offset, 2, 1); ui.SetText("(...)"); } offset++; int component_index = 0; foreach (VarTestsComponent tc in component.tests.VarTestsComponents) { if (tc is VarOperation) { int tmp_index = component_index; // only display arrows if item can be moved if (component_index != (component.tests.VarTestsComponents.Count - 1) && component.tests.VarTestsComponents.Count > 1 && component.tests.VarTestsComponents.FindIndex(component_index + 1, x => x.GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) != -1 ) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { component.tests.moveComponent(tmp_index, false); Update(); }); new UIElementBorder(ui, Color.yellow); } if (component_index != 0 && component.tests.VarTestsComponents.FindLastIndex(component_index - 1, x => x.GetClassVarTestsComponentType() == VarTestsLogicalOperator.GetVarTestsComponentType()) != -1 ) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(1.5f, offset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { component.tests.moveComponent(tmp_index, true); Update(); }); new UIElementBorder(ui, Color.yellow); } VarOperation tmp = (VarOperation)tc; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(2.5f, offset, 8.5f, 1); ui.SetText(tmp.var); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(11f, offset, 2, 1); ui.SetText(tmp.operation); ui.SetButton(delegate { SetTestOpp(tmp); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(13f, offset, 5.5f, 1); ui.SetText(tmp.value); ui.SetButton(delegate { SetValue(tmp); }); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(18.5f, offset++, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { RemoveOp(tmp_index); }); new UIElementBorder(ui, Color.red); } if (tc is VarTestsLogicalOperator) { VarTestsLogicalOperator tmp = (VarTestsLogicalOperator)tc; ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(10f, offset, 4, 1); if (tmp.op.Equals("AND")) { ui.SetText(AND); } else if (tmp.op.Equals("OR")) { ui.SetText(OR); } ui.SetButton(delegate { tmp.NextLogicalOperator(); Update(); }); new UIElementBorder(ui); offset++; } if (tc is VarTestsParenthesis) { int tmp_index = component_index; VarTestsParenthesis tp = (VarTestsParenthesis)tc; if (component_index != (component.tests.VarTestsComponents.Count - 1) && component.tests.VarTestsComponents.FindIndex(component_index + 1, x => x.GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) != -1 ) { if (tp.parenthesis == "(") { int valid_index = component.tests.FindNextValidPosition(component_index, false); if (valid_index != -1 && component.tests.FindClosingParenthesis(valid_index) != -1) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { component.tests.moveComponent(tmp_index, false); Update(); }); new UIElementBorder(ui, Color.yellow); } } else if (tp.parenthesis == ")") { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(0.5f, offset, 1, 1); ui.SetText(CommonStringKeys.DOWN, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { component.tests.moveComponent(tmp_index, false); Update(); }); new UIElementBorder(ui, Color.yellow); } } if (component_index != 0 && component.tests.VarTestsComponents.FindLastIndex(component_index - 1, x => x.GetClassVarTestsComponentType() == VarOperation.GetVarTestsComponentType()) != -1 ) { if (tp.parenthesis == "(") { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(1.5f, offset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { component.tests.moveComponent(tmp_index, true); Update(); }); new UIElementBorder(ui, Color.yellow); } else if (tp.parenthesis == ")") { int valid_index = component.tests.FindNextValidPosition(component_index, true); if (valid_index != -1 && component.tests.FindOpeningParenthesis(valid_index) != -1) { ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(1.5f, offset, 1, 1); ui.SetText(CommonStringKeys.UP, Color.yellow); ui.SetTextAlignment(TextAnchor.LowerCenter); ui.SetButton(delegate { component.tests.moveComponent(tmp_index, true); Update(); }); new UIElementBorder(ui, Color.yellow); } } } ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(2.5f, offset, 2, 1); ui.SetText(tp.parenthesis); new UIElementBorder(ui); ui = new UIElement(Game.EDITOR, scrollArea.GetScrollTransform()); ui.SetLocation(4.5f, offset, 1, 1); ui.SetText(CommonStringKeys.MINUS, Color.red); ui.SetButton(delegate { component.tests.Remove(tmp_index); Update(); }); new UIElementBorder(ui, Color.red); offset++; } component_index++; } return(offset + 1); }