Skip to content

Commit

Permalink
Added action listeners for enableRnd ans fixNeighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
ipochto committed Dec 9, 2024
1 parent 5db0824 commit 08a4df2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/editor/editloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ static void EditTile(const Vec2i &pos, int32_t tileIdx)
UI.Minimap.UpdateSeenXY(pos);
UI.Minimap.UpdateXY(pos);

EditorTileChanged(pos);
if (Editor.brushes.getCurrentBrush().isFixNeighborsEnabled()) {
EditorTileChanged(pos);
}
UpdateMinimap = true;
}

Expand Down
16 changes: 14 additions & 2 deletions src/editor/editor_brush_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ void CBrushControlsUI::Init(gcn::Container* parrent, const gcn::Rectangle &recta
+ allowResize["HeightOnly"]->getHeight()
+ verticalGap);

enableRndListener =
std::make_unique<LambdaActionListener>([this](const std::string&) {
Editor.brushes.getCurrentBrush().enableAutoRandomization(enableRnd->isSelected());
});
enableRnd->addActionListener(enableRndListener.get());

fixNeighbors = std::make_unique<gcn::CheckBox>("Fix neighbors");
fixNeighbors->setHeight(14);
fixNeighbors->setFont(&GetGameFont());
Expand All @@ -170,17 +176,23 @@ void CBrushControlsUI::Init(gcn::Container* parrent, const gcn::Rectangle &recta
enableRnd->getX(),
enableRnd->getY() + enableRnd->getHeight() + verticalGap);

fixNeighborsListener =
std::make_unique<LambdaActionListener>([this](const std::string&) {
Editor.brushes.getCurrentBrush().enableFixNeighbors(fixNeighbors->isSelected());
});
fixNeighbors->addActionListener(fixNeighborsListener.get());

reloadCtrlSettings();
}

void CBrushControlsUI::reloadCtrlSettings()
{
const auto brush = Editor.brushes.getCurrentBrush();
enableRnd->setVisible(brush.isRandomizeAllowed());
enableRnd->setSelected(brush.getAutoRandomizable());
enableRnd->setSelected(brush.isAutoRandomizationEnabled());

fixNeighbors->setVisible(brush.isNeighborsFixAllowed());
fixNeighbors->setSelected(brush.getFixNeighbors());
fixNeighbors->setSelected(brush.isFixNeighborsEnabled());

updateSizeCtrls();
}
Expand Down
12 changes: 8 additions & 4 deletions src/include/editor_brush.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class CBrush
{
this->name = std::move(name);
this->properties = std::move(properties);
autoRndEnabled = this->properties.randomizeAllowed;
fixNeighborsEnabled = this->properties.fixNeighborsAllowed;
setSize(this->properties.minSize.width, this->properties.minSize.height);
}
explicit CBrush(std::string name,
Expand All @@ -79,6 +81,8 @@ class CBrush
{
this->name = std::move(name);
this->properties = std::move(properties);
autoRndEnabled = this->properties.randomizeAllowed;
fixNeighborsEnabled = this->properties.fixNeighborsAllowed;
setSize(this->properties.minSize.width, this->properties.minSize.height);
fillWith(tilesSrc);
}
Expand Down Expand Up @@ -123,16 +127,16 @@ class CBrush
bool isRandomizeAllowed() const { return properties.randomizeAllowed; }
bool isNeighborsFixAllowed() const { return properties.fixNeighborsAllowed; }

void setAutoRandomizable(bool enable = true)
void enableAutoRandomization(bool enable = true)
{
autoRndEnabled = properties.randomizeAllowed ? enable : false;
}
bool getAutoRandomizable() const { return autoRndEnabled; }
void setFixNeighbors(bool enable = true)
bool isAutoRandomizationEnabled() const { return autoRndEnabled; }
void enableFixNeighbors(bool enable = true)
{
fixNeighborsEnabled = properties.fixNeighborsAllowed ? enable : false;
}
bool getFixNeighbors() const { return fixNeighborsEnabled; }
bool isFixNeighborsEnabled() const { return fixNeighborsEnabled; }

std::string getName() const { return name; }
void setName(const std::string &name) { this->name = name; }
Expand Down
2 changes: 2 additions & 0 deletions src/include/editor_brush_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class CBrushControlsUI
std::map<std::string, std::unique_ptr<gcn::RadioButton>> allowResize;

std::unique_ptr<gcn::CheckBox> enableRnd;
std::unique_ptr<LambdaActionListener> enableRndListener;
std::unique_ptr<gcn::CheckBox> fixNeighbors;
std::unique_ptr<LambdaActionListener> fixNeighborsListener;

gcn::Rectangle UIRectangle {};
int16_t verticalGap = 10;
Expand Down

0 comments on commit 08a4df2

Please sign in to comment.