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:
@@ -203,5 +203,4 @@ public class RhythmBullet extends Game {
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
69
core/src/zero1hd/rhythmbullet/graphics/ui/Page.java
Executable file
69
core/src/zero1hd/rhythmbullet/graphics/ui/Page.java
Executable file
@@ -0,0 +1,69 @@
|
||||
package zero1hd.rhythmbullet.graphics.ui;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Group;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||
|
||||
public class Page extends Group implements Disposable {
|
||||
private Label pageTitle;
|
||||
private int baseXPos, baseYPos;
|
||||
|
||||
public Page(int baseXPos, int baseYPos) {
|
||||
this.baseXPos = baseXPos;
|
||||
this.baseYPos = baseYPos;
|
||||
setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||
setTouchable(Touchable.childrenOnly);
|
||||
setToBasePosition();
|
||||
}
|
||||
|
||||
public Page(int baseXPos, int baseYPos, String titleText, Skin skin) {
|
||||
this(baseXPos, baseYPos);
|
||||
pageTitle = new Label(titleText, skin, "large-font", skin.getColor("default"));
|
||||
pageTitle.setPosition(18f, getHeight()-pageTitle.getHeight()-15f);
|
||||
addActor(pageTitle);
|
||||
}
|
||||
|
||||
public float getHeightBelowTitle() {
|
||||
return pageTitle.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStage(Stage stage) {
|
||||
if (stage == null) {
|
||||
if (!hasParent()) {
|
||||
dispose();
|
||||
}
|
||||
} else if (!(stage.getViewport() instanceof ScreenViewport)) {
|
||||
throw new IllegalArgumentException("Pages are explicitly for GUIs, and thus should have a 1:1 ratio between pixel and texture size for maximum clarity. This means that the stage should be using a ScreenViewport.");
|
||||
}
|
||||
super.setStage(stage);
|
||||
}
|
||||
|
||||
public void setCameraPositionToPage(Vector3 cameraPosition) {
|
||||
cameraPosition.x = (baseXPos+0.5f) * getWidth();
|
||||
cameraPosition.y = (baseYPos+0.5f) * getHeight();
|
||||
}
|
||||
|
||||
public void setToBasePosition() {
|
||||
setPosition(baseXPos*getWidth(), baseYPos*getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParent(Group parent) {
|
||||
if (parent == null && getStage() == null) {
|
||||
dispose();
|
||||
}
|
||||
super.setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Gdx.app.debug(getClass().getSimpleName(), "Disposing...");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user