1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Add support for right-aligned roomtext

This is mostly so people making levels in an RTL language have a more
pleasant and logical experience. If roomtext is placed in a level set
to RTL, it will get p1=1, which makes that roomtext right-aligned.
Because, imagine for English you click to place roomtext, and the text
runs left of where you clicked, which wouldn't be logical.

Since it's an entity-bound property, switching RTL on and off either in
the editor or via a script does not affect existing entities.
This commit is contained in:
Dav999 2024-01-09 21:50:54 +01:00 committed by Misa Elizabeth Kai
parent 7b46087077
commit 060fe6938d
6 changed files with 26 additions and 4 deletions

View file

@ -1052,8 +1052,14 @@ static void draw_entities(void)
height = font::height(PR_FONT_LEVEL); height = font::height(PR_FONT_LEVEL);
} }
graphics.draw_rect(x, y, width, height, graphics.getRGB(96, 96, 96)); int rect_x = x;
font::print(PR_FONT_LEVEL | PR_CJK_LOW, x, y, entity->scriptname, 196, 196, 255 - help.glow); if (entity->p1)
{
// RTL. The 8 is the size of a tile, not font width!
rect_x -= width - 8;
}
graphics.draw_rect(rect_x, y, width, height, graphics.getRGB(96, 96, 96));
graphics.print_roomtext(x, y, entity->scriptname.c_str(), entity->p1);
break; break;
} }
case 18: // Terminals case 18: // Terminals
@ -2549,7 +2555,7 @@ void editorclass::tool_place()
case EditorTool_ROOMTEXT: case EditorTool_ROOMTEXT:
lclickdelay = 1; lclickdelay = 1;
text_entity = customentities.size(); text_entity = customentities.size();
add_entity(levx, levy, tilex, tiley, 17); add_entity(levx, levy, tilex, tiley, 17, cl.rtl ? 1 : 0);
get_input_line(TEXT_ROOMTEXT, loc::gettext("Enter roomtext:"), &(customentities[text_entity].scriptname)); get_input_line(TEXT_ROOMTEXT, loc::gettext("Enter roomtext:"), &(customentities[text_entity].scriptname));
break; break;
case EditorTool_TERMINALS: case EditorTool_TERMINALS:

View file

@ -3602,3 +3602,15 @@ void Graphics::render_roomname(uint32_t font_flag, const char* roomname, int r,
font::print(font_flag | PR_CEN | PR_BOR | PR_CJK_LOW, -1, footerrect.y+1, roomname, r, g, b); font::print(font_flag | PR_CEN | PR_BOR | PR_CJK_LOW, -1, footerrect.y+1, roomname, r, g, b);
set_blendmode(SDL_BLENDMODE_NONE); set_blendmode(SDL_BLENDMODE_NONE);
} }
void Graphics::print_roomtext(int x, const int y, const char* text, const bool rtl)
{
uint32_t flags = PR_FONT_LEVEL | PR_CJK_LOW;
if (rtl)
{
flags |= PR_RIGHT;
x += 8; // the size of a tile, not font width!
}
font::print(flags, x, y, text, 196, 196, 255 - help.glow);
}

View file

@ -414,6 +414,8 @@ public:
SDL_Color crewcolourreal(int t); SDL_Color crewcolourreal(int t);
void render_roomname(uint32_t font_flag, const char* roomname, int r, int g, int b); void render_roomname(uint32_t font_flag, const char* roomname, int r, int g, int b);
void print_roomtext(int x, int y, const char* text, bool rtl);
}; };
#ifndef GRAPHICS_DEFINITION #ifndef GRAPHICS_DEFINITION

View file

@ -1895,6 +1895,7 @@ void mapclass::loadlevel(int rx, int ry)
text.x = ex / 8; text.x = ex / 8;
text.y = ey / 8; text.y = ey / 8;
text.text = ent.scriptname.c_str(); text.text = ent.scriptname.c_str();
text.rtl = ent.p1;
roomtext.push_back(text); roomtext.push_back(text);
break; break;
} }

View file

@ -16,6 +16,7 @@ struct Roomtext
{ {
int x, y; int x, y;
const char* text; const char* text;
bool rtl;
}; };
enum RoomnameType enum RoomnameType

View file

@ -2364,7 +2364,7 @@ void gamerender(void)
//Draw room text! //Draw room text!
for (size_t i = 0; i < map.roomtext.size(); i++) for (size_t i = 0; i < map.roomtext.size(); i++)
{ {
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); graphics.print_roomtext(map.roomtext[i].x*8, map.roomtext[i].y*8, map.roomtext[i].text, map.roomtext[i].rtl);
} }
} }