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.
This commit is contained in:
Dav999-v
2023-03-18 22:31:13 +01:00
committed by Misa Elizabeth Kai
parent 3354a1a352
commit 620365614d
8 changed files with 75 additions and 4 deletions

View File

@@ -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 */