better scroll control
This commit is contained in:
parent
42e00c5bac
commit
6cc9288c13
@ -67,12 +67,8 @@ public class MusicSelectable extends WidgetGroup implements Disposable {
|
||||
addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (selected) {
|
||||
deselect();
|
||||
} else {
|
||||
msp.deselectAll();
|
||||
select();
|
||||
}
|
||||
msp.deselectAll();
|
||||
select();
|
||||
super.clicked(event, x, y);
|
||||
}
|
||||
});
|
||||
|
@ -1,11 +1,13 @@
|
||||
package zero1hd.rhythmbullet.graphics.ui.pages;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.Preferences;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
@ -30,7 +32,7 @@ import zero1hd.rhythmbullet.audio.SongList;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicSelectable;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
|
||||
public class MusicSelectionPage extends Page {
|
||||
public class MusicSelectionPage extends Page implements Observer {
|
||||
Preferences musicFileAnnotation;
|
||||
|
||||
private SongList songList;
|
||||
@ -57,6 +59,11 @@ public class MusicSelectionPage extends Page {
|
||||
private Image vertSplitBar;
|
||||
private Image horSplitBar;
|
||||
private Texture white;
|
||||
|
||||
private boolean down, up;
|
||||
private int index;
|
||||
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod;
|
||||
|
||||
public MusicSelectionPage(Skin skin, SongList songList, AssetManager assetManager, Vector3 cameraTarget) {
|
||||
super("Select music", skin);
|
||||
songInfoTable = new Table();
|
||||
@ -112,33 +119,56 @@ public class MusicSelectionPage extends Page {
|
||||
addListener(new InputListener() {
|
||||
@Override
|
||||
public boolean keyDown(InputEvent event, int keycode) {
|
||||
int index;
|
||||
scrollTimer = 0;
|
||||
scrollDelMod = 1f;
|
||||
if (keycode == Keys.DOWN) {
|
||||
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) + 1)) == songTable.getChildren().size) {
|
||||
index = 0;
|
||||
}
|
||||
deselectAll();
|
||||
((MusicSelectable)songTable.getChildren().get(index)).select();
|
||||
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
|
||||
down = true;
|
||||
}
|
||||
if (keycode == Keys.UP) {
|
||||
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) {
|
||||
|
||||
index = songTable.getChildren().size-1;
|
||||
|
||||
}
|
||||
deselectAll();
|
||||
((MusicSelectable)songTable.getChildren().get(index)).select();
|
||||
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
|
||||
up = true;
|
||||
}
|
||||
return super.keyDown(event, keycode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyUp(InputEvent event, int keycode) {
|
||||
if (keycode == Keys.DOWN) {
|
||||
down = false;
|
||||
}
|
||||
|
||||
if (keycode == Keys.UP) {
|
||||
up = false;
|
||||
}
|
||||
return super.keyUp(event, keycode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
Gdx.gl.glLineWidth(2);
|
||||
if (down) {
|
||||
if (scrollDelMod > 0.25f) {
|
||||
scrollDelMod -= delta/0.5f;
|
||||
}
|
||||
if (scrollTimer <= 0) {
|
||||
scrollTimer = scrollDelay*scrollDelMod;
|
||||
scrollDown();
|
||||
} else {
|
||||
scrollTimer -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
if (up) {
|
||||
if (scrollDelMod > 0.25f) {
|
||||
scrollDelMod -= delta/0.5f;
|
||||
}
|
||||
if (scrollTimer <= 0) {
|
||||
scrollTimer = scrollDelay*scrollDelMod;
|
||||
scrollUp();
|
||||
} else {
|
||||
scrollTimer -= delta;
|
||||
}
|
||||
}
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
@ -188,13 +218,44 @@ public class MusicSelectionPage extends Page {
|
||||
}
|
||||
|
||||
public void deselectAll() {
|
||||
for (int i = 0; i < selectables.size; i++) {
|
||||
selectables.get(i).deselect();
|
||||
if (currentlySelected != null) {
|
||||
currentlySelected.deselect();
|
||||
} else {
|
||||
for (int i = 0; i < selectables.size; i++) {
|
||||
selectables.get(i).deselect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setCurrentlySelected(MusicSelectable currentlySelected) {
|
||||
this.currentlySelected = currentlySelected;
|
||||
}
|
||||
|
||||
private void scrollDown() {
|
||||
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) + 1)) == songTable.getChildren().size) {
|
||||
index = 0;
|
||||
}
|
||||
deselectAll();
|
||||
|
||||
((MusicSelectable)songTable.getChildren().get(index)).select();
|
||||
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
|
||||
}
|
||||
|
||||
private void scrollUp() {
|
||||
if ((index = (songTable.getChildren().indexOf(currentlySelected, true) - 1)) < 0) {
|
||||
index = songTable.getChildren().size-1;
|
||||
}
|
||||
deselectAll();
|
||||
|
||||
((MusicSelectable)songTable.getChildren().get(index)).select();
|
||||
scrollbar.scrollTo(currentlySelected.getX(), currentlySelected.getY(), currentlySelected.getWidth(), currentlySelected.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o == songList) {
|
||||
deselectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user