Esempio n. 1
0
        public static void OnGUI(UnitEntityData ch,
                                 IEnumerable <BlueprintScriptableObject> blueprints,
                                 float indent = 0, float remainingWidth = 0,
                                 Func <String, String> titleFormater = null,
                                 NamedTypeFilter typeFilter          = null
                                 )
        {
            if (titleFormater == null)
            {
                titleFormater = (t) => t.orange().bold();
            }
            int index = 0;

            if (needsLayout)
            {
                foreach (BlueprintScriptableObject blueprint in blueprints)
                {
                    var actions = blueprint.GetActions();
                    if (actions.Any(a => a.isRepeatable))
                    {
                        hasRepeatableAction = true;
                    }
                    int actionCount = actions.Sum(action => action.canPerform(blueprint, ch) ? 1 : 0);
                    maxActions = Math.Max(actionCount, maxActions);
                }
                needsLayout = false;
            }
            if (hasRepeatableAction)
            {
                UI.BeginHorizontal();
                UI.Space(553);
                UI.ActionIntTextField(
                    ref repeatCount,
                    "repeatCount",
                    (limit) => { },
                    () => { },
                    UI.Width(160));
                UI.Space(40);
                UI.Label("Parameter".cyan() + ": " + $"{repeatCount}".orange(), UI.ExpandWidth(false));
                repeatCount = Math.Max(1, repeatCount);
                repeatCount = Math.Min(100, repeatCount);
                UI.EndHorizontal();
            }
            UI.Div(indent);
            foreach (BlueprintScriptableObject blueprint in blueprints)
            {
                UI.BeginHorizontal();
                UI.Space(indent);
                var actions = blueprint.GetActions().Where(action => action.canPerform(blueprint, ch)).ToArray();
                var titles  = actions.Select(a => a.name);
                var title   = blueprint.name;
                if (titles.Contains("Remove"))
                {
                    title = title.cyan().bold();
                }
                else
                {
                    title = titleFormater(title);
                }

                UI.Label(title, UI.Width(550 - indent));
                int actionCount = actions != null?actions.Count() : 0;

                for (int ii = 0; ii < maxActions; ii++)
                {
                    if (ii < actionCount)
                    {
                        BlueprintAction action = actions[ii];
                        // TODO -don't show increase or decrease actions until we redo actions into a proper value editor that gives us Add/Remove and numeric item with the ability to show values.  For now users can edit ranks in the Facts Editor
                        if (action.name == "<" || action.name == ">")
                        {
                            UI.Space(164); continue;
                        }
                        var   actionName = action.name;
                        float extraSpace = 0;
                        if (action.isRepeatable)
                        {
                            actionName += (action.isRepeatable ? $" {repeatCount}" : "");
                            extraSpace  = 20 * (float)Math.Ceiling(Math.Log10((double)repeatCount));
                        }
                        UI.ActionButton(actionName, () => { action.action(blueprint, ch, repeatCount); }, UI.Width(160 + extraSpace));
                        UI.Space(10);
                    }
                    else
                    {
                        UI.Space(174);
                    }
                }
                UI.Space(30);
                String typeString = blueprint.GetType().Name;
                if (typeFilter?.collator != null)
                {
                    var collatorString = typeFilter.collator(blueprint);
                    if (!typeString.Contains(collatorString))
                    {
                        typeString += $" : {collatorString}".yellow();
                    }
                }
                Rect rect        = GUILayoutUtility.GetLastRect();
                var  description = blueprint.GetDescription();
                if (description != null && description.Length > 0)
                {
                    description = $"\n{description.green()}";
                }
                else
                {
                    description = "";
                }
                if (settings.showComponents && blueprint.ComponentsArray != null)
                {
                    String componentStr = String.Join <object>(" ", blueprint.ComponentsArray).grey();
                    if (description.Length == 0)
                    {
                        description = componentStr;
                    }
                    else
                    {
                        description = componentStr + description;
                    }
                }
                if (settings.showElements && blueprint.ElementsArray != null)
                {
                    String elementsStr = String.Join <object>(" ", blueprint.ElementsArray).yellow();
                    if (description.Length == 0)
                    {
                        description = elementsStr;
                    }
                    else
                    {
                        description = elementsStr + "\n" + description;
                    }
                }
                if (settings.showAssetIDs)
                {
                    UI.Label(typeString.cyan());
                    GUILayout.TextField(blueprint.AssetGuid, UI.Width(450));
                    UI.EndHorizontal();
                    if (description.Length > 0)
                    {
                        UI.BeginHorizontal();
                        UI.Label("", UI.Width(rect.x));
                        UI.Label(blueprint.GetDescription().green()); //,
                        UI.EndHorizontal();
                    }
                }
                else
                {
                    float width = remainingWidth - rect.xMax;
                    UI.Label(typeString.cyan() + " " + description, UI.Width(800));
                    //UI.Label($"{remainingWidth} - {rect.xMax} = {width}" + typeString + " " + description, UI.Width(800));
                    UI.EndHorizontal();
                }
#if false
                String description = blueprint.GetDescription();
                if (description.Length > 0)
                {
                    UI.BeginHorizontal();
                    UI.Space(684 + maxActions * 154);
                    UI.Label($"{description.green()}");
                    UI.EndHorizontal();
                }
#endif
                UI.Div(indent);
                index++;
            }
        }
