Ejemplo n.º 1
0
            public static void Prefix(ModsScreen __instance)
            {
                if (_prefab == null)
                {
                    return;
                }

                _modsScreen = __instance;
                var local = Util.KInstantiateUI(_prefab);
                var panel = __instance.transform.Find("Panel");

                if (panel != null)
                {
                    var trans = local.transform;
                    trans.SetParent(panel, false);
                    trans.SetSiblingIndex(1);
                    local.SetActive(true);

                    _filterManager = new FilterManager(
                        trans.Find("LocTextInputField").GetComponent <TMP_InputField>(),
                        trans.Find("ClearButton").GetComponent <KButton>()
                        );

                    _filterManager.ConfigureButtons(_modsScreen);
                }
                else
                {
                    Debug.Log("[ModFilter] Error adding search bar to mods screen!");
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds buttons to a mod entry to move the mod around.
        /// </summary>
        /// <param name="displayedMod">The mod entry to modify.</param>
        /// <param name="instance">The Mods screen that is the parent of these entries.</param>
        internal static void ConfigureRowInstance(object displayedMod, ModsScreen instance)
        {
            if (displayedMod == null)
            {
                throw new ArgumentNullException(nameof(displayedMod));
            }
            var type = displayedMod.GetType();

            if (!PPatchTools.TryGetFieldValue(displayedMod, "mod_index", out int index))
            {
                throw new ArgumentException("Unable to get mod index");
            }
            if (!PPatchTools.TryGetFieldValue(displayedMod, "rect_transform",
                                              out Transform transform))
            {
                throw new ArgumentException("Unable to get rect transform");
            }
            var     refs = transform.gameObject.GetComponentSafe <HierarchyReferences>();
            KButton button;

            // "More mod actions"
            if (refs != null && (button = refs.GetReference <KButton>(REF_MORE)) != null)
            {
                var onAction = new ModActionDelegates(button, index, instance.gameObject);
                button.onClick += onAction.TogglePopup;
                button.gameObject.AddOrGet <ToolTip>().OnToolTip = onAction.GetDescription;
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Applied to ModsScreen to add our buttons and otherwise tweak the dialog.
 /// </summary>
 private static void BuildDisplay(ModsScreen __instance, object ___displayedMods)
 {
     // Must cast the type because ModsScreen.DisplayedMod is private
     foreach (var displayedMod in (System.Collections.IEnumerable)___displayedMods)
     {
         ModDialogs.ConfigureRowInstance(Traverse.Create(displayedMod));
     }
     __instance.GetComponent <AllModsHandler>()?.UpdateCheckedState();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Applied after OnActivate runs.
        /// </summary>
        internal static void Postfix(ModsScreen __instance)
        {
            var        entryList = __instance.entryParent;
            GameObject go;

            if (entryList != null && (go = entryList.gameObject) != null)
            {
                var vs = go.AddOrGet <VirtualScroll>();
                vs.freezeLayout = true;
                vs.Initialize();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Applied after OnActivate runs.
 /// </summary>
 internal static void Postfix(KButton ___workshopButton, ModsScreen __instance)
 {
     if (___workshopButton != null)
     {
         // Hide the "STEAM WORKSHOP" button
         var obj = ___workshopButton.gameObject;
         obj.SetActive(false);
         var parent = obj.GetParent();
         if (parent != null)
         {
             ModDialogs.AddExtraButtons(__instance.gameObject, parent);
         }
     }
 }
Ejemplo n.º 6
0
        internal static void Prefix(ModsScreen __instance, ref VirtualScroll __state)
        {
            var entryList = __instance.entryParent;

            if (entryList != null && entryList.TryGetComponent(out VirtualScroll vs))
            {
                vs.OnBuild();
                __state = vs;
            }
            else
            {
                __state = null;
            }
        }
Ejemplo n.º 7
0
        public static void ToggleAllMods(ModsScreen modsScreen, bool enable)
        {
            var modManager = Global.Instance.modManager;

            foreach (var mod in modManager.mods)
            {
                modManager.EnableMod(mod.label, enable, modsScreen);
                var toggles = modsScreen.GetComponentsInChildren <MultiToggle>();

                foreach (var toggle in toggles)
                {
                    toggle.ChangeState(enable ? 1 : 0);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds buttons to a mod entry to move the mod around.
        /// </summary>
        /// <param name="modEntry">The mod entry to modify.</param>
        /// <param name="instance">The Mods screen that is the parent of these entries.</param>
        internal static void ConfigureRowInstance(Traverse modEntry, ModsScreen instance)
        {
            int index = modEntry.GetField <int>("mod_index");
            var refs  = modEntry.GetField <RectTransform>("rect_transform")?.gameObject.
                        GetComponentSafe <HierarchyReferences>();
            KButton button;

            // "More mod actions"
            if (refs != null && (button = refs.GetReference <KButton>(REF_MORE)) != null)
            {
                var onAction = new ModActionDelegates(button, index, instance.gameObject);
                button.onClick += onAction.TogglePopup;
                button.gameObject.AddOrGet <ToolTip>().OnToolTip = onAction.GetDescription;
            }
        }
Ejemplo n.º 9
0
            public static void Postfix(ModsScreen __instance, KButton ___workshopButton)
            {
                var buttons       = ___workshopButton.transform.parent.GetComponentsInChildren <KButton>();
                var hasEnableAll  = false;
                var hasDisableAll = false;

                foreach (var button in buttons)
                {
                    if (button.name == EnableAllButtonName)
                    {
                        hasEnableAll = true;
                    }

                    if (button.name == DisableAllButtonName)
                    {
                        hasDisableAll = true;
                    }
                }

                if (!hasDisableAll)
                {
                    var disableAllButton = Util.KInstantiateUI <KButton>(___workshopButton.gameObject,
                                                                         ___workshopButton.transform.parent.gameObject);
                    disableAllButton.name = DisableAllButtonName;
                    disableAllButton.transform.GetComponentInChildren <LocText>().text = "DISABLE ALL";
                    disableAllButton.transform.SetAsFirstSibling();
                    disableAllButton.gameObject.SetActive(true);
                    disableAllButton.onClick += (() => ToggleAllMods(__instance, false));
                }

                if (!hasEnableAll)
                {
                    var enableAllButton = Util.KInstantiateUI <KButton>(___workshopButton.gameObject,
                                                                        ___workshopButton.transform.parent.gameObject);
                    enableAllButton.name = EnableAllButtonName;
                    enableAllButton.transform.GetComponentInChildren <LocText>().text = "ENABLE ALL";
                    enableAllButton.transform.SetAsFirstSibling();
                    enableAllButton.gameObject.SetActive(true);
                    enableAllButton.onClick += (() => ToggleAllMods(__instance, true));
                }
            }
Ejemplo n.º 10
0
        public void ConfigureButtons(ModsScreen modsScreen)
        {
            _search.text = "";
            _search.onValueChanged.AddListener(
                _ =>
            {
                // This shouldn't ever be null, but good idea to check
                if (modsScreen != null)
                {
                    Traverse.Create(modsScreen).Method("RebuildDisplay", typeof(object)).GetValue();
                }
            }
                );

            _clearSearchButton.onClick += () => _search.text = "";
            var tt = _clearSearchButton.GetComponent <ToolTip>();

            if (tt != null)
            {
                tt.toolTip = "Clear Search";
            }
        }
Ejemplo n.º 11
0
            public static void Postfix(object ___displayedMods, ModsScreen __instance)
            {
                foreach (var modEntry in (IEnumerable)___displayedMods)
                {
                    int      index = Traverse.Create(modEntry).Field("mod_index").GetValue <int>();
                    KMod.Mod mod   = Global.Instance.modManager.mods[index];

                    // checks if the current mod entry is this mod
                    if (index >= 0 && mod.file_source.GetRoot() == Mod.ModPath)
                    {
                        Transform transform = Traverse.Create(modEntry).Field("rect_transform").GetValue <RectTransform>();
                        if (transform != null)
                        {
                            // find an existing subscription button to copy
                            KButton subButton = null;
                            foreach (Transform child in transform)
                            {
                                if (child.gameObject.name == "ManageButton")
                                {
                                    subButton = child.gameObject.GetComponent <KButton>();
                                }
                            }

                            // copy the subscription button
                            KButton configButton = UIHelper.MakeKButton(
                                info: new UIHelper.ButtonInfo(
                                    text: "Settings",
                                    action: new System.Action(OpenModSettingsScreen),
                                    font_size: 14),
                                buttonPrefab: subButton.gameObject,
                                parent: subButton.transform.parent.gameObject,
                                index: subButton.transform.GetSiblingIndex() - 1);
                        }
                    }
                }
            }
    private void Mods()
    {
        ModsScreen modsScreen = Util.KInstantiateUI <ModsScreen>(ScreenPrefabs.Instance.modsMenu.gameObject, base.transform.parent.gameObject, false);

        modsScreen.SetBackgroundActive(true);
    }
Ejemplo n.º 13
0
 /// <summary>
 /// Applied after OnToggleClicked runs.
 /// </summary>
 internal static void Postfix(ModsScreen __instance)
 {
     __instance?.GetComponent <AllModsHandler>()?.UpdateCheckedState();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Applied to ModsScreen to hide any popups from this mod before the rows get
 /// destroyed.
 /// </summary>
 private static void HidePopups(ModsScreen __instance)
 {
     __instance.gameObject.AddOrGet <MoreModActions>().HidePopup();
 }
 public ModOrderingDragListener(ModsScreen screen, List <DisplayedMod> mods)
 {
     this.screen = screen;
     this.mods   = mods;
 }