Exemplo n.º 1
0
    public static UnitReference create(Unit unit)
    {
        UnitReference re = new UnitReference();

        re.setUnit(unit);
        return(re);
    }
Exemplo n.º 2
0
        public static string GetDescription(this SimpleBlueprint bp)
        // borrowed shamelessly and enhanced from Bag of Tricks https://www.nexusmods.com/pathfinderkingmaker/mods/26, which is under the MIT License
        {
            try {
                // avoid exceptions on known broken items
                var guid = bp.AssetGuid;
                if (guid == "b60252a8ae028ba498340199f48ead67" || guid == "fb379e61500421143b52c739823b4082")
                {
                    return(null);
                }
                var associatedBlueprint = bp as IUIDataProvider;
                return(associatedBlueprint?.Description.StripHTML());

                // Why did BoT do this instead of the above which is what MechanicsContext.SelectUIData() does for description
#if false
                var description = bp.Des
                                  UnitReference mainChar = Game.Instance.Player.MainCharacter;
                if (mainChar == null)
                {
                    return("");
                }
                MechanicsContext context = new MechanicsContext((UnitEntityData)null, mainChar.Value.Descriptor, bp, (MechanicsContext)null, (TargetWrapper)null);
                return(context?.SelectUIData(UIDataType.Description)?.Description ?? "");
#endif
            }
            catch (Exception e) {
                Console.Write($"{e}");
#if DEBUG
                return("ERROR".red().bold() + $": caught exception {e}");
#else
                return("");
#endif
            }
        }
Exemplo n.º 3
0
        public static string GetDescription(this BlueprintScriptableObject bpObejct)
        // borrowed shamelessly and enchanced from Bag of Tricks https://www.nexusmods.com/pathfinderkingmaker/mods/26, which is under the MIT License
        {
            try {
                UnitReference mainChar = Game.Instance.Player.MainCharacter;
                if (mainChar == null)
                {
                    return("");
                }
                MechanicsContext context = new MechanicsContext((UnitEntityData)null, mainChar.Value.Descriptor, bpObejct, (MechanicsContext)null, (TargetWrapper)null);
                return(context?.SelectUIData(UIDataType.Description)?.Description ?? "");
            }
            catch (Exception e) {
                Console.Write($"{e}");
#if DEBUG
                return("ERROR".red().bold() + $": caught exception {e}");
#else
                return("");
#endif
            }
        }
        internal static bool Prefix(UnitDescriptor __instance, UnitEntityData master, ref UnitReference ___m_Pet)
        {
            if (__instance.Master == null || master == null || __instance.Master == (UnitEntityData) new UnitReference())
            {
                return(true);
            }
            Harmony12.Traverse.Create(master.Descriptor).Field("m_Pet").SetValue(null);

            return(true);
        }
