Condition Icon in Response Button

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
FlaconiaUnited
Posts: 14
Joined: Fri Oct 02, 2020 2:07 pm

Condition Icon in Response Button

Post by FlaconiaUnited »

Hello!

The scenarios in my game have multiple choices the player can activate in response to the situation.

In some scenarios, the choices' consequences depend on the player's stats (Strength, Wisdom, Charm), and therefore can have different outcomes.

I'd like to indicate this by having an image inside the response button with the icon of the stat taken into consideration with that choice.
So I put an image in the Response button template with the Strength icon in it, that I would like to activate only when that specific istantiated response button is a choice that evaluates Strength for the outcome.

I thought I might indicate in the "Description" field of the entry, which is now unused, what stat I want to show the icon of when the button is shown to the player.. for example by writing STR in it.
_
__________
_
I tried starting a custom script in the Response Button template (my UI system is still basically the same as the StandardDialogueUI that came with the Dialogue System plugin), where I try to access the dialogue entry pointed by the response button, to read for example the "Description" field where I might indicate which stat do I want to show the icon of, but I cannot seem to find the way the button knows which entry to point to :?
Is this even an idea that makes sense?

Is there any other way to do this without coding?
I don't mind adding things like scripts or sequencer commands to every single entry in my game that needs an icon, to show it, as long as it does what I need...
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Condition Icon in Response Button

Post by Tony Li »

Hi,

Make a subclass of StandardUIResponseButton. Add a method to set the stat image. Example:

Code: Select all

public class MyResponseButton : StandardUIResponseButton
{
    public GameObject STR_Image; // Assign in inspector.
    public GameObject INT_Image;
    public GameObject DEX_image;
    
    public void SetStatImage(string statName)
    {
        STR_Image.SetActive(stateName == "STR");
        INT_Image.SetActive(stateName == "INT");
        DEX_Image.SetActive(stateName == "DEX");
    }
}
Assign this to your response button(s) or response button template, and assign the images in the inspector.

Then make a subclass of StandardUIMenuPanel. Override the SetResponseButton() method to check the response's Description and set the button's image. Example:

Code: Select all

public class MyMenuPanel : StandardUIMenuPanel
{
    protected override void SetResponseButton(StandardUIResponseButton button, Response response, Transform target, int buttonNumber)
    {
        base.SetResponseButton(button, response, target, buttonNumber);
        var statName = Field.LookupValue (response.destinationEntry.fields, "Description");
        (button as MyResponseButton).SetStatImage(statName);
    }
}
User avatar
FlaconiaUnited
Posts: 14
Joined: Fri Oct 02, 2020 2:07 pm

Re: Condition Icon in Response Button

Post by FlaconiaUnited »

Thanks so much for the help :D

It totally makes sense, I did everything you said, no errors or warning from the console, created the icons and gave their dependencies to the new sublasses in the Inspector, everything complies, but the weird result is my subclasses simply don't start.

I put a couple of Debug.Logs, one in the original StandardUIMenuPanel (inside the original SetResponseButton class) and the other one in MyMenuPanel (inside the overrriding SetResponseButton class) and only the original one shows the log.

Both the MenuPanel classes are attached to the same, only Response Menu Panel, with my sublcass coming last in the list of components.
Also both classes are active at the same time, and the subclasses we created are showing the same list of field and properties of the original ones.

Same thing with the StandardUIResponseButton and MyResponseButton. I initialise the Response Buttons from a single template, to which both the ResponseButton classes are attached to.

Am I missing something to setup?
They should enter the sublclasses everytime, right?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Condition Icon in Response Button

Post by Tony Li »

Hi,

Your subclass should replace the StandardUIMenuPanel and StandardUIResponseButton.

To replace a script in-place and retain all of its settings and field assignments, change the Inspector view to Debug mode by opening the triple-bar / triple-dot menu in the upper right and selecting Debug. Then drag your subclass script into the Script field to replace the old script.
User avatar
FlaconiaUnited
Posts: 14
Joined: Fri Oct 02, 2020 2:07 pm

Re: Condition Icon in Response Button

Post by FlaconiaUnited »

Ooh I see!

Well it totally works now!! You're amazing Toni, thanks so much! :lol:

I thought about the fact that my subclasses needed to replace the original ones, in fact I made a try by just deactivating the original class' component, but leaving it inside the GameObjects.
It didn't produce any different result, but I could still perfectly play the game, meaning that the original classes were still being executed. I don't know why though... shouldn't a deactivated script not be executed at all? :?
User avatar
Tony Li
Posts: 22051
Joined: Thu Jul 18, 2013 1:27 pm

Re: Condition Icon in Response Button

Post by Tony Li »

Hi,

No, because in that case the disabled script is assigned to the StandardDialogueUI component, so the StandardDialogueUI component will continue to try to use it.
User avatar
FlaconiaUnited
Posts: 14
Joined: Fri Oct 02, 2020 2:07 pm

Re: Condition Icon in Response Button

Post by FlaconiaUnited »

Tony Li wrote: Sun Nov 08, 2020 8:29 pm Hi,

No, because in that case the disabled script is assigned to the StandardDialogueUI component, so the StandardDialogueUI component will continue to try to use it.

Ah I see, there's some kind of security system for dummies like me :lol:
Useful infos, thanks.
Post Reply