Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite textboxes #987

Merged
merged 3 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions desktop_version/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,19 @@ void Game::savecustomlevelstats(void)

void Game::levelcomplete_textbox(void)
{
graphics.createtextboxflipme("", -1, 12, 165, 165, 255);
graphics.createtextboxflipme("", -1, 12, TEXT_COLOUR("cyan"));
graphics.addline(" ");
graphics.addline("");
graphics.addline("");
graphics.textboxprintflags(PR_FONT_8X8);
graphics.textboxcenterx();
graphics.setimage(TEXTIMAGE_LEVELCOMPLETE);
}

void Game::crewmate_textbox(const int r, const int g, const int b)
void Game::crewmate_textbox(const int color)
{
const int extra_cjk_height = (font::height(PR_FONT_INTERFACE) * 4) - 32;
graphics.createtextboxflipme("", -1, 64 + 8 + 16 - extra_cjk_height/2, r, g, b);
graphics.createtextboxflipme("", -1, 64 + 8 + 16 - extra_cjk_height/2, TEXT_COLOUR("gray"));

/* This is a special case for wrapping, we MUST have two lines.
* So just make sure it can't fit in one line. */
Expand All @@ -729,6 +730,7 @@ void Game::crewmate_textbox(const int r, const int g, const int b)
float spaces_per_8 = font::len(PR_FONT_INTERFACE, " ")/8.0f;
graphics.textboxpad(SDL_ceilf(5/spaces_per_8), SDL_ceilf(2/spaces_per_8));
graphics.textboxcenterx();
graphics.addsprite(14, 12, 0, color);
}

void Game::remaining_textbox(void)
Expand Down Expand Up @@ -2493,7 +2495,7 @@ void Game::updatestate(void)
incstate();
setstatedelay(45);

crewmate_textbox(175, 174, 174);
crewmate_textbox(13);
break;
case 3008:
incstate();
Expand Down Expand Up @@ -2535,7 +2537,7 @@ void Game::updatestate(void)
incstate();
setstatedelay(45);

crewmate_textbox(174, 175, 174);
crewmate_textbox(14);
break;
case 3022:
incstate();
Expand Down Expand Up @@ -2576,7 +2578,7 @@ void Game::updatestate(void)
incstate();
setstatedelay(45);

crewmate_textbox(174, 174, 175);
crewmate_textbox(16);
break;
case 3042:
incstate();
Expand Down Expand Up @@ -2618,7 +2620,7 @@ void Game::updatestate(void)
incstate();
setstatedelay(45);

crewmate_textbox(175, 175, 174);
crewmate_textbox(20);
break;
case 3052:
incstate();
Expand Down Expand Up @@ -2684,7 +2686,7 @@ void Game::updatestate(void)
incstate();
setstatedelay(45);

crewmate_textbox(175, 174, 175);
crewmate_textbox(15);
break;
case 3062:
incstate();
Expand Down Expand Up @@ -2900,12 +2902,13 @@ void Game::updatestate(void)
setstatedelay(75);
music.play(Music_PLENARY);

