示例#1
0
        public static void UpdateSearchResults()
        {
            if (blueprints == null)
            {
                return;
            }
            selectedCollationIndex      = 0;
            selectedBlueprint           = null;
            selectedBlueprintIndex      = -1;
            selectedCollatedBPs         = null;
            BlueprintListUI.needsLayout = true;
            if (settings.searchText.Trim().Length == 0)
            {
                ResetSearch();
            }
            var terms = settings.searchText.Split(' ').Select(s => s.ToLower()).ToHashSet();

            selectedTypeFilter = blueprintTypeFilters[settings.selectedBPTypeFilter];
            var selectedType = selectedTypeFilter.type;
            IEnumerable <BlueprintScriptableObject> bps = null;

            if (selectedTypeFilter.blueprintSource != null)
            {
                bps = selectedTypeFilter.blueprintSource();
            }
            else
            {
                bps = BlueprintExensions.BlueprintsOfType(selectedType).Where((bp) => selectedTypeFilter.filter(bp));
            }
            var filtered = new List <BlueprintScriptableObject>();

            foreach (BlueprintScriptableObject blueprint in bps)
            {
                var name = blueprint.name.ToLower();
                if (terms.All(term => name.Contains(term)))
                {
                    filtered.Add(blueprint);
                }
            }
            filteredBPs = filtered.OrderBy(bp => bp.name);
            matchCount  = filtered.Count();
            if (selectedTypeFilter.collator != null)
            {
                collatedBPs = filtered.GroupBy(selectedTypeFilter.collator).OrderBy(bp => bp.Key);
                // I could do something like this but I will leave it up to the UI when a collation is selected.
                // GetItems().GroupBy(g => g.Type).Select(s => new { Type = s.Key, LastTen = s.Take(10).ToList() });
                collationKeys = new List <String>()
                {
                    "All"
                };
                collationKeys = collationKeys.Concat(collatedBPs.Select(cbp => cbp.Key)).ToList();
            }
            filteredBPs     = filteredBPs.Take(settings.searchLimit).ToArray();
            filteredBPNames = filteredBPs.Select(b => b.name).ToArray();
            firstSearch     = false;
        }
示例#2
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++;
            }
        }
示例#3
0
        public static void UpdateSearchResults()
        {
            if (blueprints == null)
            {
                return;
            }
            selectedCollationIndex      = 0;
            selectedCollatedBPs         = null;
            BlueprintListUI.needsLayout = true;
            if (settings.searchText.Trim().Length == 0)
            {
                ResetSearch();
            }
            var searchText = settings.searchText;
            var terms      = searchText.Split(' ').Select(s => s.ToLower()).ToHashSet();

            selectedTypeFilter = blueprintTypeFilters[settings.selectedBPTypeFilter];
            var selectedType = selectedTypeFilter.type;
            IEnumerable <SimpleBlueprint> bps = null;

            if (selectedTypeFilter.blueprintSource != null)
            {
                bps = selectedTypeFilter.blueprintSource();
            }
            else
            {
                bps = from bp in BlueprintExensions.BlueprintsOfType(selectedType)
                      where selectedTypeFilter.filter(bp)
                      select bp;
            }
            var filtered = new List <SimpleBlueprint>();

            foreach (var blueprint in bps)
            {
                if (blueprint.AssetGuid.ToString().Contains(searchText) ||
                    blueprint.GetType().ToString().Contains(searchText))
                {
                    filtered.Add(blueprint);
                }
                else
                {
                    var name        = blueprint.name;
                    var displayName = blueprint.GetDisplayName();
                    var description = blueprint.GetDescription() ?? "";
                    if (terms.All(term => name.Matches(term)) ||
                        terms.All(term => displayName.Matches(term)) ||
                        settings.searchesDescriptions &&
                        (terms.All(term => description.Matches(term)) ||
                         blueprint is BlueprintItem itemBP &&
                         terms.All(term => itemBP.FlavorText.Matches(term))
                        )
                        )
                    {
                        filtered.Add(blueprint);
                    }
                }
            }
            filteredBPs = filtered.OrderBy(bp => bp.name);
            matchCount  = filtered.Count();
            UpdatePageCount();
            for (var i = 0; i < BlueprintListUI.ParamSelected.Length; i++)
            {
                BlueprintListUI.ParamSelected[i] = 0;
            }
            uncolatedMatchCount = matchCount;
            if (selectedTypeFilter.collator != null)
            {
                collatedBPs = from bp in filtered
                              from key in selectedTypeFilter.collator(bp)
                              //where selectedTypeFilter.collator(bp).Contains(key) // this line causes a mutation error
                              group bp by key into g
                              orderby g.Key.LongSortKey(), g.Key
                select g;

                _ = collatedBPs.Count();
                var keys = collatedBPs.ToList().Select(cbp => cbp.Key).ToList();
                collationKeys = new List <string> {
                    "All"
                };
                collationKeys.AddRange(keys);
            }
            else
            {
                collationKeys = null;
            }

            unpagedBPs = filteredBPs;
            UpdatePaginatedResults();
            firstSearch = false;
            UpdateCollation();
        }