// DRAWING
    public void drawEditorGui(Rect container)
    {
        DialogueEditorVariablesContainer variables = getVariables();

        if (variables.variables.Count < 1)
        {
            VariableEditorGUI.drawNoVariablesWarning(container, __scope, __type);
        }
        else
        {
            VariableEditorGUI.drawEditorBase(container, variables, __scope, __type);
            switch (__type)
            {
            case VariableEditorTypes.Boolean:
                VariableEditorGUI.drawBooleanEditor(container, variables);
                break;

            case VariableEditorTypes.Float:
                VariableEditorGUI.drawFloatEditor(container, variables);
                break;

            case VariableEditorTypes.String:
                VariableEditorGUI.drawStringEditor(container, variables);
                break;
            }
        }
    }
Beispiel #2
0
    private DialogueEditorVariablesContainer getVariables()
    {
        DialogueEditorVariablesContainer variables;

        if (__scope == VariableEditorScopes.Global)
        {
            if (__type == VariableEditorTypes.Float)
            {
                variables = DialogueEditorDataManager.data.globals.floats;
            }
            else if (__type == VariableEditorTypes.String)
            {
                variables = DialogueEditorDataManager.data.globals.strings;
            }
            else
            {
                variables = DialogueEditorDataManager.data.globals.booleans;
            }
        }
        else
        {
            if (DialogueEditorDataManager.data.dialogues.Count < 1)
            {
                return(variables = new DialogueEditorVariablesContainer());
            }
            if (__type == VariableEditorTypes.Float)
            {
                variables = DialogueEditorDataManager.data.dialogues[DialogueEditorDataManager.data.currentDialogueId].floats;
            }
            else if (__type == VariableEditorTypes.String)
            {
                variables = DialogueEditorDataManager.data.dialogues[DialogueEditorDataManager.data.currentDialogueId].strings;
            }
            else
            {
                variables = DialogueEditorDataManager.data.dialogues[DialogueEditorDataManager.data.currentDialogueId].booleans;
            }
        }

        return(variables);
    }
    void OnGUI()
    {
        bool isPro = EditorGUIUtility.isProSkin;

        DialogueEditorGUI.drawBackground();

        DialogueEditorVariablesContainer variables = getVariables();

        Rect titleRect = new Rect(5, 5, Screen.width - 10, 22);

        if (isPro)
        {
            DialogueEditorGUI.drawShadowedRect(titleRect, 2);
        }
        else
        {
            GUI.Box(titleRect, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
            GUI.Box(titleRect, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
            GUI.Box(titleRect, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
        }

        int globalFloatsCount   = DialogueEditorDataManager.data.globals.floats.variables.Count;
        int globalBooleansCount = DialogueEditorDataManager.data.globals.booleans.variables.Count;
        int globalStringsCount  = DialogueEditorDataManager.data.globals.strings.variables.Count;

        int localFloatsCount   = DialogueEditorDataManager.data.dialogues[DialogueEditorDataManager.data.currentDialogueId].floats.variables.Count;
        int localBooleansCount = DialogueEditorDataManager.data.dialogues[DialogueEditorDataManager.data.currentDialogueId].booleans.variables.Count;
        int localStringsCount  = DialogueEditorDataManager.data.dialogues[DialogueEditorDataManager.data.currentDialogueId].strings.variables.Count;

        int globalVarsCount = globalFloatsCount + globalBooleansCount + globalStringsCount;
        int localVarsCount  = localFloatsCount + localBooleansCount + localStringsCount;

        int currentFloatsCount   = (__scope == VariableEditorScopes.Local)? localFloatsCount : globalFloatsCount;
        int currentBooleansCount = (__scope == VariableEditorScopes.Local)? localBooleansCount : globalBooleansCount;
        int currentStringsCount  = (__scope == VariableEditorScopes.Local)? localStringsCount : globalStringsCount;

        string titleText = "Variable Editor: " + __scope.ToString() + " " + __type.ToString();

        GUI.Label(new Rect(titleRect.x + 5, titleRect.y + 3, Screen.width, 20), titleText, EditorStyles.boldLabel);

        if (GUI.Toggle(new Rect(5, 30, (Screen.width - 10) * 0.5f, 25), (__scope == VariableEditorScopes.Global), "Globals (" + globalVarsCount + ")", DialogueEditorGUI.gui.GetStyle("toolbar_left")))
        {
            setTarget(VariableEditorScopes.Global, __type);
        }
        if (GUI.Toggle(new Rect((Screen.width - 20) * 0.5f + 10, 30, (Screen.width - 10) * 0.5f, 25), (__scope == VariableEditorScopes.Local), "Locals (" + localVarsCount + ")", DialogueEditorGUI.gui.GetStyle("toolbar_right")))
        {
            setTarget(VariableEditorScopes.Local, __type);
        }

        Rect typesRect             = new Rect(5, 60, Screen.width - 10, 25);
        Rect typeBooleanToggleRect = new Rect(typesRect.x, typesRect.y, typesRect.width * 0.33333f, typesRect.height);
        Rect typeFloatToggleRect   = new Rect(typesRect.x + (typesRect.width * 0.33333f), typesRect.y, typesRect.width * 0.33333f, typesRect.height);
        Rect typeStringToggleRect  = new Rect(typesRect.x + ((typesRect.width * 0.33333f) * 2), typesRect.y, typesRect.width * 0.33333f, typesRect.height);

        if (GUI.Toggle(typeBooleanToggleRect, (__type == VariableEditorTypes.Boolean), "Booleans (" + currentBooleansCount + ")", DialogueEditorGUI.gui.GetStyle("toolbar_left")))
        {
            setTarget(__scope, VariableEditorTypes.Boolean);
        }
        if (GUI.Toggle(typeFloatToggleRect, (__type == VariableEditorTypes.Float), "Floats (" + currentFloatsCount + ")", DialogueEditorGUI.gui.GetStyle("toolbar_center")))
        {
            setTarget(__scope, VariableEditorTypes.Float);
        }
        if (GUI.Toggle(typeStringToggleRect, (__type == VariableEditorTypes.String), "Strings (" + currentStringsCount + ")", DialogueEditorGUI.gui.GetStyle("toolbar_right")))
        {
            setTarget(__scope, VariableEditorTypes.String);
        }


        // Editor Box
        Rect editorRect = new Rect(5, typeBooleanToggleRect.y + typeBooleanToggleRect.height + 5, Screen.width - 10, 130);

        drawEditorGui(editorRect);

        // ------------------ SCROLL BOX
        // VISUALS
        Rect scrollRect = new Rect(8, editorRect.y + editorRect.height + 8, Screen.width - 16, Screen.height - (editorRect.y + editorRect.height + 70));

        if (isPro)
        {
            GUI.color = GUI.contentColor;
            GUI.Box(new Rect(scrollRect.x - 2, scrollRect.y - 2, scrollRect.width + 4, scrollRect.height + 4), string.Empty);
            GUI.color = Color.black;
            GUI.Box(new Rect(scrollRect.x - 1, scrollRect.y - 1, scrollRect.width + 2, scrollRect.height + 2), string.Empty);
            GUI.Box(new Rect(scrollRect.x - 1, scrollRect.y - 1, scrollRect.width + 2, scrollRect.height + 2), string.Empty);
            GUI.Box(new Rect(scrollRect.x - 1, scrollRect.y - 1, scrollRect.width + 2, scrollRect.height + 2), string.Empty);
            GUI.Box(new Rect(scrollRect.x - 1, scrollRect.y - 1, scrollRect.width + 2, scrollRect.height + 2), string.Empty);
            GUI.color = GUI.contentColor;
        }
        else
        {
            GUI.Box(DialogueEditorGUI.getOutlineRect(scrollRect, 1), string.Empty, DialogueEditorGUI.gui.GetStyle("box_inset"));
        }
        // MOUSE HANDLING
        int     rowHeight          = 20;
        int     rowSpacing         = (EditorGUIUtility.isProSkin) ? 1 : -1;
        int     newScrollHeight    = (scrollRect.height > ((rowHeight + rowSpacing) * variables.variables.Count)) ? (int)scrollRect.height : (rowHeight + rowSpacing) * variables.variables.Count;
        Rect    scrollContentRect  = new Rect(0, 0, scrollRect.width - 15, newScrollHeight);
        Vector2 mouseClickPosition = Vector2.zero;

        if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && scrollRect.Contains(Event.current.mousePosition))
        {
            mouseClickPosition = new Vector2(Event.current.mousePosition.x - scrollRect.x - 3, Event.current.mousePosition.y - scrollRect.y - 3 + __scrollPosition.y);
        }
        //START SCROLL VIEW
        __scrollPosition = GUI.BeginScrollView(scrollRect, __scrollPosition, scrollContentRect, false, true);

        GUI.color = (isPro) ? new Color(1, 1, 1, 0.25f) : new Color(1, 1, 1, 0.1f);
        GUI.DrawTextureWithTexCoords(
            scrollContentRect,
            DialogueEditorGUI.scrollboxBgTexture,
            new Rect(0, 0, scrollContentRect.width / DialogueEditorGUI.scrollboxBgTexture.width, scrollContentRect.height / DialogueEditorGUI.scrollboxBgTexture.height)
            );
        GUI.color = GUI.contentColor;

        for (int i = 0; i < variables.variables.Count; i += 1)
        {
            Rect row = new Rect(0, 0 + ((rowHeight + rowSpacing) * i), scrollRect.width - 15, 20);
            if (mouseClickPosition != Vector2.zero && row.Contains(mouseClickPosition))
            {
                variables.selection = i;
            }
            GUI.color = new Color(1, 1, 1, 0.5f);
            GUI.Box(row, string.Empty);
            if (i == variables.selection)
            {
                if (isPro)
                {
                    GUI.color = GUI.contentColor;
                    GUI.Box(row, string.Empty);
                    GUI.Box(row, string.Empty);
                }
                else
                {
                    GUI.Box(row, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
                    GUI.Box(row, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
                }
            }

            if (row.Contains(Event.current.mousePosition))
            {
                if (isPro)
                {
                    GUI.color = Color.black;
                    GUI.Box(new Rect(row.x - 1, row.y - 1, row.width + 2, row.height + 2), string.Empty);
                }
                else
                {
                    GUI.color = Color.white;
                    GUI.Box(row, string.Empty);
                    GUI.Box(row, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
                    GUI.Box(row, string.Empty, DialogueEditorGUI.gui.GetStyle("box_outset"));
                }
            }

            GUI.color = GUI.contentColor;

            Rect labelNumberRow = new Rect(row.x + 2, row.y + 2, row.width - 4, row.height - 4);
            Rect labelNameRow   = new Rect(labelNumberRow.x + 25, labelNumberRow.y, labelNumberRow.width - 25, labelNumberRow.height);
            GUI.Label(labelNumberRow, variables.variables[i].id.ToString());
            string labelNameText = (variables.variables[i].name != string.Empty) ? variables.variables[i].name : string.Empty;
            GUI.Label(labelNameRow, labelNameText);
            GUI.color = new Color(1, 1, 1, 0.5f);
            GUI.Label(labelNameRow, (variables.variables[i].variable != string.Empty) ? labelNameText + ": " + variables.variables[i].variable : string.Empty);
            GUI.color = GUI.contentColor;
        }
        // END SCROLL VIES
        GUI.EndScrollView();

        // ADD/REMOVE BUTTONS
        //ADD
        Rect addButtonRect = new Rect(5, scrollRect.y + scrollRect.height + 8, (Screen.width - 10) * 0.5f, 25);

        if (GUI.Button(addButtonRect, "Add", DialogueEditorGUI.gui.GetStyle("toolbar_left")))
        {
            variables.addVariable();
        }

        //REMOVE
        Rect removeButtonRect = new Rect((Screen.width - 10) * 0.5f + 5, scrollRect.y + scrollRect.height + 8, (Screen.width - 10) * 0.5f, 25);

        if (variables.variables.Count > 0)
        {
            if (GUI.Button(removeButtonRect, "Remove", DialogueEditorGUI.gui.GetStyle("toolbar_right")))
            {
                variables.removeVariable();
            }
        }
        else
        {
            GUI.color = new Color(1, 1, 1, 0.5f);
            GUI.Button(removeButtonRect, "Remove", DialogueEditorGUI.gui.GetStyle("toolbar_right"));
            GUI.color = GUI.contentColor;
        }

        Repaint();
    }