diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java index 0d007cc35..69b5223d1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Talent.java @@ -266,7 +266,7 @@ public enum Talent { if (talentBundle.contains(talent.name())){ for (LinkedHashMap tier : hero.talents){ if (tier.containsKey(talent)){ - tier.put(talent, talentBundle.getInt(talent.name())); + tier.put(talent, Math.min(talentBundle.getInt(talent.name()), talent.maxPoints())); } } } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentButton.java index 4d6bfd2ae..4de67e6d8 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentButton.java @@ -61,6 +61,7 @@ public class TalentButton extends Button { this.pointsInTalent = points; this.upgradeEnabled = upgradeEnabled; + bg.frame(20*(talent.maxPoints()-1), 0, WIDTH, HEIGHT); icon.frame( film.get( talent.icon() ) ); } @@ -74,7 +75,7 @@ public class TalentButton extends Button { fill = new ColorBlock(0, 4, 0xFFFFFF44); add(fill); - bg = new Image(Assets.Interfaces.TALENT_BUTTON, 20, 0, WIDTH, HEIGHT); + bg = new Image(Assets.Interfaces.TALENT_BUTTON); add(bg); icon = new Image( icons ); @@ -90,7 +91,7 @@ public class TalentButton extends Button { fill.x = x; fill.y = y + WIDTH - 1; - fill.size( pointsInTalent/2f * WIDTH, 5); + fill.size( pointsInTalent/(float)talent.maxPoints() * WIDTH, 5); bg.x = x; bg.y = y; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentsPane.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentsPane.java index 8b9f047b9..d40e6b6b7 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentsPane.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/TalentsPane.java @@ -33,13 +33,10 @@ import com.watabou.noosa.ui.Component; import java.util.ArrayList; import java.util.LinkedHashMap; -//TODO some stuff here is currently coded without accounting for tiers public class TalentsPane extends ScrollPane { - RenderedTextBlock title; - ArrayList buttons; - - ArrayList stars = new ArrayList<>(); + ArrayList panes = new ArrayList<>(); + ArrayList separators = new ArrayList<>(); ColorBlock sep; ColorBlock blocker; @@ -52,26 +49,24 @@ public class TalentsPane extends ScrollPane { public TalentsPane( boolean canUpgrade, ArrayList> talents ) { super(new Component()); - title = PixelScene.renderTextBlock(Messages.titleCase(Messages.get(this, "tier", 1)), 9); - title.hardlight(Window.TITLE_COLOR); - content.add(title); + //TODO more code here for future tiers as they are added + int tiersAvailable; + if (!canUpgrade){ + tiersAvailable = 4; + } else if (Dungeon.hero.lvl >= 7){ + tiersAvailable = 2; + } else { + tiersAvailable = 1; + } - if (canUpgrade) setupStars(); + for (int i = 0; i < Math.min(tiersAvailable, talents.size()); i++){ + TalentTierPane pane = new TalentTierPane(talents.get(i), i+1, canUpgrade); + panes.add(pane); + content.add(pane); - buttons = new ArrayList<>(); - for (Talent talent : talents.get(0).keySet()){ - TalentButton btn = new TalentButton(talent, talents.get(0).get(talent), canUpgrade){ - @Override - public void upgradeTalent() { - super.upgradeTalent(); - if (parent != null) { - setupStars(); - TalentsPane.this.layout(); - } - } - }; - buttons.add(btn); - content.add(btn); + ColorBlock sep = new ColorBlock(0, 1, 0xFF000000); + separators.add(sep); + content.add(sep); } sep = new ColorBlock(0, 1, 0xFF000000); @@ -84,61 +79,114 @@ public class TalentsPane extends ScrollPane { content.add(blockText); } - private void setupStars(){ - if (!stars.isEmpty()){ - for (Image im : stars){ - im.killAndErase(); - } - stars.clear(); - } - - int totStars = 5; - int openStars = Dungeon.hero.talentPointsAvailable(); - int usedStars = Dungeon.hero.talentPointsSpent(); - for (int i = 0; i < totStars; i++){ - Image im = new Speck().image(Speck.STAR); - stars.add(im); - add(im); - if (i >= openStars && i < (openStars + usedStars)){ - im.tint(0.75f, 0.75f, 0.75f, 0.9f); - } else if (i >= (openStars + usedStars)){ - im.tint(0f, 0f, 0f, 0.9f); - } - } - } - @Override protected void layout() { super.layout(); - float titleWidth = title.width(); - titleWidth += 2 + stars.size()*6; - title.setPos((width - titleWidth)/2f, 2); + float top = 2; + for (int i = 0; i < panes.size(); i++){ + panes.get(i).setRect(x, top, width, 0); + top = panes.get(i).bottom(); + + separators.get(i).x = 0; + separators.get(i).y = top + 2; + separators.get(i).size(width, 1); + + top += 3; - float left = title.right() + 2; - for (Image star : stars){ - star.x = left; - star.y = title.top(); - PixelScene.align(star); - left += 6; } - float gap = (width - buttons.size()*TalentButton.WIDTH)/(buttons.size()+1); - left = gap; - for (TalentButton btn : buttons){ - btn.setPos(left, title.bottom() + 4); - PixelScene.align(btn); - left += btn.width() + gap; - } - - sep.x = 0; - sep.y = buttons.get(0).bottom() + 2; - sep.size(width, 1); - blocker.x = 0; - blocker.y = sep.y + 1; - blocker.size(width, height - sep.y - 1); + blocker.y = top; + blocker.size(width, height - top); blockText.setPos((width - blockText.width())/2f, blocker.y + 10); } + + public static class TalentTierPane extends Component { + + RenderedTextBlock title; + ArrayList buttons; + + ArrayList stars = new ArrayList<>(); + + public TalentTierPane(LinkedHashMap talents, int tier, boolean canUpgrade){ + super(); + + title = PixelScene.renderTextBlock(Messages.titleCase(Messages.get(TalentsPane.class, "tier", tier)), 9); + title.hardlight(Window.TITLE_COLOR); + add(title); + + if (canUpgrade) setupStars(); + + buttons = new ArrayList<>(); + for (Talent talent : talents.keySet()){ + TalentButton btn = new TalentButton(talent, talents.get(talent), canUpgrade){ + @Override + public void upgradeTalent() { + super.upgradeTalent(); + if (parent != null) { + setupStars(); + TalentTierPane.this.layout(); + } + } + }; + buttons.add(btn); + add(btn); + } + + } + + private void setupStars(){ + if (!stars.isEmpty()){ + for (Image im : stars){ + im.killAndErase(); + } + stars.clear(); + } + + int totStars = 5; + int openStars = Dungeon.hero.talentPointsAvailable(); + int usedStars = Dungeon.hero.talentPointsSpent(); + for (int i = 0; i < totStars; i++){ + Image im = new Speck().image(Speck.STAR); + stars.add(im); + add(im); + if (i >= openStars && i < (openStars + usedStars)){ + im.tint(0.75f, 0.75f, 0.75f, 0.9f); + } else if (i >= (openStars + usedStars)){ + im.tint(0f, 0f, 0f, 0.9f); + } + } + } + + @Override + protected void layout() { + super.layout(); + + float titleWidth = title.width(); + titleWidth += 2 + stars.size()*6; + title.setPos(x + (width - titleWidth)/2f, y); + + float left = title.right() + 2; + for (Image star : stars){ + star.x = left; + star.y = title.top(); + PixelScene.align(star); + left += 6; + } + + float gap = (width - buttons.size()*TalentButton.WIDTH)/(buttons.size()+1); + left = x + gap; + for (TalentButton btn : buttons){ + btn.setPos(left, title.bottom() + 4); + PixelScene.align(btn); + left += btn.width() + gap; + } + + height = buttons.get(0).bottom() - y; + + } + + } }