Example #1
0
    void OnGUI()
    {
        GUILayout.Space(10);
        GUILayout.BeginHorizontal();
        GUILayout.Label("Areas Editor", EditorStyles.boldLabel);
        GUIStyle wordWrapStyle = new GUIStyle(EditorStyles.textArea);

        wordWrapStyle.wordWrap = true;

        if (GUILayout.Button("Add Area"))
        {
            AreaDatabase.CreateAsset();
        }
        if (GUILayout.Button("Delete Selected Area"))
        {
            AreaDatabase.DeleteAsset(_viewIndex);
            _viewIndex = (_viewIndex == 0 ? _viewIndex++ : _viewIndex--);
        }
        if (GUILayout.Button("Reload"))
        {
            AreaDatabase.LoadDatabaseForce();
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(20);

        GUILayout.BeginArea(new Rect(10, 70, 140, 350));
        _scrollPositionLeft = EditorGUILayout.BeginScrollView(_scrollPositionLeft, false, true);
        if (AreaDatabase.GetNumOfAssets() > 0)
        {
            for (int areaIndx = 0; areaIndx < AreaDatabase.GetNumOfAssets(); areaIndx++)
            {
                Area area = AreaDatabase.GetObject(areaIndx);
                if (GUILayout.Button(area.name, "label" /*+ (itemInd == _viewIndex ? "active" : "")*/))
                {
                    _viewIndex = areaIndx;
                    GUIUtility.keyboardControl = 0;
                }
            }
        }
        EditorGUILayout.EndScrollView();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(170, 70, 500, 350), EditorStyles.helpBox);
        _scrollPositionRight = EditorGUILayout.BeginScrollView(_scrollPositionRight);
        if (AreaDatabase.GetNumOfAssets() > 0)
        {
            Area asset = AreaDatabase.GetAsset(_viewIndex);
            if (asset != null)
            {
                EditorUtility.SetDirty(asset);
                GUILayout.Space(5);
                asset.name = EditorGUILayout.TextField("Area Name", asset.name, GUILayout.MaxWidth(300));

                GUILayout.Space(10);
                EditorGUILayout.LabelField("Goals:", EditorStyles.boldLabel);
                for (int goalIndx = 0; goalIndx < asset.goals.Count; goalIndx++)
                {
                    Term goal = asset.goals[goalIndx];
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Goal" + goalIndx + ":" + goal.GetTermAsString());
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        asset.DeleteGoal(goalIndx);
                    }
                    GUILayout.EndHorizontal();
                    EditorGUI.indentLevel++;
                    goal.name = EditorGUILayout.TextField("Goal Name", goal.name, GUILayout.MaxWidth(300));

                    EditorGUILayout.LabelField("Objective:", EditorStyles.label);
                    EditorStyles.textArea.wordWrap = true;
                    goal.description = EditorGUILayout.TextArea(goal.description, wordWrapStyle);

                    EditorGUILayout.LabelField("Hint:", EditorStyles.label);
                    goal.hint = EditorGUILayout.TextArea(goal.hint, wordWrapStyle);


                    EditorGUILayout.LabelField("Properties:", EditorStyles.boldLabel);
                    for (int propIndx = 0; propIndx < goal.properties.Count; propIndx++)
                    {
                        Property property = goal.properties[propIndx];
                        GUILayout.BeginHorizontal();
                        PropertyGUI(property);
                        GUILayout.Space(3);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            goal.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }
                    EditorGUI.indentLevel--;
                    GUILayout.Space(5);
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        goal.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndHorizontal();
                    GUILayout.Space(10);
                }
                GUILayout.Space(3);
                if (GUILayout.Button("Add Goal", GUILayout.ExpandWidth(false)))
                {
                    asset.AddGoal();
                }
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Connected Areas:", EditorStyles.boldLabel);
                for (int connectedId = 0; connectedId < asset.connectedTo.Count; connectedId++)
                {
                    GUILayout.BeginHorizontal();
                    asset.connectedTo[connectedId] = (Area)EditorGUILayout.ObjectField(asset.connectedTo[connectedId], typeof(Area), false);
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        asset.DeleteConnectedArea(connectedId);
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.Space(5);
                if (GUILayout.Button("Add Connected Area", GUILayout.ExpandWidth(false)))
                {
                    asset.AddConnectedArea();
                }
                GUILayout.Space(5);
                //Addition 10/01/2020
                EditorGUILayout.LabelField("MaxDepth: ", EditorStyles.boldLabel);
                //end add
                asset.maxDepth = EditorGUILayout.IntField(asset.maxDepth, GUILayout.MinWidth(100), GUILayout.MaxWidth(300));
            }
        }
        EditorGUILayout.EndScrollView();
        GUILayout.EndArea();
    }
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(10, 10, 1200, 500), EditorStyles.helpBox);
        _scrollPositionBottom = EditorGUILayout.BeginScrollView(_scrollPositionBottom, true, true);

        EditorGUILayout.LabelField("Rules:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField(" -S: second input item doesn't need to be selected. -I: main output goes straight to inventory. #Rules: " + RuleDatabase.GetNumOfAssets()); // +
        //"-A: rule is executed automatically. ");
        if (GUILayout.Button("Add New Rule", GUILayout.ExpandWidth(false)))
        {
            foldedOut.Add(false);
            RuleDatabase.CreateAsset();
        }



        for (int ruleIndx = 0; ruleIndx < RuleDatabase.GetNumOfAssets(); ruleIndx++)
        {
            Rule rule = RuleDatabase.GetAsset(ruleIndx);
            EditorUtility.SetDirty(rule);
            string additionalProperties = "";       //Addition - indicating Rule properties:
            if (rule.selectedInput)
            {
                additionalProperties += " -S ";     //Second input item does not need to be selected
            }
            if (rule.inventory)
            {
                additionalProperties += " -I ";     //First output item is spawned directly in the inventory
            }

            /*if (rule.automatic)
             *  additionalProperties += " -A ";  *///Such rules are excuted automatically
            if (rule.ruleNumber != GetFileNameShort(rule))
            {
                rule.ruleNumber = GetFileNameShort(rule);
            }
            string ruleNumber = "#" + rule.ruleNumber + ": ";
            foldedOut[ruleIndx] = EditorGUILayout.Foldout(foldedOut[ruleIndx], ruleNumber + rule.GetRuleAsString() + additionalProperties);

            if (foldedOut[ruleIndx])
            {
                // === OUTPUT ===
                EditorGUILayout.LabelField("Output:", EditorStyles.boldLabel);

                for (int outputIndx = 0; outputIndx < rule.outputs.Count; outputIndx++)
                {
                    GUILayout.BeginHorizontal();
                    Term output = rule.outputs[outputIndx];
                    output.name = EditorGUILayout.TextArea(output.name, GUILayout.Width(100));
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        rule.DeleteOutputAtIndex(outputIndx);
                    }
                    GUILayout.BeginVertical();
                    for (int propIndx = 0; propIndx < output.properties.Count; propIndx++)
                    {
                        GUILayout.BeginHorizontal();
                        PropertyGUI(output.properties[propIndx]);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            output.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        output.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                    GUILayout.EndHorizontal();
                }

                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    rule.AddOutput();
                }

                // === ACTION ===
                EditorGUILayout.LabelField("Action:", EditorStyles.boldLabel);
                rule.action = EditorGUILayout.TextArea(rule.action);

                // === INPUT ===
                EditorGUILayout.LabelField("Input:", EditorStyles.boldLabel);

                for (int inputIndx = 0; inputIndx < rule.inputs.Count; inputIndx++)
                {
                    GUILayout.BeginHorizontal();
                    Term input = rule.inputs[inputIndx];
                    input.name = EditorGUILayout.TextArea(input.name, GUILayout.Width(100));
                    if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                    {
                        rule.DeleteInputAtIndex(inputIndx);
                    }

                    GUILayout.BeginVertical();
                    for (int propIndx = 0; propIndx < input.properties.Count; propIndx++)
                    {
                        GUILayout.BeginHorizontal();
                        PropertyGUI(input.properties[propIndx]);
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            input.DeleteProperty(propIndx);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Add:", GUILayout.ExpandWidth(false)))
                    {
                        input.AddPropertyOfType(_newPropertyType);
                    }
                    _newPropertyType = (PropertyType)EditorGUILayout.EnumPopup(_newPropertyType, GUILayout.ExpandWidth(false));
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                    GUILayout.EndHorizontal();
                }


                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    rule.AddInput();
                }


                // === InIventory ===                   (addition)
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Input doesn't need to be selected:", EditorStyles.boldLabel);
                rule.selectedInput = EditorGUILayout.Toggle(rule.selectedInput);
                EditorGUILayout.EndHorizontal();

                // === Straight to Inventory ===        (addition)
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("First output goes straight to inventory:", EditorStyles.boldLabel);
                rule.inventory = EditorGUILayout.Toggle(rule.inventory);
                EditorGUILayout.EndHorizontal();

                /*// === Automatic Rule ===        (addition)       This is a starting point for including rules which can be executed without player interaction
                 * EditorGUILayout.BeginHorizontal();
                 * EditorGUILayout.LabelField("Automatically executed rule:", EditorStyles.boldLabel);
                 * rule.automatic = EditorGUILayout.Toggle(rule.automatic);
                 * EditorGUILayout.EndHorizontal();
                 */
                if (GUILayout.Button("Delete Rule", GUILayout.ExpandWidth(false)))
                {
                    RuleDatabase.DeleteAsset(ruleIndx);
                }
            }
        }

        EditorGUILayout.EndScrollView();
        GUILayout.EndArea();
    }