Peoplemon  0.1.0
Peoplemon 3 game source documentation
OwnedPeoplemonWindow.cpp
Go to the documentation of this file.
2 
5 
6 namespace editor
7 {
8 namespace component
9 {
10 using namespace bl::gui;
11 
13 : onFinish(fcb)
14 , onCancel(ccb)
15 , evBox(StatBox::EV)
16 , ivBox(StatBox::IV) {
17  window =
18  Window::create(LinePacker::create(LinePacker::Vertical, 4.f), "Owned Peoplemon Editor");
19  window->getSignal(Event::Closed).willAlwaysCall([this](const Event&, Element*) {
20  hide();
21  onCancel();
22  });
23 
24  idSelect = PeoplemonSelector::create();
25  idSelect->setMaxHeight(400.f);
26  idSelect->getSignal(Event::ValueChanged).willAlwaysCall([this](const Event&, Element*) {
27  const auto ppl = getValue();
28  moveSelector->notifyPeoplemon(ppl.id(), ppl.currentLevel());
29  });
30  Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
31  row->pack(Label::create("Species:"), false, true);
32  row->pack(idSelect, false, true);
33  window->pack(row);
34 
35  row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
36  row->pack(Label::create("Nickname:"), false, true);
37  nameEntry = TextEntry::create();
38  nameEntry->setRequisition({80.f, 1.f});
39  row->pack(nameEntry, false, true);
40  window->pack(row);
41 
42  row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
43  row->pack(Label::create("Level:"), false, true);
44  levelEntry = TextEntry::create();
45  levelEntry->setInput("50");
46  levelEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
47  levelEntry->setRequisition({60.f, 1.f});
48  levelEntry->getSignal(Event::ValueChanged).willAlwaysCall([this](const Event&, Element*) {
49  const unsigned int level = std::atoi(levelEntry->getInput().c_str());
50  evBox.notifyLevel(level);
51  moveSelector->notifyPeoplemon(getValue().id(), level);
52  });
53  row->pack(levelEntry, false, true);
54  window->pack(row);
55 
56  Label::Ptr l = Label::create("Moves:");
57  l->setHorizontalAlignment(RenderSettings::Alignment::Left);
58  window->pack(l, true, false);
59  row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
60  moveBox = SelectBox::create();
61  moveBox->setMaxSize({1200.f, 90.f});
62  moveBox->setRequisition({250.f, 108.f});
63  row->pack(moveBox, true, true);
64  Box::Ptr box = Box::create(LinePacker::create(LinePacker::Vertical, 8.f));
65  Box::Ptr subRow = Box::create(LinePacker::create());
66  moveSelector = MoveSelector::create(true);
67  subRow->pack(moveSelector, false, true);
68  box->pack(subRow, true, false);
69  subRow = Box::create(LinePacker::create());
70  Button::Ptr but = Button::create("Add");
71  but->getSignal(Event::LeftClicked).willAlwaysCall([this](const Event&, Element*) {
72  if (moves.size() < 4) {
73  if (std::find(moves.begin(), moves.end(), moveSelector->currentMove()) == moves.end()) {
74  moves.push_back(moveSelector->currentMove());
75  moveBox->addOption(core::pplmn::Move::name(moveSelector->currentMove()));
76  }
77  }
78  });
79  subRow->pack(but, false, true);
80  but = Button::create("Random");
81  but->getSignal(Event::LeftClicked).willAlwaysCall([this](const Event&, Element*) {
82  moveSelector->selectRandom();
83  });
84  subRow->pack(but, false, false);
85  but = Button::create("Remove");
86  but->setColor(sf::Color::Red, sf::Color::Black);
87  but->getSignal(Event::LeftClicked).willAlwaysCall([this](const Event&, Element*) {
88  const auto sel = moveBox->getSelectedOption();
89  if (moves.size() > 1 && sel.has_value()) {
90  moves.erase(moves.begin() + sel.value());
91  moveBox->removeOption(sel.value());
92  }
93  });
94  subRow->pack(but, false, true);
95  box->pack(subRow, true, false);
96  row->pack(box);
97  window->pack(row, true, false);
98 
99  row = Box::create(LinePacker::create(LinePacker::Horizontal, 8.f));
100  box = Box::create(LinePacker::create(LinePacker::Vertical, 4.f));
101  box->pack(Label::create("EVs"), true, false);
102  evBox.pack(*box);
103  row->pack(box, true, true);
104  box = Box::create(LinePacker::create(LinePacker::Vertical, 4.f));
105  box->pack(Label::create("IVs"), true, false);
106  ivBox.pack(*box);
107  row->pack(box, true, true);
108  window->pack(row);
109 
110  row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
111  itemSelector = ItemSelector::create();
112  but = Button::create("Clear");
113  but->getSignal(Event::LeftClicked).willAlwaysCall([this](const Event&, Element*) {
114  itemSelector->setSelectedOption(-1);
115  });
116  row->pack(Label::create("Hold item:"), false, true);
117  row->pack(itemSelector, false, true);
118  row->pack(but, false, true);
119  window->pack(row);
120 
121  but = Button::create("Save");
122  but->setColor(sf::Color::Green, sf::Color::Black);
123  but->getSignal(Event::LeftClicked).willAlwaysCall([this](const Event&, Element*) {
124  if (validate()) {
125  hide();
126  onFinish();
127  }
128  });
129  window->pack(but);
130 }
131 
132 void OwnedPeoplemonWindow::show(GUI* p, const core::pplmn::OwnedPeoplemon& value) {
133  parent = p;
134 
135  if (core::pplmn::Peoplemon::name(value.id()) == value.name()) { nameEntry->setInput(""); }
136  else {
137  nameEntry->setInput(value.name());
138  }
139 
140  levelEntry->setInput(std::to_string(value.currentLevel()));
141  idSelect->setPeoplemon(value.id());
142 
143  evBox.update(value.currentEVs());
144  ivBox.update(value.currentIVs());
145 
146  itemSelector->setItem(value.holdItem());
147  itemSelector->refresh();
148 
149  moveBox->clearOptions();
150  moves.clear();
151  moves.reserve(4);
152  for (unsigned int i = 0; i < 4; ++i) {
153  if (value.moves[i].id != core::pplmn::MoveId::Unknown) {
154  moves.push_back(value.moves[i].id);
155  moveBox->addOption(core::pplmn::Move::name(value.moves[i].id));
156  }
157  }
158  moveSelector->notifyPeoplemon(value.id(), value.currentLevel());
159 
160  parent->pack(window);
161  window->setForceFocus(true);
162 }
163 
164 void OwnedPeoplemonWindow::hide() {
165  window->setForceFocus(false);
166  window->remove();
167 }
168 
169 core::pplmn::OwnedPeoplemon OwnedPeoplemonWindow::getValue() const {
170  core::pplmn::OwnedPeoplemon val(idSelect->currentPeoplemon(),
171  std::atoi(levelEntry->getInput().c_str()));
172  val.ivs = ivBox.currentValue();
173  val.evs = evBox.currentValue();
174  val.item = itemSelector->currentItem();
175  val.hp = val.currentStats().hp;
176  for (unsigned int i = 0; i < 4; ++i) {
177  if (i < moves.size()) { val.moves[i] = core::pplmn::OwnedMove(moves[i]); }
178  else {
179  val.moves[i].id = core::pplmn::MoveId::Unknown;
180  }
181  }
182  return val;
183 }
184 
185 void OwnedPeoplemonWindow::syncMoves() {}
186 
187 bool OwnedPeoplemonWindow::validate() const {
188  const unsigned int level = std::atoi(levelEntry->getInput().c_str());
189  if (level > 100) {
190  bl::dialog::tinyfd_messageBox(
191  "Warning", "Level cannot be greater than 100", "ok", "warning", 1);
192  return false;
193  }
194 
195  const core::pplmn::Id id = idSelect->currentPeoplemon();
196  if (id == core::pplmn::Id::Unknown) {
197  bl::dialog::tinyfd_messageBox("Warning", "Please select a species", "ok", "warning", 1);
198  return false;
199  }
200 
201  if (moves.empty()) {
202  bl::dialog::tinyfd_messageBox(
203  "Warning", "Please add at least one move", "ok", "warning", 1);
204  return false;
205  }
206 
207  return true;
208 }
209 
210 } // namespace component
211 } // namespace editor
Id
The id of a peoplemon.
Definition: Id.hpp:16
All classes and functionality used for implementing the game editor.
Definition: Tile.hpp:11
static const std::string & name(MoveId move)
Returns the name of the given move.
Definition: Move.cpp:71
Represents a move owned by a peoplemon.
Definition: OwnedMove.hpp:17
MoveId id
The id of the move.
Definition: OwnedMove.hpp:19
Represents an instance of a peoplemon. Can be a wild peoplemon, trainer, or player peoplemon....
const Stats & currentEVs() const
Returns the current EVs of this peoplemon.
unsigned int currentLevel() const
Returns the current level of this peoplemon.
const Stats & currentIVs() const
Returns the current IVs of this peoplemon.
Stats currentStats() const
Returns the computed stats for the peoplemon. Does not take into account changes during battle.
Id id() const
Returns the id of this peoplemon.
item::Id & holdItem()
Access the current hold item of this peoplemon.
const std::string & name() const
Returns the name of this peoplemon, custom or defualt.
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
Definition: Peoplemon.cpp:126
static Ptr create(const ChangeCb &cb=[](core::item::Id) {})
Creates a new ItemSelector.
Definition: ItemSelector.cpp:9
static Ptr create(bool enableFilter, const ChangeCb &changeCb={})
Create a new MoveSelector.
std::function< void()> NotifyCB
Callback for when the window is closed.
OwnedPeoplemonWindow(const NotifyCB &onFinish, const NotifyCB &onCancel)
Construct a new Owned Peoplemon Window.
core::pplmn::OwnedPeoplemon getValue() const
Returns the value of the Peoplemon entered.
static Ptr create(bool allowUnknown=false)
Creates a new peoplemon selector.
Provides an inline GUI entry for stats in either EV mode or IV mode.
Definition: StatBox.hpp:17
void notifyLevel(unsigned int level)
Make the statbox aware of the level of the peoplemon it is editing. Used for random EV generation.
Definition: StatBox.cpp:109