deselection process now functions with the new keybind system;

visualizer progress (completely functional, one issue: windows drag
causes spike due to delta); all round minor cleanup and small changes;
This commit is contained in:
Harrison Deng 2018-08-11 21:10:43 -05:00
parent 8bea317ea8
commit 7a810299ce
15 changed files with 82 additions and 49 deletions

View File

@ -203,5 +203,4 @@ public class RhythmBullet extends Game {
}
super.dispose();
}
}

View File

@ -1,5 +1,8 @@
package zero1hd.rhythmbullet.audio.visualizer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
@ -9,38 +12,50 @@ import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.audio.MusicController;
public class DoubleHorizontalVisualizer implements Disposable {
private int width, height, barCount, barWidth, spaceBetweenBars;
private int width, height, barWidth, spaceBetweenBars;
private int x, y;
private ShapeRenderer shapeRenderer;
private PCMSystem pcm;
private float[] amplitudes;
private int[] barHeights;
private int binsPerBar;
private float normalFactor = 20;
private float barChangeRate = 4f;
private float offset;
private int boundaryThickness;
private float spacePercentage = 0.85f;
private int barCount = 80;
private float normalFactor = 3f;
private float barChangeRate = 14f;
private int smoothRange = 1;
private int binsToInclude = 160;
private Color color = new Color(1f, 1f, 1f, 0.85f);
/**
*
* @param barCount amount of bars this visualizer should have.
* @param width the width of the visualizer.
* @param spacePercentage the percentage of a bar that should be space.
*/
public DoubleHorizontalVisualizer(int barCount, int width, int height, float spacePercentage, MusicController musicController, PCMSystem PCMSystem) {
this.barCount = barCount;
public DoubleHorizontalVisualizer(int width, int height, MusicController musicController, PCMSystem PCMSystem) {
this.barWidth = width/barCount;
this.spaceBetweenBars = MathUtils.round(barWidth * spacePercentage);
this.barWidth -= spaceBetweenBars;
pcm = PCMSystem;
if (barWidth < 1) throw new IllegalArgumentException("The arguments you passed caused the bar width to be 0.");
binsPerBar = (pcm.getFrequencyBins().length/barCount);
binsPerBar = (binsToInclude/barCount);
this.width = width;
this.height = height;
amplitudes = new float[barCount];
barHeights = new int[barCount];
shapeRenderer = new ShapeRenderer();
boundaryThickness = barWidth;
offset = (width - (barCount*(barWidth+spaceBetweenBars)-spaceBetweenBars))/2f + x;
}
public void act(float delta) {
if (color.r > 1f) color.r = 0f;
if (color.g > 1f) color.g = 0f;
if (color.b > 1f) color.b = 0f;
if (color.a > 1f) color.a = 0.2f;
for (int bar = 0; bar < amplitudes.length; bar++) {
float normalizedAmplitude = 0;
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
@ -65,6 +80,7 @@ public class DoubleHorizontalVisualizer implements Disposable {
int pixelsMoved = MathUtils.round(amplitudes[bar] - barHeights[bar]);
pixelsMoved = MathUtils.floor(pixelsMoved*delta*barChangeRate);
barHeights[bar] += pixelsMoved;
if (barHeights[bar] < 0) barHeights[bar] = 0;
@ -74,18 +90,21 @@ public class DoubleHorizontalVisualizer implements Disposable {
public void draw(Batch batch, float parentAlpha) {
batch.end();
Gdx.gl.glEnable(GL20.GL_BLEND);
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(1f, 1f, 1f, 1f);
shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
shapeRenderer.setTransformMatrix(batch.getTransformMatrix());
shapeRenderer.rect(x, y, width, 2);
shapeRenderer.rect(x, y+height-2, width, 2);
int beginX = x + spaceBetweenBars/2, beginY = y;
shapeRenderer.rect(x, y, width, boundaryThickness);
shapeRenderer.rect(x, y+height, width, -boundaryThickness);
for (int bar = 0; bar < barCount; bar++) {
shapeRenderer.rect(beginX + (spaceBetweenBars+barWidth)*bar, beginY+height, barWidth, barHeights[bar]);
shapeRenderer.rect(beginX + (spaceBetweenBars+barWidth)*bar, beginY-barHeights[barHeights.length - 1 - bar], barWidth, barHeights[barHeights.length - 1 - bar]);
shapeRenderer.setColor(color);
shapeRenderer.rect(offset + (spaceBetweenBars+barWidth)*bar, y+height, barWidth, barHeights[bar]);
shapeRenderer.rect(offset + (spaceBetweenBars+barWidth)*bar, y-barHeights[barHeights.length - 1 - bar], barWidth, barHeights[barHeights.length - 1 - bar]);
}
shapeRenderer.end();
Gdx.gl.glDisable(GL20.GL_BLEND);
batch.begin();
}

View File

@ -1,4 +1,4 @@
package zero1hd.rhythmbullet.desktop.graphics.ui.pages;
package zero1hd.rhythmbullet.graphics.ui;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector3;

View File

@ -12,8 +12,8 @@ public class DesktopLauncher {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = "Rhythm Bullet";
config.resizable = false;
config.allowSoftwareMode = true;
config.useHDPI = true;
config.samples = 2;
core = new RhythmBullet();
core.setup(new SplashScreen(), new DesktopAssetPack());

View File

@ -103,12 +103,14 @@ public class PCMObtainer implements Observer, PCMSystem {
return offset;
}
private void synchronizeBufferWithPlayback() {
private boolean synchronizeBufferWithPlayback() {
int bufferPos = calcBufferPosition();
if (bufferPos <= playingBuffer.limit()) {
playingBuffer.position(calcBufferPosition());
windowsRead = (int) ((mc.getCurrentPosition() * sampleRate) / windowSize);
return true;
}
return false;
}
private void setMusic() {
@ -153,6 +155,7 @@ public class PCMObtainer implements Observer, PCMSystem {
private volatile boolean run = true;
private long timeOfLastRead;
private long waitTime;
private boolean read = true;
@Override
public void run() {
while (run) {
@ -161,11 +164,12 @@ public class PCMObtainer implements Observer, PCMSystem {
timeOfLastRead = TimeUtils.millis();
//calculate current pcm data and notify that there is new data
if (read) {
calcPCMData();
fft.realForward(PCM);
updated = true;
windowsRead++;
}
//contemplate synchronization
try {
currentPlaybackWindow = MathUtils.round((mc.getCurrentPosition() * sampleRate) / windowSize);
@ -175,7 +179,7 @@ public class PCMObtainer implements Observer, PCMSystem {
}
}
if (windowsRead != currentPlaybackWindow) {
synchronizeBufferWithPlayback();
read = synchronizeBufferWithPlayback();
}
//wait for a bit before reading again depending on the speed at which the system does playback.
@ -186,6 +190,9 @@ public class PCMObtainer implements Observer, PCMSystem {
e.printStackTrace();
}
} else {
for (int freqID = 0; freqID < frequencyBins.length; freqID++) {
getFrequencyBins()[freqID] = 0;
}
synchronized (this) {
try {
wait();

View File

@ -3,6 +3,7 @@ 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;
@ -10,6 +11,7 @@ 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;
@ -49,15 +51,25 @@ public class ControlOptions extends Table {
}
};
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);
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);
KeyBindButton shootKeySetter = new KeyBindButton(keyMap, KeyMap.SHOOT, selectedListener, keyPressedListener, deselected);
add(shootKeySetter);
row();
@ -65,12 +77,12 @@ public class ControlOptions extends Table {
Label backwardKeyLabel = new Label("Backward: ", skin);
backwardKeyLabel.setName(KeyMap.DOWN);
add(backwardKeyLabel).left();
KeyBindButton backwardKeySetter = new KeyBindButton(keyMap, KeyMap.DOWN, selectedListener, keyPressedListener);
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);
KeyBindButton Sector1TPKeySetter = new KeyBindButton(keyMap, KeyMap.FIRSTTHIRDTELEPORT, selectedListener, keyPressedListener, deselected);
Sector1TPKeySetter.addListener(selectedListener);
add(Sector1TPKeySetter);
@ -79,12 +91,12 @@ public class ControlOptions extends Table {
Label leftKeyLabel = new Label("Left: ", skin);
leftKeyLabel.setName(KeyMap.LEFT);
add(leftKeyLabel).left();
KeyBindButton leftKeySetter = new KeyBindButton(keyMap, KeyMap.LEFT, selectedListener, keyPressedListener);
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);
KeyBindButton sector2TPKeySetter = new KeyBindButton(keyMap, KeyMap.SECONDTHIRDTELEPORT, selectedListener, keyPressedListener, deselected);
sector2TPKeySetter.addListener(selectedListener);
add(sector2TPKeySetter);
@ -93,19 +105,19 @@ public class ControlOptions extends Table {
Label rightKeyLabel = new Label("Right: ", skin);
rightKeyLabel.setName(KeyMap.RIGHT);
add(rightKeyLabel).left();
KeyBindButton rightKeySetter = new KeyBindButton(keyMap, KeyMap.RIGHT, selectedListener, keyPressedListener);
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);
KeyBindButton sector3TPKeySetter = new KeyBindButton(keyMap, KeyMap.THIRDTHIRDTELEPORT, selectedListener, keyPressedListener, deselected);
sector3TPKeySetter.addListener(selectedListener);
add(sector3TPKeySetter);
setFillParent(true);
}
public void unselect() {
private void unselect() {
selected.setColor(Color.WHITE);
}
}

View File

@ -5,6 +5,7 @@ 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;
@ -13,7 +14,7 @@ public class KeyBindButton extends Actor {
private KeyMap keyMap;
private String controlKey;
public KeyBindButton(final KeyMap keyMap, final String control, ClickListener selectionListener, InputListener keyPressListener) {
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;
@ -21,6 +22,7 @@ public class KeyBindButton extends Actor {
addListener(selectionListener);
addListener(keyPressListener);
addListener(deselectedListener);
}

View File

@ -14,7 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.audio.analyzer.AudioAnalyzer;
import zero1hd.rhythmbullet.audio.metadata.AudioMetadata;
import zero1hd.rhythmbullet.audio.processor.AudioProcessor;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
public class AnalysisPage extends Page {
private TextButton backButton;

View File

@ -3,7 +3,7 @@ package zero1hd.rhythmbullet.desktop.screens.main;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
public class CreditsPage extends Page {

View File

@ -8,7 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.GraphicsOptions;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
public class GraphicsPage extends Page {
private ScrollPane scrollPane;

View File

@ -7,7 +7,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.controls.KeyMap;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.ControlOptions;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
public class KeybindPage extends Page {
private ControlOptions controlTable;
@ -27,8 +27,4 @@ public class KeybindPage extends Page {
addActor(backButton);
}
public void unselect() {
controlTable.unselect();
}
}

View File

@ -21,7 +21,7 @@ import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.audio.visualizer.DoubleHorizontalVisualizer;
import zero1hd.rhythmbullet.desktop.audio.PCMObtainer;
import zero1hd.rhythmbullet.desktop.graphics.ui.components.MusicControls;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
public class MainPage extends Page implements Observer {
@ -45,7 +45,7 @@ public class MainPage extends Page implements Observer {
this.mc = musicController;
this.mc.addObserver(this);
dhv = new DoubleHorizontalVisualizer(70, (int) getWidth(), (int) (getHeight()*0.3), 0.3f, mc, new PCMObtainer(mc));
dhv = new DoubleHorizontalVisualizer((int) getWidth(), (int) (getHeight()*0.3), mc, new PCMObtainer(mc));
dhv.setPosition(0, (int) ((getHeight() - dhv.getHeight())/2f));
title = new Image(assetManager.get("title.png", Texture.class));
@ -99,14 +99,14 @@ public class MainPage extends Page implements Observer {
@Override
public void act(float delta) {
dhv.act(delta);
super.act(delta);
dhv.act(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
dhv.draw(batch, parentAlpha);
super.draw(batch, parentAlpha);
dhv.draw(batch, parentAlpha);
}
@Override

View File

@ -21,8 +21,8 @@ import zero1hd.rhythmbullet.audio.MusicMetadataController;
import zero1hd.rhythmbullet.audio.MusicList;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.desktop.audio.processor.DesktopAudioProcessorFactory;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.shaders.BloomShader;
import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.util.ResizeReadyScreen;
public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
@ -143,7 +143,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
public boolean keyUp(InputEvent event, int keycode) {
if (keycode == Keys.ESCAPE) {
stage.unfocusAll();
keybindPage.unselect();
}
return super.keyUp(event, keycode);
}
@ -155,7 +154,6 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
public void clicked(InputEvent event, float x, float y) {
if (stage.hit(x, y, true) == null) {
stage.unfocusAll();
keybindPage.unselect();
}
super.clicked(event, x, y);
}

View File

@ -28,7 +28,7 @@ import com.badlogic.gdx.utils.Array;
import zero1hd.rhythmbullet.audio.MusicMetadataController;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
import zero1hd.rhythmbullet.util.MusicSelectableButtonGroup;

View File

@ -14,7 +14,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.audio.MusicController;
import zero1hd.rhythmbullet.desktop.graphics.ui.pages.Page;
import zero1hd.rhythmbullet.graphics.ui.Page;
public class OptionsPage extends Page {
Table optionsTable;