v0.9.0b: adjusted talent UI to account for multiple tiers

This commit is contained in:
Evan Debenham 2020-10-10 00:01:09 -04:00
parent f512d7b069
commit dfaed721c5
3 changed files with 121 additions and 72 deletions

View File

@ -266,7 +266,7 @@ public enum Talent {
if (talentBundle.contains(talent.name())){ if (talentBundle.contains(talent.name())){
for (LinkedHashMap<Talent, Integer> tier : hero.talents){ for (LinkedHashMap<Talent, Integer> tier : hero.talents){
if (tier.containsKey(talent)){ if (tier.containsKey(talent)){
tier.put(talent, talentBundle.getInt(talent.name())); tier.put(talent, Math.min(talentBundle.getInt(talent.name()), talent.maxPoints()));
} }
} }
} }

View File

@ -61,6 +61,7 @@ public class TalentButton extends Button {
this.pointsInTalent = points; this.pointsInTalent = points;
this.upgradeEnabled = upgradeEnabled; this.upgradeEnabled = upgradeEnabled;
bg.frame(20*(talent.maxPoints()-1), 0, WIDTH, HEIGHT);
icon.frame( film.get( talent.icon() ) ); icon.frame( film.get( talent.icon() ) );
} }
@ -74,7 +75,7 @@ public class TalentButton extends Button {
fill = new ColorBlock(0, 4, 0xFFFFFF44); fill = new ColorBlock(0, 4, 0xFFFFFF44);
add(fill); add(fill);
bg = new Image(Assets.Interfaces.TALENT_BUTTON, 20, 0, WIDTH, HEIGHT); bg = new Image(Assets.Interfaces.TALENT_BUTTON);
add(bg); add(bg);
icon = new Image( icons ); icon = new Image( icons );
@ -90,7 +91,7 @@ public class TalentButton extends Button {
fill.x = x; fill.x = x;
fill.y = y + WIDTH - 1; fill.y = y + WIDTH - 1;
fill.size( pointsInTalent/2f * WIDTH, 5); fill.size( pointsInTalent/(float)talent.maxPoints() * WIDTH, 5);
bg.x = x; bg.x = x;
bg.y = y; bg.y = y;

View File

@ -33,13 +33,10 @@ import com.watabou.noosa.ui.Component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
//TODO some stuff here is currently coded without accounting for tiers
public class TalentsPane extends ScrollPane { public class TalentsPane extends ScrollPane {
RenderedTextBlock title; ArrayList<TalentTierPane> panes = new ArrayList<>();
ArrayList<TalentButton> buttons; ArrayList<ColorBlock> separators = new ArrayList<>();
ArrayList<Image> stars = new ArrayList<>();
ColorBlock sep; ColorBlock sep;
ColorBlock blocker; ColorBlock blocker;
@ -52,26 +49,24 @@ public class TalentsPane extends ScrollPane {
public TalentsPane( boolean canUpgrade, ArrayList<LinkedHashMap<Talent, Integer>> talents ) { public TalentsPane( boolean canUpgrade, ArrayList<LinkedHashMap<Talent, Integer>> talents ) {
super(new Component()); super(new Component());
title = PixelScene.renderTextBlock(Messages.titleCase(Messages.get(this, "tier", 1)), 9); //TODO more code here for future tiers as they are added
title.hardlight(Window.TITLE_COLOR); int tiersAvailable;
content.add(title); if (!canUpgrade){
tiersAvailable = 4;
if (canUpgrade) setupStars(); } else if (Dungeon.hero.lvl >= 7){
tiersAvailable = 2;
buttons = new ArrayList<>(); } else {
for (Talent talent : talents.get(0).keySet()){ tiersAvailable = 1;
TalentButton btn = new TalentButton(talent, talents.get(0).get(talent), canUpgrade){
@Override
public void upgradeTalent() {
super.upgradeTalent();
if (parent != null) {
setupStars();
TalentsPane.this.layout();
} }
}
}; for (int i = 0; i < Math.min(tiersAvailable, talents.size()); i++){
buttons.add(btn); TalentTierPane pane = new TalentTierPane(talents.get(i), i+1, canUpgrade);
content.add(btn); panes.add(pane);
content.add(pane);
ColorBlock sep = new ColorBlock(0, 1, 0xFF000000);
separators.add(sep);
content.add(sep);
} }
sep = new ColorBlock(0, 1, 0xFF000000); sep = new ColorBlock(0, 1, 0xFF000000);
@ -84,6 +79,64 @@ public class TalentsPane extends ScrollPane {
content.add(blockText); content.add(blockText);
} }
@Override
protected void layout() {
super.layout();
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;
}
blocker.x = 0;
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<TalentButton> buttons;
ArrayList<Image> stars = new ArrayList<>();
public TalentTierPane(LinkedHashMap<Talent, Integer> 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(){ private void setupStars(){
if (!stars.isEmpty()){ if (!stars.isEmpty()){
for (Image im : stars){ for (Image im : stars){
@ -113,7 +166,7 @@ public class TalentsPane extends ScrollPane {
float titleWidth = title.width(); float titleWidth = title.width();
titleWidth += 2 + stars.size()*6; titleWidth += 2 + stars.size()*6;
title.setPos((width - titleWidth)/2f, 2); title.setPos(x + (width - titleWidth)/2f, y);
float left = title.right() + 2; float left = title.right() + 2;
for (Image star : stars){ for (Image star : stars){
@ -124,21 +177,16 @@ public class TalentsPane extends ScrollPane {
} }
float gap = (width - buttons.size()*TalentButton.WIDTH)/(buttons.size()+1); float gap = (width - buttons.size()*TalentButton.WIDTH)/(buttons.size()+1);
left = gap; left = x + gap;
for (TalentButton btn : buttons){ for (TalentButton btn : buttons){
btn.setPos(left, title.bottom() + 4); btn.setPos(left, title.bottom() + 4);
PixelScene.align(btn); PixelScene.align(btn);
left += btn.width() + gap; left += btn.width() + gap;
} }
sep.x = 0; height = buttons.get(0).bottom() - y;
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);
blockText.setPos((width - blockText.width())/2f, blocker.y + 10);
} }
} }