예제 #1
0
        public ScriptCommandEditorData(EditorController controller, IEditableScript script)
        {
            m_controller = controller;
            m_script = script;

            m_script.Updated += m_script_Updated;
        }
예제 #2
0
        public static IEnumerable<SelectListItem> GetDropdownValues(IEditorControl ctl, string currentValue, EditorController controller)
        {
            IEnumerable<string> valuesList = ctl.GetListString("validvalues");
            IDictionary<string, string> valuesDictionary = ctl.GetDictionary("validvalues");
            string source = ctl.GetString("source");

            // TO DO: Need a way of allowing free text entry

            if (source == "basefonts")
            {
                valuesList = controller.AvailableBaseFonts();
            }
            else if (source == "webfonts")
            {
                valuesList = controller.AvailableWebFonts();
            }

            if (valuesList != null)
            {
                if (string.IsNullOrEmpty(currentValue))
                {
                    valuesList = new List<string> { "" }.Union(valuesList);
                }

                return valuesList.Select(v => new SelectListItem { Text = v, Value = v, Selected = (v == currentValue) });
            }
            else if (valuesDictionary != null)
            {
                return valuesDictionary.Select(kvp => new SelectListItem { Text = kvp.Value, Value = kvp.Key, Selected = (kvp.Key == currentValue) });
            }
            else
            {
                throw new Exception("Unknown source list for dropdown");
            }
        }
예제 #3
0
 public EditableObjectReference(EditorController controller, Element obj, Element parent, string attribute)
 {
     m_object = obj;
     m_controller = controller;
     m_parent = parent;
     m_attribute = attribute;
 }
예제 #4
0
 public EditableCommandPattern(EditorController controller, EditorCommandPattern pattern, Element parent, string attribute)
 {
     m_pattern = pattern;
     m_controller = controller;
     m_parent = parent;
     m_attribute = attribute;
 }
예제 #5
0
파일: EditorData.cs 프로젝트: JatinR/quest
        public EditorData(Element element, EditorController controller)
        {
            m_element = element;
            m_controller = controller;

            element.Fields.AttributeChanged += Fields_AttributeChanged;
            element.Fields.AttributeChangedSilent += Fields_AttributeChanged;
        }
예제 #6
0
        public EditableScriptBase(EditorController controller, IScript script, UndoLogger undoLogger)
        {
            Script = script;
            m_controller = controller;
            if (script != null)
            {
                ((IMutableField)script).UndoLog = undoLogger;
            }

            s_count++;
            m_id = "script" + s_count;
        }
예제 #7
0
        internal EditableScriptFactory(EditorController controller, ScriptFactory factory, WorldModel worldModel)
        {
            m_controller = controller;
            m_scriptFactory = factory;
            m_worldModel = worldModel;

            foreach (Element editor in worldModel.Elements.GetElements(ElementType.Editor).Where(IsScriptEditor))
            {
                string appliesTo = editor.Fields.GetString("appliesto");
                m_scriptData.Add(appliesTo, new EditableScriptData(editor, worldModel));
            }
        }
예제 #8
0
        public static void EditScript(EditorController controller, ref IEditableScripts scripts, string attribute, string element, bool isReadOnly, Action dirtyAction)
        {
            ScriptEditorPopOut popOut = new ScriptEditorPopOut();

            popOut.ctlScriptEditor.HidePopOutButton();
            popOut.ctlScriptEditor.Helper.DoInitialise(controller, null);
            popOut.ctlScriptEditor.Populate(scripts);
            System.EventHandler<DataModifiedEventArgs> dirtyEventHandler = (object sender, DataModifiedEventArgs e) => dirtyAction.Invoke();
            popOut.ctlScriptEditor.Helper.Dirty += dirtyEventHandler;

            popOut.ShowDialog();
            scripts = popOut.ctlScriptEditor.Scripts;
            popOut.ctlScriptEditor.Save();
            popOut.ctlScriptEditor.Populate((IEditableScripts)null);
            popOut.ctlScriptEditor.Helper.DoUninitialise();
            popOut.ctlScriptEditor.Helper.Dirty -= dirtyEventHandler;
        }
