3 #include <BLIB/Util/Random.hpp>
11 using namespace bl::gui;
14 constexpr
float HourMinutes = 60.f;
15 constexpr
float DayMinutes = 24.f * HourMinutes;
18 const float sum =
static_cast<float>(time.hour) * HourMinutes +
static_cast<float>(time.minute);
19 return sum / DayMinutes;
23 const unsigned int sum = t * DayMinutes;
24 return {sum / 60, sum % 60};
29 ":" + std::to_string(qty);
39 void parsePeoplemon(
const std::string& s,
core::pplmn::Id&
id,
unsigned int& level) {
41 std::stringstream ss(s);
42 std::getline(ss, rd,
':');
44 std::getline(ss, rd,
':');
46 level = std::atoi(rd.c_str());
53 window = Window::create(LinePacker::create(LinePacker::Vertical, 4.f),
"Save Editor");
54 window->getSignal(Event::Closed).willAlwaysCall(std::bind(&GameTestingWindow::cancel,
this));
56 LinePacker::Ptr packer = LinePacker::create(LinePacker::Horizontal, 4.f);
57 Box::Ptr row = Box::create(packer);
59 nameEntry = TextEntry::create();
60 row->pack(Label::create(
"Name:"),
false,
true);
61 row->pack(nameEntry,
true,
true);
62 window->pack(row,
true,
false);
64 row = Box::create(packer);
65 row->pack(Label::create(
"Money:"),
false,
true);
66 moneyEntry = TextEntry::create();
67 moneyEntry->setMode(TextEntry::Mode::Integer | TextEntry::Mode::Unsigned);
68 row->pack(moneyEntry,
true,
true);
69 window->pack(row,
true,
false);
71 row = Box::create(packer);
72 row->pack(Label::create(
"Time:"),
false,
true);
73 timeSlider = Slider::create(Slider::Direction::Horizontal);
74 timeSlider->setRequisition({100.f, 10.f});
75 timeSlider->getSignal(Event::ValueChanged).willAlwaysCall([
this](
const Event&, Element*) {
76 updateTimeLabel(floatToTime(timeSlider->getValue()));
78 row->pack(timeSlider,
true,
true);
79 timeLabel = Label::create(
"00:00");
80 row->pack(timeLabel,
false,
true);
81 window->pack(row,
true,
false);
83 Label::Ptr section = Label::create(
"Items");
84 section->setCharacterSize(24);
85 window->pack(section,
true,
false);
86 row = Box::create(packer);
87 itemBox = SelectBox::create();
88 itemBox->setRequisition({250.f, 150.f});
89 itemBox->setMaxSize({400.f, 150.f});
90 row->pack(itemBox,
true,
true);
91 Box::Ptr column = Box::create(LinePacker::create(LinePacker::Vertical, 4.f));
92 Box::Ptr subrow = Box::create(packer);
94 subrow->pack(Label::create(
"Item:"));
95 subrow->pack(itemSelect,
true,
true);
96 Button::Ptr addBut = Button::create(
"Add");
97 addBut->getSignal(Event::LeftClicked)
98 .willAlwaysCall(std::bind(&GameTestingWindow::addItem,
this));
99 addBut->setColor(sf::Color::Green, sf::Color::Black);
100 subrow->pack(addBut,
false,
true);
101 column->pack(subrow,
true,
false);
102 Button::Ptr rmBut = Button::create(
"Remove");
103 rmBut->getSignal(Event::LeftClicked)
104 .willAlwaysCall(std::bind(&GameTestingWindow::rmItem,
this));
105 rmBut->setColor(sf::Color::Red, sf::Color::Black);
106 column->pack(rmBut,
false,
false);
107 row->pack(column,
true,
true);
108 window->pack(row,
true,
false);
110 section = Label::create(
"Conversation Flags");
111 section->setCharacterSize(24);
112 window->pack(section,
true,
false);
113 row = Box::create(packer);
114 flagBox = SelectBox::create();
115 flagBox->setRequisition({250.f, 150.f});
116 flagBox->setMaxSize({400.f, 250.f});
117 row->pack(flagBox,
true,
true);
118 column = Box::create(LinePacker::create(LinePacker::Vertical, 4.f));
119 subrow = Box::create(packer);
120 flagEntry = TextEntry::create();
121 subrow->pack(Label::create(
"Name:"),
false,
true);
122 subrow->pack(flagEntry,
true,
true);
123 column->pack(subrow,
true,
false);
124 subrow = Box::create(packer);
125 Button::Ptr but = Button::create(
"Add");
126 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&GameTestingWindow::addFlag,
this));
127 but->setColor(sf::Color::Green, sf::Color::Black);
128 subrow->pack(but,
false,
true);
129 but = Button::create(
"Remove");
130 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&GameTestingWindow::rmFlag,
this));
131 but->setColor(sf::Color::Red, sf::Color::Black);
132 subrow->pack(but,
false,
true);
133 column->pack(subrow,
true,
false);
134 row->pack(column,
true,
true);
135 window->pack(row,
true,
false);
137 section = Label::create(
"Peoplemon");
138 section->setCharacterSize(24);
139 window->pack(section,
true,
false);
140 row = Box::create(packer);
141 pplBox = SelectBox::create();
142 pplBox->setRequisition({250.f, 150.f});
143 pplBox->setMaxSize({400.f, 150.f});
144 row->pack(pplBox,
true,
true);
145 column = Box::create(LinePacker::create(LinePacker::Vertical, 4.f));
146 subrow = Box::create(packer);
147 subrow->pack(Label::create(
"Level"),
false,
true);
148 levelSelect = ComboBox::create();
149 levelSelect->setMaxHeight(200.f);
150 for (
int i = 5; i <= 100; i += 5) { levelSelect->addOption(std::to_string(i)); }
151 levelSelect->setSelectedOption(9);
152 subrow->pack(levelSelect,
true,
true);
153 column->pack(subrow,
true,
false);
154 subrow = Box::create(packer);
155 subrow->pack(Label::create(
"Species"),
false,
true);
157 pplSelect->setMaxHeight(300.f);
158 subrow->pack(pplSelect,
true,
true);
159 column->pack(subrow,
true,
false);
160 subrow = Box::create(packer);
161 but = Button::create(
"Add");
162 but->setColor(sf::Color::Green, sf::Color::Black);
163 but->getSignal(Event::LeftClicked)
164 .willAlwaysCall(std::bind(&GameTestingWindow::addPeoplemon,
this));
165 subrow->pack(but,
false,
true);
166 but = Button::create(
"Remove");
167 but->setColor(sf::Color::Red, sf::Color::Black);
168 but->getSignal(Event::LeftClicked)
169 .willAlwaysCall(std::bind(&GameTestingWindow::rmPeoplemon,
this));
170 subrow->pack(but,
false,
true);
171 column->pack(subrow,
true,
false);
172 row->pack(column,
true,
true);
173 window->pack(row,
true,
false);
175 row = Box::create(packer);
176 Button::Ptr saveBut = Button::create(
"Save");
177 saveBut->getSignal(Event::LeftClicked)
178 .willAlwaysCall(std::bind(&GameTestingWindow::doSave,
this));
179 saveBut->setColor(sf::Color::Green, sf::Color::Black);
180 row->pack(saveBut,
false,
true);
181 Button::Ptr cancelBut = Button::create(
"Cancel");
182 cancelBut->getSignal(Event::LeftClicked)
183 .willAlwaysCall(std::bind(&GameTestingWindow::cancel,
this));
184 cancelBut->setColor(sf::Color::Red, sf::Color::Black);
185 row->pack(cancelBut,
false,
true);
186 window->pack(row,
true,
false);
191 window->setForceFocus(
true);
195 moneyEntry->setInput(std::to_string(*save.
player.
monei));
197 timeSlider->setValue(timeToFloat(*save.
clock.
time));
199 itemBox->clearOptions();
200 std::vector<core::player::Bag::Item> items;
202 for (
const auto& item : items) { itemBox->addOption(itemString(item.id, item.qty)); }
204 flagBox->clearOptions();
207 pplBox->clearOptions();
209 pplBox->addOption(pplString(ppl.id(), ppl.currentLevel()));
213 void GameTestingWindow::cancel() {
214 window->setForceFocus(
false);
218 void GameTestingWindow::addItem() {
221 std::vector<std::string> opts;
222 itemBox->getAllOptions(opts);
223 for (
unsigned int i = 0; i < opts.size(); ++i) {
224 std::stringstream ss(opts[i] +
"\t");
225 std::string id, poop, qty;
226 std::getline(ss,
id,
':');
227 std::getline(ss, poop,
':');
228 std::getline(ss, qty,
'\t');
229 if (
id == std::to_string(
static_cast<unsigned int>(item))) {
230 const unsigned int nqty = std::atoi(qty.c_str()) + 1;
231 itemBox->editOptionText(i, itemString(item, nqty));
237 itemBox->addOption(itemString(item, 1));
241 void GameTestingWindow::rmItem() {
242 if (itemBox->getSelectedOption().has_value()) {
243 itemBox->removeOption(itemBox->getSelectedOption().value());
247 void GameTestingWindow::addFlag() {
248 if (!flagEntry->getInput().empty()) { flagBox->addOption(flagEntry->getInput()); }
251 void GameTestingWindow::rmFlag() {
252 if (flagBox->getSelectedOption().has_value()) {
253 flagBox->removeOption(flagBox->getSelectedOption().value());
257 void GameTestingWindow::doSave() {
258 if (nameEntry->getInput().empty()) {
259 bl::dialog::tinyfd_messageBox(
"Error",
"Enter a name",
"ok",
"error", 0);
265 *activeSave->
player.
monei = std::atol(moneyEntry->getInput().c_str());
266 *activeSave->
player.
sex = bl::util::Random::get<core::player::Gender>(
268 *activeSave->
clock.
time = floatToTime(timeSlider->getValue());
271 std::vector<std::string> vec;
272 itemBox->getAllOptions(vec);
273 for (
const auto& s : vec) {
274 std::stringstream ss(s +
"\t");
275 std::string id, poop, qtys;
276 std::getline(ss,
id,
':');
277 std::getline(ss, poop,
':');
278 std::getline(ss, qtys,
'\t');
281 const unsigned int qty = std::atoi(qtys.c_str());
285 flagBox->getAllOptions(vec);
290 for (
unsigned int i = 0; i < pplBox->optionCount(); ++i) {
293 parsePeoplemon(pplBox->getOption(i),
id, lvl);
295 for (
int j = 0; j < 4; ++j) {
298 MoveId mid = MoveId::_INVALID_2;
300 mid = bl::util::Random::get<MoveId>(MoveId::Absent, MoveId::_NUM_MOVES);
313 std::string minute = std::to_string(time.minute);
314 if (minute.size() == 1) minute.insert(0,
"0");
315 timeLabel->setText(std::to_string(time.hour) +
":" + minute);
318 void GameTestingWindow::addPeoplemon() {
321 pplString(pplSelect->currentPeoplemon(), levelSelect->getSelectedOption() * 5 + 5));
325 void GameTestingWindow::rmPeoplemon() {
326 const auto i = pplBox->getSelectedOption();
327 if (i.has_value()) { pplBox->removeOption(i.value()); }
Id
Represents an item in its simplist form.
All classes and functionality used for implementing the game editor.
Represents a game save and provides functionality to load and save.
struct core::file::GameSave::PlayerDataPointers player
struct core::file::GameSave::InteractDataPointers interaction
std::string saveName
Same as the player name but always valid.
void editorSave()
Saves the data back to the file it was loaded from.
struct core::file::GameSave::ClockPointers clock
std::unordered_set< std::string > * convFlags
std::vector< pplmn::OwnedPeoplemon > * peoplemon
system::Clock::Time * time
static const std::string & getName(item::Id item)
Returns the name of the given item.
static Id cast(unsigned int id)
Helper function to cast a raw id to an item Id.
static MoveId cast(unsigned int id)
Converts the given raw id to a move id, or Unknown if invalid.
static const std::string & name(Id id)
Returns the name of the given Peoplemon.
static Id cast(unsigned int id)
Casts an integer to a validated id. Returns Unknown if the id is invalid.
void getAll(std::vector< Item > &result) const
Returns all owned items.
void addItem(item::Id item, unsigned int qty=1)
Adds the given item to the bag.
void clear()
Removes all items.
Simple struct representing a point in time.
GameTestingWindow(const ActionCb &onSave)
std::function< void()> ActionCb
void open(bl::gui::GUI *gui, core::file::GameSave &save)
static Ptr create(const ChangeCb &cb=[](core::item::Id) {})
Creates a new ItemSelector.
static Ptr create(bool allowUnknown=false)
Creates a new peoplemon selector.