| | 1 | | using DCL.Helpers; |
| | 2 | | using DCL.QuestsController; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Huds.QuestsPanel |
| | 8 | | { |
| | 9 | | public class QuestsPanelHUDController : IHUD |
| | 10 | | { |
| | 11 | | internal IQuestsPanelHUDView view; |
| | 12 | | internal IQuestsController questsController; |
| 74 | 13 | | private static BaseDictionary<string, QuestModel> quests => DataStore.i.Quests.quests; |
| | 14 | |
|
| 31 | 15 | | BaseVariable<bool> questsPanelVisible => DataStore.i.HUDs.questsPanelVisible; |
| 30 | 16 | | BaseVariable<Transform> configureQuestInFullscreenMenu => DataStore.i.exploreV2.configureQuestInFullscreenMenu; |
| | 17 | |
|
| | 18 | | public void Initialize(IQuestsController newQuestsController) |
| | 19 | | { |
| 10 | 20 | | questsController = newQuestsController; |
| 10 | 21 | | view = CreateView(); |
| 10 | 22 | | SetViewActive(false); |
| | 23 | |
|
| 10 | 24 | | questsController.OnQuestUpdated += OnQuestUpdated; |
| 10 | 25 | | quests.OnAdded += OnQuestAdded; |
| 10 | 26 | | quests.OnRemoved += OnQuestRemoved; |
| 10 | 27 | | quests.OnSet += OnQuestSet; |
| | 28 | |
|
| 10 | 29 | | questsPanelVisible.OnChange -= OnQuestPanelVisibleChanged; |
| 10 | 30 | | questsPanelVisible.OnChange += OnQuestPanelVisibleChanged; |
| | 31 | |
|
| 10 | 32 | | configureQuestInFullscreenMenu.OnChange += ConfigureQuestInFullscreenMenuChanged; |
| 10 | 33 | | ConfigureQuestInFullscreenMenuChanged(configureQuestInFullscreenMenu.Get(), null); |
| | 34 | |
|
| 10 | 35 | | OnQuestSet(quests.Get()); |
| | 36 | |
|
| 10 | 37 | | DataStore.i.Quests.isInitialized.Set(true); |
| 10 | 38 | | } |
| | 39 | |
|
| 2 | 40 | | private void OnQuestPanelVisibleChanged(bool current, bool previous) { SetViewActive(current); } |
| | 41 | |
|
| | 42 | | private void OnQuestUpdated(string questId, bool hasProgress) |
| | 43 | | { |
| 4 | 44 | | if (!quests.TryGetValue(questId, out QuestModel model) || model.status == QuestsLiterals.Status.BLOCKED || ( |
| | 45 | | { |
| 3 | 46 | | view.RemoveQuest(questId); |
| 3 | 47 | | return; |
| | 48 | | } |
| | 49 | |
|
| 1 | 50 | | view.RequestAddOrUpdateQuest(questId); |
| 1 | 51 | | } |
| | 52 | |
|
| | 53 | | private void OnQuestAdded(string questId, QuestModel questModel) |
| | 54 | | { |
| 13 | 55 | | if (questModel.status == QuestsLiterals.Status.BLOCKED || (questModel.visibility == QuestsLiterals.Visibilit |
| 3 | 56 | | return; |
| 10 | 57 | | view.RequestAddOrUpdateQuest(questId); |
| 10 | 58 | | } |
| | 59 | |
|
| 2 | 60 | | private void OnQuestRemoved(string questId, QuestModel questModel) { view.RemoveQuest(questId); } |
| | 61 | |
|
| | 62 | | private void OnQuestSet(IEnumerable<KeyValuePair<string, QuestModel>> quests) |
| | 63 | | { |
| 13 | 64 | | view.ClearQuests(); |
| 52 | 65 | | foreach ((string key, QuestModel value) in quests) |
| | 66 | | { |
| 13 | 67 | | OnQuestAdded(key, value); |
| | 68 | | } |
| 13 | 69 | | } |
| | 70 | |
|
| 2 | 71 | | public void SetVisibility(bool visible) { questsPanelVisible.Set(visible); } |
| | 72 | |
|
| 22 | 73 | | private void SetViewActive(bool visible) { view?.SetVisibility(visible); } |
| | 74 | |
|
| 1 | 75 | | internal virtual IQuestsPanelHUDView CreateView() => QuestsPanelHUDView.Create(); |
| | 76 | |
|
| | 77 | | public void Dispose() |
| | 78 | | { |
| 10 | 79 | | view.Dispose(); |
| 10 | 80 | | if (questsController != null) |
| 10 | 81 | | questsController.OnQuestUpdated -= OnQuestUpdated; |
| 10 | 82 | | quests.OnAdded -= OnQuestAdded; |
| 10 | 83 | | quests.OnRemoved -= OnQuestRemoved; |
| 10 | 84 | | quests.OnSet -= OnQuestSet; |
| 10 | 85 | | questsPanelVisible.OnChange -= OnQuestPanelVisibleChanged; |
| 10 | 86 | | configureQuestInFullscreenMenu.OnChange -= ConfigureQuestInFullscreenMenuChanged; |
| 10 | 87 | | } |
| | 88 | |
|
| 20 | 89 | | private void ConfigureQuestInFullscreenMenuChanged(Transform currentParentTransform, Transform previousParentTra |
| | 90 | | } |
| | 91 | | } |