diff --git a/core/src/com/riiablo/item/Item.java b/core/src/com/riiablo/item/Item.java index 6dc97c44..a45ad8ac 100644 --- a/core/src/com/riiablo/item/Item.java +++ b/core/src/com/riiablo/item/Item.java @@ -10,6 +10,8 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.GdxRuntimeException; +import com.badlogic.gdx.utils.IntMap; +import com.badlogic.gdx.utils.IntSet; import com.riiablo.Riiablo; import com.riiablo.codec.DC6; import com.riiablo.codec.Index; @@ -780,6 +782,41 @@ public class Item extends Actor implements Disposable { for (int i = 0; i < stats.length; i++) { Array stats = Item.this.stats[i]; if (stats == null) continue; + + // TODO: This can be cleaned up later + IntMap> groups = new IntMap<>(); + for (Stat.Instance stat : stats) { + int dgrp = stat.stat.entry().dgrp; + if (dgrp > 0) { + Array group = groups.get(dgrp); + if (group == null) groups.put(dgrp, group = new Array<>()); + group.add(stat); + } + } + + IntSet groupReplaced = new IntSet(); + IntMap groupReplacements = new IntMap<>(); + for (IntMap.Entry> group : groups) { + switch (group.key) { + case 1: + case 2: + if (group.value.size == 4) { + boolean allEqual = true; + Stat.Instance first = group.value.first(); + for (int j = 1; allEqual && j < group.value.size; j++) { + Stat.Instance stat = group.value.get(j); + allEqual = (stat.value == first.value) && (stat.param == first.param); + } + + if (allEqual) { + groupReplacements.put(group.key, first); + } + } + break; + default: + } + } + stats.sort(new Comparator() { @Override public int compare(Stat.Instance o1, Stat.Instance o2) { @@ -788,7 +825,20 @@ public class Item extends Actor implements Disposable { }); for (Stat.Instance stat : stats) { - Label label = new Label(stat.format(), font); + Label label; + int dgrp = stat.stat.entry().dgrp; + boolean group = false; + if (dgrp > 0) { + if (groupReplaced.contains(dgrp)) continue; + Stat.Instance grp = groupReplacements.get(dgrp); + if (grp != null) { + stat = grp; + group = true; + groupReplaced.add(dgrp); + } + } + + label = new Label(stat.format(group), font); add(label).center().space(SPACING).row(); } } diff --git a/core/src/com/riiablo/item/Stat.java b/core/src/com/riiablo/item/Stat.java index ca84bc58..f69357ae 100644 --- a/core/src/com/riiablo/item/Stat.java +++ b/core/src/com/riiablo/item/Stat.java @@ -424,12 +424,12 @@ public enum Stat { this.param = param; } - public String format() { + public String format(boolean group) { CharStats.Entry entry; Skills.Entry skill; SkillDesc.Entry desc; - switch (stat.entry.descfunc) { - case 1: return String.format("+%d %s", value, descstr()); + switch (group ? stat.entry.dgrpfunc : stat.entry.descfunc) { + case 1: return String.format("+%d %s", value, descstr(group)); case 2: return String.format("%d%% %s", value, descstr()); case 3: return String.format("%d %s", value, descstr()); case 4: return String.format("+%d%% %s", value, descstr()); @@ -455,6 +455,7 @@ public enum Stat { skill = Riiablo.files.skills.get(param); desc = Riiablo.files.skilldesc.get(skill.skilldesc); return Riiablo.string.format(stat.entry.descstrpos, value, Riiablo.string.lookup(desc.str_name)); + case 19: return String.format(descstr(group), value); case 20: return String.format("%d%% %s", -value, descstr()); case 22: return toString(); case 23: return toString(); @@ -483,6 +484,14 @@ public enum Stat { return Riiablo.string.lookup(value < 0 ? stat.entry.descstrneg : stat.entry.descstrpos); } + private String descstr(boolean group) { + if (group) { + return Riiablo.string.lookup(value < 0 ? stat.entry.dgrpstrneg : stat.entry.dgrpstrpos); + } else { + return Riiablo.string.lookup(value < 0 ? stat.entry.descstrneg : stat.entry.descstrpos); + } + } + private String descstr2() { return Riiablo.string.lookup(stat.entry.descstr2); }