Peoplemon  0.1.0
Peoplemon 3 game source documentation
MoveSelector.cpp
Go to the documentation of this file.
2 
3 #include <BLIB/Util/Random.hpp>
5 
6 namespace editor
7 {
8 namespace component
9 {
10 using namespace bl::gui;
11 
13  return Ptr(new MoveSelector(ef, ccb));
14 }
15 
16 MoveSelector::MoveSelector(bool ef, const ChangeCb& ccb)
17 : Box(LinePacker::create(LinePacker::Vertical, 8.f)) {
18  Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
19  row->pack(Label::create("Filter:"), false, true);
20  noMoveFilter = RadioButton::create("None", "none");
21  noMoveFilter->getSignal(Event::ValueChanged)
22  .willAlwaysCall(std::bind(&MoveSelector::refresh, this));
23  levelMoveFilter = RadioButton::create("Learned", "learn", noMoveFilter->getRadioGroup());
24  levelMoveFilter->getSignal(Event::ValueChanged)
25  .willAlwaysCall(std::bind(&MoveSelector::refresh, this));
26  poolMoveFilter = RadioButton::create("Pool", "pool", noMoveFilter->getRadioGroup());
27  poolMoveFilter->getSignal(Event::ValueChanged)
28  .willAlwaysCall(std::bind(&MoveSelector::refresh, this));
29  row->pack(noMoveFilter, false, true);
30  row->pack(levelMoveFilter, false, true);
31  row->pack(poolMoveFilter, false, true);
32 
33  if (ef) { pack(row, true, true); }
34 
35  selector = ComboBox::create();
36  selector->getSignal(Event::ValueChanged).willAlwaysCall([this, ccb](const Event&, Element*) {
37  if (ccb) (ccb(currentMove()));
38  });
39  selector->setMaxHeight(300.f);
40  pack(selector, true, true);
41 
42  refresh();
43  noMoveFilter->setValue(true);
44 }
45 
47  return selector->getSelectedOption() >= 0 ? validMoves[selector->getSelectedOption()] :
49 }
50 
52  selector->setSelectedOption(core::pplmn::Move::name(m), false);
53 }
54 
56  peoplemon = id;
57  level = l;
58  refresh();
59 }
60 
62  const core::pplmn::MoveId m = currentMove();
63  selector->clearOptions();
64 
65  if (noMoveFilter->getValue()) { validMoves = core::pplmn::Move::validIds(); }
66  else if (levelMoveFilter->getValue()) {
67  validMoves.clear();
68  core::pplmn::Id ppl = peoplemon;
69  while (ppl != core::pplmn::Id::Unknown) {
70  for (unsigned int i = 0; i <= level; ++i) {
71  const auto move = core::pplmn::Peoplemon::moveLearnedAtLevel(ppl, i);
72  if (move != core::pplmn::MoveId::Unknown) {
73  if (std::find(validMoves.begin(), validMoves.end(), move) == validMoves.end()) {
74  validMoves.push_back(move);
75  }
76  }
77  }
79  }
80  }
81  else {
82  validMoves.clear();
83  core::pplmn::Id ppl = peoplemon;
84  while (ppl != core::pplmn::Id::Unknown) {
85  for (const auto move : core::pplmn::Move::validIds()) {
86  if (core::pplmn::Peoplemon::canLearnMove(ppl, move)) {
87  if (std::find(validMoves.begin(), validMoves.end(), move) == validMoves.end()) {
88  validMoves.push_back(move);
89  }
90  }
91  }
93  }
94  }
95 
96  int i = 0;
97  for (const auto move : validMoves) {
98  selector->addOption(core::pplmn::Move::name(move));
99  ++i;
100  }
101 
102  if (m == core::pplmn::MoveId::Unknown) selector->setSelectedOption(0, false);
103 }
104 
106  selector->setSelectedOption(bl::util::Random::get<int>(0, selector->optionCount() - 1));
107 }
108 
109 } // namespace component
110 } // namespace editor
MoveId
The id of a move.
Definition: MoveId.hpp:16
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< MoveId > & validIds()
Returns the list of all valid move ids.
Definition: Move.cpp:64
static const std::string & name(MoveId move)
Returns the name of the given move.
Definition: Move.cpp:71
static MoveId moveLearnedAtLevel(Id ppl, unsigned int level)
Returns the move the peoplemon learns at the given level, if any.
Definition: Peoplemon.cpp:157
static Id evolvesFrom(Id evolved)
Returns what the given Peoplemon evolved from. This is expensive.
Definition: Peoplemon.cpp:204
static bool canLearnMove(Id ppl, MoveId move)
Returns whether or not the given Peoplemon can learn the given move.
Definition: Peoplemon.cpp:152
Combobox for selecting moves.
void setCurrentMove(core::pplmn::MoveId move)
Set the currently selected move.
void selectRandom()
Selects a random move.
void notifyPeoplemon(core::pplmn::Id ppl, unsigned int level)
Notifies the selector of the peoplemon being selected for.
std::function< void(core::pplmn::MoveId)> ChangeCb
Called when a move is selected.
static Ptr create(bool enableFilter, const ChangeCb &changeCb={})
Create a new MoveSelector.
std::shared_ptr< MoveSelector > Ptr
Pointer to this component.
core::pplmn::MoveId currentMove() const
Returns the currently selected move.
void refresh()
Refreshes the list of moves.