private void HandleCurrentContextChanged(object sender, EventArgs e)
        {
            Dialogue currentDialogue = FindCurrentDialogue();

            // Reset repetitions count for dialogues, unless actively prevented:
            if (currentDialogue != null)
            {
                currentDialogue.ResetRepetitionCount();
                if (workingMemory.CurrentID == "") // If no ID has been set, then just start from the beginning.
                {
                    workingMemory.CurrentID = currentDialogue.DialogueItemList[0].ID;
                }
                else
                {
                    DialogueItem currentDialogueItem = FindCurrentDialogueItem();
                    PropertyInfo timeoutProperty     = currentDialogueItem.GetType().GetProperty(AgentConstants.TIMEOUT_INTERVAL_PROPERTY_NAME);
                    if (timeoutProperty != null)
                    {
                        dialogueItemTimer.Stop(); // Just in case it was running previously.
                        double timeoutInterval = (double)timeoutProperty.GetValue(currentDialogueItem);
                        dialogueItemTimer.Run(timeoutInterval);
                    }
                }
            }
        }
        private void HandleCurrentIDChanged(object sender, EventArgs e)
        {
            DialogueItem currentDialogueItem = FindCurrentDialogueItem();

            if (currentDialogueItem != null)
            {
                //  currentDialogueItem.RepetitionCount++;
                // Run the timeout timer only for those items that have the corresponding property:
                PropertyInfo timeoutProperty = currentDialogueItem.GetType().GetProperty(AgentConstants.TIMEOUT_INTERVAL_PROPERTY_NAME);
                if (timeoutProperty != null)
                {
                    dialogueItemTimer.Stop(); // Just in case it was running previously.
                    double timeoutInterval = (double)timeoutProperty.GetValue(currentDialogueItem);
                    if (timeoutInterval > 0)
                    {
                        dialogueItemTimer.Run(timeoutInterval);
                    }
                }
                if (!(currentDialogueItem is InputItem)) // If this is NOT true, then just await the input; see above.
                {
                    if (currentDialogueItem is AsynchronousDialogueItem)
                    {
                        ((AsynchronousDialogueItem)currentDialogueItem).RunAsynchronously(null);
                    }
                    else
                    {
                        string targetContext = null;
                        string targetID      = null;
                        currentDialogueItem.Run(null, out targetContext, out targetID);
                        if (targetContext != workingMemory.CurrentContext)
                        {
                            workingMemory.CurrentContext = targetContext;
                        }                                                                                                    // Triggers the ContextChangedEvent in working memory
                        else
                        {
                            workingMemory.CurrentID = targetID;
                        }                                            // Triggers the IDChangedEvent in working memory
                    }
                }
                // else // But perhaps add a timeout, then repeat, then set context = "".
                //  { }
            }
        }
Beispiel #3
0
    float text_pad;                               // Padding between text and dialogue box

    // Initializes dialogue box and starts text scroll
    public Coroutine dialogueBoxStart()
    {
        text_pad = fx_text.rectTransform.offsetMin.y - fx_text.rectTransform.offsetMax.y;
        // Initialize color effect to hide text
        set_color         = fx_text.gameObject.AddComponent <FXTextColor> ();
        set_color.color   = fx_text.color;
        set_color.color.a = 0;
        set_color.chars   = new int[2] {
            0, text.Length
        };
        fx_text.addEffect(set_color);
        if (d_item.GetType() == typeof(DialogueItemChat))
        {
            DialogueItemChat c_item = (DialogueItemChat)d_item;
            // Set icon
            left_icon.sprite  = c_item.left_icon;
            right_icon.sprite = c_item.right_icon;
            // Display appropriate icon
            if (c_item.icon_side == IconSide.LEFT || c_item.icon_side == IconSide.BOTH)
            {
                left_icon.enabled = true;
            }
            if (c_item.icon_side == IconSide.RIGHT || c_item.icon_side == IconSide.BOTH)
            {
                right_icon.enabled = true;
            }
            // Add text with speaker's name, and offset text display
            int offset = 0;
            if (d_item.speaker_name != null && d_item.speaker_name.Length != 0)
            {
                text    = d_item.speaker_name + "\n" + text;
                offset += d_item.speaker_name.Length + 1;
            }
            fx_text.text         = text;
            set_color.chars [0]  = offset;
            set_color.chars [1] += offset;
            // Set box height
            setBoxHeight();
        }
        else if (d_item.GetType() == typeof(DialogueItemVN))
        {
            DialogueItemVN v_item = (DialogueItemVN)d_item;
            // Display character sprites
            for (int i = 0; i < v_item.char_sprites.Length; ++i)
            {
                DialogueManager.main.displayCharacter(v_item.char_sprites [i], v_item.char_sprite_pos [i]);
            }
            fx_text.text = text;
        }
        else if (d_item.GetType() == typeof(DialogueItemAN))
        {
            fx_text.text = text;
            setBoxHeight();
        }
        else
        {
            fx_text.text = text;
        }
        // Set talking sfx
        if (talk_sfx)
        {
            AudioPlayer.main.setSFX(AudioPlayer.channel_voice, "speak_boop");
        }
        return(StartCoroutine(startTextScrollCR()));
    }