Exemplo n.º 5
0
        public static IEnumerable OnGUI()
        {
            if (blueprints == null)
            {
                blueprints = BlueprintLoader.Shared.GetBlueprints();
                if (blueprints != null)
                {
                    UpdateSearchResults();
                }
            }
            // Stackable browser
            using (HorizontalScope(Width(350))) {
                var remainingWidth = ummWidth;
                // First column - Type Selection Grid
                using (VerticalScope(GUI.skin.box)) {
                    ActionSelectionGrid(ref settings.selectedBPTypeFilter,
                                        blueprintTypeFilters.Select(tf => tf.name).ToArray(),
                                        1,
                                        (selected) => { UpdateSearchResults(); },
                                        buttonStyle,
                                        Width(200));
                }
                remainingWidth -= 350;
                var collationChanged = false;
                if (collatedBPs != null)
                {
                    using (VerticalScope(GUI.skin.box)) {
                        var selectedKey = collationKeys.ElementAt(selectedCollationIndex);
                        if (VPicker("Categories", ref selectedKey, collationKeys, null, s => s, ref collationSearchText, Width(300)))
                        {
                            collationChanged = true; BlueprintListUI.needsLayout = true;
                        }
                        if (selectedKey != null)
                        {
                            selectedCollationIndex = collationKeys.IndexOf(selectedKey);
                        }

#if false
                        UI.ActionSelectionGrid(ref selectedCollationIndex, collationKeys.ToArray(),
                                               1,
                                               (selected) => { collationChanged = true; BlueprintListUI.needsLayout = true; },
                                               UI.buttonStyle,
                                               UI.Width(200));
#endif
                    }
                    remainingWidth -= 450;
                }

                // Section Column  - Main Area
                using (VerticalScope(MinWidth(remainingWidth))) {
                    // Search Field and modifiers
                    using (HorizontalScope()) {
                        ActionTextField(
                            ref settings.searchText,
                            "searhText",
                            (text) => { },
                            () => UpdateSearchResults(),
                            Width(400));
                        50.space();
                        Label("Limit", AutoWidth());
                        15.space();
                        ActionIntTextField(
                            ref settings.searchLimit,
                            "searchLimit",
                            (limit) => { },
                            () => UpdateSearchResults(),
                            Width(75));
                        if (settings.searchLimit > 1000)
                        {
                            settings.searchLimit = 1000;
                        }
                        25.space();
                        if (Toggle("Search Descriptions", ref settings.searchesDescriptions, AutoWidth()))
                        {
                            UpdateSearchResults();
                        }
                        25.space();
                        if (Toggle("Attributes", ref settings.showAttributes, AutoWidth()))
                        {
                            UpdateSearchResults();
                        }
                        25.space();
                        Toggle("Show GUIDs", ref settings.showAssetIDs, AutoWidth());
                        25.space();
                        Toggle("Components", ref settings.showComponents, AutoWidth());
                        25.space();
                        Toggle("Show Display & Internal Names", ref settings.showDisplayAndInternalNames, AutoWidth());
                    }
                    // Search Button and Results Summary
                    using (HorizontalScope()) {
                        ActionButton("Search", () => {
                            UpdateSearchResults();
                        }, AutoWidth());
                        Space(25);
                        if (firstSearch)
                        {
                            Label("please note the first search may take a few seconds.".green(), AutoWidth());
                        }
                        else if (matchCount > 0)
                        {
                            var title = "Matches: ".green().bold() + $"{matchCount}".orange().bold();
                            if (matchCount > settings.searchLimit)
                            {
                                title += " => ".cyan() + $"{settings.searchLimit}".cyan().bold();
                            }
                            Label(title, ExpandWidth(false));
                        }
                        Space(130);
                        Label($"Page: ".green() + $"{Math.Min(currentPage + 1, pageCount + 1)}".orange() + " / " + $"{pageCount + 1}".cyan(), AutoWidth());
                        ActionButton("-", () => {
                            currentPage = Math.Max(currentPage -= 1, 0);
                            UpdatePaginatedResults();
                        }, AutoWidth());
                        ActionButton("+", () => {
                            currentPage = Math.Min(currentPage += 1, pageCount);
                            UpdatePaginatedResults();
                        }, AutoWidth());
                        Space(25);
                        var pageNum = currentPage + 1;
                        if (Slider(ref pageNum, 1, pageCount + 1, 1))
                        {
                            UpdatePaginatedResults();
                        }
                        currentPage = pageNum - 1;
                    }
                    Space(10);

                    if (filteredBPs != null)
                    {
                        CharacterPicker.OnGUI();
                        UnitReference selected = CharacterPicker.GetSelectedCharacter();
                        var           bps      = filteredBPs;
                        if (selectedCollationIndex == 0)
                        {
                            selectedCollatedBPs = null;
                            matchCount          = uncolatedMatchCount;
                            UpdatePageCount();
                        }
                        if (selectedCollationIndex > 0)
                        {
                            if (collationChanged)
                            {
                                UpdateCollation();
                            }
                            bps = selectedCollatedBPs;
                        }
                        BlueprintListUI.OnGUI(selected, bps, 0, remainingWidth, null, selectedTypeFilter, (keys) => {
                            if (keys.Length > 0)
                            {
                                var changed = false;
                                //var bpTypeName = keys[0];
                                //var newTypeFilterIndex = blueprintTypeFilters.FindIndex(f => f.type.Name == bpTypeName);
                                //if (newTypeFilterIndex >= 0) {
                                //    settings.selectedBPTypeFilter = newTypeFilterIndex;
                                //    changed = true;
                                //}
                                if (keys.Length > 1)
                                {
                                    var collationKey      = keys[1];
                                    var newCollationIndex = collationKeys.FindIndex(ck => ck == collationKey);
                                    if (newCollationIndex >= 0)
                                    {
                                        selectedCollationIndex = newCollationIndex;
                                        UpdateCollation();
                                    }
                                }
                                if (changed)
                                {
                                    UpdateSearchResults();
                                }
                            }
                        }).ForEach(action => action());
                    }
                    Space(25);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Adds an unconditionally compiled source code element to a sequence of conditionally compiled elements.
 /// </summary>
 /// <param name="sequence">The sequence append to</param>
 /// <param name="element">The element to append</param>
 public static void Add(this RepeatedField <ConditionalUnitReference> sequence, UnitReference element) => sequence.Add(new ConditionalUnitReference()
 {
     Element = element
 });
Exemplo n.º 7
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);
        }
        public UnitReference GetUnitReference(Actor target)
        {
            UnitReference reference = new UnitReference(target.unitSpawn.unitID);

            return(reference);
        }
Exemplo n.º 9
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);
        }