fixed music title delay during scrolling

This commit is contained in:
Harrison Deng 2017-05-15 00:14:29 -05:00
parent 3ef1e1a9a3
commit 31045da431
4 changed files with 49 additions and 27 deletions

View File

@ -44,7 +44,7 @@ public class MusicSelectable extends Button implements Disposable {
public void addInfoToPanel(ScrollPane scroller, float coverSize) {
displayName = new ScrollText(audioInfo.getSongName(), skin, true, scroller);
displayName = new ScrollText(audioInfo.getSongName(), skin, true);
defaults().align(Align.top);
@ -92,6 +92,9 @@ public class MusicSelectable extends Button implements Disposable {
return musicFile;
}
public AudioInfo getAudioInfo() {
return audioInfo;
}
@Override
public void dispose() {

View File

@ -1,12 +1,13 @@
package zero1hd.polyjet.ui.builders;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
@ -26,11 +27,11 @@ public class ScrollText extends Widget {
private boolean currentlyHovering;
private float textOffset;
private ScrollPane scrollCoords;
public ScrollText(String text, Skin skin, boolean scrollOnHover, ScrollPane scrollCoords) {
private Vector2 coords;
public ScrollText(String text, Skin skin, boolean scrollOnHover) {
super();
setName(text);
this.scrollCoords = scrollCoords;
this.scrollOnHover = scrollOnHover;
this.text = text;
@ -41,6 +42,7 @@ public class ScrollText extends Widget {
fontHeight = gLayout.height;
fontWidth = gLayout.width;
coords = new Vector2();
addListener(new ClickListener() {
@Override
@ -59,7 +61,6 @@ public class ScrollText extends Widget {
public void clicked(InputEvent event, float x, float y) {
}
});
}
public float getFontHeight() {
@ -73,15 +74,12 @@ public class ScrollText extends Widget {
@Override
public void layout() {
setHeight(fontHeight+4);
clipBounds.set(getParent().getX()+getX()-scrollCoords.getVisualScrollX(), getParent().getY()+getY() - getHeight()*0.5f, getWidth(), getHeight()*1.5f);
clipBounds.setSize(getWidth(), getHeight()*1.5f);
super.layout();
}
@Override
public void act(float delta) {
clipBounds.setX(getParent().getX()+getX()+scrollCoords.getWidget().getX());
clipBounds.setY(getParent().getY()+getY()+scrollCoords.getWidget().getY());
if (fontWidth > clipBounds.getWidth()) {
if (scrollOnHover) {
if ((int) textOffset != 0 || currentlyHovering) {
@ -104,11 +102,19 @@ public class ScrollText extends Widget {
@Override
public void draw(Batch batch, float parentAlpha) {
validate();
coords.x = getX();
coords.y = getY();
getParent().localToStageCoordinates(coords);
clipBounds.setX(coords.x);
clipBounds.setY(coords.y - 0.5f*getHeight());
getStage().calculateScissors(clipBounds, scissors);
batch.flush();
if (ScissorStack.pushScissors(scissors)) {
font.draw(batch, text, clipBounds.getX() + textOffset, clipBounds.getY() + (fontHeight));
font.draw(batch, text, coords.x + textOffset, coords.y + getFontHeight());
batch.flush();
ScissorStack.popScissors();
};

View File

@ -6,10 +6,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.SnapshotArray;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.polyjet.audio.AudioAnalyzer;
import zero1hd.polyjet.audio.AudioData;
import zero1hd.polyjet.audio.AudioInfo;
public class AnalyzePage extends Page {
AudioAnalyzer audioAnalyzer;
@ -20,29 +22,41 @@ public class AnalyzePage extends Page {
Table songInfo;
Slider difficultyModifier;
Label difficultyModifierPercentage;
private Skin skin;
private TextButton back;
public AnalyzePage(Skin skin, Vector3 camPos) {
super("Results", skin);
this.skin = skin;
cameraPos = camPos;
audioAnalyzer = new AudioAnalyzer();
songInfo = new Table(skin);
songInfo.debug();
back = new TextButton("Back", skin);
back.setPosition(getWidth()-back.getWidth()-15f, getHeight()-back.getHeight()-15f);
back.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
clearAudioData();
cameraPos.x = 0.5f*getWidth();
}
});
addActor(back);
}
public void setSong(AudioData music, SnapshotArray<Actor> uiMusicInfo) {
public void setSong(AudioData music, AudioInfo audioInfo) {
cameraPos.x = 1.5f*getWidth();
this.music = music;
audioAnalyzer.startAnalyticalThread(music);
songInfo.add(new Label(audioInfo.getSongName(), skin, "sub-font", skin.getColor("default")));
addActor(songInfo);
songInfo.add(uiMusicInfo.get(0)).spaceBottom(20f);
songInfo.add(uiMusicInfo.pop()).expandX().center();
songInfo.row();
for (int currentActor = 1; currentActor < uiMusicInfo.size; currentActor++) {
songInfo.add(uiMusicInfo.get(currentActor));
songInfo.row();
}
}
@Override
public void act(float delta) {
super.act(delta);
}
public boolean hasAudioData() {
@ -52,7 +66,7 @@ public class AnalyzePage extends Page {
return false;
}
}
public void clearAUdioData() {
public void clearAudioData() {
music = null;
}
}

View File

@ -65,7 +65,6 @@ public class MusicSelectionPage extends Page {
musicChoiceScroller.setScrollingDisabled(false, true);
musicChoiceScroller.setSize(getWidth(), getHeight()-(getHeight()-back.getY()));
musicChoiceScroller.debug();
addActor(musicChoiceScroller);
loadingWindow.toFront();
@ -111,7 +110,7 @@ public class MusicSelectionPage extends Page {
@Override
public void changed(ChangeEvent event, Actor actor) {
System.out.println();
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getChildren());
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getAudioInfo());
}
});
}