mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Fix up system registration for the most part
This commit is contained in:
1 parent
5b006ab7d3
commit
34148499b7
18 files changed
+67
-66
No files matched your search
File renamed without changes.
File renamed without changes.
@@ -1,5 +1,5 @@
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Localization.Utilities;
|
||||
using MiraAPI.Translation;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Colors;
|
||||
@@ -43,7 +43,7 @@ public sealed class CustomColor(StringNames name, Color32 mainColor, Color32 sha
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public CustomColor(string name, Color32 mainColor, Color32 shadowColor) : this(CustomStringName.CreateAndRegister(name), mainColor, shadowColor)
|
||||
public CustomColor(string name, Color32 mainColor, Color32 shadowColor) : this(MiraLocaleManager.GetOrCreateLocaleString(name), mainColor, shadowColor)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Translation;
|
||||
using Reactor.Localization.Utilities;
|
||||
|
||||
namespace MiraAPI.Colors;
|
||||
|
||||
@@ -23,8 +21,7 @@ public static class PaletteManager
|
||||
var colors = CustomColors.Select(x => x.MainColor).ToArray();
|
||||
var shadowColors = CustomColors.Select(x => x.ShadowColor).ToArray();
|
||||
var stringNames = CustomColors.Select(x =>
|
||||
CustomStringName.CreateAndRegister(TranslationController.Instance.GetString(x.Name).Translate())
|
||||
).ToArray();
|
||||
x.Name).ToArray();
|
||||
|
||||
Palette.PlayerColors = Palette.PlayerColors.ToArray().AddRangeToArray(colors);
|
||||
Palette.ShadowColors = Palette.ShadowColors.ToArray().AddRangeToArray(shadowColors);
|
||||
|
||||
@@ -6,6 +6,7 @@ using MiraAPI.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Patches.GameModes;
|
||||
using MiraAPI.Patches.Options;
|
||||
using MiraAPI.Translation;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Localization.Utilities;
|
||||
@@ -48,17 +49,17 @@ public static class GameModeOption
|
||||
internal static StringOption OptionBehaviour { get; set; } = null!;
|
||||
|
||||
internal static int _lastValue;
|
||||
internal static readonly StringNames GamemodeName = CustomStringName.CreateAndRegister("Gamemode");
|
||||
internal static readonly StringNames CustomName = CustomStringName.CreateAndRegister("Custom");
|
||||
internal static readonly StringNames GamemodeName = MiraLocaleManager.GetOrCreateLocaleString("Gamemode");
|
||||
internal static readonly StringNames CustomName = MiraLocaleManager.GetOrCreateLocaleString("Custom");
|
||||
internal static readonly Dictionary<uint, StringNames> Values = new()
|
||||
{
|
||||
[0] = CustomStringName.CreateAndRegister("Classic"),
|
||||
[0] = MiraLocaleManager.GetOrCreateLocaleString("Classic"),
|
||||
};
|
||||
|
||||
internal static void AddOption(AbstractGameMode mode)
|
||||
{
|
||||
if (!Values.ContainsKey(mode.ID))
|
||||
Values.Add(mode.ID, CustomStringName.CreateAndRegister(mode.ColoredName));
|
||||
Values.Add(mode.ID, MiraLocaleManager.GetOrCreateLocaleString(mode + ".colored"));
|
||||
}
|
||||
/*[HarmonyPatch(typeof(GameOptionsMenu), nameof(GameOptionsMenu.CreateSettings))]
|
||||
[HarmonyPostfix]
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Translation;
|
||||
using Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -37,8 +38,8 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(enumType).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: [.. values.Select(CustomStringName.CreateAndRegister)];
|
||||
Enum.GetNames(enumType).Select(MiraLocaleManager.GetOrCreateLocaleString).ToArray()
|
||||
: [.. values.Select(MiraLocaleManager.GetOrCreateLocaleString)];
|
||||
|
||||
data.Index = Value;
|
||||
}
|
||||
@@ -136,8 +137,8 @@ public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(typeof(T)).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: [.. values.Select(CustomStringName.CreateAndRegister)];
|
||||
Enum.GetNames(typeof(T)).Select(MiraLocaleManager.GetOrCreateLocaleString).ToArray()
|
||||
: [.. values.Select(MiraLocaleManager.GetOrCreateLocaleString)];
|
||||
|
||||
data.Index = Convert.ToInt32(Value, NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
Title = title.Translate();
|
||||
DefaultValue = defaultValue;
|
||||
Value = defaultValue;
|
||||
StringName = CustomStringName.CreateAndRegister(Title.Translate());
|
||||
StringName = MiraLocaleManager.GetOrCreateLocaleString(Title);
|
||||
Visible = () => true;
|
||||
IncludeInPreset = includeInPreset;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Translation;
|
||||
using Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -56,7 +57,7 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
newVals.Insert(index, value);
|
||||
Values = newVals.ToArray();
|
||||
var newStrVals = StringNameValues.ToList();
|
||||
newStrVals.Insert(index, CustomStringName.CreateAndRegister(value));
|
||||
newStrVals.Insert(index, MiraLocaleManager.GetOrCreateLocaleString(value));
|
||||
StringNameValues = newStrVals.ToArray();
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ public class ModdedStringOption : ModdedOption<string>
|
||||
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
StringNameValues = values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
StringNameValues = values.Select(MiraLocaleManager.GetOrCreateLocaleString).ToArray();
|
||||
data.Values = StringNameValues;
|
||||
|
||||
data.Index = GetIndex(Value, 3);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class LocalToggleSetting : LocalSettingBase<bool>
|
||||
toggleObject.transform.localPosition = new Vector3(order == 1 ? -1.185f : 1.185f, 1.85f - offset, -7);
|
||||
}
|
||||
|
||||
toggleObject.BaseText = CustomStringName.CreateAndRegister(Name.Translate());
|
||||
toggleObject.BaseText = MiraLocaleManager.GetOrCreateLocaleString(Name);
|
||||
toggleObject.UpdateText(GetValue());
|
||||
toggleObject.name = Name.Translate();
|
||||
toggleObject.Background.color = GetValue() ? Tab!.TabAppearance.ToggleActiveColor : Tab!.TabAppearance.ToggleInactiveColor;
|
||||
|
||||
@@ -457,7 +457,7 @@ internal static class GameOptionsMenuPatch
|
||||
|
||||
num -= 0.58f;
|
||||
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName), 20);
|
||||
categoryHeaderMasked.SetHeader(MiraLocaleManager.GetOrCreateLocaleString(group.GroupName), 20);
|
||||
categoryHeaderMasked.Background.color = group.GroupColor;
|
||||
categoryHeaderMasked.Divider.color = group.GroupColor;
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor)
|
||||
@@ -697,7 +697,7 @@ internal static class GameOptionsMenuPatch
|
||||
Quaternion.identity,
|
||||
container);
|
||||
|
||||
categoryHeaderMasked.SetHeader(CustomStringName.CreateAndRegister(group.GroupName.Translate()), 20);
|
||||
categoryHeaderMasked.SetHeader(MiraLocaleManager.GetOrCreateLocaleString(group.GroupName), 20);
|
||||
categoryHeaderMasked.Background.color = group.GroupColor;
|
||||
categoryHeaderMasked.Divider.color = group.GroupColor;
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.Equals(MiraApiPlugin.DefaultHeaderColor)
|
||||
|
||||
@@ -32,8 +32,7 @@ public static class LobbyViewPanePatches
|
||||
: Plugins[SelectedModIdx - 1];
|
||||
|
||||
private static PassiveButton? ModifiersTabButton { get; set; }
|
||||
|
||||
private static StringNames ModifiersTabName { get; } = CustomStringName.CreateAndRegister("ModifiersTab");
|
||||
internal static StringNames ModifiersTabName { get; } = MiraLocaleManager.GetOrCreateLocaleString("ModifiersTab");
|
||||
|
||||
private static AbstractGameMode? GetCustomGamemode()
|
||||
{
|
||||
@@ -455,7 +454,7 @@ public static class LobbyViewPanePatches
|
||||
// sort the groups by priority
|
||||
var sortedRoleGroups = roleGroups
|
||||
.OrderBy(x => x.Key.Priority)
|
||||
.ThenBy(x => x.Key.Name);
|
||||
.ThenBy(x => x.Key.Name.Translate());
|
||||
|
||||
foreach (var grouping in sortedRoleGroups)
|
||||
{
|
||||
@@ -466,13 +465,7 @@ public static class LobbyViewPanePatches
|
||||
|
||||
var group = grouping.Key;
|
||||
|
||||
var translatedName = group.Name.Translate();
|
||||
var name = translatedName switch
|
||||
{
|
||||
"Crewmate" => StringNames.CrewmateRolesHeader,
|
||||
"Impostor" => StringNames.ImpostorRolesHeader,
|
||||
_ => CustomStringName.CreateAndRegister(translatedName),
|
||||
};
|
||||
var name = MiraLocaleManager.GetOrCreateLocaleString(group.Name);
|
||||
|
||||
var categoryHeaderRoleVariant = Object.Instantiate(instance.categoryHeaderRoleOrigin, instance.settingsContainer, true);
|
||||
categoryHeaderRoleVariant.SetHeader(name, 61);
|
||||
|
||||
@@ -196,7 +196,7 @@ public static class RoleSettingMenuPatches
|
||||
// sort the groups by priority
|
||||
var sortedRoleGroups = roleGroups
|
||||
.OrderBy(x => x.Key.Priority)
|
||||
.ThenBy(x => x.Key.Name);
|
||||
.ThenBy(x => x.Key.Name.Translate());
|
||||
|
||||
var quotaThing = roleMenu.categoryHeaderEditRoleOrigin.transform.FindChild("QuotaHeader");
|
||||
var usingNewQuota = false;
|
||||
@@ -215,13 +215,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
RoleGroupHidden.TryAdd(group, false);
|
||||
|
||||
var translatedName = group.Name.Translate();
|
||||
var name = translatedName switch
|
||||
{
|
||||
"Crewmate" => StringNames.CrewmateRolesHeader,
|
||||
"Impostor" => StringNames.ImpostorRolesHeader,
|
||||
_ => CustomStringName.CreateAndRegister(translatedName),
|
||||
};
|
||||
var name = MiraLocaleManager.GetOrCreateLocaleString(group.Name);
|
||||
|
||||
var categoryHeaderMasked = Object.Instantiate(
|
||||
template,
|
||||
|
||||
@@ -29,10 +29,14 @@ Outlive the timer or eliminate the crew.</string>
|
||||
<string name="gamesetting.preset.save">Save</string>
|
||||
<string name="gamesetting.roles">Roles</string>
|
||||
<string name="gamesetting.modifiers">Modifiers</string>
|
||||
<string name="roleTeam.crewmate.long">Crewmate</string>
|
||||
<string name="roleTeam.crewmate">Crewmate</string>
|
||||
<string name="roleTeam.crewmate.short">Crew</string>
|
||||
<string name="roleTeam.impostor.long">Impostor</string>
|
||||
<string name="roleTeam.crewmate.group">Crewmate Roles</string>
|
||||
<string name="roleTeam.impostor">Impostor</string>
|
||||
<string name="roleTeam.impostor.short">Imp</string>
|
||||
<string name="roleTeam.neutral.long">Neutral</string>
|
||||
<string name="roleTeam.impostor.group">Impostor Roles</string>
|
||||
<string name="roleTeam.neutral">Neutral</string>
|
||||
<string name="roleTeam.neutral.short">Neut</string>
|
||||
<string name="roleTeam.neutral.group">Neutral Roles</string>
|
||||
<string name="roleTeam.other">Other</string>
|
||||
</resources>
|
||||
@@ -132,9 +132,10 @@ public static class CustomRoleManager
|
||||
roleBehaviour.Role = (RoleTypes)roleId;
|
||||
roleBehaviour.TeamType = customRole.Team == ModdedRoleTeams.Custom ? RoleTeamTypes.Crewmate : (RoleTeamTypes)customRole.Team;
|
||||
roleBehaviour.NameColor = customRole.RoleColor;
|
||||
roleBehaviour.StringName = CustomStringName.CreateAndRegister(customRole.RoleName.Translate());
|
||||
roleBehaviour.BlurbName = CustomStringName.CreateAndRegister(customRole.RoleDescription.Translate());
|
||||
roleBehaviour.BlurbNameLong = CustomStringName.CreateAndRegister(customRole.RoleLongDescription.Translate());
|
||||
roleBehaviour.StringName = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleName);
|
||||
roleBehaviour.BlurbName = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleDescription);
|
||||
roleBehaviour.BlurbNameMed = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleMedDescription);
|
||||
roleBehaviour.BlurbNameLong = MiraLocaleManager.GetOrCreateLocaleString(customRole.RoleLongDescription);
|
||||
roleBehaviour.AffectedByLightAffectors = customRole.Configuration.AffectedByLightOnAirship;
|
||||
roleBehaviour.CanBeKilled = customRole.Configuration.CanGetKilled;
|
||||
roleBehaviour.CanUseKillButton = customRole.Configuration.UseVanillaKillButton;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.GameOptions;
|
||||
@@ -17,7 +18,7 @@ public interface ICustomRole : IOptionable
|
||||
/// <summary>
|
||||
/// Gets the id part used to build the role's translation keys.
|
||||
/// </summary>
|
||||
string IdPart => GetType().Name.ToLower();
|
||||
string IdPart => GetType().Name.ToLower(CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the role.
|
||||
@@ -44,10 +45,10 @@ public interface ICustomRole : IOptionable
|
||||
/// </summary>
|
||||
string RoleFactionTitle => Team switch
|
||||
{
|
||||
ModdedRoleTeams.Crewmate => TranslationController.Instance.GetString(StringNames.Crewmate),
|
||||
ModdedRoleTeams.Impostor => TranslationController.Instance.GetString(StringNames.Impostor),
|
||||
ModdedRoleTeams.Custom => "Neutral",
|
||||
_ => "Other",
|
||||
ModdedRoleTeams.Crewmate => MiraLocaleManager.Get("roleTeam.crewmate"),
|
||||
ModdedRoleTeams.Impostor => MiraLocaleManager.Get("roleTeam.impostor"),
|
||||
ModdedRoleTeams.Custom => MiraLocaleManager.Get("roleTeam.neutral"),
|
||||
_ => MiraLocaleManager.Get("roleTeam.other"),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -78,7 +79,7 @@ public interface ICustomRole : IOptionable
|
||||
ModdedRoleTeams.Crewmate => RoleOptionsGroup.Crewmate,
|
||||
ModdedRoleTeams.Impostor => RoleOptionsGroup.Impostor,
|
||||
ModdedRoleTeams.Custom => RoleOptionsGroup.Neutral,
|
||||
_ => new RoleOptionsGroup(RoleName.Translate(), RoleColor),
|
||||
_ => new RoleOptionsGroup(RoleName, RoleColor),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -13,15 +13,15 @@ public record struct RoleOptionsGroup(string Name, Color Color, int Priority = 0
|
||||
/// <summary>
|
||||
/// Gets the default group for crewmates.
|
||||
/// </summary>
|
||||
public static RoleOptionsGroup Crewmate { get; } = new("Crewmate", Palette.CrewmateBlue, -2);
|
||||
public static RoleOptionsGroup Crewmate { get; } = new("roleTeam.crewmate.group", Palette.CrewmateBlue, -2);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default group for impostors.
|
||||
/// </summary>
|
||||
public static RoleOptionsGroup Impostor { get; } = new("Impostor", Palette.ImpostorRed, -1);
|
||||
public static RoleOptionsGroup Impostor { get; } = new("roleTeam.impostor.group", Palette.ImpostorRed, -1);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default group for neutral roles.
|
||||
/// </summary>
|
||||
public static RoleOptionsGroup Neutral { get; } = new("Neutral Roles", Color.gray);
|
||||
public static RoleOptionsGroup Neutral { get; } = new("roleTeam.neutral.group", Color.gray);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using Reactor.Localization.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Translation;
|
||||
@@ -12,7 +13,10 @@ public static class MiraLocaleManager
|
||||
{
|
||||
private const string LangDirectory = "mira_languages";
|
||||
|
||||
private static readonly Dictionary<string, Dictionary<MiraLanguage, Dictionary<string, string>>> Locale = [];
|
||||
public static readonly Dictionary<string, Dictionary<MiraLanguage, Dictionary<string, string>>> Locale = [];
|
||||
|
||||
public static readonly Dictionary<string, StringNames> RegisteredStringNames = [];
|
||||
internal static readonly Dictionary<StringNames, string> StringNamesLookup = [];
|
||||
|
||||
public static Dictionary<MiraLanguage, string> LangList { get; } = new()
|
||||
{
|
||||
@@ -177,6 +181,19 @@ public static class MiraLocaleManager
|
||||
return Path.Combine(Application.persistentDataPath, LangDirectory, modGuid);
|
||||
}
|
||||
|
||||
public static StringNames GetOrCreateLocaleString(string name)
|
||||
{
|
||||
if (RegisteredStringNames.TryGetValue(name, out var stringName))
|
||||
{
|
||||
return stringName;
|
||||
}
|
||||
|
||||
var newString = CustomStringName.CreateAndRegister(name);
|
||||
RegisteredStringNames.Add(name, newString);
|
||||
StringNamesLookup.Add(newString, name);
|
||||
return newString;
|
||||
}
|
||||
|
||||
private static void LoadInternalStrings(Assembly assembly, string modGuid, string dir)
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
@@ -13,20 +13,11 @@ public class MiraLocalizationProvider : LocalizationProvider
|
||||
|
||||
public override bool TryGetText(StringNames stringName, out string? result)
|
||||
{
|
||||
if (_reactorProvider != null && (int)stringName < 0 && _reactorProvider.TryGetText(stringName, out var reactorText))
|
||||
if (MiraLocaleManager.StringNamesLookup.TryGetValue(stringName, out var key))
|
||||
{
|
||||
if (reactorText.IsNullOrWhiteSpace())
|
||||
{
|
||||
result = "STRMISS";
|
||||
result = MiraLocaleManager.Get(key);
|
||||
return true;
|
||||
}
|
||||
var localeText = MiraLocaleManager.Get(reactorText!);
|
||||
if (localeText != reactorText)
|
||||
{
|
||||
result = localeText;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user