Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Sep 26, 2024
1 parent 4b1efbf commit c867094
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.6.8

- Fixed checking for updates text being positioned wrong when the Loading Circle is visible
- Fixed freeze when opening the font picker menu for the first time

# 1.6.7

- Fixed Speedhack not working with physics bypass enabled in cbf
Expand Down
2 changes: 1 addition & 1 deletion mod.json
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",
Expand Down
2 changes: 1 addition & 1 deletion src/Client/AndroidBall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bool AndroidBall::init()

this->setID("QOLModButton"_spr);
this->setMouseEnabled(false);
this->setTouchEnabled(true);
this->setTouchEnabled(false);

highest++;
this->setTag(highest);
Expand Down
2 changes: 1 addition & 1 deletion src/Client/AndroidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ void AndroidUI::updateVersionLabel()

updateListener.setFilter(Mod::get()->checkUpdates());

versionParent->updateLayout();
return;
}

Expand All @@ -235,7 +236,6 @@ void AndroidUI::updateVersionLabel()
n->setColor(ccc3(87, 87, 255));
}
}

}

versionParent->updateLayout();
Expand Down
9 changes: 6 additions & 3 deletions src/Layers/ChooseFontPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void ChooseFontPopup::customSetup()
{
// 59 being the custom song count
// 59 being the custom font count
int fontCount = 59 + 3;
float cellSize = 30;

Expand Down Expand Up @@ -69,9 +69,12 @@ void ChooseFontPopup::customSetup()

toggles.push_back(btn);

auto lbl = CCLabelBMFont::create(name.c_str(), font.c_str());
auto lbl = ThreadedLabelBMFont::create(name.c_str(), font.c_str(), [this](ThreadedLabelBMFont* label)
{
label->getLabel()->setScale(20 / label->getLabel()->getContentHeight());
});

lbl->setAnchorPoint(ccp(0, 0.5f));
lbl->setScale(20 / lbl->getContentHeight());

cell->addChildAtPosition(menu, Anchor::Right, ccp(-17.5f, 0));
cell->addChildAtPosition(lbl, Anchor::Left, ccp(6, 0));
Expand Down
1 change: 1 addition & 0 deletions src/Layers/ChooseFontPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Geode/Geode.hpp>
#include "../Client/Module.h"
#include "../Hacks/SafeMode/SafeMode.hpp"
#include "../UI/ThreadedLabelBMFont.hpp"

#include "SillyBaseLayer.h"

Expand Down
104 changes: 104 additions & 0 deletions src/UI/ThreadedLabelBMFont.cpp
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;
}
28 changes: 28 additions & 0 deletions src/UI/ThreadedLabelBMFont.hpp
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);
};

0 comments on commit c867094

Please sign in to comment.