public IEnumerator LoadGroupsOverTime()
        {
            Debug.Log("Superloading path " + GroupPath);
            if (string.IsNullOrEmpty(GroupPath))
            {
                Debug.Log("Path was empty!");
                OnFinish();
                yield break;
            }
            GroupsToLoad = WIGroup.SplitPath(GroupPath);
            //pop the first - it will be the root
            GroupsToLoad.Pop();
            LastGroupLoaded = WIGroups.Get.Root;
            LastGroupLoaded.Load();
            if (GroupsToLoad.Count > 0)
            {
                NextGroupToLoad = GroupsToLoad.Peek();
                //start at the root and then load the groups all the way down
                //we'll keep loading groups until we've loaded everything in the stack
                while (GroupsToLoad.Count > 0)
                {
                    State = "Loading group";
                    WIGroup nextGroup = null;
                    while (!LastGroupLoaded.Is(WIGroupLoadState.Loaded) || !LastGroupLoaded.GetChildGroup(out nextGroup, NextGroupToLoad))
                    {
                        Debug.Log("Last group " + LastGroupLoaded.name + " loaded? " + LastGroupLoaded.Is(WIGroupLoadState.Loaded).ToString() + "\n" +
                                  "Child group available? " + LastGroupLoaded.GetChildGroup(out nextGroup, NextGroupToLoad).ToString());
                        State = "Waiting for child group " + NextGroupToLoad;
                        Ticks++;
                        yield return(null);
                    }
                    //now that it has its child items, tell it to load its child groups
                    LastGroupLoaded = nextGroup;
                    GroupsToLoad.Pop();
                    if (GroupsToLoad.Count > 0)
                    {
                        NextGroupToLoad = GroupsToLoad.Peek();
                        Ticks++;
                        yield return(null);
                    }
                }

                yield return(null);

                //now we search the group to see if it holds the child item we're looking for
                while (!LastGroupLoaded.FindChildItem(ChildItemFileName, out LoadedWorldItem))
                {
                    //LastGroupLoaded.State = WIGroupState.ForceLoad;
                    Ticks++;
                    State = "Waiting for child item " + ChildItemFileName;
                    yield return(null);
                }
            }
            //finished!
            OnFinish();

            yield break;
        }
Exemple #2
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;
    }