Ejemplo n.º 1
0
        public virtual void DrawCommandInspectorGUI()
        {
            Command t = target as Command;

            if (t == null)
            {
                return;
            }

            FungusScript fungusScript = t.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(t.GetType());

            if (commandInfoAttr == null)
            {
                return;
            }

            EditorGUILayout.PrefixLabel(new GUIContent("Command"));

            GUILayout.BeginVertical(GUI.skin.box);

            if (t.enabled)
            {
                if (fungusScript.colorCommands)
                {
                    GUI.backgroundColor = t.GetButtonColor();
                }
                else
                {
                    GUI.backgroundColor = Color.white;
                }
            }
            else
            {
                GUI.backgroundColor = Color.grey;
            }
            GUILayout.BeginHorizontal(GUI.skin.button);

            string commandName = commandInfoAttr.CommandName;

            GUILayout.Label(commandName, GUILayout.MinWidth(80), GUILayout.ExpandWidth(true));

            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.white;
            bool enabled = t.enabled;

            enabled = GUILayout.Toggle(enabled, new GUIContent());

            if (t.enabled != enabled)
            {
                Undo.RecordObject(t, "Set Enabled");
                t.enabled = enabled;
            }

            GUILayout.EndHorizontal();
            GUI.backgroundColor = Color.white;

            EditorGUILayout.Separator();

            DrawCommandGUI();

            EditorGUILayout.Separator();

            if (t.errorMessage.Length > 0)
            {
                GUIStyle style = new GUIStyle(GUI.skin.label);
                style.normal.textColor = new Color(1, 0, 0);
                EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style);
            }

            GUILayout.EndVertical();

            // Display help text
            CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(t.GetType());

            if (infoAttr != null)
            {
                EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info, true);
            }
        }
