7 using namespace bl::gui;
11 content = Box::create(LinePacker::create(LinePacker::Vertical, 4.f));
13 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
14 row->pack(Label::create(
"Save:"),
false,
true);
15 saveSelector = ComboBox::create();
16 saveSelector->setMaxHeight(350.f);
17 saveSelector->getSignal(Event::ValueChanged).willAlwaysCall([
this](
const Event&, Element*) {
18 if (saveSelector->getSelectedOption() >= 0) {
19 auto& save = saves[saveSelector->getSelectedOption()];
21 bl::dialog::tinyfd_messageBox(
"Error",
"Error loading save",
"ok",
"error", 0);
24 updatePosLabel(save.world.playerPos->level, save.world.playerPos->position);
27 row->pack(saveSelector,
true,
true);
28 Button::Ptr but = Button::create(
"Edit");
29 but->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
30 if (saveSelector->getSelectedOption() >= 0) {
31 auto& save = saves[saveSelector->getSelectedOption()];
33 window.open(gui, save);
36 row->pack(but,
false,
true);
37 but = Button::create(
"Create");
38 but->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
39 newSave.useLocalData();
40 newSave.saveName =
"New Save";
41 *newSave.world.prevMap =
"Worldmap";
42 *newSave.world.prevPlayerPos = {0, glm::i32vec2(300, 300), bl::tmap::Direction::Down};
43 newSave.player.inventory->clear();
44 *newSave.player.monei = 1000000;
45 newSave.player.peoplemon->clear();
47 *newSave.player.playerName =
"Assturd";
49 newSave.interaction.convFlags->clear();
50 newSave.interaction.talkedto->clear();
51 newSave.scripts.entries->clear();
52 posLabel->setText(
"<unset>");
53 window.open(gui, newSave);
55 row->pack(but,
false,
true);
56 content->pack(row,
true,
false);
58 content->pack(Label::create(
"Click map to set spawn position"));
59 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4.f));
60 row->pack(Label::create(
"Spawn position:"),
false,
true);
61 posLabel = Label::create(
"<unchanged>");
62 posLabel->setColor(sf::Color(20, 230, 245), sf::Color::Transparent);
63 row->pack(posLabel,
false,
true);
64 content->pack(row,
true,
false);
66 but = Button::create(
"Launch Game");
67 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&GameTesting::launchGame,
this));
68 but->setColor(sf::Color(30, 230, 40), sf::Color::Black);
73 void GameTesting::registerGUI(GUI* g) { gui = g; }
75 const Box::Ptr& GameTesting::getContent()
const {
return content; }
77 void GameTesting::sync() {
80 for (
auto& save : saves) { save.useLocalData(); }
82 saveSelector->clearOptions();
83 for (
auto& save : saves) { saveSelector->addOption(save.saveName); }
86 void GameTesting::notifyClick(
const std::string& mapName,
unsigned int level,
87 const sf::Vector2i& pos) {
88 if (saveSelector->getSelectedOption() >= 0) {
89 auto& save = saves[saveSelector->getSelectedOption()];
91 *save.world.currentMap = mapName;
92 *save.world.playerPos =
93 bl::tmap::Position(level, glm::i32vec2(pos.x, pos.y), bl::tmap::Direction::Down);
95 updatePosLabel(level, glm::i32vec2(pos.x, pos.y));
99 void GameTesting::updatePosLabel(
unsigned int level,
const glm::i32vec2& pos) {
100 std::stringstream ss;
101 ss <<
"Lvl: " << level <<
". Tile: (" << pos.x <<
", " << pos.y <<
")";
102 posLabel->setText(ss.str());
105 void GameTesting::launchGame() {
106 static const std::string Path =
"PeoplemonDebug.exe";
107 if (bl::util::FileUtil::exists(Path)) {
108 if (saveSelector->getSelectedOption() >= 0) {
109 auto& save = saves[saveSelector->getSelectedOption()];
112 const std::string cmd =
114 BL_LOG_INFO <<
"Launching game: '" << cmd <<
"'";
115 std::system(cmd.c_str());
118 bl::dialog::tinyfd_messageBox(
119 "Invalid Save",
"Failed to load save",
"ok",
"error", 1);
123 bl::dialog::tinyfd_messageBox(
"Invalid Save",
"Please select a save",
"ok",
"error", 1);
127 bl::dialog::tinyfd_messageBox(
128 "Game not found",
"PeoplemonDebug.exe not found",
"ok",
"error", 1);
All classes and functionality used for implementing the game editor.
static std::string filename(const std::string &saveName)
Returns the filename for the given save name.
static void listSaves(std::vector< GameSave > &result)
Lists all saves in the save directory.
Subpage in the map editor for creating and testing game saves.
GameTesting()
Construct a new Game Testing page.