Skip to content

Commit

Permalink
Initial implementation of textbox sprites
Browse files Browse the repository at this point in the history
This commit adds a system for displaying sprites in textboxes, meant to
replace the hardcoded system in the main game. This does not support
levelcomplete.png and gamecomplete.png yet, which will most likely just
be special cases.
  • Loading branch information
AllyTally committed Aug 13, 2023
1 parent 1006626 commit a34aff2
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
22 changes: 22 additions & 0 deletions desktop_version/src/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,17 @@ void Graphics::drawgui(void)
//blue guy
draw_sprite(crew_xp, crew_yp, crew_sprite, 75, 75, 255 - help.glow / 4 - textboxes[i].rand);
}

for (int index = 0; index < (int) textboxes[i].sprites.size(); index++)
{
TextboxSprite* sprite = &textboxes[i].sprites[index];
draw_sprite(
sprite->x + textboxes[i].xp,
sprite->y + textboxes[i].yp,
sprite->tile,
getcol(sprite->col)
);
}
}
}

Expand Down Expand Up @@ -1367,6 +1378,17 @@ void Graphics::textboxtimer(int t)
textboxes[m].timer = t;
}

void Graphics::addsprite(int x, int y, int tile, int col)
{
if (!INBOUNDS_VEC(m, textboxes))
{
vlog_error("addsprite() out-of-bounds!");
return;
}

textboxes[m].addsprite(x, y, tile, col);
}

void Graphics::addline( const std::string& t )
{
if (!INBOUNDS_VEC(m, textboxes))
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 @@ -122,6 +122,8 @@ class Graphics

void textboxtimer(int t);

void addsprite(int x, int y, int tile, int col);

void textboxremove(void);

void textboxremovefast(void);
Expand Down
16 changes: 16 additions & 0 deletions desktop_version/src/Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ scriptclass::scriptclass(void)
textcase = 1;
textbuttons = false;
textlarge = false;
textbox_sprites.clear();
}

void scriptclass::add_default_colours(void)
Expand Down Expand Up @@ -505,6 +506,7 @@ void scriptclass::run(void)
textpad_right = 0;
textpadtowidth = 0;
textboxtimer = 0;
textbox_sprites.clear();

translate_dialogue();
}
Expand Down Expand Up @@ -675,6 +677,15 @@ void scriptclass::run(void)
{
textboxtimer = ss_toi(words[1]);
}
else if (words[0] == "textsprite")
{
TextboxSprite sprite;
sprite.x = ss_toi(words[1]);
sprite.y = ss_toi(words[2]);
sprite.tile = ss_toi(words[3]);
sprite.col = ss_toi(words[4]);
textbox_sprites.push_back(sprite);
}
else if (words[0] == "flipme")
{
textflipme = !textflipme;
Expand Down Expand Up @@ -706,6 +717,11 @@ void scriptclass::run(void)
graphics.textboxtimer(textboxtimer);
}

for (size_t i = 0; i < textbox_sprites.size(); i++)
{
graphics.addsprite(textbox_sprites[i].x, textbox_sprites[i].y, textbox_sprites[i].tile, textbox_sprites[i].col);
}

// Some textbox formatting that can be set by translations...
if (textcentertext)
{
Expand Down
4 changes: 3 additions & 1 deletion desktop_version/src/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define SCRIPT_H

#include <map>
#include <SDL.h>
#include <string>
#include <vector>

#include <SDL.h>
#include "Textbox.h"

#define filllines(lines) commands.insert(commands.end(), lines, lines + SDL_arraysize(lines))

Expand Down Expand Up @@ -123,6 +124,7 @@ class scriptclass
bool textbuttons;
bool textlarge;
int textboxtimer;
std::vector<TextboxSprite> textbox_sprites;

//Misc
int i, j, k;
Expand Down
12 changes: 12 additions & 0 deletions desktop_version/src/Textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ textboxclass::textboxclass(void)

print_flags = PR_FONT_LEVEL;
fill_buttons = false;

sprites.clear();
}

void textboxclass::addsprite(int x, int y, int tile, int col)
{
TextboxSprite sprite;
sprite.x = x;
sprite.y = y;
sprite.tile = tile;
sprite.col = col;
sprites.push_back(sprite);
}

void textboxclass::centerx(void)
Expand Down
12 changes: 12 additions & 0 deletions desktop_version/src/Textbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
#include <string>
#include <vector>

struct TextboxSprite
{
int x;
int y;
int col;
int tile;
};

class textboxclass
{
public:
textboxclass(void);

void addsprite(int x, int y, int tile, int col);

void centerx(void);

void centery(void);
Expand Down Expand Up @@ -53,6 +63,8 @@ class textboxclass

uint32_t print_flags;
bool fill_buttons;

std::vector<TextboxSprite> sprites;
};

#endif /* TEXTBOX_H */

0 comments on commit a34aff2

Please sign in to comment.