Fixed menu
This commit is contained in:
@ -77,13 +77,28 @@ void SpaceWarp::setAutoPilotEnabled(bool enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpaceWarp::scheduleNewAutoTarget() {
|
void SpaceWarp::scheduleNewAutoTarget() {
|
||||||
motionTarget.forwardScale = randomRange(0.82f, 1.28f);
|
// Autopilot behavior:
|
||||||
if (randomRange(0.0f, 1.0f) < 0.12f) {
|
// - 90% of the time: gentle forward flight with small lateral/vertical drift
|
||||||
motionTarget.forwardScale = -randomRange(0.35f, 0.85f);
|
// - 10% of the time: short lateral "bank" burst (stronger lateral speed) for a while
|
||||||
|
float choice = randomRange(0.0f, 1.0f);
|
||||||
|
if (choice < 0.90f) {
|
||||||
|
// Normal forward flight
|
||||||
|
motionTarget.forwardScale = randomRange(0.95f, 1.12f);
|
||||||
|
motionTarget.lateralSpeed = randomRange(-0.18f, 0.18f);
|
||||||
|
motionTarget.verticalSpeed = randomRange(-0.12f, 0.12f);
|
||||||
|
// Longer interval between aggressive maneuvers
|
||||||
|
autoTimer = randomRange(autoMinInterval, autoMaxInterval);
|
||||||
|
} else {
|
||||||
|
// Occasional lateral bank burst
|
||||||
|
motionTarget.forwardScale = randomRange(0.90f, 1.10f);
|
||||||
|
// Pick left or right burst
|
||||||
|
float dir = (randomRange(0.0f, 1.0f) < 0.5f) ? -1.0f : 1.0f;
|
||||||
|
motionTarget.lateralSpeed = dir * randomRange(0.70f, 1.35f);
|
||||||
|
// Allow modest vertical bias during a bank
|
||||||
|
motionTarget.verticalSpeed = randomRange(-0.35f, 0.35f);
|
||||||
|
// Shorter duration for the burst so it feels like a brief maneuver
|
||||||
|
autoTimer = randomRange(1.0f, 3.0f);
|
||||||
}
|
}
|
||||||
motionTarget.lateralSpeed = randomRange(-1.35f, 1.35f);
|
|
||||||
motionTarget.verticalSpeed = randomRange(-0.75f, 0.75f);
|
|
||||||
autoTimer = randomRange(autoMinInterval, autoMaxInterval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpaceWarp::spawnComet() {
|
void SpaceWarp::spawnComet() {
|
||||||
|
|||||||
@ -108,7 +108,11 @@ void UIRenderer::drawButton(SDL_Renderer* renderer, FontAtlas* font, float cx, f
|
|||||||
font->measure(label, textScale, textW, textH);
|
font->measure(label, textScale, textW, textH);
|
||||||
float tx = x + (w - static_cast<float>(textW)) * 0.5f;
|
float tx = x + (w - static_cast<float>(textW)) * 0.5f;
|
||||||
// Adjust vertical position for better alignment with background buttons
|
// Adjust vertical position for better alignment with background buttons
|
||||||
float ty = y + (h - static_cast<float>(textH)) * 0.5f + 2.0f;
|
// Vertically center text precisely within the button
|
||||||
|
// Vertically center text precisely within the button, then nudge down slightly
|
||||||
|
// to improve optical balance relative to icons and button art.
|
||||||
|
const float textNudge = 3.0f; // tweak this value to move labels up/down
|
||||||
|
float ty = y + (h - static_cast<float>(textH)) * 0.5f + textNudge;
|
||||||
|
|
||||||
// Choose text color based on selection state
|
// Choose text color based on selection state
|
||||||
SDL_Color textColor = {255, 255, 255, 255}; // Default white
|
SDL_Color textColor = {255, 255, 255, 255}; // Default white
|
||||||
|
|||||||
@ -30,6 +30,10 @@
|
|||||||
// This avoids renderer readback / surface APIs which aren't portable across SDL3 builds.
|
// This avoids renderer readback / surface APIs which aren't portable across SDL3 builds.
|
||||||
static void renderBackdropBlur(SDL_Renderer* renderer, const SDL_Rect& logicalVP, float logicalScale, float panelTop, float panelH, SDL_Texture* sceneTex, int sceneW, int sceneH) {
|
static void renderBackdropBlur(SDL_Renderer* renderer, const SDL_Rect& logicalVP, float logicalScale, float panelTop, float panelH, SDL_Texture* sceneTex, int sceneW, int sceneH) {
|
||||||
if (!renderer) return;
|
if (!renderer) return;
|
||||||
|
// Preserve previous draw blend mode so callers don't get surprised when
|
||||||
|
// the helper early-returns or changes blend state.
|
||||||
|
SDL_BlendMode prevBlendMode = SDL_BLENDMODE_NONE;
|
||||||
|
SDL_GetRenderDrawBlendMode(renderer, &prevBlendMode);
|
||||||
// If we don't have a captured scene texture, fall back to the frosted tint.
|
// If we don't have a captured scene texture, fall back to the frosted tint.
|
||||||
if (!sceneTex || sceneW <= 0 || sceneH <= 0) {
|
if (!sceneTex || sceneW <= 0 || sceneH <= 0) {
|
||||||
float viewportLogicalW = (float)logicalVP.w / logicalScale;
|
float viewportLogicalW = (float)logicalVP.w / logicalScale;
|
||||||
@ -43,7 +47,8 @@ static void renderBackdropBlur(SDL_Renderer* renderer, const SDL_Rect& logicalVP
|
|||||||
SDL_SetRenderDrawColor(renderer, 16, 24, 32, 12);
|
SDL_SetRenderDrawColor(renderer, 16, 24, 32, 12);
|
||||||
SDL_FRect shadow{ 0.0f, panelTop + panelH - std::max(2.0f, panelH * 0.06f), viewportLogicalW, std::max(2.0f, panelH * 0.06f) };
|
SDL_FRect shadow{ 0.0f, panelTop + panelH - std::max(2.0f, panelH * 0.06f), viewportLogicalW, std::max(2.0f, panelH * 0.06f) };
|
||||||
SDL_RenderFillRect(renderer, &shadow);
|
SDL_RenderFillRect(renderer, &shadow);
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
// Restore previous blend mode
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer, prevBlendMode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +72,7 @@ static void renderBackdropBlur(SDL_Renderer* renderer, const SDL_Rect& logicalVP
|
|||||||
SDL_SetRenderDrawColor(renderer, 200, 210, 220, 48);
|
SDL_SetRenderDrawColor(renderer, 200, 210, 220, 48);
|
||||||
SDL_FRect base{ 0.0f, panelTop, viewportLogicalW, panelH };
|
SDL_FRect base{ 0.0f, panelTop, viewportLogicalW, panelH };
|
||||||
SDL_RenderFillRect(renderer, &base);
|
SDL_RenderFillRect(renderer, &base);
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
SDL_SetRenderDrawBlendMode(renderer, prevBlendMode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +100,8 @@ static void renderBackdropBlur(SDL_Renderer* renderer, const SDL_Rect& logicalVP
|
|||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
SDL_DestroyTexture(small);
|
SDL_DestroyTexture(small);
|
||||||
|
// Restore previous blend mode so caller drawing is unaffected
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer, prevBlendMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuState::MenuState(StateContext& ctx) : State(ctx) {}
|
MenuState::MenuState(StateContext& ctx) : State(ctx) {}
|
||||||
@ -113,7 +120,7 @@ void MenuState::renderMainButtonTop(SDL_Renderer* renderer, float logicalScale,
|
|||||||
const float LOGICAL_W = 1200.f;
|
const float LOGICAL_W = 1200.f;
|
||||||
const float LOGICAL_H = 1000.f;
|
const float LOGICAL_H = 1000.f;
|
||||||
float contentOffsetX = 0.0f;
|
float contentOffsetX = 0.0f;
|
||||||
float contentOffsetY = 0.0f;
|
float contentOffsetY = 20.0f;
|
||||||
UIRenderer::computeContentOffsets((float)logicalVP.w, (float)logicalVP.h, LOGICAL_W, LOGICAL_H, logicalScale, contentOffsetX, contentOffsetY);
|
UIRenderer::computeContentOffsets((float)logicalVP.w, (float)logicalVP.h, LOGICAL_W, LOGICAL_H, logicalScale, contentOffsetX, contentOffsetY);
|
||||||
|
|
||||||
float contentW = LOGICAL_W * logicalScale;
|
float contentW = LOGICAL_W * logicalScale;
|
||||||
@ -124,7 +131,7 @@ void MenuState::renderMainButtonTop(SDL_Renderer* renderer, float logicalScale,
|
|||||||
// move buttons a bit lower for better visibility
|
// move buttons a bit lower for better visibility
|
||||||
// small global vertical offset for the whole menu (tweak to move UI down)
|
// small global vertical offset for the whole menu (tweak to move UI down)
|
||||||
float menuYOffset = LOGICAL_H * 0.03f;
|
float menuYOffset = LOGICAL_H * 0.03f;
|
||||||
float btnY = LOGICAL_H * 0.865f + contentOffsetY + (LOGICAL_H * 0.02f) + menuYOffset;
|
float btnY = LOGICAL_H * 0.865f + contentOffsetY + (LOGICAL_H * 0.02f) + menuYOffset + 45.0f;
|
||||||
|
|
||||||
// Compose same button definition used in render()
|
// Compose same button definition used in render()
|
||||||
char levelBtnText[32];
|
char levelBtnText[32];
|
||||||
@ -151,13 +158,15 @@ void MenuState::renderMainButtonTop(SDL_Renderer* renderer, float logicalScale,
|
|||||||
float halfSpan = 1.5f * spacing; // covers from leftmost to rightmost button centers
|
float halfSpan = 1.5f * spacing; // covers from leftmost to rightmost button centers
|
||||||
float panelLeft = groupCenterX - halfSpan - btnW * 0.5f - 14.0f;
|
float panelLeft = groupCenterX - halfSpan - btnW * 0.5f - 14.0f;
|
||||||
float panelRight = groupCenterX + halfSpan + btnW * 0.5f + 14.0f;
|
float panelRight = groupCenterX + halfSpan + btnW * 0.5f + 14.0f;
|
||||||
float panelTop = btnY - btnH * 0.5f - 12.0f;
|
// Nudge the panel slightly lower for better visual spacing
|
||||||
|
float panelTop = btnY - btnH * 0.5f - 12.0f + 18.0f;
|
||||||
float panelH = btnH + 24.0f;
|
float panelH = btnH + 24.0f;
|
||||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||||
// Backdrop blur pass before tint (use captured scene texture if available)
|
// Backdrop blur pass before tint (use captured scene texture if available)
|
||||||
renderBackdropBlur(renderer, logicalVP, logicalScale, panelTop, panelH, ctx.sceneTex, ctx.sceneW, ctx.sceneH);
|
renderBackdropBlur(renderer, logicalVP, logicalScale, panelTop, panelH, ctx.sceneTex, ctx.sceneW, ctx.sceneH);
|
||||||
// Brighter, less-opaque background to increase contrast
|
// Brighter, more transparent background to increase contrast but keep scene visible
|
||||||
SDL_SetRenderDrawColor(renderer, 28, 36, 46, 180);
|
// More transparent background so underlying scene shows through
|
||||||
|
SDL_SetRenderDrawColor(renderer, 28, 36, 46, 110);
|
||||||
// Fill full-width background so edges are covered in fullscreen
|
// Fill full-width background so edges are covered in fullscreen
|
||||||
float viewportLogicalW = (float)logicalVP.w / logicalScale;
|
float viewportLogicalW = (float)logicalVP.w / logicalScale;
|
||||||
SDL_FRect fullPanel{ 0.0f, panelTop, viewportLogicalW, panelH };
|
SDL_FRect fullPanel{ 0.0f, panelTop, viewportLogicalW, panelH };
|
||||||
@ -165,8 +174,8 @@ void MenuState::renderMainButtonTop(SDL_Renderer* renderer, float logicalScale,
|
|||||||
// Also draw the central strip to keep visual center emphasis
|
// Also draw the central strip to keep visual center emphasis
|
||||||
SDL_FRect panelRect{ panelLeft, panelTop, panelRight - panelLeft, panelH };
|
SDL_FRect panelRect{ panelLeft, panelTop, panelRight - panelLeft, panelH };
|
||||||
SDL_RenderFillRect(renderer, &panelRect);
|
SDL_RenderFillRect(renderer, &panelRect);
|
||||||
// brighter full-width border
|
// brighter full-width border (slightly more transparent)
|
||||||
SDL_SetRenderDrawColor(renderer, 120, 140, 160, 200);
|
SDL_SetRenderDrawColor(renderer, 120, 140, 160, 120);
|
||||||
// Expand border to cover full window width (use actual viewport)
|
// Expand border to cover full window width (use actual viewport)
|
||||||
SDL_FRect borderFull{ 0.0f, panelTop, viewportLogicalW, panelH };
|
SDL_FRect borderFull{ 0.0f, panelTop, viewportLogicalW, panelH };
|
||||||
SDL_RenderRect(renderer, &borderFull);
|
SDL_RenderRect(renderer, &borderFull);
|
||||||
|
|||||||
Reference in New Issue
Block a user