83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include "dialogue/DialogueDatabase.h"
|
|
#include "quest/QuestJournal.h"
|
|
#include <functional>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
namespace ZL::Dialogue {
|
|
|
|
class DialogueRuntime {
|
|
public:
|
|
void setDatabase(const DialogueDatabase* value);
|
|
|
|
bool startDialogue(const std::string& dialogueId);
|
|
void stop();
|
|
|
|
// Called by DialogueSystem after the inline cutscene finishes.
|
|
void resumeFromNode(const std::string& nodeId);
|
|
|
|
void setOnCutsceneStartNeeded(std::function<void(const std::string& cutsceneId, const std::string& nextNodeId)> cb);
|
|
void setOnDialogueLineStarted(std::function<void(const std::string&)> cb);
|
|
void setOnChatBubbleReady(std::function<void(const std::string&, bool)> cb);
|
|
|
|
void update(int deltaMs);
|
|
|
|
bool isActive() const { return mode != Mode::Inactive; }
|
|
bool isInChoice() const { return mode == Mode::WaitingForChoice; }
|
|
|
|
void confirmAdvance();
|
|
void moveSelection(int delta);
|
|
void selectChoice(int index);
|
|
|
|
const PresentationModel& getPresentation() const { return presentation; }
|
|
|
|
void setFlag(const std::string& name, int value);
|
|
int getFlag(const std::string& name) const;
|
|
void setGlobalFlagStore(std::unordered_map<std::string, int>* store);
|
|
void setQuestJournal(Quest::QuestJournal* journal);
|
|
|
|
private:
|
|
enum class Mode {
|
|
Inactive,
|
|
PresentingLine,
|
|
WaitingForChoice,
|
|
WaitingForCutscene // paused while an inline cutscene plays
|
|
};
|
|
|
|
std::function<void(const std::string&, const std::string&)> onCutsceneStartNeeded;
|
|
std::function<void(const std::string&)> onDialogueLineStarted;
|
|
std::function<void(const std::string&, bool)> onChatBubbleReady;
|
|
|
|
const DialogueDatabase* database = nullptr;
|
|
Quest::QuestJournal* questJournal = nullptr;
|
|
const DialogueDefinition* activeDialogue = nullptr;
|
|
|
|
std::unordered_map<std::string, int>* flagStore = nullptr;
|
|
std::unordered_set<std::string> consumedChoices;
|
|
|
|
std::string currentNodeId;
|
|
std::vector<Choice> visibleChoices;
|
|
PresentationModel presentation;
|
|
Mode mode = Mode::Inactive;
|
|
|
|
int selectedChoice = -1;
|
|
float revealCharacters = 0.0f;
|
|
float revealSpeedCharsPerSecond = 52.0f;
|
|
|
|
bool evaluateConditions(const std::vector<Condition>& conditions) const;
|
|
void applyEffects(const std::vector<Effect>& effects);
|
|
void applyQuestActions(const std::string& questUnlock, const std::string& questComplete,
|
|
const std::string& questFail, const std::string& objectiveComplete,
|
|
const std::string& objectiveVisible);
|
|
|
|
bool enterNode(const std::string& nodeId);
|
|
void presentLine(const Node& node);
|
|
void presentChoices(const Node& node);
|
|
};
|
|
|
|
} // namespace ZL::Dialogue
|