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;
} 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<>(); ColorBlock sep = new ColorBlock(0, 1, 0xFF000000);
for (Talent talent : talents.get(0).keySet()){ separators.add(sep);
TalentButton btn = new TalentButton(talent, talents.get(0).get(talent), canUpgrade){ content.add(sep);
@Override
public void upgradeTalent() {
super.upgradeTalent();
if (parent != null) {
setupStars();
TalentsPane.this.layout();
}
}
};
buttons.add(btn);
content.add(btn);
} }
sep = new ColorBlock(0, 1, 0xFF000000); sep = new ColorBlock(0, 1, 0xFF000000);
@ -84,61 +79,114 @@ public class TalentsPane extends ScrollPane {
content.add(blockText); 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 @Override
protected void layout() { protected void layout() {
super.layout(); super.layout();
float titleWidth = title.width(); float top = 2;
titleWidth += 2 + stars.size()*6; for (int i = 0; i < panes.size(); i++){
title.setPos((width - titleWidth)/2f, 2); 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.x = 0;
blocker.y = sep.y + 1; blocker.y = top;
blocker.size(width, height - sep.y - 1); blocker.size(width, height - top);
blockText.setPos((width - blockText.width())/2f, blocker.y + 10); 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(){
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;
}
}
} }