예제 #9
0
        public static string AddScript(EditorController controller)
        {
            if (controller != s_popOutScriptAdderController)
            {
                if (s_popOutScriptAdder != null)
                {
                    s_popOutScriptAdder.ctlScriptAdder.Uninitialise();
                }

                s_popOutScriptAdder = new ScriptAdderPopOut();
                s_popOutScriptAdder.ctlScriptAdder.Initialise(controller);

                s_popOutScriptAdderController = controller;
            }

            s_popOutScriptAdder.ctlScriptAdder.PopulateTree();

            s_popOutScriptAdder.SelectedScript = null;
            s_popOutScriptAdder.ShowDialog();
            return s_popOutScriptAdder.SelectedScript;
        }
예제 #10
0
 public void Init()
 {
     m_controller = new EditorController();
     m_controller.ClearTree += m_controller_ClearTree;
     m_controller.BeginTreeUpdate += m_controller_BeginTreeUpdate;
     m_controller.EndTreeUpdate += m_controller_EndTreeUpdate;
     m_controller.AddedNode += m_controller_AddedNode;
     m_controller.UndoListUpdated += m_controller_UndoListUpdated;
     m_controller.RedoListUpdated += m_controller_RedoListUpdated;
     string tempFile = System.IO.Path.GetTempFileName();
     ExtractResource("EditorControllerTests.test.aslx", tempFile);
     m_controller.Initialise(tempFile);
     DoExtraInitialisation();
     try
     {
         System.IO.File.Delete(tempFile);
     }
     catch (System.IO.IOException)
     {
         // ignore
     }
 }
예제 #11
0
        public void TestTemplates()
        {
            string folder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6).Replace("/", @"\");
            string templateFolder = System.IO.Path.Combine(folder, @"..\..\..\..\WorldModel\WorldModel\Core");
            Dictionary<string, TemplateData> templates = EditorController.GetAvailableTemplates(templateFolder);
            List<string> tempFiles = new List<string>();

            foreach (TemplateData template in templates.Values)
            {
                string tempFile = System.IO.Path.GetTempFileName();

                EditorController.CreateNewGameFile(tempFile, template.Filename, "Test");
                EditorController controller = new EditorController();
                string errorsRaised = string.Empty;
                
                controller.ShowMessage += (object sender, TextAdventures.Quest.EditorController.ShowMessageEventArgs e) =>
                {
                    errorsRaised += e.Message;
                };

                bool result = controller.Initialise(tempFile, templateFolder);

                Assert.IsTrue(result, string.Format("Initialisation failed for template '{0}': {1}", System.IO.Path.GetFileName(template.Filename), errorsRaised));
                Assert.AreEqual(0, errorsRaised.Length, string.Format("Error loading game with template '{0}': {1}", System.IO.Path.GetFileName(template.Filename), errorsRaised));

                tempFiles.Add(tempFile);
            }

            try
            {
                foreach (string tempFile in tempFiles)
                {
                    System.IO.File.Delete(tempFile);
                }
            }
            catch { }
        }
예제 #12
0
        public static IEnumerable<SelectListItem> GetDropDownTypesControlItems(IEditorControl ctl, EditorController controller, string element)
        {
            IDictionary<string, string> types = ctl.GetDictionary("types");

            // TO DO: If more than one type is inherited by the object, disable the control
            string selectedItem = controller.GetSelectedDropDownType(ctl, element);

            return types.Select(t => new SelectListItem { Value = t.Key, Text = t.Value, Selected = (selectedItem == t.Key) });
        }
예제 #13
0
파일: Element.cs 프로젝트: JatinR/quest
        private object BindScript(IValueProvider provider, string attribute, IEditorData data, EditorController controller, string ignoreExpression)
        {
            IEditableScripts originalScript = (IEditableScripts)data.GetAttribute(attribute);

            if (originalScript == null) return null;

            ElementSaveData.ScriptsSaveData result = new ElementSaveData.ScriptsSaveData();

            BindScriptLines(provider, attribute, controller, originalScript, result, ignoreExpression);

            return result;
        }
