From 438f26d468e1617e55a564ee8003bb882037be3f Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Wed, 13 Jan 2021 21:29:13 -0800 Subject: [PATCH] Upgraded LibGDX from 1.9.11 -> 1.9.13 API change scrolled(int) -> scrolled(float,float) Changed switches to if/else, asserting non-zero amounts API change gdx.utils.Pool removed prefill argument -- adjusted code Note: DS1Viewer remains broken, API updated anyways --- .../java/com/riiablo/console/Console.java | 15 +++++----- .../com/riiablo/console/RenderedConsole.java | 25 +++++++---------- .../main/java/com/riiablo/mpq/util/ADPCM.java | 21 ++++++++------ .../riiablo/mpq_bytebuf/util/Exploder.java | 15 ++++++---- .../java/com/riiablo/screen/GameScreen.java | 24 ++++++---------- .../java/com/riiablo/widget/ScrollPane.java | 28 +++++++++++++++++-- gradle.properties | 2 +- .../java/com/riiablo/camera/CameraTool.java | 6 ++-- .../main/java/com/riiablo/map/DS1Viewer.java | 23 +++++++-------- .../main/java/com/riiablo/map/MapViewer.java | 14 ++++------ 10 files changed, 93 insertions(+), 80 deletions(-) diff --git a/core/src/main/java/com/riiablo/console/Console.java b/core/src/main/java/com/riiablo/console/Console.java index 7bc2ba7f..d24d6569 100644 --- a/core/src/main/java/com/riiablo/console/Console.java +++ b/core/src/main/java/com/riiablo/console/Console.java @@ -2,20 +2,19 @@ package com.riiablo.console; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; +import org.apache.commons.lang3.Validate; import com.badlogic.gdx.Application; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputProcessor; + import com.riiablo.util.StringUtils; -import org.apache.commons.lang3.Validate; - -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; - public class Console implements InputProcessor { private static final int INITIAL_BUFFER_CAPACITY = 128; @@ -207,7 +206,7 @@ public class Console implements InputProcessor { } @Override - public boolean scrolled(int amount) { + public boolean scrolled(float amountX, float amountY) { return false; } diff --git a/core/src/main/java/com/riiablo/console/RenderedConsole.java b/core/src/main/java/com/riiablo/console/RenderedConsole.java index b2999cc5..23a53935 100644 --- a/core/src/main/java/com/riiablo/console/RenderedConsole.java +++ b/core/src/main/java/com/riiablo/console/RenderedConsole.java @@ -295,24 +295,19 @@ public class RenderedConsole extends Console implements Disposable, InputProcess } @Override - public boolean scrolled(int amount) { + public boolean scrolled(float amountX, float amountY) { if (!visible) return false; - switch (amount) { - case -1: - if (scrollOffset > 0) { - scrollOffset--; - } - break; - case 1: - if (scrollOffset < OUTPUT.size) { - scrollOffset++; - } - break; - default: - Gdx.app.error(TAG, "Unexpected scroll amount: " + amount); + if (amountY < 0) { + if (scrollOffset > 0) { + scrollOffset--; + } + } else { + if (scrollOffset < OUTPUT.size) { + scrollOffset++; + } } - super.scrolled(amount); + super.scrolled(amountX, amountY); return true; } diff --git a/core/src/main/java/com/riiablo/mpq/util/ADPCM.java b/core/src/main/java/com/riiablo/mpq/util/ADPCM.java index 5b06585d..5db5ec84 100644 --- a/core/src/main/java/com/riiablo/mpq/util/ADPCM.java +++ b/core/src/main/java/com/riiablo/mpq/util/ADPCM.java @@ -39,14 +39,19 @@ public class ADPCM { byte stepIndex; } - private static final Pool POOL = new Pool(8, 64, true) { - @Override - protected Channel[] newObject() { - final Channel[] channels = new Channel[CHANNELS]; - for (int i = 0; i < CHANNELS; i++) channels[i] = new Channel(); - return channels; - } - }; + private static final Pool POOL; + static { + final int initialCapacity = 8, max = 64; + POOL = new Pool(initialCapacity, max) { + @Override + protected Channel[] newObject() { + final Channel[] channels = new Channel[CHANNELS]; + for (int i = 0; i < CHANNELS; i++) channels[i] = new Channel(); + return channels; + } + }; + POOL.fill(initialCapacity); + } public static void decompress(ByteBuffer in, ByteBuffer out, int numChannels) { Channel[] channels = POOL.obtain(); diff --git a/core/src/main/java/com/riiablo/mpq_bytebuf/util/Exploder.java b/core/src/main/java/com/riiablo/mpq_bytebuf/util/Exploder.java index 95619f9d..f904ef55 100644 --- a/core/src/main/java/com/riiablo/mpq_bytebuf/util/Exploder.java +++ b/core/src/main/java/com/riiablo/mpq_bytebuf/util/Exploder.java @@ -159,11 +159,16 @@ public final class Exploder { } } - private static final Pool BYTES = new Pool(1, 8, true) { - @Override - protected byte[] newObject() { - return new byte[0x1000]; - } + private static final Pool BYTES; + static { + final int initialCapacity = 1, max = 8; + BYTES = new Pool(initialCapacity, max) { + @Override + protected byte[] newObject() { + return new byte[0x1000]; + } + }; + BYTES.fill(initialCapacity); }; public static ByteBuf pkexplode(final ByteBuf inout) { diff --git a/core/src/main/java/com/riiablo/screen/GameScreen.java b/core/src/main/java/com/riiablo/screen/GameScreen.java index 963043b0..dadf30cf 100644 --- a/core/src/main/java/com/riiablo/screen/GameScreen.java +++ b/core/src/main/java/com/riiablo/screen/GameScreen.java @@ -445,21 +445,15 @@ public class GameScreen extends ScreenAdapter implements GameLoadingScreen.Loada private final float ZOOM_AMOUNT = 0.1f; @Override - public boolean scrolled(int amount) { - switch (amount) { - case -1: - if (UIUtils.ctrl()) { - renderer.zoom(Math.max(0.20f, renderer.zoom() - ZOOM_AMOUNT)); - } - - break; - case 1: - if (UIUtils.ctrl()) { - renderer.zoom(Math.min(5.00f, renderer.zoom() + ZOOM_AMOUNT)); - } - - break; - default: + public boolean scrolled(float amountX, float amountY) { + if (amountY < 0) { + if (UIUtils.ctrl()) { + renderer.zoom(Math.max(0.20f, renderer.zoom() - ZOOM_AMOUNT)); + } + } else { + if (UIUtils.ctrl()) { + renderer.zoom(Math.min(5.00f, renderer.zoom() + ZOOM_AMOUNT)); + } } return true; diff --git a/core/src/main/java/com/riiablo/widget/ScrollPane.java b/core/src/main/java/com/riiablo/widget/ScrollPane.java index 2f5927df..2d37fac6 100644 --- a/core/src/main/java/com/riiablo/widget/ScrollPane.java +++ b/core/src/main/java/com/riiablo/widget/ScrollPane.java @@ -86,6 +86,7 @@ public class ScrollPane extends WidgetGroup { addCaptureListener(new InputListener() { private float handlePosition; + @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { if (draggingPointer != -1) return false; if (pointer == 0 && button != 0) return false; @@ -124,11 +125,13 @@ public class ScrollPane extends WidgetGroup { return false; } + @Override public void touchUp (InputEvent event, float x, float y, int pointer, int button) { if (pointer != draggingPointer) return; cancel(); } + @Override public void touchDragged (InputEvent event, float x, float y, int pointer) { if (pointer != draggingPointer) return; if (touchScrollH) { @@ -152,6 +155,7 @@ public class ScrollPane extends WidgetGroup { } } + @Override public boolean mouseMoved (InputEvent event, float x, float y) { if (!flickScroll) setScrollbarsVisible(true); return false; @@ -159,6 +163,7 @@ public class ScrollPane extends WidgetGroup { }); flickScrollListener = new ActorGestureListener() { + @Override public void pan (InputEvent event, float x, float y, float deltaX, float deltaY) { setScrollbarsVisible(true); amountX -= deltaX; @@ -167,6 +172,7 @@ public class ScrollPane extends WidgetGroup { if (cancelTouchFocus && ((scrollX && deltaX != 0) || (scrollY && deltaY != 0))) cancelTouchFocus(); } + @Override public void fling (InputEvent event, float x, float y, int button) { if (Math.abs(x) > 150 && scrollX) { flingTimer = flingTime; @@ -180,6 +186,7 @@ public class ScrollPane extends WidgetGroup { } } + @Override public boolean handle (Event event) { if (super.handle(event)) { if (((InputEvent)event).getType() == InputEvent.Type.touchDown) flingTimer = 0; @@ -192,12 +199,13 @@ public class ScrollPane extends WidgetGroup { addListener(flickScrollListener); addListener(new InputListener() { - public boolean scrolled (InputEvent event, float x, float y, int amount) { + @Override + public boolean scrolled (InputEvent event, float x, float y, float amountX, float amountY) { setScrollbarsVisible(true); if (scrollY) - setScrollY(amountY + getMouseWheelY() * amount); + setScrollY(amountY + getMouseWheelY() * amountY); else if (scrollX) // - setScrollX(amountX + getMouseWheelX() * amount); + setScrollX(amountX + getMouseWheelX() * amountY); else return false; return true; @@ -252,6 +260,7 @@ public class ScrollPane extends WidgetGroup { return style; } + @Override public void act (float delta) { super.act(delta); @@ -350,6 +359,7 @@ public class ScrollPane extends WidgetGroup { } } + @Override public void layout () { final Drawable bg = style.background; final Drawable hScrollKnob = style.hScrollKnob; @@ -627,6 +637,7 @@ public class ScrollPane extends WidgetGroup { this.velocityY = velocityY; } + @Override public float getPrefWidth () { if (widget instanceof Layout) { float width = ((Layout)widget).getPrefWidth(); @@ -642,6 +653,7 @@ public class ScrollPane extends WidgetGroup { return 150; } + @Override public float getPrefHeight () { if (widget instanceof Layout) { float height = ((Layout)widget).getPrefHeight(); @@ -657,10 +669,12 @@ public class ScrollPane extends WidgetGroup { return 150; } + @Override public float getMinWidth () { return 0; } + @Override public float getMinHeight () { return 0; } @@ -691,28 +705,33 @@ public class ScrollPane extends WidgetGroup { /** @deprecated ScrollPane may have only a single child. * @see #setWidget(Actor) */ + @Override public void addActor (Actor actor) { throw new UnsupportedOperationException("Use ScrollPane#setWidget."); } /** @deprecated ScrollPane may have only a single child. * @see #setWidget(Actor) */ + @Override public void addActorAt (int index, Actor actor) { throw new UnsupportedOperationException("Use ScrollPane#setWidget."); } /** @deprecated ScrollPane may have only a single child. * @see #setWidget(Actor) */ + @Override public void addActorBefore (Actor actorBefore, Actor actor) { throw new UnsupportedOperationException("Use ScrollPane#setWidget."); } /** @deprecated ScrollPane may have only a single child. * @see #setWidget(Actor) */ + @Override public void addActorAfter (Actor actorAfter, Actor actor) { throw new UnsupportedOperationException("Use ScrollPane#setWidget."); } + @Override public boolean removeActor (Actor actor) { if (actor == null) throw new IllegalArgumentException("actor cannot be null."); if (actor != widget) return false; @@ -720,6 +739,7 @@ public class ScrollPane extends WidgetGroup { return true; } + @Override public boolean removeActor (Actor actor, boolean unfocus) { if (actor == null) throw new IllegalArgumentException("actor cannot be null."); if (actor != widget) return false; @@ -727,6 +747,7 @@ public class ScrollPane extends WidgetGroup { return super.removeActor(actor, unfocus); } + @Override public Actor hit (float x, float y, boolean touchable) { if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) return null; if (touchable && getTouchable() == Touchable.enabled && isVisible()) { @@ -1078,6 +1099,7 @@ public class ScrollPane extends WidgetGroup { this.cancelTouchFocus = cancelTouchFocus; } + @Override public void drawDebug (ShapeRenderer shapes) { shapes.flush(); applyTransform(shapes, computeTransform()); diff --git a/gradle.properties b/gradle.properties index 664224dc..e5b52d36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.configureondemand=false androidBuildToolsPluginVersion=4.0.1 flatbuffersPluginVersion=1.0.7 -gdxVersion=1.9.11 +gdxVersion=1.9.13 artemisOdbVersion=2.3.0 artemisContribVersion=2.4.0 gdxAiVersion=1.8.2 diff --git a/tools/camera/src/main/java/com/riiablo/camera/CameraTool.java b/tools/camera/src/main/java/com/riiablo/camera/CameraTool.java index 2dbbb434..a78a96b2 100644 --- a/tools/camera/src/main/java/com/riiablo/camera/CameraTool.java +++ b/tools/camera/src/main/java/com/riiablo/camera/CameraTool.java @@ -66,10 +66,10 @@ public class CameraTool extends Tool { Gdx.input.setInputProcessor(new InputAdapter() { @Override - public boolean scrolled(int amount) { - iso.zoom += (amount * 0.05); + public boolean scrolled(float amountX, float amountY) { + iso.zoom += (amountY * 0.05); iso.zoom = MathUtils.clamp(iso.zoom, 0.05f, 2f); - return super.scrolled(amount); + return super.scrolled(amountX, amountY); } @Override diff --git a/tools/ds1-viewer/src/main/java/com/riiablo/map/DS1Viewer.java b/tools/ds1-viewer/src/main/java/com/riiablo/map/DS1Viewer.java index a86ff7b7..b3a2f0a6 100644 --- a/tools/ds1-viewer/src/main/java/com/riiablo/map/DS1Viewer.java +++ b/tools/ds1-viewer/src/main/java/com/riiablo/map/DS1Viewer.java @@ -1,5 +1,9 @@ package com.riiablo.map; +import com.kotcrab.vis.ui.VisUI; +import com.kotcrab.vis.ui.widget.VisSelectBox; +import com.kotcrab.vis.ui.widget.VisTable; + import com.badlogic.gdx.Application; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; @@ -24,9 +28,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.GdxRuntimeException; -import com.kotcrab.vis.ui.VisUI; -import com.kotcrab.vis.ui.widget.VisSelectBox; -import com.kotcrab.vis.ui.widget.VisTable; + import com.riiablo.COFs; import com.riiablo.Files; import com.riiablo.Palettes; @@ -40,7 +42,6 @@ import com.riiablo.codec.excel.LvlTypes; import com.riiablo.graphics.PaletteIndexedBatch; import com.riiablo.loader.COFLoader; import com.riiablo.loader.DCCLoader; -import com.riiablo.loader.TXTLoader; import com.riiablo.mpq.MPQFileHandleResolver; public class DS1Viewer extends ApplicationAdapter { @@ -199,15 +200,11 @@ public class DS1Viewer extends ApplicationAdapter { private final float ZOOM_AMOUNT = 0.1f; @Override - public boolean scrolled(int amount) { - switch (amount) { - case -1: - camera.zoom = Math.max(0.25f, camera.zoom - ZOOM_AMOUNT); - break; - case 1: - camera.zoom = Math.min(10.0f, camera.zoom + ZOOM_AMOUNT); - break; - default: + public boolean scrolled(float amountX, float amountY) { + if (amountY < 0) { + camera.zoom = Math.max(0.25f, camera.zoom - ZOOM_AMOUNT); + } else { + camera.zoom = Math.min(10.0f, camera.zoom + ZOOM_AMOUNT); } camera.update(); diff --git a/tools/map-viewer/src/main/java/com/riiablo/map/MapViewer.java b/tools/map-viewer/src/main/java/com/riiablo/map/MapViewer.java index ad0ebbec..8e101a11 100644 --- a/tools/map-viewer/src/main/java/com/riiablo/map/MapViewer.java +++ b/tools/map-viewer/src/main/java/com/riiablo/map/MapViewer.java @@ -430,15 +430,11 @@ public class MapViewer extends Tool { private final float ZOOM_AMOUNT = 0.1f; @Override - public boolean scrolled(int amount) { - switch (amount) { - case -1: - mapRenderer.zoom(Math.max(0.20f, mapRenderer.zoom() - ZOOM_AMOUNT)); - break; - case 1: - mapRenderer.zoom(Math.min(2.50f, mapRenderer.zoom() + ZOOM_AMOUNT)); - break; - default: + public boolean scrolled(float amountX, float amountY) { + if (amountX < 0) { + mapRenderer.zoom(Math.max(0.20f, mapRenderer.zoom() - ZOOM_AMOUNT)); + } else { + mapRenderer.zoom(Math.min(2.50f, mapRenderer.zoom() + ZOOM_AMOUNT)); } return true; }