Skip to content

Commit

Permalink
Settings + some list fixes (#1108)
Browse files Browse the repository at this point in the history
* Made the force disable work as expected by replacing the NOT AND with an XOR

* Made sure that the mods layer doesn't force disable the geode theme in the settings

* Reverted the previous fix and properly migrated the force disable theme option

* Fixed the name of the last argument of ListBorders::setSpriteFrames

* Made a correction for the vanilla borders being gigantic

* Added a missing force disable theme

* Removed a test line

* Fixed the scroll issue in the entire geode UI

* Fixed the min height of the settings list

* Applied the same fix the mod lists

* Made the fuzzy search less random

* Replaced as with a static cast
  • Loading branch information
SMJSGaming authored Oct 11, 2024
1 parent 30542d7 commit a04edcf
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 65 deletions.
2 changes: 1 addition & 1 deletion loader/include/Geode/ui/General.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace geode {
public:
static ListBorders* create();

void setSpriteFrames(const char* topAndBottom, const char* sides, float topPadding = 7.5f);
void setSpriteFrames(const char* topAndBottom, const char* sides, float horizontalPadding = 7.5f);
void setSprites(
cocos2d::extension::CCScale9Sprite* top,
cocos2d::extension::CCScale9Sprite* bottom,
Expand Down
52 changes: 28 additions & 24 deletions loader/src/ui/mods/GeodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@
});
}

