private void QuestsListElementInserted(
            NetworkSyncList <PlayerCharacterQuests.CharacterQuestEntry> source,
            int index,
            PlayerCharacterQuests.CharacterQuestEntry value)
        {
            var vm = new ViewModelQuestEntry(value, this.ViewModelQuestEntryOnCompletedStateChanged);

            if (vm.QuestEntry.IsCompleted)
            {
                this.CompletedQuests.Insert(0, vm);
                if (this.CompletedQuests.Count == 1)
                {
                    // display completed quests
                    this.NotifyPropertyChanged(nameof(this.CompletedQuests));
                }

                this.NotifyPropertyChanged(nameof(this.UnlockedQuestsCount));
                return;
            }

            // add new active quest
            // make it expanded by default
            vm.SetIsCollapsed(false, removeNewFlag: false);
            this.ActiveQuests.Add(vm);
            if (this.ActiveQuests.Count == 1)
            {
                // remove no active quests label
                this.NotifyPropertyChanged(nameof(this.ActiveQuests));
            }

            Api.Client.Audio.PlayOneShot(new SoundResource("UI/Quests/QuestUnlocked.ogg"));
            this.NotifyPropertyChanged(nameof(this.UnlockedQuestsCount));
        }
        private void ViewModelQuestEntryOnCompletedStateChanged(ViewModelQuestEntry viewModel)
        {
            if (viewModel.QuestEntry.IsCompleted)
            {
                if (!this.ActiveQuests.Contains(viewModel))
                {
                    return;
                }

                // the quest is completed now
                // move the quest to the completed quests list
                this.ActiveQuests.Remove(viewModel);
                if (this.ActiveQuests.Count == 0)
                {
                    // display no active quests label
                    this.NotifyPropertyChanged(nameof(this.ActiveQuests));
                }

                viewModel.SetIsCollapsed(true);
                this.CompletedQuests.Insert(0, viewModel);
                if (this.CompletedQuests.Count == 1)
                {
                    // display completed quests
                    this.NotifyPropertyChanged(nameof(this.CompletedQuests));
                }

                this.NotifyPropertyChanged(nameof(this.UnlockedQuestsCount));
                return;
            }

            // the quest is not completed
            if (!this.CompletedQuests.Contains(viewModel))
            {
                return;
            }

            // move the quest to the active quests list
            this.CompletedQuests.Remove(viewModel);
            if (this.CompletedQuests.Count == 0)
            {
                // hide completed quests
                this.NotifyPropertyChanged(nameof(this.CompletedQuests));
            }

            viewModel.SetIsCollapsed(true);
            this.ActiveQuests.Add(viewModel);
            if (this.ActiveQuests.Count == 1)
            {
                // remove no active quests label
                this.NotifyPropertyChanged(nameof(this.ActiveQuests));
            }

            this.NotifyPropertyChanged(nameof(this.UnlockedQuestsCount));
        }
Esempio n. 3
0
        private void QuestsListElementInserted(
            NetworkSyncList <PlayerCharacterQuests.CharacterQuestEntry> source,
            int index,
            PlayerCharacterQuests.CharacterQuestEntry value)
        {
            var vm = new ViewModelQuestEntry(value, this.ViewModelQuestEntryOnCompletedStateChanged);

            if (vm.QuestEntry.IsCompleted)
            {
                this.CompletedQuests.Insert(0, vm);
                if (this.CompletedQuests.Count == 1)
                {
                    // display completed quests
                    this.NotifyPropertyChanged(nameof(this.CompletedQuests));
                }

                this.NotifyPropertyChanged(nameof(this.UnlockedQuestsCount));
                return;
            }

            // add new active quest
            // make it expanded by default
            vm.SetIsCollapsed(false, removeNewFlag: false);
            this.ActiveQuests.Add(vm);
            if (this.ActiveQuests.Count == 1)
            {
                // remove no active quests label
                this.NotifyPropertyChanged(nameof(this.ActiveQuests));
            }

            // play quest unlocked sound (not more often than once per frame)
            if (lastQuestUnlockedFrame != Client.CurrentGame.ServerFrameNumber)
            {
                lastQuestUnlockedFrame = Client.CurrentGame.ServerFrameNumber;
                Api.Client.Audio.PlayOneShot(SoundResourceQuestUnlocked, volume: 0.5f);
            }

            this.NotifyPropertyChanged(nameof(this.UnlockedQuestsCount));
        }