99
1010namespace CustomizableName . Components {
1111 internal class PreferredNameSetting : StringSetting , IExposedSetting , IConditionalSetting {
12- private readonly GameObject uiCell ;
12+ private static bool initialized = false ;
1313
14- private PreferredNameSetting ( ) : base ( ) {
15- uiCell = Object . Instantiate ( SingletonAsset < InputCellMapper > . Instance . FloatSettingCell ) ;
14+ private PreferredNameSetting ( ) : base ( ) { }
15+
16+ public override void Load ( ISettingsSaveLoad loader ) {
17+ Value = Plugin . Config . PreferredName . Value ?? "" ;
18+ }
19+
20+ public override void Save ( ISettingsSaveLoad saver ) {
21+ Plugin . Config . DisplayName = Value . Trim ( ) ;
22+ }
23+
24+ public override void ApplyValue ( ) { }
25+
26+ protected override string GetDefaultValue ( ) {
27+ return "" ;
28+ }
29+
30+ public string GetDisplayName ( ) {
31+ return "PREFERREDNAMESETTING" ;
32+ }
33+
34+ public string GetCategory ( ) {
35+ return "Accessibility" ;
36+ }
37+
38+ public bool ShouldShow ( ) {
39+ return ! PhotonNetwork . InRoom ;
40+ }
41+
42+ public override GameObject GetSettingUICell ( ) {
43+ GameObject existing = GameObject . Find ( "PreferredNameInputCell" ) ;
44+ if ( existing != null ) return existing ;
45+
46+ GameObject uiCell = Object . Instantiate ( SingletonAsset < InputCellMapper > . Instance . FloatSettingCell ) ;
1647 uiCell . name = "PreferredNameInputCell" ;
1748
1849 FloatSettingUI old = uiCell . GetComponent < FloatSettingUI > ( ) ;
@@ -22,6 +53,9 @@ private PreferredNameSetting() : base() {
2253 Object . DestroyImmediate ( old . slider . gameObject ) ;
2354 Object . DestroyImmediate ( old ) ;
2455
56+ ui . disable = PhotonNetwork . InRoom ;
57+ ui . inputField . readOnly = ui . disable ;
58+ ui . inputField . interactable = ! ui . disable ;
2559 ui . inputField . characterValidation = TMP_InputField . CharacterValidation . None ;
2660 ui . inputField . characterLimit = 24 ;
2761 ui . inputField . contentType = TMP_InputField . ContentType . Standard ;
@@ -39,40 +73,11 @@ private PreferredNameSetting() : base() {
3973 label . fontSize = label . fontSizeMin = label . fontSizeMax = 24f ;
4074 label . alignment = TextAlignmentOptions . MidlineLeft ;
4175 }
42- Object . DontDestroyOnLoad ( uiCell ) ;
43- }
44-
45- public override void Load ( ISettingsSaveLoad loader ) {
46- Value = Plugin . Config . PreferredName . Value ?? "" ;
47- }
48-
49- public override void Save ( ISettingsSaveLoad saver ) {
50- Plugin . Config . DisplayName = Value . Trim ( ) ;
51- }
52-
53- public override void ApplyValue ( ) { }
54-
55- public override GameObject GetSettingUICell ( ) {
5676 return uiCell ;
5777 }
5878
59- protected override string GetDefaultValue ( ) {
60- return "" ;
61- }
62-
63- public string GetDisplayName ( ) {
64- return "PREFERREDNAMESETTING" ;
65- }
66-
67- public string GetCategory ( ) {
68- return "General" ;
69- }
70-
71- public bool ShouldShow ( ) {
72- return ! PhotonNetwork . InRoom ;
73- }
74-
7579 internal static void Initialize ( Transform parent ) {
80+ if ( initialized ) return ;
7681 TranslationKey i18n = MenuAPI . CreateLocalization ( "PREFERREDNAMESETTING" )
7782 . AddLocalization ( "Preferred Name" , LocalizedText . Language . English )
7883 . AddLocalization ( "Nom préféré" , LocalizedText . Language . French )
@@ -90,6 +95,7 @@ internal static void Initialize(Transform parent) {
9095 . AddLocalization ( "Preferowana nazwa" , LocalizedText . Language . Polish )
9196 . AddLocalization ( "Tercih edilen isim" , LocalizedText . Language . Turkish ) ;
9297 SettingsHandler . Instance . AddSetting ( new PreferredNameSetting ( ) ) ;
98+ initialized = true ;
9399 }
94100 }
95101}
0 commit comments