Choose Dialogue Panel Based on State

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Choose Dialogue Panel Based on State

Post by VoodooDetective »

I was just wondering if it's possible to have game state driven logic dictate which dialogue panel opens. The specific use case for our game is, when the inventory is open, I'd like to have a specific dialogue panel such that it doesn't overlap with the inventory UI.

I could go through and find all conversations in the database that are recited while the inventory is open, but I think a more elegant solution (if possible) would be to check game state and decided based on that. Just curious if there's a built in hook to do that kind of thing?
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: Choose Dialogue Panel Based on State

Post by Tony Li »

Hi,

Yes. The upcoming metroidvania Gestalt: Steam & Cinder does that by subclassing StandardDialogueUI. It uses an OnConversationStart method, but you could override Open() to do the same.

In Gestalt, there are 3 sets of UI panels. The OnConversationStart method calls conversationUIElements.standardSubtitleControls.OverrideActorPanel() on each participant based on these rules:
  • If any of the participants have portrait images, it uses the "regular" UI with text at the bottom and portraits on the left and right.
  • If no participants have portrait images, then if the player avatar is in the bottom half of the screen, it uses a portraitless UI that's at the top of the screen.
  • If the player avatar is in the top half of the screen, it uses a different portraitless UI that's at the bottom of the screen.
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: Choose Dialogue Panel Based on State

Post by VoodooDetective »

Oh awesome! I think this will work perfectly.
I just noticed something that might be a bug in StandardUISubtitleControls:

Code: Select all

        public void OverrideActorPanel(Actor actor, SubtitlePanelNumber subtitlePanelNumber, StandardUISubtitlePanel customPanel = null)
        {
            if (actor == null) return;
            if (customPanel == null) customPanel = actor.IsPlayer ? m_defaultPCPanel : m_defaultNPCPanel;
            m_actorIdOverridePanel[actor.id] = GetPanelFromNumber(subtitlePanelNumber, customPanel);
        }
If you call this:

Code: Select all

conversationUIElements.standardSubtitleControls.OverrideActorPanel(<an actor>, SubtitlePanelNumber.Default)
You end up doing this:

Code: Select all

 m_actorIdOverridePanel[actor.id] = null; 
Based on the return value in GetPanelFromNumber().

Later on that causes trouble on line 164:

Code: Select all

            // Check actor ID override:
            if (m_actorIdOverridePanel.ContainsKey(subtitle.speakerInfo.id))
            {
                var overridePanel = m_actorIdOverridePanel[subtitle.speakerInfo.id];
                overridePanel.actorOverridingPanel = subtitle.speakerInfo.transform; <-- NPE
                return overridePanel;
            }


Is there a better way to unset an override?

This is my workaround:

Code: Select all

        /// <summary>
        /// For speakers who do not have DialogueActor components, this method overrides the
        /// actor's default panel.
        /// </summary>
        public void OverrideActorPanel(Actor actor, SubtitlePanelNumber subtitlePanelNumber, StandardUISubtitlePanel customPanel = null)
        {
            if (actor == null) return;
            if (customPanel == null) customPanel = actor.IsPlayer ? m_defaultPCPanel : m_defaultNPCPanel;
            // TODO
            // https://www.pixelcrushers.com/phpbb/viewtopic.php?f=3&t=4564&p=25651#p25651
            StandardUISubtitlePanel panel = GetPanelFromNumber(subtitlePanelNumber, customPanel);
            if (panel == null) m_actorIdOverridePanel.Remove(actor.id);
            else m_actorIdOverridePanel[actor.id] = GetPanelFromNumber(subtitlePanelNumber, customPanel);
        }
User avatar
Tony Li
Posts: 22161
Joined: Thu Jul 18, 2013 1:27 pm

Re: Choose Dialogue Panel Based on State

Post by Tony Li »

Hi,

Thanks for reporting the bug. I put basically the same code in a patch:

DS_SubtitleControlsPatch_2021-06-09.unitypackage

The change will also be in version 2.2.18, which I plan to release before June 22.
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: Choose Dialogue Panel Based on State

Post by VoodooDetective »

Awesome! Thanks so much for the help!
Post Reply