bool GeodeSquareSprite::init(CCSprite* top, bool* state) {
if (!CCSprite::initWithFile(isGeodeTheme() ? "GE_button_05.png"_spr : "GJ_button_01.png"))
bool isGeodeTheme(bool forceDisableTheme) {
return !forceDisableTheme && Mod::get()->template getSettingValue<bool>("enable-geode-theme");
}

bool GeodeSquareSprite::init(CCSprite* top, bool* state, bool forceDisableTheme) {
if (!CCSprite::initWithFile(isGeodeTheme(forceDisableTheme) ? "GE_button_05.png"_spr : "GJ_button_01.png"))
return false;

m_stateSrc = state;
m_topSprite = top;
m_forceDisableTheme = forceDisableTheme;

limitNodeSize(top, m_obContentSize * .65f, 2.f, .1f);
this->addChildAtPosition(top, Anchor::Center);
Expand All @@ -94,7 +99,7 @@ bool GeodeSquareSprite::init(CCSprite* top, bool* state) {

void GeodeSquareSprite::updateImage() {
this->setTexture(CCTextureCache::get()->addImage(
(m_state ? "GJ_button_02.png" : (isGeodeTheme() ? "GE_button_05.png"_spr : "GJ_button_01.png")),
(m_state ? "GJ_button_02.png" : (isGeodeTheme(m_forceDisableTheme) ? "GE_button_05.png"_spr : "GJ_button_01.png")),
false
));
}
Expand All @@ -106,18 +111,18 @@ void GeodeSquareSprite::update(float dt) {
}
}

GeodeSquareSprite* GeodeSquareSprite::create(const char* top, bool* state) {
GeodeSquareSprite* GeodeSquareSprite::create(const char* top, bool* state, bool forceDisableTheme) {
auto ret = new GeodeSquareSprite();
if (ret->init(CCSprite::create(top), state)) {
if (ret->init(CCSprite::create(top), state, forceDisableTheme)) {
ret->autorelease();
return ret;
}
delete ret;
return nullptr;
}
GeodeSquareSprite* GeodeSquareSprite::createWithSpriteFrameName(const char* top, bool* state) {
GeodeSquareSprite* GeodeSquareSprite::createWithSpriteFrameName(const char* top, bool* state, bool forceDisableTheme) {
auto ret = new GeodeSquareSprite();
if (ret->init(CCSprite::createWithSpriteFrameName(top), state)) {
if (ret->init(CCSprite::createWithSpriteFrameName(top), state, forceDisableTheme)) {
ret->autorelease();
return ret;
}
Expand All @@ -142,8 +147,8 @@ CCNode* createLoadingCircle(float sideLength, const char* id) {
return spinner;
}

const char* getGeodeButtonSpriteName(GeodeButtonSprite spr) {
if (isGeodeTheme()) {
const char* getGeodeButtonSpriteName(GeodeButtonSprite spr, bool forceDisableTheme) {
if (isGeodeTheme(forceDisableTheme)) {
switch (spr) {
default:
case GeodeButtonSprite::Default: return "GE_button_05.png"_spr;
Expand All @@ -165,18 +170,18 @@ const char* getGeodeButtonSpriteName(GeodeButtonSprite spr) {
}
}

IconButtonSprite* createGeodeButton(CCNode* icon, std::string const& text, GeodeButtonSprite bg) {
return IconButtonSprite::create(getGeodeButtonSpriteName(bg), icon, text.c_str(), "bigFont.fnt");
IconButtonSprite* createGeodeButton(CCNode* icon, std::string const& text, GeodeButtonSprite bg, bool forceDisableTheme) {
return IconButtonSprite::create(getGeodeButtonSpriteName(bg, forceDisableTheme), icon, text.c_str(), "bigFont.fnt");
}
ButtonSprite* createGeodeButton(std::string const& text, int width, bool gold, bool absolute, GeodeButtonSprite bg) {
return ButtonSprite::create(text.c_str(), width, absolute, gold ? "goldFont.fnt" : "bigFont.fnt", getGeodeButtonSpriteName(bg), 0.0f, .8f);
ButtonSprite* createGeodeButton(std::string const& text, int width, bool gold, bool absolute, GeodeButtonSprite bg, bool forceDisableTheme) {
return ButtonSprite::create(text.c_str(), width, absolute, gold ? "goldFont.fnt" : "bigFont.fnt", getGeodeButtonSpriteName(bg, forceDisableTheme), 0.0f, .8f);
}
ButtonSprite* createGeodeButton(std::string const& text, bool gold, GeodeButtonSprite bg) {
return ButtonSprite::create(text.c_str(), gold ? "goldFont.fnt" : "bigFont.fnt", getGeodeButtonSpriteName(bg), .8f);
ButtonSprite* createGeodeButton(std::string const& text, bool gold, GeodeButtonSprite bg, bool forceDisableTheme) {
return ButtonSprite::create(text.c_str(), gold ? "goldFont.fnt" : "bigFont.fnt", getGeodeButtonSpriteName(bg, forceDisableTheme), .8f);
}

CircleButtonSprite* createGeodeCircleButton(CCSprite* top, float scale, CircleBaseSize size, bool altColor) {
const auto geodeTheme = isGeodeTheme();
CircleButtonSprite* createGeodeCircleButton(CCSprite* top, float scale, CircleBaseSize size, bool altColor, bool forceDisableTheme) {
const auto geodeTheme = isGeodeTheme(forceDisableTheme);
auto ret = CircleButtonSprite::create(
top, geodeTheme ? (altColor ? CircleBaseColor::DarkAqua : CircleBaseColor::DarkPurple) : CircleBaseColor::Green, size
);
Expand Down Expand Up @@ -217,19 +222,18 @@ std::string geodeTagName(std::string_view tag) {
return readable;
}

ListBorders* createGeodeListBorders(CCSize const& size) {
ListBorders* createGeodeListBorders(CCSize const& size, bool forceDisableTheme) {
auto ret = ListBorders::create();
if (isGeodeTheme()) {
const bool geodeTheme = isGeodeTheme(forceDisableTheme);
if (geodeTheme) {
ret->setSpriteFrames("geode-list-top.png"_spr, "geode-list-side.png"_spr, 2);
ret->setContentSize(size);
} else {
ret->setContentSize(size + ccp(5, 5));
}
ret->setContentSize(size);
return ret;
}

bool isGeodeTheme() {
return Mod::get()->template getSettingValue<bool>("enable-geode-theme");
}

bool GeodeTabSprite::init(const char* iconFrame, const char* text, float width, bool altColor) {
if (!CCNode::init())
return false;
Expand Down
28 changes: 16 additions & 12 deletions loader/src/ui/mods/GeodeStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ enum class GeodePopupStyle {
Alt2,
};

bool isGeodeTheme(bool forceDisableTheme = false);

template <class... Args>
class GeodePopup : public Popup<Args...> {
protected:
bool m_forceDisableTheme = false;

bool init(float width, float height, Args... args, GeodePopupStyle style = GeodePopupStyle::Default, bool forceDisableTheme = false) {
const bool geodeTheme = !forceDisableTheme && Mod::get()->template getSettingValue<bool>("enable-geode-theme");
m_forceDisableTheme = forceDisableTheme;
const bool geodeTheme = isGeodeTheme(forceDisableTheme);
const char* bg;
switch (style) {
default:
Expand Down Expand Up @@ -49,16 +54,17 @@ class GeodeSquareSprite : public CCSprite {
protected:
bool* m_stateSrc = nullptr;
bool m_state = false;
bool m_forceDisableTheme = false;
CCSprite* m_topSprite;

bool init(CCSprite* top, bool* state);
bool init(CCSprite* top, bool* state, bool forceDisableTheme = false);

void update(float dt) override;
void updateImage();

public:
static GeodeSquareSprite* create(const char* top, bool* state = nullptr);
static GeodeSquareSprite* createWithSpriteFrameName(const char* top, bool* state = nullptr);
static GeodeSquareSprite* create(const char* top, bool* state = nullptr, bool forceDisableTheme = false);
static GeodeSquareSprite* createWithSpriteFrameName(const char* top, bool* state = nullptr, bool forceDisableTheme = false);

CCSprite* getTopSprite() const;
void setState(bool state);
Expand All @@ -73,21 +79,19 @@ enum class GeodeButtonSprite {
Enable,
Gray,
};
const char* getGeodeButtonSpriteName(GeodeButtonSprite spr);
IconButtonSprite* createGeodeButton(CCNode* icon, std::string const& text, GeodeButtonSprite bg = GeodeButtonSprite::Default);
ButtonSprite* createGeodeButton(std::string const& text, int width, bool absolute = false, bool gold = false, GeodeButtonSprite bg = GeodeButtonSprite::Default);
ButtonSprite* createGeodeButton(std::string const& text, bool gold = false, GeodeButtonSprite bg = GeodeButtonSprite::Default);
const char* getGeodeButtonSpriteName(GeodeButtonSprite spr, bool forceDisableTheme = false);
IconButtonSprite* createGeodeButton(CCNode* icon, std::string const& text, GeodeButtonSprite bg = GeodeButtonSprite::Default, bool forceDisableTheme = false);
ButtonSprite* createGeodeButton(std::string const& text, int width, bool absolute = false, bool gold = false, GeodeButtonSprite bg = GeodeButtonSprite::Default, bool forceDisableTheme = false);
ButtonSprite* createGeodeButton(std::string const& text, bool gold = false, GeodeButtonSprite bg = GeodeButtonSprite::Default, bool forceDisableTheme = false);

CircleButtonSprite* createGeodeCircleButton(CCSprite* top, float scale = 1.f, CircleBaseSize size = CircleBaseSize::Medium, bool altColor = false);
CircleButtonSprite* createGeodeCircleButton(CCSprite* top, float scale = 1.f, CircleBaseSize size = CircleBaseSize::Medium, bool altColor = false, bool forceDisableTheme = false);

ButtonSprite* createTagLabel(std::string const& text, std::pair<ccColor3B, ccColor3B> const& color);
ButtonSprite* createGeodeTagLabel(std::string_view tag);
std::pair<ccColor3B, ccColor3B> geodeTagColors(std::string_view tag);
std::string geodeTagName(std::string_view tag);

ListBorders* createGeodeListBorders(CCSize const& size);

bool isGeodeTheme();
ListBorders* createGeodeListBorders(CCSize const& size, bool forceDisableTheme = false);

class GeodeTabSprite : public CCNode {
protected:
Expand Down
2 changes: 1 addition & 1 deletion loader/src/ui/mods/ModsLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void ModsLayer::onTheme(CCObject*) {
);
}
void ModsLayer::onSettings(CCObject*) {
openSettingsPopup(Mod::get());
openSettingsPopup(Mod::get(), false);
}

ModsLayer* ModsLayer::create() {
Expand Down
4 changes: 3 additions & 1 deletion loader/src/ui/mods/list/ModList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void ModList::updateTopContainer() {
auto oldPosition = oldPositionArea > 0.f ?
m_list->m_contentLayer->getPositionY() / oldPositionArea :
-1.f;

// Update list size to account for the top menu
// (giving a little bit of extra padding for it, the same size as gap)
m_list->setContentHeight(
Expand All @@ -530,6 +530,8 @@ void ModList::updateTopContainer() {
static_cast<AxisLayout*>(m_list->m_contentLayer->getLayout())->getGap() :
this->getContentHeight()
);
static_cast<ColumnLayout*>(m_list->m_contentLayer->getLayout())->setAutoGrowAxis(m_list->getContentHeight());
m_list->m_contentLayer->updateLayout();

// Preserve relative scroll position
m_list->m_contentLayer->setPositionY((
Expand Down
2 changes: 1 addition & 1 deletion loader/src/ui/mods/popups/FiltersPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool FiltersPopup::setup(ModListSource* src) {
m_mainLayer->addChildAtPosition(inputContainer, Anchor::Bottom, ccp(0, 60), ccp(.5f, .5f));
}

auto okSpr = createGeodeButton("OK");
auto okSpr = createGeodeButton("OK", false, GeodeButtonSprite::Default, m_forceDisableTheme);
okSpr->setScale(.7f);
auto okBtn = CCMenuItemSpriteExtra::create(
okSpr, this, menu_selector(FiltersPopup::onClose)
Expand Down
25 changes: 16 additions & 9 deletions loader/src/ui/mods/popups/ModPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ bool ModPopup::setup(ModSource&& src) {
auto updateModSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("update.png"_spr),
"Update",
GeodeButtonSprite::Install
GeodeButtonSprite::Install,
m_forceDisableTheme
);
updateModSpr->setScale(.5f);
m_updateBtn = CCMenuItemSpriteExtra::create(
Expand All @@ -347,13 +348,15 @@ bool ModPopup::setup(ModSource&& src) {
auto enableModOffSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("GJ_completesIcon_001.png"),
"Enable",
GeodeButtonSprite::Enable
GeodeButtonSprite::Enable,
m_forceDisableTheme
);
enableModOffSpr->setScale(.5f);
auto enableModOnSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png"),
"Disable",
GeodeButtonSprite::Delete
GeodeButtonSprite::Delete,
m_forceDisableTheme
);
enableModOnSpr->setScale(.5f);
m_enableBtn = CCMenuItemToggler::create(
Expand All @@ -366,7 +369,8 @@ bool ModPopup::setup(ModSource&& src) {
auto reenableModOffSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("reset.png"_spr),
"Re-Enable",
GeodeButtonSprite::Default
GeodeButtonSprite::Default,
m_forceDisableTheme
);
reenableModOffSpr->setScale(.5f);
auto reenableModOnSpr = createGeodeButton(
Expand All @@ -385,7 +389,8 @@ bool ModPopup::setup(ModSource&& src) {
auto installModSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("GJ_downloadsIcon_001.png"),
"Install",
GeodeButtonSprite::Install
GeodeButtonSprite::Install,
m_forceDisableTheme
);
installModSpr->setScale(.5f);
m_installBtn = CCMenuItemSpriteExtra::create(
Expand All @@ -396,7 +401,8 @@ bool ModPopup::setup(ModSource&& src) {
auto uninstallModSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("delete-white.png"_spr),
"Uninstall",
GeodeButtonSprite::Default
GeodeButtonSprite::Default,
m_forceDisableTheme
);
uninstallModSpr->setScale(.5f);
m_uninstallBtn = CCMenuItemSpriteExtra::create(
Expand All @@ -407,7 +413,8 @@ bool ModPopup::setup(ModSource&& src) {
auto cancelDownloadSpr = createGeodeButton(
CCSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png"),
"Cancel",
GeodeButtonSprite::Default
GeodeButtonSprite::Default,
m_forceDisableTheme
);
cancelDownloadSpr->setScale(.5f);
m_cancelBtn = CCMenuItemSpriteExtra::create(
Expand Down Expand Up @@ -567,7 +574,7 @@ bool ModPopup::setup(ModSource&& src) {
m_settingsBG->setContentSize(ccp(35, 30) / linksBG->getScale());
m_buttonMenu->addChildAtPosition(m_settingsBG, Anchor::BottomLeft, ccp(28, 25));

auto settingsSpr = createGeodeCircleButton(CCSprite::createWithSpriteFrameName("settings.png"_spr));
auto settingsSpr = createGeodeCircleButton(CCSprite::createWithSpriteFrameName("settings.png"_spr), 1.f, CircleBaseSize::Medium, false, m_forceDisableTheme);
settingsSpr->setScale(.6f);
auto settingsBtn = CCMenuItemSpriteExtra::create(
settingsSpr, this, menu_selector(ModPopup::onSettings)
Expand Down Expand Up @@ -909,7 +916,7 @@ void ModPopup::onLoadTags(typename server::ServerRequest<std::unordered_set<std:
label->setScale(.35f);
menu->addChildAtPosition(label, Anchor::Left, ccp(10, 0), ccp(0, .5f));

auto aboutSpr = createGeodeButton("About");
auto aboutSpr = createGeodeButton("About", false, GeodeButtonSprite::Default, m_forceDisableTheme);
aboutSpr->setScale(.35f);
auto aboutBtn = CCMenuItemSpriteExtra::create(
aboutSpr, this, menu_selector(ModPopup::onModtoberInfo)
Expand Down
2 changes: 1 addition & 1 deletion loader/src/ui/mods/popups/ModtoberPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool ModtoberPopup::setup() {
auto bg = CCSprite::createWithSpriteFrameName("modtober24-popup.png"_spr);
m_mainLayer->addChildAtPosition(bg, Anchor::Center);

auto supportSpr = createGeodeButton("Join");
auto supportSpr = createGeodeButton("Join", false, GeodeButtonSprite::Default, m_forceDisableTheme);
supportSpr->setScale(.8f);
auto supportBtn = CCMenuItemSpriteExtra::create(
supportSpr, this, menu_selector(ModtoberPopup::onDiscord)
Expand Down
19 changes: 8 additions & 11 deletions loader/src/ui/mods/settings/ModSettingsPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ static bool matchSearch(SettingNodeV3* node, std::string const& query) {
else {
addToList |= weightedFuzzyMatch(setting->getKey(), query, 1, weighted);
}
if (auto desc = setting->getDescription()) {
addToList |= weightedFuzzyMatch(*desc, query, 0.02, weighted);
}
if (weighted < 2) {
if (weighted < 60 + 10 * query.size()) {
addToList = false;
}
return addToList;
Expand Down Expand Up @@ -63,7 +60,7 @@ bool ModSettingsPopup::setup(Mod* mod) {
m_searchInput->setID("search-input");
searchContainer->addChildAtPosition(m_searchInput, Anchor::Left, ccp(7.5f, 0), ccp(0, .5f));

auto searchClearSpr = GeodeSquareSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png");
auto searchClearSpr = GeodeSquareSprite::createWithSpriteFrameName("GJ_deleteIcon_001.png", nullptr, m_forceDisableTheme);
searchClearSpr->setScale(.45f);
m_searchClearBtn = CCMenuItemSpriteExtra::create(
searchClearSpr, this, menu_selector(ModSettingsPopup::onClearSearch)
Expand Down Expand Up @@ -91,7 +88,7 @@ bool ModSettingsPopup::setup(Mod* mod) {
m_list->m_contentLayer->setLayout(
ColumnLayout::create()
->setAxisReverse(true)
->setAutoGrowAxis(layerSize.height)
->setAutoGrowAxis(m_list->getContentHeight())
->setCrossAxisOverflow(false)
->setAxisAlignment(AxisAlignment::End)
->setGap(0)
Expand All @@ -107,7 +104,7 @@ bool ModSettingsPopup::setup(Mod* mod) {

// layer borders

m_mainLayer->addChildAtPosition(createGeodeListBorders(layerSize), Anchor::Center);
m_mainLayer->addChildAtPosition(createGeodeListBorders(layerSize, m_forceDisableTheme), Anchor::Center);

auto scrollBar = Scrollbar::create(m_list);
m_mainLayer->addChildAtPosition(
Expand All @@ -122,14 +119,14 @@ bool ModSettingsPopup::setup(Mod* mod) {
m_applyMenu->getLayout()->ignoreInvisibleChildren(true);
m_applyMenu->setTouchPriority(buttonPriority);

auto restartBtnSpr = createGeodeButton("Restart Now", true);
auto restartBtnSpr = createGeodeButton("Restart Now", true, GeodeButtonSprite::Default, m_forceDisableTheme);
restartBtnSpr->setScale(.6f);
m_restartBtn = CCMenuItemSpriteExtra::create(
restartBtnSpr, this, menu_selector(ModSettingsPopup::onRestart)
);
m_applyMenu->addChildAtPosition(m_restartBtn, Anchor::Bottom, ccp(0, 20));

m_applyBtnSpr = createGeodeButton("Apply", true);
m_applyBtnSpr = createGeodeButton("Apply", true, GeodeButtonSprite::Default, m_forceDisableTheme);
m_applyBtnSpr->setScale(.6f);
m_applyBtn = CCMenuItemSpriteExtra::create(
m_applyBtnSpr, this, menu_selector(ModSettingsPopup::onApply)
Expand All @@ -138,7 +135,7 @@ bool ModSettingsPopup::setup(Mod* mod) {

m_mainLayer->addChildAtPosition(m_applyMenu, Anchor::Bottom, ccp(0, 20));

auto resetBtnSpr = createGeodeButton("Reset All", true);
auto resetBtnSpr = createGeodeButton("Reset All", true, GeodeButtonSprite::Default, m_forceDisableTheme);
resetBtnSpr->setScale(.6f);

auto resetBtn = CCMenuItemSpriteExtra::create(
Expand All @@ -163,7 +160,7 @@ bool ModSettingsPopup::setup(Mod* mod) {
folderSprSub->setOpacity(155);
folderSprSub->setScale(.55f);
folderSpr->addChildAtPosition(folderSprSub, Anchor::Center, ccp(0, -3));
auto buttonSpr = createGeodeButton(folderSpr, "");
auto buttonSpr = createGeodeButton(folderSpr, "", GeodeButtonSprite::Default, m_forceDisableTheme);
buttonSpr->setScale(.6f);
buttonSpr->getIcon()->setScale(buttonSpr->getIcon()->getScale() * 1.4f);
auto folderBtn = CCMenuItemSpriteExtra::create(
Expand Down
Loading

0 comments on commit a04edcf

Please sign in to comment.