Fix UI handling

This commit is contained in:
2024-01-15 12:41:56 +01:00
parent 6acbe63276
commit 95e95e6893
2 changed files with 13 additions and 13 deletions

View File

@@ -174,8 +174,7 @@ void updatePlayerInput() {
if (IsKeyDown(KEY_E)) game->camera.rotation++;
if (IsKeyReleased(input->mapping.backBtn)) {
i32 selectedCount = ecs_query_entity_count(input->queries.selected);
if (selectedCount == 0) {
if (input->state == INPUT_NONE) {
setScreen(game, SCREEN_PAUSE_MENU);
} else {
ecs_remove_all(ECS, Selected);
@@ -185,12 +184,10 @@ void updatePlayerInput() {
}
}
if (!input->canUseMouse)
return;
// https://gamedev.stackexchange.com/questions/9330/zoom-to-cursor-calculation
float wheel = GetMouseWheelMove();
if (wheel != 0.0f) {
if (wheel != 0.0f && input->canUseMouse) {
const float zoomIncrement = 0.125f;
f32 oldZoom = game->camera.zoom;
f32 newZoom = oldZoom + wheel * zoomIncrement;
@@ -226,6 +223,9 @@ void updatePlayerInput() {
mapHeight - height + game->map.tileHeight + height * 0.5f);
}
if (!input->canUseMouse)
return;
BzTileMap *map = &game->map;

View File

@@ -48,12 +48,7 @@ void drawGameUI(Game *game, f32 dt) {
uiGameResCount(1, 10, popRec, tileset->tiles);
bzUIPopParent(UI);
BzUINode *buildMenu = bzUINodeMake(UI, bzUIGetUniqueKey(UI), &(BzUINodeDesc) {
.semanticSize[BZ_UI_AXIS_X] = {BZ_UI_SIZE_AS_PARENT},
.semanticSize[BZ_UI_AXIS_Y] = {BZ_UI_SIZE_CHILD_MAX},
.margin[BZ_UI_AXIS_Y * 2] = 5.0f * uiGetScale(),
});
bzUIPushParent(UI, buildMenu);
InputState *input = ecs_singleton_get_mut(ECS, InputState);
const BuildingType buildingOrder[] = {
@@ -78,9 +73,16 @@ void drawGameUI(Game *game, f32 dt) {
};
i32 numBuildings = sizeof(buildingOrder) / sizeof(*buildingOrder);
BzUINode *menu = NULL;
switch (input->state) {
case INPUT_NONE:
case INPUT_BUILDING:
menu = bzUINodeMake(UI, bzUIGetUniqueKey(UI), &(BzUINodeDesc) {
.semanticSize[BZ_UI_AXIS_X] = {BZ_UI_SIZE_AS_PARENT},
.semanticSize[BZ_UI_AXIS_Y] = {BZ_UI_SIZE_CHILD_MAX},
.margin[BZ_UI_AXIS_Y * 2] = 5.0f * uiGetScale(),
});
bzUIPushParent(UI, menu);
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
@@ -111,9 +113,7 @@ void drawGameUI(Game *game, f32 dt) {
}
bzUISetDebugMode(UI, true);
bzUIEnd(UI);
bzUISetDebugMode(UI, false);
}
void drawPauseUI(Game *game, f32 dt) {