Inserting a Canvas UI in the middle of a dialogue

Announcements, support questions, and discussion for the Dialogue System.
HunterTom
Posts: 18
Joined: Fri Dec 24, 2021 4:58 pm

Re: Inserting a Canvas UI in the middle of a dialogue

Post by HunterTom »

Thanks for your answer! I think I am almost there! Everything else has been working other than one final glitch.

I used your code and wrapped it inside a function

Code: Select all

void ResumeDialogueContinueButton()
        {
            DialogueActor actor;
            var subtitle = DialogueManager.currentConversationState.subtitle;
            var subtitleControls = DialogueManager.standardDialogueUI.conversationUIElements.standardSubtitleControls;
            var panel = subtitleControls.GetPanel(subtitle, out actor);
            var continueButton = panel.continueButton;

            if (continueButton != null) continueButton.interactable = true;
            if (continueButton.GetComponent<UIButtonKeyTrigger>())
                continueButton.GetComponent<UIButtonKeyTrigger>().enabled = true;
        }
I call ResumeDialogueContinueButton() together with the code that closes the getItemUI. (I have a button in the getItemUI and the onclicklistener for that button contains code to close the UI and calls ResumeDialogueContinueButton)

However, I found something weird.

The moment I close the UI, the conversation would move forward one node. If I comment out the line that calls ResumeDialogueContinueButton, the UI closes and the conversation will not go forward but the continue button wouldn't work either.

If I hold the left mouse a bit (several seconds in between the mouse down and mouse up), the mouse up action will only close the UI and continue button also resumes function, and the conversation will not go forward. If I just do a normal click, the UI closes, continue button resumes, but conversation will go forward.

Can you help me on this one please? I don't understand how resuming the continue button would move the conversation node forward, and I also do not understand why holding the mouse for a few second would make that difference.

Thank you very much!
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Inserting a Canvas UI in the middle of a dialogue

Post by Tony Li »

Does your continue button have a UI Button Key Trigger that's mapped to mouse clicks? If so, unmap that. Only map UI Button Key Trigger to keys such as "E" -- unless you're also using "E" to dismiss your message box. If so, then you'll need to wait one frame before re-enabling the continue button. Otherwise, on the frame in which you dismiss the message box, the continue button will read the same input that dismissed the message box and use it to also click the button. To address that, change the CloseMessageBox() method to:

Code: Select all

        private void CloseMessageBox()
        {
            messagePanel.SetActive(false);
            StartCoroutine(EnableContinueButtonNextFrame());
        }

        IEnumerator EnableContinueButtonNextFrame()
        {
            yield return null;
            if (continueButton != null)
            {
                continueButton.interactable = true; //[EDIT: Fixed typo. Thanks, HunterTom!]
                if (continueButton.GetComponent<UIButtonKeyTrigger>()) continueButton.GetComponent<UIButtonKeyTrigger>().enabled = false;
            }
        }
and add "using System.Collections;" to the top of your script.
HunterTom
Posts: 18
Joined: Fri Dec 24, 2021 4:58 pm

Re: Inserting a Canvas UI in the middle of a dialogue

Post by HunterTom »

Thank you very much!

I used the coroutine and it worked, although I have to change

Code: Select all

yield return null;
to

Code: Select all

yield return new WaitForSeconds(0.05f);
BTW, I just noticed that I actually set my continue button game object to be not active the whole time (I just didn't want it to show up), but somehow the UI Button Key Trigger component on that continue object was still working. Your code's

Code: Select all

if (continueButton != null)
            {
                continueButton.interactable = false;
                if (continueButton.GetComponent<UIButtonKeyTrigger>()) continueButton.GetComponent<UIButtonKeyTrigger>().enabled = false;
            }
also worked. Is that normal?

Also for future / other people's reference, the

Code: Select all

false
in the above code block should be

Code: Select all

true
User avatar
Tony Li
Posts: 22152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Inserting a Canvas UI in the middle of a dialogue

Post by Tony Li »

Thanks. I fixed that typo.

The UIButtonKeyTrigger thing is strange. If it's disabled, it shouldn't check for input.

Another way to handle it, and perhaps a better way, is to tell all UIButtonKeyTriggers to stop listening for hotkeys:

Code: Select all

if (continueButton != null)
{
    continueButton.interactable = false;
    UIButtonKeyTrigger.monitorInput = false;
}
Post Reply