From 6734c9a6149999b788f020ba6f95362a70dc4ecc Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Tue, 19 Mar 2019 20:34:44 -0700 Subject: [PATCH] Implemented SpellsQuickPanel changes to MobileControls buttons --- .../src/com/riiablo/panel/MobileControls.java | 22 +++++++------------ .../com/riiablo/panel/SpellsQuickPanel.java | 15 +++++++------ core/src/com/riiablo/screen/GameScreen.java | 4 ++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/core/src/com/riiablo/panel/MobileControls.java b/core/src/com/riiablo/panel/MobileControls.java index c1af90c4..c9c77fd9 100644 --- a/core/src/com/riiablo/panel/MobileControls.java +++ b/core/src/com/riiablo/panel/MobileControls.java @@ -16,6 +16,7 @@ import com.riiablo.codec.DC6; import com.riiablo.entity.Entity; import com.riiablo.screen.GameScreen; import com.riiablo.widget.Button; +import com.riiablo.widget.HotkeyButton; public class MobileControls extends WidgetGroup implements Disposable { final AssetDescriptor SkilliconDescriptor = new AssetDescriptor<>("data\\global\\ui\\SPELLS\\Skillicon.DC6", DC6.class); @@ -27,7 +28,7 @@ public class MobileControls extends WidgetGroup implements Disposable { GameScreen gameScreen; Button interact; - Button skills[]; + HotkeyButton skills[]; final float SIZE = 64; @@ -63,23 +64,14 @@ public class MobileControls extends WidgetGroup implements Disposable { } }); - skills = new Button[3]; - skills[0] = new Button(new Button.ButtonStyle() {{ - up = new TextureRegionDrawable(SoSkillicon.getTexture(36)); - down = new TextureRegionDrawable(SoSkillicon.getTexture(37)); - }}); + skills = new HotkeyButton[3]; + skills[0] = new HotkeyButton(Skillicon, 0); skills[0].setSize(SIZE, SIZE); - skills[1] = new Button(new Button.ButtonStyle() {{ - up = new TextureRegionDrawable(Skillicon.getTexture(0)); - down = new TextureRegionDrawable(Skillicon.getTexture(1)); - }}); + skills[1] = new HotkeyButton(Skillicon, 0); skills[1].setSize(SIZE, SIZE); - skills[2] = new Button(new Button.ButtonStyle() {{ - up = new TextureRegionDrawable(Skillicon.getTexture(0)); - down = new TextureRegionDrawable(Skillicon.getTexture(1)); - }}); + skills[2] = new HotkeyButton(Skillicon, 0); skills[2].setSize(SIZE, SIZE); ActorGestureListener gestureListener = new ActorGestureListener() { @@ -90,6 +82,8 @@ public class MobileControls extends WidgetGroup implements Disposable { SpellsQuickPanel spellsQuickPanel = gameScreen.spellsQuickPanelR; final boolean visible = !spellsQuickPanel.isVisible(); if (visible) { + HotkeyButton dst = (HotkeyButton) actor; + spellsQuickPanel.setObserver(dst); // FIXME: Scale this better tmpVec2.set(actor.getWidth(), actor.getHeight()); actor.localToStageCoordinates(tmpVec2); diff --git a/core/src/com/riiablo/panel/SpellsQuickPanel.java b/core/src/com/riiablo/panel/SpellsQuickPanel.java index 41f4a418..1046fec5 100644 --- a/core/src/com/riiablo/panel/SpellsQuickPanel.java +++ b/core/src/com/riiablo/panel/SpellsQuickPanel.java @@ -54,9 +54,11 @@ public class SpellsQuickPanel extends Table implements Disposable { GameScreen gameScreen; ObjectMap keyMappings; MappedKeyStateAdapter mappedKeyListener; + HotkeyButton observer; - public SpellsQuickPanel(final GameScreen gameScreen, final boolean leftSkills) { + public SpellsQuickPanel(final GameScreen gameScreen, final HotkeyButton o, final boolean leftSkills) { this.gameScreen = gameScreen; + this.observer = o; Riiablo.assets.load(SkilliconDescriptor); Riiablo.assets.finishLoadingAsset(SkilliconDescriptor); @@ -112,12 +114,7 @@ public class SpellsQuickPanel extends Table implements Disposable { button.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - ControlPanel controlPanel = gameScreen.controlPanel; - if (leftSkills) { - controlPanel.getLeftSkill().copy(button); - } else { - controlPanel.getRightSkill().copy(button); - } + observer.copy(button); SpellsQuickPanel.this.setVisible(false); } }); @@ -156,6 +153,10 @@ public class SpellsQuickPanel extends Table implements Disposable { for (MappedKey Skill : Keys.Skill) Skill.addStateListener(mappedKeyListener); } + public void setObserver(HotkeyButton observer) { + this.observer = observer; + } + @Override public void dispose() { for (MappedKey Skill : Keys.Skill) Skill.removeStateListener(mappedKeyListener); diff --git a/core/src/com/riiablo/screen/GameScreen.java b/core/src/com/riiablo/screen/GameScreen.java index 0d2e1005..0f8923d5 100644 --- a/core/src/com/riiablo/screen/GameScreen.java +++ b/core/src/com/riiablo/screen/GameScreen.java @@ -235,11 +235,11 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable 0, stage.getHeight() - stashPanel.getHeight()); - spellsQuickPanelL = new SpellsQuickPanel(this, true); + spellsQuickPanelL = new SpellsQuickPanel(this, controlPanel.getLeftSkill(), true); spellsQuickPanelL.setPosition(0, 100, Align.bottomLeft); spellsQuickPanelL.setVisible(false); - spellsQuickPanelR = new SpellsQuickPanel(this, false); + spellsQuickPanelR = new SpellsQuickPanel(this, controlPanel.getRightSkill(), false); spellsQuickPanelR.setPosition(stage.getWidth(), 100, Align.bottomRight); spellsQuickPanelR.setVisible(false);