Skip to content

Commit a1a9e56

Browse files
committed
feat(UI): Add on next or dispose condition
1 parent f6082bd commit a1a9e56

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

Assets/JCSUnity/Prefabs.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ public class JCS_DialogueSystem : MonoBehaviour
2020
{
2121
/* Variables */
2222

23+
// Callback when successfully dispose the dialogue.
24+
public EmptyFunction onDispose = null;
25+
26+
// Callback determine when the dialogue system suppose to be
27+
// disposed when executing the function `NextOrDispose`.
28+
public EmptyBoolFunction onNextOrDisposeCondition = null;
29+
2330
private bool mInitialized = false;
2431

2532
private JCS_DialogueScript mPreselectingScript = null;
2633

27-
// Callback when successfully dispose the dialogue.
28-
public EmptyFunction onDispose = null;
29-
3034
[Separator("Check Variables (JCS_DialogueSystem)")]
3135

3236
[Tooltip("Script to run the current text box.")]
@@ -805,7 +809,7 @@ public bool Previous()
805809
if (SkipToEnd(mCompleteTextBeforeAction))
806810
return false;
807811

808-
PreviousBtnCallback();
812+
OnPreviousBtn();
809813

810814
return true;
811815
}
@@ -827,7 +831,7 @@ public bool Next()
827831
if (SkipToEnd(mCompleteTextBeforeAction))
828832
return false;
829833

830-
NextBtnCallback();
834+
OnNextBtn();
831835

832836
return true;
833837
}
@@ -841,9 +845,14 @@ public bool NextOrDispose()
841845
if (!Next())
842846
return false;
843847

844-
if (mMessage == "")
848+
bool dispose = (onNextOrDisposeCondition != null) ?
849+
onNextOrDisposeCondition.Invoke() :
850+
mMessage == ""; // The fallback condition; when text is empty.
851+
852+
if (dispose)
845853
{
846854
Dispose();
855+
847856
return false;
848857
}
849858

