From 652b748553ad98d5ee11a00e7f01e71bed6e15fd Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Fri, 12 Apr 2019 01:56:50 -0700 Subject: [PATCH] Added support for dynamic spell quickpanel --- core/src/com/riiablo/CharData.java | 17 ++++ .../com/riiablo/panel/SpellsQuickPanel.java | 78 ++++++++++--------- 2 files changed, 60 insertions(+), 35 deletions(-) diff --git a/core/src/com/riiablo/CharData.java b/core/src/com/riiablo/CharData.java index 06f1e911..0cd9ad88 100644 --- a/core/src/com/riiablo/CharData.java +++ b/core/src/com/riiablo/CharData.java @@ -31,6 +31,7 @@ public class CharData { private final EnumMap equipped = new EnumMap<>(BodyLoc.class); private final Array belt = new Array<>(16); private final Array EQUIPPED_LISTENERS = new Array<>(); + private final Array SKILLS_LISTENERS = new Array<>(); private final IntIntMap equippedSets = new IntIntMap(); // Indexed using set id private final IntIntMap setItemsOwned = new IntIntMap(); // Indexed using set item id @@ -159,6 +160,7 @@ public class CharData { for (int spellId = charClass.firstSpell, i = 0; spellId < charClass.lastSpell; spellId++, i++) { skills.put(spellId, d2s.skills.data[i]); } + notifySkillsChanged(skills); } public CharacterClass getCharacterClass() { @@ -195,6 +197,7 @@ public class CharData { skills.getAndIncrement(stat.param, 0, stat.value()); } } + notifySkillsChanged(skills); System.out.println("Skills:"); for (IntIntMap.Entry skill : skills) { @@ -376,4 +379,18 @@ public class CharData { @Override public void onChanged(CharData client, BodyLoc bodyLoc, Item oldItem, Item item) {} @Override public void onAlternated(CharData client, int alternate, Item LH, Item RH) {} } + + private void notifySkillsChanged(IntIntMap skills) { + for (SkillsListener l : SKILLS_LISTENERS) l.onChanged(this, skills); + } + + public boolean addSkillsListener(SkillsListener l) { + SKILLS_LISTENERS.add(l); + l.onChanged(this, skills); + return true; + } + + public interface SkillsListener { + void onChanged(CharData client, IntIntMap skills); + } } diff --git a/core/src/com/riiablo/panel/SpellsQuickPanel.java b/core/src/com/riiablo/panel/SpellsQuickPanel.java index 71d103ba..2840cf9f 100644 --- a/core/src/com/riiablo/panel/SpellsQuickPanel.java +++ b/core/src/com/riiablo/panel/SpellsQuickPanel.java @@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.IntIntMap; import com.badlogic.gdx.utils.ObjectMap; +import com.riiablo.CharData; import com.riiablo.CharacterClass; import com.riiablo.Keys; import com.riiablo.Riiablo; @@ -27,7 +28,7 @@ import com.riiablo.widget.HotkeyButton; import org.apache.commons.lang3.ArrayUtils; -public class SpellsQuickPanel extends Table implements Disposable { +public class SpellsQuickPanel extends Table implements Disposable, CharData.SkillsListener { private static final String SPELLS_PATH = "data\\global\\ui\\SPELLS\\"; final AssetDescriptor SkilliconDescriptor = new AssetDescriptor<>("data\\global\\ui\\SPELLS\\Skillicon.DC6", DC6.class); @@ -58,10 +59,14 @@ public class SpellsQuickPanel extends Table implements Disposable { ObjectMap keyMappings; MappedKeyStateAdapter mappedKeyListener; HotkeyButton observer; + boolean leftSkills; + Table[] tables; + final float SIZE; public SpellsQuickPanel(final GameScreen gameScreen, final HotkeyButton o, final boolean leftSkills) { this.gameScreen = gameScreen; this.observer = o; + this.leftSkills = leftSkills; Riiablo.assets.load(SkilliconDescriptor); Riiablo.assets.finishLoadingAsset(SkilliconDescriptor); @@ -76,7 +81,7 @@ public class SpellsQuickPanel extends Table implements Disposable { CharSkillicon[i] = Riiablo.assets.get(CharSkilliconDescriptor[i]); } - final float SIZE = Gdx.app.getType() == Application.ApplicationType.Android ? 64 : 48; + SIZE = Gdx.app.getType() == Application.ApplicationType.Android ? 64 : 48; CharacterClass charClass = Riiablo.charData.getCharacterClass(); keyMappings = new ObjectMap<>(31); @@ -85,8 +90,42 @@ public class SpellsQuickPanel extends Table implements Disposable { add(new HotkeyButton(Skillicon, 18, -1)).size(SIZE); pack(); }}; - Table[] tables = new Table[5]; - // TODO: Include non-class spells gained from items + tables = new Table[5]; + for (int i = 0; i < tables.length; i++) tables[i] = new Table(); + Table bottom = new Table() {{ + add(new HotkeyButton(Skillicon, 4, -1)).size(SIZE); + add(new HotkeyButton(Skillicon, 6, -1)).size(SIZE); + add(new HotkeyButton(Skillicon, 2, -1)).size(SIZE); + pack(); + }}; + add(top).align(leftSkills ? Align.left : Align.right).row(); + for (int i = tables.length - 1; i >= 0; i--) { + add(tables[i]).align(leftSkills ? Align.left : Align.right).row(); + } + add(bottom).align(leftSkills ? Align.left : Align.right).row(); + pack(); + //setDebug(true, true); + + mappedKeyListener = new MappedKeyStateAdapter() { + @Override + public void onPressed(MappedKey key, int keycode) { + HotkeyButton button = keyMappings.get(key); + if (button == null) return; + // TODO: Assign + ControlPanel controlPanel = gameScreen.controlPanel; + if (leftSkills) { + controlPanel.getLeftSkill().copy(button); + } else { + controlPanel.getRightSkill().copy(button); + } + } + }; + for (MappedKey Skill : Keys.Skill) Skill.addStateListener(mappedKeyListener); + Riiablo.charData.addSkillsListener(this); + } + + @Override + public void onChanged(CharData client, IntIntMap skills) { for (IntIntMap.Entry skillId : Riiablo.charData.getSkills()) { if (skillId.value <= 0) continue; // level <= 0 @@ -96,7 +135,6 @@ public class SpellsQuickPanel extends Table implements Disposable { final SkillDesc.Entry desc = Riiablo.files.skilldesc.get(skill.skilldesc); Table table = tables[desc.ListRow]; - if (table == null) table = tables[desc.ListRow] = new Table(); int iconCel = desc.IconCel; DC icons = getSkillicon(skill.charclass, iconCel); if (icons == null) { @@ -124,37 +162,7 @@ public class SpellsQuickPanel extends Table implements Disposable { }); table.add(button).size(SIZE); } - Table bottom = new Table() {{ - add(new HotkeyButton(Skillicon, 4, -1)).size(SIZE); - add(new HotkeyButton(Skillicon, 6, -1)).size(SIZE); - add(new HotkeyButton(Skillicon, 2, -1)).size(SIZE); - pack(); - }}; - add(top).align(leftSkills ? Align.left : Align.right).row(); - for (int i = tables.length - 1; i >= 0; i--) { - if (tables[i] != null) { - add(tables[i]).align(leftSkills ? Align.left : Align.right).row(); - } - } - add(bottom).align(leftSkills ? Align.left : Align.right).row(); pack(); - //setDebug(true, true); - - mappedKeyListener = new MappedKeyStateAdapter() { - @Override - public void onPressed(MappedKey key, int keycode) { - HotkeyButton button = keyMappings.get(key); - if (button == null) return; - // TODO: Assign - ControlPanel controlPanel = gameScreen.controlPanel; - if (leftSkills) { - controlPanel.getLeftSkill().copy(button); - } else { - controlPanel.getRightSkill().copy(button); - } - } - }; - for (MappedKey Skill : Keys.Skill) Skill.addStateListener(mappedKeyListener); } public void setObserver(HotkeyButton observer) {