graphics.createtextboxflipme("", -1, 12, 164, 165, 255);
graphics.createtextboxflipme("", -1, 12, TEXT_COLOUR("cyan"));
graphics.addline(" ");
graphics.addline("");
graphics.addline("");
graphics.textboxprintflags(PR_FONT_8X8);
graphics.textboxcenterx();
graphics.setimage(TEXTIMAGE_GAMECOMPLETE);
break;
case 3502:
{
Expand Down
2 changes: 1 addition & 1 deletion desktop_version/src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Game
void gethardestroom(void);

void levelcomplete_textbox(void);
void crewmate_textbox(const int r, const int g, const int b);
void crewmate_textbox(const int color);
void remaining_textbox(void);
void actionprompt_textbox(void);
void savetele_textbox(void);
Expand Down
77 changes: 45 additions & 32 deletions desktop_version/src/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,20 +777,14 @@ const char* Graphics::textbox_line(
void Graphics::drawgui(void)
{
int text_sign;
int crew_yp;
int crew_sprite;

if (flipmode)
{
text_sign = -1;
crew_yp = 64 + 48 + 4;
crew_sprite = 6;
}
else
{
text_sign = 1;
crew_yp = 64 + 32 + 4;
crew_sprite = 0;
}

//Draw all the textboxes to the screen
Expand Down Expand Up @@ -889,7 +883,7 @@ void Graphics::drawgui(void)
continue;
}

if (textboxes[i].yp == 12 && textboxes[i].r == 165)
if (textboxes[i].image == TEXTIMAGE_LEVELCOMPLETE)
{
// Level complete
const char* english = "Level Complete!";
Expand Down Expand Up @@ -926,7 +920,7 @@ void Graphics::drawgui(void)
}
}
}
else if (textboxes[i].yp == 12 && textboxes[i].g == 165)
else if (textboxes[i].image == TEXTIMAGE_GAMECOMPLETE)
{
// Game complete
const char* english = "Game Complete!";
Expand Down Expand Up @@ -962,31 +956,28 @@ void Graphics::drawgui(void)
}
}
}
int crew_xp = textboxes[i].xp+20 - 6;
if (textboxes[i].r == 175 && textboxes[i].g == 175)
{
//purple guy
draw_sprite(crew_xp, crew_yp, crew_sprite, 220 - help.glow / 4 - textboxes[i].rand, 120 - help.glow / 4, 210 - help.glow / 4);
}
else if (textboxes[i].r == 175 && textboxes[i].b == 175)
{
//red guy
draw_sprite(crew_xp, crew_yp, crew_sprite, 255 - help.glow / 8, 70 - help.glow / 4, 70 - help.glow / 4);
}
else if (textboxes[i].r == 175)
{
//green guy
draw_sprite(crew_xp, crew_yp, crew_sprite, 120 - help.glow / 4 - textboxes[i].rand, 220 - help.glow / 4, 120 - help.glow / 4);
}
else if (textboxes[i].g == 175)
{
//yellow guy
draw_sprite(crew_xp, crew_yp, crew_sprite, 220 - help.glow / 4 - textboxes[i].rand, 210 - help.glow / 4, 120 - help.glow / 4);
}
else if (textboxes[i].b == 175)

for (size_t index = 0; index < textboxes[i].sprites.size(); index++)
{
//blue guy
draw_sprite(crew_xp, crew_yp, crew_sprite, 75, 75, 255 - help.glow / 4 - textboxes[i].rand);
TextboxSprite* sprite = &textboxes[i].sprites[index];
int y = sprite->y + yp;

if (flipmode)
{
y = yp + textboxes[i].h - sprite->y - sprites_rect.h;
}

draw_grid_tile(
grphx.im_sprites,
sprite->tile,
sprite->x + textboxes[i].xp,
y,
sprites_rect.w,
sprites_rect.h,
getcol(sprite->col),
1,
(flipmode ? -1 : 1)
);
}
}
}
Expand Down Expand Up @@ -1367,6 +1358,28 @@ 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::setimage(TextboxImage image)
{
if (!INBOUNDS_VEC(m, textboxes))
{
vlog_error("setimage() out-of-bounds!");
return;
}

textboxes[m].setimage(image);
}

void Graphics::addline( const std::string& t )
{
if (!INBOUNDS_VEC(m, textboxes))
Expand Down
4 changes: 4 additions & 0 deletions desktop_version/src/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Graphics

void textboxtimer(int t);

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

void setimage(TextboxImage image);

void textboxremove(void);

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

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

translate_dialogue();
}
Expand Down Expand Up @@ -675,6 +679,30 @@ 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] == "textimage")
{
if (words[1] == "levelcomplete")
{
textbox_image = TEXTIMAGE_LEVELCOMPLETE;
}
else if (words[1] == "gamecomplete")
{
textbox_image = TEXTIMAGE_GAMECOMPLETE;
}
else
{
textbox_image = TEXTIMAGE_NONE;
}
}
else if (words[0] == "flipme")
{
textflipme = !textflipme;
Expand Down Expand Up @@ -706,6 +734,13 @@ 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);
}

graphics.setimage(textbox_image);

// Some textbox formatting that can be set by translations...
if (textcentertext)
{
Expand Down
5 changes: 4 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,8 @@ class scriptclass
bool textbuttons;
bool textlarge;
int textboxtimer;
std::vector<TextboxSprite> textbox_sprites;
TextboxImage textbox_image;

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

print_flags = PR_FONT_LEVEL;
fill_buttons = false;

sprites.clear();

image = TEXTIMAGE_NONE;
}

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::setimage(TextboxImage new_image)
{
image = new_image;
}

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

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

enum TextboxImage
{
TEXTIMAGE_NONE,
TEXTIMAGE_LEVELCOMPLETE,
TEXTIMAGE_GAMECOMPLETE
};

class textboxclass
{
public:
textboxclass(void);

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

void setimage(TextboxImage image);

void centerx(void);

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

uint32_t print_flags;
bool fill_buttons;

std::vector<TextboxSprite> sprites;
TextboxImage image;
};

#endif /* TEXTBOX_H */