mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Merge branch 'wiki-improv' of https://github.com/idkimneil/MiraAPI into pr/111
This commit is contained in:
commit
63c411754c
3 files changed
+139
-35
No files matched your search
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.GameOptions;
|
using MiraAPI.GameOptions;
|
||||||
using MiraAPI.Networking;
|
using MiraAPI.Networking;
|
||||||
|
using MiraAPI.Patches;
|
||||||
using MiraAPI.Patches.GameModes;
|
using MiraAPI.Patches.GameModes;
|
||||||
using MiraAPI.Patches.Options;
|
using MiraAPI.Patches.Options;
|
||||||
using MiraAPI.Translation;
|
using MiraAPI.Translation;
|
||||||
@@ -128,6 +129,9 @@ public static class GameModeOption
|
|||||||
MenuState.Instance.QueuedRoleMenuRefresh[roleMenu.Key] = true;
|
MenuState.Instance.QueuedRoleMenuRefresh[roleMenu.Key] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameOptionsMenuPatch.RefreshForGameMode();
|
||||||
|
RoleGuidePatches.RefreshSettingsForGameMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: could make Values a dict of AbstractGameMode too
|
// TODO: could make Values a dict of AbstractGameMode too
|
||||||
@@ -143,12 +147,6 @@ public static class GameModeOption
|
|||||||
Info($"Game mode changed to {option.GetInt()}");
|
Info($"Game mode changed to {option.GetInt()}");
|
||||||
RpcSyncGamemode(PlayerControl.LocalPlayer, option.GetInt());
|
RpcSyncGamemode(PlayerControl.LocalPlayer, option.GetInt());
|
||||||
|
|
||||||
if (GameSettingMenu.Instance && CustomGameModeManager.ActiveMode != null)
|
|
||||||
{
|
|
||||||
GameOptionsMenuPatch.ToggleGamemodeOptions(CustomGameModeManager.ActiveMode, __instance);
|
|
||||||
GameSettingMenu.Instance.RoleSettingsButton.gameObject.SetActive(CustomGameModeManager.ActiveMode.ShowNormalRoleSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,66 @@ internal static class GameOptionsMenuPatch
|
|||||||
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
instance.scrollBar.SetYBoundsMax(-num - 1.65f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void RefreshForGameMode()
|
||||||
|
{
|
||||||
|
if (CustomGameModeManager.ActiveMode == null ||
|
||||||
|
!GameSettingMenu.Instance ||
|
||||||
|
!GameSettingMenu.Instance.GameSettingsTab ||
|
||||||
|
!MenuState.Instance ||
|
||||||
|
MenuState.Instance.CurrentModIdx != 0 ||
|
||||||
|
GameModeGroups.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToggleGamemodeOptions(CustomGameModeManager.ActiveMode, GameSettingMenu.Instance.GameSettingsTab);
|
||||||
|
GameSettingMenu.Instance.RoleSettingsButton.gameObject.SetActive(
|
||||||
|
CustomGameModeManager.ActiveMode.ShowNormalRoleSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static List<KeyValuePair<string, string>> GetActiveGameSettingsRows(Func<bool, string> formatBool)
|
||||||
|
{
|
||||||
|
var menu = GameSettingMenu.Instance ? GameSettingMenu.Instance.GameSettingsTab : null;
|
||||||
|
if (!menu || menu.Children == null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var rows = new List<KeyValuePair<string, string>>();
|
||||||
|
foreach (var option in menu.Children)
|
||||||
|
{
|
||||||
|
if (!option || !option!.gameObject.activeInHierarchy ||
|
||||||
|
option == menu.MapPicker ||
|
||||||
|
(GameModeOption.OptionBehaviour && option == GameModeOption.OptionBehaviour) ||
|
||||||
|
!option.Data)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var title = option switch
|
||||||
|
{
|
||||||
|
ToggleOption toggle => toggle.TitleText.text,
|
||||||
|
NumberOption number => number.TitleText.text,
|
||||||
|
StringOption str => str.TitleText.text,
|
||||||
|
PlayerOption player => player.TitleText.text,
|
||||||
|
_ => TranslationController.Instance.GetString(option.Data.Title),
|
||||||
|
};
|
||||||
|
|
||||||
|
var value = option switch
|
||||||
|
{
|
||||||
|
ToggleOption toggle => formatBool(toggle.GetBool()),
|
||||||
|
NumberOption number => number.ValueText.text,
|
||||||
|
StringOption str => str.ValueText.text,
|
||||||
|
PlayerOption player => player.ValueText.text,
|
||||||
|
_ => option.Data.GetValueString(option.GetFloat()),
|
||||||
|
};
|
||||||
|
|
||||||
|
rows.Add(new KeyValuePair<string, string>(title, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
private static void CreateSettings(GameOptionsMenu instance, Transform container)
|
private static void CreateSettings(GameOptionsMenu instance, Transform container)
|
||||||
{
|
{
|
||||||
var num = 0.713f;
|
var num = 0.713f;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Innersloth.Assets;
|
|||||||
using MiraAPI.LocalSettings;
|
using MiraAPI.LocalSettings;
|
||||||
using MiraAPI.Modifiers;
|
using MiraAPI.Modifiers;
|
||||||
using MiraAPI.Modifiers.Types;
|
using MiraAPI.Modifiers.Types;
|
||||||
|
using MiraAPI.Patches.Options;
|
||||||
using MiraAPI.Roles;
|
using MiraAPI.Roles;
|
||||||
using MiraAPI.Translation;
|
using MiraAPI.Translation;
|
||||||
using MiraAPI.Utilities;
|
using MiraAPI.Utilities;
|
||||||
@@ -1807,26 +1808,19 @@ public static class RoleGuidePatches
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var vanillaTab = guide.settingsTabs[SettingsTabIndex];
|
||||||
|
vanillaTab.SetActive(false);
|
||||||
|
var vanillaEntries = GameOptionsMenuPatch.GetActiveGameSettingsRows(guide.GetBoolString);
|
||||||
|
if (vanillaEntries.Count == 0)
|
||||||
|
{
|
||||||
|
vanillaEntries = BuildVanillaSettingsEntries(guide);
|
||||||
|
}
|
||||||
_settingsPages = GuideOptionPages.BuildPages(guide.GetBoolString);
|
_settingsPages = GuideOptionPages.BuildPages(guide.GetBoolString);
|
||||||
if (_settingsPage > _settingsPages.Count)
|
if (_settingsPage > _settingsPages.Count)
|
||||||
{
|
{
|
||||||
_settingsPage = 0;
|
_settingsPage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var vanillaTab = guide.settingsTabs[SettingsTabIndex];
|
|
||||||
|
|
||||||
// Keep the vanilla tab when there are no MiraAPI settings pages.
|
|
||||||
if (_settingsPages.Count == 0)
|
|
||||||
{
|
|
||||||
_settingsSearching = false;
|
|
||||||
_settingsScroller?.gameObject.SetActive(false);
|
|
||||||
_settingsNoResults?.SetActive(false);
|
|
||||||
vanillaTab.SetActive(true);
|
|
||||||
RestoreSortButtons();
|
|
||||||
UpdateSettingsTitle();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var searchText = GetSearchText().Trim();
|
var searchText = GetSearchText().Trim();
|
||||||
_settingsSearching = searchText.Length > 0;
|
_settingsSearching = searchText.Length > 0;
|
||||||
|
|
||||||
@@ -1838,9 +1832,7 @@ public static class RoleGuidePatches
|
|||||||
}
|
}
|
||||||
else if (_settingsPage == 0)
|
else if (_settingsPage == 0)
|
||||||
{
|
{
|
||||||
_settingsScroller?.gameObject.SetActive(false);
|
ShowSettingsRows(vanillaEntries, scrollToTop);
|
||||||
_settingsNoResults?.SetActive(false);
|
|
||||||
vanillaTab.SetActive(true);
|
|
||||||
RepurposeSortButtons(true);
|
RepurposeSortButtons(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1853,7 +1845,62 @@ public static class RoleGuidePatches
|
|||||||
UpdateSettingsTitle();
|
UpdateSettingsTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void RefreshSettingsForGameMode()
|
||||||
|
{
|
||||||
|
if (IsSettingsTabActive)
|
||||||
|
{
|
||||||
|
RefreshSettingsTab(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<KeyValuePair<string, string>> BuildVanillaSettingsEntries(MatchInfoGuide guide)
|
||||||
|
{
|
||||||
|
foreach (var setting in guide.NormalModeSettings.ToArray())
|
||||||
|
{
|
||||||
|
if (setting)
|
||||||
|
{
|
||||||
|
setting.Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guide.NormalModeSettings.Clear();
|
||||||
|
guide.CreateNormalModeSettings();
|
||||||
|
|
||||||
|
var entries = new List<KeyValuePair<string, string>>(guide.NormalModeSettings.Count);
|
||||||
|
foreach (var setting in guide.NormalModeSettings)
|
||||||
|
{
|
||||||
|
if (!setting)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var texts = setting.GetComponentsInChildren<TextMeshPro>(true);
|
||||||
|
if (texts.Length < 2)
|
||||||
|
{
|
||||||
|
Warning($"Could not read vanilla settings row '{setting.name}'.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entries.Add(new KeyValuePair<string, string>(texts[0].text, texts[1].text));
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
private static void ShowSettingsEntries(IReadOnlyList<GuideOptionEntry> entries, bool showGroup, bool scrollToTop)
|
private static void ShowSettingsEntries(IReadOnlyList<GuideOptionEntry> entries, bool showGroup, bool scrollToTop)
|
||||||
|
{
|
||||||
|
var rows = new List<KeyValuePair<string, string>>(entries.Count);
|
||||||
|
foreach (var entry in entries)
|
||||||
|
{
|
||||||
|
var label = showGroup ? $"<size=60%>{entry.GroupName}</size>\n{entry.Title}" : entry.Title;
|
||||||
|
rows.Add(new KeyValuePair<string, string>(label, entry.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowSettingsRows(rows, scrollToTop);
|
||||||
|
_settingsNoResults?.SetActive(entries.Count == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ShowSettingsRows(IReadOnlyList<KeyValuePair<string, string>> rows, bool scrollToTop)
|
||||||
{
|
{
|
||||||
var guide = MatchInfoGuide.Instance;
|
var guide = MatchInfoGuide.Instance;
|
||||||
if (_settingsScroller == null || !guide || !guide.MatchInfoRolePanelPrefab)
|
if (_settingsScroller == null || !guide || !guide.MatchInfoRolePanelPrefab)
|
||||||
@@ -1870,16 +1917,9 @@ public static class RoleGuidePatches
|
|||||||
_settingsPageObject = null;
|
_settingsPageObject = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rows = new List<KeyValuePair<string, string>>(entries.Count);
|
|
||||||
foreach (var entry in entries)
|
|
||||||
{
|
|
||||||
var label = showGroup ? $"<size=60%>{entry.GroupName}</size>\n{entry.Title}" : entry.Title;
|
|
||||||
rows.Add(new KeyValuePair<string, string>(label, entry.Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
_settingsScroller.gameObject.SetActive(true);
|
_settingsScroller.gameObject.SetActive(true);
|
||||||
_settingsPageObject = Helpers.CreateAdvancedSettingsPage(guide, _settingsScroller, rows);
|
_settingsPageObject = Helpers.CreateAdvancedSettingsPage(guide, _settingsScroller, rows);
|
||||||
_settingsNoResults?.SetActive(entries.Count == 0);
|
_settingsNoResults?.SetActive(rows.Count == 0);
|
||||||
if (scrollToTop)
|
if (scrollToTop)
|
||||||
{
|
{
|
||||||
_settingsScroller.ScrollToTop();
|
_settingsScroller.ScrollToTop();
|
||||||
@@ -1889,20 +1929,26 @@ public static class RoleGuidePatches
|
|||||||
private static string GetSettingsTitle()
|
private static string GetSettingsTitle()
|
||||||
{
|
{
|
||||||
var baseTitle = MiraLocaleManager.Get("MiraApi.Wiki.SettingsTab");
|
var baseTitle = MiraLocaleManager.Get("MiraApi.Wiki.SettingsTab");
|
||||||
if (!_uiInitialized || _settingsPages.Count == 0)
|
if (!_uiInitialized)
|
||||||
{
|
{
|
||||||
return baseTitle;
|
return baseTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_settingsPage == 0 || _settingsPages.Count == 0)
|
||||||
|
{
|
||||||
|
var vanillaTitle = $"{MiraLocaleManager.Get("MiraApi.Wiki.VanillaSettings", "Vanilla")} Settings";
|
||||||
|
return _settingsPages.Count == 0
|
||||||
|
? vanillaTitle
|
||||||
|
: $"{vanillaTitle} ({_settingsPage + 1}/{_settingsPages.Count + 1})";
|
||||||
|
}
|
||||||
|
|
||||||
if (_settingsSearching)
|
if (_settingsSearching)
|
||||||
{
|
{
|
||||||
return $"{baseTitle}: {MiraLocaleManager.Get("MiraApi.Wiki.SearchResults", "Search Results")}";
|
return $"{baseTitle}: {MiraLocaleManager.Get("MiraApi.Wiki.SearchResults", "Search Results")}";
|
||||||
}
|
}
|
||||||
|
|
||||||
var counter = $"({_settingsPage + 1}/{_settingsPages.Count + 1})";
|
var counter = $"({_settingsPage + 1}/{_settingsPages.Count + 1})";
|
||||||
return _settingsPage == 0
|
return $"{_settingsPages[_settingsPage - 1].Title} Settings {counter}";
|
||||||
? $"{baseTitle} {counter}"
|
|
||||||
: $"{baseTitle}: {_settingsPages[_settingsPage - 1].Title} {counter}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateSettingsTitle()
|
private static void UpdateSettingsTitle()
|
||||||
|
|||||||
Reference in new issue
Block a user