better control system; album art loading more efficient;

This commit is contained in:
2018-08-22 19:35:39 -05:00
parent d7008796f4
commit dc4db57281
17 changed files with 358 additions and 594 deletions

View File

@@ -0,0 +1,45 @@
package zero1hd.rhythmbullet.desktop;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.Input.Keys;
public enum Controls {
UP("Forward", Keys.UP), DOWN("Backwards", Keys.DOWN), LEFT("Left", Keys.LEFT), RIGHT("Right", Keys.RIGHT), SHOOT("Shoot", Keys.SPACE), ACCELERATE("Boost", Keys.SHIFT_LEFT);
private int keycode;
private final String friendly;
private final int defectKey;
private Controls(String friendly, int defectKey) {
this.friendly = friendly;
this.defectKey = defectKey;
this.keycode = defectKey;
}
public Controls setKeycode(int keycode) {
Controls[] controls = Controls.values();
for (int i = 0; i < controls.length; i++) {
if (controls[i] != this && controls[i].getKeycode() == keycode) {
return controls[i];
}
}
this.keycode = keycode;
return null;
}
public int getKeycode() {
return keycode;
}
public void loadKeyFromPreferences(Preferences preferences) {
setKeycode(preferences.getInteger(name(), defectKey));
}
public void saveKeyToPreferences(Preferences preferences) {
preferences.putInteger(name(), keycode);
}
@Override
public String toString() {
return friendly;
}
}

View File

