Example #1
0
        public override Form CreateForm(object value)
        {
            string scriptName = (string)value;

            script       = null;
            wasGenerated = false;

            // Open the script this property is referencing.
            if (scriptName.Length > 0)
            {
                script = EditorControl.World.GetScript(scriptName);
            }

            // If it is null, create a new hidden script.
            if (script == null)
            {
                script       = EditorControl.GenerateInternalScript();
                wasGenerated = true;

                if (PropertyGrid.PropertyObject is IEventObject)
                {
                    ObjectEvent e = ((IEventObject)PropertyGrid.PropertyObject).Events.GetEvent(property.Name);
                    if (e != null)
                    {
                        script.Parameters = e.Parameters;
                    }
                }
            }

            // Open the scrpit editor form.
            ScriptEditor form = new ScriptEditor(script, EditorControl);

            return(form);
        }
Example #2
0
        public void ApplyChanges()
        {
            EditorControl.NeedsRecompiling = true;

            for (int i = 0; i < objectEvents.Count; i++)
            {
                InternalObjectEvent objEvent = objectEvents[i];

                // Check if we need to generate the custom script.
                if (objEvent.RadioButtonIndex == RedioButtonIndex.CustomCode && !objEvent.CustomScriptExists)
                {
                    EditorControl.GenerateInternalScript(objEvent.CustomScript);
                    Console.WriteLine("Generated internal script with name '" + objEvent.CustomScript.Name + "'");
                }

                // Check if we need to remove the hidden custom script.
                if (objEvent.RadioButtonIndex != RedioButtonIndex.CustomCode && objEvent.CustomScript != null && objEvent.CustomScriptExists)
                {
                    EditorControl.World.RemoveScript(objEvent.CustomScript);
                    Console.WriteLine("Removed internal script with name '" + objEvent.CustomScript.Name + "'");
                }

                // Determine the value for the script property.
                string propValue = "";
                if (objEvent.RadioButtonIndex == RedioButtonIndex.CustomCode)
                {
                    propValue = objEvent.CustomScript.Name;
                }
                else if (objEvent.RadioButtonIndex == RedioButtonIndex.Script)
                {
                    propValue = objEvent.ReferencedScript.Name;
                }

                // Set the property.
                Console.WriteLine("Setting property '" + objEvent.Id + "' to the value '" + propValue + "'");
                objectEditor.PropertyObject.Properties.Set(objEvent.Id, propValue);
            }
        }