@@ -1232,28 +1241,28 @@ private void ClearSelectBtnMessage()
12321241
private void InitBtnsSet()
12331242
{
12341243
if (mOkBtn != null)
1235-
mOkBtn.SetSystemCallback(OkBtnCallback);
1244+
mOkBtn.SetSystemCallback(OnOkBtn);
12361245

12371246
if (mNoBtn != null)
1238-
mNoBtn.SetSystemCallback(NoBtnCallback);
1247+
mNoBtn.SetSystemCallback(OnNoBtn);
12391248

12401249
if (mYesBtn != null)
1241-
mYesBtn.SetSystemCallback(YesBtnCallback);
1250+
mYesBtn.SetSystemCallback(OnYesBtn);
12421251

12431252
if (mNextBtn != null)
1244-
mNextBtn.SetSystemCallback(NextBtnCallback);
1253+
mNextBtn.SetSystemCallback(OnNextBtn);
12451254

12461255
if (mPreviousBtn != null)
1247-
mPreviousBtn.SetSystemCallback(PreviousBtnCallback);
1256+
mPreviousBtn.SetSystemCallback(OnPreviousBtn);
12481257

12491258
if (mExitBtn != null)
1250-
mExitBtn.SetSystemCallback(ExitBtnCallback);
1259+
mExitBtn.SetSystemCallback(OnExitBtn);
12511260

12521261
if (mAcceptBtn != null)
1253-
mAcceptBtn.SetSystemCallback(AcceptBtnCallback);
1262+
mAcceptBtn.SetSystemCallback(OnAcceptBtn);
12541263

12551264
if (mDeclineBtn != null)
1256-
mDeclineBtn.SetSystemCallback(DeclineBtnCallback);
1265+
mDeclineBtn.SetSystemCallback(OnDeclineBtn);
12571266

12581267
for (int index = 0; index < mSelectBtn.Length; ++index)
12591268
{
@@ -1268,8 +1277,8 @@ private void InitBtnsSet()
12681277
{
12691278
if (btn.ButtonSelection == null)
12701279
{
1271-
JCS_Debug.LogWarning(@"Cannot make hover select because
1272-
button selection is not attach to all selections in the list!");
1280+
JCS_Debug.LogWarning(@"Cannot make hover select
1281+
because button selection is not attach to all selections in the list!");
12731282
}
12741283
else
12751284
{
@@ -1332,7 +1341,7 @@ private int FindSelectedButton()
13321341
/// <summary>
13331342
/// Callback for button `Next`.
13341343
/// </summary>
1335-
private void NextBtnCallback()
1344+
private void OnNextBtn()
13361345
{
13371346
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
13381347
return;
@@ -1341,10 +1350,11 @@ private void NextBtnCallback()
13411350

13421351
RunAction();
13431352
}
1353+
13441354
/// <summary>
13451355
/// Callback for button `Previous`.
13461356
/// </summary>
1347-
private void PreviousBtnCallback()
1357+
private void OnPreviousBtn()
13481358
{
13491359
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
13501360
return;
@@ -1353,10 +1363,11 @@ private void PreviousBtnCallback()
13531363

13541364
RunAction();
13551365
}
1366+
13561367
/// <summary>
13571368
/// Callback for button `Yes`.
13581369
/// </summary>
1359-
private void YesBtnCallback()
1370+
private void OnYesBtn()
13601371
{
13611372
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
13621373
return;
@@ -1366,10 +1377,11 @@ private void YesBtnCallback()
13661377

13671378
RunAction();
13681379
}
1380+
13691381
/// <summary>
13701382
/// Callback for button `No`.
13711383
/// </summary>
1372-
private void NoBtnCallback()
1384+
private void OnNoBtn()
13731385
{
13741386
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
13751387
return;
@@ -1379,26 +1391,29 @@ private void NoBtnCallback()
13791391

13801392
RunAction();
13811393
}
1394+
13821395
/// <summary>
13831396
/// Callback for button `Ok`.
13841397
/// </summary>
1385-
private void OkBtnCallback()
1398+
private void OnOkBtn()
13861399
{
13871400
// when exit button happens, exit the dialogue box.
13881401
Dispose();
13891402
}
1403+
13901404
/// <summary>
13911405
/// Callback for button `Exit`.
13921406
/// </summary>
1393-
private void ExitBtnCallback()
1407+
private void OnExitBtn()
13941408
{
13951409
// when exit button happens, exit the dialogue box.
13961410
Dispose();
13971411
}
1412+
13981413
/// <summary>
13991414
/// Callback for button `Accept`.
14001415
/// </summary>
1401-
private void AcceptBtnCallback()
1416+
private void OnAcceptBtn()
14021417
{
14031418
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
14041419
return;
@@ -1408,10 +1423,11 @@ private void AcceptBtnCallback()
14081423

14091424
RunAction();
14101425
}
1426+
14111427
/// <summary>
14121428
/// Callback for button `Decline`.
14131429
/// </summary>
1414-
private void DeclineBtnCallback()
1430+
private void OnDeclineBtn()
14151431
{
14161432
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
14171433
return;
@@ -1421,10 +1437,11 @@ private void DeclineBtnCallback()
14211437

14221438
RunAction();
14231439
}
1440+
14241441
/// <summary>
14251442
/// Callback for button `Select`.
14261443
/// </summary>
1427-
private void SelectBtnCallback()
1444+
private void OnSelectBtn()
14281445
{
14291446
if (SkipToEnd(mCompleteTextBeforeActionOnButton))
14301447
return;
@@ -1438,7 +1455,7 @@ private void SelectBtnCallback()
14381455
private void SelectionInt(int selection)
14391456
{
14401457
Selection = selection;
1441-
SelectBtnCallback();
1458+
OnSelectBtn();
14421459
}
14431460

14441461
/// <summary>

0 commit comments

Comments
 (0)