Example #1
0
    protected void DrawMobileReference(MobileReference mr)
    {                           //TODO move this to Frontiers.Data, this is actually useful
        bool stretchWidthBeforeEntry = miniButtonStyle.stretchWidth;

        miniButtonStyle.stretchWidth = false;
        GUI.color = Color.yellow;

        string         finalPath           = string.Empty;
        Stack <string> newGroupStack       = new Stack <string>();
        Stack <string> groupMinusLast      = new Stack <string>();
        bool           doLastGroupDropDown = false;
        bool           doChildItemDropDown = false;

        if (string.IsNullOrEmpty(mr.GroupPath))
        {
            mr.GroupPath = "Root";
        }
        Stack <string> splitGroup = WIGroup.SplitPath(mr.GroupPath);
        //it's always root
        string lastGroupInPath = string.Empty;

        if (splitGroup.Count == 1)
        {
            lastGroupInPath = splitGroup.Pop();
            groupMinusLast.Push(lastGroupInPath);
            newGroupStack.Push(lastGroupInPath);
            GUILayout.Button(lastGroupInPath, miniButtonStyle);
        }
        else
        {
            while (splitGroup.Count > 0)
            {
                lastGroupInPath = splitGroup.Pop();
                if (splitGroup.Count > 0)                                                       //if there's still at least one more to go...
                //add it to both stacks
                {
                    groupMinusLast.Push(lastGroupInPath);
                    newGroupStack.Push(lastGroupInPath);
                    doLastGroupDropDown = true;
                    GUILayout.Button(lastGroupInPath, miniButtonStyle);
                }
            }
        }

        bool   madeGroupSelection = false;
        string newGroupSelection  = string.Empty;
        string groupPathMinusLast = WIGroup.CombinePath(groupMinusLast);

        if (doLastGroupDropDown)
        {
            //get the path of the group, minus the last group
            List <string> currentGroups = Mods.Get.Editor.GroupChildGroupNames(groupPathMinusLast);
            if (currentGroups.Count > 0)
            {
                GUI.color = Color.Lerp(Color.yellow, Color.gray, 0.5f);
                int indexOfLastGroup = currentGroups.IndexOf(lastGroupInPath);
                if (indexOfLastGroup < 0)
                {
                    indexOfLastGroup = 0;
                }
                int indexOfGroupSelection = EditorGUILayout.Popup(indexOfLastGroup, currentGroups.ToArray());
                if (indexOfGroupSelection >= 0 && indexOfGroupSelection < currentGroups.Count)
                {
                    newGroupSelection  = currentGroups[indexOfGroupSelection];
                    madeGroupSelection = true;
                }
            }
        }

        //if we picked a new group add the selected group
        //otherwise just add the old group
        if (madeGroupSelection)
        {
            newGroupStack.Push(newGroupSelection);
        }
        else
        {
            newGroupStack.Push(lastGroupInPath);
        }

        List <string> nextGroups = Mods.Get.Editor.GroupChildGroupNames(mr.GroupPath);

        if (nextGroups.Count > 0)
        {
            GUI.color = Color.green;
            if (GUILayout.Button("+", miniButtonStyle))                                         //if we click the add button, change the group
            {
                newGroupStack.Push(nextGroups[0]);
            }
        }

        finalPath = WIGroup.CombinePath(newGroupStack);

        GUI.color = Color.red;
        if (GUILayout.Button("-", miniButtonStyle))
        {
            //set the last group path to the one BEFORE the current last
            finalPath = groupPathMinusLast;
        }

        mr.GroupPath = finalPath;

        miniButtonStyle.stretchWidth = true;
        GUI.color = Color.white;
        //now get all child items
        List <string> childItemsInGroup = Mods.Get.Editor.GroupChildItemNames(mr.GroupPath);

        if (childItemsInGroup.Count == 0)
        {
            GUILayout.Label("(No child items)");
        }
        else
        {
            string newChildItemSelection = string.Empty;
            int    indexChildSelection   = childItemsInGroup.IndexOf(mr.FileName);
            if (indexChildSelection < 0)
            {
                indexChildSelection = 0;
            }
            int indexOfChildItemSelection = EditorGUILayout.Popup(indexChildSelection, childItemsInGroup.ToArray());
            if (indexOfChildItemSelection >= 0 && indexOfChildItemSelection < childItemsInGroup.Count)
            {
                newChildItemSelection = childItemsInGroup[indexOfChildItemSelection];
                mr.FileName           = newChildItemSelection;
            }
        }

        //mr.GroupPath = newGroupPath;
        //mr.FileName = newChildItemSelection;

        miniButtonStyle.stretchWidth = stretchWidthBeforeEntry;
    }