part refactor settings logic

This commit is contained in:
2025-11-15 01:15:43 +01:00
parent a951b3bcb2
commit dbbcd7f926
5 changed files with 50 additions and 39 deletions

View File

@@ -61,9 +61,8 @@ public class GameScreen implements Screen {
}
private void initCamera() {
camera = new PerspectiveCamera(55f, RETRO_WIDTH, RETRO_HEIGHT);
settings = new GameSettings();
settings.fov = camera.fieldOfView;
camera = new PerspectiveCamera(settings.fov, RETRO_WIDTH, RETRO_HEIGHT);
cameraController = new FpsCameraController(camera, settings);
}

View File

@@ -110,9 +110,10 @@ public class FpsCameraController {
/** Update each frame with delta time */
public void update(float delta, World3D world) {
if (settings.bobbingEnabled) {
camera.position.y -= bobOffsetY;
bobOffsetY = 0f;
}
if (!mouseCaptured) {
return;
@@ -322,6 +323,7 @@ public class FpsCameraController {
// 4) VIEW BOBBING (purely visual)
// =========================================================
// horizontal movement magnitude (world units per frame)
if (settings.bobbingEnabled) {
float horizLen = (float)Math.sqrt(moveX * moveX + moveZ * moveZ);
if (grounded && horizLen > 0.0001f) {
@@ -339,6 +341,7 @@ public class FpsCameraController {
camera.position.y += bobOffsetY;
}
}
private void updateCameraDirection() {
// build direction vector from yaw/pitch
float useYaw = yaw;

View File

@@ -2,10 +2,13 @@ package wtf.beatrice.retrorender.engine;
public class GameSettings {
public float fov = 55f; // degrees
public float fov = 60f; // degrees
public float mouseSensitivity = 0.15f;
public float moveSpeed = 5f;
public float minFov = 40f;
public float maxFov = 100f;
public final float minFov = 40f;
public final float maxFov = 100f;
public final float fovStep = 2f;
public boolean bobbingEnabled = true;
}

View File

@@ -17,10 +17,7 @@ public class GameUi {
public GameUi(GameSettings settings) {
this.settings = settings;
this.pauseMenu = new PauseMenu();
this.settingsMenu = new SettingsMenu();
// sync initial settings
this.settingsMenu.setFov(settings.fov);
this.settingsMenu = new SettingsMenu(settings);
}
public UiMode onEsc(UiMode current) {
@@ -54,6 +51,7 @@ public class GameUi {
boolean close = settingsMenu.handleClick(retroX, retroY);
// always sync FOV to settings
settings.fov = settingsMenu.getFov();
settings.bobbingEnabled = settingsMenu.isBobbingEnabled();
if (close) {
// Settings “Close” button clicked -> go back to PAUSE

View File

@@ -17,18 +17,18 @@ public class SettingsMenu {
private final BitmapFont boldFont;
private final Texture pixel;
// FOV value stored here, GameScreen syncs it to the camera
private float fov;
private final float minFov = 40f;
private final float maxFov = 100f;
private final float fovStep = 2f;
private final GameSettings settings;
private boolean bobbingEnabled = true;
// button / hit areas
private float fovDecX, fovDecY, fovDecW, fovDecH;
private float fovIncX, fovIncY, fovIncW, fovIncH;
private float closeX, closeY, closeW, closeH;
public SettingsMenu() {
public SettingsMenu(GameSettings settings) {
this.settings = settings;
batch = new SpriteBatch();
FreeTypeFontGenerator generator =
@@ -60,19 +60,27 @@ public class SettingsMenu {
pm.fill();
pixel = new Texture(pm);
pm.dispose();
// default FOV
fov = 55f;
}
public void setFov(float fov) {
this.fov = MathUtils.clamp(fov, minFov, maxFov);
settings.fov = MathUtils.clamp(fov, settings.minFov, settings.maxFov);
}
public float getFov() {
return fov;
return settings.fov;
}
public boolean isBobbingEnabled()
{
return bobbingEnabled;
}
public void setBobbingEnabled(boolean enabled){
bobbingEnabled = enabled;
}
/**
* @param width RETRO_WIDTH
* @param height RETRO_HEIGHT
@@ -136,7 +144,7 @@ public class SettingsMenu {
drawButtonWithLabel(">", fovIncX, fovIncY, fovIncW, fovIncH);
// numeric value centered between dec/inc
String fovText = String.format("%3.0f°", fov);
String fovText = String.format("%3.0f°", settings.fov);
layout.setText(font, fovText);
float valueCenter = (fovDecX + fovDecW + fovIncX) / 2f;
@@ -196,14 +204,14 @@ public class SettingsMenu {
// FOV -
if (x >= fovDecX && x <= fovDecX + fovDecW &&
y >= fovDecY && y <= fovDecY + fovDecH) {
fov = MathUtils.clamp(fov - fovStep, minFov, maxFov);
settings.fov = MathUtils.clamp(settings.fov - settings.fovStep, settings.minFov, settings.maxFov);
return false;
}
// FOV +
if (x >= fovIncX && x <= fovIncX + fovIncW &&
y >= fovIncY && y <= fovIncY + fovIncH) {
fov = MathUtils.clamp(fov + fovStep, minFov, maxFov);
settings.fov = MathUtils.clamp(settings.fov + settings.fovStep, settings.minFov, settings.maxFov);
return false;
}