Skip to content

Commit

Permalink
Improve research button item display
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Dec 23, 2023
1 parent 1de51ca commit 58f8cbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion core/src/mindustry/core/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ public void hideFollowUpMenu(int menuId) {
}

public static String formatAmount(long number){
return formatAmount(number, false);
}

public static String formatAmount(long number, boolean extraDP){
//prevent things like bars displaying erroneous representations of casted infinities
if(number == Long.MAX_VALUE) return "∞";
if(number == Long.MIN_VALUE) return "-∞";
Expand All @@ -698,7 +702,7 @@ public static String formatAmount(long number){
return sign + Strings.fixed(mag / 1_000_000_000f, 1) + "[gray]" + billions + "[]";
}else if(mag >= 1_000_000){
return sign + Strings.fixed(mag / 1_000_000f, 1) + "[gray]" + millions + "[]";
}else if(mag >= 10_000){
}else if(mag >= (extraDP ? 100_000 : 10_000)){
return number / 1000 + "[gray]" + thousands + "[]";
}else if(mag >= 1000){
return sign + Strings.fixed(mag / 1000f, 1) + "[gray]" + thousands + "[]";
Expand Down
13 changes: 9 additions & 4 deletions core/src/mindustry/ui/dialogs/ResearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,15 @@ public void rebuild(@Nullable boolean[] shine){
list.image(req.item.uiIcon).size(8 * 3).padRight(3);
list.add(req.item.localizedName).color(Color.lightGray);
Label label = list.label(() -> " " +
UI.formatAmount(Math.min(items.get(req.item), reqAmount)) + " / "
+ UI.formatAmount(reqAmount)).get();

Color targetColor = items.has(req.item) ? Color.lightGray : Color.scarlet;
UI.formatAmount(items.get(req.item), true) + " / "
+ UI.formatAmount(reqAmount, true)).get();

float fraction = (float)items.get(req.item) / reqAmount;
Color targetColor =
fraction > 1.8 ? Color.green :
fraction >= 1 ? Color.lime :
fraction >= 0.5 ? Color.salmon :
Color.red;

if(shiny){
label.setColor(Pal.accent);
Expand Down

0 comments on commit 58f8cbe

Please sign in to comment.