Added a progress bar class for future use

This commit is contained in:
Ziver Koc 2007-04-05 13:30:18 +00:00
parent c2a579788a
commit 318f92bc93
2 changed files with 238 additions and 37 deletions

View file

@ -4,6 +4,7 @@ import java.util.LinkedList;
import java.util.Queue;
import ei.engine.LWJGLGameWindow;
import ei.engine.effects.ProgressBar;
import ei.engine.math.Vector3f;
import ei.engine.scene.Sprite;
import ei.engine.sound.SoundLoader;
@ -23,12 +24,8 @@ public class LoadingState extends GameState{
private Queue<String> loadSounds;
// The name of the next state to activate after loading
private String nextState;
// Temp things for the loadingbar
private int status;
private Sprite bar;
private Sprite loadBar;
private Sprite background;
private ProgressBar progress;
/**
* Creates a loadingstate
@ -37,21 +34,14 @@ public class LoadingState extends GameState{
public LoadingState(String name,String nextState) {
super(name);
this.nextState = nextState;
status = 0;
loadTextures = new LinkedList<String>();
loadSounds = new LinkedList<String>();
bar = new Sprite("Bar","data/loadbar_front.png");
bar.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2),
(LWJGLGameWindow.getHeight()/2),0.0f));
loadBar = new Sprite("LoadingBar","data/loadbar.png");
loadBar.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2)-loadBar.getWidth(),
(LWJGLGameWindow.getHeight()/2)+3,0.0f));
background = new Sprite("Bar","data/loadbar_back.png");
background.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2),
(LWJGLGameWindow.getHeight()/2),0.0f));
progress = new ProgressBar("Loading");
progress.centerToScreen();
progress.setBarTexture(new Sprite("ProgressBar","data/loadbar_front.png"));
progress.setProgressTexture(new Sprite("Progress","data/loadbar.png"));
progress.setBackgroundTexture(new Sprite("progressBackground","data/loadbar_back.png"));
}
/**
@ -60,6 +50,7 @@ public class LoadingState extends GameState{
*/
public void addTexture(String url){
loadTextures.add(url);
progress.setMax(loadTextures.size()+loadSounds.size());
}
/**
@ -68,6 +59,7 @@ public class LoadingState extends GameState{
*/
public void addSound(String url){
loadSounds.add(url);
progress.setMax(loadTextures.size()+loadSounds.size());
}
/**
@ -76,39 +68,28 @@ public class LoadingState extends GameState{
public void update() {
if(!loadTextures.isEmpty()){
TextureLoader.getTextureLoaderInstance().getTexture(loadTextures.poll());
status++;
progress.setValue(progress.getValue()+1);
}
else if(!loadSounds.isEmpty()){
SoundLoader.getInstnace().loadSound(loadSounds.poll());
status++;
progress.setValue(progress.getValue()+1);
}
else{
status++;
if(status >= 100){
progress.setValue(progress.getValue()+1);
if(progress.getProcent() >= 100){
//deactivate this state and activate the next one
GameStateManager.getInstance().removeState(this);
GameStateManager.getInstance().setActive(nextState);
}
}
}
background.update();
loadBar.update();
bar.update();
progress.update();
}
/**
* Render the load bar
*/
public void render() {
// Calculate the procentage
float procent = (float)status/100;//(loadTextures.size()+loadSounds.size());
loadBar.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2)-loadBar.getWidth()+(loadBar.getWidth()*procent),
(LWJGLGameWindow.getHeight()/2)+6,0.0f));
//render the bar
background.render();
loadBar.render();
bar.render();
progress.render();
}
}