dim disabled mods a bit

This commit is contained in:
HJfod 2024-02-29 22:28:06 +02:00
parent 72fa718a76
commit 78fe601066
3 changed files with 56 additions and 13 deletions

View file

@ -9,6 +9,13 @@ bool BaseModItem::init() {
auto meta = this->getMetadata();
m_bg = CCScale9Sprite::create("square02b_small.png");
m_bg->setOpacity(0);
m_bg->ignoreAnchorPointForPosition(false);
m_bg->setAnchorPoint({ .5f, .5f });
m_bg->setScale(.7f);
this->addChild(m_bg);
m_logo = this->createModLogo();
this->addChild(m_logo);
@ -31,13 +38,13 @@ bool BaseModItem::init() {
->setAxisAlignment(AxisAlignment::Start)
);
auto title = CCLabelBMFont::create(meta.getName().c_str(), "bigFont.fnt");
title->setAnchorPoint({ .0f, .5f });
title->setLayoutOptions(
m_titleLabel = CCLabelBMFont::create(meta.getName().c_str(), "bigFont.fnt");
m_titleLabel->setAnchorPoint({ .0f, .5f });
m_titleLabel->setLayoutOptions(
AxisLayoutOptions::create()
->setMinScale(.1f)
);
m_titleContainer->addChild(title);
m_titleContainer->addChild(m_titleLabel);
m_infoContainer->addChild(m_titleContainer);
@ -46,9 +53,9 @@ bool BaseModItem::init() {
m_developers->setAnchorPoint({ .0f, .5f });
auto by = "By " + ModMetadata::formatDeveloperDisplayString(this->getMetadata().getDevelopers());
m_developerLabel = CCLabelBMFont::create(by.c_str(), "goldFont.fnt");
auto developersBtn = CCMenuItemSpriteExtra::create(
CCLabelBMFont::create(by.c_str(), "goldFont.fnt"),
this, nullptr
m_developerLabel, this, nullptr
);
m_developers->addChild(developersBtn);
@ -97,6 +104,17 @@ void BaseModItem::updateState() {
m_developers->setVisible(!wantsRestart);
m_infoContainer->updateLayout();
// Set default color to BG to start off with
// (possibly overriding later based on state)
m_bg->setColor(to3B(m_defaultBG));
m_bg->setOpacity(m_defaultBG.a);
// Highlight item via BG if it wants to restart for extra UI attention
if (wantsRestart) {
m_bg->setColor({ 153, 245, 245 });
m_bg->setOpacity(40);
}
// Propagate update up the chain
if (m_updateParentState) {
m_updateParentState();
@ -106,6 +124,9 @@ void BaseModItem::updateState() {
void BaseModItem::updateSize(float width, bool big) {
this->setContentSize({ width, big ? 40.f : 30.f });
m_bg->setContentSize((m_obContentSize - ccp(6, 0)) / m_bg->getScale());
m_bg->setPosition(m_obContentSize / 2);
auto logoSize = m_obContentSize.height - 10;
limitNodeSize(m_logo, { logoSize, logoSize }, 999, .1f);
m_logo->setPosition(m_obContentSize.height / 2 + 5, m_obContentSize.height / 2);
@ -160,6 +181,10 @@ bool InstalledModItem::init(Mod* mod) {
}
void InstalledModItem::updateState() {
m_defaultBG.a = m_mod->isOrWillBeEnabled() ? 25 : 10;
m_titleLabel->setOpacity(m_mod->isOrWillBeEnabled() ? 255 : 155);
m_developerLabel->setOpacity(m_mod->isOrWillBeEnabled() ? 255 : 155);
BaseModItem::updateState();
// Update enable toggle state
@ -228,6 +253,17 @@ bool ServerModItem::init(server::ServerModMetadata const& metadata) {
return true;
}
void ServerModItem::updateState() {
BaseModItem::updateState();
// Update BG color unless we want to restart (more important color to show)
// and if the mod is featured
if (!this->wantsRestart() && m_metadata.featured && m_checkmark) {
m_bg->setColor(m_checkmark->getColor());
m_bg->setOpacity(40);
}
}
ServerModItem* ServerModItem::create(server::ServerModMetadata const& metadata) {
auto ret = new ServerModItem();
if (ret && ret->init(metadata)) {

View file

@ -7,10 +7,14 @@ using namespace geode::prelude;
class BaseModItem : public CCNode {
protected:
CCScale9Sprite* m_bg;
ccColor4B m_defaultBG = { 255, 255, 255, 25 };
CCNode* m_logo;
CCNode* m_infoContainer;
CCNode* m_titleContainer;
CCLabelBMFont* m_titleLabel;
CCNode* m_developers;
CCLabelBMFont* m_developerLabel;
ButtonSprite* m_restartRequiredLabel = nullptr;
CCMenu* m_viewMenu;
MiniFunction<void()> m_updateParentState = nullptr;
@ -64,6 +68,8 @@ protected:
bool init(server::ServerModMetadata const& metadata);
void updateState() override;
public:
/**
* @note Make sure to call `updateSize` afterwards

View file

@ -19,7 +19,7 @@ bool ModList::init(ModListSource* src, CCSize const& size) {
->setAxisReverse(true)
->setAxisAlignment(AxisAlignment::End)
->setAutoGrowAxis(size.height)
->setGap(0)
->setGap(2.5f)
);
this->addChildAtPosition(m_list, Anchor::Bottom, ccp(-m_list->getScaledContentSize().width / 2, 0));
@ -188,11 +188,11 @@ void ModList::onPromise(typename ModListSource::PageLoadEvent* event) {
for (auto item : *resolved) {
// Add separators between items after the first one
if (!first) {
auto separator = CCLayerColor::create(
ColorProvider::get()->define("mod-list-separator"_spr, { 255, 255, 255, 45 })
);
separator->setContentSize({ m_obContentSize.width - 10, .5f });
m_list->m_contentLayer->addChild(separator);
// auto separator = CCLayerColor::create(
// ColorProvider::get()->define("mod-list-separator"_spr, { 255, 255, 255, 45 })
// );
// separator->setContentSize({ m_obContentSize.width - 10, .5f });
// m_list->m_contentLayer->addChild(separator);
}
first = false;
m_list->m_contentLayer->addChild(item);
@ -274,7 +274,8 @@ void ModList::activateSearch(bool activate) {
// (giving a little bit of extra padding for it, the same size as gap)
m_list->setContentHeight(
activate ?
this->getContentHeight() - m_searchMenu->getContentHeight() :
this->getContentHeight() - m_searchMenu->getContentHeight() -
static_cast<AxisLayout*>(m_list->m_contentLayer->getLayout())->getGap() :
this->getContentHeight()
);