fix player name valid checks

This commit is contained in:
Isaac0-dev 2025-02-15 08:09:14 +10:00
parent cd5b5f9934
commit e0ee642f4a

View file

@ -338,6 +338,15 @@ static bool djui_panel_player_name_valid(char* buffer) {
return true; return true;
} }
static char *djui_panel_player_name_default_get(void) {
char *langName = DLANG(PLAYER, PLAYER);
if (djui_panel_player_name_valid(langName)) {
return langName;
}
static char *name = "Player";
return name;
}
static void djui_panel_player_name_text_change(struct DjuiBase* caller) { static void djui_panel_player_name_text_change(struct DjuiBase* caller) {
struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller; struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller;
if (djui_panel_player_name_valid(inputbox1->buffer)) { if (djui_panel_player_name_valid(inputbox1->buffer)) {
@ -350,7 +359,7 @@ static void djui_panel_player_name_text_change(struct DjuiBase* caller) {
static void djui_panel_player_name_on_focus_end(struct DjuiBase* caller) { static void djui_panel_player_name_on_focus_end(struct DjuiBase* caller) {
struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller; struct DjuiInputbox* inputbox1 = (struct DjuiInputbox*)caller;
if (!djui_panel_player_name_valid(inputbox1->buffer)) { if (!djui_panel_player_name_valid(inputbox1->buffer)) {
djui_inputbox_set_text(inputbox1, DLANG(PLAYER, PLAYER)); djui_inputbox_set_text(inputbox1, djui_panel_player_name_default_get());
} }
snprintf(configPlayerName, MAX_CONFIG_STRING, "%s", inputbox1->buffer); snprintf(configPlayerName, MAX_CONFIG_STRING, "%s", inputbox1->buffer);
djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255); djui_inputbox_set_text_color(inputbox1, 0, 0, 0, 255);
@ -428,7 +437,7 @@ void djui_panel_player_create(struct DjuiBase* caller) {
if (djui_panel_player_name_valid(configPlayerName)) { if (djui_panel_player_name_valid(configPlayerName)) {
djui_inputbox_set_text(inputbox1, configPlayerName); djui_inputbox_set_text(inputbox1, configPlayerName);
} else { } else {
djui_inputbox_set_text(inputbox1, DLANG(PLAYER, PLAYER)); djui_inputbox_set_text(inputbox1, djui_panel_player_name_default_get());
} }
djui_interactable_hook_value_change(&inputbox1->base, djui_panel_player_name_text_change); djui_interactable_hook_value_change(&inputbox1->base, djui_panel_player_name_text_change);
djui_interactable_hook_focus(&inputbox1->base, djui_inputbox_on_focus_begin, NULL, djui_panel_player_name_on_focus_end); djui_interactable_hook_focus(&inputbox1->base, djui_inputbox_on_focus_begin, NULL, djui_panel_player_name_on_focus_end);