Skip to content

Commit

Permalink
Set up the Examine UI to accept localization.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan089 committed Aug 10, 2024
1 parent 9229bfe commit 1a26a10
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 37 deletions.
166 changes: 135 additions & 31 deletions Assets/Content/Systems/UI/Font/TMPFontText.asset

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions Assets/Scripts/SS3D/Systems/Examine/ExamineUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class ExamineUI : Actor
{
[SerializeField] private TMP_Text HoverName;

private StringTable _currentStringTable;

protected override void OnEnabled()
{
base.OnEnabled();
Expand All @@ -24,16 +26,33 @@ protected override void OnDisabled()
Subsystems.Get<ExamineSystem>().OnExaminableChanged -= UpdateHoverText;
}

/// <summary>
/// Updates the hover text with the appropriate localized string.
/// </summary>
/// <param name="examinable">The object that is being examined</param>
private void UpdateHoverText(IExaminable examinable)
{
if (examinable?.GetData() == null)
{
HoverName.text = "";
}
else
string _hoverTextToDisplay = string.Empty;

if (examinable?.GetData() != null)
{
HoverName.text = examinable.GetData().NameKey;
ExamineData data = examinable.GetData();

if (data.LocalizationTable != null)
{
_currentStringTable = data.LocalizationTable?.GetTable();
if (_currentStringTable[data.NameKey]?.LocalizedValue is null)
{
_hoverTextToDisplay = data.NameKey + " *[to be localized]*";
}
else
{
_hoverTextToDisplay = _currentStringTable[data.NameKey]?.LocalizedValue;
}
}
}

HoverName.text = _hoverTextToDisplay;
}
}
}

0 comments on commit 1a26a10

Please sign in to comment.