mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 15:37:53 -05:00
color settings
This commit is contained in:
parent
a2f74431c1
commit
dd17301761
2 changed files with 87 additions and 16 deletions
|
@ -387,10 +387,6 @@ void FileSettingNodeV3::updateState() {
|
||||||
m_nameLabel->limitLabelWidth(75, .35f, .1f);
|
m_nameLabel->limitLabelWidth(75, .35f, .1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSettingNodeV3::onCommit() {
|
|
||||||
this->getSetting()->setValue(m_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileSettingNodeV3::onPickFile(CCObject*) {
|
void FileSettingNodeV3::onPickFile(CCObject*) {
|
||||||
m_pickListener.bind([this](auto* event) {
|
m_pickListener.bind([this](auto* event) {
|
||||||
auto value = event->getValue();
|
auto value = event->getValue();
|
||||||
|
@ -422,6 +418,9 @@ void FileSettingNodeV3::onPickFile(CCObject*) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileSettingNodeV3::onCommit() {
|
||||||
|
this->getSetting()->setValue(m_path);
|
||||||
|
}
|
||||||
bool FileSettingNodeV3::hasUncommittedChanges() const {
|
bool FileSettingNodeV3::hasUncommittedChanges() const {
|
||||||
return m_path != this->getSetting()->getValue();
|
return m_path != this->getSetting()->getValue();
|
||||||
}
|
}
|
||||||
|
@ -452,20 +451,48 @@ bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float
|
||||||
if (!SettingNodeV3::init(setting, width))
|
if (!SettingNodeV3::init(setting, width))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// todo
|
m_value = setting->getValue();
|
||||||
|
|
||||||
|
m_colorSprite = ColorChannelSprite::create();
|
||||||
|
m_colorSprite->setScale(.65f);
|
||||||
|
|
||||||
|
auto button = CCMenuItemSpriteExtra::create(
|
||||||
|
m_colorSprite, this, menu_selector(Color3BSettingNodeV3::onSelectColor)
|
||||||
|
);
|
||||||
|
this->getButtonMenu()->addChildAtPosition(button, Anchor::Right, ccp(-10, 0));
|
||||||
|
|
||||||
|
this->updateState();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color3BSettingNodeV3::onCommit() {}
|
void Color3BSettingNodeV3::updateState() {
|
||||||
|
SettingNodeV3::updateState();
|
||||||
|
m_colorSprite->setColor(m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color3BSettingNodeV3::onSelectColor(CCObject*) {
|
||||||
|
auto popup = ColorPickPopup::create(m_value);
|
||||||
|
popup->setDelegate(this);
|
||||||
|
popup->show();
|
||||||
|
}
|
||||||
|
void Color3BSettingNodeV3::updateColor(ccColor4B const& color) {
|
||||||
|
m_value = to3B(color);
|
||||||
|
this->markChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color3BSettingNodeV3::onCommit() {
|
||||||
|
this->getSetting()->setValue(m_value);
|
||||||
|
}
|
||||||
bool Color3BSettingNodeV3::hasUncommittedChanges() const {
|
bool Color3BSettingNodeV3::hasUncommittedChanges() const {
|
||||||
return false;
|
return m_value != this->getSetting()->getValue();
|
||||||
}
|
}
|
||||||
bool Color3BSettingNodeV3::hasNonDefaultValue() const {
|
bool Color3BSettingNodeV3::hasNonDefaultValue() const {
|
||||||
return false;
|
return m_value != this->getSetting()->getDefaultValue();
|
||||||
|
}
|
||||||
|
void Color3BSettingNodeV3::onResetToDefault() {
|
||||||
|
m_value = this->getSetting()->getDefaultValue();
|
||||||
}
|
}
|
||||||
void Color3BSettingNodeV3::onResetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<Color3BSettingV3> Color3BSettingNodeV3::getSetting() const {
|
std::shared_ptr<Color3BSettingV3> Color3BSettingNodeV3::getSetting() const {
|
||||||
return std::static_pointer_cast<Color3BSettingV3>(SettingNodeV3::getSetting());
|
return std::static_pointer_cast<Color3BSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
@ -487,20 +514,49 @@ bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float
|
||||||
if (!SettingNodeV3::init(setting, width))
|
if (!SettingNodeV3::init(setting, width))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// todo
|
m_value = setting->getValue();
|
||||||
|
|
||||||
|
m_colorSprite = ColorChannelSprite::create();
|
||||||
|
m_colorSprite->setScale(.65f);
|
||||||
|
|
||||||
|
auto button = CCMenuItemSpriteExtra::create(
|
||||||
|
m_colorSprite, this, menu_selector(Color4BSettingNodeV3::onSelectColor)
|
||||||
|
);
|
||||||
|
this->getButtonMenu()->addChildAtPosition(button, Anchor::Right, ccp(-10, 0));
|
||||||
|
|
||||||
|
this->updateState();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color4BSettingNodeV3::onCommit() {}
|
void Color4BSettingNodeV3::updateState() {
|
||||||
|
SettingNodeV3::updateState();
|
||||||
|
m_colorSprite->setColor(to3B(m_value));
|
||||||
|
m_colorSprite->updateOpacity(m_value.a / 255.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color4BSettingNodeV3::onSelectColor(CCObject*) {
|
||||||
|
auto popup = ColorPickPopup::create(m_value);
|
||||||
|
popup->setDelegate(this);
|
||||||
|
popup->show();
|
||||||
|
}
|
||||||
|
void Color4BSettingNodeV3::updateColor(ccColor4B const& color) {
|
||||||
|
m_value = color;
|
||||||
|
this->markChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color4BSettingNodeV3::onCommit() {
|
||||||
|
this->getSetting()->setValue(m_value);
|
||||||
|
}
|
||||||
bool Color4BSettingNodeV3::hasUncommittedChanges() const {
|
bool Color4BSettingNodeV3::hasUncommittedChanges() const {
|
||||||
return false;
|
return m_value != this->getSetting()->getValue();
|
||||||
}
|
}
|
||||||
bool Color4BSettingNodeV3::hasNonDefaultValue() const {
|
bool Color4BSettingNodeV3::hasNonDefaultValue() const {
|
||||||
return false;
|
return m_value != this->getSetting()->getDefaultValue();
|
||||||
|
}
|
||||||
|
void Color4BSettingNodeV3::onResetToDefault() {
|
||||||
|
m_value = this->getSetting()->getDefaultValue();
|
||||||
}
|
}
|
||||||
void Color4BSettingNodeV3::onResetToDefault() {}
|
|
||||||
|
|
||||||
std::shared_ptr<Color4BSettingV3> Color4BSettingNodeV3::getSetting() const {
|
std::shared_ptr<Color4BSettingV3> Color4BSettingNodeV3::getSetting() const {
|
||||||
return std::static_pointer_cast<Color4BSettingV3>(SettingNodeV3::getSetting());
|
return std::static_pointer_cast<Color4BSettingV3>(SettingNodeV3::getSetting());
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <Geode/loader/SettingV3.hpp>
|
#include <Geode/loader/SettingV3.hpp>
|
||||||
#include <Geode/loader/SettingNode.hpp>
|
#include <Geode/loader/SettingNode.hpp>
|
||||||
#include <Geode/binding/CCMenuItemToggler.hpp>
|
#include <Geode/binding/CCMenuItemToggler.hpp>
|
||||||
|
#include <Geode/ui/ColorPickPopup.hpp>
|
||||||
|
|
||||||
using namespace geode::prelude;
|
using namespace geode::prelude;
|
||||||
|
|
||||||
|
@ -290,11 +291,18 @@ public:
|
||||||
std::shared_ptr<FileSettingV3> getSetting() const;
|
std::shared_ptr<FileSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Color3BSettingNodeV3 : public SettingNodeV3 {
|
class Color3BSettingNodeV3 : public SettingNodeV3, public ColorPickPopupDelegate {
|
||||||
protected:
|
protected:
|
||||||
|
ccColor3B m_value;
|
||||||
|
ColorChannelSprite* m_colorSprite;
|
||||||
|
|
||||||
bool init(std::shared_ptr<Color3BSettingV3> setting, float width);
|
bool init(std::shared_ptr<Color3BSettingV3> setting, float width);
|
||||||
|
|
||||||
|
void updateState() override;
|
||||||
|
|
||||||
void onCommit() override;
|
void onCommit() override;
|
||||||
|
void onSelectColor(CCObject*);
|
||||||
|
void updateColor(ccColor4B const& color) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Color3BSettingNodeV3* create(std::shared_ptr<Color3BSettingV3> setting, float width);
|
static Color3BSettingNodeV3* create(std::shared_ptr<Color3BSettingV3> setting, float width);
|
||||||
|
@ -306,11 +314,18 @@ public:
|
||||||
std::shared_ptr<Color3BSettingV3> getSetting() const;
|
std::shared_ptr<Color3BSettingV3> getSetting() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Color4BSettingNodeV3 : public SettingNodeV3 {
|
class Color4BSettingNodeV3 : public SettingNodeV3, public ColorPickPopupDelegate {
|
||||||
protected:
|
protected:
|
||||||
|
ccColor4B m_value;
|
||||||
|
ColorChannelSprite* m_colorSprite;
|
||||||
|
|
||||||
bool init(std::shared_ptr<Color4BSettingV3> setting, float width);
|
bool init(std::shared_ptr<Color4BSettingV3> setting, float width);
|
||||||
|
|
||||||
|
void updateState() override;
|
||||||
|
|
||||||
void onCommit() override;
|
void onCommit() override;
|
||||||
|
void onSelectColor(CCObject*);
|
||||||
|
void updateColor(ccColor4B const& color) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Color4BSettingNodeV3* create(std::shared_ptr<Color4BSettingV3> setting, float width);
|
static Color4BSettingNodeV3* create(std::shared_ptr<Color4BSettingV3> setting, float width);
|
||||||
|
|
Loading…
Reference in a new issue