Skip to content

Commit 0ba9b60

Browse files
committed
feat: complete dropdown object
1 parent 3c50898 commit 0ba9b60

File tree

13 files changed

+2856
-303
lines changed

13 files changed

+2856
-303
lines changed

Assets/JCSUnity/Scripts/Settings/JCS_ScreenSettings.cs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ public class JCS_ScreenSettings : JCS_Settings<JCS_ScreenSettings>
2121

2222
public Action onChanged = null;
2323
public Action onChangedResolution = null;
24+
public Action onChangedSize = null;
2425
public Action onChangedMode = null;
2526

2627
public Action onResizableResize = null;
2728
public Action onResizableIdle = null;
2829

2930
private Resolution mPrevResolution = default(Resolution);
3031

32+
private float mSizeWidth = 0;
33+
private float mSizeHeight = 0;
34+
3135
private FullScreenMode mPrevScreenMode = FullScreenMode.FullScreenWindow;
3236

3337
#if UNITY_EDITOR
@@ -159,8 +163,18 @@ private void Awake()
159163
}
160164

161165
// Initialize.
162-
mPrevResolution = Screen.currentResolution;
163-
mPrevScreenMode = Screen.fullScreenMode;
166+
{
167+
Resolution currentResolution = Screen.currentResolution;
168+
169+
mPrevResolution = new Resolution();
170+
mPrevResolution.width = currentResolution.width;
171+
mPrevResolution.height = currentResolution.height;
172+
173+
mSizeWidth = JCS_Screen.width;
174+
mSizeHeight = JCS_Screen.height;
175+
176+
mPrevScreenMode = Screen.fullScreenMode;
177+
}
164178
}
165179

166180
private void Start()
@@ -188,28 +202,41 @@ private void OnChanged()
188202
Resolution currentResolution = Screen.currentResolution;
189203
FullScreenMode fullScreenMode = Screen.fullScreenMode;
190204

191-
bool resolutionChanged =
205+
bool resolutionChanged =
192206
mPrevResolution.width != currentResolution.width ||
193207
mPrevResolution.height != currentResolution.height;
194208

195-
bool modeChanged = mPrevScreenMode != fullScreenMode;
196-
197209
if (resolutionChanged)
198210
{
199211
onChangedResolution?.Invoke();
212+
213+
mPrevResolution.width = currentResolution.width;
214+
mPrevResolution.height = currentResolution.height;
200215
}
201216

217+
bool sizeChanged = mSizeWidth != JCS_Screen.width ||
218+
mSizeHeight != JCS_Screen.height;
219+
220+
if (sizeChanged)
221+
{
222+
onChangedSize?.Invoke();
223+
224+
mSizeWidth = JCS_Screen.width;
225+
mSizeHeight = JCS_Screen.height;
226+
}
227+
228+
bool modeChanged = mPrevScreenMode != fullScreenMode;
229+
202230
if (modeChanged)
203231
{
204232
onChangedMode?.Invoke();
233+
234+
mPrevScreenMode = fullScreenMode;
205235
}
206236

207-
if (modeChanged || resolutionChanged)
237+
if (modeChanged || sizeChanged || resolutionChanged)
208238
{
209239
onChanged?.Invoke();
210-
211-
mPrevResolution = currentResolution;
212-
mPrevScreenMode = fullScreenMode;
213240
}
214241
}
215242

@@ -404,7 +431,7 @@ private void DoScreenType()
404431
{
405432
// These types do not expect resize!
406433
return;
407-
}
434+
}
408435

409436
switch (SCREEN_TYPE)
410437
{
@@ -483,8 +510,7 @@ private void DoResizableScreen()
483510

484511
if (CURRENT_SCREEN_SIZE.width == width && CURRENT_SCREEN_SIZE.height == height)
485512
{
486-
if (onResizableIdle != null)
487-
onResizableIdle.Invoke();
513+
onResizableIdle?.Invoke();
488514
return;
489515
}
490516

@@ -506,8 +532,7 @@ private void DoResizableScreen()
506532
CURRENT_SCREEN_SIZE.height = height;
507533

508534
// Do callback.
509-
if (onResizableResize != null)
510-
onResizableResize.Invoke();
535+
onResizableResize?.Invoke();
511536
}
512537
}
513538
}

