コード例 #1
0
        private ElementSaveData.ScriptSaveData BindStringDictionary(IValueProvider provider, EditorController controller, string ignoreExpression, IEditableDictionary <string> dictionary, string key, IEditorControl ctl)
        {
            ElementSaveData.ScriptSaveData result = new ElementSaveData.ScriptSaveData();
            if (dictionary != null)
            {
                int dictionaryCount = 0;
                foreach (var item in dictionary.Items)
                {
                    string keyValue;
                    if (string.IsNullOrEmpty(ctl.GetString("source")))
                    {
                        keyValue = GetValueProviderString(provider, string.Format("{0}-key{1}", key, dictionaryCount));
                    }
                    else
                    {
                        // key is not editable when a source is specified
                        keyValue = item.Key;
                    }
                    result.Attributes.Add(string.Format("key{0}", dictionaryCount), keyValue);

                    string valueValue = GetValueProviderString(provider, string.Format("{0}-value{1}", key, dictionaryCount));
                    result.Attributes.Add(string.Format("value{0}", dictionaryCount), valueValue);

                    dictionaryCount++;
                }
            }
            return(result);
        }
コード例 #2
0
        private ElementSaveData.ScriptSaveData BindScriptDictionary(IValueProvider provider, EditorController controller, string ignoreExpression, IEditableDictionary <IEditableScripts> dictionary, string key)
        {
            ElementSaveData.ScriptSaveData result = new ElementSaveData.ScriptSaveData();
            if (dictionary != null)
            {
                int dictionaryCount = 0;
                foreach (var item in dictionary.Items.Values)
                {
                    string expressionValue = GetValueProviderString(provider, string.Format("{0}-key{1}", key, dictionaryCount));
                    result.Attributes.Add(string.Format("key{0}", dictionaryCount), expressionValue);

                    ElementSaveData.ScriptsSaveData scriptResult = new ElementSaveData.ScriptsSaveData();
                    BindScriptLines(provider, string.Format("{0}-value{1}", key, dictionaryCount), controller, item.Value, scriptResult, ignoreExpression);
                    result.Attributes.Add(string.Format("value{0}", dictionaryCount), scriptResult);

                    dictionaryCount++;
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: Element.cs プロジェクト: JatinR/quest
        private ElementSaveData.ScriptSaveData BindStringDictionary(IValueProvider provider, EditorController controller, string ignoreExpression, IEditableDictionary<string> dictionary, string key, IEditorControl ctl)
        {
            ElementSaveData.ScriptSaveData result = new ElementSaveData.ScriptSaveData();
            if (dictionary != null)
            {
                int dictionaryCount = 0;
                foreach (var item in dictionary.Items)
                {
                    string keyValue;
                    if (string.IsNullOrEmpty(ctl.GetString("source")))
                    {
                        keyValue = GetValueProviderString(provider, string.Format("{0}-key{1}", key, dictionaryCount));
                    }
                    else
                    {
                        // key is not editable when a source is specified
                        keyValue = item.Key;
                    }
                    result.Attributes.Add(string.Format("key{0}", dictionaryCount), keyValue);

                    string valueValue = GetValueProviderString(provider, string.Format("{0}-value{1}", key, dictionaryCount));
                    result.Attributes.Add(string.Format("value{0}", dictionaryCount), valueValue);

                    dictionaryCount++;
                }
            }
            return result;
        }
コード例 #4
0
ファイル: Element.cs プロジェクト: JatinR/quest
        private ElementSaveData.ScriptSaveData BindScriptDictionary(IValueProvider provider, EditorController controller, string ignoreExpression, IEditableDictionary<IEditableScripts> dictionary, string key)
        {
            ElementSaveData.ScriptSaveData result = new ElementSaveData.ScriptSaveData();
            if (dictionary != null)
            {
                int dictionaryCount = 0;
                foreach (var item in dictionary.Items.Values)
                {
                    string expressionValue = GetValueProviderString(provider, string.Format("{0}-key{1}", key, dictionaryCount));
                    result.Attributes.Add(string.Format("key{0}", dictionaryCount), expressionValue);

                    ElementSaveData.ScriptsSaveData scriptResult = new ElementSaveData.ScriptsSaveData();
                    BindScriptLines(provider, string.Format("{0}-value{1}", key, dictionaryCount), controller, item.Value, scriptResult, ignoreExpression);
                    result.Attributes.Add(string.Format("value{0}", dictionaryCount), scriptResult);

                    dictionaryCount++;
                }
            }
            return result;
        }
コード例 #5
0
ファイル: Element.cs プロジェクト: JatinR/quest
        private void BindScriptLines(IValueProvider provider, string attribute, EditorController controller, IEditableScripts originalScript, ElementSaveData.ScriptsSaveData result, string ignoreExpression)
        {
            if (originalScript == null) return;
            int count = 0;
            foreach (IEditableScript script in originalScript.Scripts)
            {
                ElementSaveData.ScriptSaveData scriptLine = new ElementSaveData.ScriptSaveData();
                scriptLine.IsSelected = (bool)provider.GetValue(string.Format("selected-{0}-{1}", attribute, count)).ConvertTo(typeof(bool));

                if (script.Type != ScriptType.If)
                {
                    IEditorDefinition definition = controller.GetEditorDefinition(script);
                    foreach (IEditorControl ctl in definition.Controls.Where(c => c.Attribute != null))
                    {
                        string key = string.Format("{0}-{1}-{2}", attribute, count, ctl.Attribute);

                        if (ctl.ControlType == "script")
                        {
                            IEditorData scriptEditorData = controller.GetScriptEditorData(script);
                            IEditableScripts originalSubScript = (IEditableScripts)scriptEditorData.GetAttribute(ctl.Attribute);
                            ElementSaveData.ScriptsSaveData scriptResult = new ElementSaveData.ScriptsSaveData();
                            BindScriptLines(provider, key, controller, originalSubScript, scriptResult, ignoreExpression);
                            scriptLine.Attributes.Add(ctl.Attribute, scriptResult);
                        }
                        else if (ctl.ControlType == "scriptdictionary")
                        {
                            IEditorData dictionaryData = controller.GetScriptEditorData(script);
                            IEditableDictionary<IEditableScripts> dictionary = (IEditableDictionary<IEditableScripts>)dictionaryData.GetAttribute(ctl.Attribute);
                            ElementSaveData.ScriptSaveData switchResult = BindScriptDictionary(provider, controller, ignoreExpression, dictionary, key);
                            scriptLine.Attributes.Add(ctl.Attribute, switchResult);
                        }
                        else if (ctl.ControlType == "list")
                        {
                            // do nothing
                        }
                        else
                        {
                            object value = GetScriptParameterValue(
                                scriptLine,
                                controller,
                                provider,
                                key,
                                ctl.ControlType,
                                ctl.GetString("simpleeditor") ?? "textbox",
                                ctl.GetString("usetemplates"),
                                (string)script.GetParameter(ctl.Attribute),
                                ignoreExpression
                            );
                            scriptLine.Attributes.Add(ctl.Attribute, value);
                        }
                    }
                }
                else
                {
                    EditableIfScript ifScript = (EditableIfScript)script;

                    object expressionValue = GetScriptParameterValue(
                        scriptLine,
                        controller,
                        provider,
                        string.Format("{0}-{1}-expression", attribute, count),
                        "expression",
                        null,
                        "if",
                        (string)ifScript.GetAttribute("expression"),
                        ignoreExpression
                    );

                    scriptLine.Attributes.Add("expression", expressionValue);

                    ElementSaveData.ScriptsSaveData thenScriptResult = new ElementSaveData.ScriptsSaveData();
                    BindScriptLines(provider, string.Format("{0}-{1}-then", attribute, count), controller, ifScript.ThenScript, thenScriptResult, ignoreExpression);
                    scriptLine.Attributes.Add("then", thenScriptResult);

                    int elseIfCount = 0;
                    foreach (EditableIfScript.EditableElseIf elseIf in ifScript.ElseIfScripts)
                    {
                        object elseIfExpressionValue = GetScriptParameterValue(
                            scriptLine,
                            controller,
                            provider,
                            string.Format("{0}-{1}-elseif{2}-expression", attribute, count, elseIfCount),
                            "expression",
                            null,
                            "if",
                            elseIf.Expression,
                            ignoreExpression
                        );

                        scriptLine.Attributes.Add(string.Format("elseif{0}-expression", elseIfCount), elseIfExpressionValue);

                        ElementSaveData.ScriptsSaveData elseIfScriptResult = new ElementSaveData.ScriptsSaveData();
                        BindScriptLines(provider, string.Format("{0}-{1}-elseif{2}", attribute, count, elseIfCount), controller, elseIf.EditableScripts, elseIfScriptResult, ignoreExpression);
                        scriptLine.Attributes.Add(string.Format("elseif{0}-then", elseIfCount), elseIfScriptResult);
                        elseIfCount++;
                    }

                    if (ifScript.ElseScript != null)
                    {
                        ElementSaveData.ScriptsSaveData elseScriptResult = new ElementSaveData.ScriptsSaveData();
                        BindScriptLines(provider, string.Format("{0}-{1}-else", attribute, count), controller, ifScript.ElseScript, elseScriptResult, ignoreExpression);
                        scriptLine.Attributes.Add("else", elseScriptResult);
                    }
                }

                result.ScriptLines.Add(scriptLine);
                count++;
            }
        }
コード例 #6
0
        private string GetAndValidateValueProviderString(IValueProvider provider, string key, string oldValue, ElementSaveData.ScriptSaveData scriptLine, EditorController controller)
        {
            string           result           = GetValueProviderString(provider, key);
            ValidationResult validationResult = controller.ValidateExpression(result);

            if (!validationResult.Valid)
            {
                scriptLine.Error = string.Format("Could not set value '{0}' - {1}",
                                                 result,
                                                 Services.EditorService.GetValidationError(validationResult, result));
                result = oldValue;
            }
            return(result);
        }
コード例 #7
0
        private object GetScriptParameterValue(ElementSaveData.ScriptSaveData scriptLine, EditorController controller, IValueProvider provider, string attributePrefix, string controlType, string simpleEditor, string templatesFilter, string oldValue, string ignoreExpression)
        {
            if (attributePrefix == ignoreExpression)
            {
                return(new IgnoredValue());
            }

            if (controlType == "expression")
            {
                if (templatesFilter == null)
                {
                    string dropdownKey = string.Format("{0}-expressioneditordropdown", attributePrefix);
                    ValueProviderResult dropdownKeyValueResult = provider.GetValue(dropdownKey);
                    string dropdownKeyValue = (dropdownKeyValueResult != null) ? dropdownKeyValueResult.ConvertTo(typeof(string)) as string : null;
                    if (dropdownKeyValue == "expression" || dropdownKeyValue == null)
                    {
                        string key = string.Format("{0}-expressioneditor", attributePrefix);
                        return(GetAndValidateValueProviderString(provider, key, oldValue, scriptLine, controller));
                    }
                    else
                    {
                        if (simpleEditor == "boolean")
                        {
                            return(dropdownKeyValue == "yes" ? "true" : "false");
                        }
                        else
                        {
                            string key         = string.Format("{0}-simpleeditor", attributePrefix);
                            string simpleValue = GetValueProviderString(provider, key);
                            if (simpleValue == null)
                            {
                                return(string.Empty);
                            }

                            switch (simpleEditor)
                            {
                            case "objects":
                            case "number":
                            case "numberdouble":
                                return(simpleValue);

                            default:
                                return(EditorUtility.ConvertFromSimpleStringExpression(simpleValue));
                            }
                        }
                    }
                }
                else
                {
                    string dropdownKey      = string.Format("{0}-templatedropdown", attributePrefix);
                    string dropdownKeyValue = provider.GetValue(dropdownKey).ConvertTo(typeof(string)) as string;
                    if (dropdownKeyValue == "expression")
                    {
                        string key = attributePrefix;
                        return(GetAndValidateValueProviderString(provider, key, oldValue, scriptLine, controller));
                    }
                    else
                    {
                        IEditorDefinition editorDefinition = controller.GetExpressionEditorDefinition(oldValue, templatesFilter);
                        IEditorData       data             = controller.GetExpressionEditorData(oldValue, templatesFilter, null);

                        foreach (IEditorControl ctl in editorDefinition.Controls.Where(c => c.Attribute != null))
                        {
                            string key   = attributePrefix + "-" + ctl.Attribute;
                            object value = GetScriptParameterValue(scriptLine, controller, provider, key, ctl.ControlType, ctl.GetString("simpleeditor") ?? "textbox", null, null, ignoreExpression);
                            data.SetAttribute(ctl.Attribute, value);
                        }

                        return(controller.GetExpression(data, null, null));
                    }
                }
            }
            else
            {
                string key = attributePrefix;
                return(GetValueProviderString(provider, key));
            }
        }
コード例 #8
0
        private void BindScriptLines(IValueProvider provider, string attribute, EditorController controller, IEditableScripts originalScript, ElementSaveData.ScriptsSaveData result, string ignoreExpression)
        {
            if (originalScript == null)
            {
                return;
            }
            int count = 0;

            foreach (IEditableScript script in originalScript.Scripts)
            {
                ElementSaveData.ScriptSaveData scriptLine = new ElementSaveData.ScriptSaveData();
                scriptLine.IsSelected = (bool)provider.GetValue(string.Format("selected-{0}-{1}", attribute, count)).ConvertTo(typeof(bool));

                if (script.Type != ScriptType.If)
                {
                    IEditorDefinition definition = controller.GetEditorDefinition(script);
                    foreach (IEditorControl ctl in definition.Controls.Where(c => c.Attribute != null))
                    {
                        string key = string.Format("{0}-{1}-{2}", attribute, count, ctl.Attribute);

                        if (ctl.ControlType == "script")
                        {
                            IEditorData      scriptEditorData            = controller.GetScriptEditorData(script);
                            IEditableScripts originalSubScript           = (IEditableScripts)scriptEditorData.GetAttribute(ctl.Attribute);
                            ElementSaveData.ScriptsSaveData scriptResult = new ElementSaveData.ScriptsSaveData();
                            BindScriptLines(provider, key, controller, originalSubScript, scriptResult, ignoreExpression);
                            scriptLine.Attributes.Add(ctl.Attribute, scriptResult);
                        }
                        else if (ctl.ControlType == "scriptdictionary")
                        {
                            IEditorData dictionaryData = controller.GetScriptEditorData(script);
                            IEditableDictionary <IEditableScripts> dictionary   = (IEditableDictionary <IEditableScripts>)dictionaryData.GetAttribute(ctl.Attribute);
                            ElementSaveData.ScriptSaveData         switchResult = BindScriptDictionary(provider, controller, ignoreExpression, dictionary, key);
                            scriptLine.Attributes.Add(ctl.Attribute, switchResult);
                        }
                        else if (ctl.ControlType == "list")
                        {
                            // do nothing
                        }
                        else
                        {
                            object value = GetScriptParameterValue(
                                scriptLine,
                                controller,
                                provider,
                                key,
                                ctl.ControlType,
                                ctl.GetString("simpleeditor") ?? "textbox",
                                ctl.GetString("usetemplates"),
                                (string)script.GetParameter(ctl.Attribute),
                                ignoreExpression
                                );
                            scriptLine.Attributes.Add(ctl.Attribute, value);
                        }
                    }
                }
                else
                {
                    EditableIfScript ifScript = (EditableIfScript)script;

                    object expressionValue = GetScriptParameterValue(
                        scriptLine,
                        controller,
                        provider,
                        string.Format("{0}-{1}-expression", attribute, count),
                        "expression",
                        null,
                        "if",
                        (string)ifScript.GetAttribute("expression"),
                        ignoreExpression
                        );

                    scriptLine.Attributes.Add("expression", expressionValue);

                    ElementSaveData.ScriptsSaveData thenScriptResult = new ElementSaveData.ScriptsSaveData();
                    BindScriptLines(provider, string.Format("{0}-{1}-then", attribute, count), controller, ifScript.ThenScript, thenScriptResult, ignoreExpression);
                    scriptLine.Attributes.Add("then", thenScriptResult);

                    int elseIfCount = 0;
                    foreach (EditableIfScript.EditableElseIf elseIf in ifScript.ElseIfScripts)
                    {
                        object elseIfExpressionValue = GetScriptParameterValue(
                            scriptLine,
                            controller,
                            provider,
                            string.Format("{0}-{1}-elseif{2}-expression", attribute, count, elseIfCount),
                            "expression",
                            null,
                            "if",
                            elseIf.Expression,
                            ignoreExpression
                            );

                        scriptLine.Attributes.Add(string.Format("elseif{0}-expression", elseIfCount), elseIfExpressionValue);

                        ElementSaveData.ScriptsSaveData elseIfScriptResult = new ElementSaveData.ScriptsSaveData();
                        BindScriptLines(provider, string.Format("{0}-{1}-elseif{2}", attribute, count, elseIfCount), controller, elseIf.EditableScripts, elseIfScriptResult, ignoreExpression);
                        scriptLine.Attributes.Add(string.Format("elseif{0}-then", elseIfCount), elseIfScriptResult);
                        elseIfCount++;
                    }

                    if (ifScript.ElseScript != null)
                    {
                        ElementSaveData.ScriptsSaveData elseScriptResult = new ElementSaveData.ScriptsSaveData();
                        BindScriptLines(provider, string.Format("{0}-{1}-else", attribute, count), controller, ifScript.ElseScript, elseScriptResult, ignoreExpression);
                        scriptLine.Attributes.Add("else", elseScriptResult);
                    }
                }

                result.ScriptLines.Add(scriptLine);
                count++;
            }
        }