public IEnumerator Sequence()
        {
            sequenceState = SequenceState.ProgressingOngoingTasks;

            ClearTaskRoutines();

            List <QuestsTrackerTask> visibleTasks = new List <QuestsTrackerTask>();
            List <QuestsTrackerTask> newTasks     = new List <QuestsTrackerTask>();

            foreach (QuestsTrackerTask task in taskEntries.Values)
            {
                if (task.gameObject.activeSelf)
                {
                    visibleTasks.Add(task);
                }
                else
                {
                    newTasks.Add(task);
                }
            }

            //Progress of currently visible tasks
            for (int i = 0; i < visibleTasks.Count; i++)
            {
                tasksRoutines.Add(StartCoroutine(visibleTasks[i].ProgressAndCompleteSequence()));
            }
            yield return(WaitForTaskRoutines());

            OnLayoutRebuildRequested?.Invoke();

            sequenceState = SequenceState.ShowingNewTasks;

            //Play "new task" sound
            if (newTasks.Count > 0)
            {
                newTaskAudioEvent.Play();
            }

            //Show and progress of new tasks
            for (int i = 0; i < newTasks.Count; i++)
            {
                newTasks[i].gameObject.SetActive(true);
                newTasks[i].SetIsNew(true);
                tasksRoutines.Add(StartCoroutine(newTasks[i].ProgressAndCompleteSequence()));
            }
            OnLayoutRebuildRequested?.Invoke();

            yield return(WaitForTaskRoutines());

            if (taskEntries.Count == 0)
            {
                animator.SetTrigger(ANIMATION_TRIGGER_OUT);
                yield return(WaitForSecondsCache.Get(0.5f));

                Destroy(gameObject);
                OnDestroyed?.Invoke(section.id);
            }
            sequenceState = SequenceState.Finished;
        }
        private QuestsTrackerSection CreateSection()
        {
            var sectionEntry = Instantiate(sectionPrefab, sectionContainer).GetComponent <QuestsTrackerSection>();

            sectionEntry.OnLayoutRebuildRequested += () => OnLayoutRebuildRequested?.Invoke();
            sectionEntry.OnDestroyed += (sectionId) => sectionEntries.Remove(sectionId);
            return(sectionEntry);
        }
Esempio n. 3
0
        private IEnumerator DestroyRoutine()
        {
            containerAnimator.SetTrigger(OUT_ANIM_TRIGGER);
            yield return(WaitForSecondsCache.Get(DELAY_TO_DESTROY));

            OnLayoutRebuildRequested?.Invoke();
            Destroy(gameObject);
        }
Esempio n. 4
0
 internal void SetExpandCollapseState(bool newIsExpanded)
 {
     isExpanded = newIsExpanded;
     expandIcon.SetActive(!isExpanded);
     collapseIcon.SetActive(isExpanded);
     tasksContainer.gameObject.SetActive(isExpanded);
     OnLayoutRebuildRequested?.Invoke();
 }
        public void SetExpandCollapseState(bool newIsExpanded)
        {
            foreach (QuestsTrackerTask taskEntry in taskEntries.Values)
            {
                taskEntry.SetExpandedStatus(newIsExpanded);
            }

            OnLayoutRebuildRequested?.Invoke();
        }
        private IEnumerator DestroySequence()
        {
            AudioScriptableObjects.fadeOut.Play();
            containerAnimator.SetTrigger(OUT_ANIM_TRIGGER);
            yield return(WaitForSecondsCache.Get(DELAY_TO_DESTROY));

            OnLayoutRebuildRequested?.Invoke();
            Destroy(gameObject);
        }
        internal QuestsTrackerTask CreateTask()
        {
            var taskEntry = Instantiate(taskPrefab, taskContainer).GetComponent <QuestsTrackerTask>();

            taskEntry.OnDestroyed += (taskId) =>
            {
                taskEntries.Remove(taskId);
                OnLayoutRebuildRequested?.Invoke();
            };
            return(taskEntry);
        }
        internal void SetExpandCollapseState(bool newIsExpanded)
        {
            isExpanded = newIsExpanded;
            expandIcon.SetActive(!isExpanded);
            collapseIcon.SetActive(isExpanded);
            sectionContainer.gameObject.SetActive(isExpanded);

            foreach (QuestsTrackerSection section in sectionEntries.Values)
            {
                section.SetExpandCollapseState(newIsExpanded);
            }

            OnLayoutRebuildRequested?.Invoke();
        }
        private IEnumerator Sequence(List <QuestsTrackerSection> visibleSections, List <QuestsTrackerSection> newSections)
        {
            yield return(new WaitUntil(() => outAnimDone));

            ClearSectionRoutines();

            if (progressRoutine != null)
            {
                StopCoroutine(progressRoutine);
            }
            progressRoutine = StartCoroutine(ProgressSequence());

            //Progress of currently visible sections
            for (int i = 0; i < visibleSections.Count; i++)
            {
                sectionRoutines.Add(StartCoroutine(visibleSections[i].Sequence()));
            }

            yield return(WaitForTaskRoutines());

            //Show and progress of new tasks
            for (int i = 0; i < newSections.Count; i++)
            {
                newSections[i].gameObject.SetActive(true);
                sectionRoutines.Add(StartCoroutine(newSections[i].Sequence()));
            }

            OnLayoutRebuildRequested?.Invoke();
            yield return(WaitForTaskRoutines());

            OnLayoutRebuildRequested?.Invoke();
            //The entry should exit automatically if questCompleted or no progress, therefore the use of MinValue
            DateTime tasksIdleTime = (quest.isCompleted || !hasProgressedThisUpdate) ? DateTime.MinValue : DateTime.Now;

            yield return(new WaitUntil(() => isProgressAnimationDone && !isPinned && (DateTime.Now - tasksIdleTime) > TimeSpan.FromSeconds(3)));

            if (quest.isCompleted)
            {
                OnQuestCompleted?.Invoke(quest);
            }

            for (int i = 0; i < rewardsToNotify.Count; i++)
            {
                OnRewardObtained?.Invoke(rewardsToNotify[i]);
            }

            rewardsToNotify.Clear();

            isReadyForDisposal = true;
        }