Assets/JCSUnity/Scripts/UI/DeltaNumber/JCS_TextDeltaNumber.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ private void DoDeltaCurrentNumber()
241241
private void UpdateTextRender()
242242
{
243243
#if TMP_PRO
244-
if (mTextContainer == null && mTMP_Text == null)
244+
if (mTextLegacy == null && mTMP_Text == null)
245245
#else
246-
if (mTextContainer == null)
246+
if (mTextLegacy == null)
247247
#endif
248248
{
249-
JCS_Debug.LogError("Text slot cannot be null references...");
249+
JCS_Debug.LogError("Text slot cannot be null references");
250250
return;
251251
}
252252

@@ -260,8 +260,8 @@ private void UpdateTextRender()
260260
+ renderNumberString
261261
+ PostString;
262262

263-
if (mTextContainer)
264-
mTextContainer.text = mFullString;
263+
if (mTextLegacy)
264+
mTextLegacy.text = mFullString;
265265
#if TMP_PRO
266266
if (mTMP_Text)
267267
mTMP_Text.text = mFullString;

Assets/JCSUnity/Scripts/UI/Dropdown/JCS_DropdownScreenResolution.cs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
/**
2+
* $File: JCS_DropdownScreenResolution.cs $
3+
* $Date: 2025-04-15 01:14:38 $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright © 2025 by Shen, Jen-Chieh $
8+
*/
19
using System.Linq;
210
using UnityEngine;
11+
using UnityEngine.UI;
312
using TMPro;
413
using MyBox;
514

@@ -12,12 +21,10 @@ namespace JCSUnity
1221
/// <summary>
1322
/// A dropdown menu let you choose the screen resolution.
1423
/// </summary>
15-
[RequireComponent(typeof(TMP_Dropdown))]
16-
public class JCS_DropdownScreenResolution : MonoBehaviour
24+
public class JCS_DropdownScreenResolution : JCS_DropdownObject
1725
{
1826
/* Variables */
1927

20-
private TMP_Dropdown mDropdown = null;
2128

2229
[Separator("Initialize Variables (JCS_DropdownScreenResolution)")]
2330

@@ -33,8 +40,6 @@ public class JCS_DropdownScreenResolution : MonoBehaviour
3340

3441
private void Awake()
3542
{
36-
this.mDropdown = GetComponent<TMP_Dropdown>();
37-
3843
Refresh();
3944

4045
AddListener();
@@ -44,18 +49,24 @@ private void Start()
4449
{
4550
var screens = JCS_ScreenSettings.instance;
4651

47-
screens.onChangedResolution += Refresh;
52+
screens.onChangedSize += Refresh;
4853
}
4954

5055
private void AddListener()
5156
{
52-
mDropdown.onValueChanged.AddListener(delegate
57+
DropdownLegacy?.onValueChanged.AddListener(delegate
58+
{
59+
OnValueChanged_Legacy(DropdownLegacy);
60+
});
61+
62+
TMP_Dropdown?.onValueChanged.AddListener(delegate
5363
{
54-
OnValueChanged(mDropdown);
64+
OnValueChanged_TMP(TMP_Dropdown);
5565
});
5666

5767
// Run once.
58-
OnValueChanged(mDropdown);
68+
OnValueChanged_Legacy(DropdownLegacy);
69+
OnValueChanged_TMP(TMP_Dropdown);
5970
}
6071

6172
/// <summary>
@@ -64,31 +75,49 @@ private void AddListener()
6475
public void Refresh()
6576
{
6677
if (mRemoveAllOptions)
67-
mDropdown.ClearOptions();
78+
ClearOptions();
79+
80+
Debug.Log("what?");
6881

6982
foreach (Resolution res in Screen.resolutions.Reverse())
7083
{
7184
string text = FormatName(res.width, res.height);
7285

73-
int index = JCS_UIUtil.Dropdown_GetItemIndex(mDropdown, text);
86+
int index = JCS_UIUtil.Dropdown_GetItemIndex(this, text);
7487

7588
// Prevent adding the same options.
7689
if (index == -1)
77-
JCS_UIUtil.Dropdown_AddOption(mDropdown, text);
90+
JCS_UIUtil.Dropdown_AddOption(this, text);
7891
}
7992

8093
// Default to the current screen resolution.
8194
{
8295
string res = FormatName(Screen.width, Screen.height);
8396

84-
JCS_UIUtil.Dropdown_SetSelection(mDropdown, res);
97+
JCS_UIUtil.Dropdown_SetSelection(this, res);
8598
}
8699
}
87100

88-
private void OnValueChanged(TMP_Dropdown dropdown)
101+
private void OnValueChanged_Legacy(Dropdown dropdown)
89102
{
103+
if (dropdown == null)
104+
return;
105+
90106
string text = JCS_UIUtil.Dropdown_GetSelectedValue(dropdown);
91107

108+
OnValueChanged(text);
109+
}
110+
private void OnValueChanged_TMP(TMP_Dropdown dropdown)
111+
{
112+
if (dropdown == null)
113+
return;
114+
115+
string text = JCS_UIUtil.Dropdown_GetSelectedValue(dropdown);
116+
117+
OnValueChanged(text);
118+
}
119+
private void OnValueChanged(string text)
120+
{
92121
string[] data = text.Split("x");
93122

94123
Resolution res = Screen.currentResolution;

Assets/JCSUnity/Scripts/UI/Dropdown/JCS_DropdownWindowedMode.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
/**
2+
* $File: JCS_DropdownWindowedMode.cs $
3+
* $Date: 2025-04-15 01:14:38 $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright © 2025 by Shen, Jen-Chieh $
8+
*/
19
using System.Collections.Generic;
210
using UnityEngine;
11+
using UnityEngine.UI;
312
using TMPro;
413
using MyBox;
514

@@ -9,12 +18,10 @@ namespace JCSUnity
918
/// A dropdown menu let you choose the windowed mode.
1019
/// </summary>
1120
[RequireComponent(typeof(TMP_Dropdown))]
12-
public class JCS_DropdownWindowedMode : MonoBehaviour
21+
public class JCS_DropdownWindowedMode : JCS_DropdownObject
1322
{
1423
/* Variables */
1524

16-
private TMP_Dropdown mDropdown = null;
17-
1825
private List<string> mOptions = new List<string>()
1926
{
2027
"Full Screen",
@@ -36,8 +43,6 @@ public class JCS_DropdownWindowedMode : MonoBehaviour
3643

3744
private void Awake()
3845
{
39-
this.mDropdown = GetComponent<TMP_Dropdown>();
40-
4146
Refresh();
4247

4348
AddListener();
@@ -52,13 +57,19 @@ private void Start()
5257

5358
private void AddListener()
5459
{
55-
mDropdown.onValueChanged.AddListener(delegate
60+
DropdownLegacy?.onValueChanged.AddListener(delegate
5661
{
57-
OnValueChanged(mDropdown);
62+
OnValueChanged_Legacy(DropdownLegacy);
63+
});
64+
65+
TMP_Dropdown?.onValueChanged.AddListener(delegate
66+
{
67+
OnValueChanged_TMP(TMP_Dropdown);
5868
});
5969

6070
// Run once.
61-
OnValueChanged(mDropdown);
71+
OnValueChanged_Legacy(DropdownLegacy);
72+
OnValueChanged_TMP(TMP_Dropdown);
6273
}
6374

6475
/// <summary>
@@ -67,25 +78,41 @@ private void AddListener()
6778
public void Refresh()
6879
{
6980
if (mRemoveAllOptions)
70-
mDropdown.ClearOptions();
81+
ClearOptions();
7182

7283
foreach (string option in mOptions)
7384
{
74-
JCS_UIUtil.Dropdown_AddOption(mDropdown, option);
85+
JCS_UIUtil.Dropdown_AddOption(this, option);
7586
}
7687

7788
// Default to the current windowed mode.
7889
{
7990
string text = ModeToString(Screen.fullScreenMode);
8091

81-
JCS_UIUtil.Dropdown_SetSelection(mDropdown, text);
92+
JCS_UIUtil.Dropdown_SetSelection(this, text);
8293
}
8394
}
8495

85-
private void OnValueChanged(TMP_Dropdown dropdown)
96+
private void OnValueChanged_Legacy(Dropdown dropdown)
8697
{
98+
if (dropdown == null)
99+
return;
100+
87101
string text = JCS_UIUtil.Dropdown_GetSelectedValue(dropdown);
88102

103+
OnValueChanged(text);
104+
}
105+
private void OnValueChanged_TMP(TMP_Dropdown dropdown)
106+
{
107+
if (dropdown == null)
108+
return;
109+
110+
string text = JCS_UIUtil.Dropdown_GetSelectedValue(dropdown);
111+
112+
OnValueChanged(text);
113+
}
114+
private void OnValueChanged(string text)
115+
{
89116
FullScreenMode mode = StringToMode(text);
90117

91118
Resolution res = Screen.currentResolution;

Assets/JCSUnity/Scripts/UI/JCS_Button.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public void Init(bool forceInit = false)
159159

160160
if (mItText != null)
161161
{
162-
if (mItText.TextContainer == null)
163-
mItText.TextContainer = this.GetComponentInChildren<Text>();
162+
if (mItText.TextLegacy == null)
163+
mItText.TextLegacy = this.GetComponentInChildren<Text>();
164164
if (mItText.TMP_Text == null)
165165
mItText.TMP_Text = this.GetComponentInChildren<TMP_Text>();
166166
}

0 commit comments

Comments
 (0)