summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/kz/ilotterytea/maxon/MaxonConstants.java2
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt8
-rw-r--r--core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java4
-rw-r--r--core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java4
-rw-r--r--core/src/kz/ilotterytea/maxon/utils/formatters/NumberFormatter.java53
5 files changed, 47 insertions, 24 deletions
diff --git a/core/src/kz/ilotterytea/maxon/MaxonConstants.java b/core/src/kz/ilotterytea/maxon/MaxonConstants.java
index fc07f27..dca8771 100644
--- a/core/src/kz/ilotterytea/maxon/MaxonConstants.java
+++ b/core/src/kz/ilotterytea/maxon/MaxonConstants.java
@@ -34,7 +34,7 @@ public class MaxonConstants {
public static final FileHandle FILE_EN_US = Gdx.files.internal("i18n/en_us.json");
public static final FileHandle FILE_RU_RU = Gdx.files.internal("i18n/ru_ru.json");
- public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###,###.##");
+ public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###,###.#");
public static final DecimalFormat DECIMAL_FORMAT2 = new DecimalFormat("###,###");
@SuppressWarnings("SimpleDateFormat")
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/M/yyyy hh:mm:ss");
diff --git a/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt b/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt
index a93e8c5..18adb38 100644
--- a/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt
+++ b/core/src/kz/ilotterytea/maxon/screens/SlotsMinigameScreen.kt
@@ -134,7 +134,7 @@ class SlotsMinigameScreen : Screen {
moneyIcon.setPosition(stage.width / 2f + 60f, stage.height / 2f - 180f)
stage.addActor(moneyIcon)
- moneyLabel = Label(NumberFormatter.format(savegame.money.toLong()), skin, "slots")
+ moneyLabel = Label(NumberFormatter.format(savegame.money), skin, "slots")
moneyLabel?.setAlignment(Align.right)
moneyLabel?.setPosition(stage.width / 2f, stage.height / 2f - 180f)
stage.addActor(moneyLabel)
@@ -331,7 +331,7 @@ class SlotsMinigameScreen : Screen {
val prizeText = if (prize == 0.0) {
game.locale.getLine(LineId.MinigameSlotsNothing)
} else {
- game.locale.getFormattedLine(LineId.MinigameSlotsPrize, NumberFormatter.format(prize.toLong()))
+ game.locale.getFormattedLine(LineId.MinigameSlotsPrize, NumberFormatter.format(prize))
}
prizeLabel?.setText(prizeText)
@@ -342,13 +342,13 @@ class SlotsMinigameScreen : Screen {
val stakeText = if (savegame.money.roundToInt() <= 0) {
"---"
} else {
- NumberFormatter.format(savegame.money.toLong())
+ NumberFormatter.format(savegame.money)
}
stakeField?.text = stakeText
}
- moneyLabel?.setText(NumberFormatter.format(savegame.money.roundToLong()))
+ moneyLabel?.setText(NumberFormatter.format(savegame.money))
}
private fun disableSlotMachineIfNoStake() {
diff --git a/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java b/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java
index 9cec62d..50ab62e 100644
--- a/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java
+++ b/core/src/kz/ilotterytea/maxon/screens/game/shop/ShopUI.java
@@ -358,8 +358,8 @@ public class ShopUI {
}
public void render() {
- this.pointsLabel.setText(NumberFormatter.format((long) savegame.getMoney()));
- this.multiplierLabel.setText(String.format("%s/s", NumberFormatter.format((long) savegame.getMultiplier())));
+ this.pointsLabel.setText(NumberFormatter.format(savegame.getMoney(), false));
+ this.multiplierLabel.setText(String.format("%s/s", NumberFormatter.format(savegame.getMultiplier())));
updatePurchaseItems();
}
diff --git a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java
index 2d12f86..364a793 100644
--- a/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java
+++ b/core/src/kz/ilotterytea/maxon/ui/SavegameWidget.java
@@ -101,7 +101,7 @@ public class SavegameWidget extends Table implements Disposable {
Image pointsIcon = new Image(atlas.findRegion("points"));
data.add(pointsIcon).size(iconSize, iconSize).padRight(8f);
- Label points = new Label(NumberFormatter.format((long) savegame.getMoney()), skin, styleName);
+ Label points = new Label(NumberFormatter.format(savegame.getMoney(), false), skin, styleName);
data.add(points).padRight(iconSize);
// Unit
@@ -121,7 +121,7 @@ public class SavegameWidget extends Table implements Disposable {
Image multiplierIcon = new Image(atlas.findRegion("multiplier"));
data.add(multiplierIcon).size(iconSize, iconSize).padRight(8f);
- Label multiplier = new Label(NumberFormatter.format((long) savegame.getMultiplier()), skin, styleName);
+ Label multiplier = new Label(NumberFormatter.format(savegame.getMultiplier()), skin, styleName);
data.add(multiplier);
this.dataTable.add(data).grow();
diff --git a/core/src/kz/ilotterytea/maxon/utils/formatters/NumberFormatter.java b/core/src/kz/ilotterytea/maxon/utils/formatters/NumberFormatter.java
index 812b79c..f6c0fa4 100644
--- a/core/src/kz/ilotterytea/maxon/utils/formatters/NumberFormatter.java
+++ b/core/src/kz/ilotterytea/maxon/utils/formatters/NumberFormatter.java
@@ -1,33 +1,56 @@
package kz.ilotterytea.maxon.utils.formatters;
+import kz.ilotterytea.maxon.MaxonConstants;
+
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
public class NumberFormatter {
- private static final NavigableMap<Long, String> suffixes = new TreeMap<>();
+ private static final NavigableMap<Double, String> suffixes = new TreeMap<>();
static {
- suffixes.put(1_000L, "k");
- suffixes.put(1_000_000L, "M");
- suffixes.put(1_000_000_000L, "G");
- suffixes.put(1_000_000_000_000L, "T");
- suffixes.put(1_000_000_000_000_000L, "P");
- suffixes.put(1_000_000_000_000_000_000L, "E");
+ suffixes.put(1_000.0, "k");
+ suffixes.put(1_000_000.0, "M");
+ suffixes.put(1_000_000_000.0, "B");
+ suffixes.put(1_000_000_000_000.0, "T");
+ suffixes.put(1_000_000_000_000_000.0, "Qd");
+ suffixes.put(1_000_000_000_000_000_000.0, "Qi");
+ suffixes.put(1_000_000_000_000_000_000_000.0, "Sx");
+ suffixes.put(1_000_000_000_000_000_000_000_000.0, "Sp");
+ suffixes.put(1_000_000_000_000_000_000_000_000_000.0, "O");
+ suffixes.put(1_000_000_000_000_000_000_000_000_000_000.0, "N");
+ suffixes.put(1_000_000_000_000_000_000_000_000_000_000_000.0, "D");
+ suffixes.put(1_000_000_000_000_000_000_000_000_000_000_000_000.0, "Xz");
+ }
+
+ public static String format(double value) {
+ return format(value, true);
}
- public static String format(long value) {
+ public static String format(double value, boolean decimal) {
//Long.MIN_VALUE == -Long.MIN_VALUE so we need an adjustment here
- if (value == Long.MIN_VALUE) return format(Long.MIN_VALUE + 1);
- if (value < 0) return "-" + format(-value);
- if (value < 1000) return Long.toString(value); //deal with easy case
+ if (value == Long.MIN_VALUE) return format(Long.MIN_VALUE + 1, decimal);
+ if (value < 0) return "-" + format(-value, decimal);
+ if (value < 100_000.0) {
+ if (!decimal || value == Math.floor(value)) return MaxonConstants.DECIMAL_FORMAT2.format(value);
+ else return MaxonConstants.DECIMAL_FORMAT.format(value);
+ }
- Map.Entry<Long, String> e = suffixes.floorEntry(value);
- Long divideBy = e.getKey();
+ Map.Entry<Double, String> e = suffixes.floorEntry(value);
+ Double divideBy = e.getKey();
String suffix = e.getValue();
- long truncated = value / (divideBy / 10); //the number part of the output times 10
+ double truncated = value / (divideBy / 10.0); //the number part of the output times 10
boolean hasDecimal = truncated < 100 && (truncated / 10d) != (truncated / 10);
- return hasDecimal ? (truncated / 10d) + suffix : (truncated / 10) + suffix;
+ return formatWithSuffix(truncated / 10d, suffix);
+ }
+
+ private static String formatWithSuffix(double value, String suffix) {
+ if (value == Math.floor(value)) {
+ return String.format("%.0f%s", value, suffix);
+ } else {
+ return String.format("%.1f%s", value, suffix);
+ }
}
public static String pad(long value) {