Skip to content

Commit

Permalink
Add textbuttons() script command, make Violet's ENTER dialogue dynamic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Daaaav authored and InfoTeddy committed Mar 22, 2023
1 parent 3354a1a commit 6203656
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 4 deletions.
3 changes: 2 additions & 1 deletion desktop_version/lang/en/cutscenes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@
<cutscene id="bigopenworldskip" explanation="">
<dialogue speaker="purple" english="I&apos;ll be right here if you need any help!" translation=""/>
</cutscene>
<cutscene id="talkpurple_intro" explanation="">
<cutscene id="talkpurple_intro" explanation="***ENTER is OUTDATED***">
<dialogue speaker="player" english="I&apos;m feeling a bit overwhelmed, Doctor." translation=""/>
<dialogue speaker="player" english="Where do I begin?" translation=""/>
<dialogue speaker="purple" english="Remember that you can press ENTER to check where you are on the map!" translation=""/>
<dialogue speaker="purple" english="Remember that you can press {b_map} to check where you are on the map!" translation=""/>
<dialogue speaker="purple" english="Look for areas where the rest of the crew might be..." translation=""/>
<dialogue speaker="purple" english="If you get lost, you can get back to the ship from any teleporter." translation=""/>
<dialogue speaker="purple" english="And don&apos;t worry! We&apos;ll find everyone!" translation=""/>
Expand Down
55 changes: 53 additions & 2 deletions desktop_version/src/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions desktop_version/src/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class Graphics

void textboxprintflags(uint32_t flags);

void textboxbuttons(void);

void textboxcommsrelay(void);

void textboxadjust(void);
Expand Down
13 changes: 13 additions & 0 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <limits.h>
#include <SDL_timer.h>

#include "Alloc.h"
#include "Constants.h"
#include "CustomLevels.h"
#include "Editor.h"
Expand Down Expand Up @@ -48,6 +49,7 @@ scriptclass::scriptclass(void)
textpad_right = 0;
textpadtowidth = 0;
textcase = 1;
textbuttons = false;
textlarge = false;
}

Expand Down Expand Up @@ -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")
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions desktop_version/src/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class scriptclass
size_t textpad_right;
size_t textpadtowidth;
char textcase;
bool textbuttons;
bool textlarge;

//Misc
Expand Down
3 changes: 2 additions & 1 deletion desktop_version/src/Scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
1 change: 1 addition & 0 deletions desktop_version/src/Textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ textboxclass::textboxclass(void)
large = false;

print_flags = PR_FONT_LEVEL;
fill_buttons = false;
}

void textboxclass::centerx(void)
Expand Down
1 change: 1 addition & 0 deletions desktop_version/src/Textbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class textboxclass
bool large;

uint32_t print_flags;
bool fill_buttons;
};

#endif /* TEXTBOX_H */

0 comments on commit 6203656

Please sign in to comment.