From 73082f9d1d3874b43909ff6d99df9f738d84445f Mon Sep 17 00:00:00 2001 From: Klemen Plestenjak Date: Sun, 28 Jan 2024 20:18:31 +0100 Subject: [PATCH] Add continue button --- game/systems/s_ui.c | 13 ++++++++----- game/ui_widgets.c | 18 +++++++++--------- game/ui_widgets.h | 4 ++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/game/systems/s_ui.c b/game/systems/s_ui.c index 7bb8e8c..7394402 100644 --- a/game/systems/s_ui.c +++ b/game/systems/s_ui.c @@ -202,10 +202,10 @@ void drawPauseUI(Game *game, f32 dt) { .type = BZ_UI_LAYOUT_FLEX_BOX, .flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER }); - if (uiMainMenuButton("Resume")) { + if (uiMainMenuButton("Resume", true)) { setScreen(game, SCREEN_GAME); } - if (uiMainMenuButton("Exit")) { + if (uiMainMenuButton("Exit", true)) { setScreen(game, SCREEN_MAIN_MENU); unloadMap(game); loadMap(game, "assets/maps/main_menu_01.tmj"); @@ -239,16 +239,19 @@ void drawMainMenuUI(Game *game, f32 dt) { .type = BZ_UI_LAYOUT_FLEX_BOX, .flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER }); - if (uiMainMenuButton("Play")) { + if (uiMainMenuButton("Continue", false)) { + + } + if (uiMainMenuButton("Play", true)) { setScreen(game, SCREEN_GAME); unloadMap(game); loadMap(game, "assets/maps/tree_test.tmj"); //loadMap(game, "assets/maps/map_01.tmj"); } - if (uiMainMenuButton("Settings")) { + if (uiMainMenuButton("Settings", true)) { setScreen(game, SCREEN_SETTINGS); } - if (uiMainMenuButton("Exit")) { + if (uiMainMenuButton("Exit", true)) { bzGameExit(); } bzUIPopParent(UI); diff --git a/game/ui_widgets.c b/game/ui_widgets.c index 535f356..47d55c5 100644 --- a/game/ui_widgets.c +++ b/game/ui_widgets.c @@ -58,7 +58,7 @@ void uiBaseLabel(const char *txt, Font font, f32 scl, Color color) { }); } -bool uiBaseTextButton(const char *txt, Font font, f32 scl) { +bool uiBaseTextButton(const char *txt, Font font, f32 scl, bool enabled) { BzUINode *node = bzUINodeMake(UI, bzUIKeyFromString(txt), &(BzUINodeDesc) { .flags = BZ_UI_DRAW_TEXT | BZ_UI_DRAW_TEXT_SHADOW | BZ_UI_ALIGN_CENTER, .semanticSize[BZ_UI_AXIS_X] = { @@ -75,9 +75,9 @@ bool uiBaseTextButton(const char *txt, Font font, f32 scl) { .font = font, .fontSpacing = 2 * uiGetScale() * scl, .fontSize = 62 * uiGetScale() * scl, - .normal = WHITE, - .hover = GRAY, - .active = YELLOW + .normal = enabled ? WHITE : GRAY, + .hover = enabled ? GRAY : GRAY, + .active = enabled ? GRAY : LIGHTGRAY, }); bzUISetTextShadowStyle(UI, node, (BzUITextShadowStyle) { .offset[BZ_UI_AXIS_X] = 2 * uiGetScale() * scl, @@ -168,7 +168,7 @@ void uiBaseSlider(const char *txt, Font font, f32 scl, f32 *value, f32 min, f32 char buf[32]; snprintf(buf, sizeof(buf), "-##%s", txt); - if (uiBaseTextButton(buf, font, 0.6 * scl)) + if (uiBaseTextButton(buf, font, 0.6 * scl, true)) (*value)--; *value = BZ_MAX(*value, min); @@ -176,7 +176,7 @@ void uiBaseSlider(const char *txt, Font font, f32 scl, f32 *value, f32 min, f32 uiBaseLabel(buf, font, 0.6 * scl, WHITE); snprintf(buf, sizeof(buf), "+##%s", txt); - if (uiBaseTextButton(buf, font, 0.6 * scl)) + if (uiBaseTextButton(buf, font, 0.6 * scl, true)) (*value)++; *value = BZ_MIN(*value, max); bzUIPopParent(UI); @@ -188,15 +188,15 @@ void uiMainMenuLabel(const char *txt) { uiBaseLabel(txt, getFont(), 1.8f, WHITE); } -bool uiMainMenuButton(const char *txt) { - return uiBaseTextButton(txt, getFont(), 0.8f); +bool uiMainMenuButton(const char *txt, bool enabled) { + return uiBaseTextButton(txt, getFont(), 0.8f, enabled); } void uiSettingsLabel(const char *txt) { uiBaseLabel(txt, getFont(), 0.8f, WHITE); } bool uiSettingsButton(const char *txt) { - return uiBaseTextButton(txt, getFont(), 0.7f); + return uiBaseTextButton(txt, getFont(), 0.7f, true); } void uiSettingsCheckbox(const char *txt, bool *check) { uiBaseCheckbox(txt, getFont(), 1.0f, check); diff --git a/game/ui_widgets.h b/game/ui_widgets.h index e1fd5c7..da710b9 100644 --- a/game/ui_widgets.h +++ b/game/ui_widgets.h @@ -12,13 +12,13 @@ BzUINode *uiPushDivParentPercentage(f32 xPercent, f32 yPercent); // Template stuff void uiBaseLabel(const char *txt, Font font, f32 scl, Color color); -bool uiBaseTextButton(const char *txt, Font font, f32 scl); +bool uiBaseTextButton(const char *txt, Font font, f32 scl, bool enabled); void uiBaseCheckbox(const char *txt, Font font, f32 scl, bool *check); void uiBaseSlider(const char *txt, Font font, f32 scl, f32 *value, f32 min, f32 max); // actual UI void uiMainMenuLabel(const char *txt); -bool uiMainMenuButton(const char *txt); +bool uiMainMenuButton(const char *txt, bool enabled); void uiSettingsLabel(const char *txt); bool uiSettingsButton(const char *txt);