Skip to content

Commit

Permalink
fuck it no animated emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Jan 6, 2025
1 parent 3679185 commit 289eefb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
23 changes: 22 additions & 1 deletion src/CCLabelBMFontExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ void CCLabelBMFontExt::updateLabel()

objNode->removeAllChildrenWithCleanup(true);

auto oldParts = parts;
for (auto& oldPart : oldParts)
{
oldPart.node = nullptr;
}

parts.clear();

CCSize size = CCSizeMake(0, 0);
Expand Down Expand Up @@ -331,6 +335,21 @@ void CCLabelBMFontExt::updateLabel()
if (!spr)
continue;

if (!oldParts.empty())
{
if (oldParts.size() - 1 >= i)
{
if (oldParts[i].type == LabelPartType::Emoji && oldParts[i].extra == parts[i].extra)
{
spr->progress = oldParts[i].progress;
parts[i].progress = oldParts[i].progress + CCDirector::get()->getDeltaTime();

spr->update(CCDirector::get()->getDeltaTime());
spr->updateFrame(0);
}
}
}

spr->setPosition(ccp(size.width + x / 2, 0));
spr->setAnchorPoint(ccp(0, 0));
spr->setScale(spr->getContentHeight() == 0 ? 1 : (h / spr->getContentHeight()));
Expand All @@ -346,6 +365,8 @@ void CCLabelBMFontExt::updateLabel()
}

this->setContentSize(size);

oldParts = parts;
}

void CCLabelBMFontExt::addChild(CCNode* child)
Expand Down
13 changes: 9 additions & 4 deletions src/CCLabelBMFontExt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ using namespace geode::prelude;

//#define _Emoji(id) std::pair(id, std::string(""_spr) + id + std::string(".png"))

enum LabelPartType {
enum LabelPartType
{
Text,
Emoji,
Username,
Url,
Level
};

struct LabelPart {
struct LabelPart
{
LabelPartType type = LabelPartType::Text;
std::string extra;
CCNode* node;
CCNode* node = nullptr;
float progress = 0.0f;

LabelPart(LabelPartType type, std::string ext);

Expand All @@ -35,7 +38,8 @@ struct LabelPart {
bool isValidEmoji();
};

class CCLabelBMFontExt : public CCLabelBMFont {
class CCLabelBMFontExt : public CCLabelBMFont
{
public:
std::string string = "";
std::string font = "";
Expand All @@ -44,6 +48,7 @@ class CCLabelBMFontExt : public CCLabelBMFont {
GLubyte opacity = 255;
CCNode* objNode;
std::vector<LabelPart> parts;
std::vector<LabelPart> oldParts;

virtual void setString(const char *newString);
virtual void setString(const char *newString, bool needUpdateLabel);
Expand Down
26 changes: 19 additions & 7 deletions src/EmojiNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ bool EmojiNode::initWithAnimatedSprite(std::string key, float rate)
}
}

this->rate = rate;

if (frames.size() > 0)
this->schedule(schedule_selector(EmojiNode::updateFrame), rate);
this->scheduleUpdate();

return true;
}
Expand All @@ -66,19 +68,29 @@ EmojiNode* EmojiNode::createWithKey(std::string key)

void EmojiNode::updateFrame(float)
{
currentFrame++;

if (currentFrame >= frames.size())
currentFrame = 0;

int i = 0;
for (auto frame : frames)
{
frames[i]->setVisible(i == currentFrame);
i++;
}
}

void EmojiNode::update(float dt)
{
progress = progress + dt;

//this->setDisplayFrame(frames[currentFrame]);
if (progress > rate)
{
progress -= rate;

currentFrame++;

if (currentFrame >= frames.size())
currentFrame = 0;

updateFrame(0.80085f);
}
}

const char* EmojiNode::frameForKey(std::string key)
Expand Down
4 changes: 4 additions & 0 deletions src/EmojiNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ class EmojiNode : public CCSprite
{
public:
int currentFrame;
float progress = 0;
float rate = 0;
std::vector<CCSprite*> frames;


void updateFrame(float);
virtual void update(float dt);

bool init(std::string key);
bool initWithKey(std::string key);
Expand Down

0 comments on commit 289eefb

Please sign in to comment.