Skip to content

Commit

Permalink
- Fixed type for the tile mask.
Browse files Browse the repository at this point in the history
- Added flag MapFieldFromUnseparatedSlot for slots containing mixed types of tiles without zero-separators between them. This tiles cannot be randomized.
- Fixed flag assignment when changing the tile assigned to a map field.
- Reworked generation of tiles sets (all/first of type only/solid).
- Icon palette (available for map editing) moved to a separate class. Editor's slider usage for icons palette reworked also. The corresponding obsolete user interface code was removed.
- Enabled the ability to mark/unmark tiles as decorative so that they don't change automatically when editing neighboring tiles later.
- Variables and methods responsible for editing map fields have been moved to CEditor.
- Random map generator moved to CEditor;
- Reworked current brush apply;
- Cleanup CBrushControlsUI;
  • Loading branch information
ipochto committed Jan 18, 2025
1 parent cf78e71 commit 38465e2
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 542 deletions.
386 changes: 88 additions & 298 deletions src/editor/editloop.cpp

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/editor/editor_brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
-- Functions
----------------------------------------------------------------------------*/

void CBrush::applyBrushAt(const TilePos &pos, brushApplyFn applyFn, bool forbidRandomization /* = false*/) const
void CBrush::applyAt(const TilePos &pos, brushApplyFn applyFn, bool forbidRandomization /* = false*/) const
{
TilePos brushOffset{};
if (isCentered()) {
Expand All @@ -63,11 +63,10 @@ void CBrush::applyBrushAt(const TilePos &pos, brushApplyFn applyFn, bool forbidR
const tile_index tileIdx = getTile(col, row);
if (tileIdx) {
const TilePos tileOffset(col - brushOffset.x, row - brushOffset.y);
const tile_index applyTile = properties.randomizeAllowed
&& this->autoRndEnabled && !forbidRandomization
? randomizeTile(tileIdx)
: tileIdx;
applyFn(tileOffset, applyTile);
const tile_index applyTile = forbidRandomization || !this->rndEnabled
? tileIdx
: randomizeTile(tileIdx);
applyFn(tileOffset, applyTile, isFixNeighborsEnabled(), isDecorative());
}
}
}
Expand Down Expand Up @@ -276,7 +275,7 @@ bool CBrushesSet::setCurrentBrush(std::string_view name)
for (auto &brush : brushes) {
if (brush.getName() == name) {
currentBrush = brush;
const auto selectedTile = Editor.getSelectedTile();
const auto selectedTile = Editor.tileIcons.getSelectedTile();
if (selectedTile && currentBrush.getType() == CBrush::BrushTypes::SingleTile) {
currentBrush.setTile(*selectedTile);
}
Expand Down
81 changes: 58 additions & 23 deletions src/editor/editor_brush_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,37 +168,67 @@ void CBrushControlsUI::Init(gcn::Container* parrent, const gcn::Rectangle &recta
});
sizeSlider->addActionListener(brushSizeSliderListener.get());

enableRnd = std::make_unique<gcn::CheckBox>("Random");
enableRnd->setHeight(14);
enableRnd->setFont(&GetGameFont());
decorative = std::make_unique<gcn::CheckBox>("Decorative");
decorative->setHeight(14);
decorative->setFont(&GetGameFont());

controls.push_back(dynamic_cast<gcn::Widget*>(enableRnd.get()));
parrent->add(enableRnd.get(),
controls.push_back(dynamic_cast<gcn::Widget*>(decorative.get()));
parrent->add(decorative.get(),
UIRectangle.x + 5,
allowResize["HeightOnly"]->getY()
+ allowResize["HeightOnly"]->getHeight()
+ verticalGap);

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

manualEditMode = std::make_unique<gcn::CheckBox>("Manual mode");
manualEditMode->setHeight(14);
manualEditMode->setFont(&GetGameFont());

controls.push_back(dynamic_cast<gcn::Widget*>(manualEditMode.get()));
parrent->add(manualEditMode.get(),
UIRectangle.x + 5,
decorative->getY() + decorative->getHeight() + verticalGap);

fixNeighbors = std::make_unique<gcn::CheckBox>("Fix neighbors");
fixNeighbors->setHeight(14);
fixNeighbors->setFont(&GetGameFont());
manualEditModeListener = std::make_unique<LambdaActionListener>([this](const std::string &) {

controls.push_back(dynamic_cast<gcn::Widget*>(fixNeighbors.get()));
parrent->add(fixNeighbors.get(),
enableRnd->getX(),
enableRnd->getY() + enableRnd->getHeight() + verticalGap);
auto &brush = Editor.brushes.getCurrentBrush();
brush.enableFixNeighbors(manualEditMode->isSelected() == false);
enableRnd->setVisible(brush.isRandomizeAllowed() && manualEditMode->isSelected());

fixNeighborsListener =
if (manualEditMode->isSelected() == false) {
brush.setDecorative(false);
}
decorative->setVisible(!brush.isFixNeighborsEnabled());
decorative->setSelected(brush.isDecorative());

Editor.tileIcons.rebuild(brush.isFixNeighborsEnabled() == false,
brush.isRandomizationEnabled());
});
manualEditMode->addActionListener(manualEditModeListener.get());

enableRnd = std::make_unique<gcn::CheckBox>("Random");
enableRnd->setHeight(14);
enableRnd->setFont(&GetGameFont());

controls.push_back(dynamic_cast<gcn::Widget*>(enableRnd.get()));
parrent->add(enableRnd.get(),
manualEditMode->getX(),
manualEditMode->getY() + manualEditMode->getHeight() + verticalGap);

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

auto &brush = Editor.brushes.getCurrentBrush();
brush.enableRandomization(enableRnd->isSelected());
Editor.tileIcons.rebuild(brush.isFixNeighborsEnabled() == false,
brush.isRandomizationEnabled());
});
fixNeighbors->addActionListener(fixNeighborsListener.get());
enableRnd->addActionListener(enableRndListener.get());

reloadCtrlSettings();
}
Expand All @@ -209,11 +239,16 @@ void CBrushControlsUI::reloadCtrlSettings()
hiddenControls.clear();
}
const auto brush = Editor.brushes.getCurrentBrush();
enableRnd->setVisible(brush.isRandomizeAllowed());
enableRnd->setSelected(brush.isAutoRandomizationEnabled());

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

enableRnd->setVisible(brush.isRandomizeAllowed() && manualEditMode->isSelected());
enableRnd->setSelected(brush.isRandomizationEnabled());

decorative->setVisible(!brush.isFixNeighborsEnabled());
decorative->setSelected(brush.isDecorative());


updateSizeCtrls();
}
Expand Down
Loading

0 comments on commit 38465e2

Please sign in to comment.