diff --git a/assets/game.png b/assets/game.png index 3d2c7d0..5bb605e 100644 Binary files a/assets/game.png and b/assets/game.png differ diff --git a/game/game_tileset.h b/game/game_tileset.h index 1d9a265..d8c9065 100644 --- a/game/game_tileset.h +++ b/game/game_tileset.h @@ -331,6 +331,17 @@ typedef enum AnimType { ANIM_NONE, } AnimType; +static EntityType getEntityTile(EntityType type) { + switch (type) { + case ENTITY_WORKER: return 27; + case ENTITY_WOOD: return 7424; + case ENTITY_STONE: return 7425; + case ENTITY_GOLD: return 7426; + case ENTITY_POP: return 7427; + default: return -1; + } +} + static bool entityHasAnimation(EntityType entity, AnimType type) { switch (entity) { case ENTITY_WORKER: diff --git a/game/main.c b/game/main.c index 47e84c6..d066d75 100644 --- a/game/main.c +++ b/game/main.c @@ -280,6 +280,12 @@ void update(float dt, void *userData) { } } +static void drawOverScreen(Color c) { + i32 width = GetScreenWidth(); + i32 height = GetScreenHeight(); + + DrawRectangle(0, 0, width, height, c); +} static void renderGame(Game *game, float dt) { ClearBackground(RAYWHITE); BeginMode2D(game->camera); @@ -300,13 +306,48 @@ static void renderGame(Game *game, float dt) { EndMode2D(); -} -static void drawOverScreen(Color c) { + // UI i32 width = GetScreenWidth(); i32 height = GetScreenHeight(); + bzUIBegin(UI, width, height); + + bzUISetParentLayout(UI, (BzUILayout) { + .type = BZ_UI_LAYOUT_FLEX_BOX, + .flags = BZ_UI_FLEX_DIR_COLUMN | + BZ_UI_FLEX_JUSTIFY_SPACE_BETWEEN | + BZ_UI_FLEX_ALIGN_CENTER + }); + // top bar + f32 topBarHeight = 0.05f; + BzUINode *topBar = uiPushDivParentPercentage(1.0f, topBarHeight); + bzUISetParentLayout(UI, (BzUILayout) { + .type = BZ_UI_LAYOUT_FLEX_BOX, + .flags = BZ_UI_FLEX_DIR_ROW | + BZ_UI_FLEX_ALIGN_CENTER | + BZ_UI_FLEX_JUSTIFY_START + }); + Color topBarBG = {0, 0, 0, 50}; + bzUISetBackgroundStyle(UI, topBar, (BzUIBackgroundStyle) { + .normal = topBarBG, + .hover = topBarBG, + .active = topBarBG, + }); + BzTileset *tileset = &game->tileset; + Rectangle woodRec = bzTilesetGetTileRegion(tileset, getEntityTile(ENTITY_WOOD)); + Rectangle stoneRec = bzTilesetGetTileRegion(tileset, getEntityTile(ENTITY_STONE)); + Rectangle goldRec = bzTilesetGetTileRegion(tileset, getEntityTile(ENTITY_GOLD)); + Rectangle popRec = bzTilesetGetTileRegion(tileset, getEntityTile(ENTITY_POP)); + uiGameResCount(100, -1, woodRec, tileset->tiles); + uiGameResCount(100, -1, stoneRec, tileset->tiles); + uiGameResCount(100, -1, goldRec, tileset->tiles); + uiGameResCount(25, 100, popRec, tileset->tiles); + bzUIPopParent(UI); + + + bzUIEnd(UI); - DrawRectangle(0, 0, width, height, c); } + static void renderMainMenu(Game *game, float dt) { i32 width = GetScreenWidth(); i32 height = GetScreenHeight(); diff --git a/game/ui_widgets.c b/game/ui_widgets.c index a054edf..753c929 100644 --- a/game/ui_widgets.c +++ b/game/ui_widgets.c @@ -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); +} diff --git a/game/ui_widgets.h b/game/ui_widgets.h index 7d03e06..bd4e6f0 100644 --- a/game/ui_widgets.h +++ b/game/ui_widgets.h @@ -8,7 +8,7 @@ extern BzUI *UI; // defined in main.c f32 uiGetScale(); -void uiPushDivParentPercentage(f32 xPercent, f32 yPercent); +BzUINode *uiPushDivParentPercentage(f32 xPercent, f32 yPercent); // Template stuff void uiBaseLabel(const char *txt, Font font, f32 scl); @@ -25,4 +25,6 @@ bool uiSettingsButton(const char *txt); void uiSettingsCheckbox(const char *txt, bool *check); void uiSettingsSlider(const char *txt, f32 *value); +void uiGameResCount(i32 amount, i32 capacity, Rectangle icon, Texture2D texture); + #endif //PIXELDEFENSE_UI_WIDGETS_H diff --git a/scripts/extract_tileset.py b/scripts/extract_tileset.py index c19cd4a..93c4c9d 100644 --- a/scripts/extract_tileset.py +++ b/scripts/extract_tileset.py @@ -72,6 +72,8 @@ anim_writer = AnimationWriter(writer, "entity", "anim", entity_tiles) anim_writer.output_enum() anim_writer.output_anim_enum() + +anim_writer.output_enum_to_tile("getEntityTile") anim_writer.output_has_anim("entityHasAnimation") anim_writer.output_anim_sequence("entityGetAnimationSequence") anim_writer.output_anim_frame("entityGetAnimationFrame")