Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/windowing
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-06-06 10:14:18 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2025-06-06 10:14:18 +1000
commit4c34d17e57285cc67e9256fcb024101356f30129 (patch)
tree089596eab580a83186e561c4ed77e93db811591e /source/windowing
parentaa81f500ad664f9e339b01e3a9b341583197bad4 (diff)
improve short item count formatting, fix missing cooldown
Diffstat (limited to 'source/windowing')
-rw-r--r--source/windowing/StarItemSlotWidget.cpp75
1 files changed, 51 insertions, 24 deletions
diff --git a/source/windowing/StarItemSlotWidget.cpp b/source/windowing/StarItemSlotWidget.cpp
index 2d47d8a..ffd7da1 100644
--- a/source/windowing/StarItemSlotWidget.cpp
+++ b/source/windowing/StarItemSlotWidget.cpp
@@ -10,6 +10,46 @@
namespace Star {
+static String formatShortSize(uint64_t n) {
+ if (n < 10000)
+ return toString(n);
+
+ uint64_t divisor;
+ char suffix;
+
+ if (n >= 1000000000000000ull) {
+ divisor = 1000000000000000ull;
+ suffix = 'q';
+ } else if (n >= 1000000000000ull) {
+ divisor = 1000000000000ull;
+ suffix = 't';
+ } else if (n >= 1000000000ull) {
+ divisor = 1000000000ull;
+ suffix = 'b';
+ } else if (n >= 1000000ull) {
+ divisor = 1000000ull;
+ suffix = 'm';
+ } else {
+ divisor = 1000ull;
+ suffix = 'k';
+ }
+
+ uint64_t whole = n / divisor;
+
+ if (whole >= 100ull)
+ return strf("{}{:c}", whole, suffix);
+
+ uint64_t remainder = n - (whole * divisor);
+ uint64_t frac = (remainder * 1000) / divisor;
+
+ if (frac == 0)
+ return strf("{}{:c}", whole, suffix);
+ else if (whole >= 10)
+ return strf("{}.{}{:c}", whole, frac / 100, suffix);
+ else
+ return strf("{}.{:02d}{:c}", whole, frac / 10, suffix);
+}
+
ItemSlotWidget::ItemSlotWidget(ItemPtr const& item, String const& backingImage)
: m_item(item), m_backingImage(backingImage) {
m_drawBackingImageWhenFull = false;
@@ -149,6 +189,10 @@ void ItemSlotWidget::setHighlightEnabled(bool highlight) {
}
void ItemSlotWidget::renderImpl() {
+ auto drawCooldown = [this]() {
+ int frame = (int)roundf(m_progress * 18);// TODO: Hardcoded lol
+ context()->drawInterfaceQuad(String(strf("/interface/cooldown.png:{}", frame)), Vec2F(screenPosition()));
+ };
if (m_item) {
if (m_drawBackingImageWhenFull && m_backingImage != "")
context()->drawInterfaceQuad(m_backingImage, Vec2F(screenPosition()));
@@ -185,33 +229,16 @@ void ItemSlotWidget::renderImpl() {
}
}
-if (m_item->count() > 1 && m_showCount) { // we don't need to tell people that there's only 1 of something
- std::string formattedCount;
-
- if (m_item->count() >= 1000000000000000) { // Quadrillion (q)
- formattedCount = toString(m_item->count() / 1000000000000000) + "q";
- } else if (m_item->count() >= 1000000000000) { // Trillion (t)
- formattedCount = toString(m_item->count() / 1000000000000) + "t";
- } else if (m_item->count() >= 1000000000) { // Billion (b)
- formattedCount = toString(m_item->count() / 1000000000) + "b";
- } else if (m_item->count() >= 1000000) { // Million (m)
- formattedCount = toString(m_item->count() / 1000000) + "m";
- } else if (m_item->count() >= 10000) { // Thousand (k)
- formattedCount = toString(m_item->count() / 1000) + "k";
- } else {
- formattedCount = toString(m_item->count());
+ drawCooldown();
+ if (m_item->count() > 1 && m_showCount) {// we don't need to tell people that there's only 1 of something
+ context()->setTextStyle(m_textStyle);
+ context()->setFontMode(m_countFontMode);
+ context()->renderInterfaceText(formatShortSize(m_item->count()), m_countPosition.translated(Vec2F(screenPosition())));
+ context()->clearTextStyle();
}
-
- context()->setTextStyle(m_textStyle);
- context()->setFontMode(m_countFontMode);
- context()->renderInterfaceText(formattedCount, m_countPosition.translated(Vec2F(screenPosition())));
- context()->clearTextStyle();
-}
-
} else if (m_drawBackingImageWhenEmpty && m_backingImage != "") {
context()->drawInterfaceQuad(m_backingImage, Vec2F(screenPosition()));
- int frame = (int)roundf(m_progress * 18); // TODO: Hardcoded lol
- context()->drawInterfaceQuad(String(strf("/interface/cooldown.png:{}", frame)), Vec2F(screenPosition()));
+ drawCooldown();
}
if (m_highlightEnabled) {