Esempio n. 10
0
        internal void SetExpandCollapseState(bool newIsExpanded)
        {
            isExpanded = newIsExpanded;
            expandIcon.SetActive(!isExpanded);
            collapseIcon.SetActive(isExpanded);
            tasksContainer.gameObject.SetActive(isExpanded);

            foreach (QuestsTrackerTask task in GetComponentsInChildren <QuestsTrackerTask>())
            {
                task.SetExpandedStatus(newIsExpanded);
            }

            OnLayoutRebuildRequested?.Invoke();
        }
        public void Populate(QuestSection newSection)
        {
            sequenceState = SequenceState.NotStarted;
            ClearTaskRoutines();

            section = newSection;
            QuestTask[] allTasks = section.tasks;
            titleContainer.SetActive(!string.IsNullOrEmpty(section.name));
            sectionTitle.text = section.name;

            bool          hasCompletedTasksToShow = false;
            List <string> entriesToRemove         = taskEntries.Keys.ToList();

            for (int index = 0; index < allTasks.Length; index++)
            {
                QuestTask task = allTasks[index];
                //We only show completed quests that has been just completed to show the progress
                if (!taskEntries.ContainsKey(task.id) && (task.status == QuestsLiterals.Status.BLOCKED || (task.progress >= 1 && !task.justProgressed)))
                {
                    continue;
                }

                entriesToRemove.Remove(task.id);
                if (!taskEntries.TryGetValue(task.id, out QuestsTrackerTask taskEntry))
                {
                    taskEntry = CreateTask();
                    //New tasks are invisible
                    taskEntry.gameObject.SetActive(!task.justUnlocked);
                    taskEntries.Add(task.id, taskEntry);
                }

                taskEntry.Populate(task);
                taskEntry.transform.SetSiblingIndex(index);
            }

            for (int index = 0; index < entriesToRemove.Count; index++)
            {
                DestroyTaskEntry(entriesToRemove[index]);
            }
            OnLayoutRebuildRequested?.Invoke();
        }
        public void Populate(QuestModel newQuest)
        {
            StopSequence();

            quest = newQuest;
            SetIcon(quest.thumbnail_entry);
            QuestTask[] allTasks = quest.sections.SelectMany(x => x.tasks).ToArray();

            int completedTasksAmount = allTasks.Count(x => x.progress >= 1);

            questTitle.text        = $"{quest.name}";
            questProgressText.text = $"{completedTasksAmount}/{allTasks.Length}";
            progress.fillAmount    = quest.oldProgress;
            progressTarget         = quest.progress;

            hasProgressedThisUpdate = newQuest.sections.Any(x => x.tasks.Any(y => y.justProgressed));

            List <string> entriesToRemove = sectionEntries.Keys.ToList();
            List <QuestsTrackerSection> visibleSectionEntries = new List <QuestsTrackerSection>();
            List <QuestsTrackerSection> newSectionEntries     = new List <QuestsTrackerSection>();

            for (var i = 0; i < quest.sections.Length; i++)
            {
                QuestSection section = quest.sections[i];

                bool hasTasks = section.tasks.Any(x => x.status != QuestsLiterals.Status.BLOCKED && (x.progress < 1 || x.justProgressed));
                if (!hasTasks)
                {
                    continue;
                }

                bool isVisible = section.tasks.Any(x => x.status != QuestsLiterals.Status.BLOCKED && ((x.progress < 1 && !x.justUnlocked) || (x.progress >= 1 && x.justProgressed)));

                entriesToRemove.Remove(section.id);
                if (!sectionEntries.TryGetValue(section.id, out QuestsTrackerSection sectionEntry))
                {
                    sectionEntry = CreateSection();
                    //New tasks are invisible
                    sectionEntries.Add(section.id, sectionEntry);
                }

                sectionEntry.gameObject.SetActive(isVisible);
                sectionEntry.Populate(section);
                sectionEntry.transform.SetAsLastSibling();

                if (sectionEntry.gameObject.activeSelf)
                {
                    visibleSectionEntries.Add(sectionEntry);
                }
                else
                {
                    newSectionEntries.Add(sectionEntry);
                }
            }

            for (int index = 0; index < entriesToRemove.Count; index++)
            {
                DestroySectionEntry(entriesToRemove[index]);
            }

            expandCollapseButton.gameObject.SetActive(sectionEntries.Count > 0);
            SetExpandCollapseState(true);
            OnLayoutRebuildRequested?.Invoke();

            sequenceRoutine = StartCoroutine(Sequence(visibleSectionEntries, newSectionEntries));
        }