began up down arrow keys implementation on the music selection screen
This commit is contained in:
		| @@ -58,7 +58,6 @@ public class RhythmBullet extends Game { | ||||
| 	 | ||||
| 	@Override | ||||
| 	public void create() { | ||||
| 		Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF); | ||||
| 		Gdx.app.setLogLevel(Application.LOG_DEBUG); | ||||
| 		 | ||||
| 		prefs = Gdx.app.getPreferences("PolyJet_Preferences"); | ||||
| @@ -96,6 +95,8 @@ public class RhythmBullet extends Game { | ||||
| 						+ "Pixel density (PPI): " + Gdx.graphics.getDensity()); | ||||
| 		 | ||||
| 		setScreen(new LoadingScreen(this)); | ||||
| 		 | ||||
| 		Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF); | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
|   | ||||
| @@ -5,6 +5,8 @@ import java.util.concurrent.ExecutorService; | ||||
| import java.util.concurrent.Executors; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import java.util.concurrent.locks.ReentrantLock; | ||||
| import java.util.logging.Level; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException; | ||||
| import org.jaudiotagger.audio.exceptions.ReadOnlyFileException; | ||||
|   | ||||
| @@ -19,6 +19,7 @@ import com.badlogic.gdx.graphics.Texture; | ||||
| import com.badlogic.gdx.utils.Disposable; | ||||
|  | ||||
| public class SongInfo implements Disposable { | ||||
| 	 | ||||
| 	private long durationInSeconds; | ||||
| 	private String songName; | ||||
| 	private Texture albumCover; | ||||
|   | ||||
| @@ -5,7 +5,6 @@ import com.badlogic.gdx.files.FileHandle; | ||||
| import com.badlogic.gdx.graphics.Texture; | ||||
| import com.badlogic.gdx.graphics.g2d.TextureRegion; | ||||
| import com.badlogic.gdx.scenes.scene2d.InputEvent; | ||||
| import com.badlogic.gdx.scenes.scene2d.Touchable; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Image; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Label; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Skin; | ||||
| @@ -100,6 +99,7 @@ public class MusicSelectable extends WidgetGroup implements Disposable { | ||||
| 	 | ||||
| 	@Override | ||||
| 	public void layout() { | ||||
| 		table.pack(); | ||||
| 		displayName.setTargetWidth((int) (getWidth() - 300)); | ||||
| 		authorLabel.setTargetWidth((int) (getWidth() - 300)); | ||||
| 		super.layout(); | ||||
| @@ -141,4 +141,9 @@ public class MusicSelectable extends WidgetGroup implements Disposable { | ||||
| 	public boolean isSelected() { | ||||
| 		return selected; | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public float getPrefHeight() { | ||||
| 		return table.getMinHeight(); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -57,6 +57,7 @@ public class MainPage extends Page implements Observer { | ||||
| 			@Override | ||||
| 			public void changed(ChangeEvent event, Actor actor) { | ||||
| 				targetPosition.x = Gdx.graphics.getWidth()*1.5f; | ||||
| 				Gdx.input.setInputProcessor(getStage()); | ||||
| 			} | ||||
| 		}); | ||||
| 		table.add(playButton).width(Gdx.graphics.getWidth()*0.2f); | ||||
|   | ||||
| @@ -5,6 +5,7 @@ import java.util.concurrent.Executors; | ||||
|  | ||||
| import com.badlogic.gdx.Gdx; | ||||
| import com.badlogic.gdx.Preferences; | ||||
| import com.badlogic.gdx.Input.Keys; | ||||
| import com.badlogic.gdx.assets.AssetManager; | ||||
| import com.badlogic.gdx.files.FileHandle; | ||||
| import com.badlogic.gdx.graphics.Pixmap; | ||||
| @@ -14,18 +15,20 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas; | ||||
| import com.badlogic.gdx.math.Vector3; | ||||
| import com.badlogic.gdx.scenes.scene2d.Actor; | ||||
| import com.badlogic.gdx.scenes.scene2d.InputEvent; | ||||
| import com.badlogic.gdx.scenes.scene2d.InputListener; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Image; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Label; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Skin; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.Table; | ||||
| import com.badlogic.gdx.scenes.scene2d.ui.TextButton; | ||||
| import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; | ||||
| import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; | ||||
| import com.badlogic.gdx.utils.Array; | ||||
|  | ||||
| import zero1hd.rhythmbullet.audio.SongInfo; | ||||
| import zero1hd.rhythmbullet.audio.SongList; | ||||
| import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable; | ||||
| import zero1hd.rhythmbullet.graphics.ui.components.ScrollText; | ||||
|  | ||||
| public class MusicSelectionPage extends Page { | ||||
| 	Preferences musicFileAnnotation; | ||||
| @@ -36,6 +39,15 @@ public class MusicSelectionPage extends Page { | ||||
| 	private ScrollPane scrollbar; | ||||
| 	private TextButton back; | ||||
| 	 | ||||
| 	private ScrollText songTitle; | ||||
| 	private Label author; | ||||
| 	private Label songLength; | ||||
| 	private Label previousTop; | ||||
| 	private Table songInfoTable; | ||||
| 	private Image albumCover; | ||||
| 	 | ||||
| 	private MusicSelectable currentlySelected; | ||||
| 	 | ||||
| 	private FileHandle selectedMusic; | ||||
| 	private SongInfo selectedMusicInfo; | ||||
| 	 | ||||
| @@ -47,6 +59,13 @@ public class MusicSelectionPage extends Page { | ||||
| 	private Texture white; | ||||
| 	public MusicSelectionPage(Skin skin, SongList songList, AssetManager assetManager, Vector3 cameraTarget) { | ||||
| 		super("Select music", skin); | ||||
| 		songInfoTable = new Table(); | ||||
| 		songTitle = new ScrollText("", null, skin, false, false); | ||||
| 		author = new Label("", skin, "sub-font", skin.getColor("default")); | ||||
| 		songLength = new Label(null, skin, "sub-font", skin.getColor("default")); | ||||
| 		previousTop = new Label(null, skin, "sub-font", skin.getColor("default")); | ||||
| 		albumCover = new Image(assetManager.get("defaultCover.png", Texture.class)); | ||||
| 		 | ||||
| 		setTextureBackground(assetManager.get("gradients.atlas", TextureAtlas.class).findRegion("red-round")); | ||||
| 		this.skin = skin; | ||||
| 		this.songList = songList; | ||||
| @@ -89,6 +108,32 @@ public class MusicSelectionPage extends Page { | ||||
| 		horSplitBar.setWidth(vertSplitBar.getX()); | ||||
| 		horSplitBar.setPosition(0, getHeightBelowTitle()); | ||||
| 		addActor(horSplitBar); | ||||
| 		 | ||||
| 		addListener(new InputListener() { | ||||
| 			@Override | ||||
| 			public boolean keyDown(InputEvent event, int keycode) { | ||||
| 				Gdx.app.debug("MusicSelectionPage", "Scrolling"); | ||||
| 				int index; | ||||
| 				if (keycode == Keys.DOWN) { | ||||
| 					if ((index = (songTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) { | ||||
| 						index = songTable.getChildren().size; | ||||
| 					} | ||||
| 					deselectAll(); | ||||
| 					//ez broken casting. | ||||
| 					((MusicSelectable)songTable.getChildren().get(index)).select(); | ||||
| 					scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); | ||||
| 				} | ||||
| 				if (keycode == Keys.UP) { | ||||
| 					if ((index = (songTable.getChildren().indexOf(currentlySelected, true) + 1)) < songTable.getChildren().size -1) { | ||||
| 						index = 0; | ||||
| 					} | ||||
| 					deselectAll(); | ||||
| 					((MusicSelectable)songTable.getChildren().get(index)).select(); | ||||
| 					scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight()); | ||||
| 				} | ||||
| 				return super.keyDown(event, keycode); | ||||
| 			} | ||||
| 		}); | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| @@ -118,7 +163,7 @@ public class MusicSelectionPage extends Page { | ||||
| 			MusicSelectable selectable = new MusicSelectable(songList.getSongFileHandleFromIndex(i), musicFileAnnotation, skin, assets.get("defaultCover.png", Texture.class), this); | ||||
| 			selectables.add(selectable); | ||||
| 			 | ||||
| 			songTable.add(selectable).expandX().fillX().height((getHeight() >= 2160 ? 300f : 200f)); | ||||
| 			songTable.add(selectable).expandX().fillX(); | ||||
| 			songTable.row(); | ||||
| 		} | ||||
| 		 | ||||
| @@ -147,4 +192,9 @@ public class MusicSelectionPage extends Page { | ||||
| 			selectables.get(i).deselect(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public void setCurrentlySelected(MusicSelectable currentlySelected) { | ||||
| 		this.currentlySelected = currentlySelected; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user