Added ñ and Ñ to coop

This commit is contained in:
MysterD 2023-03-27 18:35:39 -07:00
parent 0435bf7b68
commit f4fe5a9457
7 changed files with 61 additions and 6 deletions

View file

@ -3591,6 +3591,14 @@ ALIGNED8 static const u8 texture_font_normal_char_93[] = {
#include "textures/segment2/custom_font_normal_char_93.ia4.inc.c" #include "textures/segment2/custom_font_normal_char_93.ia4.inc.c"
}; };
ALIGNED8 static const u8 texture_font_normal_char_sn[] = {
#include "textures/segment2/custom_font_normal_char_sn.ia4.inc.c"
};
ALIGNED8 static const u8 texture_font_normal_char_scn[] = {
#include "textures/segment2/custom_font_normal_char_scn.ia4.inc.c"
};
const u8* const font_normal_chars[] = { const u8* const font_normal_chars[] = {
texture_font_char_us_exclamation, // ! texture_font_char_us_exclamation, // !
texture_font_char_us_double_quote_open, // " texture_font_char_us_double_quote_open, // "
@ -3687,6 +3695,8 @@ const u8* const font_normal_chars[] = {
texture_font_normal_char_93, // } texture_font_normal_char_93, // }
texture_font_char_us_tilde, // ~ texture_font_char_us_tilde, // ~
texture_font_char_us_star_filled, // DEL texture_font_char_us_star_filled, // DEL
texture_font_normal_char_sn, // ñ
texture_font_normal_char_scn, // Ñ
}; };
const f32 font_normal_widths[] = { const f32 font_normal_widths[] = {
@ -3703,7 +3713,9 @@ const f32 font_normal_widths[] = {
/* a b c d e f g h i j k l m n o p q r s t u v w x y z */ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
0.3750f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.2500f, 0.3125f, 0.3125f, 0.1875f, 0.4375f, 0.3125f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, 0.4375f, 0.4375f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.2500f, 0.3125f, 0.3125f, 0.1875f, 0.4375f, 0.3125f, 0.3125f, 0.3125f, 0.3750f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, 0.3125f, 0.4375f, 0.4375f, 0.3125f, 0.3125f,
/* { | } ~ DEL */ /* { | } ~ DEL */
0.3125f, 0.2500f, 0.3125f, 0.5000f, 0.5000f 0.3125f, 0.2500f, 0.3125f, 0.5000f, 0.5000f,
/* ñ Ñ */
0.3125f, 0.5000f,
}; };

View file

@ -35,9 +35,9 @@ const Gfx dl_font_normal_display_list[] = {
static void djui_font_normal_render_char(char c) { static void djui_font_normal_render_char(char c) {
extern const u8* const font_normal_chars[]; extern const u8* const font_normal_chars[];
// replace undisplayable characters // replace undisplayable characters
if (c < ' ' || (u8)c > ('~' + 1)) { c = '?'; } if ((u8)c < ' ' || (u8)c > ('~' + 3)) { c = '?'; }
if (c == ' ') { return; } if (c == ' ') { return; }
void* fontChar = (void*)font_normal_chars[c - '!']; void* fontChar = (void*)font_normal_chars[(u8)c - '!'];
if (fontChar == NULL) { fontChar = (void*)font_normal_chars[94]; } if (fontChar == NULL) { fontChar = (void*)font_normal_chars[94]; }
gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, (void*)fontChar); gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, (void*)fontChar);
@ -47,7 +47,7 @@ static void djui_font_normal_render_char(char c) {
static f32 djui_font_normal_char_width(char c) { static f32 djui_font_normal_char_width(char c) {
if (c == ' ') { return 0.30f; } if (c == ' ') { return 0.30f; }
extern const f32 font_normal_widths[]; extern const f32 font_normal_widths[];
return font_normal_widths[c - '!']; return font_normal_widths[(u8)c - '!'];
} }
static const struct DjuiFont sDjuiFontNormal = { static const struct DjuiFont sDjuiFontNormal = {
@ -76,7 +76,7 @@ static void djui_font_title_render_char(char c) {
static f32 djui_font_title_char_width(char c) { static f32 djui_font_title_char_width(char c) {
if (c == ' ') { return 0.30f; } if (c == ' ') { return 0.30f; }
extern const f32 font_title_widths[]; extern const f32 font_title_widths[];
return font_title_widths[c - '!']; return font_title_widths[(u8)c - '!'];
} }
static const struct DjuiFont sDjuiFontTitle = { static const struct DjuiFont sDjuiFontTitle = {

View file

@ -1,6 +1,12 @@
#pragma once #pragma once
#include "djui.h" #include "djui.h"
#define SPANISH_UNICODE_START -61
#define SPANISH_UNICODE_LOWER_N -79 // ñ
#define SPANISH_UNICODE_UPPER_N -111 // Ñ
#define SPANISH_SMCODE_LOWER_N ((s8)('~' + 2))
#define SPANISH_SMCODE_UPPER_N ((s8)('~' + 3))
struct DjuiFont { struct DjuiFont {
f32 charWidth; f32 charWidth;
f32 charHeight; f32 charHeight;

View file

@ -291,15 +291,44 @@ static void djui_inputbox_on_focus_end(UNUSED struct DjuiBase* base) {
wm_api->stop_text_input(); wm_api->stop_text_input();
} }
#define SPANISH_UNICODE_START -61
#define SPANISH_UNICODE_LOWER_N -79 // ñ
#define SPANISH_UNICODE_UPPER_N -111 // Ñ
#define SPANISH_SMCODE_LOWER_N ((s8)('~' + 2))
#define SPANISH_SMCODE_UPPER_N ((s8)('~' + 3))
static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) { static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) {
struct DjuiInputbox *inputbox = (struct DjuiInputbox *) base; struct DjuiInputbox *inputbox = (struct DjuiInputbox *) base;
char* msg = inputbox->buffer; char* msg = inputbox->buffer;
int msgLen = strlen(msg); int msgLen = strlen(msg);
int textLen = strlen(text); int textLen = strlen(text);
// special case ñ and Ñ
char* tinput = text;
while (*tinput != '\0') {
if (tinput[0] == SPANISH_UNICODE_START) {
if ((tinput[1] == SPANISH_UNICODE_LOWER_N || tinput[1] == SPANISH_UNICODE_UPPER_N)) {
// consume SPANISH_UNICODE_START
char* t2 = tinput;
while (*t2 != '\0') {
t2[0] = t2[1];
t2++;
}
// translate
if (tinput[0] == SPANISH_UNICODE_LOWER_N) {
tinput[0] = SPANISH_SMCODE_LOWER_N;
} else if (tinput[0] == SPANISH_UNICODE_UPPER_N) {
tinput[0] = SPANISH_SMCODE_UPPER_N;
}
}
}
tinput++;
}
// make sure we're not just printing garbage characters // make sure we're not just printing garbage characters
bool containsValidAscii = false; bool containsValidAscii = false;
char* tinput = text; tinput = text;
while (*tinput != '\0') { while (*tinput != '\0') {
if (*tinput >= '!' && *tinput <= '~') { if (*tinput >= '!' && *tinput <= '~') {
containsValidAscii = true; containsValidAscii = true;
@ -307,6 +336,12 @@ static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) {
} else if (*tinput == ' ') { } else if (*tinput == ' ') {
containsValidAscii = true; containsValidAscii = true;
break; break;
} else if (*tinput == SPANISH_SMCODE_LOWER_N) {
containsValidAscii = true;
break;
} else if (*tinput == SPANISH_SMCODE_UPPER_N) {
containsValidAscii = true;
break;
} }
tinput++; tinput++;
} }
@ -333,6 +368,8 @@ static void djui_inputbox_on_text_input(struct DjuiBase *base, char* text) {
if (*t == '\n') { *t = ' '; } if (*t == '\n') { *t = ' '; }
else if (*t == '\r') { *t = ' '; } else if (*t == '\r') { *t = ' '; }
else if (*t == ' ') { ; } else if (*t == ' ') { ; }
else if (*t == SPANISH_SMCODE_LOWER_N) { ; }
else if (*t == SPANISH_SMCODE_UPPER_N) { ; }
else if (*t < '!' || *t > '~') { *t = '?'; } else if (*t < '!' || *t > '~') { *t = '?'; }
t++; t++;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B