Update widgets to new UI

This commit is contained in:
2023-12-22 12:50:27 +01:00
parent 935cfdbba3
commit da1eeefe70
3 changed files with 62 additions and 60 deletions

View File

@@ -42,5 +42,5 @@ target_link_libraries(PixelDefense LINK_PRIVATE Breeze)
if (EMSCRIPTEN)
set_target_properties(PixelDefense
PROPERTIES SUFFIX ".html"
LINK_FLAGS " --bind -s WASM=1 -s STACK_SIZE=512kb -s ASSERTIONS=2 -s MIN_WEBGL_VERSION=1 --preload-file ../assets -g2 -gseparate-dwarf -gsource-map -s USE_GLFW=3")
LINK_FLAGS " --bind -s WASM=1 -s ALLOW_MEMORY_GROWTH -s STACK_SIZE=2048kb -s ASSERTIONS=2 -s MIN_WEBGL_VERSION=1 --preload-file ../assets -g2 -gseparate-dwarf -gsource-map -s USE_GLFW=3")
endif()

View File

@@ -331,14 +331,12 @@ static void renderMainMenu(Game *game, float dt) {
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER
});
if (uiMainMenuButton("Play")) {
bzLogInfo("Play");
game->screen = SCREEN_GAME;
}
if (uiMainMenuButton("Settings")) {
bzLogInfo("Settings");
game->screen = SCREEN_SETTINGS;
}
if (uiMainMenuButton("Exit")) {
bzLogInfo("Bye");
bzGameExit();
}
bzUIPopParent(UI);
@@ -366,6 +364,8 @@ void render(float dt, void *userData) {
renderMainMenu(game, dt);
break;
case SCREEN_SETTINGS:
renderGame(game, dt);
drawOverScreen(shadow);
renderSettings(game, dt);
break;
}

View File

@@ -16,17 +16,16 @@ Font getFont() {
void uiPushDivParentPercentage(f32 xPercent, f32 yPercent) {
bzUIPushDiv(UI, (BzUISize) {
.kind = BZ_UI_SIZE_PARENT_PERCENT,
.kind = BZ_UI_SIZE_REL_PARENT,
.value = xPercent,
}, (BzUISize) {
.kind = BZ_UI_SIZE_PARENT_PERCENT,
.kind = BZ_UI_SIZE_REL_PARENT,
.value = yPercent
});
}
void uiBaseLabel(const char *txt, Font font, f32 scl) {
bzUINodeMake(UI, bzUIKeyFromString(txt),
&(BzUINodeDesc) {
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] = {
.kind = BZ_UI_SIZE_FIT,
@@ -34,28 +33,28 @@ void uiBaseLabel(const char *txt, Font font, f32 scl) {
.semanticSize[BZ_UI_AXIS_Y] = {
.kind = BZ_UI_SIZE_FIT
},
.string = txt,
.padding = {5, 5, 5, 5},
.style = {
});
bzUISetTextStyle(UI, node, (BzUITextStyle) {
.text = txt,
.font = font,
.fontSpacing = 2 * uiGetScale() * scl,
.fontSize = 62 * uiGetScale() * scl,
.shadowOffset[BZ_UI_AXIS_X] = 2 * uiGetScale() * scl,
.shadowOffset[BZ_UI_AXIS_Y] = 2 * uiGetScale() * scl,
.textColor = WHITE,
.textHoverColor = WHITE,
.textActiveColor = WHITE,
.textShadowColor = BLACK,
.textShadowHoverColor = BLACK,
.textShadowActiveColor = BLACK,
}
.normal = WHITE,
.hover = WHITE,
.active = WHITE,
});
bzUISetTextShadowStyle(UI, node, (BzUITextShadowStyle) {
.offset[BZ_UI_AXIS_X] = 2 * uiGetScale() * scl,
.offset[BZ_UI_AXIS_Y] = 2 * uiGetScale() * scl,
.normal = BLACK,
.hover = BLACK,
.active = BLACK,
});
}
bool uiBaseTextButton(const char *txt, Font font, f32 scl) {
BzUINode *node = bzUINodeMake(UI, bzUIKeyFromString(txt),
&(BzUINodeDesc) {
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] = {
.kind = BZ_UI_SIZE_FIT,
@@ -63,22 +62,24 @@ bool uiBaseTextButton(const char *txt, Font font, f32 scl) {
.semanticSize[BZ_UI_AXIS_Y] = {
.kind = BZ_UI_SIZE_FIT
},
.string = txt,
.padding = {0, 0, 0, 0},
.margin = {5, 5, 5, 5},
.style = {
});
bzUISetTextStyle(UI, node, (BzUITextStyle) {
.text = txt,
.font = font,
.fontSpacing = 2 * uiGetScale() * scl,
.fontSize = 62 * uiGetScale() * scl,
.shadowOffset[BZ_UI_AXIS_X] = 2 * uiGetScale() * scl,
.shadowOffset[BZ_UI_AXIS_Y] = 2 * uiGetScale() * scl,
.textColor = WHITE,
.textHoverColor = GRAY,
.textActiveColor = YELLOW,
.textShadowColor = BLACK,
.textShadowHoverColor = BLACK,
.textShadowActiveColor = BLACK,
}
.normal = WHITE,
.hover = GRAY,
.active = YELLOW
});
bzUISetTextShadowStyle(UI, node, (BzUITextShadowStyle) {
.offset[BZ_UI_AXIS_X] = 2 * uiGetScale() * scl,
.offset[BZ_UI_AXIS_Y] = 2 * uiGetScale() * scl,
.normal = BLACK,
.hover = BLACK,
.active = BLACK,
});
return bzUIGetInteraction(UI, node).clicked;
}
@@ -86,6 +87,7 @@ bool uiBaseTextButton(const char *txt, Font font, f32 scl) {
void uiMainMenuLabel(const char *txt) {
uiBaseLabel(txt, getFont(), 1.8f);
}
bool uiMainMenuButton(const char *txt) {
return uiBaseTextButton(txt, getFont(), 1.0f);
return uiBaseTextButton(txt, getFont(), 0.8f);
}