@@ -1,6 +1,7 @@
package zero1hd.rhythmbullet.desktop;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
@@ -94,13 +95,6 @@ public class DesktopAssetPack implements AssetPack {
windowTextButton.font = skin.getFont("window-font");
skin.add("window", windowTextButton);
TextButtonStyle textButtonLeft = new TextButtonStyle();
textButtonLeft.up = skin.getDrawable("left-button");
textButtonLeft.down = skin.getDrawable("left-button-down");
textButtonLeft.font = skin.getFont("default-font");
textButtonLeft.fontColor = skin.getColor("default");
skin.add("left", textButtonLeft);
SliderStyle defaultSlider = new SliderStyle(skin.getDrawable("default-slider"), skin.getDrawable("default-slider-knob"));
skin.add("default-horizontal", defaultSlider);
@@ -172,10 +166,13 @@ public class DesktopAssetPack implements AssetPack {
shuffleButtonStyle.checkboxOn = skin.getDrawable("shuffle-down");
skin.add("shuffle-button", shuffleButtonStyle);
ButtonStyle musicSelectable = new ButtonStyle();
musicSelectable.checked = skin.getDrawable("holo-pane-down");
musicSelectable.up = skin.getDrawable("holo-pane");
skin.add("music-selectable", musicSelectable);
ButtonStyle selectableButton = new ButtonStyle();
selectableButton.checked = skin.getDrawable("holo-pane-down");
selectableButton.up = skin.getDrawable("holo-pane");
skin.add("selectable-button", selectableButton);
ButtonStyle selectableCleanButton = new ButtonStyle();
skin.add("selectable-clean-button", selectableCleanButton);
}
@Override
@@ -220,6 +217,14 @@ public class DesktopAssetPack implements AssetPack {
@Override
public void complete(AssetManager assetManager) {
assetManager.get("standard_thrust.p", ParticleEffect.class).flipY();
Preferences controlsPrefs = Gdx.app.getPreferences("RhythmBullet_Controls");
Controls.UP.loadKeyFromPreferences(controlsPrefs);
Controls.DOWN.loadKeyFromPreferences(controlsPrefs);
Controls.LEFT.loadKeyFromPreferences(controlsPrefs);
Controls.RIGHT.loadKeyFromPreferences(controlsPrefs);
Controls.SHOOT.loadKeyFromPreferences(controlsPrefs);
Controls.ACCELERATE.loadKeyFromPreferences(controlsPrefs);
}
@Override

View File

@@ -1,16 +1,7 @@
package zero1hd.rhythmbullet.desktop;
import java.awt.Canvas;
import java.awt.Color;
import javax.swing.JFrame;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.AWTGLCanvas;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl.LwjglGraphics;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.screens.SplashScreen;

View File

@@ -1,123 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.components;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color;
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.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener;
import com.badlogic.gdx.utils.Align;
import zero1hd.rhythmbullet.controls.KeyMap;
public class ControlOptions extends Table {
private KeyBindButton selected;
public ControlOptions(Skin skin, KeyMap keyMap) {
super(skin);
align(Align.center);
ClickListener selectedListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
getStage().setKeyboardFocus(event.getTarget());
event.getTarget().setColor(Color.ORANGE);
selected = (KeyBindButton) event.getTarget();
super.clicked(event, x, y);
}
};
InputListener keyPressedListener = new InputListener() {
@Override
public boolean keyUp(InputEvent event, int keycode) {
getStage().setKeyboardFocus(null);
Gdx.app.debug("KeySetter", "input keycode received: " + keycode);
if (keycode != Keys.ESCAPE) {
Gdx.app.debug("keySetter", "input has been set to: " + Keys.toString(keycode));
if (selected.setKey(keycode)) {
keyMap.updateKeys();
selected.addAction(Actions.sequence(Actions.color(Color.GREEN, 0.2f), Actions.color(Color.WHITE, 0.2f)));
} else {
selected.addAction(Actions.sequence(Actions.color(Color.RED, 0.2f), Actions.delay(0.1f), Actions.color(Color.WHITE, 0.2f)));
}
}
return super.keyUp(event, keycode);
}
};
FocusListener deselected = new FocusListener() {
@Override
public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
if (!focused) {
unselect();
}
super.keyboardFocusChanged(event, actor, focused);
}
};
Label forwardKeyLabel = new Label("Forward: ",skin);
forwardKeyLabel.setName(KeyMap.UP);
add(forwardKeyLabel).left();
KeyBindButton forwardKeySetter = new KeyBindButton(keyMap, KeyMap.UP, selectedListener, keyPressedListener, deselected);
add(forwardKeySetter).spaceRight(45f);
Label shootKeyLabel = new Label("Shoot: ", skin);
shootKeyLabel.setName(KeyMap.SHOOT);
add(shootKeyLabel).left();
KeyBindButton shootKeySetter = new KeyBindButton(keyMap, KeyMap.SHOOT, selectedListener, keyPressedListener, deselected);
add(shootKeySetter);
row();
Label backwardKeyLabel = new Label("Backward: ", skin);
backwardKeyLabel.setName(KeyMap.DOWN);
add(backwardKeyLabel).left();
KeyBindButton backwardKeySetter = new KeyBindButton(keyMap, KeyMap.DOWN, selectedListener, keyPressedListener, deselected);
add(backwardKeySetter).spaceRight(45f);
Label sector1TPKeyLabel = new Label("Left Teleport", skin);
sector1TPKeyLabel.setName(KeyMap.FIRSTTHIRDTELEPORT);
add(sector1TPKeyLabel).left();
KeyBindButton Sector1TPKeySetter = new KeyBindButton(keyMap, KeyMap.FIRSTTHIRDTELEPORT, selectedListener, keyPressedListener, deselected);
Sector1TPKeySetter.addListener(selectedListener);
add(Sector1TPKeySetter);
row();
Label leftKeyLabel = new Label("Left: ", skin);
leftKeyLabel.setName(KeyMap.LEFT);
add(leftKeyLabel).left();
KeyBindButton leftKeySetter = new KeyBindButton(keyMap, KeyMap.LEFT, selectedListener, keyPressedListener, deselected);
add(leftKeySetter).spaceRight(45f);
Label sector2TPKeyLabel = new Label("Middle Teleport: ", skin);
sector2TPKeyLabel.setName(KeyMap.SECONDTHIRDTELEPORT);
add(sector2TPKeyLabel).left();
KeyBindButton sector2TPKeySetter = new KeyBindButton(keyMap, KeyMap.SECONDTHIRDTELEPORT, selectedListener, keyPressedListener, deselected);
sector2TPKeySetter.addListener(selectedListener);
add(sector2TPKeySetter);
row();
Label rightKeyLabel = new Label("Right: ", skin);
rightKeyLabel.setName(KeyMap.RIGHT);
add(rightKeyLabel).left();
KeyBindButton rightKeySetter = new KeyBindButton(keyMap, KeyMap.RIGHT, selectedListener, keyPressedListener, deselected);
add(rightKeySetter).spaceRight(45f);
Label sector3TPKeyLabel = new Label("Right Teleport: ", skin);
sector3TPKeyLabel.setName(KeyMap.THIRDTHIRDTELEPORT);
add(sector3TPKeyLabel).left();
KeyBindButton sector3TPKeySetter = new KeyBindButton(keyMap, KeyMap.THIRDTHIRDTELEPORT, selectedListener, keyPressedListener, deselected);
sector3TPKeySetter.addListener(selectedListener);
add(sector3TPKeySetter);
setFillParent(true);
}
private void unselect() {
selected.setColor(Color.WHITE);
}
}

View File

@@ -1,71 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.components;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup;
import zero1hd.rhythmbullet.entity.ally.PolyjetEntity;
public class HealthBar extends WidgetGroup {
Image empty;
Image filler;
float health;
float maxHealth;
PolyjetEntity pje;
public HealthBar(Skin skin, float maxHealth) {
super();
filler = new Image(skin.getPatch("bar-fill"));
addActor(filler);
empty = new Image(skin.getPatch("bar-empty"));
addActor(empty);
this.maxHealth = maxHealth;
}
public void setPolyjetEntity(PolyjetEntity pje) {
this.pje = pje;
}
public void setHealth(float health) {
this.health = health;
filler.addAction(Actions.sizeTo(getWidth(), MathUtils.round((health/maxHealth)*getHeight()), 0.1f));;
}
@Override
public void act(float delta) {
if (pje != null) {
health = pje.health;
}
super.act(delta);
}
@Override
public void setSize(float width, float height) {
empty.setSize(width, height);
filler.setSize(width, height);
super.setSize(width, height);
}
@Override
public void setWidth(float width) {
empty.setWidth(width);
filler.setWidth(width);
super.setWidth(width);
}
@Override
public void setHeight(float height) {
empty.setHeight(height);
super.setHeight(height);
}
public float getMaxHealth() {
return maxHealth;
}
}

View File

