public override void ResolveNotificationData(NotificationData notifiData)
    {
        MessageFrom_0_NotificationData data = (MessageFrom_0_NotificationData)notifiData;

        FromWho.text = data.FromWho;
        Message.text = data.Message;
    }
예제 #2
0
    public override void ExecuteScriptableObject(AppExecution scriptable)
    {
        TextMsgObj textMsgObj = (TextMsgObj)scriptable;

        //TextProg.SetText(textMsgObj);
        TextMsgObjManager.AddMsgObj(textMsgObj);
        TextViewController.OnTextMsgObjExecute(textMsgObj.speaker);

        if (NotificationController.Instance)
        {
            MessageFrom_0_NotificationData data = (MessageFrom_0_NotificationData)NotificationController.Instance.CreateDataInstance(Utility.App.Text, "MessageFrom");
            data.FromWho = textMsgObj.speaker;
            data.Message = textMsgObj.message[0];
            NotificationController.Instance.PushNotification(data, textMsgObj.speaker);
            if (!TextProg.IsShow || TextProg.CurrentSpeaker != textMsgObj.speaker && !textMsgObj.playerTalking)
            {
                AudioManager.Instance.Play(AudioEnum.Text_Notifi_B);
            }
        }
    }
예제 #3
0
    IEnumerator ShowText()
    {
        bool wasOpened = false;

        while (true)
        {
            //wait for permission from TextAppController to show conversation
            //bool textWasNull = false;
            string thisMessage;
            bool   isPlayerTalking;
            bool   hasNextMessage = true;
            firstTextDisplayed = false;

            while (!TextMsgObjManager.TryGetCurrentMsg(CurrentSpeaker, out thisMessage) || (AppCallbackModule.Instance != null && !TextAppController.Instance.IsShowBeforeTransition) || needDecisionMaking)
            {
                yield return(null);
                //textWasNull = true;
            }
            //TextMsgObj text = currText;

            //if (textWasNull)
            //    text = GetText(firstText);

            //process changes that affect player profile here

            //display messages
            if (typingTimeNPC == 0)
            {
                typingTimeNPC = GetTypingSpeed(CurrentSpeaker);
            }
            //for (int i = currentIndex; i < text.message.Length; i++)
            while (hasNextMessage)
            {
                if (bubble != null)
                {
                    prevBubble = bubble;
                }

                if (!TextMsgObjManager.TryGetIsPlayerSpeaking(CurrentSpeaker, out isPlayerTalking))
                {
                    yield break;
                }

                if (thisMessage.Length > 0)
                {
                    //create text bubble object
                    if (!isPlayerTalking)
                    {
                        bubble = Instantiate(receivedText);
                        bubble.transform.SetParent(this.transform);
                        bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition = new Vector2(0f, nextTextLoc);
                        //bubble.transform.localPosition = new Vector2(textVisualizer.screenWidth, -textVisualizer.screenHeight / 2f);
                    }
                    else
                    {
                        bubble = Instantiate(sentText);
                        bubble.transform.SetParent(this.transform);
                        bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition = new Vector2(0f, nextTextLoc);

                        //bubble.transform.localPosition = new Vector2(-textVisualizer.screenWidth, -textVisualizer.screenHeight / 2f);
                    }
                    textVisualizer.AddBubble(bubble);
                    bubble.transform.GetChild(bubble.transform.childCount - 1).GetComponent <Text>().text = thisMessage;
                    yield return(null);

                    TextMessageController bubbleController = bubble.GetComponent <TextMessageController>();
                    textVisualizer.SetTextBubbleAppearance(bubble, bubbleController);

                    //if (transform.childCount < 3) //no texts on screen yet other than the one we just created

                    //move bubble to the start position
                    if (isPlayerTalking)
                    {
                        bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition = new Vector2(0f, nextTextLoc) - new Vector2(-textVisualizer.indent, textVisualizer.indent);

                        //bubble.transform.localPosition = new Vector2(textVisualizer.screenWidth / 2f, nextTextLoc)
                        //    - new Vector2(-textVisualizer.indent, textVisualizer.indent);
                    }
                    else
                    {
                        bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition = new Vector2(0f, nextTextLoc) - new Vector2(textVisualizer.indent, textVisualizer.indent);

                        //bubble.transform.localPosition = new Vector2(-textVisualizer.screenWidth / 2f, nextTextLoc)
                        //    - new Vector2(textVisualizer.indent, textVisualizer.indent);
                    }

                    //make text invisible
                    Color bubbleColor = bubble.transform.GetChild(0).GetComponent <Image>().color;
                    Color textColor   = bubble.transform.GetChild(bubble.transform.childCount - 1).GetComponent <Text>().color;
                    SetBubbleOpacity(bubble, bubbleColor, textColor, 0);

                    //move bubble to correct location and state
                    Vector2 startLoc = bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition;
                    endLoc = new Vector2(0f, nextTextLoc);
                    //if (isPlayerTalking)
                    //    endLoc = new Vector3(textVisualizer.screenWidth / 2f, nextTextLoc);
                    //else
                    //    endLoc = new Vector3(-textVisualizer.screenWidth / 2f, nextTextLoc);

                    textVisualizer.AdjustScrolling(endLoc, typingBubble.sizeDelta.y);

                    //first text automatically on screen, others must appear over time
                    if (firstTextDisplayed || wasOpened)
                    {
                        float startTime;

                        //typing bubble appears if player didn't just make a choice
                        if (!justMadeChoice)
                        {
                            //typing bubble
                            typingBubble.anchoredPosition = endLoc;
                            Image typingBubbleImg = typingBubble.GetComponent <Image>();
                            typingBubbleImg.color = new Color(1, 1, 1, 0);

                            //flip depending on speaker
                            if (isPlayerTalking)
                            {
                                typingBubble.transform.localScale = new Vector3(-1f, 1f, 1f);
                            }
                            else
                            {
                                typingBubble.transform.localScale = new Vector3(1f, 1f, 1f);
                            }

                            //figure out if new typing bubble is visible to the player and go there if not
                            //bool zoomToBubble = !NewTextVisible(endLoc.y);
                            //float endScrollBubble = -endLoc.y + typingBubble.sizeDelta.y + textVisualizer.vertSpace +
                            //    textVisualizer.panel.sizeDelta.y - (textVisualizer.screenHeight / 2f);
                            //float startScrollBubble = textVisualizer.rt.localPosition.y;

                            //make typing bubble appear on screen
                            startTime = Time.time;
                            float endTime = startTime + typingBubbleAppearTime;
                            while (Time.time < endTime)
                            {
                                float prog = (Time.time - startTime) / (endTime - startTime);
                                if (isPlayerTalking)
                                {
                                    typingBubble.anchoredPosition = new Vector2(endLoc.x - textVisualizer.indent * prog, endLoc.y);
                                }
                                else
                                {
                                    typingBubble.anchoredPosition = new Vector2(endLoc.x + textVisualizer.indent * prog, endLoc.y);
                                }
                                typingBubbleImg.color = new Color(1, 1, 1, prog);

                                //if (zoomToBubble)
                                //{
                                //    float y = prog * endScrollBubble + (1 - prog) * startScrollBubble;
                                //    textVisualizer.rt.localPosition = new Vector3(textVisualizer.rt.localPosition.x, y, 0f);
                                //}

                                yield return(null);
                            }
                            if (isPlayerTalking)
                            {
                                typingBubble.anchoredPosition = new Vector2(endLoc.x - textVisualizer.indent, endLoc.y);
                            }
                            else
                            {
                                typingBubble.anchoredPosition = new Vector2(endLoc.x + textVisualizer.indent, endLoc.y);
                            }
                            typingBubbleImg.color = new Color(1, 1, 1, 1);

                            //if (zoomToBubble)
                            //{
                            //    textVisualizer.rt.localPosition = new Vector3(textVisualizer.rt.localPosition.x, endScrollBubble, 0f);
                            //}

                            //typing bubble stays on screen
                            if (thisMessage.Length > 0)
                            {
                                if (isPlayerTalking)
                                {
                                    yield return(new WaitForSeconds(typingTimePlayer * thisMessage.Length));
                                }
                                else
                                {
                                    yield return(new WaitForSeconds(typingTimeNPC * thisMessage.Length));
                                }
                            }
                            else
                            {
                                yield return(new WaitForSeconds(bubbleDisappearTime));
                                //textVisualizer.maxScroll -= typingBubble.sizeDelta.y;
                            }

                            //make typing bubble leave screen
                            startTime = Time.time;
                            endTime   = startTime + typingBubbleAppearTime;
                            while (Time.time < endTime)
                            {
                                float prog = (Time.time - startTime) / (endTime - startTime);
                                if (isPlayerTalking)
                                {
                                    typingBubble.anchoredPosition = new Vector2(endLoc.x - textVisualizer.indent * (1 - prog), endLoc.y);
                                }
                                else
                                {
                                    typingBubble.anchoredPosition = new Vector2(endLoc.x + textVisualizer.indent * (1 - prog), endLoc.y);
                                }
                                typingBubbleImg.color = new Color(1, 1, 1, 1 - prog);
                                yield return(null);
                            }
                            typingBubble.anchoredPosition = endLoc;
                            typingBubbleImg.color         = new Color(1, 1, 1, 0);
                        }

                        //figure out if new text is visible to the player and go there if not
                        //bool zoomToText = !NewTextVisible(endLoc.y);
                        //float endScroll = -endLoc.y + bubbleController.bubbleHeight + textVisualizer.vertSpace +
                        //    textVisualizer.panel.sizeDelta.y - (textVisualizer.screenHeight / 2f);
                        //float startScroll = textVisualizer.rt.localPosition.y;

                        //advance how far the player can scroll
                        textVisualizer.AdjustScrolling(endLoc, bubbleController.bubbleHeight);

                        //bring on the text
                        if (isPlayerTalking)
                        {
                            AudioManager.Instance.Play(AudioEnum.Text_Sent);
                        }
                        else
                        {
                            AudioManager.Instance.Play(AudioEnum.Text_Received);
                        }
                        startTime = Time.time;
                        float appearTime = (textVisualizer.indent * Mathf.Sqrt(2f)) / moveSpeed; //time taken to appear

                        while (Time.time < startTime + appearTime)
                        {
                            float   prog = (Time.time - startTime) / appearTime;
                            Vector2 pos  = (1 - prog) * startLoc + prog * endLoc;
                            bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition = pos;
                            SetBubbleOpacity(bubble, bubbleColor, textColor, prog);

                            //if (zoomToText)
                            //{
                            //    float y = prog * endScroll + (1 - prog) * startScroll;
                            //    textVisualizer.rt.localPosition = new Vector3(textVisualizer.rt.localPosition.x, y, 0f);
                            //}

                            yield return(null);
                        }

                        //if (zoomToText)
                        //textVisualizer.rt.localPosition = new Vector3(textVisualizer.rt.localPosition.x, endScroll, 0f);
                    }

                    firstTextDisplayed = true;

                    //make sure bubble ends in the right place and state
                    bubble.GetComponent <TextMessageController>().RectTransform.anchoredPosition = endLoc;
                    SetBubbleOpacity(bubble, bubbleColor, textColor, 1);
                    bubbleController.placed = true;


                    bubble = null;
                    //currentIndex++;

                    //prepare next text

                    nextTextLoc -= (bubbleController.bubbleHeight + textVisualizer.vertSpace);
                }
                if (hasNextMessage = TextMsgObjManager.TryGetNextMsg(CurrentSpeaker, out thisMessage))
                {
                    if (NotificationController.Instance && !isPlayerTalking && thisMessage != "")
                    {
                        MessageFrom_0_NotificationData data = (MessageFrom_0_NotificationData)NotificationController.Instance.CreateDataInstance(Utility.App.Text, "MessageFrom");
                        data.FromWho = CurrentSpeaker;
                        data.Message = thisMessage;
                        NotificationController.Instance.PushNotification(data, CurrentSpeaker);
                    }
                    yield return(new WaitForSeconds(bubbleDisappearTime));
                }
                else
                {
                    string message;
                    TextMsgObjManager.TryGetLastMessage(CurrentSpeaker, out message);
                    if (NotificationController.Instance && !isPlayerTalking && message != "")
                    {
                        MessageFrom_0_NotificationData data = (MessageFrom_0_NotificationData)NotificationController.Instance.CreateDataInstance(Utility.App.Text, "MessageFrom");
                        data.FromWho = CurrentSpeaker;
                        data.Message = message;
                        NotificationController.Instance.PushNotification(data, CurrentSpeaker);
                    }
                }
            }
            wasOpened = true;
            AdvanceTexts();
            yield return(null);
        }
    }