7 using namespace bl::gui;
11 , scriptSelector(std::bind(&
EventEditor::onScriptChosen, this, std::placeholders::_1),
12 [this]() { window->setForceFocus(
true); }) {
13 window = Window::create(LinePacker::create(LinePacker::Vertical, 10),
"Event Editor");
14 window->getSignal(Event::Closed).willAlwaysCall([
this](
const Event&, Element*) {
18 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 8));
19 scriptLabel = Label::create(
"");
20 scriptLabel->setColor(sf::Color::Blue, sf::Color::Transparent);
21 row->pack(scriptLabel,
true,
true);
22 Button::Ptr pickButton = Button::create(
"Pick/Edit Script");
23 pickButton->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
24 window->setForceFocus(
false);
25 scriptSelector.open(parent, scriptLabel->getText());
27 row->pack(pickButton,
false,
true);
28 window->pack(row,
true,
false);
30 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
31 Box::Ptr input = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
32 input->pack(Label::create(
"X:"),
false,
true);
33 xInput = TextEntry::create();
34 input->pack(xInput,
true,
true);
35 row->pack(input,
true,
true);
36 input = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
37 input->pack(Label::create(
"Y:"),
false,
true);
38 yInput = TextEntry::create();
39 input->pack(yInput,
true,
true);
40 row->pack(input,
true,
true);
41 window->pack(row,
true,
false);
43 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
44 input = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
45 input->pack(Label::create(
"W:"),
false,
true);
46 wInput = TextEntry::create();
47 input->pack(wInput,
true,
true);
48 row->pack(input,
true,
true);
49 input = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
50 input->pack(Label::create(
"H:"),
false,
true);
51 hInput = TextEntry::create();
52 input->pack(hInput,
true,
true);
53 row->pack(input,
true,
true);
54 window->pack(row,
true,
false);
56 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
57 triggerSelect = ComboBox::create();
58 triggerSelect->addOption(
"OnEnter");
59 triggerSelect->addOption(
"OnExit");
60 triggerSelect->addOption(
"OnEnterOrExit");
61 triggerSelect->addOption(
"WhileIn");
62 triggerSelect->addOption(
"OnInteract");
63 row->pack(Label::create(
"Trigger:"),
false,
true);
64 row->pack(triggerSelect,
false,
true);
65 window->pack(row,
true,
false);
67 row = Box::create(LinePacker::create(LinePacker::Horizontal, 4));
68 Button::Ptr editBut = Button::create(
"Confirm");
69 editBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
71 onEdit(orig, makeEvent());
75 row->pack(editBut,
false,
true);
76 Button::Ptr cancelBut = Button::create(
"Cancel");
77 cancelBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
80 row->pack(cancelBut,
false,
true);
81 window->pack(row,
true,
false);
85 const sf::Vector2i& tiles) {
88 window->setForceFocus(
true);
92 scriptLabel->setText(source->
script);
93 xInput->setInput(std::to_string(source->
position.x));
94 yInput->setInput(std::to_string(source->
position.y));
95 wInput->setInput(std::to_string(source->
areaSize.x));
96 hInput->setInput(std::to_string(source->
areaSize.y));
97 triggerSelect->setSelectedOption(
static_cast<int>(source->
trigger) - 1);
100 scriptLabel->setText(
"");
101 xInput->setInput(std::to_string(tiles.x));
102 yInput->setInput(std::to_string(tiles.y));
103 wInput->setInput(
"1");
104 hInput->setInput(
"1");
105 triggerSelect->setSelectedOption(0);
109 bool EventEditor::valid()
const {
110 const auto isNum = [](
const std::string& s) ->
bool {
111 for (
const char c : s) {
112 if (c < '0' || c >
'9')
return false;
117 const auto err = [](
const std::string& e) {
118 bl::dialog::tinyfd_messageBox(
"Error", e.c_str(),
"ok",
"error", 1);
121 if (!isNum(xInput->getInput())) {
122 err(
"X tile position is invalid");
125 if (!isNum(yInput->getInput())) {
126 err(
"Y tile position is invalid");
129 if (!isNum(wInput->getInput())) {
130 err(
"Region tile width is invalid");
133 if (!isNum(hInput->getInput())) {
134 err(
"Region tile height is invalid");
142 e.
script = scriptLabel->getText();
143 e.
position.x = std::atoi(xInput->getInput().c_str());
144 e.
position.y = std::atoi(yInput->getInput().c_str());
145 e.
areaSize.x = std::atoi(wInput->getInput().c_str());
146 e.
areaSize.y = std::atoi(hInput->getInput().c_str());
151 void EventEditor::onScriptChosen(
const std::string& s) {
152 scriptLabel->setText(s);
153 window->setForceFocus(
true);
All classes and functionality used for implementing the game editor.
Represents an event in a Map. A script that is run on a trigger within a given region.
Trigger
What action triggers the event.
std::function< void(const core::map::Event *, const core::map::Event &)> OnEdit
Callback called when an event is created or modified.
void open(bl::gui::GUI *parent, const core::map::Event *source, const sf::Vector2i &pos)
Opens the dialog window and optionally populates with event info.
EventEditor(const OnEdit &onEdit)
Construct a new Event Editor dialog.