latest state

This commit is contained in:
2025-12-06 09:43:33 +01:00
parent 294e935344
commit b44de25113
19 changed files with 2451 additions and 524 deletions

View File

@ -8,6 +8,7 @@
#include <algorithm>
#include <cstdio>
#include <string>
#include "../graphics/renderers/UIRenderer.h"
// Use dynamic logical dimensions from GlobalState instead of hardcoded values
@ -93,30 +94,7 @@ static void Vignette(SDL_Renderer* r, int w, int h) {
FillRect(r, SDL_FRect{(float)w - pad, 0, (float)pad, (float)h}, SDL_Color{0, 0, 0, 140});
}
static SDL_FRect DrawPanel(SDL_Renderer* r, float w, float h, bool draw = true, float offX = 0.f, float offY = 0.f) {
float PW = std::min(520.f, w * 0.65f);
float PH = std::min(360.f, h * 0.7f);
SDL_FRect p{ (w - PW) / 2.f + offX, (h - PH) / 2.f - 40.f + offY, PW, PH }; // Moved up by 50px
if (!draw) return p; // geometry only
// drop shadow
FillRect(r, SDL_FRect{p.x + 6, p.y + 10, p.w, p.h}, SDL_Color{0, 0, 0, 120});
// glow aura
for (int i = 0; i < 6; i++) {
SDL_FRect g{ p.x - (float)(i * 2), p.y - (float)(i * 2), p.w + (float)(i * 4), p.h + (float)(i * 4) };
SDL_Color c = COL_CYAN_SO; c.a = (Uint8)(36 - i * 6);
StrokeRect(r, g, c);
}
// outer body + border
FillRect(r, p, COL_PANEL);
StrokeRect(r, p, COL_CYAN);
// inner face
FillRect(r, SDL_FRect{p.x + 12, p.y + 56, p.w - 24, p.h - 68}, COL_PANEL_IN);
StrokeRect(r, SDL_FRect{p.x + 12, p.y + 56, p.w - 24, p.h - 68}, SDL_Color{24, 31, 41, 180});
return p;
}
// DrawPanel removed, replaced by UIRenderer::drawSciFiPanel
struct Grid {
int cols = 4, rows = 5;
@ -195,7 +173,17 @@ void LevelSelectorState::handleEvent(const SDL_Event& e) {
float ly = (float(e.button.y) - float(lastLogicalVP.y)) / (lastLogicalScale > 0.f ? lastLogicalScale : 1.f);
// Use same panel calculation as render (centered)
SDL_FRect panel = DrawPanel(nullptr, LOGICAL_W, LOGICAL_H, /*draw=*/false, 0.f, 0.f);
const float LOGICAL_W_F = 1200.f;
const float LOGICAL_H_F = 1000.f;
float winW = (float)lastLogicalVP.w;
float winH = (float)lastLogicalVP.h;
float contentOffsetX = 0.0f;
float contentOffsetY = 0.0f;
UIRenderer::computeContentOffsets(winW, winH, LOGICAL_W_F, LOGICAL_H_F, lastLogicalScale, contentOffsetX, contentOffsetY);
float PW = std::min(520.f, LOGICAL_W_F * 0.65f);
float PH = std::min(360.f, LOGICAL_H_F * 0.7f);
SDL_FRect panel{ (LOGICAL_W_F - PW) / 2.f + contentOffsetX, (LOGICAL_H_F - PH) / 2.f - 40.f + contentOffsetY, PW, PH };
Grid g = MakeGrid(panel);
int hit = HitTest(g, int(lx), int(ly));
if (hit != -1) {
@ -214,7 +202,17 @@ void LevelSelectorState::handleEvent(const SDL_Event& e) {
float ly = (float(e.motion.y) - float(lastLogicalVP.y)) / (lastLogicalScale > 0.f ? lastLogicalScale : 1.f);
// Use same panel calculation as render (centered)
SDL_FRect panel = DrawPanel(nullptr, LOGICAL_W, LOGICAL_H, /*draw=*/false, 0.f, 0.f);
const float LOGICAL_W_F = 1200.f;
const float LOGICAL_H_F = 1000.f;
float winW = (float)lastLogicalVP.w;
float winH = (float)lastLogicalVP.h;
float contentOffsetX = 0.0f;
float contentOffsetY = 0.0f;
UIRenderer::computeContentOffsets(winW, winH, LOGICAL_W_F, LOGICAL_H_F, lastLogicalScale, contentOffsetX, contentOffsetY);
float PW = std::min(520.f, LOGICAL_W_F * 0.65f);
float PH = std::min(360.f, LOGICAL_H_F * 0.7f);
SDL_FRect panel{ (LOGICAL_W_F - PW) / 2.f + contentOffsetX, (LOGICAL_H_F - PH) / 2.f - 40.f + contentOffsetY, PW, PH };
Grid g = MakeGrid(panel);
hoveredLevel = HitTest(g, int(lx), int(ly));
}
@ -242,29 +240,30 @@ void LevelSelectorState::drawLevelSelectionPopup(SDL_Renderer* renderer, float l
// Compute content offsets (same approach as MenuState for proper centering)
float winW = (float)logicalVP.w;
float winH = (float)logicalVP.h;
float contentW = LOGICAL_W * logicalScale;
float contentH = LOGICAL_H * logicalScale;
float contentOffsetX = (winW - contentW) * 0.5f / logicalScale;
float contentOffsetY = (winH - contentH) * 0.5f / logicalScale;
float contentOffsetX = 0.0f;
float contentOffsetY = 0.0f;
UIRenderer::computeContentOffsets(winW, winH, LOGICAL_W, LOGICAL_H, logicalScale, contentOffsetX, contentOffsetY);
// Draw the logo at the top (same as MenuState)
SDL_Texture* logoToUse = ctx.logoSmallTex ? ctx.logoSmallTex : ctx.logoTex;
if (logoToUse) {
// Use dimensions provided by the shared context when available
int texW = (logoToUse == ctx.logoSmallTex && ctx.logoSmallW > 0) ? ctx.logoSmallW : 872;
int texH = (logoToUse == ctx.logoSmallTex && ctx.logoSmallH > 0) ? ctx.logoSmallH : 273;
float maxW = LOGICAL_W * 0.6f; // Match MenuState and OptionsState
float scale = std::min(1.0f, maxW / float(texW));
float dw = texW * scale;
float dh = texH * scale;
float logoX = (LOGICAL_W - dw) / 2.f + contentOffsetX;
float logoY = LOGICAL_H * 0.05f + contentOffsetY; // Match MenuState and OptionsState
SDL_FRect dst{logoX, logoY, dw, dh};
SDL_RenderTexture(renderer, logoToUse, nullptr, &dst);
int logoW = 0, logoH = 0;
if (logoToUse == ctx.logoSmallTex && ctx.logoSmallW > 0) {
logoW = ctx.logoSmallW;
logoH = ctx.logoSmallH;
}
UIRenderer::drawLogo(renderer, logoToUse, LOGICAL_W, LOGICAL_H, contentOffsetX, contentOffsetY, logoW, logoH);
// Panel and title strip (in logical space) - centered properly with offsets
SDL_FRect panel = DrawPanel(renderer, LOGICAL_W, LOGICAL_H, /*draw=*/true, contentOffsetX, contentOffsetY);
float PW = std::min(520.f, LOGICAL_W * 0.65f);
float PH = std::min(360.f, LOGICAL_H * 0.7f);
SDL_FRect panel{ (LOGICAL_W - PW) / 2.f + contentOffsetX, (LOGICAL_H - PH) / 2.f - 40.f + contentOffsetY, PW, PH };
UIRenderer::drawSciFiPanel(renderer, panel);
// Inner face (LevelSelector specific)
SDL_FRect inner{panel.x + 12, panel.y + 56, panel.w - 24, panel.h - 68};
FillRect(renderer, inner, COL_PANEL_IN);
StrokeRect(renderer, inner, SDL_Color{24, 31, 41, 180});
// Title text - prefer pixelFont for a blocky title if available, fallback to regular font
FontAtlas* titleFont = ctx.pixelFont ? ctx.pixelFont : ctx.font;
@ -296,7 +295,17 @@ bool LevelSelectorState::isMouseInPopup(float mouseX, float mouseY, float& popup
lx = (float(mouseX) - float(lastLogicalVP.x)) / lastLogicalScale;
ly = (float(mouseY) - float(lastLogicalVP.y)) / lastLogicalScale;
}
SDL_FRect p = DrawPanel(nullptr, LOGICAL_W, LOGICAL_H, /*draw=*/false, 0.f, 0.f);
const float LOGICAL_W_F = 1200.f;
const float LOGICAL_H_F = 1000.f;
float winW = (float)lastLogicalVP.w;
float winH = (float)lastLogicalVP.h;
float contentOffsetX = 0.0f;
float contentOffsetY = 0.0f;
UIRenderer::computeContentOffsets(winW, winH, LOGICAL_W_F, LOGICAL_H_F, lastLogicalScale, contentOffsetX, contentOffsetY);
float PW = std::min(520.f, LOGICAL_W_F * 0.65f);
float PH = std::min(360.f, LOGICAL_H_F * 0.7f);
SDL_FRect p{ (LOGICAL_W_F - PW) / 2.f + contentOffsetX, (LOGICAL_H_F - PH) / 2.f - 40.f + contentOffsetY, PW, PH };
popupX = p.x; popupY = p.y; popupW = p.w; popupH = p.h;
return lx >= popupX && lx <= popupX + popupW && ly >= popupY && ly <= popupY + popupH;
}
@ -312,7 +321,17 @@ int LevelSelectorState::getLevelFromMouse(float mouseX, float mouseY, float popu
lx = (float(mouseX) - float(lastLogicalVP.x)) / lastLogicalScale;
ly = (float(mouseY) - float(lastLogicalVP.y)) / lastLogicalScale;
}
SDL_FRect p = DrawPanel(nullptr, LOGICAL_W, LOGICAL_H, /*draw=*/false, 0.f, 0.f);
const float LOGICAL_W_F = 1200.f;
const float LOGICAL_H_F = 1000.f;
float winW = (float)lastLogicalVP.w;
float winH = (float)lastLogicalVP.h;
float contentOffsetX = 0.0f;
float contentOffsetY = 0.0f;
UIRenderer::computeContentOffsets(winW, winH, LOGICAL_W_F, LOGICAL_H_F, lastLogicalScale, contentOffsetX, contentOffsetY);
float PW = std::min(520.f, LOGICAL_W_F * 0.65f);
float PH = std::min(360.f, LOGICAL_H_F * 0.7f);
SDL_FRect p{ (LOGICAL_W_F - PW) / 2.f + contentOffsetX, (LOGICAL_H_F - PH) / 2.f - 40.f + contentOffsetY, PW, PH };
Grid g = MakeGrid(p);
return HitTest(g, (int)lx, (int)ly);
}