Skip to content

Commit

Permalink
feat: Expose dialogue system's variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Aug 6, 2024
1 parent 327fdaf commit dc34f07
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.382}
m_RaycastTarget: 0
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
Expand Down
2 changes: 1 addition & 1 deletion Assets/JCSUnity/Resources/UI/JCS_DialogueSystem.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.382}
m_RaycastTarget: 0
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
Expand Down
1 change: 1 addition & 0 deletions Assets/JCSUnity/Scenes/Utilities/JCS_ScriptTester.unity
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ MonoBehaviour:
mTestDialogueScript: {fileID: 1098634727}
DisposeKey: 113
RunScriptKey: 119
SkipKey: 101
--- !u!4 &1098634726
Transform:
m_ObjectHideFlags: 0
Expand Down
3 changes: 3 additions & 0 deletions Assets/JCSUnity/Scripts/Examples/JCS_ScriptTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class JCS_ScriptTester : MonoBehaviour
public KeyCode DisposeKey = KeyCode.Q;
public KeyCode RunScriptKey = KeyCode.W;

public KeyCode SkipKey = KeyCode.E;

/* Setter & Getter */

Expand All @@ -53,6 +54,8 @@ private void Update()
mDialogueSystem.Dispose();
if (JCS_Input.GetKeyDown(RunScriptKey))
mDialogueSystem.ActiveDialogue(mTestDialogueScript);
if (JCS_Input.GetKeyDown(SkipKey))
print(mDialogueSystem.SkipToEnd());
}
}
}
Expand Down
65 changes: 52 additions & 13 deletions Assets/JCSUnity/Scripts/UI/Dialogue/JCS_DialogueSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public class JCS_DialogueSystem : MonoBehaviour

/* Setter & Getter */

public bool Active { get { return this.mActive; } }
public bool Scrolling { get { return this.mScrolling; } }
public bool ScrollingSelectBtnText { get { return this.mScrollingSelectBtnText; } }
public bool Skip { get { return this.mSkip; } }

public bool MakeHoverSelect { get { return this.mMakeHoverSelect; } set { this.mMakeHoverSelect = value; } }
public JCS_DeltaTimeType DeltaTimeType { get { return this.mDeltaTimeType; } set { this.mDeltaTimeType = value; } }
public JCS_DialogueScript DialogueScript { get { return this.mDialogueScript; } set { this.mDialogueScript = value; } }
Expand Down Expand Up @@ -236,7 +241,7 @@ public void ActiveDialogue(JCS_DialogueScript script)

if (mActive)
{
JCS_Debug.LogError("Dialogue System is already active... Failed to active another one.");
JCS_Debug.LogError("Dialogue System is already active!");
return;
}

Expand Down Expand Up @@ -484,7 +489,6 @@ public void Dispose()
// disable the exit button!
ExitBtnActive(false);


// dis-attach the script.
mDialogueScript = null;

Expand Down Expand Up @@ -556,7 +560,7 @@ public void SendNameTag(string name)
#if UNITY_EDITOR
if (mNameTag == null)
{
JCS_Debug.LogError("Name tag is not assign but u still trying to access?");
JCS_Debug.LogError("Name tag doesn't exist!");
return;
}
#endif
Expand All @@ -575,7 +579,7 @@ public void SendCenterImage(Sprite sprite)
#if UNITY_EDITOR
if (mCenterImage == null)
{
JCS_Debug.LogError("Center image call with image component attached");
JCS_Debug.LogError("Image (center) doesn't exist");
return;
}
#endif
Expand All @@ -593,7 +597,7 @@ public void SendLeftImage(Sprite sprite)
#if UNITY_EDITOR
if (mLeftImage == null)
{
JCS_Debug.LogError("Left image call with image component attached");
JCS_Debug.LogError("Image (left) doesn't exist");
return;
}
#endif
Expand All @@ -611,7 +615,7 @@ public void SendRightImage(Sprite sprite)
#if UNITY_EDITOR
if (mRightImage == null)
{
JCS_Debug.LogError("Right image call with image component attached");
JCS_Debug.LogError("Image (right) doesn't exist");
return;
}
#endif
Expand Down Expand Up @@ -649,6 +653,29 @@ public void NextOrDispose()
Dispose();
}

/// <summary>
/// Return true if the dialogue system is still animating the text.
/// </summary>
public bool IsScrolling()
{
return this.mScrolling || this.mScrollingSelectBtnText;
}

/// <summary>
/// Skip the current text scroll.
/// </summary>
public bool SkipToEnd()
{
if (IsScrolling())
{
mSkip = true;

return true;
}

return false;
}

/// <summary>
/// Do scroll text action.
/// </summary>
Expand All @@ -667,7 +694,7 @@ private void ScrollText()
return;

// reset timer
mScrollTimer = 0;
mScrollTimer = 0.0f;

if (mMessage == mTextBox.text)
{
Expand All @@ -684,6 +711,7 @@ private void ScrollText()

// reset text index counter
mTextIndex = 0;

return;
}

Expand All @@ -692,6 +720,9 @@ private void ScrollText()
// set directly to the text box.
mTextBox.text = mMessage;

// set the rest to the selections.
CompleteSelectionsScroll();

mSkip = false;

// end effect.
Expand Down Expand Up @@ -723,7 +754,7 @@ private void ScrollSelectBtnText()
return;

// reset timer
mScrollTimer = 0;
mScrollTimer = 0.0f;

if (mSelectBtn.Length <= mRenderSelectTextIndex)
{
Expand All @@ -736,7 +767,6 @@ private void ScrollSelectBtnText()
return;
}


if (// if the text in not active skip it, and render the
// next possible active selection.
!mSelectBtn[mRenderSelectTextIndex].gameObject.activeSelf
Expand All @@ -760,9 +790,8 @@ private void ScrollSelectBtnText()

if (mSkip)
{
// set directly to the text box.
mSelectBtn[mRenderSelectTextIndex].ButtonText.text
= mSelectMessage[mRenderSelectTextIndex];
// set the rest to the selections.
CompleteSelectionsScroll();

mSkip = false;

Expand All @@ -780,6 +809,17 @@ private void ScrollSelectBtnText()
++mSelectTextIndex;
}

/// <summary>
/// Complete the selection scroll text immediately.
/// </summary>
private void CompleteSelectionsScroll()
{
for (int index = mRenderSelectTextIndex; index < mSelectBtn.Length; ++index)
{
mSelectBtn[index].ButtonText.text = mSelectMessage[index];
}
}

/// <summary>
/// Active the panel?
/// </summary>
Expand Down Expand Up @@ -1089,7 +1129,6 @@ private int FindSelectedButton()
return -1;
}


/// <summary>
/// What if "Next Button" clicked?
/// </summary>
Expand Down

0 comments on commit dc34f07

Please sign in to comment.