Peoplemon  0.1.0
Peoplemon 3 game source documentation
PeoplemonSelector.cpp
Go to the documentation of this file.
3 
4 namespace editor
5 {
6 namespace component
7 {
9 
10 PeoplemonSelector::PeoplemonSelector(bool au)
11 : ComboBox()
12 , allowUnknown(au) {
13  refresh();
14 }
15 
17  return getSelectedOption() < 0 ? core::pplmn::Id::Unknown :
18  core::pplmn::Peoplemon::validIds()[getSelectedOption()];
19 }
20 
22  if (allowUnknown && id == core::pplmn::Id::Unknown) {
23  setSelectedOption(0);
24  return;
25  }
26 
27  for (unsigned int i = 0; i < core::pplmn::Peoplemon::validIds().size(); ++i) {
28  if (core::pplmn::Peoplemon::validIds()[i] == id) {
29  setSelectedOption(allowUnknown ? i + 1 : i);
30  return;
31  }
32  }
33 
34  BL_LOG_WARN << "Tried to set invalid Peoplemon id: " << id;
35 }
36 
38  clearOptions();
39  if (allowUnknown) { addOption("Unknown/None"); }
41  addOption(std::to_string(static_cast<int>(id)) + ": " + core::pplmn::Peoplemon::name(id));
42  }
43 }
44 
45 } // namespace component
46 } // 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::vector< Id > & validIds()
Returtns the list of all valid ids.
Definition: Peoplemon.cpp:118
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
Definition: Peoplemon.cpp:126
Special combobox for Peoplemon ids.
static Ptr create(bool allowUnknown=false)
Creates a new peoplemon selector.
core::pplmn::Id currentPeoplemon() const
Returns the currently selected peoplemon.
std::shared_ptr< PeoplemonSelector > Ptr
void setPeoplemon(core::pplmn::Id id)
Sets the currently selected Peoplemon.
void refresh()
Refreshes the list of peoplemon.