mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Start using level-specific font where needed, make CJK tweaks
Level text such as room names, text box content, and the contents of the script editor need to be displayed in the level-specific font, and tweaked to look right. This involves displaying less lines in the script editor, making text boxes bigger, displaying some text higher and some text lower. This is still unfinished, but it's the real start of a migration to font::print functions!
This commit is contained in:
parent
29a3789dec
commit
6ca83114bc
8 changed files with 133 additions and 45 deletions
|
@ -99,6 +99,7 @@ void editorclass::reset(void)
|
|||
sbx=0;
|
||||
sby=0;
|
||||
pagey=0;
|
||||
lines_visible = 25;
|
||||
scripteditmod=false;
|
||||
sbscript="null";
|
||||
scripthelppage=0;
|
||||
|
@ -755,9 +756,9 @@ void editorrender(void)
|
|||
}
|
||||
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),16,24,graphics.getRGB(255, 255, 164));
|
||||
short labelcol = ed.entframe<2 ? 255 : 196;
|
||||
short startlen = graphics.len(loc::gettext("START"));
|
||||
graphics.bprint(
|
||||
(customentities[i].x*8) - (ed.levx*40*8) + 8 - startlen/2,
|
||||
font::print(
|
||||
PR_BOR | PR_CEN | PR_CJK_HIGH,
|
||||
(customentities[i].x*8) - (ed.levx*40*8) + 8,
|
||||
(customentities[i].y*8) - (ed.levy*30*8) - 8,
|
||||
loc::gettext("START"),
|
||||
labelcol,labelcol,labelcol
|
||||
|
@ -767,14 +768,13 @@ void editorrender(void)
|
|||
case 17: //Roomtext
|
||||
if(customentities[i].scriptname.length()<1)
|
||||
{
|
||||
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),8,8,graphics.getRGB(96,96,96));
|
||||
fillboxabs((customentities[i].x*8)-(ed.levx*40*8), (customentities[i].y*8)-(ed.levy*30*8), 8, 8, graphics.getRGB(96,96,96));
|
||||
}
|
||||
else
|
||||
{
|
||||
int length = utf8::unchecked::distance(customentities[i].scriptname.begin(), customentities[i].scriptname.end());
|
||||
fillboxabs((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8),length*8,8,graphics.getRGB(96,96,96));
|
||||
fillboxabs((customentities[i].x*8)-(ed.levx*40*8), (customentities[i].y*8)-(ed.levy*30*8), font::len(PR_FONT_LEVEL, customentities[i].scriptname), font::height(PR_FONT_LEVEL), graphics.getRGB(96,96,96));
|
||||
}
|
||||
graphics.Print((customentities[i].x*8)- (ed.levx*40*8),(customentities[i].y*8)- (ed.levy*30*8), customentities[i].scriptname, 196, 196, 255 - help.glow);
|
||||
font::print(PR_FONT_LEVEL | PR_CJK_LOW, (customentities[i].x*8)-(ed.levx*40*8), (customentities[i].y*8)-(ed.levy*30*8), customentities[i].scriptname, 196, 196, 255 - help.glow);
|
||||
break;
|
||||
case 18: //Terminals
|
||||
{
|
||||
|
@ -1214,17 +1214,18 @@ void editorrender(void)
|
|||
);
|
||||
graphics.Print(16,228, namebuffer, 123, 111, 218, true);
|
||||
//Draw text
|
||||
for(int i=0; i<25; i++)
|
||||
int font_height = font::height(PR_FONT_LEVEL);
|
||||
for(int i=0; i<ed.lines_visible; i++)
|
||||
{
|
||||
if(i+ed.pagey<(int)ed.sb.size())
|
||||
{
|
||||
graphics.Print(16,20+(i*8),ed.sb[i+ed.pagey], 123, 111, 218, false);
|
||||
font::print(PR_FONT_LEVEL, 16, 20+(i*font_height), ed.sb[i+ed.pagey], 123, 111, 218);
|
||||
}
|
||||
}
|
||||
//Draw cursor
|
||||
if(ed.entframe<2)
|
||||
{
|
||||
graphics.Print(16+(ed.sbx*8),20+(ed.sby*8),"_",123, 111, 218, false);
|
||||
font::print(PR_FONT_LEVEL, 16+font::len(PR_FONT_LEVEL, ed.sb[ed.pagey+ed.sby]),20+(ed.sby*font_height),"_",123, 111, 218);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1348,7 +1349,7 @@ void editorrender(void)
|
|||
|
||||
fillboxabs(4+(ed.drawmode*tg), 209,20,20,graphics.getRGB(200,200,200));
|
||||
|
||||
graphics.Print(4, 232, "1/2", 196, 196, 255 - help.glow, false);
|
||||
font::print(PR_CJK_HIGH, 4, 232, "1/2", 196, 196, 255 - help.glow);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1358,10 +1359,8 @@ void editorrender(void)
|
|||
}
|
||||
graphics.fill_rect(4+((ed.drawmode-10)*tg), 209,20,20,graphics.getRGB(64,64,64));
|
||||
//10:
|
||||
graphics.Print(tx,ty,"A",196, 196, 255 - help.glow, false);
|
||||
graphics.Print(tx+8,ty,"B",196, 196, 255 - help.glow, false);
|
||||
graphics.Print(tx,ty+8,"C",196, 196, 255 - help.glow, false);
|
||||
graphics.Print(tx+8,ty+8,"D",196, 196, 255 - help.glow, false);
|
||||
font::print(PR_FONT_8X8, tx, ty, "AB", 196, 196, 255 - help.glow);
|
||||
font::print(PR_FONT_8X8, tx, ty+8, "CD", 196, 196, 255 - help.glow);
|
||||
//11:
|
||||
tx+=tg;
|
||||
graphics.draw_sprite(tx,ty,17,196,196,196);
|
||||
|
@ -1391,7 +1390,7 @@ void editorrender(void)
|
|||
|
||||
fillboxabs(4 + (ed.drawmode - 10) * tg, 209, 20, 20, graphics.getRGB(200, 200, 200));
|
||||
|
||||
graphics.Print(4, 232, "2/2", 196, 196, 255 - help.glow, false);
|
||||
font::print(PR_CJK_HIGH, 4, 232, "2/2", 196, 196, 255 - help.glow);
|
||||
}
|
||||
|
||||
char changetooltext[SCREEN_WIDTH_CHARS + 1];
|
||||
|
@ -1400,7 +1399,7 @@ void editorrender(void)
|
|||
"button1:str, button2:str",
|
||||
",", "."
|
||||
);
|
||||
graphics.Print(320-graphics.len(changetooltext), 232, changetooltext, 196, 196, 255 - help.glow, false);
|
||||
font::print(PR_CJK_HIGH | PR_RIGHT, 320, 232, changetooltext, 196, 196, 255 - help.glow);
|
||||
|
||||
const char* toolname;
|
||||
switch(ed.drawmode)
|
||||
|
@ -1467,7 +1466,7 @@ void editorrender(void)
|
|||
|
||||
graphics.fill_rect(260,197,80,11, graphics.getRGB(32,32,32));
|
||||
graphics.fill_rect(261,198,80,10, graphics.getRGB(0,0,0));
|
||||
graphics.bprint(268,199, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")",196, 196, 255 - help.glow, false);
|
||||
font::print(PR_BOR | PR_CJK_HIGH | PR_RIGHT, 316, 199, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")", 196, 196, 255 - help.glow);
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -1482,14 +1481,14 @@ void editorrender(void)
|
|||
graphics.fill_rect(&graphics.footerrect, graphics.getRGBA(0, 0, 0, graphics.translucentroomname ? 127 : 255));
|
||||
graphics.set_blendmode(SDL_BLENDMODE_NONE);
|
||||
|
||||
graphics.bprint(5,231+ed.roomnamehide,room->roomname, 196, 196, 255 - help.glow, true);
|
||||
graphics.bprint(4, 222, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow, false);
|
||||
graphics.bprint(268,222, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")",196, 196, 255 - help.glow, false);
|
||||
font::print(PR_CEN | PR_BOR | PR_FONT_LEVEL | PR_CJK_LOW, -1, 231+ed.roomnamehide, room->roomname, 196, 196, 255 - help.glow);
|
||||
font::print(PR_BOR | PR_CJK_HIGH, 4, 222, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow);
|
||||
font::print(PR_BOR | PR_CJK_HIGH | PR_RIGHT, 316, 222, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")", 196, 196, 255 - help.glow);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.bprint(4, 232, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow, false);
|
||||
graphics.bprint(268,232, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")",196, 196, 255 - help.glow, false);
|
||||
font::print(PR_BOR | PR_CJK_HIGH, 4, 232, loc::gettext("SPACE ^ SHIFT ^"), 196, 196, 255 - help.glow);
|
||||
font::print(PR_BOR | PR_CJK_HIGH | PR_RIGHT, 316, 232, "("+help.String(ed.levx+1)+","+help.String(ed.levy+1)+")", 196, 196, 255 - help.glow);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1856,6 +1855,7 @@ static void editormenuactionpress(void)
|
|||
ed.scripthelppagedelay=0;
|
||||
ed.sby=0;
|
||||
ed.sbx=0, ed.pagey=0;
|
||||
ed.lines_visible = 200/font::height(PR_FONT_LEVEL);
|
||||
break;
|
||||
case 2:
|
||||
music.playef(11);
|
||||
|
@ -2191,7 +2191,7 @@ void editorinput(void)
|
|||
|
||||
ed.sby=ed.sb.size()-1;
|
||||
ed.pagey=0;
|
||||
while(ed.sby>=20)
|
||||
while(ed.sby>=ed.lines_visible-5)
|
||||
{
|
||||
ed.pagey++;
|
||||
ed.sby--;
|
||||
|
@ -2240,7 +2240,7 @@ void editorinput(void)
|
|||
if(ed.sby+ed.pagey<(int)ed.sb.size()-1)
|
||||
{
|
||||
ed.sby++;
|
||||
if(ed.sby>=20)
|
||||
if(ed.sby>=ed.lines_visible-5)
|
||||
{
|
||||
ed.pagey++;
|
||||
ed.sby--;
|
||||
|
@ -2299,7 +2299,7 @@ void editorinput(void)
|
|||
if(ed.sby+ed.pagey>=(int)ed.sb.size()) //we're on the last line
|
||||
{
|
||||
ed.sby++;
|
||||
if(ed.sby>=20)
|
||||
if(ed.sby>=ed.lines_visible-5)
|
||||
{
|
||||
ed.pagey++;
|
||||
ed.sby--;
|
||||
|
@ -2311,7 +2311,7 @@ void editorinput(void)
|
|||
{
|
||||
//We're not, insert a line instead
|
||||
ed.sby++;
|
||||
if(ed.sby>=20)
|
||||
if(ed.sby>=ed.lines_visible-5)
|
||||
{
|
||||
ed.pagey++;
|
||||
ed.sby--;
|
||||
|
|
|
@ -147,6 +147,7 @@ public:
|
|||
std::string sbscript;
|
||||
int sbx, sby;
|
||||
int pagey;
|
||||
int lines_visible;
|
||||
|
||||
//Functions for interfacing with the script:
|
||||
void addhook(const std::string& t);
|
||||
|
|
|
@ -118,6 +118,11 @@ static GlyphInfo* find_glyphinfo(const Font* f, const uint32_t codepoint)
|
|||
int get_advance(const Font* f, const uint32_t codepoint)
|
||||
{
|
||||
// Get the width of a single character in a font
|
||||
if (f == NULL)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
GlyphInfo* glyph = find_glyphinfo(f, codepoint);
|
||||
if (glyph == NULL)
|
||||
{
|
||||
|
@ -341,7 +346,8 @@ static bool find_font_by_name(FontContainer* container, const char* name, size_t
|
|||
|
||||
static void set_custom_font(const char* name)
|
||||
{
|
||||
/* Apply the choice for a certain level-specific font */
|
||||
/* Apply the choice for a certain level-specific font. */
|
||||
|
||||
if (find_font_by_name(&fonts_custom, name, &font_idx_custom))
|
||||
{
|
||||
font_idx_custom_is_custom = true;
|
||||
|
@ -693,11 +699,59 @@ static int print_char(
|
|||
return glyph->advance * scale;
|
||||
}
|
||||
|
||||
static Font* container_get(FontContainer* container, size_t idx)
|
||||
{
|
||||
/* Get a certain font from the given container (with bounds checking).
|
||||
* Does its best to return at least something,
|
||||
* but if there are no fonts whatsoever, can return NULL. */
|
||||
|
||||
if (idx < container->count)
|
||||
{
|
||||
return &container->fonts[idx];
|
||||
}
|
||||
if (font_idx_8x8 < fonts_main.count)
|
||||
{
|
||||
return &fonts_main.fonts[font_idx_8x8];
|
||||
}
|
||||
if (fonts_main.count > 0)
|
||||
{
|
||||
return &fonts_main.fonts[0];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Font* fontsel_to_font(int sel)
|
||||
{
|
||||
/* Take font selection integer (0-31) and turn it into the correct Font */
|
||||
// TODO handle all these cases here like 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 etc
|
||||
return &fonts_main.fonts[font_idx_8x8];
|
||||
/* Take font selection integer (0-31) and turn it into the correct Font
|
||||
* 0: PR_FONT_INTERFACE - use interface font
|
||||
* 1: PR_FONT_LEVEL - use level font
|
||||
* 2: PR_FONT_8X8 - use 8x8 font no matter what
|
||||
* 3-31: - use (main) font index 0-28 */
|
||||
|
||||
if (sel < 0)
|
||||
{
|
||||
/* Shouldn't happen but better safe than sorry... */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (sel)
|
||||
{
|
||||
case 0:
|
||||
return container_get(&fonts_main, font_idx_interface);
|
||||
case 1:
|
||||
if (font_idx_custom_is_custom)
|
||||
{
|
||||
return container_get(&fonts_custom, font_idx_custom);
|
||||
}
|
||||
else
|
||||
{
|
||||
return container_get(&fonts_main, font_idx_custom);
|
||||
}
|
||||
case 2:
|
||||
return container_get(&fonts_main, font_idx_8x8);
|
||||
}
|
||||
|
||||
return container_get(&fonts_main, sel-3);
|
||||
}
|
||||
|
||||
#define FLAG_PART(start, count) ((flags >> start) % (1 << count))
|
||||
|
@ -742,6 +796,17 @@ int len(const uint32_t flags, const std::string& t)
|
|||
return text_len * pf.scale;
|
||||
}
|
||||
|
||||
int height(const uint32_t flags)
|
||||
{
|
||||
PrintFlags pf = decode_print_flags(flags);
|
||||
if (pf.font_sel == NULL)
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
return pf.font_sel->glyph_h * pf.scale;
|
||||
}
|
||||
|
||||
void print(
|
||||
const uint32_t flags,
|
||||
int x,
|
||||
|
@ -753,6 +818,10 @@ void print(
|
|||
)
|
||||
{
|
||||
PrintFlags pf = decode_print_flags(flags);
|
||||
if (pf.font_sel == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (pf.align_cen || pf.align_right)
|
||||
{
|
||||
|
|
|
@ -115,6 +115,7 @@ std::string string_wordwrap_balanced(const std::string& s, int maxwidth);
|
|||
std::string string_unwordwrap(const std::string& s);
|
||||
|
||||
int len(uint32_t flags, const std::string& t);
|
||||
int height(const uint32_t flags);
|
||||
|
||||
void print(
|
||||
uint32_t flags,
|
||||
|
|
|
@ -873,11 +873,17 @@ void Graphics::drawgui(void)
|
|||
const int b = textboxes[i].b * tl_lerp;
|
||||
size_t j;
|
||||
|
||||
drawtextbox(textboxes[i].xp, yp, textboxes[i].w/8, textboxes[i].h/8, r, g, b);
|
||||
drawpixeltextbox(textboxes[i].xp, yp, textboxes[i].w, textboxes[i].h, r, g, b);
|
||||
|
||||
for (j = 0; j < textboxes[i].lines.size(); j++)
|
||||
{
|
||||
font::print(PR_COLORGLYPH_BRI(tl_lerp*255), textboxes[i].xp + 8, yp + text_yoff + text_sign * (j * 8), textboxes[i].lines[j], r, g, b);
|
||||
font::print(
|
||||
PR_COLORGLYPH_BRI(tl_lerp*255) | PR_CJK_LOW,
|
||||
textboxes[i].xp + 8,
|
||||
yp + text_yoff + text_sign * (j * font::height(PR_FONT_LEVEL)),
|
||||
textboxes[i].lines[j],
|
||||
r, g, b
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1336,7 +1342,7 @@ void Graphics::drawtextbox(
|
|||
const int g,
|
||||
const int b
|
||||
) {
|
||||
return drawpixeltextbox(x, y, w*8, h*8, r, g, b);
|
||||
return drawpixeltextbox(x, y, w*8, 16 + (h-2)*font::height(PR_FONT_LEVEL), r, g, b);
|
||||
}
|
||||
|
||||
void Graphics::textboxactive(void)
|
||||
|
@ -3476,10 +3482,19 @@ SDL_Color Graphics::crewcolourreal(int t)
|
|||
|
||||
void Graphics::render_roomname(const char* roomname, int r, int g, int b)
|
||||
{
|
||||
footerrect.y = 230;
|
||||
int font_height = font::height(PR_FONT_LEVEL);
|
||||
if (font_height <= 8)
|
||||
{
|
||||
footerrect.h = font_height + 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
footerrect.h = font_height + 1;
|
||||
}
|
||||
footerrect.y = 240 - footerrect.h;
|
||||
|
||||
set_blendmode(SDL_BLENDMODE_BLEND);
|
||||
fill_rect(&footerrect, getRGBA(0, 0, 0, translucentroomname ? 127 : 255));
|
||||
bprint(5, 231, roomname, r, g, b, true);
|
||||
font::print(PR_CEN | PR_BOR | PR_FONT_LEVEL | PR_CJK_LOW, -1, footerrect.y+1, roomname, r, g, b);
|
||||
set_blendmode(SDL_BLENDMODE_NONE);
|
||||
}
|
||||
|
|
|
@ -1945,7 +1945,7 @@ void gamerender(void)
|
|||
//Draw room text!
|
||||
for (size_t i = 0; i < map.roomtext.size(); i++)
|
||||
{
|
||||
graphics.Print(map.roomtext[i].x*8, (map.roomtext[i].y*8), map.roomtext[i].text, 196, 196, 255 - help.glow);
|
||||
font::print(PR_FONT_LEVEL | PR_CJK_LOW, map.roomtext[i].x*8, (map.roomtext[i].y*8), map.roomtext[i].text, 196, 196, 255 - help.glow);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2233,7 +2233,7 @@ void gamerender(void)
|
|||
game.activity_b*act_alpha
|
||||
);
|
||||
font::print(
|
||||
PR_COLORGLYPH_BRI(act_alpha*255),
|
||||
PR_COLORGLYPH_BRI(act_alpha*255) | PR_CJK_LOW,
|
||||
centered_x + game.activity_x,
|
||||
game.activity_y + 12,
|
||||
final_string,
|
||||
|
|
|
@ -577,12 +577,12 @@ void scriptclass::run(void)
|
|||
if (j == 1) //left
|
||||
{
|
||||
textx = obj.entities[i].xp -10000; //tells the box to be oriented correctly later
|
||||
texty = obj.entities[i].yp - 16 - (txt.size()*8);
|
||||
texty = obj.entities[i].yp - 16 - (txt.size() * font::height(PR_FONT_LEVEL));
|
||||
}
|
||||
else if (j == 0) //Right
|
||||
{
|
||||
textx = obj.entities[i].xp - 16;
|
||||
texty = obj.entities[i].yp - 18 - (txt.size() * 8);
|
||||
texty = obj.entities[i].yp - 18 - (txt.size() * font::height(PR_FONT_LEVEL));
|
||||
}
|
||||
}
|
||||
else if (INBOUNDS_VEC(i, obj.entities))
|
||||
|
@ -674,12 +674,12 @@ void scriptclass::run(void)
|
|||
if (j == 1) //left
|
||||
{
|
||||
textx = obj.entities[i].xp -10000; //tells the box to be oriented correctly later
|
||||
texty = obj.entities[i].yp - 16 - (txt.size()*8);
|
||||
texty = obj.entities[i].yp - 16 - (txt.size() * font::height(PR_FONT_LEVEL));
|
||||
}
|
||||
else if (j == 0) //Right
|
||||
{
|
||||
textx = obj.entities[i].xp - 16;
|
||||
texty = obj.entities[i].yp - 18 - (txt.size() * 8);
|
||||
texty = obj.entities[i].yp - 18 - (txt.size() * font::height(PR_FONT_LEVEL));
|
||||
}
|
||||
}
|
||||
else if (INBOUNDS_VEC(i, obj.entities))
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <SDL.h>
|
||||
#include <utf8/unchecked.h>
|
||||
|
||||
#include "Font.h"
|
||||
|
||||
textboxclass::textboxclass(void)
|
||||
{
|
||||
w = 0;
|
||||
|
@ -100,13 +102,13 @@ void textboxclass::resize(void)
|
|||
int max = 0;
|
||||
for (size_t iter = 0; iter < lines.size(); iter++)
|
||||
{
|
||||
unsigned int len = utf8::unchecked::distance(lines[iter].begin(), lines[iter].end());
|
||||
int len = font::len(PR_FONT_LEVEL, lines[iter]);
|
||||
if (len > (unsigned int)max) max = len;
|
||||
}
|
||||
|
||||
// 16 for the borders
|
||||
w = max*8 + 16;
|
||||
h = lines.size()*8 + 16;
|
||||
w = max + 16;
|
||||
h = lines.size()*font::height(PR_FONT_LEVEL) + 16;
|
||||
}
|
||||
|
||||
void textboxclass::addline(const std::string& t)
|
||||
|
|
Loading…
Reference in a new issue