Example #1
0
        private void Update()
        {
            if (shown)
            {
                if (scrollToEnd)
                {
                    messagesScroll.normalizedPosition = Vector2.zero;
                    scrollToEnd = false;
                }

                switch (state)
                {
                case State.WAITING_FOR_ANSWER:
                    break;

                case State.WAITING_TO_PRESENT_PASSAGE:
                    time += Time.deltaTime;
                    if (time >= timeToWait)
                    {
                        timeToWait = 0;
                        time       = 0;
                        typingText.gameObject.SetActive(false);

                        state = State.PRESENT_PASSAGE_BASE;     // blocking
                    }
                    else
                    {
                        HandleTypingAnimation();
                    }
                    break;

                case State.PRESENT_PASSAGE_BASE:
                    PresentPassage();

                    state = State.PRESENT_PASSAGE_EXECUTE_NEXT_STATEMENT;

                    currentStatement      = null;
                    currentStatementIndex = -1;
                    break;

                case State.PRESENT_PASSAGE_EXECUTE_NEXT_STATEMENT:
                    for (int i = currentStatementIndex + 1; i < currentPassage.effects.Count; i++)
                    {
                        currentStatement = currentPassage.effects[i];
                        if (currentStatement.blocking && (executeStatements || currentStatement.type == SFStatement.Type.CHANGE_IMAGE))
                        {
                            currentStatement.ExecuteBlocking();
                            currentStatementIndex = i;
                            state = State.PRESENT_PASSAGE_WAITING_STATEMENT_FINISH;
                            break;
                        }
                    }

                    if (state != State.PRESENT_PASSAGE_WAITING_STATEMENT_FINISH)
                    {
                        ContinueDialogue();
                    }

                    break;

                case State.PRESENT_PASSAGE_WAITING_STATEMENT_FINISH:
                    if (currentStatement.finished)
                    {
                        state = State.PRESENT_PASSAGE_EXECUTE_NEXT_STATEMENT;
                    }
                    break;

                case State.DIALOGUE_FINISHED:
                    break;

                default:
                    Debug.LogError($"ChatScreenWidget: unknown state {state}");
                    break;
                }
            }
        }
Example #2
0
        public override void Show(Action onComplete = null)
        {
            base.Show(onComplete);

            if (firstTimeShown)
            {
                StartCoroutine(GradualInit());

                firstTimeShown = false;
            }

            savePath              = true;
            executeStatements     = true;
            soundEnabled          = true;
            currentStatement      = null;
            currentStatementIndex = -1;

            var newCompanion = Inventory.Instance.worldState.Value.GetCompanion(Inventory.Instance.currentCompanion.Value);

            if (currentCompanion == null || newCompanion.Data.id != currentCompanion.Data.id || currentCompanion.lastDialogueTaken != currentCompanion.activeDialogue)
            {
                dialogueIsBuilt = false;
                ResetScreen();
            }

            var lm = LayoutManager.Instance;

            currentCompanion = newCompanion;

            companionNameText.fontSize = 1.25f * lm.esw;

            currentCompanion.lastDialogueTaken = currentCompanion.activeDialogue;
            currentDialog = currentCompanion.activeDialogue;

            // screenWidth = UIManager.Instance.canvasRectTransform.rect.size.x;
            // em = screenWidth / 25f;
            // margins = new Vector4(em, 0.5f * em, em, 0.5f * em);
            typingText.fontSize = 0.75f * lm.esw;

            SFDialogue dialogue = currentCompanion.dialogues[currentCompanion.activeDialogue];
            var        path     = dialogue.path;

            // we either talked to some companion, went back and entered another companion screen
            // or this is the first time we enter companion screen
            if (!dialogueIsBuilt)
            {
                time       = 0;
                timeToWait = 0;

                SetEmotionAndName(currentCompanion, "main");

                BuildPastConversation();

                // dialogue was undergoing before
                if (path.Count != 0)
                {
                    currentPassage = dialogue.root.Find(path[path.Count - 1]);

                    tempNextAvailablePassages.Clear();
                    currentPassage.GetNextAvailablePassages(ref tempNextAvailablePassages);

                    // if it is the end of the dialogue present last passage and do nothing
                    if (tempNextAvailablePassages.Count == 0)
                    {
                        savePath          = false;
                        executeStatements = false;
                        soundEnabled      = false;
                        PresentPassage();
                        savePath          = true;
                        executeStatements = true;
                        soundEnabled      = true;

                        state = State.DIALOGUE_FINISHED;
                    }
                    // if dialogue is continuing then show last line with sound effect
                    else
                    {
                        savePath          = false;
                        executeStatements = false;
                        PresentPassage();
                        savePath          = true;
                        executeStatements = true;

                        ContinueDialogue();
                    }
                }
                // dialogue is undergoing first time
                else
                {
                    currentPassage = dialogue.root.startPassage;
                    SFStatement e = currentPassage.GetStatement(SFStatement.Type.CHANGE_IMAGE);
                    if (e != null)
                    {
                        e.Execute();
                    }

                    e = currentPassage.GetStatement(SFStatement.Type.SET_COMPANION_NAME);
                    if (e != null)
                    {
                        e.Execute();
                    }

                    StartDialogue(); //blocking
                }
            }
            // else
            // {
            //     if (path.Count != 0)
            //     {
            //         StartDialogue();
            //     }
            // }
        }