Dialogue markup and lines, shared common folder, item atlases, ids, seconds and key checks
This commit is contained in:
1 parent
3e9a0cbd34
commit
f900a0d01f
217 files changed
+6833
-6426
No files matched your search
+20
-18
@@ -220,13 +220,13 @@ static float hash_unit(Uint32 value)
|
||||
return (value & 0xffffu) / 65535.0f;
|
||||
}
|
||||
|
||||
// The scale, color and offset a dialogue entry's effects give its character at an index.
|
||||
static float letter_style_get(const Entry& entry, int at, float time, ImU32& color, ImVec2& offset)
|
||||
// The scale, color and offset a dialogue line's effects give its character at an index.
|
||||
static float letter_style_get(const Line& line, int at, float time, ImU32& color, ImVec2& offset)
|
||||
{
|
||||
float scale = 1;
|
||||
color = ImGui::GetColorU32(ImGuiCol_Text);
|
||||
offset = {};
|
||||
for (const Effect& effect : entry.effects)
|
||||
for (const Effect& effect : line.effects)
|
||||
{
|
||||
if (at < effect.start || at >= effect.end)
|
||||
continue;
|
||||
@@ -235,7 +235,7 @@ static float letter_style_get(const Entry& entry, int at, float time, ImU32& col
|
||||
color = ImGui::GetColorU32(imvec4_get({effect.color.r, effect.color.g, effect.color.b, 1}));
|
||||
else if (effect.type == EFFECT_BIG || effect.type == EFFECT_SMALL)
|
||||
scale = effect.type == EFFECT_BIG ? TEXT_BIG : TEXT_SMALL;
|
||||
else if (effect.type == EFFECT_OSCILLATION)
|
||||
else if (effect.type == EFFECT_WAVE)
|
||||
offset.y +=
|
||||
std::sin((time * OSCILLATION_FREQUENCY + at * OSCILLATION_SPREAD) * 2 * PI) * OSCILLATION_AMPLITUDE;
|
||||
else if (effect.type == EFFECT_SHAKE)
|
||||
@@ -247,8 +247,8 @@ static float letter_style_get(const Entry& entry, int at, float time, ImU32& col
|
||||
return scale;
|
||||
}
|
||||
|
||||
// Draws a dialogue entry's first count characters with their effects, wrapping whole words to the window.
|
||||
static void letters_draw(const Entry& entry, int count, float time)
|
||||
// Draws a dialogue line's first count characters with their effects, wrapping whole words to the window.
|
||||
static void letters_draw(const Line& line, int count, float time)
|
||||
{
|
||||
ImFont* font = ImGui::GetFont();
|
||||
float fontSize = ImGui::GetFontSize();
|
||||
@@ -256,11 +256,11 @@ static void letters_draw(const Entry& entry, int count, float time)
|
||||
float wrap = start.x + ImGui::GetContentRegionAvail().x;
|
||||
ImVec2 cursor = start;
|
||||
float lineHeight = fontSize;
|
||||
const char* end = entry.text.data() + entry.text.size();
|
||||
const char* end = line.text.data() + line.text.size();
|
||||
auto width_get = [&](const char* from, const char* to, int at) {
|
||||
ImU32 color;
|
||||
ImVec2 offset;
|
||||
return font->CalcTextSizeA(fontSize * letter_style_get(entry, at, time, color, offset), FLT_MAX, 0, from, to).x;
|
||||
return font->CalcTextSizeA(fontSize * letter_style_get(line, at, time, color, offset), FLT_MAX, 0, from, to).x;
|
||||
};
|
||||
auto line_break = [&]() {
|
||||
cursor = {start.x, cursor.y + lineHeight};
|
||||
@@ -268,7 +268,7 @@ static void letters_draw(const Entry& entry, int count, float time)
|
||||
};
|
||||
|
||||
int at = 0;
|
||||
for (const char* it = entry.text.data(); it < end && at < count; at++)
|
||||
for (const char* it = line.text.data(); it < end && at < count; at++)
|
||||
{
|
||||
unsigned int codepoint = 0;
|
||||
const char* next = it + ImTextCharFromUtf8(&codepoint, it, end);
|
||||
@@ -294,7 +294,7 @@ static void letters_draw(const Entry& entry, int count, float time)
|
||||
}
|
||||
ImU32 color;
|
||||
ImVec2 offset;
|
||||
float scale = letter_style_get(entry, at, time, color, offset);
|
||||
float scale = letter_style_get(line, at, time, color, offset);
|
||||
float width = width_get(it, next, at);
|
||||
if (cursor.x + width > wrap)
|
||||
{
|
||||
@@ -421,7 +421,9 @@ void Ui::text_draw(Play& play, ImVec2 screen)
|
||||
{
|
||||
Text& text = play.text;
|
||||
Entry* entry = text.entry;
|
||||
if (!entry || entry->text.empty())
|
||||
Line* line = text.line_get();
|
||||
bool isChoosing = entry && text.is_last_line() && !entry->choices.empty();
|
||||
if (!entry || (line->text.empty() && !isChoosing))
|
||||
return;
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec2 size = {screen.x * TEXT_WIDTH - style.WindowPadding.x * 2,
|
||||
@@ -441,13 +443,13 @@ void Ui::text_draw(Play& play, ImVec2 screen)
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::PushFont(nullptr, FONT_NORMAL);
|
||||
letters_draw(*entry, text.index, (float)ImGui::GetTime());
|
||||
letters_draw(*line, text.index, (float)ImGui::GetTime());
|
||||
|
||||
ImVec2 position = ImGui::GetWindowPos();
|
||||
ImVec2 contentMin = {position.x + style.WindowPadding.x, position.y + style.WindowPadding.y};
|
||||
ImVec2 contentMax = {position.x + ImGui::GetWindowWidth() - style.WindowPadding.x,
|
||||
position.y + ImGui::GetWindowHeight() - style.WindowPadding.y};
|
||||
if (text.isFinished && !entry->choices.empty())
|
||||
if (text.isFinished && isChoosing)
|
||||
{
|
||||
float buttonY = contentMax.y - ImGui::GetFrameHeight();
|
||||
float separatorY = buttonY - style.ItemSpacing.y;
|
||||
@@ -473,7 +475,7 @@ void Ui::text_draw(Play& play, ImVec2 screen)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (text.isFinished && !entry->next.empty())
|
||||
if (text.isFinished && (!text.is_last_line() || !entry->next.empty()))
|
||||
{
|
||||
float side = ImGui::GetTextLineHeightWithSpacing();
|
||||
ImVec2 center = {contentMax.x - side / 2 +
|
||||
@@ -757,9 +759,9 @@ void Ui::catalog_tab_draw(Play& play)
|
||||
for (int i = 0; i < (int)items.size(); i++)
|
||||
{
|
||||
ImGui::PushID(i);
|
||||
bool isColored = play.items.discovered[i] && items[i].color.a > 0;
|
||||
bool isColored = play.items.discovered[i] && items[i].color;
|
||||
if (isColored)
|
||||
style_push(items[i].color);
|
||||
style_push(*items[i].color);
|
||||
bool isCurrent = i == selectedItem;
|
||||
if (isCurrent)
|
||||
for (ImGuiCol id : {ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive})
|
||||
@@ -795,9 +797,9 @@ void Ui::catalog_tab_draw(Play& play)
|
||||
|
||||
if (infoHeight <= 0)
|
||||
return;
|
||||
bool isColored = isDiscovered && items[selectedItem].color.a > 0;
|
||||
bool isColored = isDiscovered && items[selectedItem].color;
|
||||
if (isColored)
|
||||
style_push(items[selectedItem].color);
|
||||
style_push(*items[selectedItem].color);
|
||||
if (ImGui::BeginChild("##Info", {available.x, infoHeight}))
|
||||
{
|
||||
ImGui::Separator();
|
||||
|
||||
Reference in new issue
Block a user