22#include < Geode/modify/PlayLayer.hpp>
33#include < nodes.hpp>
44#include < fmt/core.h>
5- #include < string_view >
5+ #include < array >
66
77using namespace geode ::prelude;
88
9+ constexpr float truncate (float x, int precision) {
10+ constexpr std::array powers { 1 .0f , 10 .0f , 100 .0f , 1000 .0f , 10000 .0f };
11+ return std::floorf (x * powers[precision]) / powers[precision];
12+ }
13+
914class RunInfoWidget : public CCNodeRGBA {
1015public:
1116 CCLabelBMFont* m_status_label = nullptr ;
@@ -141,13 +146,9 @@ class RunInfoWidget : public CCNodeRGBA {
141146 m_was_practice = false ;
142147 }
143148
144- bool decimal = Mod::get ()->getSettingValue <bool >(" use-decimal" );
145-
146- if (decimal) {
147- m_info_label->setString (fmt::format (" From {:.2f}%" , percent).c_str ());
148- } else {
149- m_info_label->setString (fmt::format (" From {}%" , int (percent)).c_str ());
150- }
149+ int decimal = Mod::get ()->getSettingValue <int >(" decimal-places" );
150+ percent = truncate (percent, decimal);
151+ m_info_label->setString (fmt::format (" From {1:.{0}f}%" , decimal, percent).c_str ());
151152
152153 m_top_layout->updateLayout ();
153154 this ->updateLayout ();
@@ -159,13 +160,18 @@ class $modify(PlayLayer) {
159160 struct Fields {
160161 RunInfoWidget* m_widget = nullptr ;
161162 float m_initial_percent = 0 ;
163+ bool m_show_in_percentage = false ;
164+ bool m_show_in_progress_bar = false ;
162165 };
163166
164167 bool init (GJGameLevel* level, bool unk1, bool unk2) {
165168 if (!PlayLayer::init (level, unk1, unk2)) return false ;
166169
167170 if (!Mod::get ()->getSettingValue <bool >(" enabled" )) return true ;
168171
172+ m_fields->m_show_in_percentage = Mod::get ()->getSettingValue <bool >(" show-in-percentage" );
173+ m_fields->m_show_in_progress_bar = Mod::get ()->getSettingValue <bool >(" show-in-progress-bar" );
174+
169175 // removes the testmode label gd creates
170176 if (this ->getChildrenCount ()) {
171177 CCArrayExt<CCNode*> children = this ->getChildren ();
@@ -197,6 +203,12 @@ class $modify(PlayLayer) {
197203 return true ;
198204 }
199205
206+ void update_labels () {
207+ if (!m_fields->m_widget || !Mod::get ()->getSettingValue <bool >(" enabled" )) return ;
208+ m_fields->m_widget ->update_labels (this , m_fields->m_initial_percent );
209+ m_fields->m_widget ->setVisible (m_isPracticeMode || m_isTestMode);
210+ }
211+
200212 void update_position () {
201213 auto const position = Mod::get ()->getSettingValue <std::string>(" position" );
202214 this ->update_position (
@@ -242,10 +254,29 @@ class $modify(PlayLayer) {
242254 this ->update_position ();
243255 }
244256
245- void update_labels () {
246- if (!m_fields->m_widget || !Mod::get ()->getSettingValue <bool >(" enabled" )) return ;
247- m_fields->m_widget ->update_labels (this , m_fields->m_initial_percent );
248- m_fields->m_widget ->setVisible (m_isPracticeMode || m_isTestMode);
257+ void updateProgressbar () {
258+ PlayLayer::updateProgressbar ();
259+
260+ if (m_isPlatformer) return ;
261+ if (!(m_isPracticeMode || m_isTestMode)) return ;
262+ if (!Mod::get ()->getSettingValue <bool >(" enabled" )) return ;
263+
264+ auto from = m_fields->m_initial_percent ;
265+ auto to = this ->getCurrentPercent ();
266+
267+ if (m_percentageLabel && m_fields->m_show_in_percentage ) {
268+ int decimal = Mod::get ()->getSettingValue <int >(" decimal-places" );
269+ auto from_trunc = truncate (from, decimal);
270+ auto to_trunc = truncate (to, decimal);
271+ m_percentageLabel->setString (fmt::format (" {1:.{0}f}-{2:.{0}f}%" , decimal, from_trunc, to_trunc).c_str ());
272+ }
273+
274+ if (m_progressFill && m_fields->m_show_in_progress_bar ) {
275+ float x = from / 100 .0f * m_progressWidth;
276+ float width = (to - from) / 100 .0f * m_progressWidth;
277+ m_progressFill->setTextureRect ({ x, 0 .0f , width, m_progressHeight });
278+ m_progressFill->setPositionX (2 .0f + x);
279+ }
249280 }
250281};
251282
@@ -262,4 +293,12 @@ class $modify(PlayLayer) {
262293
263294 Mod::get ()->setSettingValue <std::string>(" position" , top ? (left ? " Top Left" : " Top Right" ) : (left ? " Bottom Left" : " Bottom Right" ));
264295 }
265- }
296+ if (container.contains (" use-decimal" )) {
297+ auto use_decimal = container[" use-decimal" ].asBool ().unwrapOr (false );
298+ log::debug (" Migrating from old settings: use-decimal={}" , use_decimal);
299+
300+ container.erase (" use-decimal" );
301+
302+ Mod::get ()->setSettingValue <int >(" decimal-places" , use_decimal ? 2 : 0 );
303+ }
304+ }
0 commit comments