From 8632d97f3c6aaa5d03a0791f8ed91ea3075244ec Mon Sep 17 00:00:00 2001 From: Justin Pridgen Date: Tue, 11 Jun 2024 14:40:09 -0400 Subject: [PATCH] v1.1.9-beta.2 --- changelog.md | 4 + mod.json | 2 +- src/FREditPopup.cpp | 199 ++++++++++++++++++++------------------------ src/FREditPopup.hpp | 9 -- src/FakeRate.cpp | 30 +++---- src/FakeRate.hpp | 4 +- 6 files changed, 110 insertions(+), 138 deletions(-) diff --git a/changelog.md b/changelog.md index 451f8ea..1c6a673 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ # Fake Rate Changelog +## v1.1.9-beta.2 (2024-06-11) +- Fixed incompatibility with the mod "More Difficulties" by uproxide (Again like seriously how many times do I have to fix this) +- Fixed estimated time label not positioning correctly + ## v1.1.9-beta.1 (2024-06-08) - Fixed a few things diff --git a/mod.json b/mod.json index 564d28c..50fe670 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "win": "2.206", "mac": "2.206" }, - "version": "v1.1.9-beta.1", + "version": "v1.1.9-beta.2", "id": "hiimjustin000.fake_rate", "name": "Fake Rate", "developer": "hiimjustin000", diff --git a/src/FREditPopup.cpp b/src/FREditPopup.cpp index a2598d8..ada25d4 100644 --- a/src/FREditPopup.cpp +++ b/src/FREditPopup.cpp @@ -1,3 +1,4 @@ +#include #include "FREditPopup.hpp" void FRLevelInfoLayer::onModify(auto& self) { @@ -123,8 +124,8 @@ void FRLevelInfoLayer::updateFakeRate(int stars, int feature, int difficulty, bo } } if (m_level->m_dailyID > 0 || m_level->m_gauntletLevel) { - auto diamondLabel = getChildOfType(this, update ? 5 : m_level->m_dailyID > 0 ? 7 : 6); - auto diamondIcon = static_cast(getChildBySpriteFrameName(this, "diamond_small01_001.png")); + auto diamondLabel = static_cast(getChildByID("diamond-label")); + auto diamondIcon = getChildByID("diamond-icon"); auto diamonds = stars > 1 ? stars + 2 : 0; diamondLabel->setString(fmt::format("{}/{}", (int)floorf(diamonds * m_level->m_normalPercent / 100.0f), diamonds).c_str()); diamondIcon->setPosition({ @@ -142,7 +143,7 @@ void FRLevelInfoLayer::updateFakeRate(int stars, int feature, int difficulty, bo m_likesLabel->setPositionY(m_likesIcon->getPositionY()); auto lengthIcon = static_cast(m_icons->objectAtIndex(0)); lengthIcon->setPositionY(yPos - yOffset); - m_lengthLabel->setPositionY(lengthIcon->getPositionY()); + m_lengthLabel->setPositionY(lengthIcon->getPositionY() + (m_exactLengthLabel->isVisible() ? 6.0f : 0.0f)); m_orbsIcon->setVisible(showStars); m_orbsLabel->setVisible(showStars); if (showStars) { @@ -153,10 +154,7 @@ void FRLevelInfoLayer::updateFakeRate(int stars, int feature, int difficulty, bo m_orbsLabel->setString(fmt::format("{}/{}", (int)floorf(m_level->m_normalPercent != 100 ? orbs * m_level->m_normalPercent / 100.0f : totalOrbs), totalOrbs).c_str()); m_orbsLabel->limitLabelWidth(60.0f, 0.5f, 0.0f); } - if (auto exactTime = static_cast(getChildByID("cvolton.betterinfo/exact-time"))) { - exactTime->setPositionY(m_lengthLabel->getPositionY() - 2.0f); - m_lengthLabel->setPositionY(m_lengthLabel->getPositionY() + 6.0f); - } + if (m_exactLengthLabel->isVisible()) m_exactLengthLabel->setPositionY(m_lengthLabel->getPositionY() - 14.0f); if (Loader::get()->isModLoaded("uproxide.more_difficulties")) fixMoreDifficultiesIncompatibility(difficultySpriteParent); } @@ -167,6 +165,21 @@ void FRLevelInfoLayer::fixMoreDifficultiesIncompatibility(CCNode* difficultySpri if (moreDifficultiesSprite) { moreDifficultiesSprite->setVisible(false); spriteName = FakeRate::getSpriteName(moreDifficultiesSprite); + } // thanks uproxide for making my life worse + else { + auto children = getChildren(); + for (int i = 0; i < children->count(); i++) { + if (auto child = typeinfo_cast(children->objectAtIndex(i))) { + auto sprName = FakeRate::getSpriteName(child); + if (string::startsWith(sprName, "uproxide.more_difficulties/MD_Difficulty")) { + moreDifficultiesSprite = child; + moreDifficultiesSprite->setID("uproxide.more_difficulties/more-difficulties-spr"); + moreDifficultiesSprite->setVisible(false); + spriteName = sprName; + break; + } + } + } } m_difficultySprite->setOpacity(255); @@ -239,7 +252,7 @@ bool FREditPopup::setup(FRLevelInfoLayer* delegate, GJGameLevel* level, int star setTitle("Fake Rate"); m_delegate = delegate; m_level = level; - m_stars = stars; + m_stars = stars < 1 ? 1 : stars; m_feature = feature; m_difficulty = difficulty; @@ -249,7 +262,7 @@ bool FREditPopup::setup(FRLevelInfoLayer* delegate, GJGameLevel* level, int star if (Loader::get()->isModLoaded("uproxide.more_difficulties")) { auto legacy = Loader::get()->getLoadedMod("uproxide.more_difficulties")->getSettingValue("legacy-difficulties"); - auto pos = CCPoint { legacy ? 100.0f : 100.25f, legacy ? 85.0f : 84.9f }; + auto pos = CCPoint { legacy ? 100.0f, 85.0f : 100.25f, 84.9f }; m_casualSprite = CCSprite::createWithSpriteFrameName(fmt::format("uproxide.more_difficulties/MD_Difficulty04{}.png", legacy ? "_Legacy" : "").c_str()); m_casualSprite->setPosition(pos); @@ -278,53 +291,107 @@ bool FREditPopup::setup(FRLevelInfoLayer* delegate, GJGameLevel* level, int star auto starLeftSprite = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png"); starLeftSprite->setFlipX(true); starLeftSprite->setScale(0.2f); - m_starLeftArrow = CCMenuItemSpriteExtra::create(starLeftSprite, this, menu_selector(FREditPopup::onStarLeft)); + m_starLeftArrow = CCMenuItemExt::createSpriteExtra(starLeftSprite, [this](auto) { + m_stars = (10 + ((m_stars - 2) % 10)) % 10 + 1; + updateLabels(); + }); m_buttonMenu->addChild(m_starLeftArrow); auto starRightSprite = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png"); starRightSprite->setScale(0.2f); - m_starRightArrow = CCMenuItemSpriteExtra::create(starRightSprite, this, menu_selector(FREditPopup::onStarRight)); + m_starRightArrow = CCMenuItemExt::createSpriteExtra(starRightSprite, [this](auto) { + m_stars = m_stars % 10 + 1; + updateLabels(); + }); m_buttonMenu->addChild(m_starRightArrow); auto difficultyLeftSprite = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png"); difficultyLeftSprite->setFlipX(true); difficultyLeftSprite->setScale(0.3f); - m_difficultyLeftArrow = CCMenuItemSpriteExtra::create(difficultyLeftSprite, this, menu_selector(FREditPopup::onDifficultyLeft)); + m_difficultyLeftArrow = CCMenuItemExt::createSpriteExtra(difficultyLeftSprite, [this](auto) { + if (m_difficulty == 6) m_difficulty = 8; + else if (m_difficulty == 7) m_difficulty = 10; + else if (m_difficulty == 9) m_difficulty = 6; + else m_difficulty--; + updateLabels(); + }); m_difficultyLeftArrow->setPosition(70.0f, 70.0f); m_buttonMenu->addChild(m_difficultyLeftArrow); auto difficultyRightSprite = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png"); difficultyRightSprite->setScale(0.3f); - m_difficultyRightArrow = CCMenuItemSpriteExtra::create(difficultyRightSprite, this, menu_selector(FREditPopup::onDifficultyRight)); + m_difficultyRightArrow = CCMenuItemExt::createSpriteExtra(difficultyRightSprite, [this](auto) { + if (m_difficulty == 6) m_difficulty = 9; + else if (m_difficulty == 8) m_difficulty = 6; + else if (m_difficulty == 10) m_difficulty = 7; + else m_difficulty++; + updateLabels(); + }); m_difficultyRightArrow->setPosition(130.0f, 70.0f); m_buttonMenu->addChild(m_difficultyRightArrow); auto featureLeftSprite = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png"); featureLeftSprite->setFlipX(true); featureLeftSprite->setScale(0.4f); - m_featureLeftArrow = CCMenuItemSpriteExtra::create(featureLeftSprite, this, menu_selector(FREditPopup::onFeatureLeft)); + m_featureLeftArrow = CCMenuItemExt::createSpriteExtra(featureLeftSprite, [this](auto) { + m_feature = (5 + ((m_feature - 1) % 5)) % 5; + updateLabels(); + }); m_featureLeftArrow->setPositionX(70.0f); m_buttonMenu->addChild(m_featureLeftArrow); auto featureRightSprite = CCSprite::createWithSpriteFrameName("navArrowBtn_001.png"); featureRightSprite->setScale(0.4f); - m_featureRightArrow = CCMenuItemSpriteExtra::create(featureRightSprite, this, menu_selector(FREditPopup::onFeatureRight)); + m_featureRightArrow = CCMenuItemExt::createSpriteExtra(featureRightSprite, [this](auto) { + m_feature = (m_feature + 1) % 5; + updateLabels(); + }); m_featureRightArrow->setPositionX(130.0f); m_buttonMenu->addChild(m_featureRightArrow); - auto addButton = CCMenuItemSpriteExtra::create( - ButtonSprite::create("Add", "goldFont.fnt", "GJ_button_01.png", 0.8f), - this, - menu_selector(FREditPopup::onAdd) - ); + auto addButton = CCMenuItemExt::createSpriteExtra(ButtonSprite::create("Add", "goldFont.fnt", "GJ_button_01.png", 0.8f), [this](auto) { + auto vec = Mod::get()->getSavedValue>("fake-rate", {}); + auto it = std::find_if(vec.begin(), vec.end(), [this](auto const& item) { + return item.id == m_level->m_levelID; + }); + if (it != vec.end()) { + it->stars = m_stars; + it->feature = m_feature; + it->difficulty = m_difficulty; + } + else { + vec.push_back({ + .id = m_level->m_levelID, + .stars = m_stars, + .feature = m_feature, + .difficulty = m_difficulty + }); + } + Mod::get()->setSavedValue("fake-rate", vec); + m_delegate->updateFakeRate(m_stars, m_feature, m_difficulty, true, true); + onClose(nullptr); + }); addButton->setPosition(50.0f, 25.0f); m_buttonMenu->addChild(addButton); - auto removeButton = CCMenuItemSpriteExtra::create( - ButtonSprite::create("Remove", "goldFont.fnt", "GJ_button_06.png", 0.8f), - this, - menu_selector(FREditPopup::onRemove) - ); + auto removeButton = CCMenuItemExt::createSpriteExtra(ButtonSprite::create("Remove", "goldFont.fnt", "GJ_button_06.png", 0.8f), [this](auto) { + auto vec = Mod::get()->getSavedValue>("fake-rate", {}); + if (vec.empty()) return; + vec.erase(std::remove_if(vec.begin(), vec.end(), [this](auto const& item) { + return item.id == m_level->m_levelID; + }), vec.end()); + Mod::get()->setSavedValue("fake-rate", vec); + auto difficulty = m_level->getAverageDifficulty(); + if (m_level->m_demon > 0) switch (m_level->m_demonDifficulty) { + case 3: difficulty = 7; break; + case 4: difficulty = 8; break; + case 5: difficulty = 9; break; + case 6: difficulty = 10; break; + default: difficulty = 6; break; + } + m_delegate->updateFakeRate(m_level->m_stars, m_level->m_featured > 1 ? m_level->m_isEpic + 1 : 0, FakeRate::getDifficultyFromLevel(m_level), true, false); + onClose(nullptr); + }); removeButton->setPosition(135.0f, 25.0f); m_buttonMenu->addChild(removeButton); @@ -333,46 +400,6 @@ bool FREditPopup::setup(FRLevelInfoLayer* delegate, GJGameLevel* level, int star return true; } -void FREditPopup::onStarLeft(CCObject*) { - m_stars--; - if (m_stars < 1) m_stars = 10; - updateLabels(); -} - -void FREditPopup::onStarRight(CCObject*) { - m_stars++; - if (m_stars > 10) m_stars = 1; - updateLabels(); -} - -void FREditPopup::onDifficultyLeft(CCObject*) { - if (m_difficulty == 6) m_difficulty = 8; - else if (m_difficulty == 7) m_difficulty = 10; - else if (m_difficulty == 9) m_difficulty = 6; - else m_difficulty--; - updateLabels(); -} - -void FREditPopup::onDifficultyRight(CCObject*) { - if (m_difficulty == 6) m_difficulty = 9; - else if (m_difficulty == 8) m_difficulty = 6; - else if (m_difficulty == 10) m_difficulty = 7; - else m_difficulty++; - updateLabels(); -} - -void FREditPopup::onFeatureLeft(CCObject*) { - m_feature--; - if (m_feature < 0) m_feature = 4; - updateLabels(); -} - -void FREditPopup::onFeatureRight(CCObject*) { - m_feature++; - if (m_feature > 4) m_feature = 0; - updateLabels(); -} - void FREditPopup::updateLabels() { m_difficulty = m_stars >= 10 ? m_difficulty > 5 ? m_difficulty : 7 : FakeRate::getDifficultyForStars(m_stars); m_difficultySprite->updateDifficultyFrame(m_difficulty, GJDifficultyName::Long); @@ -396,45 +423,3 @@ void FREditPopup::updateLabels() { m_difficultySprite->setOpacity(m_stars != 4 && m_stars != 7 && m_stars != 9 ? 255 : 0); } } - -void FREditPopup::onAdd(CCObject*) { - auto vec = Mod::get()->getSavedValue>("fake-rate", {}); - auto it = std::find_if(vec.begin(), vec.end(), [this](auto const& item) { - return item.id == m_level->m_levelID; - }); - if (it != vec.end()) { - it->stars = m_stars; - it->feature = m_feature; - it->difficulty = m_difficulty; - } - else { - vec.push_back({ - .id = m_level->m_levelID, - .stars = m_stars, - .feature = m_feature, - .difficulty = m_difficulty - }); - } - Mod::get()->setSavedValue("fake-rate", vec); - m_delegate->updateFakeRate(m_stars, m_feature, m_difficulty, true, true); - onClose(nullptr); -} - -void FREditPopup::onRemove(CCObject*) { - auto vec = Mod::get()->getSavedValue>("fake-rate", {}); - if (vec.empty()) return; - vec.erase(std::remove_if(vec.begin(), vec.end(), [this](auto const& item) { - return item.id == m_level->m_levelID; - }), vec.end()); - Mod::get()->setSavedValue("fake-rate", vec); - auto difficulty = m_level->getAverageDifficulty(); - if (m_level->m_demon > 0) switch (m_level->m_demonDifficulty) { - case 3: difficulty = 7; break; - case 4: difficulty = 8; break; - case 5: difficulty = 9; break; - case 6: difficulty = 10; break; - default: difficulty = 6; break; - } - m_delegate->updateFakeRate(m_level->m_stars, m_level->m_featured > 1 ? m_level->m_isEpic + 1 : 0, difficulty, true, false); - onClose(nullptr); -} \ No newline at end of file diff --git a/src/FREditPopup.hpp b/src/FREditPopup.hpp index 377e60c..30e2c44 100644 --- a/src/FREditPopup.hpp +++ b/src/FREditPopup.hpp @@ -47,15 +47,6 @@ class FREditPopup : public Popup void updateLabels(); public: static FREditPopup* create(FRLevelInfoLayer*, GJGameLevel*, int, int, int); - - void onStarLeft(CCObject*); - void onStarRight(CCObject*); - void onDifficultyLeft(CCObject*); - void onDifficultyRight(CCObject*); - void onFeatureLeft(CCObject*); - void onFeatureRight(CCObject*); - void onAdd(CCObject*); - void onRemove(CCObject*); }; template<> diff --git a/src/FakeRate.cpp b/src/FakeRate.cpp index 9b2ff2d..22e1746 100644 --- a/src/FakeRate.cpp +++ b/src/FakeRate.cpp @@ -30,27 +30,19 @@ int FakeRate::getDifficultyForStars(int stars) { } int FakeRate::getDifficultyFromLevel(GJGameLevel* level) { - auto difficulty = level->getAverageDifficulty(); - if (level->m_demon > 0) switch (level->m_demonDifficulty) { - case 3: difficulty = 7; break; - case 4: difficulty = 8; break; - case 5: difficulty = 9; break; - case 6: difficulty = 10; break; - default: difficulty = 6; break; - } - return difficulty; + if (level->m_demon > 0) return level->m_demonDifficulty > 0 ? level->m_demonDifficulty + 4 : 6; + else if (level->m_ratings < 5) return 0; + else return level->m_ratingsSum / level->m_ratings; } -std::string FakeRate::getSpriteName(CCNode* node) { - if (auto spriteNode = typeinfo_cast(node)) { - if (auto texture = spriteNode->getTexture()) { - for (auto [key, frame] : CCDictionaryExt(CCSpriteFrameCache::sharedSpriteFrameCache()->m_pSpriteFrames)) { - if (frame->getTexture() == texture && frame->getRect() == spriteNode->getTextureRect()) return key; - } - for (auto [key, obj] : CCDictionaryExt(CCTextureCache::sharedTextureCache()->m_pTextures)) { - if (obj == texture) return key; - } +std::string FakeRate::getSpriteName(CCSprite* sprite) { + if (auto texture = sprite->getTexture()) { + for (auto [key, frame] : CCDictionaryExt(CCSpriteFrameCache::sharedSpriteFrameCache()->m_pSpriteFrames)) { + if (frame->getTexture() == texture && frame->getRect() == sprite->getTextureRect()) return key; + } + for (auto [key, obj] : CCDictionaryExt(CCTextureCache::sharedTextureCache()->m_pTextures)) { + if (obj == texture) return key; } } return ""; -} \ No newline at end of file +} diff --git a/src/FakeRate.hpp b/src/FakeRate.hpp index 10f5f04..bd9655c 100644 --- a/src/FakeRate.hpp +++ b/src/FakeRate.hpp @@ -7,5 +7,5 @@ class FakeRate { static int getBaseCurrency(int); static int getDifficultyForStars(int); static int getDifficultyFromLevel(GJGameLevel*); - static std::string getSpriteName(CCNode*); -}; \ No newline at end of file + static std::string getSpriteName(CCSprite*); +};