예제 #1
0
        /// <summary>
        /// Displays a binary choice dialogue to the user, allowing them to interact with it
        /// </summary>
        /// <param name="dialogue">The BinaryOptionDialogue object which contains the information for the view</param>
        /// <param name="onOptionPressed">A callback which is used when the user interacts with the card</param>
        public void StartBinaryOptionDialogue(OptionDialogue dialogue, Action <int> onOptionPressed)
        {
            Debug.Log("Got dialogue: " + dialogue.Question + dialogue.PrecedingDialogue);
            Action <int> handleButtonPressed = num =>
            {
                onOptionPressed(num);
                optionViewAnimator.SetBool("InstantTransition", false);
                optionViewAnimator.SetBool("IsVisible", false);
            };

            //TODO handle if absent preceding dialogue
            if (dialogue.PrecedingDialogue.Statements.Length != 0)
            {
                StartSimpleDialogue(dialogue.PrecedingDialogue, () =>
                {
                    optionDialogueView.SetContent(dialogue, handleButtonPressed);
                    simpleDialogueViewAnimator.SetBool("InstantTransition", true);
                    simpleDialogueViewAnimator.SetBool("IsVisible", false);
                    optionViewAnimator.SetBool("InstantTransition", true);
                    optionViewAnimator.SetBool("IsVisible", true);
                });
            }
            else
            {
                optionDialogueView.SetContent(dialogue, handleButtonPressed);
                optionViewAnimator.SetBool("InstantTransition", false);
                optionViewAnimator.SetBool("IsVisible", true);
            }
        }
예제 #2
0
        /// <summary>
        /// Sets the content to be displayed on the view
        /// </summary>
        /// <param name="dialogue">The dialogue to be displayed to the user</param>
        /// <param name="onOptionPressed">A callback which should be used to execute instructions
        /// after a user has chosen an option</param>
        internal void SetContent(OptionDialogue dialogue, Action <int> onOptionPressed)
        {
            // clear current listeners and text on the buttons
            foreach (Button button in optionButtons)
            {
                button.onClick.RemoveAllListeners();
                button.gameObject.SetActive(false);
            }

            npcImage = GameObject.Find("BinaryNPCImage").GetComponent <Image>();
            Debug.Log("Binary NPC Name: " + dialogue.PrecedingDialogue.Name);
            npcImage.sprite      = NPCSpriteManager.Instance.GetSprite(dialogue.PrecedingDialogue.Name);
            npcNameText.text     = dialogue.PrecedingDialogue.Name;
            npcDialogueText.text = dialogue.Question;

            // Add buttons for each option available
            foreach (var item in dialogue.Options.Select((value, index) => (value, index)))
            {
                var optionText = item.value;
                // currently 2 is used to render the bottom button first
                var    buttonIndex     = item.index;
                Button buttonToDisplay = optionButtons[buttonIndex];
                buttonToDisplay.gameObject.SetActive(true);
                optionTexts[buttonIndex].text = optionText;
                buttonToDisplay.onClick.AddListener(() => onOptionPressed(item.index));
            }

            if (dialogue.Options.Count() > 1)
            {
                cardTypeText.text  = dialogue.CardType + " Decision";
                cardTypeText.color = dialogue.CardType == "Story" ? new Color32(168, 24, 36, 255) : new Color32(219, 164, 44, 255);
            }
            else
            {
                cardTypeText.text = "";
            }
        }