Add top bar game UI

This commit is contained in:
2023-12-28 09:47:55 +01:00
parent 0d09ffd67d
commit 118f7f9d93
6 changed files with 99 additions and 6 deletions

View File

@@ -16,8 +16,8 @@ Font getFont() {
return game->font;
}
void uiPushDivParentPercentage(f32 xPercent, f32 yPercent) {
bzUIPushDiv(UI, (BzUISize) {
BzUINode *uiPushDivParentPercentage(f32 xPercent, f32 yPercent) {
return bzUIPushDiv(UI, (BzUISize) {
.kind = BZ_UI_SIZE_REL_PARENT,
.value = xPercent,
}, (BzUISize) {
@@ -201,3 +201,40 @@ void uiSettingsCheckbox(const char *txt, bool *check) {
void uiSettingsSlider(const char *txt, f32 *value) {
uiBaseSlider(txt, getFont(), 1.0f, value, 0, 10);
}
void uiGameResCount(i32 amount, i32 capacity, Rectangle icon, Texture2D texture) {
bzUIPushDiv(UI, (BzUISize) { BZ_UI_SIZE_CHILD_SUM },
(BzUISize) { BZ_UI_SIZE_CHILD_MAX });
bzUISetParentLayout(UI, (BzUILayout) {
BZ_UI_LAYOUT_FLEX_BOX,
BZ_UI_FLEX_DIR_ROW | BZ_UI_FLEX_ALIGN_CENTER
});
char buf[64];
BzUIKey id = bzUIGetUniqueKey(UI);
if (capacity == -1)
snprintf(buf, sizeof(buf), "%d##%d", amount, id);
else
snprintf(buf, sizeof(buf), "%d/%d##%d", amount, capacity, id);
const f32 scl = 0.4f;
uiBaseLabel(buf, getFont(), scl);
BzUINode *iconNode = bzUINodeMake(UI, id, &(BzUINodeDesc) {
.flags = BZ_UI_DRAW_SPRITE | BZ_UI_ALIGN_CENTER,
.semanticSize[BZ_UI_AXIS_X] = {
BZ_UI_SIZE_PIXELS, 80 * scl * uiGetScale(),
},
.semanticSize[BZ_UI_AXIS_Y] = {
BZ_UI_SIZE_PIXELS, 80 * scl * uiGetScale(),
},
.margin = {0, 0, 20 * uiGetScale(), 0}
});
bzUISetSpriteStyle(UI, iconNode, (BzUISpriteStyle) {
.rec = icon,
.texture = texture,
.tintNormal = WHITE,
.tintHover = WHITE,
.tintActive = WHITE,
});
bzUIPopParent(UI);
}