Page 1 of 1

How to toggle between Active and Complete Quests [SOLVED]

Posted: Sat Jul 22, 2023 9:20 pm
by Luseya
Hello again!

This is sort of a followup to this thread: https://www.pixelcrushers.com/phpbb/vie ... f=9&t=7289

I would like to set up the Quest Journal UI so that the Player can toggle between Active and Completed quests. This way, they would only view the Active Quests in one panel (just to make a cleaner UI since my game will have a crazy amount of characters and quests). This is how it looks:
QuestListScreenshot.png
QuestListScreenshot.png (64.73 KiB) Viewed 434 times
So basically, when you click the "ACTIVE" button, you would only see the Active quests, and when you click the COMPLETE button, you would only see the completed quests.

Is there a way to accomplish this without scripting? So far, the methods I have tried don't work. This is what I have tried so far:

1. Setting up the buttons to activate and deactivate the Active Quest Name Template and the Completed Quest Name Template.
QuestsNavBarButtonSettings.png
QuestsNavBarButtonSettings.png (12.08 KiB) Viewed 434 times
2. Making the Active Quest Name Template the child of another panel that would get activated/deactivated by the buttons, and same with the Completed Quest Name Template.

And that's pretty much it. It's fine if scripting is required; I can pass it on to the developer if so, but I wanted to see if I could accomplish it on my own without scripting since the quest design/quest machine setup tasks fall under my responsibilities. Thank you so much!

Re: How to toggle between Active and Complete Quests

Posted: Sat Jul 22, 2023 9:59 pm
by Tony Li
Hi,

It will require a little scripting. You'd change the CustomQuestJournalUI script to something like:

CustomQuestJournalUI.cs

Code: Select all

using UnityEngine;
using UnityEngine.UI;

namespace PixelCrushers.QuestMachine.Examples
{

    public class CustomQuestJournalUI : UnityUIQuestJournalUI
    {

        [SerializeField] private Button showActiveQuestsButton;
        [SerializeField] private Button showCompletedQuestsButton;
        [SerializeField] private GameObject detailsPanel;

        private bool showActiveQuests = true;

        protected virtual void Start()
        {
            showActiveQuestsButton.onClick.AddListener(() => { ShowQuestsInState(true); });
            showCompletedQuestsButton.onClick.AddListener(() => { ShowQuestsInState(false); });
        }

        protected virtual void ShowQuestsInState(bool showActive)
        {
            showActiveQuests = showActive;
            Repaint();
        }

        protected override void AddQuestToUI(Quest quest, RectTransform container)
        {
            if (quest == null) return;
                var state = quest.GetState();
                var isCompleted = state == QuestState.Successful || state == QuestState.Failed;
            if ((showActiveQuests && state == QuestState.Active) ||
                (!showActiveQuests && isCompleted))
            {
                base.AddQuestToUI(quest, container);
            }
        }

        protected override void RepaintSelectedQuest()
        {
            detailsPanel.SetActive(selectedQuest != null);
            base.RepaintSelectedQuest();
        }
    }
}
and add buttons to ACTIVE and COMPLETED.

Here's an updated example scene:

QM_CustomJournalUIExample_2023-07-22.unitypackage

Re: How to toggle between Active and Complete Quests

Posted: Sun Jul 23, 2023 2:50 pm
by Luseya
Perfect, thank you so much! This is exactly what I needed :)

Re: How to toggle between Active and Complete Quests [SOLVED]

Posted: Sun Jul 23, 2023 2:54 pm
by Tony Li
Glad to help!