From d78f3adc77350cbdcaf29be5bf030da825172725 Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Sat, 16 Aug 2025 07:00:47 -0500 Subject: [PATCH 1/7] progress bars --- loader/include/Geode/UI.hpp | 2 + loader/include/Geode/ui/ProgressBar.hpp | 42 +++++++++++ loader/include/Geode/ui/ProgressBarSolid.hpp | 30 ++++++++ loader/src/ui/nodes/ProgressBar.cpp | 67 ++++++++++++++++++ loader/src/ui/nodes/ProgressBarSolid.cpp | 73 ++++++++++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 loader/include/Geode/ui/ProgressBar.hpp create mode 100644 loader/include/Geode/ui/ProgressBarSolid.hpp create mode 100644 loader/src/ui/nodes/ProgressBar.cpp create mode 100644 loader/src/ui/nodes/ProgressBarSolid.cpp diff --git a/loader/include/Geode/UI.hpp b/loader/include/Geode/UI.hpp index 54edc0236..b2fd83b08 100644 --- a/loader/include/Geode/UI.hpp +++ b/loader/include/Geode/UI.hpp @@ -17,6 +17,8 @@ #include "ui/MDTextArea.hpp" #include "ui/Notification.hpp" #include "ui/Popup.hpp" +#include "ui/ProgressBar.hpp" +#include "ui/ProgressBarSolid.hpp" #include "ui/SceneManager.hpp" #include "ui/Scrollbar.hpp" #include "ui/ScrollLayer.hpp" diff --git a/loader/include/Geode/ui/ProgressBar.hpp b/loader/include/Geode/ui/ProgressBar.hpp new file mode 100644 index 000000000..7684bf897 --- /dev/null +++ b/loader/include/Geode/ui/ProgressBar.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include + +namespace geode { + // Custom class for the progress bar + class ProgressBar : public cocos2d::CCNode { + protected: + Ref m_progressBar = nullptr; // Progress bar outline + CCSprite* m_progressBarFill = nullptr; // Progress bar fill + + float m_progress = 0.f; // Current progress bar fill percentage ranging from 0 to 100 + + float m_progressBarFillMaxWidth = 0.f; // Max width for the progress fill bar node + float m_progressBarFillMaxHeight = 0.f; // Max height for the progress fill bar node + + bool init() override; + + public: + // Create a custom progress bar + static ProgressBar* create(); + + /** + * Set the color of the fill of the bar + * + * @param color RGB color object + */ + void setProgressBarFillColor(ccColor3B color); + + /** + * Update the size of the fill of the bar + * + * @param value A float from 0 to 100 + */ + virtual void updateProgress(float value); + + /** + * Get the current progress percentage of the bar + */ + float getProgress(); + }; +} \ No newline at end of file diff --git a/loader/include/Geode/ui/ProgressBarSolid.hpp b/loader/include/Geode/ui/ProgressBarSolid.hpp new file mode 100644 index 000000000..e2753dd14 --- /dev/null +++ b/loader/include/Geode/ui/ProgressBarSolid.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +namespace geode { + // Custom class for the Normal/Practice mode style progress bar + class ProgressBarSolid : public ProgressBar { + protected: + CCLabelBMFont* m_progressPercentLabel = nullptr; // The text label displaying the percentage + + bool init() override; + + public: + // Create a custom progress bar + static ProgressBarSolid* create(); + + /** + * Update the size of the fill of the bar and the percentage label + * + * @param value A float from 0 to 100 + */ + void updateProgress(float value) override; + + /** + * Get the progress percentage text label node + */ + CCLabelBMFont* getProgressLabel(); + }; +} \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp new file mode 100644 index 000000000..26eca9a70 --- /dev/null +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -0,0 +1,67 @@ +#include +#include + +using namespace geode::prelude; + +bool ProgressBar::init() { + if (!CCNode::init()) return false; + + this->setID("bar"_spr); + + m_progressBar = CCSprite::create("slidergroove2.png"); + m_progressBar->setID("progress-bar"); + m_progressBar->setPosition({ m_progressBar->getScaledContentWidth() / 2.f, m_progressBar->getScaledContentHeight() / 2.f }); + m_progressBar->setAnchorPoint({ 0.5, 0.5 }); + m_progressBar->setZOrder(501); + + this->setScaledContentSize(m_progressBar->getScaledContentSize()); + + m_progressBarFill = CCSprite::create("sliderBar2.png"); + m_progressBarFill->setID("bar-fill"); + m_progressBarFill->setAnchorPoint({ 0, 0.5 }); + m_progressBarFill->setPosition({ 2.f, m_progressBar->getScaledContentHeight() / 2.f }); + m_progressBarFill->setColor({ 255, 255, 255 }); + m_progressBarFill->setZOrder(-1); + + m_progressBarFillMaxWidth = m_progressBar->getScaledContentWidth() - 4.f; + m_progressBarFillMaxHeight = m_progressBarFill->getScaledContentHeight(); + + m_progressBar->addChild(m_progressBarFill); + + this->addChild(m_progressBar); + this->updateProgress(0.0f); + + return true; +}; + +void ProgressBar::setProgressBarFillColor(ccColor3B color) { + if (m_progressBarFill) m_progressBarFill->setColor(color); +}; + +void ProgressBar::updateProgress(float value) { + if (value > 100.0f) value = 100.0f; + if (value < 0.0f) value = 0.0f; + + m_progress = value; + + if (m_progressBar && m_progressBarFill) { + float width = m_progressBarFillMaxWidth * (m_progress / 100.f); + m_progressBarFill->setTextureRect({ 0.f, 0.f, width, m_progressBarFillMaxHeight }); + }; +}; + +float ProgressBar::getProgress() { + return m_progress; +}; + +ProgressBar* ProgressBar::create() { + auto ret = new ProgressBar(); + + if (ret && ret->init()) { + ret->autorelease(); + return ret; + }; + + CC_SAFE_DELETE(ret); + return nullptr; +}; \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBarSolid.cpp b/loader/src/ui/nodes/ProgressBarSolid.cpp new file mode 100644 index 000000000..7f6d6cd94 --- /dev/null +++ b/loader/src/ui/nodes/ProgressBarSolid.cpp @@ -0,0 +1,73 @@ +#include +#include +#include + +using namespace geode::prelude; + +bool ProgressBarSolid::init() { + if (!CCNode::init()) return false; + + this->setID("bar-solid"_spr); + + m_progressBar = CCSprite::create("GJ_progressBar_001.png"); + m_progressBar->setID("progress-bar"); + m_progressBar->setAnchorPoint({ 0.5, 0.5 }); + m_progressBar->setPosition({ m_progressBar->getScaledContentWidth() / 2.f, m_progressBar->getScaledContentHeight() / 2.f }); + m_progressBar->setColor({ 0, 0, 0 }); + m_progressBar->setOpacity(125); + + this->setScaledContentSize(m_progressBar->getScaledContentSize()); + + m_progressBarFill = CCSprite::create("GJ_progressBar_001.png"); + m_progressBarFill->setID("bar-fill"); + m_progressBarFill->setScale(0.992f); + m_progressBarFill->setScaleY(0.86f); + m_progressBarFill->setAnchorPoint({ 0, 0.5 }); + m_progressBarFill->setPosition({ 1.36f, m_progressBar->getScaledContentHeight() / 2.f }); + m_progressBarFill->setColor({ 255, 255, 255 }); + m_progressBarFill->setZOrder(1); + + m_progressBarFillMaxWidth = m_progressBar->getScaledContentWidth(); + m_progressBarFillMaxHeight = 20.f; + + m_progressBar->addChild(m_progressBarFill); + + this->addChild(m_progressBar); + this->updateProgress(0.0f); + + m_progressPercentLabel = CCLabelBMFont::create("0%", "bigFont.fnt"); + m_progressPercentLabel->setID("percent-label"); + m_progressPercentLabel->setScale(0.5f); + m_progressPercentLabel->setAnchorPoint({ 0.5, 0.5 }); + m_progressPercentLabel->setPosition({ getScaledContentWidth() / 2.f, getScaledContentHeight() / 2.f }); + m_progressPercentLabel->setZOrder(2); + + this->addChild(m_progressPercentLabel); + + return true; +}; + +void ProgressBarSolid::updateProgress(float value) { + ProgressBar::updateProgress(value); + + if (m_progressPercentLabel) { + auto percentString = fmt::format("{}%", static_cast(m_progress)); + m_progressPercentLabel->setCString(percentString.c_str()); + }; +}; + +CCLabelBMFont* ProgressBarSolid::getProgressLabel() { + return m_progressPercentLabel; +}; + +ProgressBarSolid* ProgressBarSolid::create() { + auto ret = new ProgressBarSolid(); + + if (ret && ret->init()) { + ret->autorelease(); + return ret; + }; + + CC_SAFE_DELETE(ret); + return nullptr; +}; \ No newline at end of file From 7dd5c09020ffb66927fb44cad26da0e758c82360 Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Mon, 1 Sep 2025 15:26:59 -0500 Subject: [PATCH 2/7] merge classes and add pimpl --- loader/include/Geode/UI.hpp | 1 - loader/include/Geode/ui/ProgressBar.hpp | 42 +++++- loader/include/Geode/ui/ProgressBarSolid.hpp | 30 ---- loader/src/ui/nodes/ProgressBar.cpp | 149 +++++++++++++++---- loader/src/ui/nodes/ProgressBarSolid.cpp | 73 --------- 5 files changed, 157 insertions(+), 138 deletions(-) delete mode 100644 loader/include/Geode/ui/ProgressBarSolid.hpp delete mode 100644 loader/src/ui/nodes/ProgressBarSolid.cpp diff --git a/loader/include/Geode/UI.hpp b/loader/include/Geode/UI.hpp index b2fd83b08..a6aa5b0f0 100644 --- a/loader/include/Geode/UI.hpp +++ b/loader/include/Geode/UI.hpp @@ -18,7 +18,6 @@ #include "ui/Notification.hpp" #include "ui/Popup.hpp" #include "ui/ProgressBar.hpp" -#include "ui/ProgressBarSolid.hpp" #include "ui/SceneManager.hpp" #include "ui/Scrollbar.hpp" #include "ui/ScrollLayer.hpp" diff --git a/loader/include/Geode/ui/ProgressBar.hpp b/loader/include/Geode/ui/ProgressBar.hpp index 7684bf897..3afe96298 100644 --- a/loader/include/Geode/ui/ProgressBar.hpp +++ b/loader/include/Geode/ui/ProgressBar.hpp @@ -3,16 +3,20 @@ #include namespace geode { + // Enum for progress bar style + enum class ProgressBarStyle { + Level = 0, + Solid = 1, + }; + // Custom class for the progress bar class ProgressBar : public cocos2d::CCNode { protected: - Ref m_progressBar = nullptr; // Progress bar outline - CCSprite* m_progressBarFill = nullptr; // Progress bar fill - - float m_progress = 0.f; // Current progress bar fill percentage ranging from 0 to 100 + class Impl; + std::unique_ptr m_impl; - float m_progressBarFillMaxWidth = 0.f; // Max width for the progress fill bar node - float m_progressBarFillMaxHeight = 0.f; // Max height for the progress fill bar node + ProgressBar(); + ~ProgressBar(); bool init() override; @@ -20,6 +24,13 @@ namespace geode { // Create a custom progress bar static ProgressBar* create(); + /** + * Set the style of the progress bar + * + * @param style Style to switch to + */ + void setStyle(ProgressBarStyle style); + /** * Set the color of the fill of the bar * @@ -37,6 +48,23 @@ namespace geode { /** * Get the current progress percentage of the bar */ - float getProgress(); + float getProgress() const; + + /** + * Get the progress percentage text label node + */ + CCLabelBMFont* getProgressLabel() const; + + /** + * Get the current style of the progress bar + */ + ProgressBarStyle getProgressBarStyle() const; + + /** + * Show the label displaying the current percentage of progress + * + * @param bool Whether to toggle visibility + */ + void showProgressLabel(bool show); }; } \ No newline at end of file diff --git a/loader/include/Geode/ui/ProgressBarSolid.hpp b/loader/include/Geode/ui/ProgressBarSolid.hpp deleted file mode 100644 index e2753dd14..000000000 --- a/loader/include/Geode/ui/ProgressBarSolid.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -namespace geode { - // Custom class for the Normal/Practice mode style progress bar - class ProgressBarSolid : public ProgressBar { - protected: - CCLabelBMFont* m_progressPercentLabel = nullptr; // The text label displaying the percentage - - bool init() override; - - public: - // Create a custom progress bar - static ProgressBarSolid* create(); - - /** - * Update the size of the fill of the bar and the percentage label - * - * @param value A float from 0 to 100 - */ - void updateProgress(float value) override; - - /** - * Get the progress percentage text label node - */ - CCLabelBMFont* getProgressLabel(); - }; -} \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp index 26eca9a70..aff9172ab 100644 --- a/loader/src/ui/nodes/ProgressBar.cpp +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -3,55 +3,150 @@ using namespace geode::prelude; +class ProgressBar::Impl final { +public: + Ref progressBar = nullptr; // Progress bar outline + CCSprite* progressBarFill = nullptr; // Progress bar fill + CCLabelBMFont* progressPercentLabel = nullptr; // The text label displaying the percentage + + float progress = 0.0f; // Current progress bar fill percentage ranging from 0 to 100 + + ProgressBarStyle style = ProgressBarStyle::Level; // Style of the progress bar + + float progressBarFillMaxWidth = 0.0f; // Max width for the progress fill bar node + float progressBarFillMaxHeight = 0.0f; // Max height for the progress fill bar node + + bool showProgressPercentLabel = false; // Whether to show the label showing the percentage of the current progress +}; + +ProgressBar::ProgressBar() { + m_impl = std::make_unique(); +}; + +ProgressBar::~ProgressBar() {}; + bool ProgressBar::init() { if (!CCNode::init()) return false; - this->setID("bar"_spr); + switch (m_impl->style) { + case ProgressBarStyle::Level: + m_impl->progressBar = CCSprite::create("slidergroove2.png"); + m_impl->progressBar->setID("progress-bar"); + m_impl->progressBar->setAnchorPoint({ 0.5, 0.5 }); + m_impl->progressBar->setPosition({ m_impl->progressBar->getScaledContentWidth() / 2.0f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressBar->setZOrder(1); + + m_impl->progressBarFill = CCSprite::create("sliderBar2.png"); + m_impl->progressBarFill->setID("progress-bar-fill"); + m_impl->progressBarFill->setAnchorPoint({ 0, 0.5 }); + m_impl->progressBarFill->setPosition({ 2.0f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressBarFill->setColor({ 255, 255, 255 }); + m_impl->progressBarFill->setZOrder(-1); + + m_impl->progressBarFillMaxWidth = m_impl->progressBar->getScaledContentWidth() - 4.0f; + m_impl->progressBarFillMaxHeight = m_impl->progressBarFill->getScaledContentHeight() - 0.5f; + + m_impl->progressPercentLabel = CCLabelBMFont::create("0%", "bigFont.fnt"); + m_impl->progressPercentLabel->setID("progress-percent-label"); + m_impl->progressPercentLabel->setScale(0.5f); + m_impl->progressPercentLabel->setAnchorPoint({ 0, 0.5 }); + m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentLeft); + m_impl->progressPercentLabel->setPosition({ m_impl->progressBar->getScaledContentWidth() + 2.5f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressPercentLabel->setVisible(m_impl->showProgressPercentLabel); + m_impl->progressPercentLabel->setZOrder(1); + break; + + case ProgressBarStyle::Solid: + m_impl->showProgressPercentLabel = true; + + m_impl->progressBar = CCSprite::create("GJ_progressBar_001.png"); + m_impl->progressBar->setID("progress-bar"); + m_impl->progressBar->setAnchorPoint({ 0.5, 0.5 }); + m_impl->progressBar->setPosition({ m_impl->progressBar->getScaledContentWidth() / 2.0f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressBar->setColor({ 0, 0, 0 }); + m_impl->progressBar->setOpacity(125); + m_impl->progressBar->setZOrder(-1); + + m_impl->progressBarFill = CCSprite::create("GJ_progressBar_001.png"); + m_impl->progressBarFill->setID("progress-bar-fill"); + m_impl->progressBarFill->setScale(0.992f); + m_impl->progressBarFill->setScaleY(0.86f); + m_impl->progressBarFill->setAnchorPoint({ 0, 0.5 }); + m_impl->progressBarFill->setPosition({ 1.36f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressBarFill->setColor({ 255, 255, 255 }); + m_impl->progressBarFill->setZOrder(0); + + m_impl->progressBarFillMaxWidth = m_impl->progressBar->getScaledContentWidth(); + m_impl->progressBarFillMaxHeight = 20.0f; + + m_impl->progressPercentLabel = CCLabelBMFont::create("0%", "bigFont.fnt"); + m_impl->progressPercentLabel->setID("progress-percent-label"); + m_impl->progressPercentLabel->setScale(0.5f); + m_impl->progressPercentLabel->setAnchorPoint({ 0.5, 0.5 }); + m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentCenter); + m_impl->progressPercentLabel->setPosition({ m_impl->progressBar->getScaledContentWidth() / 2.0f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressPercentLabel->setVisible(m_impl->showProgressPercentLabel); + m_impl->progressPercentLabel->setZOrder(1); + break; + }; - m_progressBar = CCSprite::create("slidergroove2.png"); - m_progressBar->setID("progress-bar"); - m_progressBar->setPosition({ m_progressBar->getScaledContentWidth() / 2.f, m_progressBar->getScaledContentHeight() / 2.f }); - m_progressBar->setAnchorPoint({ 0.5, 0.5 }); - m_progressBar->setZOrder(501); + this->setScaledContentSize(m_impl->progressBar->getScaledContentSize()); - this->setScaledContentSize(m_progressBar->getScaledContentSize()); + m_impl->progressBar->addChild(m_impl->progressBarFill); - m_progressBarFill = CCSprite::create("sliderBar2.png"); - m_progressBarFill->setID("bar-fill"); - m_progressBarFill->setAnchorPoint({ 0, 0.5 }); - m_progressBarFill->setPosition({ 2.f, m_progressBar->getScaledContentHeight() / 2.f }); - m_progressBarFill->setColor({ 255, 255, 255 }); - m_progressBarFill->setZOrder(-1); + this->addChild(m_impl->progressBar); + this->updateProgress(m_impl->progress); - m_progressBarFillMaxWidth = m_progressBar->getScaledContentWidth() - 4.f; - m_progressBarFillMaxHeight = m_progressBarFill->getScaledContentHeight(); + if (m_impl->progressPercentLabel) this->addChild(m_impl->progressPercentLabel); - m_progressBar->addChild(m_progressBarFill); + return true; +}; - this->addChild(m_progressBar); - this->updateProgress(0.0f); +void ProgressBar::setStyle(ProgressBarStyle style) { + if (m_impl->style != style) { + m_impl->style = style; - return true; + this->removeAllChildren(); + init(); // init again with new style + }; }; void ProgressBar::setProgressBarFillColor(ccColor3B color) { - if (m_progressBarFill) m_progressBarFill->setColor(color); + if (m_impl->progressBarFill) m_impl->progressBarFill->setColor(color); }; void ProgressBar::updateProgress(float value) { if (value > 100.0f) value = 100.0f; if (value < 0.0f) value = 0.0f; - m_progress = value; + m_impl->progress = value; - if (m_progressBar && m_progressBarFill) { - float width = m_progressBarFillMaxWidth * (m_progress / 100.f); - m_progressBarFill->setTextureRect({ 0.f, 0.f, width, m_progressBarFillMaxHeight }); + if (m_impl->progressBar && m_impl->progressBarFill) { + float width = m_impl->progressBarFillMaxWidth * (m_impl->progress / 100.0f); + m_impl->progressBarFill->setTextureRect({ 0.0f, 0.0f, width, m_impl->progressBarFillMaxHeight }); }; + + if (m_impl->progressPercentLabel) { + auto percentString = fmt::format("{}%", static_cast(m_impl->progress)); + m_impl->progressPercentLabel->setCString(percentString.c_str()); + }; +}; + +float ProgressBar::getProgress() const { + return m_impl->progress; +}; + +CCLabelBMFont* ProgressBar::getProgressLabel() const { + return m_impl->progressPercentLabel; +}; + +ProgressBarStyle ProgressBar::getProgressBarStyle() const { + return m_impl->style; }; -float ProgressBar::getProgress() { - return m_progress; +void ProgressBar::showProgressLabel(bool show) { + m_impl->showProgressPercentLabel = show; + if (m_impl->progressPercentLabel) m_impl->progressPercentLabel->setVisible(show); }; ProgressBar* ProgressBar::create() { @@ -62,6 +157,6 @@ ProgressBar* ProgressBar::create() { return ret; }; - CC_SAFE_DELETE(ret); + delete ret; return nullptr; }; \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBarSolid.cpp b/loader/src/ui/nodes/ProgressBarSolid.cpp deleted file mode 100644 index 7f6d6cd94..000000000 --- a/loader/src/ui/nodes/ProgressBarSolid.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include - -using namespace geode::prelude; - -bool ProgressBarSolid::init() { - if (!CCNode::init()) return false; - - this->setID("bar-solid"_spr); - - m_progressBar = CCSprite::create("GJ_progressBar_001.png"); - m_progressBar->setID("progress-bar"); - m_progressBar->setAnchorPoint({ 0.5, 0.5 }); - m_progressBar->setPosition({ m_progressBar->getScaledContentWidth() / 2.f, m_progressBar->getScaledContentHeight() / 2.f }); - m_progressBar->setColor({ 0, 0, 0 }); - m_progressBar->setOpacity(125); - - this->setScaledContentSize(m_progressBar->getScaledContentSize()); - - m_progressBarFill = CCSprite::create("GJ_progressBar_001.png"); - m_progressBarFill->setID("bar-fill"); - m_progressBarFill->setScale(0.992f); - m_progressBarFill->setScaleY(0.86f); - m_progressBarFill->setAnchorPoint({ 0, 0.5 }); - m_progressBarFill->setPosition({ 1.36f, m_progressBar->getScaledContentHeight() / 2.f }); - m_progressBarFill->setColor({ 255, 255, 255 }); - m_progressBarFill->setZOrder(1); - - m_progressBarFillMaxWidth = m_progressBar->getScaledContentWidth(); - m_progressBarFillMaxHeight = 20.f; - - m_progressBar->addChild(m_progressBarFill); - - this->addChild(m_progressBar); - this->updateProgress(0.0f); - - m_progressPercentLabel = CCLabelBMFont::create("0%", "bigFont.fnt"); - m_progressPercentLabel->setID("percent-label"); - m_progressPercentLabel->setScale(0.5f); - m_progressPercentLabel->setAnchorPoint({ 0.5, 0.5 }); - m_progressPercentLabel->setPosition({ getScaledContentWidth() / 2.f, getScaledContentHeight() / 2.f }); - m_progressPercentLabel->setZOrder(2); - - this->addChild(m_progressPercentLabel); - - return true; -}; - -void ProgressBarSolid::updateProgress(float value) { - ProgressBar::updateProgress(value); - - if (m_progressPercentLabel) { - auto percentString = fmt::format("{}%", static_cast(m_progress)); - m_progressPercentLabel->setCString(percentString.c_str()); - }; -}; - -CCLabelBMFont* ProgressBarSolid::getProgressLabel() { - return m_progressPercentLabel; -}; - -ProgressBarSolid* ProgressBarSolid::create() { - auto ret = new ProgressBarSolid(); - - if (ret && ret->init()) { - ret->autorelease(); - return ret; - }; - - CC_SAFE_DELETE(ret); - return nullptr; -}; \ No newline at end of file From 2ff3f4dfc8b1f46f56fff26c1cedf789f219caee Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Mon, 1 Sep 2025 15:31:16 -0500 Subject: [PATCH 3/7] dont force options --- loader/src/ui/nodes/ProgressBar.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp index aff9172ab..0d710329e 100644 --- a/loader/src/ui/nodes/ProgressBar.cpp +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -11,12 +11,13 @@ class ProgressBar::Impl final { float progress = 0.0f; // Current progress bar fill percentage ranging from 0 to 100 + ccColor3B progressBarFillColor = { 255, 255, 255 }; + bool showProgressPercentLabel = false; // Whether to show the label showing the percentage of the current progress + ProgressBarStyle style = ProgressBarStyle::Level; // Style of the progress bar float progressBarFillMaxWidth = 0.0f; // Max width for the progress fill bar node float progressBarFillMaxHeight = 0.0f; // Max height for the progress fill bar node - - bool showProgressPercentLabel = false; // Whether to show the label showing the percentage of the current progress }; ProgressBar::ProgressBar() { @@ -40,7 +41,7 @@ bool ProgressBar::init() { m_impl->progressBarFill->setID("progress-bar-fill"); m_impl->progressBarFill->setAnchorPoint({ 0, 0.5 }); m_impl->progressBarFill->setPosition({ 2.0f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); - m_impl->progressBarFill->setColor({ 255, 255, 255 }); + m_impl->progressBarFill->setColor(m_impl->progressBarFillColor); m_impl->progressBarFill->setZOrder(-1); m_impl->progressBarFillMaxWidth = m_impl->progressBar->getScaledContentWidth() - 4.0f; @@ -57,8 +58,6 @@ bool ProgressBar::init() { break; case ProgressBarStyle::Solid: - m_impl->showProgressPercentLabel = true; - m_impl->progressBar = CCSprite::create("GJ_progressBar_001.png"); m_impl->progressBar->setID("progress-bar"); m_impl->progressBar->setAnchorPoint({ 0.5, 0.5 }); @@ -73,7 +72,7 @@ bool ProgressBar::init() { m_impl->progressBarFill->setScaleY(0.86f); m_impl->progressBarFill->setAnchorPoint({ 0, 0.5 }); m_impl->progressBarFill->setPosition({ 1.36f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); - m_impl->progressBarFill->setColor({ 255, 255, 255 }); + m_impl->progressBarFill->setColor(m_impl->progressBarFillColor); m_impl->progressBarFill->setZOrder(0); m_impl->progressBarFillMaxWidth = m_impl->progressBar->getScaledContentWidth(); @@ -112,6 +111,7 @@ void ProgressBar::setStyle(ProgressBarStyle style) { }; void ProgressBar::setProgressBarFillColor(ccColor3B color) { + m_impl->progressBarFillColor = color; if (m_impl->progressBarFill) m_impl->progressBarFill->setColor(color); }; From 969be70e940a6e53e9076c5cb50795cdd201168e Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Mon, 1 Sep 2025 16:01:20 -0500 Subject: [PATCH 4/7] organize --- loader/src/ui/nodes/ProgressBar.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp index 0d710329e..8dd7e4862 100644 --- a/loader/src/ui/nodes/ProgressBar.cpp +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -11,7 +11,7 @@ class ProgressBar::Impl final { float progress = 0.0f; // Current progress bar fill percentage ranging from 0 to 100 - ccColor3B progressBarFillColor = { 255, 255, 255 }; + ccColor3B progressBarFillColor = { 255, 255, 255 }; // Current color of the filled progress bar bool showProgressPercentLabel = false; // Whether to show the label showing the percentage of the current progress ProgressBarStyle style = ProgressBarStyle::Level; // Style of the progress bar @@ -51,8 +51,8 @@ bool ProgressBar::init() { m_impl->progressPercentLabel->setID("progress-percent-label"); m_impl->progressPercentLabel->setScale(0.5f); m_impl->progressPercentLabel->setAnchorPoint({ 0, 0.5 }); - m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentLeft); m_impl->progressPercentLabel->setPosition({ m_impl->progressBar->getScaledContentWidth() + 2.5f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentLeft); m_impl->progressPercentLabel->setVisible(m_impl->showProgressPercentLabel); m_impl->progressPercentLabel->setZOrder(1); break; @@ -82,8 +82,8 @@ bool ProgressBar::init() { m_impl->progressPercentLabel->setID("progress-percent-label"); m_impl->progressPercentLabel->setScale(0.5f); m_impl->progressPercentLabel->setAnchorPoint({ 0.5, 0.5 }); - m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentCenter); m_impl->progressPercentLabel->setPosition({ m_impl->progressBar->getScaledContentWidth() / 2.0f, m_impl->progressBar->getScaledContentHeight() / 2.0f }); + m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentCenter); m_impl->progressPercentLabel->setVisible(m_impl->showProgressPercentLabel); m_impl->progressPercentLabel->setZOrder(1); break; @@ -94,9 +94,9 @@ bool ProgressBar::init() { m_impl->progressBar->addChild(m_impl->progressBarFill); this->addChild(m_impl->progressBar); - this->updateProgress(m_impl->progress); + this->addChild(m_impl->progressPercentLabel); - if (m_impl->progressPercentLabel) this->addChild(m_impl->progressPercentLabel); + this->updateProgress(m_impl->progress); return true; }; @@ -121,7 +121,7 @@ void ProgressBar::updateProgress(float value) { m_impl->progress = value; - if (m_impl->progressBar && m_impl->progressBarFill) { + if (m_impl->progressBarFill) { float width = m_impl->progressBarFillMaxWidth * (m_impl->progress / 100.0f); m_impl->progressBarFill->setTextureRect({ 0.0f, 0.0f, width, m_impl->progressBarFillMaxHeight }); }; From 3a78b4ea1fbb55aec065b2b9ee9ee418b334e69f Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Fri, 5 Sep 2025 14:11:45 -0500 Subject: [PATCH 5/7] customsetup, shorten func names --- loader/include/Geode/ui/ProgressBar.hpp | 19 +++++--- loader/src/ui/nodes/ProgressBar.cpp | 60 ++++++++++++++++--------- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/loader/include/Geode/ui/ProgressBar.hpp b/loader/include/Geode/ui/ProgressBar.hpp index 3afe96298..5ea30d993 100644 --- a/loader/include/Geode/ui/ProgressBar.hpp +++ b/loader/include/Geode/ui/ProgressBar.hpp @@ -18,6 +18,8 @@ namespace geode { ProgressBar(); ~ProgressBar(); + void customSetup(); + bool init() override; public: @@ -36,7 +38,7 @@ namespace geode { * * @param color RGB color object */ - void setProgressBarFillColor(ccColor3B color); + void setFillColor(ccColor3B color); /** * Update the size of the fill of the bar @@ -45,6 +47,13 @@ namespace geode { */ virtual void updateProgress(float value); + /** + * Show the label displaying the current percentage of progress + * + * @param bool Whether to toggle visibility + */ + void showProgressLabel(bool show); + /** * Get the current progress percentage of the bar */ @@ -58,13 +67,11 @@ namespace geode { /** * Get the current style of the progress bar */ - ProgressBarStyle getProgressBarStyle() const; + ProgressBarStyle getStyle() const; /** - * Show the label displaying the current percentage of progress - * - * @param bool Whether to toggle visibility + * Get the current color of the fill of the progress bar */ - void showProgressLabel(bool show); + ccColor3B getFillColor() const; }; } \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp index 8dd7e4862..087fbbca9 100644 --- a/loader/src/ui/nodes/ProgressBar.cpp +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -5,19 +5,27 @@ using namespace geode::prelude; class ProgressBar::Impl final { public: - Ref progressBar = nullptr; // Progress bar outline - CCSprite* progressBarFill = nullptr; // Progress bar fill - CCLabelBMFont* progressPercentLabel = nullptr; // The text label displaying the percentage - - float progress = 0.0f; // Current progress bar fill percentage ranging from 0 to 100 - - ccColor3B progressBarFillColor = { 255, 255, 255 }; // Current color of the filled progress bar - bool showProgressPercentLabel = false; // Whether to show the label showing the percentage of the current progress - - ProgressBarStyle style = ProgressBarStyle::Level; // Style of the progress bar - - float progressBarFillMaxWidth = 0.0f; // Max width for the progress fill bar node - float progressBarFillMaxHeight = 0.0f; // Max height for the progress fill bar node + // Progress bar outline + Ref progressBar = nullptr; + // Progress bar fill + CCSprite* progressBarFill = nullptr; + // The text label displaying the percentage + Ref progressPercentLabel = nullptr; + + // Current progress bar fill percentage ranging from 0 to 100 + float progress = 0.0f; + + // Style of the progress bar + ProgressBarStyle style = ProgressBarStyle::Level; + // Current color of the filled progress bar + ccColor3B progressBarFillColor = { 255, 255, 255 }; + // Whether to show the label showing the percentage of the current progress + bool showProgressPercentLabel = false; + + // Max width for the progress fill bar node + float progressBarFillMaxWidth = 0.0f; + // Max height for the progress fill bar node + float progressBarFillMaxHeight = 0.0f; }; ProgressBar::ProgressBar() { @@ -26,9 +34,7 @@ ProgressBar::ProgressBar() { ProgressBar::~ProgressBar() {}; -bool ProgressBar::init() { - if (!CCNode::init()) return false; - +void ProgressBar::customSetup() { switch (m_impl->style) { case ProgressBarStyle::Level: m_impl->progressBar = CCSprite::create("slidergroove2.png"); @@ -97,6 +103,12 @@ bool ProgressBar::init() { this->addChild(m_impl->progressPercentLabel); this->updateProgress(m_impl->progress); +}; + +bool ProgressBar::init() { + if (!CCNode::init()) return false; + + this->customSetup(); return true; }; @@ -106,11 +118,11 @@ void ProgressBar::setStyle(ProgressBarStyle style) { m_impl->style = style; this->removeAllChildren(); - init(); // init again with new style + this->customSetup(); // setup again with new style }; }; -void ProgressBar::setProgressBarFillColor(ccColor3B color) { +void ProgressBar::setFillColor(ccColor3B color) { m_impl->progressBarFillColor = color; if (m_impl->progressBarFill) m_impl->progressBarFill->setColor(color); }; @@ -132,6 +144,11 @@ void ProgressBar::updateProgress(float value) { }; }; +void ProgressBar::showProgressLabel(bool show) { + m_impl->showProgressPercentLabel = show; + if (m_impl->progressPercentLabel) m_impl->progressPercentLabel->setVisible(show); +}; + float ProgressBar::getProgress() const { return m_impl->progress; }; @@ -140,13 +157,12 @@ CCLabelBMFont* ProgressBar::getProgressLabel() const { return m_impl->progressPercentLabel; }; -ProgressBarStyle ProgressBar::getProgressBarStyle() const { +ProgressBarStyle ProgressBar::getStyle() const { return m_impl->style; }; -void ProgressBar::showProgressLabel(bool show) { - m_impl->showProgressPercentLabel = show; - if (m_impl->progressPercentLabel) m_impl->progressPercentLabel->setVisible(show); +ccColor3B ProgressBar::getFillColor() const { + return m_impl->progressBarFillColor; }; ProgressBar* ProgressBar::create() { From 746e39781adf2182a7ac8c50e9b7bb65f620e08d Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Sat, 20 Sep 2025 13:18:32 -0500 Subject: [PATCH 6/7] add percent precision, tweak some stuff --- loader/include/Geode/ui/ProgressBar.hpp | 17 ++++++++++++++-- loader/src/ui/nodes/ProgressBar.cpp | 26 +++++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/loader/include/Geode/ui/ProgressBar.hpp b/loader/include/Geode/ui/ProgressBar.hpp index 5ea30d993..7c17aa5d3 100644 --- a/loader/include/Geode/ui/ProgressBar.hpp +++ b/loader/include/Geode/ui/ProgressBar.hpp @@ -16,9 +16,10 @@ namespace geode { std::unique_ptr m_impl; ProgressBar(); - ~ProgressBar(); + virtual ~ProgressBar(); - void customSetup(); + // Reload the style of the progress bar + void reloadStyle(); bool init() override; @@ -40,6 +41,13 @@ namespace geode { */ void setFillColor(ccColor3B color); + /** + * Set the progress percentage of the bar + * + * @param precision Number of decimal places to show in the percentage label + */ + void setPrecision(size_t precision); + /** * Update the size of the fill of the bar * @@ -73,5 +81,10 @@ namespace geode { * Get the current color of the fill of the progress bar */ ccColor3B getFillColor() const; + + /** + * Get the current precision of the percentage label + */ + size_t getPrecision() const; }; } \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp index 087fbbca9..310278286 100644 --- a/loader/src/ui/nodes/ProgressBar.cpp +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -21,6 +21,8 @@ class ProgressBar::Impl final { ccColor3B progressBarFillColor = { 255, 255, 255 }; // Whether to show the label showing the percentage of the current progress bool showProgressPercentLabel = false; + // Precision of the percentage label + size_t precision = 0; // Max width for the progress fill bar node float progressBarFillMaxWidth = 0.0f; @@ -34,9 +36,9 @@ ProgressBar::ProgressBar() { ProgressBar::~ProgressBar() {}; -void ProgressBar::customSetup() { +void ProgressBar::reloadStyle() { switch (m_impl->style) { - case ProgressBarStyle::Level: + case ProgressBarStyle::Level: { m_impl->progressBar = CCSprite::create("slidergroove2.png"); m_impl->progressBar->setID("progress-bar"); m_impl->progressBar->setAnchorPoint({ 0.5, 0.5 }); @@ -61,9 +63,9 @@ void ProgressBar::customSetup() { m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentLeft); m_impl->progressPercentLabel->setVisible(m_impl->showProgressPercentLabel); m_impl->progressPercentLabel->setZOrder(1); - break; + } break; - case ProgressBarStyle::Solid: + case ProgressBarStyle::Solid: { m_impl->progressBar = CCSprite::create("GJ_progressBar_001.png"); m_impl->progressBar->setID("progress-bar"); m_impl->progressBar->setAnchorPoint({ 0.5, 0.5 }); @@ -92,7 +94,7 @@ void ProgressBar::customSetup() { m_impl->progressPercentLabel->setAlignment(CCTextAlignment::kCCTextAlignmentCenter); m_impl->progressPercentLabel->setVisible(m_impl->showProgressPercentLabel); m_impl->progressPercentLabel->setZOrder(1); - break; + } break; }; this->setScaledContentSize(m_impl->progressBar->getScaledContentSize()); @@ -108,7 +110,7 @@ void ProgressBar::customSetup() { bool ProgressBar::init() { if (!CCNode::init()) return false; - this->customSetup(); + this->reloadStyle(); return true; }; @@ -118,7 +120,7 @@ void ProgressBar::setStyle(ProgressBarStyle style) { m_impl->style = style; this->removeAllChildren(); - this->customSetup(); // setup again with new style + this->reloadStyle(); // setup again with new style }; }; @@ -127,6 +129,10 @@ void ProgressBar::setFillColor(ccColor3B color) { if (m_impl->progressBarFill) m_impl->progressBarFill->setColor(color); }; +void ProgressBar::setPrecision(size_t precision) { + m_impl->precision = precision; +}; + void ProgressBar::updateProgress(float value) { if (value > 100.0f) value = 100.0f; if (value < 0.0f) value = 0.0f; @@ -139,7 +145,7 @@ void ProgressBar::updateProgress(float value) { }; if (m_impl->progressPercentLabel) { - auto percentString = fmt::format("{}%", static_cast(m_impl->progress)); + auto percentString = fmt::format("{}%", geode::utils::numToString(m_impl->progress, m_impl->precision)); m_impl->progressPercentLabel->setCString(percentString.c_str()); }; }; @@ -165,6 +171,10 @@ ccColor3B ProgressBar::getFillColor() const { return m_impl->progressBarFillColor; }; +size_t ProgressBar::getPrecision() const { + return m_impl->precision; +}; + ProgressBar* ProgressBar::create() { auto ret = new ProgressBar(); From de1d55c0df5720a60cca4bdf8cafb91bb79403bb Mon Sep 17 00:00:00 2001 From: Cheeseworks Date: Sat, 20 Sep 2025 14:24:26 -0500 Subject: [PATCH 7/7] update progressbar when setting precision --- loader/include/Geode/ui/ProgressBar.hpp | 8 ++++---- loader/src/ui/nodes/ProgressBar.cpp | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/loader/include/Geode/ui/ProgressBar.hpp b/loader/include/Geode/ui/ProgressBar.hpp index 7c17aa5d3..add5fe886 100644 --- a/loader/include/Geode/ui/ProgressBar.hpp +++ b/loader/include/Geode/ui/ProgressBar.hpp @@ -18,7 +18,7 @@ namespace geode { ProgressBar(); virtual ~ProgressBar(); - // Reload the style of the progress bar + // Reloads the style of the progress bar void reloadStyle(); bool init() override; @@ -42,7 +42,7 @@ namespace geode { void setFillColor(ccColor3B color); /** - * Set the progress percentage of the bar + * Set the precision of the percentage label * * @param precision Number of decimal places to show in the percentage label */ @@ -83,8 +83,8 @@ namespace geode { ccColor3B getFillColor() const; /** - * Get the current precision of the percentage label + * Get the precision of the percentage label */ size_t getPrecision() const; }; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/loader/src/ui/nodes/ProgressBar.cpp b/loader/src/ui/nodes/ProgressBar.cpp index 310278286..88a4bb960 100644 --- a/loader/src/ui/nodes/ProgressBar.cpp +++ b/loader/src/ui/nodes/ProgressBar.cpp @@ -21,7 +21,7 @@ class ProgressBar::Impl final { ccColor3B progressBarFillColor = { 255, 255, 255 }; // Whether to show the label showing the percentage of the current progress bool showProgressPercentLabel = false; - // Precision of the percentage label + // Precision of the percentage on the progress percent label size_t precision = 0; // Max width for the progress fill bar node @@ -131,6 +131,7 @@ void ProgressBar::setFillColor(ccColor3B color) { void ProgressBar::setPrecision(size_t precision) { m_impl->precision = precision; + this->updateProgress(m_impl->progress); // update label with new precision }; void ProgressBar::updateProgress(float value) {