Esempio n. 2
0
        public void OnGUI(UnitEntityData character, bool refresh)
        {
            if (!Main.IsInGame)
            {
                return;
            }
            var activeScene = SceneManager.GetActiveScene().name;

            if (Game.Instance?.Player == null || activeScene == "MainMenu" || activeScene == "Start")
            {
                UI.Label(" * Please start or load the game first.".color(RGBA.yellow));
                return;
            }
            if (_buttonStyle == null)
            {
                _buttonStyle = new GUIStyle(GUI.skin.button)
                {
                    alignment = TextAnchor.MiddleLeft, wordWrap = true
                }
            }
            ;

            try {
                if (character != _selectedCharacter || refresh)
                {
                    _selectedCharacter = character;
                    _featuresTree      = new FeaturesTree(_selectedCharacter.Descriptor.Progression);;
                }
                using (UI.HorizontalScope()) {
                    // features tree
                    if (_featuresTree != null)
                    {
                        using (UI.VerticalScope()) {
                            var expandAll   = false;
                            var collapseAll = false;

                            // draw tool bar
                            using (UI.HorizontalScope()) {
                                UI.ActionButton("Refresh", () => _featuresTree = new FeaturesTree(_selectedCharacter.Descriptor.Progression), UI.Width(200));
                                UI.Button("Expand All", ref expandAll, UI.Width(200));
                                UI.Button("Collapse All", ref collapseAll, UI.Width(200));
                            }

                            UI.Space(10f);

                            // draw tree
                            foreach (var node in _featuresTree.RootNodes)
                            {
                                draw(node);
                            }

                            void draw(FeaturesTree.FeatureNode node)
                            {
                                using (UI.HorizontalScope()) {
                                    var levelText     = node.Level == 0 ? "" : $" {node.Level} - ";
                                    var blueprintName = $"[{node.Blueprint.name}]".color(node.IsMissing ? RGBA.maroon : RGBA.aqua);
                                    var titleText     = $"{levelText}{node.Name.Bold()} {blueprintName}";
                                    if (node.ChildNodes.Count > 0)
                                    {
                                        if (node.Expanded == ToggleState.None)
                                        {
                                            node.Expanded = ToggleState.Off;
                                        }
                                        node.Expanded = expandAll ? ToggleState.On : collapseAll ? ToggleState.Off : node.Expanded;
                                    }
                                    else
                                    {
                                        node.Expanded = ToggleState.None;
                                    }
                                    Mod.Trace($"{node.Expanded} {titleText}");
                                    UI.ToggleButton(ref node.Expanded, titleText, _buttonStyle);
                                    if (node.Expanded.IsOn())
                                    {
                                        using (UI.VerticalScope(UI.ExpandWidth(false))) {
                                            foreach (var child in node.ChildNodes.OrderBy(n => n.Level))
                                            {
                                                draw(child);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        GUILayout.FlexibleSpace();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) {
                _selectedCharacter = null;
                _featuresTree      = null;
                Mod.Error(e);
                throw e;
            }
        }
Esempio n. 3
0
        public static IEnumerable OnGUI()
        {
            UI.ActionSelectionGrid(ref settings.selectedBPTypeFilter,
                                   blueprintTypeFilters.Select(tf => tf.name).ToArray(),
                                   10,
                                   (selected) => { UpdateSearchResults(); },
                                   UI.MinWidth(200));
            UI.Space(10);

            UI.BeginHorizontal();
            UI.ActionTextField(
                ref settings.searchText,
                "searhText",
                (text) => { },
                () => { UpdateSearchResults(); },
                UI.Width(400));
            UI.Label("Limit", UI.ExpandWidth(false));
            UI.ActionIntTextField(
                ref settings.searchLimit,
                "searchLimit",
                (limit) => { },
                () => { UpdateSearchResults(); },
                UI.Width(200));
            if (settings.searchLimit > 1000)
            {
                settings.searchLimit = 1000;
            }
            UI.Space(25);
            UI.Toggle("Show GUIs", ref settings.showAssetIDs);
            UI.Space(25);
            UI.Toggle("Dividers", ref settings.showDivisions);

            UI.EndHorizontal();
            UI.BeginHorizontal();
            UI.ActionButton("Search", () => {
                UpdateSearchResults();
            }, UI.AutoWidth());
            UI.Space(25);
            if (firstSearch)
            {
                UI.Label("please note the first search may take a few seconds.".green(), UI.AutoWidth());
            }
            else if (matchCount > 0)
            {
                String title = "Matches: ".green().bold() + $"{matchCount}".orange().bold();
                if (matchCount > settings.searchLimit)
                {
                    title += " => ".cyan() + $"{settings.searchLimit}".cyan().bold();
                }
                if (collatedBPs != null)
                {
                    foreach (var group in collatedBPs)
                    {
                        title += $" {group.Key} ({group.Count()})";
                    }
                }
                UI.Label(title, UI.ExpandWidth(false));
            }
            UI.Space(50);
            UI.Label("".green(), UI.AutoWidth());
            UI.EndHorizontal();
            UI.Space(10);

            if (filteredBPs != null)
            {
                CharacterPicker.OnGUI();
                UnitReference selected = CharacterPicker.GetSelectedCharacter();
                BlueprintListUI.OnGUI(selected, filteredBPs, collatedBPs, 0, null, selectedTypeFilter);
            }
            UI.Space(25);
            return(null);
        }
Esempio n. 4
0
        static public void OnGUI <T>(String callerKey,
                                     UnitEntityData unit,
                                     List <T> facts,
                                     Func <T, BlueprintScriptableObject> blueprint,
                                     IEnumerable <BlueprintScriptableObject> blueprints,
                                     Func <T, String> title,
                                     Func <T, String> description          = null,
                                     Func <T, int> value                   = null,
                                     IEnumerable <BlueprintAction> actions = null
                                     )
        {
            bool searchChanged = false;

            if (actions == null)
            {
                actions = new List <BlueprintAction>();
            }
            if (callerKey != prevCallerKey)
            {
                searchChanged = true; showAll = false;
            }
            prevCallerKey = callerKey;
            var mutatorLookup = actions.Distinct().ToDictionary(a => a.name, a => a);

            UI.BeginHorizontal();
            UI.Space(100);
            UI.ActionTextField(ref searchText, "searhText", null, () => { searchChanged = true; }, UI.Width(320));
            UI.Space(25);
            UI.Label("Limit", UI.ExpandWidth(false));
            UI.ActionIntTextField(ref searchLimit, "searchLimit", null, () => { searchChanged = true; }, UI.Width(175));
            if (searchLimit > 1000)
            {
                searchLimit = 1000;
            }
            UI.Space(25);
            UI.Toggle("Show GUIDs", ref Main.settings.showAssetIDs);
            UI.Space(25);
            UI.Toggle("Dividers", ref Main.settings.showDivisions);
            UI.Space(25);
            searchChanged |= UI.DisclosureToggle("Show All".orange().bold(), ref showAll);
            UI.EndHorizontal();
            UI.BeginHorizontal();
            UI.Space(100);
            UI.ActionButton("Search", () => { searchChanged = true; }, UI.AutoWidth());
            UI.Space(25);
            if (matchCount > 0 && searchText.Length > 0)
            {
                String matchesText = "Matches: ".green().bold() + $"{matchCount}".orange().bold();
                if (matchCount > searchLimit)
                {
                    matchesText += " => ".cyan() + $"{searchLimit}".cyan().bold();
                }
                UI.Label(matchesText, UI.ExpandWidth(false));
            }
#if false
            UI.Label("Repeat Count", UI.ExpandWidth(false));
            UI.ActionIntTextField(
                ref repeatCount,
                "repeatCount",
                (limit) => { },
                () => { },
                UI.Width(200));
#endif
            UI.EndHorizontal();

            if (showAll)
            {
                // TODO - do we need this logic or can we make blueprint filtering fast enough to do keys by key searching?
                //if (filteredBPs == null || searchChanged) {
                UpdateSearchResults(searchText, searchLimit, blueprints);
                //}
                BlueprintListUI.OnGUI(unit, filteredBPs, 100);
                return;
            }
            var terms = searchText.Split(' ').Select(s => s.ToLower()).ToHashSet();

            BlueprintAction add      = mutatorLookup.GetValueOrDefault("Add", null);
            BlueprintAction remove   = mutatorLookup.GetValueOrDefault("Remove", null);
            BlueprintAction decrease = mutatorLookup.GetValueOrDefault("<", null);
            BlueprintAction increase = mutatorLookup.GetValueOrDefault(">", null);

            mutatorLookup.Remove("Add");
            mutatorLookup.Remove("Remove");
            mutatorLookup.Remove("<");
            mutatorLookup.Remove(">");

            BlueprintScriptableObject toAdd      = null;
            BlueprintScriptableObject toRemove   = null;
            BlueprintScriptableObject toIncrease = null;
            BlueprintScriptableObject toDecrease = null;
            var toValues = new Dictionary <String, BlueprintScriptableObject>();
            var sorted   = facts.OrderBy((f) => title(f));
            matchCount = 0;
            UI.Div(100);
            foreach (var fact in sorted)
            {
                if (fact == null)
                {
                    continue;
                }
                var    bp        = blueprint(fact);
                String name      = title(fact);
                String nameLower = name.ToLower();
                if (name != null && name.Length > 0 && (searchText.Length == 0 || terms.All(term => nameLower.Contains(term))))
                {
                    matchCount++;
                    UI.BeginHorizontal();
                    UI.Space(100);
                    UI.Label($"{name}".cyan().bold(), UI.Width(400));
                    UI.Space(30);
                    if (value != null)
                    {
                        var v = value(fact);
                        decrease.BlueprintActionButton(unit, bp, () => { toDecrease = bp; }, 50);
                        UI.Space(10f);
                        UI.Label($"{v}".orange().bold(), UI.Width(30));
                        increase.BlueprintActionButton(unit, bp, () => { toIncrease = bp; }, 50);
                    }
#if false
                    UI.Space(30);
                    add.BlueprintActionButton(unit, bp, () => { toAdd = bp; }, 150);
#endif
                    UI.Space(30);
                    remove.BlueprintActionButton(unit, bp, () => { toRemove = bp; }, 150);
#if false
                    foreach (var action in actions)
                    {
                        action.MutatorButton(unit, bp, () => { toValues[action.name] = bp; }, 150);
                    }
#endif
                    if (description != null)
                    {
                        UI.Space(30);
                        var assetID = Main.settings.showAssetIDs ? blueprint(fact).AssetGuid.magenta() + " " : "";
                        UI.Label(assetID + description(fact).green(), UI.AutoWidth());
                    }
                    UI.EndHorizontal();
                    UI.Div(100);
                }
            }
            if (toAdd != null)
            {
                add.action(toAdd, unit, repeatCount); toAdd = null;
            }
            if (toRemove != null)
            {
                remove.action(toRemove, unit, repeatCount); toRemove = null;
            }
            if (toDecrease != null)
            {
                decrease.action(toDecrease, unit, repeatCount); toDecrease = null;
            }
            if (toIncrease != null)
            {
                increase.action(toIncrease, unit, repeatCount); toIncrease = null;
            }
            foreach (var item in toValues)
            {
                var muator = mutatorLookup[item.Key];
                if (muator != null)
                {
                    muator.action(item.Value, unit, repeatCount);
                }
            }
            toValues.Clear();
        }
Esempio n. 5
0
        public static IEnumerable OnGUI()
        {
            // Stackable browser
            using (UI.HorizontalScope(UI.Width(450))) {
                // First column - Type Selection Grid
                using (UI.VerticalScope(GUI.skin.box)) {
                    UI.ActionSelectionGrid(ref settings.selectedBPTypeFilter,
                                           blueprintTypeFilters.Select(tf => tf.name).ToArray(),
                                           1,
                                           (selected) => { UpdateSearchResults(); },
                                           UI.buttonStyle,
                                           UI.Width(200));
                }
                bool collationChanged = false;
                if (collatedBPs != null)
                {
                    using (UI.VerticalScope(GUI.skin.box)) {
                        UI.ActionSelectionGrid(ref selectedCollationIndex, collationKeys.ToArray(),
                                               1,
                                               (selected) => { collationChanged = true; BlueprintListUI.needsLayout = true; },
                                               UI.buttonStyle,
                                               UI.Width(200));
                    }
                }
                // Section Column  - Main Area
                float remainingWidth = Main.ummWidth - 325;
                using (UI.VerticalScope(UI.Width(remainingWidth))) {
                    // Search Field and modifiers
                    using (UI.HorizontalScope()) {
                        UI.ActionTextField(
                            ref settings.searchText,
                            "searhText",
                            (text) => { },
                            () => { UpdateSearchResults(); },
                            UI.Width(400));
                        UI.Label("Limit", UI.ExpandWidth(false));
                        UI.ActionIntTextField(
                            ref settings.searchLimit,
                            "searchLimit",
                            (limit) => { },
                            () => { UpdateSearchResults(); },
                            UI.Width(200));
                        if (settings.searchLimit > 1000)
                        {
                            settings.searchLimit = 1000;
                        }
                        UI.Space(25);
                        UI.Toggle("Show GUIDs", ref settings.showAssetIDs);
                        UI.Space(25);
                        UI.Toggle("Components", ref settings.showComponents);
                        UI.Space(25);
                        UI.Toggle("Elements", ref settings.showElements);
                        UI.Space(25);
                        UI.Toggle("Dividers", ref settings.showDivisions);
                    }
                    // Search Button and Results Summary
                    using (UI.HorizontalScope()) {
                        UI.ActionButton("Search", () => {
                            UpdateSearchResults();
                        }, UI.AutoWidth());
                        UI.Space(25);
                        if (firstSearch)
                        {
                            UI.Label("please note the first search may take a few seconds.".green(), UI.AutoWidth());
                        }
                        else if (matchCount > 0)
                        {
                            String title = "Matches: ".green().bold() + $"{matchCount}".orange().bold();
                            if (matchCount > settings.searchLimit)
                            {
                                title += " => ".cyan() + $"{settings.searchLimit}".cyan().bold();
                            }
                            UI.Label(title, UI.ExpandWidth(false));
                        }
                        UI.Space(50);
                        UI.Label($"".green(), UI.AutoWidth());
                    }
                    UI.Space(10);

                    if (filteredBPs != null)
                    {
                        CharacterPicker.OnGUI();
                        UnitReference selected = CharacterPicker.GetSelectedCharacter();
                        var           bps      = filteredBPs;
                        if (selectedCollationIndex == 0)
                        {
                            selectedCollatedBPs = null;
                        }
                        if (selectedCollationIndex > 0)
                        {
                            if (collationChanged)
                            {
                                var key = collationKeys.ElementAt(selectedCollationIndex);

                                var selectedKey = collationKeys.ElementAt(selectedCollationIndex);

                                foreach (var group in collatedBPs)
                                {
                                    if (group.Key == selectedKey)
                                    {
                                        selectedCollatedBPs = group.Take(settings.searchLimit).ToArray();
                                    }
                                }
                                BlueprintListUI.needsLayout = true;
                            }
                            bps = selectedCollatedBPs;
                        }
                        BlueprintListUI.OnGUI(selected, bps, 0, remainingWidth, null, selectedTypeFilter);
                    }
                    UI.Space(25);
                }
            }
            return(null);
        }