Skip to content

Commit

Permalink
Fix texture rotation, fix callbacks, add hex
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Dec 20, 2024
1 parent e8ce717 commit 84bc420
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.7.5
- Allow inputting hex colors
- Fix sprite frame texture rotate bug
- Fix an issue where onCreator and onGarage wouldn't work

## 1.7.4
- Fix a crash that can occur when pressing space on the main menu
- Fix a crash that can occur with invalid parents
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"android": "2.2074",
"mac": "2.2074"
},
"version": "v1.7.4",
"version": "v1.7.5",
"id": "alphalaneous.happy_textures",
"name": "Happy Textures :3",
"developer": "Alphalaneous",
Expand Down
20 changes: 16 additions & 4 deletions src/UIModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,18 @@ void UIModding::setColor(CCNode* node, matjson::Value attributes) {
}
}
}
else if (utils::string::startsWith(colorStr, "#")) {
ccColor3B color = cc3bFromHexString(colorStr).unwrapOr(ccColor3B{255, 0, 255});
if (CCMenuItemSpriteExtra* node1 = typeinfo_cast<CCMenuItemSpriteExtra*>(node)) {
node1->setColor(color);
if (ButtonSprite* node2 = node1->getChildByType<ButtonSprite>(0)) {
node2->setColor(color);
}
}
if (CCRGBAProtocol* node1 = typeinfo_cast<CCRGBAProtocol*>(node)) {
node1->setColor(color);
}
}
}
}
}
Expand Down Expand Up @@ -975,7 +987,7 @@ void UIModding::setSprite(CCNode* node, matjson::Value attributes) {

if (CCSprite* spriteNode = typeinfo_cast<CCSprite*>(node)) {
spriteNode->setTexture(spr->getTexture());
spriteNode->setTextureRect(spr->getTextureRect());
spriteNode->setTextureRect(spr->getTextureRect(), spr->isTextureRectRotated(), spr->getContentSize());
}
if (CCMenuItemSpriteExtra* buttonNode = typeinfo_cast<CCMenuItemSpriteExtra*>(node)) {

Expand Down Expand Up @@ -1029,7 +1041,7 @@ void UIModding::setSprite(CCNode* node, matjson::Value attributes) {
}
else if (CCSprite* sprite = node->getChildByType<CCSprite>(0)) {
sprite->setTexture(spr->getTexture());
sprite->setTextureRect(spr->getTextureRect());
sprite->setTextureRect(spr->getTextureRect(), spr->isTextureRectRotated(), spr->getContentSize());
sprite->setContentSize(spr->getContentSize());
buttonNode->setContentSize(spr->getContentSize());
sprite->setPosition(buttonNode->getContentSize()/2);
Expand All @@ -1049,15 +1061,15 @@ void UIModding::setSpriteFrame(CCNode* node, matjson::Value attributes) {
if(spr) {
spriteNode->setTextureAtlas(spr->getTextureAtlas());
spriteNode->setTexture(spr->getTexture());
spriteNode->setTextureRect(spr->getTextureRect());
spriteNode->setTextureRect(spr->getTextureRect(), spr->isTextureRectRotated(), spr->getContentSize());
}
}
if (CCMenuItemSpriteExtra* buttonNode = typeinfo_cast<CCMenuItemSpriteExtra*>(node)) {
CCSprite* spr = Utils::getValidSpriteFrame(spriteName.c_str());
if (spr) {
if (CCSprite* spriteNode = buttonNode->getChildByType<CCSprite>(0)) {
spriteNode->setTexture(spr->getTexture());
spriteNode->setTextureRect(spr->getTextureRect());
spriteNode->setTextureRect(spr->getTextureRect(), spr->isTextureRectRotated(), spr->getContentSize());
spriteNode->setTextureAtlas(spr->getTextureAtlas());
spriteNode->setContentSize(spr->getContentSize());
buttonNode->setContentSize(spr->getContentSize());
Expand Down
20 changes: 20 additions & 0 deletions src/nodes/MenuLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ class $modify(MyMenuLayer, MenuLayer) {
MenuLayer::onPlay(obj);
}

void onCreator(CCObject* obj) {
if (CCNode* node = typeinfo_cast<CCNode*>(obj)) {
if (node->getUserObject("dummy"_spr)) {
CCDirector::get()->pushScene(CCTransitionFade::create(0.5, CreatorLayer::scene()));
return;
}
}
MenuLayer::onCreator(obj);
}

void onGarage(CCObject* obj) {
if (CCNode* node = typeinfo_cast<CCNode*>(obj)) {
if (node->getUserObject("dummy"_spr)) {
CCDirector::get()->pushScene(CCTransitionFade::create(0.5, GJGarageLayer::scene()));
return;
}
}
MenuLayer::onGarage(obj);
}

bool init() {
UIModding::get()->finishedLoad = true;
if (!MenuLayer::init()) return false;
Expand Down

0 comments on commit 84bc420

Please sign in to comment.