keybind efficiency by removing excessive object creation; removed a few

extra imports;
This commit is contained in:
Harrison Deng 2018-08-11 18:11:06 -05:00
parent b083e5f187
commit 8bea317ea8
5 changed files with 57 additions and 71 deletions

View File

@ -12,7 +12,6 @@ import org.jaudiotagger.audio.mp3.MP3AudioHeader;
import org.jaudiotagger.audio.mp3.MP3File; import org.jaudiotagger.audio.mp3.MP3File;
import org.jaudiotagger.tag.TagException; import org.jaudiotagger.tag.TagException;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
public class MinimalAudioHeader { public class MinimalAudioHeader {

View File

@ -4,14 +4,12 @@ import java.util.Comparator;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh; import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.VertexAttribute; import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage; import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.Disposable;

View File

@ -10,7 +10,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;

View File

@ -1,46 +1,77 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.components; 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.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent; 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.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.controls.KeyMap; import zero1hd.rhythmbullet.controls.KeyMap;
public class ControlOptions extends Table { public class ControlOptions extends Table {
private KeyBindButton selected;
public ControlOptions(Skin skin, KeyMap keyMap) { public ControlOptions(Skin skin, KeyMap keyMap) {
super(skin); super(skin);
align(Align.center); align(Align.center);
//first 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);
}
};
Label forwardKeyLabel = new Label("Forward: ",skin); Label forwardKeyLabel = new Label("Forward: ",skin);
forwardKeyLabel.setName(KeyMap.UP); forwardKeyLabel.setName(KeyMap.UP);
add(forwardKeyLabel).left(); add(forwardKeyLabel).left();
KeyBindButton forwardKeySetter = new KeyBindButton(keyMap, KeyMap.UP); KeyBindButton forwardKeySetter = new KeyBindButton(keyMap, KeyMap.UP, selectedListener, keyPressedListener);
add(forwardKeySetter).spaceRight(45f); add(forwardKeySetter).spaceRight(45f);
Label shootKeyLabel = new Label("Shoot: ", skin); Label shootKeyLabel = new Label("Shoot: ", skin);
shootKeyLabel.setName(KeyMap.SHOOT); shootKeyLabel.setName(KeyMap.SHOOT);
add(shootKeyLabel).left(); add(shootKeyLabel).left();
KeyBindButton shootKeySetter = new KeyBindButton(keyMap, KeyMap.SHOOT); KeyBindButton shootKeySetter = new KeyBindButton(keyMap, KeyMap.SHOOT, selectedListener, keyPressedListener);
add(shootKeySetter); add(shootKeySetter);
row(); row();
//second
Label backwardKeyLabel = new Label("Backward: ", skin); Label backwardKeyLabel = new Label("Backward: ", skin);
backwardKeyLabel.setName(KeyMap.DOWN); backwardKeyLabel.setName(KeyMap.DOWN);
add(backwardKeyLabel).left(); add(backwardKeyLabel).left();
KeyBindButton backwardKeySetter = new KeyBindButton(keyMap, KeyMap.DOWN); KeyBindButton backwardKeySetter = new KeyBindButton(keyMap, KeyMap.DOWN, selectedListener, keyPressedListener);
add(backwardKeySetter).spaceRight(45f); add(backwardKeySetter).spaceRight(45f);
Label sector1TPKeyLabel = new Label("Left Teleport", skin); Label sector1TPKeyLabel = new Label("Left Teleport", skin);
sector1TPKeyLabel.setName(KeyMap.FIRSTTHIRDTELEPORT); sector1TPKeyLabel.setName(KeyMap.FIRSTTHIRDTELEPORT);
add(sector1TPKeyLabel).left(); add(sector1TPKeyLabel).left();
KeyBindButton Sector1TPKeySetter = new KeyBindButton(keyMap, KeyMap.FIRSTTHIRDTELEPORT); KeyBindButton Sector1TPKeySetter = new KeyBindButton(keyMap, KeyMap.FIRSTTHIRDTELEPORT, selectedListener, keyPressedListener);
Sector1TPKeySetter.addListener(selectedListener);
add(Sector1TPKeySetter); add(Sector1TPKeySetter);
row(); row();
@ -48,12 +79,13 @@ public class ControlOptions extends Table {
Label leftKeyLabel = new Label("Left: ", skin); Label leftKeyLabel = new Label("Left: ", skin);
leftKeyLabel.setName(KeyMap.LEFT); leftKeyLabel.setName(KeyMap.LEFT);
add(leftKeyLabel).left(); add(leftKeyLabel).left();
KeyBindButton leftKeySetter = new KeyBindButton(keyMap, KeyMap.LEFT); KeyBindButton leftKeySetter = new KeyBindButton(keyMap, KeyMap.LEFT, selectedListener, keyPressedListener);
add(leftKeySetter).spaceRight(45f); add(leftKeySetter).spaceRight(45f);
Label sector2TPKeyLabel = new Label("Middle Teleport: ", skin); Label sector2TPKeyLabel = new Label("Middle Teleport: ", skin);
sector2TPKeyLabel.setName(KeyMap.SECONDTHIRDTELEPORT); sector2TPKeyLabel.setName(KeyMap.SECONDTHIRDTELEPORT);
add(sector2TPKeyLabel).left(); add(sector2TPKeyLabel).left();
KeyBindButton sector2TPKeySetter = new KeyBindButton(keyMap, KeyMap.SECONDTHIRDTELEPORT); KeyBindButton sector2TPKeySetter = new KeyBindButton(keyMap, KeyMap.SECONDTHIRDTELEPORT, selectedListener, keyPressedListener);
sector2TPKeySetter.addListener(selectedListener);
add(sector2TPKeySetter); add(sector2TPKeySetter);
row(); row();
@ -61,40 +93,19 @@ public class ControlOptions extends Table {
Label rightKeyLabel = new Label("Right: ", skin); Label rightKeyLabel = new Label("Right: ", skin);
rightKeyLabel.setName(KeyMap.RIGHT); rightKeyLabel.setName(KeyMap.RIGHT);
add(rightKeyLabel).left(); add(rightKeyLabel).left();
KeyBindButton rightKeySetter = new KeyBindButton(keyMap, KeyMap.RIGHT); KeyBindButton rightKeySetter = new KeyBindButton(keyMap, KeyMap.RIGHT, selectedListener, keyPressedListener);
add(rightKeySetter).spaceRight(45f); add(rightKeySetter).spaceRight(45f);
Label sector3TPKeyLabel = new Label("Right Teleport: ", skin); Label sector3TPKeyLabel = new Label("Right Teleport: ", skin);
sector3TPKeyLabel.setName(KeyMap.THIRDTHIRDTELEPORT); sector3TPKeyLabel.setName(KeyMap.THIRDTHIRDTELEPORT);
add(sector3TPKeyLabel).left(); add(sector3TPKeyLabel).left();
KeyBindButton sector3TPKeySetter = new KeyBindButton(keyMap, KeyMap.THIRDTHIRDTELEPORT); KeyBindButton sector3TPKeySetter = new KeyBindButton(keyMap, KeyMap.THIRDTHIRDTELEPORT, selectedListener, keyPressedListener);
sector3TPKeySetter.addListener(selectedListener);
add(sector3TPKeySetter); add(sector3TPKeySetter);
addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
unselect();
if (event.getTarget() instanceof KeyBindButton) {
getStage().setKeyboardFocus(event.getTarget());
event.getTarget().setColor(Color.ORANGE);
} else {
unselect();
}
super.clicked(event, x, y);
}
});
setFillParent(true); setFillParent(true);
} }
public void unselect() { public void unselect() {
Array<Actor> keys = getChildren(); selected.setColor(Color.WHITE);
for (int i = 0; i < keys.size; i++) {
keys.get(i).setColor(Color.WHITE);;
}
}
@Override
public void act(float delta) {
super.act(delta);
} }
} }

