Files
Outer-Wilds-SK-Translation-Mod/SlovakTranslation.cs
T
Jaroslav Beneš 575a819c73 Draw menu carons with the game's own typeface, per font rather than per label
The previous commit claimed this was fixed; it was not. It hooked
UIStyleManager.GetMenuFont, GetTranslatorFont, GetShipLogFont and
GetShipLogCardFont — all four of which are dead code with no callers anywhere in
Assembly-CSharp. Fonts are assigned straight onto the Text components in the
scene data, so nothing the mod did was ever consulted.

Three further things were wrong and are fixed here:

- The language check reflected into the Localization Utility for TryGetLanguage,
  which the installed version does not have, so it could only ever fail. It now
  uses the utility's own definition instead: custom languages are numbered past
  Language.TOTAL. No reflection, nothing to fail silently.
- The substitution was decided per label, from whether that label's own string
  needed a glyph, which left menus mixing two typefaces line by line. It is now
  decided per font: a face that cannot draw Slovak is replaced everywhere it is
  used. Faces that can — Futura PT for dialogue, Space Mono for the translator —
  are still never touched.
- The menu font was assumed to be Gill Sans MT. Logging the fonts actually in
  use showed the menus are Adobe - SerifGothicStd, which had been listed as a
  stylised face to leave alone. Gill Sans is the HUD prompts.

The replacement now prefers the game's own dynamic cut of the same typeface
(Adobe - SerifGothicStd_Dynamic and friends), matched by name prefix so bold
variants resolve too, which keeps the menu looking like vanilla. Bundled Cabin
is the fallback where the game ships no dynamic sibling, and the new
preferGameTypeface setting forces Cabin everywhere.

Hooks are Text.OnEnable, the Text.text setter, TextTranslation.SetLanguage and
scene load, plus a 2s sweep for menus built lazily after all of those.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 21:39:19 +02:00

82 lines
3.3 KiB
C#

using HarmonyLib;
using OWML.Common;
using OWML.ModHelper;
using UnityEngine;
namespace SlovakTranslation
{
/// <summary>
/// Registers Slovenčina as a selectable language via xen-42's Localization
/// Utility (xen.LocalizationUtility). All the heavy lifting lives in the
/// utility; this mod just points it at our translated strings and patches the
/// few menu/HUD fonts that were never baked with Slovak glyphs (see
/// <see cref="SlovakFont"/>).
/// </summary>
public class SlovakTranslation : ModBehaviour
{
public static SlovakTranslation Instance;
/// <summary>Name the language is registered (and displayed) under.</summary>
public const string LanguageName = "Slovenčina";
/// <summary>Path (relative to the mod folder) to the translated strings.</summary>
public static string translationFile = "assets/Translation.xml";
/// <summary>The Localization Utility's API, kept for reflection in <see cref="SlovakFont"/>.</summary>
internal static ILocalizationAPI LocalizationApi;
private void Start()
{
Instance = this;
LocalizationApi = ModHelper.Interaction.TryGetModApi<ILocalizationAPI>("xen.LocalizationUtility");
if (LocalizationApi == null)
{
ModHelper.Console.WriteLine(
"Could not find xen.LocalizationUtility — is Interplanetary Polyglot installed?",
MessageType.Error);
return;
}
LocalizationApi.RegisterLanguage(this, LanguageName, translationFile);
ModHelper.Console.WriteLine("Registered language: " + LanguageName, MessageType.Success);
// Deliberately *not* AddLanguageFont: that would make IsLanguageLatin false
// and pull dialogue, the translator and the ship log off their correct
// vanilla fonts. We only patch the fonts that can't draw Slovak.
SlovakFont.Load(this);
if (SlovakFont.Loaded)
{
new Harmony("Homer.SlovakTranslation").PatchAll();
UnityEngine.SceneManagement.SceneManager.sceneLoaded += (scene, mode) => SlovakFont.ApplyToAll();
ModHelper.Console.WriteLine("Slovak menu/HUD font (Cabin) loaded and patched in.", MessageType.Success);
}
}
/// <summary>
/// <c>preferGameTypeface</c> — when on, a menu font that can't draw Slovak is
/// replaced by the game's own dynamic cut of the same typeface where one exists,
/// so the menu keeps its vanilla look. Turn it off to use the bundled Cabin
/// everywhere instead.
/// </summary>
public override void Configure(IModConfig config)
{
SlovakFont.PreferGameTypeface = config.GetSettingsValue<bool>("preferGameTypeface");
if (!SlovakFont.Loaded) return;
SlovakFont.ForgetChoices();
SlovakFont.ApplyToAll();
}
/// <summary>Labels can be built long after a scene loads, so keep sweeping.</summary>
private float _nextSweep;
private void Update()
{
if (!SlovakFont.Loaded || Time.unscaledTime < _nextSweep) return;
_nextSweep = Time.unscaledTime + 2f;
SlovakFont.ApplyToAll();
}
}
}