Forum rules - please read before posting.

Alternating position of subtitles menu depending on speaker?

Hello!
I have rencently run into the case where, inside the Subtitles menu, I have two label elements in different screen position: one for player speech, and the other for NPC (to help diferenciate who is talking).
My main issue is (due to never touching AC code) that I'm not sure where speech text is sent to the UI elements, so I can add the exception that, if it's the player who is talking, it sends it to a specific element. I need to do this with speaker labels, also.
In which script is this done? Surely it is not as hidden as it seems, but still prefer to ask before messing something.

Comments

  • edited May 2021

    Your thread's title and description seem to be covering slightly different topics - are you looking to alter the position of the Menu itself, or alter the appearance of the elements within it? As this is a visual problem, screenshots would help clarify the context.

    Speech text will be fed into any Label element set to "Dialogue Line", but that doesn't mean it needs to be visible - you could make only one of the two elements visible at a time.

    However, if you use Unity UI, I'd suggest using animation to control the position of one element instead. You could then hook this up to a Bool parameter in your Animator Controller (e.g. "IsPlayer") that transitions between the two states accordingly.

    In order to update this parameter (or reposition the UI elements directly), you can hook into the OnMenuTurnOn custom event and read the Subtitle Menu's "speech" variable:

    using UnityEngine;
    using AC;
    
    public class RepositionSubtitles : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
        private void OnDisable () { EventManager.OnMenuTurnOn -= OnMenuTurnOn; }
    
        private void OnMenuTurnOn (AC.Menu menu, bool isInstant)
        {
            if (menu.title == "Subtitles")
            {
                bool isPlayer = menu.speech.GetSpeakingCharacter () == KickStarter.player;
                menu.RuntimeCanvas.GetComponentInChildren <Animator>().SetBool ("IsPlayer", isPlayer);
            }
        }
    
    }
    
  • edited May 2021

    Sorry for the mess! What I want exactly is just move from the classical "low on the screen" dialogue text box I have:

    To a "Text is near the character is speaking" approach:

    I initially though the best way to do it is just by changing the position of a single text element every time a character speaks, but right now I have the setup ready, with two text boxes and two speaker labels. So maybe it will be better to just activate and deactivate the different elements.
    The main issue with this approach, however, is:
    a) The Dialogue menu has a background, transitions, etc. So, if I just make two different menus and use the "every time X character speaks" condition to appear, it will trigger the transition each time the speaker switches, which is no good. Besides, I prefer to have all packed in a single menu for organization purposes.
    b) As I have them organized, my text elements are child of the menu.

    Sadly, this means I cannot add the condition of "every time X character speaks" I could add in the menus, so my (AFAIK) only option is to activate and deactivate the elements by code.
    Which should be farily easy, but the fact is that AC is so gigantic, I still couldn't grasp where I should work!
    By the way, I'm using the native UI system of AC

  • I recommend the use of Unity UI for menu rendering, as it gives you much more customisation options. AC menu elements can't typically be repositioned, so anything dynamic is best left to Unity UI.

    However, to hide/show elements based on the speaking character, you can hook into the OnStartSpeech event:

    using UnityEngine;
    using AC;
    
    public class RepositionSubtitles : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartSpeech += StartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech -= StartSpeech; }
    
        private void StartSpeech (AC.Char character, string lineText, int lineID)
        {
            if (character == null) return;
            bool isPlayer = character.IsPlayer;
            PlayerMenus.GetElementWithName ("Subtitles", "PlayerLabel").IsVisible = isPlayer;
            PlayerMenus.GetElementWithName ("Subtitles", "PlayerDialogue").IsVisible = isPlayer;
            PlayerMenus.GetElementWithName ("Subtitles", "NPCLabel").IsVisible = !isPlayer;
            PlayerMenus.GetElementWithName ("Subtitles", "NPCDialogue").IsVisible = !isPlayer;
        }
    
    }
    
  • Thanks! I will consider moving to Unity UI, in that case

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.