@@ -1,45 +0,0 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.components;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener;
import zero1hd.rhythmbullet.controls.KeyMap;
public class KeyBindButton extends Actor {
private TextureRegion keyIcon;
private KeyMap keyMap;
private String controlKey;
public KeyBindButton(final KeyMap keyMap, final String control, ClickListener selectionListener, InputListener keyPressListener, FocusListener deselectedListener) {
this.keyMap = keyMap;
this.keyIcon = keyMap.getIcon(keyMap.stringToID(control));
this.controlKey = control;
setSize(keyIcon.getRegionWidth(), keyIcon.getRegionHeight());
addListener(selectionListener);
addListener(keyPressListener);
addListener(deselectedListener);
}
public boolean setKey(int keycode) {
if (keyMap.getIcon(keycode) != null) {
keyMap.getKeys().putInteger(controlKey, keycode);
keyIcon = keyMap.getIcon(keycode);
return true;
} else {
return false;
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.setColor(getColor());
batch.draw(keyIcon, getX(), getY(), getWidth(), getHeight());
super.draw(batch, parentAlpha);
}
}

View File

@@ -13,13 +13,11 @@ import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.audio.visualizer.CircularVisualizer;
import zero1hd.rhythmbullet.desktop.audio.PCMObtainer;
import zero1hd.rhythmbullet.game.GameController;
public class GameScreen extends ScreenAdapter {
private AssetManager assets;
private SpriteBatch batch;
private ExtendViewport viewport;
private GameController gc;
private CircularVisualizer circleVisualizer;
public GameScreen(AssetManager assets, Preferences prefs, MusicController musicController) {

View File

@@ -1,30 +1,224 @@
package zero1hd.rhythmbullet.desktop.screens.main;
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.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
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.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
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.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.controls.KeyMap;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.ControlOptions;
import zero1hd.rhythmbullet.desktop.Controls;
import zero1hd.rhythmbullet.graphics.ui.Page;
public class KeybindPage extends Page {
private ControlOptions controlTable;
private KeyMap keyMap;
private TextButton backButton;
private ButtonGroup<KeyChangeButton> buttonOptions;
private VerticalGroup group;
private ScrollPane scrollPane;
private Skin skin;
TextureAtlas keyTextures;
private Preferences keyBindPrefs;
private InputListener inputListener;
private ChangeListener checkedListener;
public KeybindPage(AssetManager assetManager, Skin skin, ChangeListener backButtonListener) {
super(-1, -1);
keyMap = new KeyMap(assetManager);
controlTable = new ControlOptions(skin, keyMap);
addActor(controlTable);
backButton = new TextButton("Back", skin);
backButton.setPosition(10, getHeight() - 10 - backButton.getHeight());
backButton.setWidth(backButton.getWidth() + 20);
setTouchable(Touchable.enabled);
this.skin = skin;
keyTextures = assetManager.get("keyboard.atlas", TextureAtlas.class);
this.keyBindPrefs = Gdx.app.getPreferences("PolyJet_Controls");
TextButton backButton = new TextButton("Back", skin);
backButton.setWidth(backButton.getWidth()+20f);
backButton.setPosition(getWidth()-backButton.getWidth()-15f, getHeight() - backButton.getHeight() - 15f);
backButton.addListener(backButtonListener);
addActor(backButton);
inputListener = new InputListener() {
@Override
public boolean keyUp(InputEvent event, int keycode) {
KeyChangeButton button = buttonOptions.getChecked();
if (button != null) {
if (keycode != Keys.ESCAPE) {
button.attemptSetKeycode(keycode);
}
getStage().setKeyboardFocus(null);
}
return super.keyUp(event, keycode);
}
};
checkedListener = new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
KeyChangeButton button = (KeyChangeButton) actor;
if (button.isChecked()) {
button.ready();
} else {
button.done();
}
}
};
buttonOptions = new ButtonGroup<>();
buttonOptions.setMinCheckCount(0);
buttonOptions.setMaxCheckCount(1);
group = new VerticalGroup();
group.setTouchable(Touchable.childrenOnly);
group.space(15f);
Controls[] controls = Controls.values();
for (int i = 0; i < controls.length; i++) {
KeyChangeButton button = new KeyChangeButton(controls[i]);
buttonOptions.add(button);
group.addActor(button);
}
scrollPane = new ScrollPane(group);
scrollPane.setHeight(Math.min(getHeight(), group.getPrefHeight()));
scrollPane.setWidth(group.getPrefWidth());
scrollPane.setPosition((getWidth()-scrollPane.getWidth())/2f, (getHeight()-scrollPane.getHeight())/2f);
scrollPane.setTouchable(Touchable.childrenOnly);
addActor(scrollPane);
addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (hit(x, y, true) == event.getListenerActor()) {
simpleDebug("unchecking selected key change buttons.");
buttonOptions.uncheckAll();
}
super.clicked(event, x, y);
}
});
}
@Override
public void setCameraPositionToPage(Vector3 cameraPosition) {
getStage().setScrollFocus(scrollPane);
super.setCameraPositionToPage(cameraPosition);
}
@Override
public void dispose() {
save();
super.dispose();
}
public void save() {
keyBindPrefs.flush();
}
public class KeyChangeButton extends Button {
private Image keyImage;
private Label nameLabel;
private Controls control;
private boolean error;
public KeyChangeButton(Controls control) {
super(skin, "selectable-clean-button");
this.control = control;
nameLabel = new Label(control.toString(), skin);
keyImage = new Image(getIcon(control.getKeycode()));
add(nameLabel).expandX().left().spaceRight(20f);
add(keyImage).expandX().right();
addListener(inputListener);
addListener(checkedListener);
}
public void attemptSetKeycode(int keycode) {
simpleDebug("Attempting to set keycode to " + keycode);
TextureRegion textureRegion = getIcon(keycode);
if (textureRegion != null) {
setKeycode(keycode, textureRegion);
error = false;
} else {
error = true;
}
setChecked(false);
}
public void setKeycode(int keycode, TextureRegion texture) {
Controls conflict = control.setKeycode(keycode);
if (conflict != null) {
Array<KeyChangeButton> buttons = buttonOptions.getButtons();
for (int i = 0; i < buttons.size; i++) {
System.out.println(buttons.get(i).getControl());
if (buttons.get(i).getControl() == conflict) {
KeyChangeButton b = buttons.get(i);
scrollPane.scrollTo(b.getX(), b.getY(), b.getWidth(), b.getHeight());
b.done(true);
return;
}
}
}
TextureRegion textureRegion = getIcon(keycode);
if (textureRegion != null) {
keyImage.setDrawable(new TextureRegionDrawable(texture));
control.saveKeyToPreferences(keyBindPrefs);
}
}
public void ready() {
getStage().setKeyboardFocus(this);
keyImage.setColor(Color.ORANGE);
}
public void done() {
done(error);
}
public void done(boolean error) {
if (error) {
keyImage.addAction(Actions.repeat(3, Actions.sequence(Actions.color(Color.RED, 0.2f), Actions.color(Color.WHITE, 0.1f))));
} else {
keyImage.addAction(Actions.color(Color.WHITE, 0.2f));
}
}
public Controls getControl() {
return control;
}
}
public TextureRegion getIcon(int keycode) {
switch (keycode) {
case Keys.ALT_LEFT:
case Keys.ALT_RIGHT:
return keyTextures.findRegion("Keyboard_Black_Alt");
case Keys.SHIFT_LEFT:
case Keys.SHIFT_RIGHT:
return keyTextures.findRegion("Keyboard_Black_Shift");
case Keys.LEFT_BRACKET:
return keyTextures.findRegion("Keyboard_Black_Bracket_Left");
case Keys.RIGHT_BRACKET:
return keyTextures.findRegion("Keyboard_Black_Bracket_Right");
case Keys.SEMICOLON:
return keyTextures.findRegion("Keyboard_Black_Semicolon");
case Keys.SLASH:
return keyTextures.findRegion("Keyboard_Black_Slash");
case Keys.NUM:
return keyTextures.findRegion("Keyboard_Black_Num_Lock");
case Keys.ESCAPE:
return null;
default:
return keyTextures.findRegion("Keyboard_Black_" + Keys.toString(keycode).replace(' ', '_'));
}
}
}

