Esempio n. 1
0
        void m_scripts_Updated(object sender, EditableScriptsUpdatedEventArgs e)
        {
            m_helper.RaiseDirtyEvent(m_scripts.DisplayString());

            if (e.UpdatedScriptEventArgs != null)
            {
                // For nested script updates (e.g. an "if"'s "then" script), there's no need to repopulate the parent script control,
                // as the child script control will have already updated itself to reflect the change.
                if (e.UpdatedScriptEventArgs.IsNestedScriptUpdate)
                {
                    return;
                }

                if (e.UpdatedScriptEventArgs.IsParameterUpdate)
                {
                    // might be an update for a nested script, so check it's "ours" first, and if so, update the control
                    if (m_scriptParameterControlMap.ContainsKey(e.UpdatedScript))
                    {
                        // An entire script refresh would be overkill - we just need to update the specified parameter
                        IElementEditorControl control = GetScriptParameterControl(e.UpdatedScript, e.UpdatedScriptEventArgs.Index.ToString(CultureInfo.InvariantCulture));
                        if (e.UpdatedScript.Type == ScriptType.Normal)
                        {
                            control.Populate(m_controller.GetScriptEditorData(e.UpdatedScript));
                        }
                        else
                        {
                            ((IfEditor)control).Populate((EditableIfScript)e.UpdatedScript);
                        }
                    }
                    return;
                }

                if (e.UpdatedScriptEventArgs.IsNamedParameterUpdate)
                {
                    // might be an update for a nested script, so check it's "ours" first, and if so, update the control
                    if (m_scriptParameterControlMap.ContainsKey(e.UpdatedScript))
                    {
                        // currently, named parameter updates are only used for "else if" expressions. The entire "if" is
                        // registered for attribute "0".
                        IElementEditorControl control = GetScriptParameterControl(e.UpdatedScript, "0");
                        ((IfEditor)control).Populate((EditableIfScript)e.UpdatedScript);
                    }
                    return;
                }

                if (e.UpdatedScript.Type == ScriptType.If)
                {
                    // "If" scripts have their own events which the editor controls handle themselves to update
                    // appropriately, so there is nothing further to do in response to the Updated event.
                    return;
                }
            }

            RefreshScriptsList();
        }
Esempio n. 2
0
        private string GetDisplayString(object value)
        {
            IEditableScripts                       scriptValue           = value as IEditableScripts;
            IEditableList <string>                 listStringValue       = value as IEditableList <string>;
            IEditableDictionary <string>           dictionaryStringValue = value as IEditableDictionary <string>;
            IEditableDictionary <IEditableScripts> dictionaryScriptValue = value as IEditableDictionary <IEditableScripts>;
            IDataWrapper wrappedValue = value as IDataWrapper;
            string       result       = null;

            if (scriptValue != null)
            {
                result = scriptValue.DisplayString();
            }
            else if (listStringValue != null)
            {
                result = GetListDisplayString(listStringValue.DisplayItems);
            }
            else if (dictionaryStringValue != null)
            {
                result = GetDictionaryDisplayString(dictionaryStringValue.DisplayItems);
            }
            else if (dictionaryScriptValue != null)
            {
                result = GetDictionaryDisplayString(dictionaryScriptValue.DisplayItems);
            }
            else if (wrappedValue != null)
            {
                result = wrappedValue.DisplayString();
            }
            else if (value == null)
            {
                result = "(null)";
            }
            else
            {
                result = value.ToString();
            }

            return(EditorUtility.FormatAsOneLine(result));
        }
Esempio n. 3
0
        public IEditableDictionary<IEditableScripts> CreateNewEditableScriptDictionary(string parent, string attribute, string key, IEditableScripts script, bool useTransaction)
        {
            if (useTransaction)
            {
                WorldModel.UndoLogger.StartTransaction(string.Format("Set '{0}' {1} to '{2}'", parent, attribute, script.DisplayString()));
            }

            Element element = (parent == null) ? null : m_worldModel.Elements.Get(parent);

            QuestDictionary<IScript> newDictionary = new QuestDictionary<IScript>();

            if (key != null)
            {
                newDictionary.Add(key, (IScript)script.GetUnderlyingValue());
            }

            if (element != null)
            {
                element.Fields.Set(attribute, newDictionary);

                // setting an element field will clone the value, so we want to return the new dictionary
                newDictionary = element.Fields.GetAsType<QuestDictionary<IScript>>(attribute);
            }

            IEditableDictionary<IEditableScripts> newValue = (IEditableDictionary<IEditableScripts>)WrapValue(newDictionary);

            if (useTransaction)
            {
                WorldModel.UndoLogger.EndTransaction();
            }

            return newValue;
        }