3 #include <BLIB/Interfaces/GUI/Dialogs/tinyfiledialogs.hpp>
12 bool isnum(
const std::string& s) {
14 if (c < '0' || c >
'9')
return false;
19 using namespace bl::gui;
24 core::Properties::TilesetPath(), {
"tlst"},
25 [
this](
const std::string& tileset) {
26 tilesetLabel->setText(tileset);
27 tilesetPicker.close();
28 window->setForceFocus(
true);
31 tilesetPicker.close();
32 window->setForceFocus(
true);
34 window = Window::create(LinePacker::create(LinePacker::Vertical, 4),
"New map");
36 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 6));
37 row->pack(Label::create(
"Map file:"),
false,
true);
38 mapFileLabel = Label::create(
"map file");
39 mapFileLabel->setColor(sf::Color(15, 100, 245), sf::Color::Transparent);
40 row->pack(mapFileLabel,
false,
true);
41 window->pack(row,
true,
false);
43 row = Box::create(LinePacker::create(LinePacker::Horizontal, 6));
44 row->pack(Label::create(
"Name:"),
false,
true);
45 nameEntry = TextEntry::create();
46 nameEntry->setRequisition({250, 10});
47 row->pack(nameEntry,
true,
true);
48 window->pack(row,
true,
false);
50 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
51 row->pack(Label::create(
"Width:"),
false,
true);
52 widthEntry = TextEntry::create();
53 widthEntry->setRequisition({100, 10});
54 row->pack(widthEntry,
false,
true);
55 row->pack(Label::create(
"Height:"),
false,
true);
56 heightEntry = TextEntry::create();
57 heightEntry->setRequisition({100, 10});
58 row->pack(heightEntry,
false,
true);
61 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
62 pickBut = Button::create(
"Pick Tileset");
63 row->pack(pickBut,
false,
true);
64 tilesetLabel = Label::create(
"tileset file");
65 tilesetLabel->setColor(sf::Color(30, 245, 85), sf::Color::Transparent);
66 row->pack(tilesetLabel,
false,
true);
67 window->pack(row,
true,
false);
69 Button::Ptr createBut = Button::create(
"Create Map");
70 createBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
71 if (nameEntry->getInput().empty()) {
72 bl::dialog::tinyfd_messageBox(
"Error",
"Please enter a map name",
"ok",
"error", 1);
75 if (widthEntry->getInput().empty()) {
76 bl::dialog::tinyfd_messageBox(
"Error",
"Please enter a width",
"ok",
"error", 1);
79 if (heightEntry->getInput().empty()) {
80 bl::dialog::tinyfd_messageBox(
"Error",
"Please enter a height",
"ok",
"error", 1);
83 if (!isnum(widthEntry->getInput())) {
84 bl::dialog::tinyfd_messageBox(
85 "Error",
"Width must be a positive integer",
"ok",
"error", 1);
88 if (!isnum(heightEntry->getInput())) {
89 bl::dialog::tinyfd_messageBox(
90 "Error",
"Height must be a positive integer",
"ok",
"error", 1);
93 if (tilesetLabel->getText().empty()) {
94 bl::dialog::tinyfd_messageBox(
"Error",
"Please pick a tileset",
"ok",
"error", 1);
99 createCb(mapFileLabel->getText(),
100 nameEntry->getInput(),
101 tilesetLabel->getText(),
102 std::atoi(widthEntry->getInput().c_str()),
103 std::atoi(heightEntry->getInput().c_str()));
105 window->pack(createBut);
107 window->getSignal(Event::Closed).willAlwaysCall([
this](
const Event&, Element*) {
113 mapFileLabel->setText(file);
114 tilesetLabel->setText(
"");
115 nameEntry->setInput(
"");
116 widthEntry->setInput(
"");
117 heightEntry->setInput(
"");
121 pickBut->getSignal(Event::LeftClicked)
122 .willAlwaysCall([
this, parent](
const Event&, Element*) {
123 window->setForceFocus(
false);
124 tilesetPicker.open(FilePicker::CreateOrPick,
"Pick tileset", parent,
true);
128 parent->pack(window);
129 window->setForceFocus(
true);
Core classes and functionality for both the editor and game.
All classes and functionality used for implementing the game editor.
void show(bl::gui::GUI *parent, const std::string &file)
Opens the new map dialog.
NewMapDialog(const CreateCb &createCb)
Creates a new new-map dialoig.
std::function< void(const std::string &file, const std::string &name, const std::string &tileset, unsigned int w, unsigned int h)> CreateCb
Callback for when maps are created.