Fix nametags using alpha
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run

This commit is contained in:
PeachyPeachSM64 2026-05-30 02:11:52 +02:00
parent 54cb1b96ea
commit aea840bda2
3 changed files with 38 additions and 0 deletions

View file

@ -132,6 +132,42 @@ void djui_text_remove_colors(char *str) {
}
}
void djui_text_remove_alpha(char *str) {
if (!str) { return; }
char *colorStart = str;
const char *strEnd = str + strlen(str);
while ((colorStart = strstr(colorStart, "\\#"))) {
char *colorEnd;
struct DjuiColor parsedColor;
if (djui_text_parse_color(colorStart, strEnd, false, NULL, &colorEnd, &parsedColor) && colorEnd > colorStart) {
u8 length = (u8) (colorEnd - colorStart) - 3;
switch (length) {
// #rgba -> #rgb
case 4: {
snprintf(colorStart, strEnd - colorStart, "\\#%01x%01x%01x\\", parsedColor.r >> 4, parsedColor.g >> 4, parsedColor.b >> 4);
colorStart = colorEnd - 1;
memmove(colorStart, colorStart + 1, strlen(colorStart + 1) + 1);
} break;
// #rrggbbaa -> #rrggbb
case 8: {
snprintf(colorStart, strEnd - colorStart, "\\#%02x%02x%02x\\", parsedColor.r, parsedColor.g, parsedColor.b);
colorStart = colorEnd - 2;
memmove(colorStart, colorStart + 2, strlen(colorStart + 2) + 1);
} break;
// Nothing to change
default: {
colorStart = colorEnd;
} break;
}
} else {
colorStart++;
}
}
}
char *djui_text_get_uncolored_string(char *dest, size_t length, const char *str) {
if (!dest) {
dest = malloc(length * sizeof(char));

View file

@ -13,6 +13,7 @@ struct DjuiText {
bool djui_text_parse_color(char *begin, const char *end, bool ignoreAlpha, const struct DjuiColor *baseColor, char **nextChar, struct DjuiColor *parsedColor);
void djui_text_remove_colors(char *str);
void djui_text_remove_alpha(char *str);
char *djui_text_get_uncolored_string(char *dest, size_t length, const char *str);
void djui_text_set_text(struct DjuiText* text, const char* message);

View file

@ -121,6 +121,7 @@ void nametags_render(void) {
vec3f_copy(nametag->pos, out);
nametag->scale = scale;
memcpy(nametag->name, name, sizeof(name));
djui_text_remove_alpha(nametag->name);
numNametags++;
}