Avoid selecting a different theme when dragging

This commit is contained in:
Lonami Exo 2017-05-09 16:49:16 +02:00
parent 3b1124d77c
commit 8b38d92633

View file

@ -32,12 +32,15 @@ class CustomizeScreen implements Screen {
private final Screen lastScreen; private final Screen lastScreen;
private float themeDragStartX, themeDragStartY;
//endregion //endregion
//region Static members //region Static members
// As the examples show on the LibGdx wiki // As the examples show on the LibGdx wiki
private static final float minDelta = 1/30f; private static final float MIN_DELTA = 1/30f;
private static final float DRAG_LIMIT_SQ = 5*5;
//endregion //endregion
@ -129,6 +132,22 @@ class CustomizeScreen implements Screen {
card.addListener(new InputListener() { card.addListener(new InputListener() {
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
themeDragStartX = x;
themeDragStartY = y;
return true;
}
// We could actually rely on touchDragged not being called,
// but perhaps it would be hard for some people not to move
// their fingers even the slightest bit, so we use a custom
// drag limit
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
x -= themeDragStartX;
y -= themeDragStartY;
float distSq = x * x + y * y;
if (distSq < DRAG_LIMIT_SQ) {
if (Klooni.isThemeBought(card.theme)) if (Klooni.isThemeBought(card.theme))
card.use(); card.use();
else else
@ -138,7 +157,7 @@ class CustomizeScreen implements Screen {
ThemeCard c = (ThemeCard)a; ThemeCard c = (ThemeCard)a;
c.usedThemeUpdated(); c.usedThemeUpdated();
} }
return true; }
} }
}); });
themesGroup.addActor(card); themesGroup.addActor(card);
@ -186,7 +205,7 @@ class CustomizeScreen implements Screen {
public void render(float delta) { public void render(float delta) {
Klooni.theme.glClearBackground(); Klooni.theme.glClearBackground();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Math.min(Gdx.graphics.getDeltaTime(), minDelta)); stage.act(Math.min(Gdx.graphics.getDeltaTime(), MIN_DELTA));
stage.draw(); stage.draw();
if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) { if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) {