Ejemplo n.º 2
0
        public void DrawItem(Rect position, int index)
        {
            Command command = this[index].objectReferenceValue as Command;

            if (command == null)
            {
                return;
            }

            CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType());

            if (commandInfoAttr == null)
            {
                return;
            }

            FungusScript fungusScript = command.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            bool isComment = (command.GetType() == typeof(Comment));
            bool isLabel   = (command.GetType() == typeof(Label));

            bool   error   = false;
            string summary = command.GetSummary();

            if (summary == null)
            {
                summary = "";
            }
            else
            {
                summary = summary.Replace("\n", "").Replace("\r", "");
            }
            if (summary.StartsWith("Error:"))
            {
                error = true;
            }

            if (isComment || isLabel)
            {
                summary = "<b> " + summary + "</b>";
            }
            else
            {
                summary = "<i>" + summary + "</i>";
            }

            bool commandIsSelected = false;

            foreach (Command selectedCommand in fungusScript.selectedCommands)
            {
                if (selectedCommand == command)
                {
                    commandIsSelected = true;
                    break;
                }
            }

            string commandName = commandInfoAttr.CommandName;

            GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box);

            commandLabelStyle.normal.background = FungusEditorResources.texCommandBackground;
            commandLabelStyle.border.top        = 1;
            commandLabelStyle.border.bottom     = 1;
            commandLabelStyle.border.left       = 1;
            commandLabelStyle.border.right      = 1;
            commandLabelStyle.alignment         = TextAnchor.MiddleLeft;
            commandLabelStyle.richText          = true;
            commandLabelStyle.fontSize          = 11;
            commandLabelStyle.padding.top      -= 1;

            float indentSize = 20;

            for (int i = 0; i < command.indentLevel; ++i)
            {
                Rect indentRect = position;
                indentRect.x       += i * indentSize - 21;
                indentRect.width    = indentSize + 1;
                indentRect.y       -= 2;
                indentRect.height  += 5;
                GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1f);
                GUI.Box(indentRect, "", commandLabelStyle);
            }

            float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f);
            float indentWidth      = command.indentLevel * indentSize;

            Rect commandLabelRect = position;

            commandLabelRect.x      += indentWidth - 21;
            commandLabelRect.y      -= 2;
            commandLabelRect.width  -= (indentSize * command.indentLevel - 22);
            commandLabelRect.height += 5;

            // Select command via left click
            if (Event.current.type == EventType.MouseDown &&
                Event.current.button == 0 &&
                position.Contains(Event.current.mousePosition))
            {
                if (fungusScript.selectedCommands.Contains(command) && Event.current.button == 0)
                {
                    // Left click on an already selected command
                    fungusScript.selectedCommands.Remove(command);
                }
                else
                {
                    // Left click and no command key
                    if (!EditorGUI.actionKey && Event.current.button == 0)
                    {
                        fungusScript.ClearSelectedCommands();
                    }

                    fungusScript.AddSelectedCommand(command);
                }
                GUIUtility.keyboardControl = 0;                 // Fix for textarea not refeshing (change focus)
            }

            Color commandLabelColor = Color.white;

            if (fungusScript.colorCommands)
            {
                commandLabelColor = command.GetButtonColor();
            }

            if (commandIsSelected)
            {
                commandLabelColor = Color.green;
            }
            else if (!command.enabled)
            {
                commandLabelColor = Color.grey;
            }
            else if (error)
            {
                // TODO: Show warning icon
            }

            GUI.backgroundColor = commandLabelColor;

            if (isComment || isLabel)
            {
                GUI.Label(commandLabelRect, "", commandLabelStyle);
            }
            else
            {
                GUI.Label(commandLabelRect, commandName, commandLabelStyle);
            }

            if (command.IsExecuting())
            {
                Rect iconRect = new Rect(commandLabelRect);
                iconRect.x     += iconRect.width - commandLabelRect.width - 20;
                iconRect.width  = 20;
                iconRect.height = 20;
                GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle());
            }

            Rect summaryRect = new Rect(commandLabelRect);

            if (!isComment && !isLabel)
            {
                summaryRect.x     += commandNameWidth;
                summaryRect.width -= commandNameWidth;
                summaryRect.width -= 5;
            }

            GUIStyle summaryStyle = new GUIStyle();

            summaryStyle.fontSize     = 10;
            summaryStyle.padding.top += 5;
            summaryStyle.richText     = true;
            summaryStyle.wordWrap     = false;
            summaryStyle.clipping     = TextClipping.Clip;
            GUI.Label(summaryRect, summary, summaryStyle);

            if (error)
            {
                GUISkin editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
                Rect    errorRect  = new Rect(summaryRect);
                errorRect.x    += errorRect.width - 20;
                errorRect.y    += 2;
                errorRect.width = 20;
                GUI.Label(errorRect, editorSkin.GetStyle("CN EntryError").normal.background);
                summaryRect.width -= 20;
            }

            GUI.backgroundColor = Color.white;
        }
Ejemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            // The variable reference and data properties must follow the naming convention 'typeRef', 'typeVal'

            VariableInfoAttribute typeInfo = VariableEditor.GetVariableInfo(typeof(T));

            if (typeInfo == null)
            {
                return;
            }

            string propNameBase = typeInfo.VariableType;

            propNameBase = Char.ToLowerInvariant(propNameBase[0]) + propNameBase.Substring(1);

            SerializedProperty referenceProp = property.FindPropertyRelative(propNameBase + "Ref");
            SerializedProperty valueProp     = property.FindPropertyRelative(propNameBase + "Val");

            if (referenceProp == null || valueProp == null)
            {
                return;
            }

            const int popupWidth = 65;

            Rect controlRect = EditorGUI.PrefixLabel(position, label);
            Rect valueRect   = controlRect;

            valueRect.width = controlRect.width - popupWidth - 5;
            Rect popupRect = controlRect;

            if (referenceProp.objectReferenceValue == null)
            {
                EditorGUI.PropertyField(valueRect, valueProp, new GUIContent(""));
                popupRect.x    += valueRect.width + 5;
                popupRect.width = popupWidth;
            }

            FungusScript fungusScript = property.serializedObject.targetObject as FungusScript;

            if (fungusScript == null)
            {
                Command command = property.serializedObject.targetObject as Command;
                if (command != null)
                {
                    fungusScript = command.GetFungusScript();
                }
            }

            if (fungusScript != null)
            {
                T selectedVariable = referenceProp.objectReferenceValue as T;

                List <string>   variableKeys    = new List <string>();
                List <Variable> variableObjects = new List <Variable>();

                variableKeys.Add("<Value>");
                variableObjects.Add(null);

                int index         = 0;
                int selectedIndex = 0;
                foreach (Variable v in fungusScript.variables)
                {
                    if (v.GetType() != typeof(T))
                    {
                        continue;
                    }

                    variableKeys.Add(v.key);
                    variableObjects.Add(v);

                    index++;

                    if (v == selectedVariable)
                    {
                        selectedIndex = index;
                    }
                }

                selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray());
                referenceProp.objectReferenceValue = variableObjects[selectedIndex];
            }

            EditorGUI.EndProperty();
        }
