7 using namespace bl::gui;
12 , map(component::EditMap::create(
13 cb, std::bind(&
MapArea::onMouseOver, this, std::placeholders::_1, std::placeholders::_2),
14 std::bind(&
MapArea::refreshButtons, this), syncCb, s))
15 , lastDragTile(-1, -1) {
16 content = Box::create(LinePacker::create(LinePacker::Vertical, 0));
17 content->setOutlineThickness(0.f);
19 Box::Ptr controlRow = Box::create(LinePacker::create(LinePacker::Horizontal, 0));
20 controlRow->setOutlineThickness(0.f);
22 Box::Ptr leftSide = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
23 undoBut = Button::create(
"Undo");
24 undoBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
27 undoBut->setActive(
false);
28 redoBut = Button::create(
"Redo");
29 redoBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
32 redoBut->setActive(
false);
33 CheckButton::Ptr gbut = CheckButton::create(
"Grid");
34 gbut->getSignal(Event::ValueChanged).willAlwaysCall([
this](
const Event& e, Element*) {
35 map->showGrid(e.toggleValue());
37 positionLabel = Label::create(
"Tile: ()");
38 positionLabel->setHorizontalAlignment(RenderSettings::Right);
39 positionLabel->setVerticalAlignment(RenderSettings::Bottom);
40 leftSide->pack(undoBut,
false,
true);
41 leftSide->pack(redoBut,
false,
true);
42 leftSide->pack(gbut,
false,
true);
43 leftSide->pack(positionLabel,
true,
true);
45 Box::Ptr rightSide = Box::create(LinePacker::create(
46 LinePacker::Horizontal, 6.f, LinePacker::Compact, LinePacker::RightAlign));
47 enableBut = CheckButton::create(
"Enable Map Controls");
48 enableBut->setTooltip(
"Enable or disable map editing. Useful for not making accidental edits");
49 enableBut->getSignal(Event::ValueChanged).willAlwaysCall([
this](
const Event& a, Element*) {
50 map->setControlsEnabled(a.toggleValue());
52 dragBut = CheckButton::create(
"Enable drag");
54 rightSide->pack(enableBut,
false,
true);
55 rightSide->pack(dragBut,
false,
true);
57 controlRow->pack(leftSide,
true,
false);
58 controlRow->pack(rightSide,
true,
false);
59 content->pack(controlRow,
true,
false);
60 content->pack(map,
true,
true);
62 bl::event::Dispatcher::subscribe(
this);
69 void MapArea::refreshButtons() {
70 const char* undoDesc = map->undoDescription();
72 undoBut->setTooltip(std::string(
"Undo ") + undoDesc);
73 undoBut->setActive(
true);
76 undoBut->setTooltip(
"");
77 undoBut->setActive(
false);
80 const char* redoDesc = map->redoDescription();
82 redoBut->setTooltip(std::string(
"Redo ") + redoDesc);
83 redoBut->setActive(
true);
86 redoBut->setTooltip(
"");
87 redoBut->setActive(
false);
91 void MapArea::onMouseOver(
const sf::Vector2f& pixels,
const sf::Vector2i& tiles) {
92 positionLabel->setText(
"Tile: (" + std::to_string(tiles.x) +
", " + std::to_string(tiles.y) +
94 if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && dragBut->getValue()) {
95 if (lastDragTile != tiles && enableBut->getValue()) {
97 onClick(pixels, tiles);
104 enableBut->setValue(
true);
109 enableBut->setValue(
false);
113 enableBut->setActive(
false);
114 enableBut->setForceFocus(
true);
118 enableBut->setActive(
true);
119 enableBut->setForceFocus(
false);
All classes and functionality used for implementing the game editor.
Owns all primary systems and a reference to the engine.
Wrapper over the core::Map class that is directly usable in a bl::gui::GUI.
std::function< void(const sf::Vector2f &pixels, const sf::Vector2i &tiles)> PositionCb
Called when the map is clicked.
std::function< void()> ActionCb
Called on various event types.
void setControlsEnabled(bool enabled)
Enables or disables the map camera and click controls.
Fired when a map rendering is started.
Fired when a map rendering is complete.
Section of the map area with the map itself and related controls.
bl::gui::Element::Ptr getContent()
Returns the GUI element to pack.
void enableControls()
Enables the map controls.
MapArea(const component::EditMap::PositionCb &clickCb, const component::EditMap::ActionCb &syncCb, core::system::Systems &systems)
Construct a new Map Area.
component::EditMap & editMap()
Returns the contained map.
void disableControls()
Disables the map controls when a dialog is opened or the map tab is inactive.