From 620365614de9ee6ecdfb3c6d1da7144b9470ecb4 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sat, 18 Mar 2023 22:31:13 +0100 Subject: [PATCH] Add textbuttons() script command, make Violet's ENTER dialogue dynamic Violet's dialogue now looks like this: squeak(purple) text(purple,0,0,2) Remember that you can press {b_map} to check where you are on the map! position(purple,above) textbuttons() speak_active The new textbuttons() command sets the next textbox to replace {b_map} with the map button, and {b_int} with the interact button. The remaining keys would be added as soon as they need to be added to ActionSets.h as well. --- desktop_version/lang/en/cutscenes.xml | 3 +- desktop_version/src/Graphics.cpp | 55 ++++++++++++++++++++++++++- desktop_version/src/Graphics.h | 2 + desktop_version/src/Script.cpp | 13 +++++++ desktop_version/src/Script.h | 1 + desktop_version/src/Scripts.cpp | 3 +- desktop_version/src/Textbox.cpp | 1 + desktop_version/src/Textbox.h | 1 + 8 files changed, 75 insertions(+), 4 deletions(-) diff --git a/desktop_version/lang/en/cutscenes.xml b/desktop_version/lang/en/cutscenes.xml index 4ac5d538..4fc2715c 100644 --- a/desktop_version/lang/en/cutscenes.xml +++ b/desktop_version/lang/en/cutscenes.xml @@ -76,10 +76,11 @@ - + + diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 73df8702..7a817326 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -764,6 +764,17 @@ void Graphics::drawtile3( int x, int y, int t, int off, int height_subtract /*= draw_texture_part(grphx.im_tiles3, x, y, x2, y2, 8, 8 - height_subtract, 1, 1); } +static void fill_buttons(char* buffer, const size_t buffer_len, const char* line) +{ + vformat_buf(buffer, buffer_len, + line, + "b_int:but," + "b_map:but", + vformat_button(ActionSet_InGame, Action_InGame_Interact), + vformat_button(ActionSet_InGame, Action_InGame_Map) + ); +} + void Graphics::drawgui(void) { int text_sign; @@ -840,15 +851,44 @@ void Graphics::drawgui(void) const int b = textboxes[i].b * tl_lerp; size_t j; - drawpixeltextbox(textboxes[i].xp, yp, textboxes[i].w, textboxes[i].h, r, g, b); + int w = textboxes[i].w; + if (textboxes[i].fill_buttons) + { + /* If we can fill in buttons, the width of the box may change... + * This is Violet's fault. She decided to say a button name out loud. */ + int max = 0; + char buffer[SCREEN_WIDTH_CHARS + 1]; + for (j = 0; j < textboxes[i].lines.size(); j++) + { + fill_buttons(buffer, sizeof(buffer), textboxes[i].lines[j].c_str()); + int len = font::len(textboxes[i].print_flags, buffer); + if (len > max) + { + max = len; + } + } + w = max + 16; + } + + drawpixeltextbox(textboxes[i].xp, yp, w, textboxes[i].h, r, g, b); for (j = 0; j < textboxes[i].lines.size(); j++) { + const char* line = textboxes[i].lines[j].c_str(); + char buffer[SCREEN_WIDTH_CHARS + 1]; + + if (textboxes[i].fill_buttons) + { + // Fill button placeholders like {b_map} in dialogue text. + fill_buttons(buffer, sizeof(buffer), line); + line = buffer; + } + font::print( textboxes[i].print_flags | PR_BRIGHTNESS(tl_lerp*255) | PR_CJK_LOW, textboxes[i].xp + 8, yp + text_yoff + text_sign * (j * font_height), - textboxes[i].lines[j], + line, textboxes[i].r, textboxes[i].g, textboxes[i].b ); } @@ -3148,6 +3188,17 @@ void Graphics::textboxprintflags(const uint32_t flags) textboxes[m].resize(); } +void Graphics::textboxbuttons(void) +{ + if (!INBOUNDS_VEC(m, textboxes)) + { + vlog_error("textboxbuttons() out-of-bounds!"); + return; + } + + textboxes[m].fill_buttons = true; +} + void Graphics::textboxcommsrelay(void) { /* Special treatment for the gamestate textboxes in Comms Relay */ diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index cac0c12a..30a2a510 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -111,6 +111,8 @@ public: void textboxprintflags(uint32_t flags); + void textboxbuttons(void); + void textboxcommsrelay(void); void textboxadjust(void); diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index a5f39a6f..ffa213f3 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -4,6 +4,7 @@ #include #include +#include "Alloc.h" #include "Constants.h" #include "CustomLevels.h" #include "Editor.h" @@ -48,6 +49,7 @@ scriptclass::scriptclass(void) textpad_right = 0; textpadtowidth = 0; textcase = 1; + textbuttons = false; textlarge = false; } @@ -798,6 +800,12 @@ void scriptclass::run(void) || key.isDown(KEYBOARD_UP) || key.isDown(KEYBOARD_DOWN)) game.jumpheld = true; } game.backgroundtext = false; + + if (textbuttons) + { + graphics.textboxbuttons(); + } + textbuttons = false; } else if (words[0] == "endtext") { @@ -2427,6 +2435,11 @@ void scriptclass::run(void) } } } + else if (words[0] == "textbuttons") + { + // Parse buttons in the next textbox + textbuttons = true; + } else if (words[0] == "textcase") { // Used to disambiguate identical textboxes for translations (1 by default) diff --git a/desktop_version/src/Script.h b/desktop_version/src/Script.h index 77692576..476d236c 100644 --- a/desktop_version/src/Script.h +++ b/desktop_version/src/Script.h @@ -111,6 +111,7 @@ public: size_t textpad_right; size_t textpadtowidth; char textcase; + bool textbuttons; bool textlarge; //Misc diff --git a/desktop_version/src/Scripts.cpp b/desktop_version/src/Scripts.cpp index 97130097..cf82c79c 100644 --- a/desktop_version/src/Scripts.cpp +++ b/desktop_version/src/Scripts.cpp @@ -5054,9 +5054,10 @@ bool scriptclass::load(const std::string& name) "squeak(purple)", "text(purple,0,0,2)", - "Remember that you can press ENTER", + "Remember that you can press {b_map}", "to check where you are on the map!", "position(purple,above)", + "textbuttons()", "speak_active", "squeak(purple)", diff --git a/desktop_version/src/Textbox.cpp b/desktop_version/src/Textbox.cpp index 9b0f8479..7978a3da 100644 --- a/desktop_version/src/Textbox.cpp +++ b/desktop_version/src/Textbox.cpp @@ -27,6 +27,7 @@ textboxclass::textboxclass(void) large = false; print_flags = PR_FONT_LEVEL; + fill_buttons = false; } void textboxclass::centerx(void) diff --git a/desktop_version/src/Textbox.h b/desktop_version/src/Textbox.h index 4e82effc..46cf1f1f 100644 --- a/desktop_version/src/Textbox.h +++ b/desktop_version/src/Textbox.h @@ -52,6 +52,7 @@ public: bool large; uint32_t print_flags; + bool fill_buttons; }; #endif /* TEXTBOX_H */