3 #include <BLIB/Util/Random.hpp>
9 using namespace bl::gui;
13 : bottomAdd(bottomAddCb)
14 , ysortAdd(ysortAddCb)
18 , filterCb(filterCb) {
19 contentWrapper = Box::create(LinePacker::create(LinePacker::Vertical, 4));
20 contentWrapper->setOutlineThickness(0.f);
21 content = Notebook::create();
22 content->setRequisition({1.f, 200.f});
26 const std::vector<std::vector<bool>>& filter) {
27 for (
unsigned int i = 0; i < content->pageCount(); ++i) { content->removePageByIndex(i); }
30 pages.reserve(levels.size());
31 for (
unsigned int i = 0; i < levels.size(); ++i) {
32 const auto& level = levels[i];
34 i, level, filter[i], filterCb, bottomAdd, ysortAdd, topAdd, delCb, shiftCb);
35 const std::string title =
"Level " + std::to_string(pages.back().index);
36 content->addPage(title, title, pages.back().page);
47 const std::vector<bool>& filter,
const RenderFilterCb& vcb,
48 const AppendCb& bottomAddCb,
const AppendCb& ysortAddCb,
49 const AppendCb& topAddCb,
const DeleteCb& delCb,
const ShiftCb& shiftCb)
51 page = ScrollArea::create(LinePacker::create(LinePacker::Vertical, 8));
52 page->setMaxSize({300, 175});
54 Box::Ptr box = Box::create(LinePacker::create(LinePacker::Vertical, 8));
55 const auto visibleCb = [
this, vcb](
unsigned int layer,
bool v) { vcb(index, layer, v); };
56 const auto deleteCb = [
this, delCb](
unsigned int layer) { delCb(index, layer); };
57 const auto onShift = [
this, shiftCb](
unsigned int layer,
bool up) {
58 shiftCb(index, layer, up);
61 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 0, LinePacker::Uniform));
62 Button::Ptr addBut = Button::create(
"Add");
63 addBut->getSignal(Event::LeftClicked)
65 [
this, bottomAddCb, visibleCb](
const Event&, Element*) { bottomAddCb(index); });
66 bottomBox = Box::create(LinePacker::create(LinePacker::Vertical, 4));
67 row->pack(Label::create(
"Bottom Layers"),
true,
true);
68 row->pack(addBut,
false,
false);
69 bottomBox->pack(row,
true,
false);
71 row = Box::create(LinePacker::create(LinePacker::Horizontal, 0, LinePacker::Uniform));
72 addBut = Button::create(
"Add");
73 addBut->getSignal(Event::LeftClicked)
74 .willAlwaysCall([
this, ysortAddCb](
const Event&, Element*) { ysortAddCb(index); });
75 ysortBox = Box::create(LinePacker::create(LinePacker::Vertical, 4));
76 row->pack(Label::create(
"Y-Sort Layers"),
true,
true);
77 row->pack(addBut,
false,
false);
78 ysortBox->pack(row,
true,
false);
80 row = Box::create(LinePacker::create(LinePacker::Horizontal, 0, LinePacker::Uniform));
81 addBut = Button::create(
"Add");
82 addBut->getSignal(Event::LeftClicked).willAlwaysCall([
this, topAddCb](
const Event&, Element*) {
85 topBox = Box::create(LinePacker::create(LinePacker::Vertical, 4));
86 row->pack(Label::create(
"Top Layers"),
true,
true);
87 row->pack(addBut,
false,
false);
88 topBox->pack(row,
true,
false);
90 box->pack(bottomBox,
true,
false);
91 box->pack(ysortBox,
true,
false);
92 box->pack(topBox,
true,
false);
95 for (
unsigned int i = 0; i < level.
bottomLayers().size(); ++i) {
96 items.emplace_back(i, i != 0,
true, filter[i], visibleCb, deleteCb, onShift);
97 bottomBox->pack(items.back().row,
true,
false);
102 items.emplace_back(i,
true,
true, filter[i], visibleCb, deleteCb, onShift);
103 ysortBox->pack(items.back().row,
true,
false);
109 i,
true, i != level.
layerCount() - 1, filter[i], visibleCb, deleteCb, onShift);
110 topBox->pack(items.back().row,
true,
false);
113 page->pack(box,
true,
true);
116 Layers::LayerRow::LayerRow(
unsigned int i,
bool canUp,
bool canDown,
bool visible,
117 const VisibleCb& visibleCb,
const DeleteCb& delCb,
118 const ShiftCb& shiftCb)
120 row = Box::create(LinePacker::create(
121 LinePacker::Horizontal, 2.f, LinePacker::Compact, LinePacker::LeftAlign));
122 row->setOutlineThickness(0.f);
124 name = Label::create(
"Layer " + std::to_string(i));
125 name->setColor(sf::Color(bl::util::Random::get<std::uint8_t>(80, 255),
126 bl::util::Random::get<std::uint8_t>(80, 255),
127 bl::util::Random::get<std::uint8_t>(80, 255)),
128 sf::Color::Transparent);
129 row->pack(name,
true,
false);
131 visibleToggle = CheckButton::create(
"Visible");
132 visibleToggle->setValue(visible);
133 visibleToggle->getSignal(Event::ValueChanged)
134 .willAlwaysCall([
this, visibleCb](
const Event&, Element*) {
135 visibleCb(index, visibleToggle->getValue());
137 row->pack(visibleToggle,
false,
true);
139 upBut = Button::create(
"Up");
140 upBut->setTooltip(
"Move this layer up the list. Higher layers are below lower layers");
141 upBut->setActive(canUp);
143 upBut->getSignal(Event::LeftClicked)
144 .willAlwaysCall([
this, shiftCb](
const Event&, Element*) { shiftCb(index,
true); });
146 row->pack(upBut,
false,
true);
148 downBut = Button::create(
"Down");
149 downBut->setTooltip(
"Move this layer down the list. Lower layers are on top of higher layers");
150 downBut->setActive(canDown);
152 downBut->getSignal(Event::LeftClicked)
153 .willAlwaysCall([
this, shiftCb](
const Event&, Element*) { shiftCb(index,
false); });
155 row->pack(downBut,
false,
true);
157 delBut = Button::create(
"Delete");
158 delBut->setColor(sf::Color(180, 15, 15), sf::Color(60, 0, 0));
159 delBut->getSignal(Event::LeftClicked).willAlwaysCall([
this, delCb](
const Event&, Element*) {
162 row->pack(delBut,
false,
true);
All classes and functionality used for implementing the game editor.
Encapsulates a set of layers for a given map height. Maps have one LayerSet per height level,...
std::vector< TileLayer > & bottomLayers()
Returns a reference to the bottom tiles in this set.
std::vector< TileLayer > & ysortLayers()
Returns a reference to the sorted tiles in this set.
unsigned int layerCount() const
Returns the total number of layers contained.
std::function< void(unsigned int level, unsigned int layer)> DeleteCb
void unpack()
Hides the GUI content. Good for saving space when not active.
std::function< void(unsigned int level)> AppendCb
void pack()
Packs the GUI content.
void sync(const std::vector< core::map::LayerSet > &levels, const std::vector< std::vector< bool >> &filter)
Syncs the GUI elements with the map layers that exist.
std::function< void(unsigned int level, unsigned int layer, bool visible)> RenderFilterCb
bl::gui::Box::Ptr getContent()
Returns the GUI content to pack.
std::function< void(unsigned int level, unsigned int layer, bool up)> ShiftCb
Layers(const AppendCb &bottomAddCb, const AppendCb &ysortAddCb, const AppendCb &topAddCb, const DeleteCb &delCb, const ShiftCb &shiftCb, const RenderFilterCb &filterCb)
Construct a new Layers subpage.