3 #include <BLIB/Util/Random.hpp>
12 constexpr
float InputWidth = 60.f;
17 if (level < 7)
return {};
20 const unsigned int l = level - 7;
21 const unsigned int iterCount = l * l / 12;
23 for (
unsigned int i = 0; i < iterCount; ++i) {
24 const unsigned int j = bl::util::Random::get<unsigned int>(0, ids.size());
33 using namespace bl::gui;
39 const auto f = std::bind(&StatBox::onChange,
this, std::placeholders::_2);
41 hpEntry = TextEntry::create();
42 hpEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
43 hpEntry->setRequisition({InputWidth, 1.f});
44 hpEntry->getSignal(Event::ValueChanged).willAlwaysCall(f);
46 atkEntry = TextEntry::create();
47 atkEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
48 atkEntry->setRequisition({InputWidth, 1.f});
49 atkEntry->getSignal(Event::ValueChanged).willAlwaysCall(f);
51 defEntry = TextEntry::create();
52 defEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
53 defEntry->setRequisition({InputWidth, 1.f});
54 defEntry->getSignal(Event::ValueChanged).willAlwaysCall(f);
56 spAtkEntry = TextEntry::create();
57 spAtkEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
58 spAtkEntry->setRequisition({InputWidth, 1.f});
59 spAtkEntry->getSignal(Event::ValueChanged).willAlwaysCall(f);
61 spDefEntry = TextEntry::create();
62 spDefEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
63 spDefEntry->setRequisition({InputWidth, 1.f});
64 spDefEntry->getSignal(Event::ValueChanged).willAlwaysCall(f);
66 spdEntry = TextEntry::create();
67 spdEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
68 spdEntry->setRequisition({InputWidth, 1.f});
69 spdEntry->getSignal(Event::ValueChanged).willAlwaysCall(f);
75 hpEntry->setInput(
"0");
76 atkEntry->setInput(
"0");
77 defEntry->setInput(
"0");
78 spAtkEntry->setInput(
"0");
79 spDefEntry->setInput(
"0");
80 spdEntry->setInput(
"0");
85 ret.
hp = std::atoi(hpEntry->getInput().c_str());
86 ret.
atk = std::atoi(atkEntry->getInput().c_str());
87 ret.
def = std::atoi(defEntry->getInput().c_str());
88 ret.
spatk = std::atoi(spAtkEntry->getInput().c_str());
89 ret.
spdef = std::atoi(spDefEntry->getInput().c_str());
90 ret.
spd = std::atoi(spdEntry->getInput().c_str());
95 hpEntry->setInput(std::to_string(val.
hp));
96 atkEntry->setInput(std::to_string(val.
atk));
97 defEntry->setInput(std::to_string(val.
def));
98 spAtkEntry->setInput(std::to_string(val.
spatk));
99 spDefEntry->setInput(std::to_string(val.
spdef));
100 spdEntry->setInput(std::to_string(val.
spd));
104 void StatBox::syncSum() {
106 sumLabel->setText(
"Sum: " + std::to_string(stats.
sum()));
112 LinePacker::Ptr rowPacker = LinePacker::create(LinePacker::Horizontal, 4.f);
114 Box::Ptr row = Box::create(rowPacker);
115 Label::Ptr lbl = Label::create(
"HP:");
116 lbl->setHorizontalAlignment(RenderSettings::Left);
117 row->pack(lbl,
true,
true);
118 row->pack(hpEntry,
false,
true);
119 content.pack(row,
true,
false);
121 row = Box::create(rowPacker);
122 lbl = Label::create(
"Atk:");
123 lbl->setHorizontalAlignment(RenderSettings::Left);
124 row->pack(lbl,
true,
true);
125 row->pack(atkEntry,
false,
true);
126 content.pack(row,
true,
false);
128 row = Box::create(rowPacker);
129 lbl = Label::create(
"Def:");
130 lbl->setHorizontalAlignment(RenderSettings::Left);
131 row->pack(lbl,
true,
true);
132 row->pack(defEntry,
false,
true);
133 content.pack(row,
true,
false);
135 row = Box::create(rowPacker);
136 lbl = Label::create(
"SpAtk:");
137 lbl->setHorizontalAlignment(RenderSettings::Left);
138 row->pack(lbl,
true,
true);
139 row->pack(spAtkEntry,
false,
true);
140 content.pack(row,
true,
false);
142 row = Box::create(rowPacker);
143 lbl = Label::create(
"SpDef:");
144 lbl->setHorizontalAlignment(RenderSettings::Left);
145 row->pack(lbl,
true,
true);
146 row->pack(spDefEntry,
false,
true);
147 content.pack(row,
true,
false);
149 row = Box::create(rowPacker);
150 lbl = Label::create(
"Spd:");
151 lbl->setHorizontalAlignment(RenderSettings::Left);
152 row->pack(lbl,
true,
true);
153 row->pack(spdEntry,
false,
true);
154 content.pack(row,
true,
false);
156 sumLabel = Label::create(
"");
157 content.pack(sumLabel,
true,
false);
160 Button::Ptr but = Button::create(
"Randomize");
161 but->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
162 if (mode == Mode::IV) {
164 hpEntry->setInput(std::to_string(bl::util::Random::get<unsigned int>(0, max)));
165 atkEntry->setInput(std::to_string(bl::util::Random::get<unsigned int>(0, max)));
166 defEntry->setInput(std::to_string(bl::util::Random::get<unsigned int>(0, max)));
167 spAtkEntry->setInput(std::to_string(bl::util::Random::get<unsigned int>(0, max)));
168 spDefEntry->setInput(std::to_string(bl::util::Random::get<unsigned int>(0, max)));
169 spdEntry->setInput(std::to_string(bl::util::Random::get<unsigned int>(0, max)));
172 update(genRandomEVs(level));
180 void StatBox::onChange(Element* e) {
183 TextEntry* te =
dynamic_cast<TextEntry*
>(e);
188 std::stringstream ss;
190 bl::dialog::tinyfd_messageBox(
"Warning", ss.str().c_str(),
"ok",
"warning", 1);
194 std::stringstream ss;
197 bl::dialog::tinyfd_messageBox(
"Warning", ss.str().c_str(),
"ok",
"warning", 1);
204 std::stringstream ss;
207 bl::dialog::tinyfd_messageBox(
"Warning", ss.str().c_str(),
"ok",
"warning", 1);
Stat
Represents a single stat. Used as an offset to access Stats as an array.
All classes and functionality used for implementing the game editor.
Collection of classes and enums pertaining to Peoplemon themselves.
static const std::vector< Id > & validIds()
Returtns the list of all valid ids.
static const Stats & evAward(Id id)
Returns the ev points awarded for defeating the given peoplemon.
Stats for Peoplemon. This struct is used for base stats, EVs, IVs, battle increases/decreases,...
static constexpr int MaxEVStat
The maximum amount that a single EV can be.
static constexpr int MaxIVStat
The maximum amount that a single IV can be.
int & get(Stat stat)
Returns a reference to the given stat.
static const std::array< Stat, 6 > IterableStats
Helper array to iterate over stats in loop.
void addEVs(const Stats &evs)
Adds the given EV points to this set of stats while obeying the constraints on EV values and sums.
static const char * statToString(Stat stat)
Converts the given stat to its string representation.
static constexpr int MaxEVSum
The maximum amount that EVs or IVs can sum to.
int sum() const
Returns the sum of the 6 stats that are used for EV calculations.
void pack(bl::gui::Box &container)
Packs the GUI elements into the given container.
void reset()
Resets all stats to 0.
core::pplmn::Stats currentValue() const
Returns the current Stats value entered.
Mode
Mode the entry is in.
StatBox(Mode mode, bool showRandomBut=true)
Construct a new Stat Box component.
void notifyLevel(unsigned int level)
Make the statbox aware of the level of the peoplemon it is editing. Used for random EV generation.
void update(const core::pplmn::Stats &value)
Updates the GUI elements with the given value.