Ejemplo n.º 4
0
        public virtual void DrawCommandInspectorGUI()
        {
            Command t = target as Command;

            if (t == null)
            {
                return;
            }

            FungusScript fungusScript = t.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(t.GetType());

            if (commandInfoAttr == null)
            {
                return;
            }

            GUILayout.BeginVertical(GUI.skin.box);

            GUI.backgroundColor = Color.green;
            GUILayout.BeginHorizontal(GUI.skin.button);

            string   commandName  = commandInfoAttr.CommandName;
            GUIStyle commandStyle = new GUIStyle(EditorStyles.miniButton);

            if (t.enabled)
            {
                if (fungusScript.colorCommands)
                {
                    GUI.backgroundColor = t.GetButtonColor();
                }
                else
                {
                    GUI.backgroundColor = Color.white;
                }
            }
            else
            {
                GUI.backgroundColor = Color.grey;
            }

            bool enabled = t.enabled;

            if (GUILayout.Button(commandName, commandStyle, GUILayout.MinWidth(80), GUILayout.ExpandWidth(true)))
            {
                enabled = !enabled;
            }

            GUI.backgroundColor = Color.white;
            enabled             = GUILayout.Toggle(enabled, new GUIContent());

            if (t.enabled != enabled)
            {
                Undo.RecordObject(t, "Set Enabled");
                t.enabled = enabled;
            }

            if (fungusScript != null)
            {
                if (GUILayout.Button("Copy", EditorStyles.miniButton))
                {
                    fungusScript.copyCommand = t;
                }
            }

            GUILayout.EndHorizontal();
            GUI.backgroundColor = Color.white;

            EditorGUILayout.Separator();

            DrawCommandGUI();

            EditorGUILayout.Separator();

            if (t.errorMessage.Length > 0)
            {
                GUIStyle style = new GUIStyle(GUI.skin.label);
                style.normal.textColor = new Color(1, 0, 0);
                EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style);
            }

            GUILayout.EndVertical();
        }
