#pragma once #include "dialogue/DialogueRuntime.h" #include "render/Renderer.h" #include "render/TextRenderer.h" #include "render/TextureManager.h" #include "UiManager.h" #include #include #include #include namespace ZL::Dialogue { class DialogueOverlay { public: bool init(Renderer& renderer, const std::string& zipFile = ""); void draw(Renderer& renderer, const PresentationModel& model); // Coordinates are expected in the game's UI projection space // Returns true only when the click should advance/select. bool handlePointerReleased(float x, float y, const PresentationModel& model, int& outChoiceIndex) const; private: struct TexturedQuad { UiRect rect; VertexRenderStruct mesh; bool initialized = false; void rebuild(const UiRect& newRect); }; Renderer* rendererRef = nullptr; std::string zipFilename; std::shared_ptr textboxTexture; std::shared_ptr portraitFrameTexture; std::shared_ptr choiceMainTexture; std::shared_ptr choiceOptionalTexture; std::shared_ptr choiceSelectedTexture; std::shared_ptr cutsceneSubtitleTexture; mutable std::vector lastChoiceRects; mutable UiRect lastDialogueAdvanceRect{}; mutable UiRect lastCutsceneAdvanceRect{}; mutable bool cutsceneAdvanceEnabled = false; std::unique_ptr nameRenderer; std::unique_ptr bodyRenderer; std::unique_ptr choiceRenderer; std::unique_ptr cutsceneRenderer; TexturedQuad portraitQuad; TexturedQuad textboxQuad; TexturedQuad subtitleQuad; TexturedQuad backgroundQuad; mutable std::vector choiceQuads; std::unordered_map> textureCache; void drawDialogue(Renderer& renderer, const PresentationModel& model); void drawCutscene(Renderer& renderer, const PresentationModel& model); std::shared_ptr loadTextureCached(const std::string& path); void drawQuad(Renderer& renderer, const TexturedQuad& quad, const std::shared_ptr& texture) const; static std::string wrapText(const std::string& input, size_t maxLineLength); }; } // namespace ZL::Dialogue