Super Text Mesh: Issues while manually calling UnRead()

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Lollie
Posts: 11
Joined: Tue May 12, 2020 7:47 am

Super Text Mesh: Issues while manually calling UnRead()

Post by Lollie »

One thing I've felt while using the native STM support in Dialogue System, is that STM's UnRead() function doesn't seem to get called by the packaged scripts, so it has to be called manually. I've had some luck here - namely, hooking up the continue button's "On Click" event and the STM subtitle text's "On Undrawn" event like the screenshots below.
Unity_20200513_03-25-35-863.png
Unity_20200513_03-25-35-863.png (81.86 KiB) Viewed 1037 times
(I also had to disable/enable the continue button manually - included scripts don't seem to do this when STM is used.)

However, I cannot figure out how to make UnRead() work correctly after selecting a Standard Menu UI dialogue option. I've tried hooking it up via the button's "On Click" event and the Menu UI script's "On Close" event, but neither seem to do the trick. It feels like STM's Rebuild() gets called immediately after selecting an option.
Last edited by Lollie on Sat May 16, 2020 7:39 am, edited 2 times in total.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Tony Li »

Hi,

You can replace the response button's StandardUIResponseButton script with this one:

STMResponseButton.cs

Code: Select all

public class STMResponseButton : PixelCrushers.DialogueSystem.StandardUIResponseButton
{
    public override void OnClick()
    {
        GetComponentInChildren<SuperTextMesh>().UnRead();
        base.OnClick();
    }
}
It will call UnRead() before telling the dialogue UI that the button has been clicked.
User avatar
Lollie
Posts: 11
Joined: Tue May 12, 2020 7:47 am

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Lollie »

Sorry, I wasn't clear — I'm trying to set up my UI so that once a response is selected, the subtitle text plays its UnRead animation.

Here's a gif as an example. Line one unreads correctly (using the setup in my first screenshot above) and plays an animation before continuing. But line two simply disappears after selecting a response, showing the next line immediately.
ezgif-2-499d39081981.gif
ezgif-2-499d39081981.gif (67.11 KiB) Viewed 1032 times
My response button is set up with the same event as the continue button, but this doesn't appear to be the solution. Adding this "UnRead" event to the Standard UI Menu Panel's "On Close" event instead also doesn't fix this.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Tony Li »

Hi,

Replace the StandardUIResponseButton component with this one and assign the Subtitle Text field:

TestResponseButton.cs

Code: Select all

using System.Collections;
using UnityEngine;

public class TestResponseButton : PixelCrushers.DialogueSystem.StandardUIResponseButton
{
    public SuperTextMesh subtitleText;

    public override void OnClick()
    {
        StartCoroutine(UnReadThenClick());
    }

    IEnumerator UnReadThenClick()
    { 
        subtitleText.UnRead();
        yield return new WaitForSeconds(subtitleText.totalUnreadTime);
        base.OnClick();
    }
}
User avatar
Lollie
Posts: 11
Joined: Tue May 12, 2020 7:47 am

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Lollie »

That did it, thank you so much!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Tony Li »

Glad to help!
User avatar
digiwombat
Posts: 50
Joined: Sun Jun 16, 2019 4:59 am

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by digiwombat »

Also, since no on asked, but I'm on this forum posting other things, here's my STMFastForward script for Continue buttons that handles overflow text if there is any:

Code: Select all

public class STMFastForward : PixelCrushers.DialogueSystem.StandardUIContinueButtonFastForward
{
	public SuperTextMesh targetTextMesh;


	public override void OnFastForward()
	{
		if(!string.IsNullOrWhiteSpace(targetTextMesh.leftoverText) && !targetTextMesh.reading)
		{
			targetTextMesh.Continue();

		}
		else if(targetTextMesh != null && targetTextMesh.reading)
		{
			targetTextMesh.SpeedRead();
		}
		else
		{
			base.OnFastForward();
		}
	}

}
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Tony Li »

Thanks! :-)
User avatar
Lollie
Posts: 11
Joined: Tue May 12, 2020 7:47 am

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Lollie »

digiwombat wrote: Thu May 14, 2020 10:22 amAlso, since no on asked, but I'm on this forum posting other things, here's my STMFastForward script for Continue buttons that handles overflow text if there is any:
This is great, thank you!

I ended up adding a couple tiny patches to both scripts - one to add Tony's Unread() code to your script, but also because I found it was possible to spam the continue/response buttons during UnRead(), which would cause Unread() to play repeatedly.

STMResponseButton.cs

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// https://www.pixelcrushers.com/phpbb/viewtopic.php?f=3&t=3147
public class STMResponseButton : PixelCrushers.DialogueSystem.StandardUIResponseButton
{
	public SuperTextMesh targetTextMesh;

	private bool noMoreClick;

	public override void OnClick()
	{
		if(!noMoreClick){
			StartCoroutine(UnReadThenClick());
			noMoreClick = true;
		}
	}

	IEnumerator UnReadThenClick()
	{ 
		targetTextMesh.UnRead();
		yield return new WaitForSeconds(targetTextMesh.totalUnreadTime);
		base.OnClick();
		noMoreClick = false;
	}
}
STMFastForward.cs (edited to include patch-fix for the post below)

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;

// https://www.pixelcrushers.com/phpbb/viewtopic.php?f=3&t=3147
public class STMFastForward : PixelCrushers.DialogueSystem.StandardUIContinueButtonFastForward
{
	public SuperTextMesh targetTextMesh;

	private bool noMoreClick;

	private UnityEngine.UI.Button contButton;

	public override void Awake()
	{
		contButton = GetComponent<UnityEngine.UI.Button>();
		base.Awake();
	}

	public override void OnFastForward()
	{
		var state = DialogueManager.currentConversationState;
		
		if(!string.IsNullOrWhiteSpace(targetTextMesh.leftoverText) && !targetTextMesh.reading)
		{
			targetTextMesh.Continue();
		}
		else if(targetTextMesh != null && targetTextMesh.reading)
		{
			targetTextMesh.SpeedRead();
		}
		else
		{
			if(state.hasPCResponses && !state.hasForceAutoResponse)
			{
				contButton.interactable = false;
			}
			else if(!state.hasPCResponses)
			{
				if(!noMoreClick){
					noMoreClick = true;
					StartCoroutine(UnReadThenFastForward());
				}
			}
		}
	}

	IEnumerator UnReadThenFastForward()
	{ 
		targetTextMesh.UnRead();
		yield return new WaitForSeconds(targetTextMesh.totalUnreadTime);
		base.OnFastForward();
		noMoreClick = false;
		contButton.interactable = true;
	}
}
Last edited by Lollie on Sat May 16, 2020 10:18 am, edited 1 time in total.
User avatar
Lollie
Posts: 11
Joined: Tue May 12, 2020 7:47 am

Re: Super Text Mesh: Issues while manually calling UnRead()

Post by Lollie »

One more quick question actually: Is there a way to check if the current line has a response menu? I think Digiwombat's fast forward script needs an additional Else If check, to ensure that UnRead() can't be called before the response menu has a chance to open. (Dialogue System Manager's "Continue Button" setting doesn't affect the button for some reason.)
Post Reply