From 2e77266cd02ab820b51964ef2d662ae92e301b7f Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sat, 16 Mar 2019 00:27:03 -0700 Subject: [PATCH] Added spell details label Added spell details label Created static ref to font16 modal background Added constructor to Label that takes in a Color too --- .../graphics/PaletteIndexedColorDrawable.java | 7 ++++ core/src/com/riiablo/item/Item.java | 11 +----- core/src/com/riiablo/panel/SpellsPanel.java | 35 +++++++++++++++++-- core/src/com/riiablo/widget/Label.java | 5 +++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/core/src/com/riiablo/graphics/PaletteIndexedColorDrawable.java b/core/src/com/riiablo/graphics/PaletteIndexedColorDrawable.java index 90b748c0..b31db979 100644 --- a/core/src/com/riiablo/graphics/PaletteIndexedColorDrawable.java +++ b/core/src/com/riiablo/graphics/PaletteIndexedColorDrawable.java @@ -6,6 +6,13 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; import com.riiablo.Riiablo; public class PaletteIndexedColorDrawable extends TextureRegionDrawable { + public static final PaletteIndexedColorDrawable MODAL_FONT16 = new PaletteIndexedColorDrawable(Riiablo.colors.modal75) {{ + final float PADDING = 6; + setLeftWidth(PADDING); + setTopHeight(PADDING - 2); // font16 has extra top padding, changing this would require propagating elsewhere + setRightWidth(PADDING); + setBottomHeight(PADDING); + }}; public Color tint; diff --git a/core/src/com/riiablo/item/Item.java b/core/src/com/riiablo/item/Item.java index 95c25b07..7ae04cdb 100644 --- a/core/src/com/riiablo/item/Item.java +++ b/core/src/com/riiablo/item/Item.java @@ -642,22 +642,13 @@ public class Item extends Actor implements Disposable { public class Details extends Table { private static final float SPACING = 2; - private static final float PADDING = 6; Label name; Label type; Label usable; Details() { - // TODO: Change this to a static object ref - setBackground(new PaletteIndexedColorDrawable(Riiablo.colors.modal75) {{ - setLeftWidth(PADDING); - setTopHeight(PADDING - 2); // font16 has extra top padding, changing this would require propagating elsewhere - setRightWidth(PADDING); - setBottomHeight(PADDING); - }}); - //pad(PADDING); - + setBackground(PaletteIndexedColorDrawable.MODAL_FONT16); BitmapFont font = Riiablo.fonts.font16; name = new Label(Item.this.getName(), font); type = new Label(Riiablo.string.lookup(base.namestr), font); diff --git a/core/src/com/riiablo/panel/SpellsPanel.java b/core/src/com/riiablo/panel/SpellsPanel.java index 8b19560c..f3a91062 100644 --- a/core/src/com/riiablo/panel/SpellsPanel.java +++ b/core/src/com/riiablo/panel/SpellsPanel.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Touchable; +import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; @@ -16,12 +17,17 @@ import com.riiablo.codec.DC; import com.riiablo.codec.DC6; import com.riiablo.codec.excel.SkillDesc; import com.riiablo.codec.excel.Skills; +import com.riiablo.graphics.PaletteIndexedBatch; +import com.riiablo.graphics.PaletteIndexedColorDrawable; import com.riiablo.loader.DC6Loader; import com.riiablo.screen.GameScreen; import com.riiablo.widget.Button; import com.riiablo.widget.Label; import com.riiablo.widget.LabelButton; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + public class SpellsPanel extends WidgetGroup implements Disposable { private static final String TAG = "SpellsPanel"; private static final String SPELLS_PATH = "data\\global\\ui\\SPELLS\\"; @@ -126,17 +132,40 @@ public class SpellsPanel extends WidgetGroup implements Disposable { Label skillsRemaining = new Label("0", Riiablo.fonts.font16); skillsRemaining.setAlignment(Align.center); skillsRemaining.setSize(40, 21); - skillsRemaining.setPosition(256, 348); + skillsRemaining.setPosition(256, 348); // 276, 359 middle addActor(skillsRemaining); float[] X = { 0, 15, 84, 153 }; float[] Y = { 0, 370, 302, 234, 166, 98, 30 }; for (int i = charClass.firstSpell; i < charClass.lastSpell; i++) { Skills.Entry skill = Riiablo.files.skills.get(i); - SkillDesc.Entry desc = Riiablo.files.skilldesc.get(skill.skilldesc); + final SkillDesc.Entry desc = Riiablo.files.skilldesc.get(skill.skilldesc); + final Table details = new Table() {{ + final float SPACING = 2; + setBackground(PaletteIndexedColorDrawable.MODAL_FONT16); + add(new Label(Riiablo.string.lookup(desc.str_name), Riiablo.fonts.font16, Riiablo.colors.green)).center().space(SPACING).row(); + add(new Label(Riiablo.fonts.font16) {{ + // TODO: It might possible to optimize this more -- goal is to reverse lines since they are backwards for some reason + String text = Riiablo.string.lookup(desc.str_long); + String[] lines = StringUtils.split(text, '\n'); + ArrayUtils.reverse(lines); + text = StringUtils.join(lines, '\n'); + setText(text); + setAlignment(Align.center); + }}).center().space(SPACING).row(); + pack(); + }}; Button button = new Button(new Button.ButtonStyle( new TextureRegionDrawable(Skillicon.getTexture(desc.IconCel)), - new TextureRegionDrawable(Skillicon.getTexture(desc.IconCel + 1)))); + new TextureRegionDrawable(Skillicon.getTexture(desc.IconCel + 1)))) { + @Override + public void draw(PaletteIndexedBatch batch, float parentAlpha) { + super.draw(batch, parentAlpha); + if (isOver()) { + gameScreen.setDetails(details, null, SpellsPanel.this, this); + } + } + }; button.setPosition(X[desc.SkillColumn], Y[desc.SkillRow]); //button.setSize(48, 48); diff --git a/core/src/com/riiablo/widget/Label.java b/core/src/com/riiablo/widget/Label.java index e1955b7a..3cf596a3 100644 --- a/core/src/com/riiablo/widget/Label.java +++ b/core/src/com/riiablo/widget/Label.java @@ -33,6 +33,11 @@ public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label { super(text, new LabelStyle(font, null)); } + public Label(String text, BitmapFont font, Color color) { + this(text, font); + setColor(color); + } + public Label(BitmapFont font) { this(null, font); }