Skip to content

Commit

Permalink
color settings
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Aug 24, 2024
1 parent a2f7443 commit dd17301
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 16 deletions.
84 changes: 70 additions & 14 deletions loader/src/loader/SettingNodeV3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,6 @@ void FileSettingNodeV3::updateState() {
m_nameLabel->limitLabelWidth(75, .35f, .1f);
}

void FileSettingNodeV3::onCommit() {
this->getSetting()->setValue(m_path);
}

void FileSettingNodeV3::onPickFile(CCObject*) {
m_pickListener.bind([this](auto* event) {
auto value = event->getValue();
Expand Down Expand Up @@ -422,6 +418,9 @@ void FileSettingNodeV3::onPickFile(CCObject*) {
));
}

void FileSettingNodeV3::onCommit() {
this->getSetting()->setValue(m_path);
}
bool FileSettingNodeV3::hasUncommittedChanges() const {
return m_path != this->getSetting()->getValue();
}
Expand Down Expand Up @@ -452,20 +451,48 @@ bool Color3BSettingNodeV3::init(std::shared_ptr<Color3BSettingV3> setting, float
if (!SettingNodeV3::init(setting, width))
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;
}

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 {
return false;
return m_value != this->getSetting()->getValue();
}
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 {
return std::static_pointer_cast<Color3BSettingV3>(SettingNodeV3::getSetting());
Expand All @@ -487,20 +514,49 @@ bool Color4BSettingNodeV3::init(std::shared_ptr<Color4BSettingV3> setting, float
if (!SettingNodeV3::init(setting, width))
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;
}

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 {
return false;
return m_value != this->getSetting()->getValue();
}
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 {
return std::static_pointer_cast<Color4BSettingV3>(SettingNodeV3::getSetting());
Expand Down
19 changes: 17 additions & 2 deletions loader/src/loader/SettingNodeV3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Geode/loader/SettingV3.hpp>
#include <Geode/loader/SettingNode.hpp>
#include <Geode/binding/CCMenuItemToggler.hpp>
#include <Geode/ui/ColorPickPopup.hpp>

using namespace geode::prelude;

Expand Down Expand Up @@ -290,11 +291,18 @@ class FileSettingNodeV3 : public SettingNodeV3 {
std::shared_ptr<FileSettingV3> getSetting() const;
};

class Color3BSettingNodeV3 : public SettingNodeV3 {
class Color3BSettingNodeV3 : public SettingNodeV3, public ColorPickPopupDelegate {
protected:
ccColor3B m_value;
ColorChannelSprite* m_colorSprite;

bool init(std::shared_ptr<Color3BSettingV3> setting, float width);

void updateState() override;

void onCommit() override;
void onSelectColor(CCObject*);
void updateColor(ccColor4B const& color) override;

public:
static Color3BSettingNodeV3* create(std::shared_ptr<Color3BSettingV3> setting, float width);
Expand All @@ -306,11 +314,18 @@ class Color3BSettingNodeV3 : public SettingNodeV3 {
std::shared_ptr<Color3BSettingV3> getSetting() const;
};

class Color4BSettingNodeV3 : public SettingNodeV3 {
class Color4BSettingNodeV3 : public SettingNodeV3, public ColorPickPopupDelegate {
protected:
ccColor4B m_value;
ColorChannelSprite* m_colorSprite;

bool init(std::shared_ptr<Color4BSettingV3> setting, float width);

void updateState() override;

void onCommit() override;
void onSelectColor(CCObject*);
void updateColor(ccColor4B const& color) override;

public:
static Color4BSettingNodeV3* create(std::shared_ptr<Color4BSettingV3> setting, float width);
Expand Down

0 comments on commit dd17301

Please sign in to comment.