Beispiel #4
0
 // Displays next line of dialogue. Returns 'false' if there is no next line.
 bool nextLine()
 {
     if (history.Count > 0 && history [history.Count - 1].cr_scroll != null)
     {
         is_dump = true;             // Flag is set back to false by 'dumpText()'
         dump_cr = StartCoroutine(history [history.Count - 1].dumpText());
     }
     else
     {
         //if (!input && Input.GetKeyDown (KeyCode.Space)) AudioPlayer.main.playSFX ("sfx_advance_text");
         //curr_spacebar_icon.SetActive (false);
         if (input)
         {
             return(true);
         }
         if (curr_line >= curr_dialogue.GetComponents <DialogueItem>().Length - 1)
         {
             return(false);
         }
         // Create dialogue box
         DialogueItem d_item = curr_dialogue.GetComponents <DialogueItem>()[++curr_line];
         DialogueBox  d_box  = null;
         if (d_item is DialogueItemJumpBase)
         {
             GameflowManager.main.jump(((DialogueItemJumpBase)d_item).evaluateTarget().gameObject, false);
             return(false);
         }
         else if (d_item.GetType() == typeof(DialogueItemVN))
         {
             Sprite mc_sprite    = ((DialogueItemVN)d_item).mc_sprite;
             Sprite codec_sprite = ((DialogueItemVN)d_item).codec_sprite;
             if (mc_sprite != null)
             {
                 VNMCSprite.sprite = mc_sprite;
             }
             if (codec_sprite != null)
             {
                 VNCodecSprite.sprite = codec_sprite;
             }
             VNView.SetActive(true);
             ChatView.SetActive(false);
             ANView.SetActive(false);
             curr_spacebar_icon     = spacebar_icon_vn;
             curr_spacebar_animator = animator_spacebar_vn;
             d_box          = VNDialogueBox;
             VNSpeaker.text = DialogueParser.main.substituteMacros(d_item.speaker_name);
         }
         else if (d_item.GetType() == typeof(DialogueItemChat))
         {
             VNView.SetActive(false);
             ChatView.SetActive(true);
             ANView.SetActive(false);
             curr_spacebar_icon     = spacebar_icon_chat;
             curr_spacebar_animator = animator_spacebar_chat;
             //clearLog (ChatView);
             GameObject d_obj = Instantiate(dialogue_box_prefab, ChatContent);
             d_box = d_obj.GetComponent <DialogueBox>();
         }
         else if (d_item.GetType() == typeof(DialogueItemAN))
         {
             VNView.SetActive(false);
             ChatView.SetActive(false);
             ANView.SetActive(true);
             curr_spacebar_icon     = spacebar_icon_an;
             curr_spacebar_animator = animator_spacebar_an;
             //clearLog (ANView);
             GameObject d_obj = Instantiate(an_dialouge_box_prefab, ANContent);
             d_box = d_obj.GetComponent <DialogueBox>();
         }
         d_box.d_item  = d_item;
         d_box.speaker = DialogueParser.main.substituteMacros(d_item.speaker_name);
         // Remove old text effects
         FXTextEffect[] fx_arr = d_box.fx_text.gameObject.GetComponents <FXTextEffect>();
         foreach (FXTextEffect fx in fx_arr)
         {
             d_box.fx_text.removeEffect(fx);
             Destroy(fx);
         }
         d_box.text = DialogueParser.main.parse(d_item, d_box);
         // Add new text effects
         foreach (FXTextEffect text_effect in d_item.fx_text_effects)
         {
             d_box.fx_text.addEffect(text_effect);
         }
         // Add dialogue box to history (only really works for Chat items)
         history.Add(d_box);
         // Start scroll
         d_box.scroll_delay = scroll_delay;
         Coroutine d_box_init = d_box.dialogueBoxStart();
         // Prompt input if necessary
         if (d_item.dialogue_type == DialogueType.INPUT)
         {
             input = true;
             StartCoroutine(showInput(d_item, d_box, d_box_init));
         }
         else
         {
             input = false;
         }
     }
     return(true);
 }