View File

@ -1,53 +1,32 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.components; 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.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor; 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.InputListener;
import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import zero1hd.rhythmbullet.controls.KeyMap; import zero1hd.rhythmbullet.controls.KeyMap;
public class KeyBindButton extends Actor { public class KeyBindButton extends Actor {
TextureRegion keyIcon; private TextureRegion keyIcon;
KeyMap keyMap; private KeyMap keyMap;
private String controlKey;
public KeyBindButton(final KeyMap keyMap, final String control) { public KeyBindButton(final KeyMap keyMap, final String control, ClickListener selectionListener, InputListener keyPressListener) {
this.keyMap = keyMap; this.keyMap = keyMap;
keyIcon = keyMap.getIcon(keyMap.stringToID(control)); this.keyIcon = keyMap.getIcon(keyMap.stringToID(control));
this.controlKey = control;
setSize(keyIcon.getRegionWidth(), keyIcon.getRegionHeight()); setSize(keyIcon.getRegionWidth(), keyIcon.getRegionHeight());
InputListener keyListener = new InputListener() { addListener(selectionListener);
@Override addListener(keyPressListener);
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 (setKey(keycode, control)) {
keyMap.updateKeys();
addAction(Actions.sequence(Actions.color(Color.GREEN, 0.2f), Actions.color(Color.WHITE, 0.2f)));
} else {
addAction(Actions.sequence(Actions.color(Color.RED, 0.2f), Actions.delay(0.1f), Actions.color(Color.WHITE, 0.2f)));
}
}
return super.keyUp(event, keycode);
}
};
addListener(keyListener);
} }
public boolean setKey(int keycode, String control) { public boolean setKey(int keycode) {
if (keyMap.getIcon(keycode) != null) { if (keyMap.getIcon(keycode) != null) {
keyMap.getKeys().putInteger(control, keycode); keyMap.getKeys().putInteger(controlKey, keycode);
keyIcon = keyMap.getIcon(keycode); keyIcon = keyMap.getIcon(keycode);
return true; return true;
} else { } else {