Add Main menu screen
This commit is contained in:
BIN
assets/fonts/CompassPro.ttf
Normal file
BIN
assets/fonts/CompassPro.ttf
Normal file
Binary file not shown.
@@ -17,6 +17,9 @@ typedef struct Game {
|
|||||||
BzTileMap map;
|
BzTileMap map;
|
||||||
BzSpatialGrid *entityGrid;
|
BzSpatialGrid *entityGrid;
|
||||||
f32 frameDuration;
|
f32 frameDuration;
|
||||||
|
|
||||||
|
Font font;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
i64 wood;
|
i64 wood;
|
||||||
i64 iron;
|
i64 iron;
|
||||||
|
|||||||
11
game/main.c
11
game/main.c
@@ -152,6 +152,7 @@ bool init(void *userData) {
|
|||||||
ecs_singleton_set(ECS, Game, {});
|
ecs_singleton_set(ECS, Game, {});
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
game->screen = SCREEN_MAIN_MENU;
|
game->screen = SCREEN_MAIN_MENU;
|
||||||
|
game->font = LoadFontEx("assets/fonts/CompassPro.ttf", 92, NULL, 0);
|
||||||
|
|
||||||
ECS_COMPONENT_DEFINE(ECS, InputState);
|
ECS_COMPONENT_DEFINE(ECS, InputState);
|
||||||
ecs_singleton_set(ECS, InputState, {});
|
ecs_singleton_set(ECS, InputState, {});
|
||||||
@@ -248,6 +249,8 @@ void deinit(void *userData) {
|
|||||||
|
|
||||||
bzUIDestroy(UI);
|
bzUIDestroy(UI);
|
||||||
UI = NULL;
|
UI = NULL;
|
||||||
|
|
||||||
|
UnloadFont(game->font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -319,7 +322,7 @@ static void renderMainMenu(Game *game, float dt) {
|
|||||||
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
||||||
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_JUSTIFY_CENTER | BZ_UI_FLEX_ALIGN_CENTER
|
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_JUSTIFY_CENTER | BZ_UI_FLEX_ALIGN_CENTER
|
||||||
});
|
});
|
||||||
uiLargeLabel("PixelDefense");
|
uiMainMenuLabel("Pixel Defense");
|
||||||
bzUIPopParent(UI);
|
bzUIPopParent(UI);
|
||||||
|
|
||||||
uiPushDivParentPercentage(1.0f, 0.6f);
|
uiPushDivParentPercentage(1.0f, 0.6f);
|
||||||
@@ -327,14 +330,14 @@ static void renderMainMenu(Game *game, float dt) {
|
|||||||
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
.type = BZ_UI_LAYOUT_FLEX_BOX,
|
||||||
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER
|
.flags = BZ_UI_FLEX_DIR_COLUMN | BZ_UI_FLEX_ALIGN_CENTER
|
||||||
});
|
});
|
||||||
if (uiLargeTextButton("Play")) {
|
if (uiMainMenuButton("Play")) {
|
||||||
bzLogInfo("Play");
|
bzLogInfo("Play");
|
||||||
game->screen = SCREEN_GAME;
|
game->screen = SCREEN_GAME;
|
||||||
}
|
}
|
||||||
if (uiLargeTextButton("Settings")) {
|
if (uiMainMenuButton("Settings")) {
|
||||||
bzLogInfo("Settings");
|
bzLogInfo("Settings");
|
||||||
}
|
}
|
||||||
if (uiLargeTextButton("Exit")) {
|
if (uiMainMenuButton("Exit")) {
|
||||||
bzLogInfo("Bye");
|
bzLogInfo("Bye");
|
||||||
bzGameExit();
|
bzGameExit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
#include "ui_widgets.h"
|
#include "ui_widgets.h"
|
||||||
|
|
||||||
|
#include "game_state.h"
|
||||||
|
|
||||||
|
f32 uiGetScale() {
|
||||||
|
return GetScreenHeight() / 720.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
Font getFont() {
|
||||||
|
static const Game *game = NULL;
|
||||||
|
if (!game) {
|
||||||
|
game = ecs_singleton_get(ECS, Game);
|
||||||
|
}
|
||||||
|
return game->font;
|
||||||
|
}
|
||||||
|
|
||||||
void uiPushDivParentPercentage(f32 xPercent, f32 yPercent) {
|
void uiPushDivParentPercentage(f32 xPercent, f32 yPercent) {
|
||||||
bzUIPushDiv(UI, (BzUISize) {
|
bzUIPushDiv(UI, (BzUISize) {
|
||||||
.kind = BZ_UI_SIZE_PARENT_PERCENT,
|
.kind = BZ_UI_SIZE_PARENT_PERCENT,
|
||||||
@@ -10,10 +24,10 @@ void uiPushDivParentPercentage(f32 xPercent, f32 yPercent) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiLargeLabel(const char *txt) {
|
void uiBaseLabel(const char *txt, Font font, f32 scl) {
|
||||||
bzUINodeMake(UI, bzUIKeyFromString(txt),
|
bzUINodeMake(UI, bzUIKeyFromString(txt),
|
||||||
&(BzUINodeDesc) {
|
&(BzUINodeDesc) {
|
||||||
.flags = BZ_UI_DRAW_TEXT | BZ_UI_ALIGN_CENTER,
|
.flags = BZ_UI_DRAW_TEXT | BZ_UI_DRAW_TEXT_SHADOW | BZ_UI_ALIGN_CENTER,
|
||||||
.semanticSize[BZ_UI_AXIS_X] = {
|
.semanticSize[BZ_UI_AXIS_X] = {
|
||||||
.kind = BZ_UI_SIZE_FIT,
|
.kind = BZ_UI_SIZE_FIT,
|
||||||
},
|
},
|
||||||
@@ -23,16 +37,55 @@ void uiLargeLabel(const char *txt) {
|
|||||||
.string = txt,
|
.string = txt,
|
||||||
.padding = {5, 5, 5, 5},
|
.padding = {5, 5, 5, 5},
|
||||||
.style = {
|
.style = {
|
||||||
.font = GetFontDefault(),
|
.font = font,
|
||||||
.fontSize = 62,
|
.fontSpacing = 2 * uiGetScale() * scl,
|
||||||
.textColor = BLACK,
|
.fontSize = 62 * uiGetScale() * scl,
|
||||||
.textHoverColor = BLACK,
|
.shadowOffset[BZ_UI_AXIS_X] = 2 * uiGetScale() * scl,
|
||||||
.textActiveColor = BLACK,
|
.shadowOffset[BZ_UI_AXIS_Y] = 2 * uiGetScale() * scl,
|
||||||
|
.textColor = WHITE,
|
||||||
|
.textHoverColor = WHITE,
|
||||||
|
.textActiveColor = WHITE,
|
||||||
|
.textShadowColor = BLACK,
|
||||||
|
.textShadowHoverColor = BLACK,
|
||||||
|
.textShadowActiveColor = BLACK,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uiLargeTextButton(const char *txt) {
|
bool uiBaseTextButton(const char *txt, Font font, f32 scl) {
|
||||||
return bzUIButton(UI, txt, NULL);
|
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,
|
||||||
|
},
|
||||||
|
.semanticSize[BZ_UI_AXIS_Y] = {
|
||||||
|
.kind = BZ_UI_SIZE_FIT
|
||||||
|
},
|
||||||
|
.string = txt,
|
||||||
|
.padding = {0, 0, 0, 0},
|
||||||
|
.margin = {5, 5, 5, 5},
|
||||||
|
.style = {
|
||||||
|
.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,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return bzUIGetInteraction(UI, node).clicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiMainMenuLabel(const char *txt) {
|
||||||
|
uiBaseLabel(txt, getFont(), 1.8f);
|
||||||
|
}
|
||||||
|
bool uiMainMenuButton(const char *txt) {
|
||||||
|
return uiBaseTextButton(txt, getFont(), 1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,16 @@
|
|||||||
|
|
||||||
extern BzUI *UI; // defined in main.c
|
extern BzUI *UI; // defined in main.c
|
||||||
|
|
||||||
|
f32 uiGetScale();
|
||||||
|
|
||||||
void uiPushDivParentPercentage(f32 xPercent, f32 yPercent);
|
void uiPushDivParentPercentage(f32 xPercent, f32 yPercent);
|
||||||
|
|
||||||
void uiLargeLabel(const char *txt);
|
// Template stuff
|
||||||
|
void uiBaseLabel(const char *txt, Font font, f32 scl);
|
||||||
|
bool uiBaseTextButton(const char *txt, Font font, f32 scl);
|
||||||
|
|
||||||
bool uiLargeTextButton(const char *txt);
|
// actual UI
|
||||||
|
void uiMainMenuLabel(const char *txt);
|
||||||
|
bool uiMainMenuButton(const char *txt);
|
||||||
|
|
||||||
#endif //PIXELDEFENSE_UI_WIDGETS_H
|
#endif //PIXELDEFENSE_UI_WIDGETS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user