only decline offered quests if the player explicitly pressed the decline button

This commit is contained in:
Kae 2024-04-05 23:09:57 +11:00
parent da8e6d1aa8
commit 4458d2e85e
4 changed files with 34 additions and 9 deletions

View File

@ -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<Drawable> 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<ButtonWidget>("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();
}
}

View File

@ -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 {

View File

@ -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();

View File

@ -49,6 +49,7 @@ public:
void offer();
void declineOffer();
void cancelOffer();
void start();
void complete(Maybe<size_t> followupIndex = {});
void fail();