Skip to content

Commit

Permalink
Add wide hou+ menu option for translators
Browse files Browse the repository at this point in the history
On hou, in the UI file, there are two images for the menu buttons.
One is very wide (button hovered), and one only is as long as the english text
(button not hovered). Translators may be unable to fit the text in the short
button, so I've added a mode which only uses the long button, and uses the engine
to give a fade effect when you hover the button.

Then translators can use the wide button to fit in more text.
  • Loading branch information
drojf committed Sep 1, 2024
1 parent f39a509 commit 452cc92
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Assets.Scripts.UI.TitleScreen/TitleScreenButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class TitleScreenButton : MonoBehaviour

private string pressedSprite;

private static bool useHoverSpriteOnlyForTranslator = false;
private static float hoverOpacityForTranslators = 0.5f;

private void OnClick()
{
GameSystem gameSystem = GameSystem.Instance;
Expand Down Expand Up @@ -101,6 +104,17 @@ private void Awake()
{
button = GetComponent<UIButton>();
hoverSprite = button.hoverSprite;

if (useHoverSpriteOnlyForTranslator)
{
pressedSprite = hoverSprite;
button.hoverSprite = hoverSprite;
button.pressedSprite = hoverSprite;
button.disabledSprite = hoverSprite;
GetComponent<UISprite>().spriteName = hoverSprite;
button.hover.a = hoverOpacityForTranslators;
}

pressedSprite = button.pressedSprite;
button.hoverSprite = button.normalSprite;
button.pressedSprite = button.normalSprite;
Expand All @@ -125,5 +139,20 @@ private void LateUpdate()
}
}
}

// MUST BE CALLED BEFORE BUTTONS APPEAR. Has no effect if buttons already on screen.
//
// On hou+, in the UI file, there are two images for the menu buttons.
// One is very wide (button hovered), and one only is as long as the english text
// (button not hovered). Translators may be unable to fit the text in the short
// button, so I've added a mode which only uses the long button, and uses the engine
// to give a fade effect when you hover the button.
//
// Then translators can use the wide button to fit in more text.
public static void UseHoverSpriteOnlyForTranslators(bool useHoverSprite, float hoverOpacity)
{
useHoverSpriteOnlyForTranslator = useHoverSprite;
hoverOpacityForTranslators = hoverOpacity;
}
}
}
12 changes: 12 additions & 0 deletions MOD.Scripts.Core/MODLocalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Assets.Scripts.Core;
using MOD.Scripts.UI;
using System.Globalization;
using Assets.Scripts.UI.TitleScreen;

namespace MOD.Scripts.Core.Localization
{
Expand Down Expand Up @@ -184,6 +185,17 @@ public static void LoadFromJSON()
Loc.dateTimeFormat = timeFormatEntry.text;
}
}

if (Loc.GetEntry("HouPlusWideMenuButtons", out LocalizationEntry houWideMenuButtons))
{
if (houWideMenuButtons.TextHasValue())
{
if(MODUtility.TryParseInvariantCulture(houWideMenuButtons.text, out float opacity))
{
TitleScreenButton.UseHoverSpriteOnlyForTranslators(opacity > 0, opacity);
}
}
}
}
catch (System.Exception e)
{
Expand Down

0 comments on commit 452cc92

Please sign in to comment.