[solved] VN - disable certain responses

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Cussa
Posts: 22
Joined: Sat Jun 03, 2023 3:50 am

[solved] VN - disable certain responses

Post by Cussa »

Hi,

I took a deep dive in the forum before posting this question, but as I didn't find the answer, I decided to open a new thread.

I want to have some responses being disabled (which the Show Invalid Responses handles), but I would like to have the option to hide some responses if their conditions are false.

As I am using the Visual Novel framework. From what I saw, it uses the `StandardUI` class. So, I basically got the examples that I found here in the forum (https://www.pixelcrushers.com/phpbb/vie ... 736#p12605 , https://www.pixelcrushers.com/phpbb/vie ... 3&start=10 , https://www.pixelcrushers.com/phpbb/vie ... alid#p6114) and tried to apply then.

Basically I created a new class that inherats the StandardUi (which is the one that VN is using) and tried to use the code mentioned. However, it seems that the VN framework is not respecting the new field "Show Invalid", is I set it to false, but the button is still show in the UI.

Could you please help me?

Maybe it's because the VN works different, but the proposed solution for the normal UI is not working.

Many thanks.
Last edited by Cussa on Fri Jul 07, 2023 3:37 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: VN - disable certain responses

Post by Tony Li »

Hi,

The VN starter framework doesn't do anything special with its dialogue UI, so it should work fine with custom code that uses a "Show Invalid" field.

The example script in that first link uses this logic:
  • The conversation assumes the Dialogue Manager's "Include Invalid Entries" is ticked.
  • The conversation evaluates all linked dialogue entries. This generates a list of responses. If a dialogue entry's Conditions are false, its corresponding Response.enabled property will be false. These responses will be shown but not clickable.
  • When showing a response menu, the example script will remove from the list of responses any responses whose enabled property is false and whose dialogue entry's "Show Invalid" field is false.
You have reported that the menu still shows responses whose "Show Invalid" fields are false. Is it possible that these responses' Conditions are currently true?

Or is it possible that the wrong dialogue UI is assigned to the Dialogue Manager's Display Settings > Dialogue UI field?
Cussa
Posts: 22
Joined: Sat Jun 03, 2023 3:50 am

Re: VN - disable certain responses

Post by Cussa »

The Dialogue UI field is using the VN Dialogue UI. I saw that it uses the StandardUI component. So, I replaced it with the custom class.

Maybe I'm doing something wrong?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: VN - disable certain responses

Post by Tony Li »

Are you using the custom class that is a subclass of StandardDialogueUI? I just want to make sure you're not using the older examine that used the deprecated UnityUIDialogueUI class.
Cussa
Posts: 22
Joined: Sat Jun 03, 2023 3:50 am

Re: VN - disable certain responses

Post by Cussa »

In the Dialogue System > Dialogue UI, I am using the Visual Novel Dialogue UI
Screenshot 2023-07-06 213344.png
Screenshot 2023-07-06 213344.png (26.31 KiB) Viewed 982 times
This is a prefab that comes with the VN Framework. This GameObject has a component Standard Dialogue UI.

So, I created a new class that inherits the StandardDialogueUI, and used the methods that you mentioned:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PixelCrushers.DialogueSystem
{
    public class UnityUIDialogueUIShowInvalidResponses : StandardDialogueUI
    {
        public string showInvalidFieldName = "Show Invalid";

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

        private Response[] CheckInvalidResponses(Response[] responses)
        {
            if (!HasAnyInvalid(responses)) return responses;
            var list = new List<Response>();
            for (int i = 0; i < responses.Length; i++)
            {
                var response = responses[i];
                if (response.enabled || Field.LookupBool(response.destinationEntry.fields, showInvalidFieldName))
                {
                    list.Add(response);
                }
            }
            return list.ToArray();
        }

        private bool HasAnyInvalid(Response[] responses)
        {
            if (responses == null) return false;
            for (int i = 0; i < responses.Length; i++)
            {
                if (!responses[i].enabled) return true;
            }
            return false;
        }
    }
}
Then, I disabled the Standard Dialogue UI and introduced the UnityUIDialogueUIShowInvalidResponses.
Screenshot 2023-07-06 213602.png
Screenshot 2023-07-06 213602.png (262.02 KiB) Viewed 982 times
Is this the right process or did I miss something?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: VN - disable certain responses

Post by Tony Li »

The Visual Novel Dialogue UI prefab is a prefab variant of the VN Template Standard Dialogue UI prefab. This means it's basically the same as VN Template Standard Dialogue UI except it has a few extra components added to it, like Conversation History and Backtracker.

Instead of disabling the StandardDialogueUI and adding your UnityUIDialogueUIShowInvalidResponses as a separate component, replace the component in-place as described here: How To: Replace Script with Subclass and Keep Field Assignments.

Newer Unity versions won't let you do this in a prefab in many cases, so you may need to right-click your dialogue UI prefab and select Prefab > Unpack Prefab. Then you'll be able to replace the component in-place.
Cussa
Posts: 22
Joined: Sat Jun 03, 2023 3:50 am

Re: VN - disable certain responses

Post by Cussa »

Ok! That worked! Many thanks
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: [solved] VN - disable certain responses

Post by Tony Li »

Glad to help!
Cussa
Posts: 22
Joined: Sat Jun 03, 2023 3:50 am

Re: [solved] VN - disable certain responses

Post by Cussa »

Hi, Sorry for reopening this topic.

After some discussion with the team, we are probably going to something similar to this thread https://www.pixelcrushers.com/phpbb/vie ... alid#p6114 as the writer wants to have the ability to define both Visible and Enable conditions.

My idea is that the default condition will be used for the enable, as it is already working this way. Then, we select to show the invalid entries.
Then I added a new field called "Visible Conditions" in the template, selecting the main so it appears in the Edit window, and I am changing the code to something like this.

Code: Select all

public class UnityUIDialogueUIShowInvalidResponses : StandardDialogueUI
{
    public const string visibleConditionsFieldName = "Visible Conditions";

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

    private Response[] CheckVisibleResponses(Response[] responses)
    {
        var list = new List<Response>();
        for (int i = 0; i < responses.Length; i++)
        {
            var response = responses[i];
            var conditions = Field.LookupValue(response.destinationEntry.fields, visibleConditionsFieldName);
            if (Lua.IsTrue(conditions))
            {
                list.Add(response);
            }
        }
        return list.ToArray();
    }
}
So, it will always validate the answers based on their visibility and it will always add the response.

However, there is something that I would like to ask: is there any way I can show this field with the "helper tool" similar to the one that we have on Conditions?

And is there any possible issue you see on my code that could affect the normal flow for DS?
User avatar
Tony Li
Posts: 22108
Joined: Thu Jul 18, 2013 1:27 pm

Re: [solved] VN - disable certain responses

Post by Tony Li »

Hi,

That code looks fine. You can write a custom field type for your "Visible Conditions" field. Draw the field using a LuaConditionWizard.
Post Reply