-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TheSillyDoggo
committed
Sep 26, 2024
1 parent
4b1efbf
commit c867094
Showing
8 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"geode": "3.7.1", | ||
"version": "v1.6.7", | ||
"version": "v1.6.8", | ||
"gd": { | ||
"win": "2.206", | ||
"android": "2.206", | ||
|
This file contains 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 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 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 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 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,104 @@ | ||
#include "ThreadedLabelBMFont.hpp" | ||
|
||
bool ThreadedLabelBMFont::init(std::string text, std::string font, MiniFunction<void(ThreadedLabelBMFont*)> callback) | ||
{ | ||
if (!CCNode::init()) | ||
return false; | ||
|
||
this->text = text; | ||
this->font = font; | ||
this->callback = callback; | ||
|
||
if (CCTextureCache::get()->textureForKey(utils::string::replace(font, ".fnt", ".png").c_str())) | ||
{ | ||
addLabel(); | ||
} | ||
else | ||
{ | ||
labels.push_back(this); | ||
this->retain(); | ||
|
||
if (labels.size() - 1 == 0) | ||
{ | ||
Loader::get()->queueInMainThread([this] | ||
{ | ||
queueStep(); | ||
}); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void ThreadedLabelBMFont::queueStep() | ||
{ | ||
if (labels.size() == 0) | ||
return; | ||
|
||
if (auto lbl = as<Ref<ThreadedLabelBMFont>>(labels[0])) | ||
{ | ||
auto conf = FNTConfigLoadFile(lbl->font.c_str()); | ||
|
||
CCTextureCache::get()->addImage(conf->getAtlasName(), false); | ||
|
||
auto fnt = lbl->font; | ||
|
||
for (auto lbl : labels) | ||
{ | ||
if (lbl->font == fnt) | ||
{ | ||
lbl->addLabel(); | ||
lbl->release(); | ||
} | ||
} | ||
|
||
labels.erase(std::remove_if(labels.begin(), labels.end(), [fnt](ThreadedLabelBMFont* obj) | ||
{ | ||
return obj->getFont() == fnt; | ||
})); | ||
|
||
if (labels.size() != 0) | ||
{ | ||
Loader::get()->queueInMainThread([this] | ||
{ | ||
queueStep(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
void ThreadedLabelBMFont::addLabel() | ||
{ | ||
label = CCLabelBMFont::create(text.c_str(), font.c_str()); | ||
this->addChild(label); | ||
|
||
if (callback) | ||
callback(this); | ||
|
||
this->setContentSize(label->getScaledContentSize()); | ||
label->setAnchorPoint(ccp(0, 0)); | ||
} | ||
|
||
CCLabelBMFont* ThreadedLabelBMFont::getLabel() | ||
{ | ||
return label; | ||
} | ||
|
||
std::string ThreadedLabelBMFont::getFont() | ||
{ | ||
return font; | ||
} | ||
|
||
ThreadedLabelBMFont* ThreadedLabelBMFont::create(std::string text, std::string font, MiniFunction<void(ThreadedLabelBMFont*)> callback) | ||
{ | ||
auto pRet = new ThreadedLabelBMFont(); | ||
|
||
if (pRet && pRet->init(text, font, callback)) | ||
{ | ||
pRet->autorelease(); | ||
return pRet; | ||
} | ||
|
||
CC_SAFE_DELETE(pRet); | ||
return nullptr; | ||
} |
This file contains 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,28 @@ | ||
#pragma once | ||
|
||
#include <Geode/Geode.hpp> | ||
|
||
using namespace geode::prelude; | ||
|
||
class ThreadedLabelBMFont : public CCNode | ||
{ | ||
private: | ||
CCLabelBMFont* label; | ||
std::string text; | ||
std::string font; | ||
MiniFunction<void(ThreadedLabelBMFont*)> callback; | ||
|
||
static inline std::vector<ThreadedLabelBMFont*> labels = {}; | ||
|
||
void addLabel(); | ||
void queueStep(); | ||
|
||
public: | ||
CCLabelBMFont* getLabel(); | ||
std::string getFont(); | ||
|
||
bool init(std::string text, std::string font, MiniFunction<void(ThreadedLabelBMFont*)> callback); | ||
|
||
// Callback is always run on main thread | ||
static ThreadedLabelBMFont* create(std::string text, std::string font, MiniFunction<void(ThreadedLabelBMFont*)> callback = nullptr); | ||
}; |