Page 3 of 3

Re: Don't Disable Response Menu and Global Delay

Posted: Sun Feb 09, 2020 4:10 pm
by bubucha
I think the example does work the way I want it to.

Re: Don't Disable Response Menu and Global Delay

Posted: Sun Feb 09, 2020 4:12 pm
by Tony Li
Okay, cool. I'll rework it to more closely mimic the setup in your video. I have to step out of the office for an hour, but I'll set it up when I get back and post it here.

Re: Don't Disable Response Menu and Global Delay

Posted: Sun Feb 09, 2020 8:01 pm
by Tony Li
I saw from your video that you're using a continue button. That made it a little trickier. You can't use a Sequence to time the hiding and delay since you don't know when the player is going to click the continue button. This example works a bit differently:

DS_TestHideDelay_2020-02-09.unitypackage

The Dialogue Manager no longer has a special script with an OnConversationLine method.

The subtitle panels still use a custom subclass that doesn't deactivate the panel.

The dialogue UI itself now uses a custom subclass that delays the calls to ShowSubtitle and ShowResponses when appropriate.

You can probably use the scripts as-is, although you may want to rename them. I included some comments in the code to explain what it does.

Re: Don't Disable Response Menu and Global Delay

Posted: Mon Feb 10, 2020 10:06 am
by bubucha
Hey hey!

It's finally done!
https://www.dropbox.com/s/9pv3zyzcq2r6e7a/Done.mp4?dl=0

Your code was delaying the Show animation, but the text was not delayed. But, I managed to get it done using your approach. In case you wonder, here it is:

Code: Select all

	private const float DELAY = 0.55f;
	private bool hasShownSubtitle;
	private int lastSpeakerId;
	private StandardUISubtitlePanel lastSubtitlePanel;
	private StandardUIMenuPanel lastMenuPanel;
	private Coroutine typeWriterDelay;
	private float typeWriterSpeed;
	
	public override void ShowSubtitle(Subtitle subtitle)
	{
		var panel = subtitle.speakerInfo.isNPC
			? conversationUIElements.defaultNPCSubtitlePanel
			: conversationUIElements.defaultPCSubtitlePanel;
		var isSameSpeakerSamePanel = panel == lastSubtitlePanel && subtitle.speakerInfo.id == lastSpeakerId &&
		                             lastMenuPanel == null;
		if (hasShownSubtitle && !isSameSpeakerSamePanel)
		{
			typeWriterSpeed = panel.GetTypewriterSpeed();
			panel.SetTypewriterSpeed(0);
			typeWriterDelay = StartCoroutine(StartTypingAfterDelay(panel));
		}

		base.ShowSubtitle(subtitle);
		hasShownSubtitle = true;
		lastSpeakerId = subtitle.speakerInfo.id;
		lastSubtitlePanel = panel;
		lastMenuPanel = null;
	}

	private IEnumerator StartTypingAfterDelay(StandardUISubtitlePanel panel)
	{
		yield return new WaitForSeconds(DELAY);
		panel.SetTypewriterSpeed(typeWriterSpeed);
		panel.GetTypewriter().Start();
		typeWriterDelay = null;
	}

	public override void HideSubtitle(Subtitle subtitle)
	{
		var nextLine = DialogueManager.currentConversationState.firstNPCResponse ??
		               DialogueManager.currentConversationState.pcAutoResponse;
		var endOfConversation = !DialogueManager.currentConversationState.hasAnyResponses;
		if (hasShownSubtitle &&
		    (nextLine == null || nextLine.destinationEntry.ActorID != lastSpeakerId || endOfConversation))
		{
			base.HideSubtitle(subtitle);
		}
	}

	public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
	{
		base.ShowResponses(subtitle, responses, timeout);
		if (lastSubtitlePanel)
		{
			lastSubtitlePanel.Close();
		}

		lastSpeakerId = -1;
		lastSubtitlePanel = null;
		lastMenuPanel = conversationUIElements.defaultMenuPanel;
	}
I had to Close the lastSubtitlePanel in ShowResponses because it was still opened when responses were shown, but yeah, it just works.
Thanks a lot for your time and effort! The tool is actually great, especially the editor.

Re: Don't Disable Response Menu and Global Delay

Posted: Mon Feb 10, 2020 10:19 am
by Tony Li
Thanks!

And thank you for your patience, and for sharing that code in case it's helpful for others in the future. I'm glad it's working now. :-)