Skip to content

Commit 3fd5269

Browse files
committed
Added toggle for credits
some characters cause tmp to chug like crazy
1 parent 36c6615 commit 3fd5269

1 file changed

Lines changed: 46 additions & 11 deletions

File tree

SiraLocalizer/UI/LanguageSettingCreator.cs

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
using HMUI;
22
using TMPro;
3+
using System;
34
using Zenject;
45
using Polyglot;
56
using UnityEngine;
7+
using IPA.Utilities;
8+
using UnityEngine.UI;
69

710
namespace SiraLocalizer.UI
811
{
9-
internal class LanguageSettingCreator : IInitializable
12+
internal class LanguageSettingCreator : IInitializable, IDisposable
1013
{
14+
private Button _creditsToggle;
15+
private CurvedTextMeshPro _credits;
1116
private readonly DiContainer _container;
12-
private readonly SettingsNavigationController _settingsNavigationController;
1317
private readonly GameplaySetupViewController _gameplaySetupViewController;
18+
private readonly SettingsNavigationController _settingsNavigationController;
19+
private readonly StandardLevelDetailViewController _standardLevelDetailViewController;
1420

15-
internal LanguageSettingCreator(DiContainer container, SettingsNavigationController settingsNavigationController, GameplaySetupViewController gameplaySetupViewController)
21+
internal LanguageSettingCreator(DiContainer container, GameplaySetupViewController gameplaySetupViewController, SettingsNavigationController settingsNavigationController, StandardLevelDetailViewController standardLevelDetailViewController)
1622
{
1723
_container = container;
18-
_settingsNavigationController = settingsNavigationController;
1924
_gameplaySetupViewController = gameplaySetupViewController;
25+
_settingsNavigationController = settingsNavigationController;
26+
_standardLevelDetailViewController = standardLevelDetailViewController;
2027
}
2128

2229
public void Initialize()
@@ -56,18 +63,18 @@ private void AddMenuOption()
5663
Plugin.Log.Debug("Created language setting");
5764

5865
var textGameObject = new GameObject("SiraLocalizerContributorsText");
59-
var curvedText = textGameObject.AddComponent<CurvedTextMeshPro>();
66+
_credits = textGameObject.AddComponent<CurvedTextMeshPro>();
6067

6168
var textRectTransform = (RectTransform)textGameObject.transform;
6269
textRectTransform.SetParent(otherSettingsContent, false);
6370
textRectTransform.offsetMin = new Vector2(-45f, -7.4f);
6471
textRectTransform.offsetMax = new Vector2(45f, -7.4f);
6572

66-
curvedText.alignment = TextAlignmentOptions.TopLeft;
67-
curvedText.lineSpacing = -35f;
68-
curvedText.fontSize = 3f;
69-
curvedText.fontStyle = FontStyles.Italic;
70-
curvedText.gameObject.SetActive(true);
73+
_credits.alignment = TextAlignmentOptions.TopLeft;
74+
_credits.lineSpacing = -35f;
75+
_credits.fontSize = 3f;
76+
_credits.fontStyle = FontStyles.Italic;
77+
_credits.gameObject.SetActive(false);
7178

7279
foreach (var lang in Localization.Instance.SupportedLanguages)
7380
{
@@ -79,9 +86,37 @@ private void AddMenuOption()
7986
var name = Localization.Get("MENU_LANGUAGE_THIS", lang);
8087
if (!string.IsNullOrEmpty(contributors))
8188
{
82-
curvedText.text += $"<b>{name}</b> <color=#bababa>{contributors}</color>\n";
89+
_credits.text += $"<b>{name}</b> <color=#bababa>{contributors}</color>\n";
8390
}
8491
}
92+
93+
_creditsToggle = _container.InstantiatePrefabForComponent<Button>(_standardLevelDetailViewController.GetField<StandardLevelDetailView, StandardLevelDetailViewController>("_standardLevelDetailView").practiceButton);
94+
_creditsToggle.name = "LocalizationCreditsButton";
95+
UnityEngine.Object.Destroy(_creditsToggle.transform.Find("Content").GetComponent<LayoutElement>());
96+
_creditsToggle.gameObject.transform.SetParent(otherSettingsContent, false);
97+
var rect = (_creditsToggle.transform as RectTransform);
98+
rect.localPosition = new Vector3(-5f, -11f, 0f);
99+
100+
ContentSizeFitter buttonSizeFitter = _creditsToggle.gameObject.AddComponent<ContentSizeFitter>();
101+
buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
102+
buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
103+
LocalizedTextMeshProUGUI localizer = _creditsToggle.GetComponentInChildren<LocalizedTextMeshProUGUI>(true);
104+
localizer.Key = "CREDITS_TITLE";
105+
106+
_creditsToggle.onClick.AddListener(ToggleCredits);
107+
}
108+
109+
private void ToggleCredits()
110+
{
111+
_credits.gameObject.SetActive(!_credits.isActiveAndEnabled);
112+
}
113+
114+
public void Dispose()
115+
{
116+
if (_creditsToggle != null)
117+
{
118+
_creditsToggle.onClick.RemoveListener(ToggleCredits);
119+
}
85120
}
86121
}
87122
}

0 commit comments

Comments
 (0)