3 #include <BLIB/Interfaces.hpp>
14 const char* moveEffectNames[] = {
"None",
79 "RoarCancelBallSpikes"};
80 constexpr std::size_t moveEffectCount =
sizeof(moveEffectNames) /
sizeof(moveEffectNames[0]);
83 const unsigned int i =
static_cast<unsigned int>(ef);
84 return i < moveEffectCount ? i : 0;
88 T parseInput(
const bl::gui::TextEntry::Ptr& input) {
89 const long long val = std::atoll(input->getInput().c_str());
90 return static_cast<T
>(val);
95 using namespace bl::gui;
100 , doingNewMove(false)
102 window = Window::create(LinePacker::create(LinePacker::Vertical, 4.f),
"Editing Move");
103 window->getSignal(Event::Closed).willAlwaysCall(std::bind(&MoveEditorWindow::onCancel,
this));
105 LinePacker::Ptr rowPack = LinePacker::create(LinePacker::Horizontal, 4.f);
106 const auto onEdit = std::bind(&MoveEditorWindow::makeDirty,
this);
107 applyBut = Button::create(
"Save");
109 Box::Ptr row = Box::create(rowPack);
110 idEntry = TextEntry::create();
111 idEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
112 idEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
113 idEntry->setRequisition({60.f, 1.f});
114 nameEntry = TextEntry::create();
115 nameEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
116 nameEntry->setRequisition({160.f, 1.f});
117 row->pack(Label::create(
"Id:"),
false,
true);
118 row->pack(idEntry,
false,
true);
119 row->pack(Label::create(
"Name:"),
false,
true);
120 row->pack(nameEntry,
false,
true);
121 window->pack(row,
true,
false);
123 row = Box::create(rowPack);
124 descEntry = TextEntry::create();
125 descEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
126 descEntry->setRequisition({400.f, 1.f});
127 row->pack(Label::create(
"Description:"),
false,
true);
128 row->pack(descEntry,
false,
true);
129 window->pack(row,
true,
false);
131 row = Box::create(rowPack);
133 typeSelect->getSignal(Event::ValueChanged).willAlwaysCall(onEdit);
134 row->pack(Label::create(
"Type:"),
false,
true);
135 row->pack(typeSelect,
false,
true);
136 priorityEntry = TextEntry::create();
137 priorityEntry->setMode(TextEntry::Mode::Integer);
138 priorityEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
139 priorityEntry->setRequisition({60.f, 1.f});
140 row->pack(Label::create(
"Priority (-7 - 5):"));
141 row->pack(priorityEntry,
false,
true);
142 contactCheck = CheckButton::create(
"Makes contact");
143 contactCheck->getSignal(Event::ValueChanged).willAlwaysCall(onEdit);
144 row->pack(contactCheck,
false,
true);
145 specialCheck = CheckButton::create(
"Special");
146 specialCheck->getSignal(Event::ValueChanged).willAlwaysCall(onEdit);
147 row->pack(specialCheck,
false,
true);
148 window->pack(row,
true,
false);
150 row = Box::create(rowPack);
151 dmgEntry = TextEntry::create();
152 dmgEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
153 dmgEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
154 dmgEntry->setRequisition({60.f, 1.f});
155 row->pack(Label::create(
"Power:"),
false,
true);
156 row->pack(dmgEntry,
false,
true);
157 accEntry = TextEntry::create();
158 accEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
159 accEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
160 accEntry->setRequisition({60.f, 1.f});
161 row->pack(Label::create(
"Accuracy:"),
false,
true);
162 row->pack(accEntry,
false,
true);
163 ppEntry = TextEntry::create();
164 ppEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
165 ppEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
166 ppEntry->setRequisition({60.f, 1.f});
167 row->pack(Label::create(
"PP:"),
false,
true);
168 row->pack(ppEntry,
false,
true);
169 window->pack(row,
true,
false);
171 row = Box::create(rowPack);
172 effectSelect = ComboBox::create();
173 effectSelect->getSignal(Event::ValueChanged).willAlwaysCall(onEdit);
174 effectSelect->setMaxHeight(300.f);
175 for (std::size_t i = 0; i < moveEffectCount; ++i) {
176 effectSelect->addOption(moveEffectNames[i]);
178 effectSelect->setSelectedOption(0);
179 row->pack(Label::create(
"Effect"),
false,
true);
180 row->pack(effectSelect,
false,
true);
181 effectSelfCheck = CheckButton::create(
"Effects user");
182 effectSelfCheck->getSignal(Event::ValueChanged).willAlwaysCall(onEdit);
183 row->pack(effectSelfCheck,
false,
true);
184 window->pack(row,
true,
false);
186 row = Box::create(rowPack);
187 effectChanceEntry = TextEntry::create();
188 effectChanceEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
189 effectChanceEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
190 effectChanceEntry->setRequisition({60.f, 1.f});
191 row->pack(Label::create(
"Effect chance (0-100):"),
false,
true);
192 row->pack(effectChanceEntry,
false,
true);
193 effectIntenseEntry = TextEntry::create();
194 effectIntenseEntry->setMode(TextEntry::Mode::Integer);
195 effectIntenseEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
196 effectIntenseEntry->setRequisition({60.f, 1.f});
197 row->pack(Label::create(
"Effect intensity:"),
false,
true);
198 row->pack(effectIntenseEntry,
false,
true);
199 window->pack(row,
true,
false);
201 row = Box::create(LinePacker::create(
202 LinePacker::Horizontal, 4.f, LinePacker::Compact, LinePacker::RightAlign));
203 Button::Ptr cancelBut = Button::create(
"Cancel");
204 cancelBut->getSignal(Event::LeftClicked)
205 .willAlwaysCall(std::bind(&MoveEditorWindow::onCancel,
this));
206 row->pack(cancelBut,
false,
true);
207 applyBut->getSignal(Event::LeftClicked)
208 .willAlwaysCall(std::bind(&MoveEditorWindow::onSave,
this));
209 row->pack(applyBut,
false,
true);
210 window->pack(row,
true,
false);
219 idEntry->setInput(doingNewMove ?
"" : std::to_string(
static_cast<int>(move)));
220 nameEntry->setInput(doingNewMove ?
"" :
Move::name(move));
223 dmgEntry->setInput(doingNewMove ?
"100" : std::to_string(
Move::damage(move)));
224 accEntry->setInput(doingNewMove ?
"100" : std::to_string(
Move::accuracy(move)));
225 priorityEntry->setInput(doingNewMove ?
"0" : std::to_string(
Move::priority(move)));
226 ppEntry->setInput(doingNewMove ?
"15" : std::to_string(
Move::pp(move)));
229 effectSelect->setSelectedOption(doingNewMove ? 0 : effectToIndex(
Move::effect(move)));
231 effectChanceEntry->setInput(doingNewMove ?
"0" : std::to_string(
Move::effectChance(move)));
235 applyBut->setColor(sf::Color(20, 240, 50), sf::Color::Black);
236 parent->pack(window);
237 window->setForceFocus(
true);
240 void MoveEditorWindow::makeDirty() {
242 applyBut->setColor(sf::Color(230, 30, 30), sf::Color::Black);
245 void MoveEditorWindow::onSave() {
247 const auto error = [](
const std::string& e) {
248 bl::dialog::tinyfd_messageBox(
"Error", e.c_str(),
"ok",
"error", 1);
251 const MoveId id = parseInput<MoveId>(idEntry);
252 const int dmg = parseInput<int>(dmgEntry);
253 const int acc = parseInput<int>(accEntry);
254 const int pri = parseInput<int>(priorityEntry);
255 const int pp = parseInput<int>(ppEntry);
257 const int effectChance = parseInput<int>(effectChanceEntry);
258 const int effectIntense = parseInput<int>(effectIntenseEntry);
260 if (idEntry->getInput().empty()) {
261 error(
"Please enter an id");
264 if (openId !=
id && moveDb.names.find(
id) != moveDb.names.end()) {
265 if (1 != bl::dialog::tinyfd_messageBox(
266 "Warning",
"Id already exists. Overwrite it?",
"yesno",
"warning", 0)) {
270 if (
id == MoveId::Unknown) {
274 if (nameEntry->getInput().empty()) {
275 error(
"Please enter a name");
278 if (descEntry->getInput().empty()) {
279 error(
"Please enter a description");
282 if (typeSelect->currentType() ==
Type::None) {
283 error(
"Please select a type");
286 if (effectSelect->getSelectedOption() < 0) {
287 error(
"Please select an effect or None");
290 if (pri < -7 || pri > 5) {
291 error(
"Priority out of range");
299 moveDb.names[id] = nameEntry->getInput();
300 moveDb.descriptions[id] = descEntry->getInput();
301 moveDb.types[id] = typeSelect->currentType();
302 moveDb.damages[id] = dmg;
303 moveDb.accuracies[id] = acc;
304 moveDb.priorities[id] = pri;
306 moveDb.contactors[id] = contactCheck->getValue();
307 moveDb.specials[id] = specialCheck->getValue();
308 moveDb.effects[id] = effect;
309 moveDb.effectChances[id] = effectChance;
310 moveDb.effectIntensities[id] = effectIntense;
311 moveDb.effectSelves[id] = effectSelfCheck->getValue();
317 void MoveEditorWindow::onCancel() {
319 if (1 != bl::dialog::tinyfd_messageBox(
320 "Warning",
"Discard unsaved changes?",
"yesno",
"warning", 0)) {
327 void MoveEditorWindow::close() {
328 window->setForceFocus(
false);
MoveEffect
Represents an effect that a move can have. Copied verbatim from Peoplemon 2, may refactor later when ...
All classes and functionality used for implementing the game editor.
Collection of classes and enums pertaining to Peoplemon themselves.
Stores the metadata of all peoplemon moves.
Encapsulates the move datastore.
static unsigned int pp(MoveId move)
Returns the max pp of the given move.
static int damage(MoveId move)
Returns the damage of the given move.
static const std::string & description(MoveId move)
Returns the description of the given move.
static int accuracy(MoveId move)
Returns the accuracy of the given move.
static int priority(MoveId move)
Returns the priority of the given move.
static bool makesContact(MoveId move)
Returns whether or not the given move makes physical contact when used.
static int effectIntensity(MoveId move)
Returns the effect intensity of the given move.
static MoveEffect effect(MoveId move)
Returns the effect of the given move.
static const std::string & name(MoveId move)
Returns the name of the given move.
static Type type(MoveId move)
Returns the type of the given move.
static int effectChance(MoveId move)
Returns the effect chance of the given move.
static bool isSpecial(MoveId move)
Returns whether or not the given move is special.
static bool affectsUser(MoveId move)
Returns whether or not the given move affects the user or the opponent.
MoveEditorWindow(core::file::MoveDB &moveDb, const OnChange &onChange)
Construct a new Move Editor Window.
void open(bl::gui::GUI *parent, core::pplmn::MoveId move)
Opens the window and populates for the given move. Pass MoveId::Unknown for a new move.
std::function< void()> OnChange
Callback signature on move change.
static Ptr create()
Create a new TypeSelector.