Difficulty Selection + press1 for gamestate in submenu
This commit is contained in:
+21
-11
@@ -1,13 +1,13 @@
|
||||
package model;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import main.Window;
|
||||
import audio.AudioPlayer;
|
||||
import audio.Song;
|
||||
import audio.SongInstance;
|
||||
import audio.io.DirScanner;
|
||||
|
||||
public class SongHandler {
|
||||
@@ -15,6 +15,7 @@ public class SongHandler {
|
||||
private List<Song> songs;
|
||||
|
||||
private Song currentSong;
|
||||
private SongInstance currentSongInstance;
|
||||
private int currentIndex;
|
||||
|
||||
private File dir;
|
||||
@@ -26,17 +27,18 @@ public class SongHandler {
|
||||
songs = new ArrayList<Song>();
|
||||
|
||||
currentSong = null;
|
||||
currentIndex = 0;
|
||||
currentSongInstance = null;
|
||||
currentIndex = 1;
|
||||
|
||||
p = new AudioPlayer();
|
||||
|
||||
if(Window.ON_RASP)
|
||||
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs");
|
||||
dir = new File(System.getProperty( "user.home" ) + "/ColorStrike/Songs/");
|
||||
else
|
||||
dir = new File(System.getProperty( "user.home" ) + "/Documents/songs");
|
||||
dir = new File(System.getProperty( "user.home" ) + "/Documents/songs/");
|
||||
|
||||
songs = DirScanner.scanDirectories(dir);
|
||||
|
||||
System.out.println(songs.size());
|
||||
updatePlayer();
|
||||
}
|
||||
|
||||
@@ -58,20 +60,24 @@ public class SongHandler {
|
||||
updatePlayer();
|
||||
}
|
||||
}
|
||||
public void set(SongInstance si)
|
||||
{
|
||||
currentSongInstance = si;
|
||||
}
|
||||
|
||||
|
||||
private void updatePlayer()
|
||||
{
|
||||
if(currentIndex < 0)
|
||||
currentIndex = songs.size() + currentIndex;
|
||||
|
||||
currentIndex%=songs.size();
|
||||
if(currentIndex >= songs.size())
|
||||
currentIndex = currentIndex - songs.size();
|
||||
|
||||
currentSong = songs.get(currentIndex);
|
||||
currentSongInstance = currentSong.getSongs().get(0);
|
||||
|
||||
p.stop();
|
||||
p.setClip(currentSong);
|
||||
|
||||
System.out.println(currentSong.getSongs().size());
|
||||
}
|
||||
|
||||
public long getProgress()
|
||||
@@ -87,6 +93,10 @@ public class SongHandler {
|
||||
{
|
||||
return currentSong;
|
||||
}
|
||||
public SongInstance getCurrentSongInstance()
|
||||
{
|
||||
return currentSongInstance;
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
@@ -106,7 +116,7 @@ public class SongHandler {
|
||||
{
|
||||
if(b)
|
||||
{
|
||||
p.play((int)currentSong.getSampleStart()*10000);
|
||||
p.play((int)currentSong.getSampleStart()*10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +129,4 @@ public class SongHandler {
|
||||
{
|
||||
p.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,8 @@ public class MenuState extends GameState {
|
||||
private int animationcounter;
|
||||
private boolean subscreen, startanimation;
|
||||
|
||||
int z;
|
||||
|
||||
int yPosDiffButton = 900;
|
||||
int yPosDiffButton = 400;
|
||||
private int difSelect=0;
|
||||
|
||||
public MenuState(GameStateManager gsm, SongHandler sh) {
|
||||
super(gsm, sh);
|
||||
@@ -72,7 +71,6 @@ public class MenuState extends GameState {
|
||||
if(selected != oldselected){
|
||||
for(int i = 0; i < buttons.size(); i++){
|
||||
buttons.get(i).setSong(selectedToSong(selected+(i-2)));
|
||||
z=i;
|
||||
}
|
||||
oldselected = selected;
|
||||
|
||||
@@ -85,6 +83,7 @@ public class MenuState extends GameState {
|
||||
buttons2.add(new DifficultyButton(yPosDiffButton-instanceNr,si.getDifficulty(), GameModel.colors[i-1]));
|
||||
instanceNr += 100;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +155,9 @@ public class MenuState extends GameState {
|
||||
b.draw(g2);
|
||||
}
|
||||
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.fillRect(865, 425 - difSelect*100, 25, 25);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -167,7 +169,10 @@ public class MenuState extends GameState {
|
||||
if(subscreen){ //Screen for Song details
|
||||
if(e.getButton().getButtonID() == 2){
|
||||
subscreen = false;
|
||||
}
|
||||
}
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
gsm.next();
|
||||
}
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getButton().getButtonID() == 1){
|
||||
subscreen = true;
|
||||
@@ -183,8 +188,26 @@ public class MenuState extends GameState {
|
||||
@Override
|
||||
public void onJoystickMoved(JoystickEvent e) {
|
||||
|
||||
if(subscreen){ //Screen for Song details
|
||||
if(subscreen){
|
||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||
difSelect--;
|
||||
if(difSelect < 0){
|
||||
difSelect += buttons2.size();
|
||||
}
|
||||
// System.out.println(difSelect);
|
||||
}else if(e.getJoystick().getPos() == Joystick.Position.UP){
|
||||
difSelect++;
|
||||
if(difSelect > buttons2.size()-1){
|
||||
difSelect = 0;
|
||||
}
|
||||
|
||||
// System.out.println(difSelect);
|
||||
}
|
||||
sh.set(sh.getCurrentSong().getSongs().get(difSelect));
|
||||
|
||||
|
||||
|
||||
|
||||
}else{ //Screen for selecting song
|
||||
if(e.getJoystick().getPos() == Joystick.Position.DOWN){
|
||||
selected++;
|
||||
|
||||
Reference in New Issue
Block a user