View File

@@ -1,7 +1,6 @@
package zero1hd.rhythmbullet.desktop.screens.main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
@@ -9,11 +8,8 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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.Stage;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet;
@@ -139,28 +135,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
analysisPage = new AnalysisPage(rhythmBullet.getSkin(), listeners.returnToMainPageListener, listeners.confirmedSongListener);
stage.addActor(analysisPage);
stage.addListener(new InputListener() {
@Override
public boolean keyUp(InputEvent event, int keycode) {
if (keycode == Keys.ESCAPE) {
stage.unfocusAll();
}
return super.keyUp(event, keycode);
}
});
stage.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (stage.hit(x, y, true) == null) {
stage.unfocusAll();
}
super.clicked(event, x, y);
}
});
musicController.getMusicList().asyncSearch(false);
resizing = false;
}
@@ -221,7 +195,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
@Override
public void changed(ChangeEvent event, Actor actor) {
setDisplayedPage(musicSelectionPage);
stage.setKeyboardFocus(musicSelectionPage);
}
};

View File

@@ -26,8 +26,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
@@ -57,6 +55,8 @@ public class MusicSelectionPage extends Page implements Observer {
private boolean down, up;
private boolean frameUsed;
private TextButton beginButton;
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
@@ -77,6 +77,7 @@ public class MusicSelectionPage extends Page implements Observer {
scrollPane.setSize(0.45f*getWidth(), getHeight());
scrollPane.setOverscroll(false, false);
scrollPane.setClamp(true);
scrollPane.setSmoothScrolling(false);
scrollPane.setColor(Color.BLUE);
addActor(scrollPane);
back = new TextButton("Back", skin);
@@ -121,11 +122,18 @@ public class MusicSelectionPage extends Page implements Observer {
mmc.addObserver(this);
mc.addObserver(this);
mc.getMusicList().addObserver(this);
selectionLoaderThread = new musicSelectionLoaderThread();
}
@Override
public void act(float delta) {
if (frameUsed) {
frameUsed = false;
simpleDebug("New frame.");
}
if (down) {
if (scrollDelMod > 0.25f) {
scrollDelMod -= delta/0.5f;
@@ -210,24 +218,31 @@ public class MusicSelectionPage extends Page implements Observer {
@Override
public void dispose() {
mc.getMusicList().deleteObserver(this);
super.dispose();
}
@Override
public void update(Observable o, Object arg) {
if (o == mmc) {
musicInfoTable.setToDefault();
selectionLoaderThread.start();
} else if (o == mc) {
if (mc.getMusicList().getTotal() == selectables.size() && mc.getCurrentMusicFileHandle() != selectables.getChecked().getMetadata().getFileHandle()) {
selectables.setChecked(mc.getCurrentMusicFileHandle());
}
} else if (o == mc.getMusicList()) {
if (arg == mc.getMusicList().states.LOADING) {
vGroup.clear();
selectables.clear();
musicInfoTable.setToDefault();
}
}
}
@Override
public void setCameraPositionToPage(Vector3 cameraPosition) {
getStage().setKeyboardFocus(this);
getStage().setScrollFocus(scrollPane);
super.setCameraPositionToPage(cameraPosition);
}
@@ -244,22 +259,14 @@ public class MusicSelectionPage extends Page implements Observer {
@Override
public void run() {
while (work) {
if (selectables.size() != mmc.size()) {
selectables.clear();
for (int mid = 0; mid < mmc.size(); mid++) {
}
selectables.uncheckAll();
} else {
while (queueList.size != 0) {
AudioMetadata metadata;
synchronized (this) {
while (queueList.size != 0) {
AudioMetadata metadata = queueList.pop();
metadata.loadAlbumCover();
}
metadata = queueList.pop();
metadata.loadAlbumCover();
simpleDebug("Loading " + metadata.getTitle());
}
}
synchronized (this) {
try {
wait();
@@ -283,10 +290,10 @@ public class MusicSelectionPage extends Page implements Observer {
return false;
}
public synchronized void queue(AudioMetadata metadata) {
public void queue(AudioMetadata metadata) {
if (!queueList.contains(metadata, true)) {
queueList.add(metadata);
notify();
start();
}
}
@@ -298,14 +305,15 @@ public class MusicSelectionPage extends Page implements Observer {
private Table informationTable;
private Label name, artist;
private Label time;
private float timeSinceOnScreen;
private boolean offScreen;
private float timeSinceChanged;
private AudioMetadata metadata;
private Texture defaultAlbumArt;
private TextureRegion albumArtTexture;
private boolean albumArtUsed, albumArtAttempted;
private boolean albumArtDisplayed, albumArtAttempted;
public MusicSelectable(AudioMetadata metadata) {
super(skin, "music-selectable");
super(skin, "selectable-button");
this.metadata = metadata;
this.defaultAlbumArt = assets.get("defaultCover.png");
@@ -314,7 +322,6 @@ public class MusicSelectionPage extends Page implements Observer {
albumCoverImage = new Image();
updateAlbumArtImage(defaultAlbumArt);
setSize(getPrefWidth(), getPrefHeight());
informationTable = new Table();
informationTable.row().width(0.75f*getWidth());
name = new Label(metadata.getTitle(), skin, "default-font", skin.getColor("default"));
@@ -349,19 +356,25 @@ public class MusicSelectionPage extends Page implements Observer {
@Override
public void draw(Batch batch, float parentAlpha) {
synchronized (albumCoverImage) {
super.draw(batch, parentAlpha);
}
super.draw(batch, parentAlpha);
}
public void onScreenAct(float delta) {
timeSinceOnScreen = 0;
if (metadata.getAlbumCover() != null && !albumArtUsed) {
updateAlbumArtImage(metadata.getAlbumCover());
albumArtUsed = true;
} else if (!albumArtAttempted) {
selectionLoaderThread.queue(metadata);
albumArtAttempted = true;
if (offScreen) {
offScreen = false;
timeSinceChanged = 0;
} else if (timeSinceChanged < 0.75f) {
timeSinceChanged += delta;
}
if (timeSinceChanged >= 0.75f) {
if (!frameUsed && metadata.getAlbumCover() != null && !albumArtDisplayed) {
updateAlbumArtImage(metadata.getAlbumCover());
albumArtDisplayed = true;
frameUsed = true;
} else if (!albumArtAttempted) {
selectionLoaderThread.queue(metadata);
albumArtAttempted = true;
}
}
}
@@ -372,17 +385,21 @@ public class MusicSelectionPage extends Page implements Observer {
}
public void offScreenAct(float delta) {
if (!offScreen) {
offScreen = true;
timeSinceChanged = 0;
}
if (metadata.getAlbumCover() != null) {
timeSinceOnScreen += delta;
if (timeSinceOnScreen >= 2) {
timeSinceChanged += delta;
if (timeSinceChanged >= 2) {
updateAlbumArtImage(defaultAlbumArt);
metadata.unloadAlbumCover();
albumArtUsed = false;
albumArtDisplayed = false;
albumArtAttempted = false;
}
}
}
public AudioMetadata getMetadata() {
return metadata;
}
@@ -446,6 +463,7 @@ public class MusicSelectionPage extends Page implements Observer {
protected boolean canCheck(MusicSelectable button, boolean newState) {
if (newState) {
musicInfoTable.setDisplayedSelectable(button);
musicSelectDelay = 0f;
}
return super.canCheck(button, newState);
}
@@ -464,7 +482,6 @@ public class MusicSelectionPage extends Page implements Observer {
private Image albumCover;
private Table subInformation;
private MusicSelectable displayedSelectable;
public InformationTable(float width, float height) {
defaults().center();
@@ -481,7 +498,6 @@ public class MusicSelectionPage extends Page implements Observer {
}
public void setDisplayedSelectable(MusicSelectable displayedSelectable) {
this.displayedSelectable = displayedSelectable;
if (displayedSelectable != null) {
AudioMetadata metadata = displayedSelectable.getMetadata();
albumCover.setDrawable(new TextureRegionDrawable(displayedSelectable.getAlbumArtTexture()));
@@ -502,6 +518,7 @@ public class MusicSelectionPage extends Page implements Observer {
}
public void setToDefault() {
clear();
subInformation.clear();