added remaining time to gamegui

This commit is contained in:
TheCodeBoat 2013-12-19 12:40:20 +01:00
parent e97736bdd5
commit 02593f5d7e
4 changed files with 80 additions and 7 deletions

View File

@ -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;

View File

@ -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() {

View File

@ -0,0 +1,49 @@
/*
* Copyright (C) 2013 Snowsun <http://wyrez.org> 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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;