-
Notifications
You must be signed in to change notification settings - Fork 240
Progress bar helper class #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+278
−0
Merged
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d78f3ad
progress bars
BlueWitherer 5833511
Merge branch 'geode-sdk:main' into main
BlueWitherer 9cd6e67
Merge branch 'geode-sdk:main' into main
BlueWitherer 4313cf7
Merge branch 'geode-sdk:main' into main
BlueWitherer 7dd5c09
merge classes and add pimpl
BlueWitherer 2ff3f4d
dont force options
BlueWitherer 969be70
organize
BlueWitherer 3a78b4e
customsetup, shorten func names
BlueWitherer 1a59f41
Merge branch 'geode-sdk:main' into main
BlueWitherer 0ba5b28
Merge branch 'geode-sdk:main' into main
BlueWitherer 2f8003c
Merge branch 'geode-sdk:main' into main
BlueWitherer 746e397
add percent precision, tweak some stuff
BlueWitherer de1d55c
update progressbar when setting precision
BlueWitherer 1b9cf7c
Merge branch 'geode-sdk:main' into main
BlueWitherer f4043ed
Merge branch 'geode-sdk:main' into main
BlueWitherer 32fdb95
fix cocos type defs
BlueWitherer 2f34cb9
fix dll
BlueWitherer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #pragma once | ||
|
|
||
| #include <cocos2d.h> | ||
|
|
||
| namespace geode { | ||
| // Custom class for the progress bar | ||
| class ProgressBar : public cocos2d::CCNode { | ||
| protected: | ||
| Ref<CCSprite> 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); | ||
HJfod marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * 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(); | ||
BlueWitherer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
|
|
||
| #include <cocos2d.h> | ||
| #include <Geode/ui/ProgressBar.hpp> | ||
|
|
||
| namespace geode { | ||
| // Custom class for the Normal/Practice mode style progress bar | ||
| class ProgressBarSolid : public ProgressBar { | ||
BlueWitherer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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(); | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #include <cocos2d.h> | ||
| #include <Geode/ui/ProgressBar.hpp> | ||
|
|
||
| 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); | ||
BlueWitherer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #include <cocos2d.h> | ||
| #include <Geode/ui/ProgressBar.hpp> | ||
| #include <Geode/ui/ProgressBarSolid.hpp> | ||
|
|
||
| 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<int>(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; | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.