shadow-over-bishkek001/src/dialogue/DialogueSystem.h
2026-07-12 16:55:23 +03:00

91 lines
3.3 KiB
C++

#pragma once
#include "external/nlohmann/json.hpp"
#include "dialogue/DialogueOverlay.h"
#include "dialogue/DialogueRuntime.h"
#include "cutscene/CutsceneDatabase.h"
#include "cutscene/CutsceneOverlay.h"
#include "cutscene/CutsceneRuntime.h"
#include "quest/QuestJournal.h"
#include "ISaveable.h"
#include <SDL.h>
#include <functional>
#include <string>
namespace ZL::Dialogue {
class DialogueSystem : public ZL::ISaveable {
public:
bool init(Renderer& renderer, const std::string& zipFile = "");
bool loadDatabase(const std::string& path);
bool loadCutsceneDatabase(const std::string& path);
bool loadTranslations(const std::string& path);
bool loadCutsceneTranslations(const std::string& path);
void update(int deltaMs);
void draw(Renderer& renderer);
bool handleKeyDown(SDL_Keycode key);
void handlePointerDown(float x, float y);
void handlePointerMoved(float x, float y);
bool handlePointerReleased(float x, float y);
bool startDialogue(const std::string& dialogueId);
bool startCutscene(const std::string& cutsceneId);
void skipCutscene();
void setOnCutsceneStarted(std::function<void()> cb);
void setOnCutsceneFinished(std::function<void(const std::string&)> cb);
void setOnCutsceneFinishedExtra(std::function<void(const std::string&)> cb);
void setOnDialogueLineStarted(std::function<void(const std::string&)> cb);
void setOnCutsceneLineStarted(std::function<void(const std::string&)> cb);
void setOnCutsceneFadeInComplete(std::function<void(const std::string&)> cb);
void setOnChatBubbleReady(std::function<void(const std::string&, bool)> cb);
void setOnDialogueAdvanced(std::function<void()> cb);
void stopDialogue();
void saveDialogueState(nlohmann::json& out) const { dialogueRuntime.save(out); }
void loadDialogueState(const nlohmann::json& in) { dialogueRuntime.load(in); }
void save(nlohmann::json& out) const override { saveDialogueState(out); }
void load(const nlohmann::json& in) override { loadDialogueState(in); }
bool isActive() const { return dialogueRuntime.isActive() || cutsceneRuntime.isActive(); }
bool isDialogueActive() const { return dialogueRuntime.isActive(); }
bool blocksGameplayInput() const { return isActive(); }
void setFlag(const std::string& name, int value) { dialogueRuntime.setFlag(name, value); }
int getFlag(const std::string& name) const { return dialogueRuntime.getFlag(name); }
void setGlobalFlagStore(std::unordered_map<std::string, int>* store) {
dialogueRuntime.setGlobalFlagStore(store);
}
void setQuestJournal(Quest::QuestJournal* journal) {
dialogueRuntime.setQuestJournal(journal);
}
private:
DialogueDatabase database;
TranslationDatabase translationDatabase;
DialogueRuntime dialogueRuntime;
DialogueOverlay dialogueOverlay;
ZL::Cutscene::CutsceneDatabase cutsceneDatabase;
TranslationDatabase cutsceneTranslationDatabase;
ZL::Cutscene::CutsceneRuntime cutsceneRuntime;
ZL::Cutscene::CutsceneOverlay cutsceneOverlay;
std::function<void()> onDialogueAdvancedCallback;
std::function<void()> onCutsceneStartedCallback;
std::function<void(const std::string&)> onCutsceneFinishedCallback;
std::function<void(const std::string&)> onCutsceneFinishedExtraCallback;
// Pending node to resume after an inline cutscene finishes.
std::string pendingNodeAfterCutscene;
void onCutsceneFinishedInternal(const std::string& id);
};
} // namespace ZL::Dialogue