Skip to content

Commit 1edcbc8

Browse files
committed
add JCS_OnClickCallback abstract for JCS_Button class. Restrict all button follows this method, reduce system duplicate code.
1 parent 35bdcdf commit 1edcbc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+417
-286
lines changed

Assets/BossFight_Assets/Scenes/BF_Lobby.unity

Lines changed: 336 additions & 135 deletions
Large diffs are not rendered by default.

Assets/BossFight_Assets/Scripts/UI/Buttons/BF_BuyButton.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ private void Update()
6868
//----------------------
6969
// Public Functions
7070

71-
public override void JCS_ButtonClick()
71+
public override void JCS_OnClickCallback()
7272
{
73-
base.JCS_ButtonClick();
74-
7573
BF_GameSettings.BF_GAME_DATA.Cash -= mBuyValue;
7674
}
7775

Assets/BossFight_Assets/Scripts/UI/Buttons/BF_LoadSelectedSceneButton.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ public class BF_LoadSelectedSceneButton
4141
//----------------------
4242
// Public Functions
4343

44-
public override void JCS_ButtonClick()
44+
public override void JCS_OnClickCallback()
4545
{
46-
base.JCS_ButtonClick();
47-
4846
string sceneName = BF_GameSettings.instance.LEVEL_SELECTED_NAME;
4947

5048
JCS_SceneManager.instance.LoadScene(sceneName);

Assets/BossFight_Assets/Scripts/UI/Buttons/BF_SelectLevelButton.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ public class BF_SelectLevelButton
4545
//----------------------
4646
// Public Functions
4747

48-
public override void JCS_ButtonClick()
48+
public override void JCS_OnClickCallback()
4949
{
50-
base.JCS_ButtonClick();
51-
5250
BF_GameSettings.instance.LEVEL_SELECTED_NAME = mSceneName;
5351
}
5452

Assets/FrameworkTest_Assets/Scripts/FT_EchoGamePadButton.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,8 @@ public class FT_EchoGamePadButton
2121
public JCS_DialogueObject closeDialogue = null;
2222

2323

24-
/// <summary>
25-
/// Default function to call this, so we dont have to
26-
/// search the function depends on name.
27-
///
28-
/// * Good for organize code and game data file in Unity.
29-
/// </summary>
30-
public override void JCS_ButtonClick()
24+
public override void JCS_OnClickCallback()
3125
{
32-
base.JCS_ButtonClick();
33-
3426
Debug.Log("echo.. Hello World!!");
3527

3628
closeDialogue.HideDialogue();

Assets/JCSUnity/Scripts/GUI/JCS_Button.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace JCSUnity
1919
[RequireComponent(typeof(RectTransform))]
2020
[RequireComponent(typeof(Button))]
2121
[RequireComponent(typeof(Image))]
22-
public abstract class JCS_Button
22+
public abstract class JCS_Button
2323
: MonoBehaviour
2424
{
2525

@@ -48,6 +48,8 @@ public abstract class JCS_Button
4848
[SerializeField]
4949
private int mDialogueSelection = -1;
5050

51+
private bool mInitialized = false;
52+
5153
/*******************************************/
5254
/* Protected Variables */
5355
/*******************************************/
@@ -145,8 +147,14 @@ protected virtual void Awake()
145147
/// <summary>
146148
/// Intialize jcs button once.
147149
/// </summary>
148-
public void InitJCSButton()
150+
public void InitJCSButton(bool forceInit = false)
149151
{
152+
if (!forceInit)
153+
{
154+
if (this.mInitialized)
155+
return;
156+
}
157+
150158
this.mRectTransform = this.GetComponent<RectTransform>();
151159
this.mButton = this.GetComponent<Button>();
152160
this.mImage = this.GetComponent<Image>();
@@ -163,6 +171,11 @@ public void InitJCSButton()
163171

164172
// set the stating interactable.
165173
SetInteractable();
174+
175+
// part of the on click callback.
176+
SetSystemCallback(JCS_OnClickCallback);
177+
178+
this.mInitialized = true;
166179
}
167180

168181
/// <summary>
@@ -198,7 +211,12 @@ public virtual void JCS_ButtonClick()
198211
if (btnCallBackBtn != null)
199212
btnCallBackBtn.Invoke(this);
200213
}
201-
214+
215+
/// <summary>
216+
/// This is the callback when the button get click.
217+
/// </summary>
218+
public abstract void JCS_OnClickCallback();
219+
202220
/// <summary>
203221
/// Use this to enable and disable the button.
204222
/// </summary>

Assets/JCSUnity/Scripts/GUI/JCS_Buttons/Dialogue/JCS_HideDialogueButton.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ public class JCS_HideDialogueButton
3535
public bool HideithSound { get { return this.mHideWithSound; } set { this.mHideWithSound = value; } }
3636

3737

38-
public override void JCS_ButtonClick()
38+
public override void JCS_OnClickCallback()
3939
{
40-
base.JCS_ButtonClick();
41-
42-
4340
foreach (JCS_DialogueObject dialogue in mDialoguesToHide)
4441
{
4542
if (mHideWithSound)

Assets/JCSUnity/Scripts/GUI/JCS_Buttons/Dialogue/JCS_HideDialogueGamePadButton.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ public class JCS_HideDialogueGamePadButton
3434
public bool HideithSound { get { return this.mHideWithSound; } set { this.mHideWithSound = value; } }
3535

3636

37-
public override void JCS_ButtonClick()
37+
public override void JCS_OnClickCallback()
3838
{
39-
base.JCS_ButtonClick();
40-
41-
4239
foreach (JCS_DialogueObject dialogue in mDialoguesToHide)
4340
{
4441
if (mHideWithSound)

Assets/JCSUnity/Scripts/GUI/JCS_Buttons/Dialogue/JCS_ShowDialogueButton.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ public class JCS_ShowDialogueButton
3636
public bool ShowWithSound { get { return this.mShowWithSound; } set { this.mShowWithSound = value; } }
3737

3838

39-
public override void JCS_ButtonClick()
39+
public override void JCS_OnClickCallback()
4040
{
41-
base.JCS_ButtonClick();
42-
43-
4441
foreach (JCS_DialogueObject dialogue in mDialoguesToShow)
4542
{
4643
if (mShowWithSound)

Assets/JCSUnity/Scripts/GUI/JCS_Buttons/Dialogue/JCS_ShowDialogueGamePadButton.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ public class JCS_ShowDialogueGamePadButton
3535
public bool ShowWithSound { get { return this.mShowWithSound; } set { this.mShowWithSound = value; } }
3636

3737

38-
public override void JCS_ButtonClick()
38+
public override void JCS_OnClickCallback()
3939
{
40-
base.JCS_ButtonClick();
41-
42-
4340
foreach (JCS_DialogueObject dialogue in mDialoguesToShow)
4441
{
4542
if (mShowWithSound)

0 commit comments

Comments
 (0)