Page 2 of 2

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

Posted: Mon Feb 14, 2022 9:57 pm
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!

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

Posted: Tue Feb 15, 2022 8:50 am
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.

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

Posted: Tue Feb 15, 2022 4:05 pm
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

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

Posted: Tue Feb 15, 2022 4:16 pm
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;
}