From 02593f5d7ef9755a6a41d536363a0fe9200330be Mon Sep 17 00:00:00 2001 From: TheCodeBoat Date: Thu, 19 Dec 2013 12:40:20 +0100 Subject: [PATCH] added remaining time to gamegui --- .../shootingstars/data/AudioDataManager.java | 4 ++ .../org/wyrez/shootingstars/gui/GameGUI.java | 28 +++++++++-- .../GuiMusicRemainingTimeControl.java | 49 +++++++++++++++++++ .../wyrez/shootingstars/states/GameState.java | 6 +-- 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 ShootingStars/src/org/wyrez/shootingstars/gui/controls/GuiMusicRemainingTimeControl.java diff --git a/ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java b/ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java index b790b6c..9c1bfba 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java +++ b/ShootingStars/src/org/wyrez/shootingstars/data/AudioDataManager.java @@ -243,6 +243,10 @@ public class AudioDataManager { lastSpawnDataPollIndex = index; return data; } + + public float getRemainingTime() { + return (player.getTime() - player.getLength()) * -1; + } public void cleanup() { speedData = null; diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java index b4e23d1..b56442c 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java @@ -22,7 +22,9 @@ import com.jme3.input.event.MouseButtonEvent; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector2f; import com.jme3.scene.Spatial; +import org.wyrez.shootingstars.data.AudioDataManager; import org.wyrez.shootingstars.gui.controls.ButtonBase; +import org.wyrez.shootingstars.gui.controls.GuiMusicRemainingTimeControl; import org.wyrez.shootingstars.gui.controls.GuiPlayerPointsControl; import org.wyrez.shootingstars.gui.listener.GameListener; import org.wyrez.shootingstars.helper.ScreenHelper; @@ -44,16 +46,17 @@ public class GameGUI extends Panel implements Gui{ private Button btnResume; private Button btnMenu; private Indicator indOverheat; - private AssetManager assetManager; private Spatial player; private Label lblPoints; + private Label lblRemainingTime; private ScreenHelper screenHelper; + private AudioDataManager audioDataManager; - public GameGUI(Screen screen, GameListener listener, AssetManager assetManager, ScreenHelper screenHelper) { + public GameGUI(Screen screen, GameListener listener, ScreenHelper screenHelper, AudioDataManager audioDataManager) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; - this.assetManager = assetManager; this.screenHelper = screenHelper; + this.audioDataManager = audioDataManager; this.setIgnoreMouse(true); this.setIsVisible(false); create(); @@ -120,17 +123,23 @@ public class GameGUI extends Panel implements Gui{ lblPoints = new Label(screen, new Vector2f(startPointPointsx, startPointPointsy), new Vector2f(screenHelper.calcX(275f), screenHelper.calcY(180f))); lblPoints.setFontColor(new ColorRGBA(1f, 0f, 0f, 1f)); lblPoints.setFontSize(screenHelper.calcX(30f)); + + lblRemainingTime = new Label(screen, new Vector2f(startPointPointsx, startPointPointsy), new Vector2f(screenHelper.calcX(275f), screenHelper.calcY(240f))); + lblRemainingTime.setFontColor(new ColorRGBA(1f, 0f, 0f, 1f)); + lblRemainingTime.setFontSize(screenHelper.calcX(30f)); this.addChild(btnStart); this.addChild(btnResume); this.addChild(btnMenu); this.addChild(indOverheat); this.addChild(lblPoints); + this.addChild(lblRemainingTime); btnResume.hide(); btnMenu.hide(); indOverheat.hide(); lblPoints.hide(); + lblRemainingTime.hide(); } public void setStart() { @@ -139,6 +148,7 @@ public class GameGUI extends Panel implements Gui{ btnMenu.hide(); indOverheat.show(); lblPoints.show(); + lblRemainingTime.show(); } public void setWait() { @@ -147,6 +157,7 @@ public class GameGUI extends Panel implements Gui{ btnMenu.hide(); indOverheat.hide(); lblPoints.hide(); + lblRemainingTime.hide(); } public void showMenu() { @@ -155,6 +166,7 @@ public class GameGUI extends Panel implements Gui{ btnMenu.show(); indOverheat.hide(); lblPoints.hide(); + lblRemainingTime.hide(); } public void resumeGame() { @@ -163,6 +175,7 @@ public class GameGUI extends Panel implements Gui{ btnMenu.hide(); indOverheat.show(); lblPoints.show(); + lblRemainingTime.show(); } public void attach() { @@ -178,12 +191,19 @@ public class GameGUI extends Panel implements Gui{ } public void setPoints(String points) { - lblPoints.setText("Points: " + points); + lblPoints.setText("Score: " + points); + } + + public void setRemainingTime(float remainingTime) { + int seconds = (int)remainingTime / 1000; + int min = (int)(seconds / 60); + lblRemainingTime.setText("Time: " + min + ":" + String.format("%02d", (seconds - min * 60))); } public void setPlayer(Spatial player) { this.player = player; this.addControl(new GuiPlayerPointsControl(player, this)); + this.addControl(new GuiMusicRemainingTimeControl(audioDataManager, this)); } public void refresh() { diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/controls/GuiMusicRemainingTimeControl.java b/ShootingStars/src/org/wyrez/shootingstars/gui/controls/GuiMusicRemainingTimeControl.java new file mode 100644 index 0000000..89ecd60 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/controls/GuiMusicRemainingTimeControl.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013 Snowsun and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.wyrez.shootingstars.gui.controls; + +import com.jme3.scene.Spatial; +import org.wyrez.shootingstars.controls.BaseControl; +import org.wyrez.shootingstars.data.AudioDataManager; +import org.wyrez.shootingstars.gui.GameGUI; +import com.jme3.scene.control.Control; + +/** + * + * @author Chris + */ +public class GuiMusicRemainingTimeControl extends BaseControl { + + private AudioDataManager audioDataManager; + private GameGUI gui; + + public GuiMusicRemainingTimeControl(AudioDataManager audioDataManager, GameGUI gui) { + this.audioDataManager = audioDataManager; + this.gui = gui; + } + + @Override + protected void controlUpdate(float tpf) { + gui.setRemainingTime(audioDataManager.getRemainingTime()); + } + + public Control cloneForSpatial(Spatial spatial) { + GuiMusicRemainingTimeControl control = new GuiMusicRemainingTimeControl(audioDataManager, gui); + spatial.addControl(control); + return control; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 5b36af1..d940848 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -83,13 +83,13 @@ public class GameState extends AbstractAppState implements GameListener, ActionL GameSettings settings, ScreenHelper screenHelper, HighscoreManager highscoreManager) { this.rootNode = rootNode; - this.gui = new GameGUI(screen, this, assetManager, screenHelper); + this.audioDataManager = audioDataManager; + this.gui = new GameGUI(screen, this, screenHelper,audioDataManager); this.stateManager = stateManager; inputManager.addListener(this, new String[]{"ESC"}); this.inputManager = inputManager; - this.camera = camera; - this.audioDataManager = audioDataManager; + this.camera = camera; this.assetManager = assetManager; this.viewPort = viewPort; this.optionSettings = optionSettings;