mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-26 21:00:50 -04:00
now with categories in UI
This commit is contained in:
parent
ce925f0bb2
commit
a30f5063e7
8 changed files with 166 additions and 22 deletions
loader
include/Geode/cocos/extensions/GUI/CCControlExtension
resources
src/ui/internal
|
@ -59,7 +59,7 @@ public:
|
|||
|
||||
public:
|
||||
/** Original sprite's size. */
|
||||
CC_SYNTHESIZE_READONLY(CCSize, m_originalSize, OriginalSize);
|
||||
CC_SYNTHESIZE_READONLY_NV(CCSize, m_originalSize, OriginalSize);
|
||||
/** Prefered sprite's size. By default the prefered size is the original size. */
|
||||
|
||||
//if the preferredSize component is given as -1, it is ignored
|
||||
|
|
BIN
loader/resources/category-bg.png
Normal file
BIN
loader/resources/category-bg.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 4.8 KiB |
BIN
loader/resources/category-dot.png
Normal file
BIN
loader/resources/category-dot.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 3.9 KiB |
75
loader/src/ui/internal/info/CategoryNode.cpp
Normal file
75
loader/src/ui/internal/info/CategoryNode.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "CategoryNode.hpp"
|
||||
|
||||
ccColor3B CategoryNode::categoryToColor(std::string const& category) {
|
||||
// all we need is to convert a string into some number
|
||||
// between 0 and 360 and for that number to always be the
|
||||
// same for the same string
|
||||
|
||||
double hue = pow(hash(category.c_str()), 1.2);
|
||||
// for some reason RGBfromHSV does not wrap around
|
||||
while (hue > 360000.0) hue -= 360000.0;
|
||||
while (hue > 360.0) hue -= 360.0;
|
||||
|
||||
auto rgb = CCControlUtils::RGBfromHSV({ hue, .5, 1.0 });
|
||||
return {
|
||||
static_cast<GLubyte>(rgb.r * 255),
|
||||
static_cast<GLubyte>(rgb.g * 255),
|
||||
static_cast<GLubyte>(rgb.b * 255)
|
||||
};
|
||||
}
|
||||
|
||||
bool CategoryNode::init(
|
||||
std::string const& category,
|
||||
CategoryNodeStyle style
|
||||
) {
|
||||
if (style == CategoryNodeStyle::Dot) {
|
||||
auto dot = CCSprite::createWithSpriteFrameName("category-dot.png"_spr);
|
||||
dot->setColor(categoryToColor(category));
|
||||
dot->setPosition({ 20.f, 20.f });
|
||||
dot->setScale(.7f);
|
||||
this->addChild(dot);
|
||||
|
||||
auto label = CCLabelBMFont::create(category.c_str(), "bigFont.fnt");
|
||||
label->limitLabelWidth(180.f, 1.5f, .1f);
|
||||
label->setAnchorPoint({ .0f, .4f });
|
||||
label->setPosition({ 40.f, 20.f });
|
||||
this->addChild(label);
|
||||
|
||||
this->setContentSize({
|
||||
label->getScaledContentSize().width + 30.f,
|
||||
40.f
|
||||
});
|
||||
} else {
|
||||
auto bg = CCScale9Sprite::createWithSpriteFrameName("category-bg.png"_spr);
|
||||
bg->setColor(categoryToColor(category));
|
||||
this->addChild(bg);
|
||||
|
||||
auto label = CCLabelBMFont::create(category.c_str(), "bigFont.fnt");
|
||||
label->limitLabelWidth(180.f, 1.5f, .1f);
|
||||
label->setAnchorPoint({ .5f, .4f });
|
||||
this->addChild(label);
|
||||
|
||||
bg->setContentSize({
|
||||
label->getScaledContentSize().width + 30.f,
|
||||
40.f
|
||||
});
|
||||
bg->setPosition(bg->getScaledContentSize() / 2);
|
||||
label->setPosition(bg->getScaledContentSize() / 2);
|
||||
this->setContentSize(bg->getScaledContentSize());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CategoryNode* CategoryNode::create(
|
||||
std::string const& category,
|
||||
CategoryNodeStyle style
|
||||
) {
|
||||
auto ret = new CategoryNode();
|
||||
if (ret && ret->init(category, style)) {
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
CC_SAFE_DELETE(ret);
|
||||
return nullptr;
|
||||
}
|
26
loader/src/ui/internal/info/CategoryNode.hpp
Normal file
26
loader/src/ui/internal/info/CategoryNode.hpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
#include <Geode/Geode.hpp>
|
||||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
||||
enum class CategoryNodeStyle {
|
||||
Tag,
|
||||
Dot,
|
||||
};
|
||||
|
||||
class CategoryNode : public CCNode {
|
||||
protected:
|
||||
bool init(
|
||||
std::string const& category,
|
||||
CategoryNodeStyle style
|
||||
);
|
||||
|
||||
public:
|
||||
static CategoryNode* create(
|
||||
std::string const& category,
|
||||
CategoryNodeStyle style = CategoryNodeStyle::Tag
|
||||
);
|
||||
|
||||
static ccColor3B categoryToColor(std::string const& category);
|
||||
};
|
|
@ -112,8 +112,8 @@ bool ModInfoLayer::init(ModObject* obj, ModListView* list) {
|
|||
auto nameLabel = CCLabelBMFont::create(
|
||||
m_info.m_name.c_str(), "bigFont.fnt"
|
||||
);
|
||||
nameLabel->setScale(.7f);
|
||||
nameLabel->setAnchorPoint({ .0f, .5f });
|
||||
nameLabel->limitLabelWidth(200.f, .7f, .1f);
|
||||
m_mainLayer->addChild(nameLabel, 2);
|
||||
|
||||
auto logoSpr = this->createLogoSpr(obj);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <Index.hpp>
|
||||
#include "ModListLayer.hpp"
|
||||
#include <InternalLoader.hpp>
|
||||
#include "../info/CategoryNode.hpp"
|
||||
|
||||
template<class T>
|
||||
static bool tryOrAlert(Result<T> const& res, const char* title) {
|
||||
|
@ -176,6 +177,8 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
logoSpr->setScale(logoSize / logoSpr->getContentSize().width);
|
||||
m_mainLayer->addChild(logoSpr);
|
||||
|
||||
bool hasCategories = false;
|
||||
|
||||
ModInfo info;
|
||||
switch (modobj->m_type) {
|
||||
case ModObjectType::Mod:
|
||||
|
@ -184,6 +187,7 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
|
||||
case ModObjectType::Index:
|
||||
info = modobj->m_index.m_info;
|
||||
hasCategories = m_expanded && modobj->m_index.m_categories.size();
|
||||
break;
|
||||
|
||||
default: return;
|
||||
|
@ -193,10 +197,14 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
|
||||
auto titleLabel = CCLabelBMFont::create(info.m_name.c_str(), "bigFont.fnt");
|
||||
titleLabel->setAnchorPoint({ .0f, .5f });
|
||||
titleLabel->setPosition(
|
||||
m_height / 2 + logoSize / 2 + 13.f,
|
||||
(hasDesc ? m_height / 2 + 15.f : m_height / 2 + 7.f)
|
||||
);
|
||||
titleLabel->setPositionX(m_height / 2 + logoSize / 2 + 13.f);
|
||||
if (hasDesc && hasCategories) {
|
||||
titleLabel->setPositionY(m_height / 2 + 20.f);
|
||||
} else if (hasDesc || hasCategories) {
|
||||
titleLabel->setPositionY(m_height / 2 + 15.f);
|
||||
} else {
|
||||
titleLabel->setPositionY(m_height / 2 + 7.f);
|
||||
}
|
||||
titleLabel->limitLabelWidth(m_width / 2 - 40.f, .5f, .1f);
|
||||
m_mainLayer->addChild(titleLabel);
|
||||
|
||||
|
@ -207,7 +215,7 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
versionLabel->setScale(.3f);
|
||||
versionLabel->setPosition(
|
||||
titleLabel->getPositionX() + titleLabel->getScaledContentSize().width + 5.f,
|
||||
(hasDesc ? m_height / 2 + 15.f : m_height / 2 + 7.f)
|
||||
titleLabel->getPositionY() - 1.f
|
||||
);
|
||||
versionLabel->setColor({ 0, 255, 0 });
|
||||
m_mainLayer->addChild(versionLabel);
|
||||
|
@ -218,10 +226,14 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
);
|
||||
creatorLabel->setAnchorPoint({ .0f, .5f });
|
||||
creatorLabel->setScale(.43f);
|
||||
creatorLabel->setPosition(
|
||||
m_height / 2 + logoSize / 2 + 13.f,
|
||||
(hasDesc ? m_height / 2 : m_height / 2 - 7.f)
|
||||
);
|
||||
creatorLabel->setPositionX(m_height / 2 + logoSize / 2 + 13.f);
|
||||
if (hasDesc && hasCategories) {
|
||||
creatorLabel->setPositionY(m_height / 2 + 7.5f);
|
||||
} else if (hasDesc || hasCategories) {
|
||||
creatorLabel->setPositionY(m_height / 2);
|
||||
} else {
|
||||
creatorLabel->setPositionY(m_height / 2 - 7.f);
|
||||
}
|
||||
m_mainLayer->addChild(creatorLabel);
|
||||
|
||||
if (hasDesc) {
|
||||
|
@ -232,10 +244,12 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
descBG->setOpacity(90);
|
||||
descBG->setContentSize({ m_width * 2, 60.f });
|
||||
descBG->setAnchorPoint({ .0f, .5f });
|
||||
descBG->setPosition(
|
||||
m_height / 2 + logoSize / 2 + 13.f,
|
||||
m_height / 2 - 17.f
|
||||
);
|
||||
descBG->setPositionX(m_height / 2 + logoSize / 2 + 13.f);
|
||||
if (hasCategories) {
|
||||
descBG->setPositionY(m_height / 2 - 7.5f);
|
||||
} else {
|
||||
descBG->setPositionY(m_height / 2 - 17.f);
|
||||
}
|
||||
descBG->setScale(.25f);
|
||||
m_mainLayer->addChild(descBG);
|
||||
|
||||
|
@ -246,12 +260,30 @@ void ModCell::loadFromObject(ModObject* modobj) {
|
|||
descText->setAnchorPoint({ .0f, .5f });
|
||||
descText->setPosition(
|
||||
m_height / 2 + logoSize / 2 + 18.f,
|
||||
m_height / 2 - 17.f
|
||||
descBG->getPositionY()
|
||||
);
|
||||
descText->limitLabelWidth(m_width / 2 - 10.f, .5f, .1f);
|
||||
m_mainLayer->addChild(descText);
|
||||
}
|
||||
|
||||
if (hasCategories) {
|
||||
float x = m_height / 2 + logoSize / 2 + 13.f;
|
||||
for (auto& category : modobj->m_index.m_categories) {
|
||||
auto node = CategoryNode::create(category);
|
||||
node->setAnchorPoint({ .0f, .5f });
|
||||
node->setPositionX(x);
|
||||
node->setScale(.3f);
|
||||
if (hasDesc) {
|
||||
node->setPositionY(m_height / 2 - 23.f);
|
||||
} else {
|
||||
node->setPositionY(m_height / 2 - 17.f);
|
||||
}
|
||||
m_mainLayer->addChild(node);
|
||||
|
||||
x += node->getScaledContentSize().width + 5.f;
|
||||
}
|
||||
}
|
||||
|
||||
switch (modobj->m_type) {
|
||||
case ModObjectType::Mod:
|
||||
this->setupLoadedButtons();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "ModListLayer.hpp"
|
||||
#include "ModListView.hpp"
|
||||
#include <Geode/ui/SelectList.hpp>
|
||||
#include "../info/CategoryNode.hpp"
|
||||
|
||||
bool SearchFilterPopup::setup(ModListLayer* layer, ModListType type) {
|
||||
// todo: clean this shitty ass popup up
|
||||
|
@ -84,8 +85,8 @@ bool SearchFilterPopup::setup(ModListLayer* layer, ModListType type) {
|
|||
pos = CCPoint { winSize.width / 2 + 30.f, winSize.height / 2 + 45.f };
|
||||
|
||||
for (auto& category : Index::get()->getCategories()) {
|
||||
this->addToggle(
|
||||
category.c_str(),
|
||||
auto toggle = CCMenuItemToggler::createWithStandardSprites(
|
||||
this,
|
||||
makeMenuSelector([this](CCMenuItemToggler* toggle) {
|
||||
// due to implementation problems in makeMemberFunction,
|
||||
// category can't be passed through capture
|
||||
|
@ -101,10 +102,20 @@ bool SearchFilterPopup::setup(ModListLayer* layer, ModListType type) {
|
|||
}
|
||||
} catch(...) {}
|
||||
}),
|
||||
m_modLayer->m_query.m_categories.count(category),
|
||||
0,
|
||||
pos
|
||||
)->setUserObject(CCString::create(category));
|
||||
.5f
|
||||
);
|
||||
toggle->toggle(m_modLayer->m_query.m_categories.count(category));
|
||||
toggle->setPosition(pos - winSize / 2);
|
||||
toggle->setUserObject(CCString::create(category));
|
||||
m_buttonMenu->addChild(toggle);
|
||||
|
||||
auto label = CategoryNode::create(category, CategoryNodeStyle::Dot);
|
||||
label->setScale(.4f);
|
||||
label->setAnchorPoint({ .0f, .5f });
|
||||
label->setPosition(pos.x + 10.f, pos.y);
|
||||
m_mainLayer->addChild(label);
|
||||
|
||||
pos.y -= 22.5f;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue