/// <summary> /// Adds the Options button to the Mods screen. /// </summary> /// <param name="modEntry">The mod entry where the button should be added.</param> private static void AddModOptions(Traverse modEntry) { int index = modEntry.GetField <int>("mod_index"); var mods = Global.Instance.modManager.mods; if (index >= 0 && index < mods.Count) { var modSpec = mods[index]; var transform = modEntry.GetField <RectTransform>("rect_transform"); string modID = modSpec.label.id; if (modSpec.enabled && !string.IsNullOrEmpty(modID) && modOptions.TryGetValue( modID, out Type optionsType) && transform != null) { // Create delegate to spawn actions dialog var action = new OptionsDialog(optionsType, modSpec); new PButton("ModSettingsButton") { FlexSize = new Vector2f(0.0f, 1.0f), OnClick = action.OnModOptions, DynamicSize = true, ToolTip = DIALOG_TITLE.text.F(modSpec.title), Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(BUTTON_OPTIONS. text.ToLower()) // Move before the subscription and enable button }.SetKleiPinkStyle().AddTo(transform.gameObject, 3); } } }
/// <summary> /// Adds buttons to a mod entry to move the mod around. /// </summary> /// <param name="modEntry">The mod entry to modify.</param> internal static void ConfigureRowInstance(Traverse modEntry) { int index = modEntry.GetField <int>("mod_index"), n; var rowInstance = modEntry.GetField <RectTransform>("rect_transform")?.gameObject; var manager = Global.Instance.modManager; var mods = manager?.mods; var refs = rowInstance.GetComponentSafe <HierarchyReferences>(); if (refs != null && mods != null && index >= 0 && index < (n = mods.Count)) { // Update "Top" button var button = refs.GetReference <KButton>(REF_TOP); if (button != null) { button.onClick += () => manager.Reinsert(index, 0, manager); button.isInteractable = index > 0; button.gameObject.AddOrGet <ToolTip>().toolTip = DebugNotIncludedStrings. TOOLTIP_TOP; } // Update "Up 10" button button = refs.GetReference <KButton>(REF_UP); if (button != null) { // Actually up 9 to account for the index change after removal button.onClick += () => manager.Reinsert(index, Math.Max(0, index - 9), manager); button.isInteractable = index > 0; button.gameObject.AddOrGet <ToolTip>().toolTip = DebugNotIncludedStrings. TOOLTIP_UPONE; } // Update "Down 10" button button = refs.GetReference <KButton>(REF_DOWN); if (button != null) { button.onClick += () => manager.Reinsert(index, Math.Min(n, index + 10), manager); button.isInteractable = index < n - 1; button.gameObject.AddOrGet <ToolTip>().toolTip = DebugNotIncludedStrings. TOOLTIP_DOWNONE; } // Update "Bottom" button button = refs.GetReference <KButton>(REF_BOTTOM); if (button != null) { button.onClick += () => manager.Reinsert(index, n, manager); button.isInteractable = index < n - 1; button.gameObject.AddOrGet <ToolTip>().toolTip = DebugNotIncludedStrings. TOOLTIP_BOTTOM; } // Update the title refs.GetReference <ToolTip>("Description")?.SetSimpleTooltip(GetDescription( mods[index])); } }
/// <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; } }
/// <summary> /// Adds the mod update date to the mods menu. /// </summary> /// <param name="modEntry">The entry in the mod menu.</param> /// <param name="outdated">The mods which are out of date.</param> internal static void AddModUpdateButton(ICollection <ModToUpdate> outdated, Traverse modEntry) { int index = modEntry.GetField <int>("mod_index"); var rowInstance = modEntry.GetField <RectTransform>("rect_transform")?.gameObject; var mods = Global.Instance.modManager?.mods; if (rowInstance != null && mods != null && index >= 0 && index < mods.Count) { var mod = mods[index]; var tooltip = new StringBuilder(128); var localDate = mod.GetLocalLastModified(); var updated = ModStatus.Disabled; // A nice colorful button with a warning or checkmark icon var updButton = new PButton("UpdateMod") { Margin = BUTTON_MARGIN, SpriteSize = ICON_SIZE, MaintainSpriteAspect = true }; if (mod.label.distribution_platform == Label.DistributionPlatform.Steam) { var modUpdate = new ModToUpdate(mod); updated = AddSteamUpdate(tooltip, modUpdate, localDate, updButton); if (updated == ModStatus.Outdated) { outdated.Add(modUpdate); } } else { tooltip.AppendFormat(UISTRINGS.LOCAL_UPDATE, localDate.ToLocalTime()); } // Icon, color, and tooltip updButton.Sprite = (updated == ModStatus.UpToDate || updated == ModStatus. Disabled) ? PUITuning.Images.Checked : PUITuning.Images.GetSpriteByName( "iconWarning"); updButton.Color = (updated == ModStatus.Outdated) ? COLOR_OUTDATED : COLOR_UPDATED; updButton.ToolTip = tooltip.ToString(); // Just before subscription button, and after the Options button PButton.SetButtonEnabled(updButton.AddTo(rowInstance, 3), updated != ModStatus. Disabled); } }