How to toggle between Active and Complete Quests [SOLVED]

Announcements, support questions, and discussion for Quest Machine.
Post Reply
Luseya
Posts: 24
Joined: Mon May 29, 2023 6:02 pm

How to toggle between Active and Complete Quests [SOLVED]

Post 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 426 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 426 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!
Last edited by Luseya on Sun Jul 23, 2023 2:51 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 20731
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to toggle between Active and Complete Quests

Post 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
Luseya
Posts: 24
Joined: Mon May 29, 2023 6:02 pm

Re: How to toggle between Active and Complete Quests

Post by Luseya »

Perfect, thank you so much! This is exactly what I needed :)
User avatar
Tony Li
Posts: 20731
Joined: Thu Jul 18, 2013 1:27 pm

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

Post by Tony Li »

Glad to help!
Post Reply