From 4458d2e85ed7f9e373af290dbe8063a52d2824b5 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:09:57 +1100 Subject: [PATCH] only decline offered quests if the player explicitly pressed the decline button --- source/frontend/StarQuestInterface.cpp | 26 ++++++++++++++++++-------- source/frontend/StarQuestInterface.hpp | 10 +++++++++- source/game/StarQuests.cpp | 6 ++++++ source/game/StarQuests.hpp | 1 + 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/source/frontend/StarQuestInterface.cpp b/source/frontend/StarQuestInterface.cpp index b862b31..4015004 100644 --- a/source/frontend/StarQuestInterface.cpp +++ b/source/frontend/StarQuestInterface.cpp @@ -293,7 +293,7 @@ void QuestPane::commonSetup(Json config, String bodyText, String const& portrait GuiReader reader; reader.registerCallback("close", [=](Widget*) { close(); }); - reader.registerCallback("btnDecline", [=](Widget*) { close(); }); + reader.registerCallback("btnDecline", [=](Widget*) { decline(); }); reader.registerCallback("btnAccept", [=](Widget*) { accept(); }); reader.construct(config.get("paneLayout"), this); @@ -330,6 +330,10 @@ void QuestPane::close() { dismiss(); } +void QuestPane::decline() { + close(); +} + void QuestPane::accept() { close(); } @@ -348,7 +352,7 @@ PanePtr QuestPane::createTooltip(Vec2I const& screenPosition) { } NewQuestInterface::NewQuestInterface(QuestManagerPtr const& manager, QuestPtr const& quest, PlayerPtr player) - : QuestPane(quest, std::move(player)), m_manager(manager), m_declined(false) { + : QuestPane(quest, std::move(player)), m_manager(manager), m_decision(QuestDecision::Cancelled) { auto assets = Root::singleton().assets(); List objectivePortrait = m_quest->portrait("Objective").value({}); @@ -364,8 +368,7 @@ NewQuestInterface::NewQuestInterface(QuestManagerPtr const& manager, QuestPtr co commonSetup(config, m_quest->text(), "QuestStarted"); - m_declined = m_quest->canBeAbandoned(); - if (!m_declined) { + if (!m_quest->canBeAbandoned()) { if (auto declineButton = fetchChild("btnDecline")) declineButton->disable(); } @@ -392,21 +395,28 @@ NewQuestInterface::NewQuestInterface(QuestManagerPtr const& manager, QuestPtr co } void NewQuestInterface::close() { - m_declined = true; + m_decision = QuestDecision::Cancelled; + dismiss(); +} + +void NewQuestInterface::decline() { + m_decision = QuestDecision::Declined; dismiss(); } void NewQuestInterface::accept() { - m_declined = false; + m_decision = QuestDecision::Accepted; dismiss(); } void NewQuestInterface::dismissed() { QuestPane::dismissed(); - if (m_declined && m_quest->canBeAbandoned()) { + if (m_decision == QuestDecision::Declined && m_quest->canBeAbandoned()) { m_manager->getQuest(m_quest->questId())->declineOffer(); - } else { + } else if (m_decision == QuestDecision::Accepted) { m_manager->getQuest(m_quest->questId())->start(); + } else { + m_manager->getQuest(m_quest->questId())->cancelOffer(); } } diff --git a/source/frontend/StarQuestInterface.hpp b/source/frontend/StarQuestInterface.hpp index d825b86..f4d523c 100644 --- a/source/frontend/StarQuestInterface.hpp +++ b/source/frontend/StarQuestInterface.hpp @@ -51,6 +51,7 @@ protected: void commonSetup(Json config, String bodyText, String const& portraitName); virtual void close(); + virtual void decline(); virtual void accept(); virtual PanePtr createTooltip(Vec2I const& screenPosition) override; @@ -60,16 +61,23 @@ protected: class NewQuestInterface : public QuestPane { public: + enum class QuestDecision { + Declined, + Accepted, + Cancelled + }; + NewQuestInterface(QuestManagerPtr const& manager, QuestPtr const& quest, PlayerPtr player); protected: void close() override; + void decline() override; void accept() override; void dismissed() override; private: QuestManagerPtr m_manager; - bool m_declined; + QuestDecision m_decision; }; class QuestCompleteInterface : public QuestPane { diff --git a/source/game/StarQuests.cpp b/source/game/StarQuests.cpp index 6643362..6e1dba7 100644 --- a/source/game/StarQuests.cpp +++ b/source/game/StarQuests.cpp @@ -240,6 +240,12 @@ void Quest::declineOffer() { uninitScript(); } +void Quest::cancelOffer() { + setState(QuestState::New); + m_scriptComponent.invoke("questCancel"); + uninitScript(); +} + void Quest::start() { setState(QuestState::Active); initScript(); diff --git a/source/game/StarQuests.hpp b/source/game/StarQuests.hpp index 9621ecd..fc35f2b 100644 --- a/source/game/StarQuests.hpp +++ b/source/game/StarQuests.hpp @@ -49,6 +49,7 @@ public: void offer(); void declineOffer(); + void cancelOffer(); void start(); void complete(Maybe followupIndex = {}); void fail();