1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 16:24:35 +01:00

implement utf8, part 24 (bug fixes)

This commit is contained in:
IntelOrca
2015-08-02 11:25:26 +01:00
parent d228d13918
commit 7bcb12503a
6 changed files with 95 additions and 95 deletions

View File

@@ -971,7 +971,7 @@ static void ttf_draw_string_raw_ttf(rct_drawpixelinfo *dpi, const utf8 *text, te
TTFFontDescriptor *fontDesc = ttf_get_font_from_sprite_base(info->font_sprite_base);
if (fontDesc->font == NULL) {
return ttf_draw_string_raw_sprite(dpi, text, info);
ttf_draw_string_raw_sprite(dpi, text, info);
}
if (info->flags & TEXT_DRAW_FLAG_NO_DRAW) {

View File

@@ -29,17 +29,17 @@ bool gConsoleOpen = false;
static bool _consoleInitialised = false;
static int _consoleLeft, _consoleTop, _consoleRight, _consoleBottom;
static int _lastMainViewportX, _lastMainViewportY;
static char _consoleBuffer[CONSOLE_BUFFER_SIZE] = { 0 };
static char *_consoleBufferPointer = _consoleBuffer;
static char *_consoleViewBufferStart = _consoleBuffer;
static char _consoleCurrentLine[CONSOLE_INPUT_SIZE];
static char *_consoleCurrentLinePointer = _consoleCurrentLine;
static utf8 _consoleBuffer[CONSOLE_BUFFER_SIZE] = { 0 };
static utf8 *_consoleBufferPointer = _consoleBuffer;
static utf8 *_consoleViewBufferStart = _consoleBuffer;
static utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE];
static utf8 *_consoleCurrentLinePointer = _consoleCurrentLine;
static int _consoleCaretTicks;
static char _consolePrintfBuffer[CONSOLE_BUFFER_2_SIZE];
static char _consoleErrorBuffer[CONSOLE_BUFFER_2_SIZE];
static utf8 _consolePrintfBuffer[CONSOLE_BUFFER_2_SIZE];
static utf8 _consoleErrorBuffer[CONSOLE_BUFFER_2_SIZE];
static int _consoleScrollPos = 0;
static char _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
static utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
static int _consoleHistoryIndex = 0;
static int _consoleHistoryCount = 0;
@@ -47,14 +47,14 @@ static void console_invalidate();
static void console_write_prompt();
static void console_update_scroll();
static void console_clear_input();
static void console_history_add(const char *src);
static void console_history_add(const utf8 *src);
static void console_write_all_commands();
static int console_parse_int(const char *src, bool *valid);
static double console_parse_double(const char *src, bool *valid);
static int console_parse_int(const utf8 *src, bool *valid);
static double console_parse_double(const utf8 *src, bool *valid);
static int cc_variables(const char **argv, int argc);
static int cc_windows(const char **argv, int argc);
static int cc_help(const char **argv, int argc);
static int cc_variables(const utf8 **argv, int argc);
static int cc_windows(const utf8 **argv, int argc);
static int cc_help(const utf8 **argv, int argc);
static bool invalidArguments(bool *invalid, bool arguments);
@@ -121,12 +121,7 @@ void console_update()
}
// Remove unwated characters in console input
unsigned char *ch = (unsigned char*)_consoleCurrentLine;
while (*ch != 0) {
if (*ch < 32 || *ch > 126)
*ch = ' ';
ch++;
}
utf8_remove_format_codes(_consoleCurrentLine);
}
// Flash the caret
@@ -137,19 +132,21 @@ void console_draw(rct_drawpixelinfo *dpi)
{
if (!gConsoleOpen)
return;
// Set font
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = (gConfigInterface.console_small_font ? FONT_SPRITE_BASE_SMALL : FONT_SPRITE_BASE_MEDIUM);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0;
int lineHeight = font_get_line_height(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16));
int lines = 0;
int maxLines = ((_consoleBottom - 22 - _consoleTop) / 10) - 1;
char *ch = strchr(_consoleBuffer, 0);
int maxLines = ((_consoleBottom - 22 - _consoleTop) / lineHeight) - 1;
utf8 *ch = strchr(_consoleBuffer, 0);
while (ch > _consoleBuffer) {
ch--;
if (*ch == '\n')
lines++;
}
// Set font
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = (gConfigInterface.console_small_font ? 0 : 224);
RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_FLAGS, uint16) = 0;
// Background
gfx_fill_rect(dpi, _consoleLeft, _consoleTop, _consoleRight, _consoleBottom, 10);
@@ -157,13 +154,13 @@ void console_draw(rct_drawpixelinfo *dpi)
int y = _consoleTop + 4;
// Draw previous lines
char lineBuffer[1 + 256];
utf8 lineBuffer[2 + 256], *lineCh;
ch = _consoleViewBufferStart;
int currentLine = 0;
int drawLines = 0;
while (*ch != 0) {
// Find line break or null terminator
char *nextLine = ch;
utf8 *nextLine = ch;
while (*nextLine != 0 && *nextLine != '\n') {
nextLine++;
}
@@ -173,7 +170,7 @@ void console_draw(rct_drawpixelinfo *dpi)
if (*nextLine == '\n') {
ch = nextLine + 1;
x = _consoleLeft + 4;
//y += 10;
// y += lineHeight;
}
else {
break;
@@ -185,10 +182,11 @@ void console_draw(rct_drawpixelinfo *dpi)
break;
drawLines++;
int lineLength = min(sizeof(lineBuffer) - 1, nextLine - ch);
strncpy(lineBuffer + 1, ch, lineLength);
lineBuffer[0] = FORMAT_GREEN;
lineBuffer[1 + lineLength] = 0;
int lineLength = min(sizeof(lineBuffer) - (size_t)utf8_get_codepoint_length(FORMAT_GREEN), (size_t)(nextLine - ch));
lineCh = lineBuffer;
lineCh = utf8_write_codepoint(lineCh, FORMAT_GREEN);
strncpy(lineCh, ch, lineLength);
lineCh[lineLength] = 0;
gfx_draw_string(dpi, lineBuffer, 255, x, y);
@@ -197,16 +195,18 @@ void console_draw(rct_drawpixelinfo *dpi)
if (*nextLine == '\n') {
ch = nextLine + 1;
x = _consoleLeft + 4;
y += 10;
y += lineHeight;
} else {
break;
}
}
x = _consoleLeft + 4;
y = _consoleBottom - 15;
// Draw current line
strcpy(lineBuffer + 1, _consoleCurrentLine);
lineBuffer[0] = FORMAT_GREEN;
lineCh = lineBuffer;
lineCh = utf8_write_codepoint(lineCh, FORMAT_GREEN);
strcpy(lineCh, _consoleCurrentLine);
gfx_draw_string(dpi, lineBuffer, 255, x, y);
// Draw caret
@@ -214,7 +214,7 @@ void console_draw(rct_drawpixelinfo *dpi)
memcpy(lineBuffer, _consoleCurrentLine, gTextInputCursorPosition);
lineBuffer[gTextInputCursorPosition] = 0;
int caretX = x + gfx_get_string_width(lineBuffer);
int caretY = y + 10;
int caretY = y + lineHeight;
gfx_fill_rect(dpi, caretX, caretY, caretX + 6, caretY + 1, FORMAT_GREEN);
}
@@ -273,7 +273,7 @@ static void console_write_prompt()
console_write("> ");
}
void console_write(const char *src)
void console_write(const utf8 *src)
{
int charactersRemainingInBuffer = CONSOLE_BUFFER_SIZE - (_consoleBufferPointer - _consoleBuffer) - 1;
int charactersToWrite = strlen(src);
@@ -287,27 +287,27 @@ void console_write(const char *src)
console_update_scroll();
}
void console_writeline(const char *src)
void console_writeline(const utf8 *src)
{
console_write(src);
console_write("\n");
}
void console_writeline_error(const char *src)
void console_writeline_error(const utf8 *src)
{
strcpy(_consoleErrorBuffer + 1, src);
_consoleErrorBuffer[0] = FORMAT_RED;
console_writeline(_consoleErrorBuffer);
}
void console_writeline_warning(const char *src)
void console_writeline_warning(const utf8 *src)
{
strcpy(_consoleErrorBuffer + 1, src);
_consoleErrorBuffer[0] = FORMAT_YELLOW;
console_writeline(_consoleErrorBuffer);
}
void console_printf(const char *format, ...)
void console_printf(const utf8 *format, ...)
{
va_list list;
va_start(list, format);
@@ -316,15 +316,15 @@ void console_printf(const char *format, ...)
console_writeline(_consolePrintfBuffer);
}
int console_parse_int(const char *src, bool *valid) {
char *end;
int console_parse_int(const utf8 *src, bool *valid) {
utf8 *end;
int value;
value = strtol(src, &end, 10); *valid = (*end == '\0');
return value;
}
double console_parse_double(const char *src, bool *valid) {
char *end;
double console_parse_double(const utf8 *src, bool *valid) {
utf8 *end;
double value;
value = strtod(src, &end); *valid = (*end == '\0');
return value;
@@ -351,7 +351,7 @@ void console_scroll(int delta)
int speed = 3;
int lines = 0;
int maxLines = ((_consoleBottom - 22 - _consoleTop) / 10) - 1;
char *ch = strchr(_consoleBuffer, 0);
utf8 *ch = strchr(_consoleBuffer, 0);
while (ch > _consoleBuffer) {
ch--;
if (*ch == '\n')
@@ -390,7 +390,7 @@ static void console_clear_input()
gTextInputLength = 0;
}
static void console_history_add(const char *src)
static void console_history_add(const utf8 *src)
{
if (_consoleHistoryCount >= CONSOLE_HISTORY_SIZE) {
for (int i = 0; i < _consoleHistoryCount - 1; i++)
@@ -401,26 +401,26 @@ static void console_history_add(const char *src)
_consoleHistoryIndex = _consoleHistoryCount;
}
static int cc_clear(const char **argv, int argc)
static int cc_clear(const utf8 **argv, int argc)
{
console_clear();
return 0;
}
static int cc_hide(const char **argv, int argc)
static int cc_hide(const utf8 **argv, int argc)
{
console_close();
return 0;
}
static int cc_echo(const char **argv, int argc)
static int cc_echo(const utf8 **argv, int argc)
{
if (argc > 0)
console_writeline(argv[0]);
return 0;
}
static int cc_get(const char **argv, int argc)
static int cc_get(const utf8 **argv, int argc)
{
if (argc > 0) {
if (strcmp(argv[0], "park_rating") == 0) {
@@ -496,7 +496,7 @@ static int cc_get(const char **argv, int argc)
console_printf("construction_rights_cost %d.%d0", RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, money32) / 10, RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, money32) % 10);
}
else if (strcmp(argv[0], "climate") == 0) {
const char* climate_names[] = { "cool_and_wet", "warm", "hot_and_dry", "cold" };
const utf8* climate_names[] = { "cool_and_wet", "warm", "hot_and_dry", "cold" };
console_printf("climate %s (%d)", climate_names[RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8)], RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8));
}
else if (strcmp(argv[0], "game_speed") == 0) {
@@ -533,7 +533,7 @@ static int cc_get(const char **argv, int argc)
}
return 0;
}
static int cc_set(const char **argv, int argc)
static int cc_set(const utf8 **argv, int argc)
{
int i;
if (argc > 1) {
@@ -639,7 +639,7 @@ static int cc_set(const char **argv, int argc)
RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8) = clamp(int_val[0], 0, 3);
}
else {
char* climate_names[] = { "cool_and_wet", "warm", "hot_and_dry", "cold" };
utf8* climate_names[] = { "cool_and_wet", "warm", "hot_and_dry", "cold" };
for (i = 0; i < 4; i++) {
if (strcmp(argv[1], climate_names[i]) == 0) {
RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8) = i;
@@ -697,7 +697,7 @@ static int cc_set(const char **argv, int argc)
}
return 0;
}
static int cc_twitch(const char **argv, int argc)
static int cc_twitch(const utf8 **argv, int argc)
{
#ifdef DISABLE_TWITCH
console_writeline_error("OpenRCT2 build not compiled with Twitch integeration.");
@@ -706,6 +706,7 @@ static int cc_twitch(const char **argv, int argc)
#endif
return 0;
}
static void editor_load_selected_objects_console()
{
uint8 *selection_flags = RCT2_GLOBAL(RCT2_ADDRESS_EDITOR_OBJECT_FLAGS_LIST, uint8*);
@@ -729,13 +730,13 @@ static void editor_load_selected_objects_console()
}
}
static int cc_load_object(const char **argv, int argc) {
static int cc_load_object(const utf8 **argv, int argc) {
if (argc > 0) {
char path[260];
utf8 path[260];
subsitute_path(path, RCT2_ADDRESS(RCT2_ADDRESS_OBJECT_DATA_PATH, char), argv[0]);
// Require pointer to start of filename
char* last_char = path + strlen(path);
utf8* last_char = path + strlen(path);
strcat(path, ".DAT\0");
rct_object_entry entry;
@@ -815,8 +816,8 @@ static int cc_load_object(const char **argv, int argc) {
return 0;
}
static int cc_object_count(const char **argv, int argc) {
const char* object_type_names[] = { "Rides", "Small scenery", "Large scenery", "Walls", "Banners", "Paths", "Path Additions", "Scenery groups", "Park entrances", "Water" };
static int cc_object_count(const utf8 **argv, int argc) {
const utf8* object_type_names[] = { "Rides", "Small scenery", "Large scenery", "Walls", "Banners", "Paths", "Path Additions", "Scenery groups", "Park entrances", "Water" };
for (int i = 0; i < 10; i++) {
int entryGroupIndex = 0;
@@ -830,7 +831,7 @@ static int cc_object_count(const char **argv, int argc) {
return 0;
}
static int cc_open(const char **argv, int argc) {
static int cc_open(const utf8 **argv, int argc) {
if (argc > 0) {
bool title = (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TITLE_DEMO) != 0;
bool invalidTitle = false;
@@ -858,15 +859,15 @@ static int cc_open(const char **argv, int argc) {
}
typedef int (*console_command_func)(const char **argv, int argc);
typedef int (*console_command_func)(const utf8 **argv, int argc);
typedef struct {
char *command;
utf8 *command;
console_command_func func;
char *help;
char *usage;
utf8 *help;
utf8 *usage;
} console_command;
char* console_variable_table[] = {
utf8* console_variable_table[] = {
"park_rating",
"money",
"current_loan",
@@ -895,7 +896,7 @@ char* console_variable_table[] = {
"no_test_crashes",
"location"
};
char* console_window_table[] = {
utf8* console_window_table[] = {
"object_selection",
"inventions_list",
"scenario_options",
@@ -922,19 +923,19 @@ console_command console_command_table[] = {
{ "twitch", cc_twitch, "Twitch API" }
};
static int cc_windows(const char **argv, int argc) {
static int cc_windows(const utf8 **argv, int argc) {
for (int i = 0; i < countof(console_window_table); i++)
console_writeline(console_window_table[i]);
return 0;
}
static int cc_variables(const char **argv, int argc)
static int cc_variables(const utf8 **argv, int argc)
{
for (int i = 0; i < countof(console_variable_table); i++)
console_writeline(console_variable_table[i]);
return 0;
}
static int cc_help(const char **argv, int argc)
static int cc_help(const utf8 **argv, int argc)
{
if (argc > 0) {
for (int i = 0; i < countof(console_command_table); i++) {
@@ -956,20 +957,20 @@ static void console_write_all_commands()
console_writeline(console_command_table[i].command);
}
void console_execute(const char *src)
void console_execute(const utf8 *src)
{
console_writeline(src);
console_execute_silent(src);
}
void console_execute_silent(const char *src)
void console_execute_silent(const utf8 *src)
{
int argc = 0;
int argvCapacity = 8;
char **argv = malloc(argvCapacity * sizeof(char*));
const char *start = src;
const char *end;
utf8 **argv = malloc(argvCapacity * sizeof(utf8*));
const utf8 *start = src;
const utf8 *end;
bool inQuotes = false;
do {
while (*start == ' ')
@@ -994,13 +995,13 @@ void console_execute_silent(const char *src)
int length = end - start;
if (length > 0) {
char *arg = malloc(length + 1);
utf8 *arg = malloc(length + 1);
memcpy(arg, start, length);
arg[length] = 0;
if (argc >= argvCapacity) {
argvCapacity *= 2;
argv = realloc(argv, argvCapacity * sizeof(char*));
argv = realloc(argv, argvCapacity * sizeof(utf8*));
}
argv[argc] = arg;
argc++;
@@ -1030,7 +1031,10 @@ void console_execute_silent(const char *src)
free(argv);
if (!validCommand) {
char output[] = { FORMAT_RED, "Unknown command. Type help to list available commands." };
utf8 output[128];
utf8 *dst = output;
dst = utf8_write_codepoint(dst, FORMAT_RED);
strcpy(dst, "Unknown command. Type help to list available commands.");
console_writeline(output);
}
}

View File

@@ -14,13 +14,13 @@ void console_update();
void console_draw(rct_drawpixelinfo *dpi);
void console_input(int c);
void console_write(const char *src);
void console_writeline(const char *src);
void console_writeline_error(const char *src);
void console_writeline_warning(const char *src);
void console_printf(const char *format, ...);
void console_execute(const char *src);
void console_execute_silent(const char *src);
void console_write(const utf8 *src);
void console_writeline(const utf8 *src);
void console_writeline_error(const utf8 *src);
void console_writeline_warning(const utf8 *src);
void console_printf(const utf8 *format, ...);
void console_execute(const utf8 *src);
void console_execute_silent(const utf8 *src);
void console_clear();
void console_clear_line();
void console_refresh_caret();

View File

@@ -297,14 +297,14 @@ void news_item_get_subject_location(int type, int subject, int *x, int *y, int *
**/
void news_item_add_to_queue(uint8 type, rct_string_id string_id, uint32 assoc)
{
char *buffer = (char*)0x0141EF68;
utf8 *buffer = (char*)0x0141EF68;
void *args = (void*)0x013CE952;
format_string(buffer, string_id, args); // overflows possible?
news_item_add_to_queue_raw(type, buffer, assoc);
}
void news_item_add_to_queue_raw(uint8 type, const char *text, uint32 assoc)
void news_item_add_to_queue_raw(uint8 type, const utf8 *text, uint32 assoc)
{
int i = 0;
rct_news_item *newsItem = RCT2_ADDRESS(RCT2_ADDRESS_NEWS_ITEM_LIST, rct_news_item);

View File

@@ -58,7 +58,7 @@ void news_item_update_current();
void news_item_close_current();
void news_item_get_subject_location(int type, int subject, int *x, int *y, int *z);
void news_item_add_to_queue(uint8 type, rct_string_id string_id, uint32 assoc);
void news_item_add_to_queue_raw(uint8 type, const char *text, uint32 assoc);
void news_item_add_to_queue_raw(uint8 type, const utf8 *text, uint32 assoc);
void news_item_open_subject(int type, int subject);
void news_item_disable_news(uint8 type, uint32 assoc);
rct_news_item *news_item_get(int index);

View File

@@ -237,11 +237,7 @@ static void window_land_rights_paint(rct_window *w, rct_drawpixelinfo *dpi)
window_draw_widgets(w, dpi);
// FEATURE larger land tool size support
if (RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16) > 7) {
RCT2_GLOBAL(0x009BC677, char) = FORMAT_BLACK;
RCT2_GLOBAL(0x009BC678, char) = FORMAT_COMMA16;
RCT2_GLOBAL(0x009BC679, char) = 0;
RCT2_GLOBAL(0x013CE952, sint16) = RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16);
gfx_draw_string_centred(dpi, 3165, x, y - 2, 0, (void*)0x013CE952);
gfx_draw_string_centred(dpi, STR_LAND_TOOL_SIZE_VALUE, x, y - 2, 0, &RCT2_GLOBAL(RCT2_ADDRESS_LAND_TOOL_SIZE, sint16));
}
y = w->y + window_land_rights_widgets[WIDX_PREVIEW].bottom + 5;