예제 #14
0
        public static void PopulateRichTextControlModel(IEditorControl ctl, EditorController controller, RichTextControl model)
        {
            if (ctl.GetBool("notextprocessor")) return;

            var commandDataList = controller.GetElementDataAttribute("_RichTextControl_TextProcessorCommands", "data") as IEnumerable;

            model.TextProcessorCommands = (from IDictionary<string, string> commandData in commandDataList
                                           select new RichTextControl.TextProcessorCommand
                                           {
                                               Command = GetDictionaryValue(commandData, "command"),
                                               Info = GetDictionaryValue(commandData, "info"),
                                               InsertBefore = GetDictionaryValue(commandData, "insertbefore"),
                                               InsertAfter = GetDictionaryValue(commandData, "insertafter"),
                                               Source = GetDictionaryValue(commandData, "source"),
                                               Extensions = GetExtensions(commandData)
                                           });

        }
예제 #15
0
 void m_controller_AddedNode(object sender, EditorController.AddedNodeEventArgs e)
 {
     m_tree.Add(e.Key, e.Text, e.Parent);
 }
예제 #16
0
        internal EditableIfScript(EditorController controller, IIfScript script, UndoLogger undoLogger)
            : base(controller, script, undoLogger)
        {
            m_ifScript = script;

            m_ifScript.IfScriptUpdated += m_ifScript_IfScriptUpdated;

            if (m_ifScript.ThenScript == null)
            {
                m_ifScript.ThenScript = new MultiScript(Controller.WorldModel);
            }

            m_thenScript = EditableScripts.GetInstance(Controller, m_ifScript.ThenScript);
            m_thenScript.Updated += nestedScript_Updated;

            foreach (var elseIfScript in m_ifScript.ElseIfScripts)
            {
                EditableElseIf newEditableElseIf = new EditableElseIf(elseIfScript, this);
                m_elseIfScripts.Add(elseIfScript.Script, newEditableElseIf);
                newEditableElseIf.EditableScripts.Updated += nestedScript_Updated;
            }

            if (m_ifScript.ElseScript != null)
            {
                m_elseScript = EditableScripts.GetInstance(Controller, m_ifScript.ElseScript);
                m_elseScript.Updated += nestedScript_Updated;
            }
        }
예제 #17
0
 public static IEnumerable<string> GetObjectListNames(IEditorControl ctl, EditorController controller)
 {
     string source = ctl.GetString("source");
     if (source != null)
     {
         return controller.GetElementNames(source);
     }
     else
     {
         string objectType = ctl.GetString("objecttype");
         IEnumerable<string> objectNames = controller.GetObjectNames(objectType ?? "object");
         return new List<string> { "" }.Union(objectNames);
     }
 }
예제 #18
0
 private EditableScripts(EditorController controller, IScript script)
     : this(controller)
 {
     InitialiseScript(script);
 }
예제 #19
0
 void m_controller_UndoListUpdated(object sender, EditorController.UpdateUndoListEventArgs e)
 {
     m_undoList = new List<string>(e.UndoList);
 }
예제 #20
0
파일: Element.cs 프로젝트: JatinR/quest
 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;
 }
예제 #21
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;
        }
예제 #22
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++;
            }
        }
예제 #23
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;
        }
예제 #24
0
 public static EditableScripts GetInstance(EditorController controller, IScript script)
 {
     return s_wrapper.GetInstance(controller, script);
 }
예제 #25
0
파일: Element.cs 프로젝트: JatinR/quest
        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);
            }
        }
예제 #26
0
 private static EditableScripts GetNewInstance(EditorController controller, IScript script)
 {
     return new EditableScripts(controller, script);
 }
예제 #27
0
 internal EditableScript(EditorController controller, IScript script, UndoLogger undoLogger)
     : base(controller, script, undoLogger)
 {
     m_editorName = Script.Keyword;
 }
예제 #28
0
 private EditableScripts(EditorController controller)
 {
     m_controller = controller;
     m_scripts = new List<IEditableScript>();
 }