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) { 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); defaults().align(Align.top);
@ -91,8 +91,11 @@ public class MusicSelectable extends Button implements Disposable {
public FileHandle getMusicFile() { public FileHandle getMusicFile() {
return musicFile; return musicFile;
} }
public AudioInfo getAudioInfo() {
return audioInfo;
}
@Override @Override
public void dispose() { public void dispose() {
audioInfo.dispose(); audioInfo.dispose();

View File

@ -1,12 +1,13 @@
package zero1hd.polyjet.ui.builders; package zero1hd.polyjet.ui.builders;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.math.Rectangle; 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.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent; 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.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Widget; import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
@ -26,11 +27,11 @@ public class ScrollText extends Widget {
private boolean currentlyHovering; private boolean currentlyHovering;
private float textOffset; 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(); super();
setName(text); setName(text);
this.scrollCoords = scrollCoords;
this.scrollOnHover = scrollOnHover; this.scrollOnHover = scrollOnHover;
this.text = text; this.text = text;
@ -41,6 +42,7 @@ public class ScrollText extends Widget {
fontHeight = gLayout.height; fontHeight = gLayout.height;
fontWidth = gLayout.width; fontWidth = gLayout.width;
coords = new Vector2();
addListener(new ClickListener() { addListener(new ClickListener() {
@Override @Override
@ -59,7 +61,6 @@ public class ScrollText extends Widget {
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
} }
}); });
} }
public float getFontHeight() { public float getFontHeight() {
@ -73,15 +74,12 @@ public class ScrollText extends Widget {
@Override @Override
public void layout() { public void layout() {
setHeight(fontHeight+4); 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(); super.layout();
} }
@Override @Override
public void act(float delta) { 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 (fontWidth > clipBounds.getWidth()) {
if (scrollOnHover) { if (scrollOnHover) {
if ((int) textOffset != 0 || currentlyHovering) { if ((int) textOffset != 0 || currentlyHovering) {
@ -104,11 +102,19 @@ public class ScrollText extends Widget {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
validate(); 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); getStage().calculateScissors(clipBounds, scissors);
batch.flush(); batch.flush();
if (ScissorStack.pushScissors(scissors)) { 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(); batch.flush();
ScissorStack.popScissors(); 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.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Table; 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.AudioAnalyzer;
import zero1hd.polyjet.audio.AudioData; import zero1hd.polyjet.audio.AudioData;
import zero1hd.polyjet.audio.AudioInfo;
public class AnalyzePage extends Page { public class AnalyzePage extends Page {
AudioAnalyzer audioAnalyzer; AudioAnalyzer audioAnalyzer;
@ -20,29 +22,41 @@ public class AnalyzePage extends Page {
Table songInfo; Table songInfo;
Slider difficultyModifier; Slider difficultyModifier;
Label difficultyModifierPercentage; Label difficultyModifierPercentage;
private Skin skin;
private TextButton back;
public AnalyzePage(Skin skin, Vector3 camPos) { public AnalyzePage(Skin skin, Vector3 camPos) {
super("Results", skin); super("Results", skin);
this.skin = skin;
cameraPos = camPos; cameraPos = camPos;
audioAnalyzer = new AudioAnalyzer(); audioAnalyzer = new AudioAnalyzer();
songInfo = new Table(skin); 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(); cameraPos.x = 1.5f*getWidth();
this.music = music; this.music = music;
audioAnalyzer.startAnalyticalThread(music); audioAnalyzer.startAnalyticalThread(music);
songInfo.add(new Label(audioInfo.getSongName(), skin, "sub-font", skin.getColor("default")));
addActor(songInfo); addActor(songInfo);
songInfo.add(uiMusicInfo.get(0)).spaceBottom(20f); }
songInfo.add(uiMusicInfo.pop()).expandX().center();
songInfo.row(); @Override
for (int currentActor = 1; currentActor < uiMusicInfo.size; currentActor++) { public void act(float delta) {
songInfo.add(uiMusicInfo.get(currentActor)); super.act(delta);
songInfo.row();
}
} }
public boolean hasAudioData() { public boolean hasAudioData() {
@ -52,7 +66,7 @@ public class AnalyzePage extends Page {
return false; return false;
} }
} }
public void clearAUdioData() { public void clearAudioData() {
music = null; music = null;
} }
} }

View File

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