From 43e6eae12a156f94891538b9f87fe31a6b9bc7c4 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sat, 23 Mar 2019 03:26:15 -0700 Subject: [PATCH] Improved item drop labels Improved item drop labels Created Item Details header table Changed Entity label to be an Actor Changed ItemHolder label to the item details header Added copy constructor to Label --- core/src/com/riiablo/entity/Entity.java | 13 +++++++++---- core/src/com/riiablo/entity/ItemHolder.java | 1 + core/src/com/riiablo/item/Item.java | 10 ++++++++++ core/src/com/riiablo/widget/Label.java | 5 +++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/core/src/com/riiablo/entity/Entity.java b/core/src/com/riiablo/entity/Entity.java index b0a9c71d..0fbc0bdb 100644 --- a/core/src/com/riiablo/entity/Entity.java +++ b/core/src/com/riiablo/entity/Entity.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ObjectIntMap; @@ -235,7 +236,7 @@ public abstract class Entity implements Animation.AnimationListener { Animation animation; String name; - Label label; + Actor label; boolean over; byte nextMode = -1; @@ -282,10 +283,11 @@ public abstract class Entity implements Animation.AnimationListener { invalidate(); // TODO: lazy init - label = new Label(Riiablo.fonts.font16); + Label label = new Label(Riiablo.fonts.font16); label.setUserObject(this); label.setAlignment(Align.center); label.getStyle().background = Label.MODAL; + this.label = label; } public void setMode(byte mode) { @@ -593,10 +595,13 @@ public abstract class Entity implements Animation.AnimationListener { } public void name(String name) { - label.setText(this.name = name); + this.name = name; + if (label instanceof Label) { + ((Label) label).setText(name); + } } - public Label getLabel() { + public Actor getLabel() { return label; } diff --git a/core/src/com/riiablo/entity/ItemHolder.java b/core/src/com/riiablo/entity/ItemHolder.java index 6c7d064d..3fc8be4d 100644 --- a/core/src/com/riiablo/entity/ItemHolder.java +++ b/core/src/com/riiablo/entity/ItemHolder.java @@ -22,6 +22,7 @@ public class ItemHolder extends Entity { super(Type.ITM, "item", null); this.item = item; name(item.getName()); + label = item.details.header; flippyDescriptor = new AssetDescriptor<>(Type.ITM.PATH + "\\" + item.getFlippyFile() + ".dc6", DC6.class); } diff --git a/core/src/com/riiablo/item/Item.java b/core/src/com/riiablo/item/Item.java index 6c5e014c..eb321ff2 100644 --- a/core/src/com/riiablo/item/Item.java +++ b/core/src/com/riiablo/item/Item.java @@ -775,6 +775,8 @@ public class Item extends Actor implements Disposable { public class Details extends Table { private static final float SPACING = 2; + public final Table header; + Label name; Label type; Label usable; @@ -819,6 +821,14 @@ public class Item extends Actor implements Disposable { if (quality.ordinal() > Quality.MAGIC.ordinal() || (flags & RUNEWORD) == RUNEWORD) add(type).center().space(SPACING).row(); + header = new Table() {{ + setBackground(PaletteIndexedColorDrawable.MODAL_FONT16); + add(new Label(name)).center().space(SPACING).row(); + if (quality.ordinal() > Quality.MAGIC.ordinal() || (flags & RUNEWORD) == RUNEWORD) + add(new Label(type)).center().space(SPACING).row(); + pack(); + }}; + if (socketed.size > 0) { String runequote = Riiablo.string.lookup("RuneQuote"); StringBuilder runewordBuilder = null; diff --git a/core/src/com/riiablo/widget/Label.java b/core/src/com/riiablo/widget/Label.java index 3cf596a3..852f2579 100644 --- a/core/src/com/riiablo/widget/Label.java +++ b/core/src/com/riiablo/widget/Label.java @@ -42,6 +42,11 @@ public class Label extends com.badlogic.gdx.scenes.scene2d.ui.Label { this(null, font); } + public Label(Label src) { + super(src.getText(), src.getStyle()); + setColor(src.getColor()); + } + @Override public void draw(Batch batch, float a) { if (batch instanceof PaletteIndexedBatch) {