Skip to content

Commit

Permalink
Important fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alphalaneous committed Aug 14, 2024
1 parent 1eab60e commit c1550f1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 24 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ When it comes to using the position attribute, you can change the x and y coordi
<td>


</td>
</tr>

<tr>
<td> base-scale </td>
<td> Set the base scale of a button (scaling a button returns to this rather than 1 when clicked). </td>
<td>

```json
"base-scale": 2
```

</td>

<td>


</td>
</tr>

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.206",
"mac": "2.206"
},
"version": "v1.3.23",
"version": "v1.4.0",
"id": "alphalaneous.happy_textures",
"name": "Happy Textures :3",
"developer": "Alphalaneous",
Expand Down
15 changes: 14 additions & 1 deletion src/UIModding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ void UIModding::playSound(CCNode* node, matjson::Object attributes){
std::string sound = soundVal.as_string();

#ifndef GEODE_IS_ANDROID
FMODAudioEngine::sharedEngine()->m_currentSoundChannel->setPaused(false);
FMODAudioEngine::sharedEngine()->m_backgroundMusicChannel->setPaused(false);
FMODAudioEngine::sharedEngine()->m_globalChannel->setPaused(false);
FMODAudioEngine::sharedEngine()->m_channelGroup2->setPaused(false);
FMODAudioEngine::sharedEngine()->m_system->update();
#endif
std::string soundPath = getSound(sound);
Expand Down Expand Up @@ -821,6 +821,18 @@ void UIModding::setScaleMult(CCNode* node, matjson::Object attributes){
}
}

void UIModding::setScaleBase(CCNode* node, matjson::Object attributes){
if(attributes.contains("base-scale")){
matjson::Value baseVal = attributes["base-scale"];
if(baseVal.is_number()){
float base = baseVal.as_double();
if(CCMenuItemSpriteExtra* button = typeinfo_cast<CCMenuItemSpriteExtra*>(node)) {
button->m_baseScale = base;
}
}
}
}

void UIModding::setText(CCNode* node, matjson::Object attributes){
if(attributes.contains("text")){
matjson::Value textVal = attributes["text"];
Expand Down Expand Up @@ -1174,6 +1186,7 @@ void UIModding::handleModifications(CCNode* node, matjson::Object nodeObject){
nodesFor(setPosition);
nodesFor(setText);
nodesFor(setScaleMult);
nodesFor(setScaleBase);
nodesFor(setZOrder);
nodesFor(setFont);
nodesFor(setFlip);
Expand Down
1 change: 1 addition & 0 deletions src/UIModding.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class UIModding {
void setColor(CCNode* node, matjson::Object attributes);
void setText(CCNode* node, matjson::Object attributes);
void setScaleMult(CCNode* node, matjson::Object attributes);
void setScaleBase(CCNode* node, matjson::Object attributes);
void setZOrder(CCNode* node, matjson::Object attributes);
void setFont(CCNode* node, matjson::Object attributes);
void setFlip(CCNode* node, matjson::Object attributes);
Expand Down
48 changes: 26 additions & 22 deletions src/nodes/MenuGameLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,29 @@ class $modify(MyMenuGameLayer, MenuGameLayer){
(void) self.setHookPriority("MenuGameLayer::update", INT_MIN);
}

void updateGroundSprite(CCSprite* spr){
std::optional<ColorData> dataOpt = UIModding::get()->getColors("main-menu-ground");
if(dataOpt.has_value()){
for(CCNode* node : CCArrayExt<CCNode*>(spr->getChildren())){
if(CCSprite* child = typeinfo_cast<CCSprite*>(node)){
ColorData data = dataOpt.value();
child->setColor(data.color);
child->setOpacity(data.alpha);
}
}
ColorData data = dataOpt.value();
spr->setColor(data.color);
spr->setOpacity(data.alpha);
}
}

void update(float p0){
MenuGameLayer::update(p0);

if(UIModding::get()->doModify){

CCSprite* bg = getChildOfType<CCSprite>(this, 0);
GJGroundLayer* ground = getChildOfType<GJGroundLayer>(this, 0);
CCSprite* bg = typeinfo_cast<CCSprite*>(getChildByID("background"));
GJGroundLayer* ground = typeinfo_cast<GJGroundLayer*>(getChildByID("ground"));

if(bg){
std::optional<ColorData> dataOpt = UIModding::get()->getColors("main-menu-bg");
Expand All @@ -31,26 +47,14 @@ class $modify(MyMenuGameLayer, MenuGameLayer){
}
}
if(ground){
CCSpriteBatchNode* groundBatch = getChildOfType<CCSpriteBatchNode>(ground, 0);
if(groundBatch){
CCSprite* groundSprite = getChildOfType<CCSprite>(groundBatch, 0);
if(groundSprite){
for(CCNode* node : CCArrayExt<CCNode*>(groundSprite->getChildren())){
if(CCSprite* child = typeinfo_cast<CCSprite*>(node)){
std::optional<ColorData> dataOpt = UIModding::get()->getColors("main-menu-ground");
if(dataOpt.has_value()){
ColorData data = dataOpt.value();
child->setColor(data.color);
child->setOpacity(data.alpha);
}
}
}
std::optional<ColorData> dataOpt = UIModding::get()->getColors("main-menu-ground");
if(dataOpt.has_value()){
ColorData data = dataOpt.value();
groundSprite->setColor(data.color);
groundSprite->setOpacity(data.alpha);
}
if(CCSpriteBatchNode* groundSprites = typeinfo_cast<CCSpriteBatchNode*>(ground->getChildByID("ground-sprites"))){
if(CCSprite* groundSprite = getChildOfType<CCSprite>(groundSprites, 0)) {
updateGroundSprite(groundSprite);
}
}
if(CCSpriteBatchNode* groundSprites2 = typeinfo_cast<CCSpriteBatchNode*>(ground->getChildByID("ground-sprites-2"))){
if(CCSprite* groundSprite = getChildOfType<CCSprite>(groundSprites2, 0)) {
updateGroundSprite(groundSprite);
}
}
}
Expand Down

0 comments on commit c1550f1

Please sign in to comment.