Bug fixes with option screen & modifiers options

This commit is contained in:
ang-xd committed 2025-03-15 23:47:05 -04:00
1 parent 144a95fa3b
commit bf795a2e36
4 files changed
+227 -80

No files matched your search

@@ -203,7 +203,10 @@ public static class GameOptionsMenuPatch
categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor) ? Color.white : group.GroupColor.FindAlternateColor(); categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor) ? Color.white : group.GroupColor.FindAlternateColor();
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset(); categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.55f, -0.1833f, 0); categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
categoryHeaderMasked.Background.sprite.texture.wrapMode = TextureWrapMode.Clamp;
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.5f, -0.1833f, 0);
categoryHeaderMasked.Background.size = new Vector2( categoryHeaderMasked.Background.size = new Vector2(
categoryHeaderMasked.Background.size.x + 1.5f, categoryHeaderMasked.Background.size.x + 1.5f,
categoryHeaderMasked.Background.size.y); categoryHeaderMasked.Background.size.y);
+218 -77
View File
@@ -1,8 +1,10 @@
using System; using System;
using System.Linq;
using HarmonyLib; using HarmonyLib;
using MiraAPI.Modifiers; using MiraAPI.Modifiers;
using MiraAPI.PluginLoading; using MiraAPI.PluginLoading;
using MiraAPI.Utilities.Assets; using MiraAPI.Utilities.Assets;
using Reactor.Utilities;
using Reactor.Utilities.Extensions; using Reactor.Utilities.Extensions;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
@@ -22,6 +24,8 @@ internal static class GameSettingMenuPatches
private static TextMeshPro? _text; private static TextMeshPro? _text;
private static Vector3 _roleBtnOgPos; private static Vector3 _roleBtnOgPos;
private static Vector3 _smallRoleBtnOgPos;
private static Vector3 _modifierBtnOgPos;
private static GameOptionsMenu? _modifiersTab; private static GameOptionsMenu? _modifiersTab;
private static PassiveButton? _modifiersButton; private static PassiveButton? _modifiersButton;
@@ -33,9 +37,20 @@ internal static class GameSettingMenuPatches
{ {
if ((previewOnly && Controller.currentTouchType == Controller.TouchType.Joystick) || !previewOnly) if ((previewOnly && Controller.currentTouchType == Controller.TouchType.Joystick) || !previewOnly)
{ {
if (_modifiersTab) _modifiersTab?.gameObject.SetActive(tabNum == 3); if (_modifiersTab) _modifiersTab!.gameObject.SetActive(tabNum == 3);
_modifiersButton?.SelectButton(tabNum == 3); _modifiersButton?.SelectButton(tabNum == 3);
_smallRolesButton?.SelectButton(tabNum == 2); _smallRolesButton?.SelectButton(tabNum == 2);
if (tabNum == 3)
{
if (__instance.RoleSettingsButton.gameObject.active)
{
__instance.RoleSettingsButton.SelectButton(true);
}
else
{
_modifiersButton?.SelectButton(true);
}
}
} }
if (previewOnly) if (previewOnly)
@@ -45,6 +60,17 @@ internal static class GameSettingMenuPatches
_modifiersButton?.SelectButton(tabNum == 3); _modifiersButton?.SelectButton(tabNum == 3);
_smallRolesButton?.SelectButton(tabNum == 2); _smallRolesButton?.SelectButton(tabNum == 2);
if (tabNum != 3) return;
if (__instance.RoleSettingsButton.gameObject.active)
{
__instance.RoleSettingsButton.SelectButton(true);
}
else
{
_modifiersButton?.SelectButton(true);
}
} }
/// <summary> /// <summary>
@@ -117,6 +143,7 @@ internal static class GameSettingMenuPatches
_modifiersTab.name = "MODIFIERS TAB"; _modifiersTab.name = "MODIFIERS TAB";
// create button for modifiers // create button for modifiers
__instance.RoleSettingsButton.buttonText.gameObject.GetComponent<TextTranslatorTMP>().Destroy();
__instance.RoleSettingsButton.gameObject.SetActive(false); __instance.RoleSettingsButton.gameObject.SetActive(false);
_smallRolesButton = Object.Instantiate( _smallRolesButton = Object.Instantiate(
__instance.RoleSettingsButton, __instance.RoleSettingsButton,
@@ -137,6 +164,8 @@ internal static class GameSettingMenuPatches
__instance.ChangeTab(2, true); __instance.ChangeTab(2, true);
})); }));
_smallRoleBtnOgPos = _smallRolesButton.transform.localPosition;
var roleText = _smallRolesButton.buttonText; var roleText = _smallRolesButton.buttonText;
roleText.text = "Roles"; roleText.text = "Roles";
roleText.GetComponent<TextTranslatorTMP>().Destroy(); roleText.GetComponent<TextTranslatorTMP>().Destroy();
@@ -178,9 +207,45 @@ internal static class GameSettingMenuPatches
_modifiersButton.transform.localPosition = pos; _modifiersButton.transform.localPosition = pos;
_modifiersButton.name = "ModifiersButton"; _modifiersButton.name = "ModifiersButton";
_modifierBtnOgPos = _modifiersButton.transform.localPosition;
UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab); UpdateText(__instance, __instance.GameSettingsTab, __instance.RoleSettingsTab);
} }
private static void ChangeRoleSettingButton(bool replace, GameSettingMenu __instance)
{
__instance.RoleSettingsButton.OnClick = new ButtonClickedEvent();
__instance.RoleSettingsButton.OnMouseOver = new UnityEvent();
if (replace)
{
__instance.RoleSettingsButton.buttonText.text = "Modifiers Settings";
__instance.RoleSettingsButton.OnClick.AddListener(
(UnityAction)(() =>
{
__instance.ChangeTab(3, false);
}));
__instance.RoleSettingsButton.OnMouseOver.AddListener(
(UnityAction)(() =>
{
__instance.ChangeTab(3, true);
}));
}
else
{
__instance.RoleSettingsButton.buttonText.text = "Roles Settings";
__instance.RoleSettingsButton.OnClick.AddListener(
(UnityAction)(() =>
{
__instance.ChangeTab(2, false);
}));
__instance.RoleSettingsButton.OnMouseOver.AddListener(
(UnityAction)(() =>
{
__instance.ChangeTab(2, true);
}));
}
}
private static void UpdateText(GameSettingMenu menu, GameOptionsMenu settings, RolesSettingsMenu roles) private static void UpdateText(GameSettingMenu menu, GameOptionsMenu settings, RolesSettingsMenu roles)
{ {
if (_text is not null && SelectedModIdx == 0) if (_text is not null && SelectedModIdx == 0)
@@ -197,106 +262,182 @@ internal static class GameSettingMenuPatches
_text.text = name[..Math.Min(name.Length, 25)]; _text.text = name[..Math.Min(name.Length, 25)];
} }
_modifiersButton.gameObject.SetActive(false); bool replaceWithModifiers = true;
_smallRolesButton.gameObject.SetActive(false); _smallRolesButton!.transform.localPosition = _smallRoleBtnOgPos;
menu.RoleSettingsButton.gameObject.SetActive(false); _modifiersButton!.transform.localPosition = _modifierBtnOgPos;
if (SelectedModIdx != 0 && menu.RoleSettingsButton.transform.localPosition = _roleBtnOgPos;
SelectedMod?.OptionGroups.Exists(x => x.ShowInModifiersMenu || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true) == true)
if (SelectedModIdx != 0)
{ {
var modHasRoles = SelectedMod!.CustomRoles.Count != 0;
var modHasModifiers = SelectedMod.OptionGroups.Exists(x => x.ShowInModifiersMenu || x.OptionableType?.IsAssignableTo(typeof(BaseModifier)) == true);
var modHasOptions = SelectedMod.OptionGroups.Exists(x => x.OptionableType == null && !x.ShowInModifiersMenu);
_modifiersButton.gameObject.SetActive(true); _modifiersButton.gameObject.SetActive(true);
_smallRolesButton.gameObject.SetActive(true); _smallRolesButton.gameObject.SetActive(true);
menu.GameSettingsButton.gameObject.SetActive(true);
menu.RoleSettingsButton.gameObject.SetActive(false);
// If there are no registered custom roles in the selected mod, hide the button.
if (!modHasRoles)
{
_smallRolesButton.gameObject.SetActive(false);
if (roles.gameObject.active)
{
menu.ChangeTab(0, false);
}
// If the mod has modifiers, we can disable the smaller modifier button and enable the bigger one.
if (modHasModifiers)
{
_modifiersButton.gameObject.SetActive(false);
menu.RoleSettingsButton.gameObject.SetActive(true);
if (_modifiersTab!.gameObject.active)
{
menu.RoleSettingsButton.SelectButton(true);
}
}
}
// If there are no modifiers in the selected mod, hide the modifiers button.
if (!modHasModifiers)
{
replaceWithModifiers = false;
_modifiersButton.gameObject.SetActive(false);
if (_modifiersTab!.gameObject.active)
{
menu.ChangeTab(0, false);
}
// If the mod has roles, we can enable the bigger role button and disable the small one.
if (modHasRoles)
{
menu.RoleSettingsButton.gameObject.SetActive(true);
_smallRolesButton.gameObject.SetActive(false);
}
}
// If there are no custom game options registered (that aren't modifier options), hide game settings button.
if (!modHasOptions)
{
menu.GameSettingsButton.gameObject.SetActive(false);
if (settings.gameObject.active)
{
menu.ChangeTab(0, false);
}
// If the mod has roles and modifiers, we can move their buttons to the game settings button position, since nothing is there.
if (menu.RoleSettingsButton.gameObject.active)
{
menu.RoleSettingsButton.transform.localPosition = menu.GameSettingsButton.transform.localPosition;
}
else if (_modifiersButton.gameObject.active && _smallRolesButton.gameObject.active)
{
_modifiersButton.transform.localPosition = new Vector3(
_modifiersButton.transform.localPosition.x,
menu.GameSettingsButton.transform.localPosition.y,
_modifiersButton.transform.localPosition.z);
_smallRolesButton.transform.localPosition = new Vector3(
_smallRolesButton.transform.localPosition.x,
menu.GameSettingsButton.transform.localPosition.y,
_smallRolesButton.transform.localPosition.z);
}
}
} }
else else
{ {
_modifiersButton.gameObject.SetActive(false);
_smallRolesButton.gameObject.SetActive(false);
menu.RoleSettingsButton.gameObject.SetActive(true); menu.RoleSettingsButton.gameObject.SetActive(true);
if (SelectedModIdx == 0 && _modifiersTab.gameObject.active) menu.GameSettingsButton.gameObject.SetActive(true);
replaceWithModifiers = false;
if (_modifiersTab!.gameObject.active)
{ {
menu.ChangeTab(0, false); menu.ChangeTab(0, false);
} }
} }
//menu.RoleSettingsButton.transform.localPosition = _roleBtnOgPos; if (menu.RoleSettingsButton.gameObject.active)
//menu.GameSettingsButton.gameObject.SetActive(true);
//menu.RoleSettingsButton.gameObject.SetActive(true);
// TODO: reimplement this
/*
if (SelectedModIdx != 0)
{ {
if (SelectedMod?.Options.Where(x=>x.AdvancedRole==null).ToList().Count == 0) ChangeRoleSettingButton(replaceWithModifiers, menu);
{
menu.GameSettingsButton.gameObject.SetActive(false);
}
if (SelectedMod?.CustomRoles.Count == 0)
{
menu.RoleSettingsButton.gameObject.SetActive(false);
}
if (!menu.GameSettingsButton.gameObject.active && menu.RoleSettingsButton.gameObject.active)
{
menu.RoleSettingsButton.transform.localPosition = menu.GameSettingsButton.transform.localPosition;
}
}*/
if (roles.roleChances != null && SelectedMod != null && SelectedMod.CustomRoles.Count != 0)
{
if (roles.advancedSettingChildren is not null)
{
foreach (var child in roles.advancedSettingChildren)
{
child.gameObject.DestroyImmediate();
}
roles.advancedSettingChildren.Clear();
roles.advancedSettingChildren = null;
}
foreach (var header in roles.RoleChancesSettings.transform
.GetComponentsInChildren<CategoryHeaderEditRole>())
{
header.gameObject.DestroyImmediate();
}
foreach (var roleChance in roles.roleChances)
{
roleChance.gameObject.DestroyImmediate();
}
roles.roleChances.Clear();
roles.AdvancedRolesSettings.gameObject.SetActive(false);
roles.RoleChancesSettings.gameObject.SetActive(true);
roles.SetQuotaTab();
roles.scrollBar.ScrollToTop();
} }
if (settings.Children != null && SelectedMod?.OptionGroups.Count != 0) CleanupTab(settings, roles);
}
private static void ClearOptions(Il2CppSystem.Collections.Generic.List<OptionBehaviour> options)
{
foreach (var child in options)
{ {
foreach (var child in settings.Children) if (child.TryCast<GameOptionsMapPicker>() || !child.gameObject)
{ {
if (child.TryCast<GameOptionsMapPicker>()) continue;
{ }
continue; child.gameObject.DestroyImmediate();
} }
options.Clear();
}
if (!child.gameObject) private static void CleanupTab(GameOptionsMenu settings, RolesSettingsMenu roles)
{ {
continue; void CleanupRoleSettings(RolesSettingsMenu rolesMenu)
} {
if (rolesMenu.advancedSettingChildren != null)
child.gameObject.DestroyImmediate(); {
ClearOptions(rolesMenu.advancedSettingChildren);
rolesMenu.advancedSettingChildren = null;
} }
foreach (var header in settings.settingsContainer.GetComponentsInChildren<CategoryHeaderMasked>()) rolesMenu.RoleChancesSettings
.transform
.GetComponentsInChildren<CategoryHeaderEditRole>()
.ToList()
.ForEach(header => header.gameObject.DestroyImmediate());
foreach (var role in rolesMenu.roleChances)
{ {
header.gameObject.DestroyImmediate(); role.gameObject.DestroyImmediate();
} }
rolesMenu.roleChances?.Clear();
settings.Children.Clear(); rolesMenu.AdvancedRolesSettings.gameObject.SetActive(false);
settings.Children = null; rolesMenu.RoleChancesSettings.gameObject.SetActive(true);
rolesMenu.SetQuotaTab();
rolesMenu.scrollBar.ScrollToTop();
}
settings.Initialize(); void CleanupSettings(GameOptionsMenu gameOptMenu)
settings.scrollBar.ScrollToTop(); {
ClearOptions(gameOptMenu.Children);
gameOptMenu.Children = null;
gameOptMenu.settingsContainer
.GetComponentsInChildren<CategoryHeaderMasked>()
.ToList()
.ForEach(header => header.gameObject.DestroyImmediate());
gameOptMenu.Initialize();
gameOptMenu.scrollBar.ScrollToTop();
}
if (roles.roleChances != null && SelectedMod?.CustomRoles.Count > 0)
{
CleanupRoleSettings(roles);
}
if (settings.Children != null && SelectedMod?.OptionGroups.Count > 0)
{
CleanupSettings(settings);
}
if (_modifiersTab?.Children?.Count > 0)
{
CleanupSettings(_modifiersTab);
} }
} }
} }
@@ -128,7 +128,10 @@ public static class RoleSettingMenuPatches
countLabel.Destroy(); countLabel.Destroy();
categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset(); categoryHeaderMasked.Background.sprite = MiraAssets.CategoryHeader.LoadAsset();
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.55f, -0.1833f, 0); categoryHeaderMasked.Background.sprite.texture.filterMode = FilterMode.Bilinear;
categoryHeaderMasked.Background.sprite.texture.wrapMode = TextureWrapMode.Clamp;
categoryHeaderMasked.Background.transform.localPosition = new Vector3(0.5f, -0.1833f, 0);
switch (name) switch (name)
{ {
@@ -243,7 +246,7 @@ public static class RoleSettingMenuPatches
[HarmonyPatch(nameof(RolesSettingsMenu.OpenChancesTab))] [HarmonyPatch(nameof(RolesSettingsMenu.OpenChancesTab))]
public static void OpenChancesTabPostfix(RolesSettingsMenu __instance) public static void OpenChancesTabPostfix(RolesSettingsMenu __instance)
{ {
if (GameSettingMenuPatches.SelectedModIdx == 0) if (GameSettingMenuPatches.SelectedModIdx == 0 || !__instance.scrollBar)
{ {
return; return;
} }
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 872 B