fix some djui related issues (#53)

- fixed a crash that could occur when closing the game with the mods menu open. this was a use after free.
- allowed pressing the B button to go back in the save file name editor to refresh the file name.
- fixed text getting cut off on paginated page count, and centered the text (as one string)
- fixed disabled buttons not fading out since the addition of djui themes
This commit is contained in:
Isaac0-dev 2024-06-04 07:27:12 +10:00 committed by GitHub
parent bdd427c561
commit 695b1cc84e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 50 additions and 32 deletions

View file

@ -24,11 +24,15 @@ static struct DjuiText* sDjuiLuaError = NULL;
static u32 sDjuiLuaErrorTimeout = 0;
bool gDjuiInMainMenu = true;
bool gDjuiDisabled = false;
bool gDjuiShuttingDown = false;
static bool sDjuiInited = false;
bool sDjuiRendered60fps = false;
void djui_shutdown(void) {
gDjuiShuttingDown = true;
djui_panel_shutdown();
sSavedDisplayListHead = NULL;
if (sDjuiPauseOptions) djui_base_destroy(&sDjuiPauseOptions->base);
if (sDjuiLuaError) djui_base_destroy(&sDjuiLuaError->base);
@ -49,6 +53,7 @@ void djui_shutdown(void) {
djui_fps_display_destroy();
gDjuiShuttingDown = false;
sDjuiInited = false;
}

View file

@ -6,8 +6,8 @@ static void djui_button_update_style(struct DjuiBase* base) {
struct DjuiTheme* theme = gDjuiThemes[configDjuiTheme];
if (!button->base.enabled) {
struct DjuiColor bc = button->style ? djui_theme_shade_color(theme->interactables.defaultBorderColor) : theme->interactables.defaultBorderColor;
struct DjuiColor rc = button->style ? djui_theme_shade_color(theme->interactables.defaultRectColor) : theme->interactables.defaultRectColor;
struct DjuiColor bc = djui_theme_shade_color(theme->interactables.defaultBorderColor, button->style ? 0.3f : 0.6f);
struct DjuiColor rc = djui_theme_shade_color(theme->interactables.defaultRectColor, button->style ? 0.3f : 0.6f);
djui_base_set_border_color(base, bc.r, bc.g, bc.b, bc.a);
djui_base_set_color(&button->rect->base, rc.r, rc.g, rc.b, rc.a);
@ -27,8 +27,8 @@ static void djui_button_update_style(struct DjuiBase* base) {
djui_base_set_color(&button->rect->base, rc.r, rc.g, rc.b, rc.a);
djui_base_set_location(&button->text->base, -1.0f, -1.0f);
} else {
struct DjuiColor bc = button->style ? djui_theme_shade_color(theme->interactables.defaultBorderColor) : theme->interactables.defaultBorderColor;
struct DjuiColor rc = button->style ? djui_theme_shade_color(theme->interactables.defaultRectColor) : theme->interactables.defaultRectColor;
struct DjuiColor bc = button->style ? djui_theme_shade_color(theme->interactables.defaultBorderColor, 0.6f) : theme->interactables.defaultBorderColor;
struct DjuiColor rc = button->style ? djui_theme_shade_color(theme->interactables.defaultRectColor, 0.6f) : theme->interactables.defaultRectColor;
djui_base_set_border_color(base, bc.r, bc.g, bc.b, bc.a);
djui_base_set_color(&button->rect->base, rc.r, rc.g, rc.b, rc.a);

View file

@ -10,8 +10,8 @@ static void djui_lobby_entry_update_style(struct DjuiBase* base) {
struct DjuiTheme* theme = gDjuiThemes[configDjuiTheme];
if (!entry->base.enabled) {
struct DjuiColor bc = djui_theme_shade_color(theme->interactables.defaultBorderColor);
struct DjuiColor rc = djui_theme_shade_color(theme->interactables.defaultRectColor);
struct DjuiColor bc = djui_theme_shade_color(theme->interactables.defaultBorderColor, 0.3f);
struct DjuiColor rc = djui_theme_shade_color(theme->interactables.defaultRectColor, 0.3f);
djui_base_set_border_color(base, bc.r, bc.g, bc.b, bc.a);
djui_base_set_color(&entry->base, rc.r, rc.g, rc.b, rc.a);

View file

@ -56,7 +56,6 @@ static void djui_paginated_next(struct DjuiBase* base) {
if (paginated->startIndex >= count) { paginated->startIndex -= paginated->showCount; }
djui_paginated_update_page_buttons(paginated);
}
void djui_paginated_calculate_height(struct DjuiPaginated* paginated) {
@ -169,8 +168,10 @@ struct DjuiPaginated* djui_paginated_create(struct DjuiBase* parent, u32 showCou
sPageNumText = djui_text_create(&paginated->base, "");
djui_base_set_color(&sPageNumText->base, 220, 220, 220, 255);
djui_base_set_alignment(&sPageNumText->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_BOTTOM);
djui_text_set_alignment(sPageNumText, DJUI_HALIGN_CENTER, DJUI_VALIGN_TOP);
djui_text_set_drop_shadow(sPageNumText, 64, 64, 64, 100);
sPageNumText->base.y.value -= 30;
sPageNumText->base.width.value += 30;
sNextButton = djui_button_create(&paginated->base, ">", DJUI_BUTTON_STYLE_NORMAL, djui_paginated_next);
djui_base_set_alignment(&sNextButton->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_BOTTOM);

View file

@ -56,6 +56,7 @@ struct DjuiPanel* djui_panel_add(struct DjuiBase* caller, struct DjuiThreePanel*
panel->parent = sPanelList;
panel->base = panelBase;
panel->defaultElementBase = defaultElementBase;
panel->on_back = threePanel->on_back;
panel->on_panel_destroy = NULL;
sPanelList = panel;
@ -99,6 +100,13 @@ void djui_panel_back(void) {
return;
}
// call back hook, return true to cancel back
if (sPanelList->on_back) {
if (sPanelList->on_back(sPanelList->base)) {
return;
}
}
// deselect cursor input
djui_cursor_input_controlled_center(NULL);
@ -177,6 +185,7 @@ void djui_panel_update(void) {
}
}
extern bool gDjuiShuttingDown;
void djui_panel_shutdown(void) {
static bool sShuttingDown = false;
if (sShuttingDown) { return; }
@ -210,10 +219,12 @@ void djui_panel_shutdown(void) {
gDjuiPanelMainCreated = false;
gDjuiPanelPauseCreated = false;
djui_cursor_set_visible(false);
if (!gDjuiShuttingDown) {
configfile_save(configfile_name());
if (gDjuiInMainMenu) {
gDjuiInMainMenu = false;
newcam_init_settings();
}
}
sShuttingDown = false;
}

View file

@ -10,6 +10,7 @@ struct DjuiPanel {
struct DjuiPanel* parent;
struct DjuiBase* defaultElementBase;
bool temporary;
bool (*on_back)(struct DjuiBase*);
void (*on_panel_destroy)(struct DjuiBase*);
};

View file

@ -17,7 +17,6 @@
static struct DjuiFlowLayout* sModLayout = NULL;
static struct DjuiThreePanel* sDescriptionPanel = NULL;
static struct DjuiText* sTooltip = NULL;
static s64 sTag = 0;
static bool sWarned = false;
void djui_panel_host_mods_create(struct DjuiBase* caller);
@ -115,13 +114,12 @@ static void djui_panel_host_mods_destroy(struct DjuiBase* base) {
djui_base_destroy(&sDescriptionPanel->base);
sDescriptionPanel = NULL;
}
sModLayout = NULL;
sTooltip = NULL;
}
void djui_panel_host_mods_create(struct DjuiBase* caller) {
if (caller != NULL) {
sTag = caller->tag;
}
bool isRomHacks = sTag;
bool isRomHacks = caller != NULL ? caller->tag != 0 : false;
mods_update_selectable();
djui_panel_host_mods_description_create();

View file

@ -22,9 +22,9 @@ static void djui_panel_host_save_save_name_change(UNUSED struct DjuiBase* caller
}
}
static void djui_panel_edit_back(struct DjuiBase* caller) {
static bool djui_panel_edit_back(UNUSED struct DjuiBase* caller) {
djui_panel_host_save_update_button(sSaveButtons[sButtonTag], sButtonTag);
djui_panel_menu_back(caller);
return false;
}
static void djui_panel_edit_create(struct DjuiBase* caller) {
@ -52,9 +52,10 @@ static void djui_panel_edit_create(struct DjuiBase* caller) {
djui_interactable_hook_value_change(&sSaveNameInputBox->base, djui_panel_host_save_save_name_change);
}
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_edit_back);
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
}
panel->on_back = djui_panel_edit_back;
djui_panel_add(caller, panel, NULL);
}

View file

@ -13,8 +13,8 @@ static void djui_selectionbox_update_style(struct DjuiBase* base) {
if (!selectionbox->base.enabled) {
struct DjuiSelectionbox* selectionbox = (struct DjuiSelectionbox*)base;
struct DjuiColor bc = djui_theme_shade_color(theme->interactables.defaultBorderColor);
struct DjuiColor rc = djui_theme_shade_color(theme->interactables.defaultRectColor);
struct DjuiColor bc = djui_theme_shade_color(theme->interactables.defaultBorderColor, 0.6f);
struct DjuiColor rc = djui_theme_shade_color(theme->interactables.defaultRectColor, 0.6f);
struct DjuiColor tc = theme->interactables.textColor;
djui_base_set_border_color(&selectionbox->rect->base, bc.r, bc.g, bc.b, bc.a);

View file

@ -171,10 +171,10 @@ struct DjuiTheme* gDjuiThemes[] = {
&sDjuiThemeMario
};
struct DjuiColor djui_theme_shade_color(struct DjuiColor color) {
color.r *= 0.6f;
color.g *= 0.6f;
color.b *= 0.6f;
struct DjuiColor djui_theme_shade_color(struct DjuiColor color, f32 mult) {
color.r *= mult;
color.g *= mult;
color.b *= mult;
return color;
}

View file

@ -43,5 +43,5 @@ struct DjuiTheme {
extern struct DjuiTheme* gDjuiThemes[];
struct DjuiColor djui_theme_shade_color(struct DjuiColor color);
struct DjuiColor djui_theme_shade_color(struct DjuiColor color, f32 mult);
void djui_themes_init(void);

View file

@ -6,6 +6,7 @@ struct DjuiThreePanel {
struct DjuiScreenValue minHeaderSize;
struct DjuiScreenValue bodySize;
struct DjuiScreenValue minFooterSize;
bool (*on_back)(struct DjuiBase*);
};
struct DjuiBase* djui_three_panel_get_header(struct DjuiThreePanel* threePanel);