예제 #1
0
        public EventButton(QuestButtonData buttonData)
        {
            label = buttonData.Label;
            string colorRGB = ColorUtil.FromName(buttonData.Color);

            // Check format is valid
            if ((colorRGB.Length != 7 && colorRGB.Length != 9) || (colorRGB[0] != '#'))
            {
                Game.Get().quest.log.Add(new Quest.LogEntry("Warning: Button color must be in #RRGGBB format or a known name", true));
            }

            // Hexadecimal to float convert (0x00-0xFF -> 0.0-1.0)
            colour.r = (byte)System.Convert.ToByte(colorRGB.Substring(1, 2), 16);
            colour.g = (byte)System.Convert.ToByte(colorRGB.Substring(3, 2), 16);
            colour.b = (byte)System.Convert.ToByte(colorRGB.Substring(5, 2), 16);

            if (colorRGB.Length == 9)
            {
                colour.a = (byte)System.Convert.ToByte(colorRGB.Substring(7, 2), 16);
            }
            else
            {
                colour.a = 255; // opaque by default
            }
            this.condition = buttonData.Condition;
            this.action    = buttonData.ConditionFailedAction;
        }
예제 #2
0
 private static void RemoveOp(VarTests tests, int index, Action updateAction)
 {
     if (index < tests.VarTestsComponents.Count)
     {
         tests.Remove(index);
     }
     updateAction.Invoke();
 }
예제 #3
0
 public QuestButtonData(StringKey label, List <string> eventNames  = null, VarTests condition = null,
                        QuestButtonAction?rawConditionFailedAction = null)
 {
     Label      = label;
     EventNames = eventNames ?? new List <string>();
     RawConditionFailedAction = rawConditionFailedAction;
     Condition = condition ?? new VarTests();
 }
예제 #4
0
    public static void SelectAddOp(string var, ITestable testable, Action updateAction, bool test = true)
    {
        if (var == null)
        {
            updateAction.Invoke();
            return;
        }

        VarTests            tests      = testable.Tests;
        List <VarOperation> operations = testable.Operations;
        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
            var textEdit = new QuestEditorTextEdit(CommonStringKeys.VAR_NAME, "", s => NewVar(s, op, test, testable, updateAction));
            textEdit.EditText();
        }
        else
        {
            if (test)
            {
                if (tests.VarTestsComponents.Count == 0)
                {
                    tests.Add(op);
                }
                else
                {
                    tests.Add(new VarTestsLogicalOperator());
                    tests.Add(op);
                }
            }
            else
            {
                operations.Add(op);
            }

            updateAction.Invoke();
        }
    }
예제 #5
0
        public static QuestButtonData FromData(Dictionary <string, string> data, int position, string sectionName)
        {
            var             buttonLabel     = ReadButtonLabel(data, position, sectionName);
            QuestButtonData questButtonData = null;

            if (data.TryGetValue("event" + position, out var nextEventString))
            {
                questButtonData = FromSingleString(buttonLabel, nextEventString);
            }
            else
            {
                questButtonData = new QuestButtonData(buttonLabel, new List <string>());
            }

            if (data.TryGetValue($"event{position}Condition", out var conditionString) && !string.IsNullOrWhiteSpace(conditionString))
            {
                var      tests = new VarTests();
                string[] array = conditionString.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in array)
                {
                    tests.Add(s);
                }

                questButtonData.Condition = tests;

                if (data.TryGetValue($"event{position}ConditionAction", out var conditionActionString) &&
                    !string.IsNullOrWhiteSpace(conditionActionString) &&
                    Enum.TryParse(conditionActionString, true, out QuestButtonAction action))
                {
                    questButtonData.RawConditionFailedAction = action;
                }
            }

            if (data.ContainsKey("buttoncolor" + position))
            {
                questButtonData.Color = data["buttoncolor" + position];
            }

            return(questButtonData);
        }
예제 #6
0
        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));
        }
예제 #7
0
    public bool Test(VarTests tests)
    {
        if (tests == null || tests.VarTestsComponents == null || tests.VarTestsComponents.Count == 0)
        {
            return(true);
        }

        bool   result                    = true;
        string current_operator          = "AND";
        int    index                     = 0;
        int    ignore_inside_parenthesis = 0;

        foreach (VarTestsComponent tc in tests.VarTestsComponents)
        {
            // ignore tests while we are running inside a parenthesis
            if (ignore_inside_parenthesis > 0)
            {
                if (tc is VarTestsParenthesis)
                {
                    VarTestsParenthesis tp = (VarTestsParenthesis)tc;
                    if (tp.parenthesis == "(")
                    {
                        ignore_inside_parenthesis++;
                    }
                    else if (tp.parenthesis == ")")
                    {
                        ignore_inside_parenthesis--;
                    }
                }

                index++;
                continue;
            }

            if (tc is VarOperation)
            {
                if (current_operator == "AND")
                {
                    result = (result && Test((VarOperation)tc));
                }
                else if (current_operator == "OR")
                {
                    result = (result || Test((VarOperation)tc));
                }
            }
            else if (tc is VarTestsLogicalOperator)
            {
                current_operator = ((VarTestsLogicalOperator)tc).op;
            }
            else if (tc is VarTestsParenthesis)
            {
                VarTestsParenthesis tp = (VarTestsParenthesis)tc;
                if (tp.parenthesis == "(")
                {
                    List <VarTestsComponent> remaining_tests = tests.VarTestsComponents.GetRange(index + 1, tests.VarTestsComponents.Count - (index + 1));
                    if (current_operator == "AND")
                    {
                        result = (result && Test(new VarTests(remaining_tests)));
                    }
                    else if (current_operator == "OR")
                    {
                        result = (result || Test(new VarTests(remaining_tests)));
                    }

                    ignore_inside_parenthesis = 1;
                }
                else if (tp.parenthesis == ")")
                {
                    return(result);
                }
            }

            index++;
        }

        if (ignore_inside_parenthesis > 0)
        {
            // we should not get here
            ValkyrieTools.ValkyrieDebug.Log("Invalid Test :" + tests.ToString() + "\n returns " + result);
        }

        return(result);
    }