Fix acousticHandler error

This commit is contained in:
Felix
2024-11-18 16:40:01 +01:00
parent 728530a8f2
commit c6438d75cc
6 changed files with 27 additions and 23 deletions

View File

@@ -23,6 +23,7 @@ public class AcousticHandler {
private GameMusic playing = null; // Currently playing track
private GameMusic scheduled = null; // Scheduled track to play next
private GameMusic old = null; // Old track being faded out
private ArrayList<GameMusic> queue = new ArrayList<>();
private float mainVolume = 1.0f;
private float musicVolume = 1.0f;
@@ -169,6 +170,12 @@ private float lerp(float start, float end, float t) {
* - Ensures no NullPointerException occurs by validating track states before invoking methods.
*/
private void updateVolumeAndTrack() {
if(!fading) {
if(!queue.isEmpty()) {
scheduled = queue.removeFirst();
}
}
if (scheduled == null && !fading && playing == null) {
// Nothing to play or fade, early exit
return;
@@ -283,7 +290,8 @@ private void updateGameTracks() {
MusicAsset nextTrack = gameTracks.remove(0);
scheduled = new GameMusic(app, nextTrack, getMusicVolumeTotal(), nextTrack.getSubVolume(), nextTrack.getLoop(), 0.0f);
GameMusic music = new GameMusic(app, nextTrack, getMusicVolumeTotal(), nextTrack.getSubVolume(), nextTrack.getLoop(), 0.0f);
queue.add(music);
}
}

View File

@@ -9,6 +9,8 @@
public abstract class Dialog {
protected MdgaApp app;
protected int xOffset = 0;
protected int yOffset = 0;
public Dialog(MdgaApp app) {
this.app = app;
@@ -17,5 +19,13 @@ public Dialog(MdgaApp app) {
public abstract void show();
public abstract void hide();
public abstract void addButton(MdgaButton button);
public void setYOffset(int yOffset) {
this.yOffset = yOffset;
}
public void setXOffset(int xOffset) {
this.xOffset = xOffset;
}
}

View File

@@ -10,6 +10,8 @@
public class HorizontalButtonDialog extends Dialog {
private Node row = new Node();
private int offset = 0;
public HorizontalButtonDialog(MdgaApp app) {
super(app);
@@ -22,7 +24,7 @@ public HorizontalButtonDialog(MdgaApp app) {
public void show() {
app.getGuiNode().attachChild(row);
row.setLocalTranslation(app.getCamera().getWidth() / 2, app.getCamera().getHeight() / 2, 0);
row.setLocalTranslation((app.getCamera().getWidth() / 2) + xOffset, (app.getCamera().getHeight() / 2) + yOffset, 0);
}
@Override

View File

@@ -25,8 +25,8 @@ public void show() {
app.getGuiNode().attachChild(container);
container.setLocalTranslation(
app.getCamera().getWidth() / 2 - container.getPreferredSize().x / 2,
app.getCamera().getHeight() / 2 + container.getPreferredSize().y / 2,
(app.getCamera().getWidth() / 2 - container.getPreferredSize().x / 2) + xOffset,
(app.getCamera().getHeight() / 2 + container.getPreferredSize().y / 2) + yOffset,
0
);
}

View File

@@ -15,9 +15,6 @@ public class MdgaApp extends SimpleApplication {
MdgaView view = null;
private MdgaState state = MdgaState.MAIN;
//TODO
private NanoTimer test = new NanoTimer();
public static void main(String[] args) {
AppSettings settings = new AppSettings(true);
settings.setSamples(128);
@@ -44,19 +41,6 @@ public void simpleInitApp() {
@Override
public void simpleUpdate(float tpf) {
acousticHandler.update();
if(test.getTimeInSeconds() < 8) {
return;
}
switch (state) {
case LOBBY:
//enter(MdgaState.GAME);
break;
case GAME:
//enter(MdgaState.CEREMONY);
break;
}
}
public void enter(MdgaState state) {
@@ -72,11 +56,9 @@ public void enter(MdgaState state) {
break;
case LOBBY:
view = new LobbyView(this);
test.reset();
break;
case GAME:
view = new GameView(this);
test.reset();
break;
case CEREMONY:
view = new CeremonyView(this);

View File

@@ -31,7 +31,7 @@ public LobbyView(MdgaApp app) {
dialog = new HorizontalButtonDialog(app);
float buttonWidth = 150;
float spacing = 60;
float spacing = 80;
float startX = -((3 * buttonWidth + 2 * spacing) / 2);
float currentX = startX;
@@ -44,6 +44,8 @@ public LobbyView(MdgaApp app) {
dialog.addButton(button);
}
dialog.setXOffset(-100);
//Button weiterButton = createButton("Weiter", new Vector3f(150, 50, 0), ColorRGBA.Blue, ColorRGBA.Cyan);
//weiterButton.setLocalTranslation(app.getCamera().getWidth() - 200, 100, 0);