4#include <simplesquirrel/simplesquirrel.hpp>
11 const std::string&
text) {
13 if (!lineId.empty()) readLines_.insert(lineId);
20const DialogueUX::HistoryEntry* DialogueUX::historyAt(
int index)
const {
21 return index >= 0 &&
static_cast<size_t>(
index) < history_.size()
22 ? &history_[
static_cast<size_t>(
index)]
27 const auto* entry = historyAt(
index);
28 return entry ? entry->lineId : std::string{};
32 const auto* entry = historyAt(
index);
33 return entry ? entry->speaker : std::string{};
37 const auto* entry = historyAt(
index);
38 return entry ? entry->text : std::string{};
43bool isControlTag(
const std::string&
tag) {
44 const size_t equal =
tag.find(
'=');
45 const std::string
name =
tag.substr(0, equal);
46 return name ==
"pause" ||
name ==
"speed" ||
name ==
"color" ||
name ==
"/color" ||
54 out.reserve(richText.size());
55 for (
size_t i = 0; i < richText.size();) {
56 if (richText[i] ==
'[') {
57 const size_t close = richText.find(
']', i + 1);
58 if (close != std::string::npos && isControlTag(richText.substr(i + 1, close - i - 1))) {
63 out.push_back(richText[i++]);
70 for (
size_t i = 0; i < richText.size();) {
71 if (richText[i] ==
'[') {
72 const size_t close = richText.find(
']', i + 1);
73 if (close != std::string::npos) {
74 if (isControlTag(richText.substr(i + 1, close - i - 1))) ++
count;
87 if (!autoMode_ || voicePlaying)
return false;
88 autoElapsed_ += dt > 0.f ? dt : 0.f;
89 if (autoElapsed_ < autoDelay_)
return false;
95 if (mode !=
"off" && mode !=
"read" && mode !=
"all")
return false;
101 if (!lineId.empty()) readLines_.insert(lineId);
105 return !lineId.empty() && readLines_.find(lineId) != readLines_.end();
109 return skipMode_ ==
"all" || (skipMode_ ==
"read" &&
isRead(lineId));
112void DialogueUX::expose(ssq::Table& table) {
113 auto cls = table.addClass(
name, DialogueUX::create,
false);
117void DialogueUX::expose(ssq::Class&
cls) {
#define Module_IMPL(ModuleName, newExpr)
virtual std::string getName() const =0
Returns the name.
Presentation state shared by default and custom dialogue UIs.
bool isAutoMode() const
True when auto mode.
void setAutoMode(bool enabled)
Sets the auto mode.
std::string getHistoryText(int index) const
Returns the history text.
int getTextActionCount(const std::string &richText) const
Number of pause/speed/style actions in rich text.
void clearHistory()
Clears history.
void record(const std::string &lineId, const std::string &speaker, const std::string &text)
Record a completed line in the player-visible backlog.
void resetAutoTimer()
Resets auto timer.
bool shouldSkip(const std::string &lineId) const
Should skip.
float getAutoDelay() const
Returns the auto delay.
bool isRead(const std::string &lineId) const
True when read.
void setAutoDelay(float seconds)
Sets the auto delay.
bool setSkipMode(const std::string &mode)
Set skip mode: off, read, or all.
std::string getHistoryLineId(int index) const
Returns the history line id.
int getHistoryCount() const
Returns the history count.
bool updateAuto(float dt, bool voicePlaying)
Advance the auto timer; voice playback holds the timer.
std::string getSkipMode() const
Returns the skip mode.
void markRead(const std::string &lineId)
Mark read.
std::string getHistorySpeaker(int index) const
Returns the history speaker.
std::string plainText(const std::string &richText) const
Strip supported control tags for plain UI widgets.