HUD hide mode fix

This commit is contained in:
MihailRis 2024-01-12 13:21:40 +03:00
parent faabb8178a
commit 31b0349757
3 changed files with 30 additions and 14 deletions

View File

@ -200,8 +200,11 @@ void HudRenderer::drawDebug(int fps){
fpsMax = max(fps, fpsMax); fpsMax = max(fps, fpsMax);
} }
void HudRenderer::update() { void HudRenderer::update(bool visible) {
auto menu = gui->getMenu(); auto menu = gui->getMenu();
if (!visible && inventoryOpen) {
inventoryOpen = false;
}
if (pause && menu->current().panel == nullptr) { if (pause && menu->current().panel == nullptr) {
pause = false; pause = false;
} }
@ -216,7 +219,7 @@ void HudRenderer::update() {
menu->set("pause"); menu->set("pause");
} }
} }
if (Events::jactive(BIND_HUD_INVENTORY)) { if (visible && Events::jactive(BIND_HUD_INVENTORY)) {
if (!pause) { if (!pause) {
inventoryOpen = !inventoryOpen; inventoryOpen = !inventoryOpen;
} }
@ -226,6 +229,26 @@ void HudRenderer::update() {
} }
} }
void HudRenderer::drawOverlay(const GfxContext& ctx) {
if (pause) {
Shader* uishader = assets->getShader("ui");
uishader->use();
uishader->uniformMatrix("u_projview", uicamera->getProjection()*uicamera->getView());
const Viewport& viewport = ctx.getViewport();
const uint width = viewport.getWidth();
const uint height = viewport.getHeight();
auto batch = ctx.getBatch2D();
batch->begin();
// draw fullscreen dark overlay
batch->texture(nullptr);
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.5f);
batch->rect(0, 0, width, height);
batch->render();
}
}
void HudRenderer::draw(const GfxContext& ctx){ void HudRenderer::draw(const GfxContext& ctx){
auto level = frontend->getLevel(); auto level = frontend->getLevel();
@ -252,7 +275,7 @@ void HudRenderer::draw(const GfxContext& ctx){
// Crosshair // Crosshair
batch->begin(); batch->begin();
if (Events::_cursor_locked && !level->player->debug) { if (!pause && Events::_cursor_locked && !level->player->debug) {
batch->lineWidth(2); batch->lineWidth(2);
batch->line(width/2, height/2-6, width/2, height/2+6, 0.2f, 0.2f, 0.2f, 1.0f); batch->line(width/2, height/2-6, width/2, height/2+6, 0.2f, 0.2f, 0.2f, 1.0f);
batch->line(width/2+6, height/2, width/2-6, height/2, 0.2f, 0.2f, 0.2f, 1.0f); batch->line(width/2+6, height/2, width/2-6, height/2, 0.2f, 0.2f, 0.2f, 1.0f);
@ -260,14 +283,6 @@ void HudRenderer::draw(const GfxContext& ctx){
batch->line(width/2+5, height/2-5, width/2-5, height/2+5, 0.9f, 0.9f, 0.9f, 1.0f); batch->line(width/2+5, height/2-5, width/2-5, height/2+5, 0.9f, 0.9f, 0.9f, 1.0f);
} }
batch->begin();
if (pause) {
// draw fullscreen dark overlay
batch->texture(nullptr);
batch->color = vec4(0.0f, 0.0f, 0.0f, 0.5f);
batch->rect(0, 0, width, height);
}
if (inventoryOpen) { if (inventoryOpen) {
// draw content access panel (all available items) // draw content access panel (all available items)
contentAccess->setPosition(viewport.getWidth()-contentAccess->getWidth(), 0); contentAccess->setPosition(viewport.getWidth()-contentAccess->getWidth(), 0);

View File

@ -45,7 +45,8 @@ public:
HudRenderer(Engine* engine, LevelFrontend* frontend); HudRenderer(Engine* engine, LevelFrontend* frontend);
~HudRenderer(); ~HudRenderer();
void update(); void update(bool hudVisible);
void drawOverlay(const GfxContext& context);
void draw(const GfxContext& context); void draw(const GfxContext& context);
void drawDebug(int fps); void drawDebug(int fps);

View File

@ -139,8 +139,7 @@ void LevelScreen::update(float delta) {
level->world->updateTimers(delta); level->world->updateTimers(delta);
} }
controller->update(delta, !inputLocked, hud->isPause()); controller->update(delta, !inputLocked, hud->isPause());
if (hudVisible) hud->update(hudVisible);
hud->update();
} }
void LevelScreen::draw(float delta) { void LevelScreen::draw(float delta) {
@ -151,6 +150,7 @@ void LevelScreen::draw(float delta) {
worldRenderer->draw(ctx, camera.get(), hudVisible); worldRenderer->draw(ctx, camera.get(), hudVisible);
hud->drawOverlay(ctx);
if (hudVisible) { if (hudVisible) {
hud->draw(ctx); hud->draw(ctx);
if (level->player->debug) { if (level->player->debug) {