Peoplemon  0.1.0
Peoplemon 3 game source documentation
Levels.cpp
Go to the documentation of this file.
2 
3 namespace editor
4 {
5 namespace page
6 {
7 using namespace bl::gui;
8 
9 Levels::Levels(const RenderFilterCb& filterCb, const ShiftCb& os, const AddCb& addCb)
10 : filterCb(filterCb)
11 , shiftCb(os) {
12  contentWrapper = Box::create(LinePacker::create(LinePacker::Vertical, 4));
13  content = Box::create(LinePacker::create(LinePacker::Vertical, 12));
14 
15  Button::Ptr addBut = Button::create("Add Level");
16  addBut->setTooltip(
17  "Add a new level. A level is a set of layers and can be thought of as in-game elevation");
18  addBut->getSignal(Event::LeftClicked).willAlwaysCall([addCb](const Event&, Element*) {
19  addCb();
20  });
21  content->pack(addBut);
22 
23  itemArea = ScrollArea::create(LinePacker::create(LinePacker::Vertical, 4));
24  itemArea->setMaxSize({300, 175});
25  content->pack(itemArea, true, false);
26 }
27 
28 Box::Ptr Levels::getContent() { return contentWrapper; }
29 
30 void Levels::pack() { contentWrapper->pack(content, true, true); }
31 
32 void Levels::unpack() { content->remove(); }
33 
34 void Levels::sync(const std::vector<bool>& filter) {
35  itemArea->clearChildren(true);
36  rows.clear();
37  rows.reserve(filter.size());
38  for (unsigned int i = 0; i < filter.size(); ++i) {
39  rows.emplace_back(i, filter.size() - 1, filter[i], filterCb, shiftCb);
40  itemArea->pack(rows.back().row, true, false);
41  }
42 }
43 
44 Levels::Item::Item(unsigned int i, unsigned int mi, bool v, const RenderFilterCb& filterCb,
45  const ShiftCb& shiftCb) {
46  row = Box::create(LinePacker::create(LinePacker::Horizontal));
47 
48  name = Label::create("Level " + std::to_string(i));
49  name->setColor(sf::Color(0, 180, 200), sf::Color::Transparent);
50  row->pack(name, true, false);
51 
52  visibleToggle = CheckButton::create("Visible");
53  visibleToggle->setValue(v);
54  visibleToggle->getSignal(Event::ValueChanged)
55  .willAlwaysCall([this, i, &filterCb](const Event&, Element*) {
56  filterCb(i, visibleToggle->getValue());
57  });
58  row->pack(visibleToggle, false, true);
59 
60  upBut = Button::create("Up");
61  upBut->setActive(i > 0);
62  upBut->getSignal(Event::LeftClicked).willAlwaysCall([i, &shiftCb](const Event&, Element*) {
63  shiftCb(i, true);
64  });
65  row->pack(upBut, false, true);
66 
67  downBut = Button::create("Down");
68  downBut->setActive(i < mi);
69  downBut->getSignal(Event::LeftClicked).willAlwaysCall([i, &shiftCb](const Event&, Element*) {
70  shiftCb(i, false);
71  });
72  row->pack(downBut, false, true);
73 
74  delBut = Button::create("Delete");
75  delBut->setColor(sf::Color(180, 15, 15), sf::Color(60, 0, 0));
76  row->pack(delBut, false, true);
77 }
78 
79 } // namespace page
80 } // namespace editor
All classes and functionality used for implementing the game editor.
Definition: Tile.hpp:11
void unpack()
Hides the GUI content. Good for saving space when not active.
Definition: Levels.cpp:32
bl::gui::Box::Ptr getContent()
Returns the GUI content to pack.
Definition: Levels.cpp:28
Levels(const RenderFilterCb &filterCb, const ShiftCb &onShift, const AddCb &addCb)
Construct a new Levels subpage.
Definition: Levels.cpp:9
std::function< void(unsigned int level, bool up)> ShiftCb
Definition: Levels.hpp:19
void pack()
Packs the GUI content.
Definition: Levels.cpp:30
void sync(const std::vector< bool > &filter)
Syncs the number of levels and their visible status.
Definition: Levels.cpp:34
std::function< void()> AddCb
Definition: Levels.hpp:20
std::function< void(unsigned int level, bool visible)> RenderFilterCb
Definition: Levels.hpp:18