Ejemplo n.º 5
0
        public void DrawItem(Rect position, int index)
        {
            Command command = this[index].objectReferenceValue as Command;

            if (command == null)
            {
                return;
            }

            CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType());

            if (commandInfoAttr == null)
            {
                return;
            }

            FungusScript fungusScript = command.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            bool   error   = false;
            string summary = command.GetSummary().Replace("\n", "").Replace("\r", "");

            if (summary.Length > 80)
            {
                summary = summary.Substring(0, 80) + "...";
            }
            if (summary.StartsWith("Error:"))
            {
                error = true;
            }

            bool selected = (Application.isPlaying && command.IsExecuting()) ||
                            (!Application.isPlaying && fungusScript.selectedCommand == command);

            float indentSize = 20;

            for (int i = 0; i < command.indentLevel; ++i)
            {
                Rect indentRect = position;
                indentRect.x       += i * indentSize;
                indentRect.width    = indentSize + 1;
                indentRect.y       -= 2;
                indentRect.height  += 5;
                GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 0.5f);
                GUI.Box(indentRect, "");
            }

            string commandName = commandInfoAttr.CommandName;

            GUIStyle commandLabelStyle = new GUIStyle(EditorStyles.miniButtonLeft);

            float buttonWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 100f);
            float indentWidth = command.indentLevel * indentSize;

            Rect buttonRect = position;

            buttonRect.x      += indentWidth;
            buttonRect.width   = buttonWidth;
            buttonRect.y      -= 2;
            buttonRect.height += 6;

            Rect summaryRect = buttonRect;

            summaryRect.x    += buttonWidth - 1;
            summaryRect.width = position.width - buttonWidth - indentWidth - 15;

            if (!Application.isPlaying &&
                Event.current.type == EventType.MouseDown &&
                Event.current.button == 0 &&
                position.Contains(Event.current.mousePosition))
            {
                fungusScript.selectedCommand = command;
                GUIUtility.keyboardControl   = 0;               // Fix for textarea not refeshing (change focus)
            }

            Color buttonBackgroundColor = Color.white;

            if (fungusScript.colorCommands)
            {
                buttonBackgroundColor = command.GetButtonColor();
            }
            Color summaryBackgroundColor = Color.white;

            if (selected)
            {
                summaryBackgroundColor = Color.green;
                buttonBackgroundColor  = Color.green;
            }
            else if (!command.enabled)
            {
                buttonBackgroundColor  = Color.grey;
                summaryBackgroundColor = Color.grey;
            }
            else if (error)
            {
                summaryBackgroundColor = Color.red;
            }

            GUI.backgroundColor = buttonBackgroundColor;
            GUI.Label(buttonRect, commandName, commandLabelStyle);

            GUIStyle summaryStyle = new GUIStyle(EditorStyles.miniButtonRight);

            summaryStyle.alignment = TextAnchor.MiddleLeft;
            if (error && !selected)
            {
                summaryStyle.normal.textColor = Color.white;
            }

            GUI.backgroundColor = summaryBackgroundColor;
            GUI.Box(summaryRect, summary, summaryStyle);

            GUI.backgroundColor = Color.white;

            Rect menuRect = summaryRect;

            menuRect.x     += menuRect.width + 2;
            menuRect.y      = position.y + 1;
            menuRect.width  = 18;
            menuRect.height = position.height;

            GUIStyle menuButtonStyle = new GUIStyle(EditorStyles.popup);

            if (GUI.Button(menuRect, new GUIContent("", "Select command type"), menuButtonStyle))
            {
                ShowCommandMenu(index, fungusScript.selectedSequence);
            }
        }
Ejemplo n.º 6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            SerializedProperty referenceProp = property.FindPropertyRelative("booleanReference");
            SerializedProperty valueProp     = property.FindPropertyRelative("booleanValue");

            const int popupWidth = 65;

            Rect controlRect = EditorGUI.PrefixLabel(position, label);
            Rect valueRect   = controlRect;

            valueRect.width = controlRect.width - popupWidth - 5;
            Rect popupRect = controlRect;

            if (referenceProp.objectReferenceValue == null)
            {
                valueProp.boolValue = EditorGUI.Toggle(valueRect, valueProp.boolValue);
                popupRect.x        += valueRect.width + 5;
                popupRect.width     = popupWidth;
            }

            FungusScript fungusScript = property.serializedObject.targetObject as FungusScript;

            if (fungusScript == null)
            {
                Command command = property.serializedObject.targetObject as Command;
                if (command != null)
                {
                    fungusScript = command.GetFungusScript();
                }
            }

            if (fungusScript != null)
            {
                BooleanVariable selectedBooleanVariable = referenceProp.objectReferenceValue as BooleanVariable;

                List <string>   variableKeys    = new List <string>();
                List <Variable> variableObjects = new List <Variable>();

                variableKeys.Add("<Value>");
                variableObjects.Add(null);

                int index         = 0;
                int selectedIndex = 0;
                foreach (Variable v in fungusScript.variables)
                {
                    if (v.GetType() != typeof(BooleanVariable))
                    {
                        continue;
                    }

                    variableKeys.Add(v.key);
                    variableObjects.Add(v);

                    index++;

                    if (v == selectedBooleanVariable)
                    {
                        selectedIndex = index;
                    }
                }

                selectedIndex = EditorGUI.Popup(popupRect, selectedIndex, variableKeys.ToArray());
                referenceProp.objectReferenceValue = variableObjects[selectedIndex];
            }

            EditorGUI.EndProperty();
        }