3 #include <BLIB/Scripts.hpp>
10 using namespace bl::gui;
15 , picker(
core::Properties::ScriptPath(), {
"psc",
"bs"},
16 std::bind(&ScriptSelector::onPick,
this, std::placeholders::_1), [
this]() {
18 window->setForceFocus(
true);
20 window = Window::create(LinePacker::create(LinePacker::Vertical, 4),
"Select Script");
21 window->getSignal(Event::Closed).willAlwaysCall([
this](
const Event&, Element*) {
26 Button::Ptr pickBut = Button::create(
"Pick File");
27 pickBut->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
28 window->setForceFocus(
false);
29 picker.open(FilePicker::PickExisting,
"Pick Script", parent,
false);
31 window->pack(pickBut);
33 scriptInput = TextEntry::create();
34 scriptInput->setRequisition({250, 1});
35 scriptInput->getSignal(Event::TextEntered).willAlwaysCall([
this](
const Event&, Element*) {
38 window->pack(scriptInput,
true,
false);
40 errorLabel = Label::create(
"");
41 window->pack(errorLabel,
true,
false);
43 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 10));
44 Button::Ptr choose = Button::create(
"Select");
45 choose->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
47 onSelect(scriptInput->getInput());
49 row->pack(choose,
false,
true);
50 Button::Ptr cancel = Button::create(
"Cancel");
51 cancel->getSignal(Event::LeftClicked).willAlwaysCall([
this](
const Event&, Element*) {
55 row->pack(cancel,
false,
true);
56 window->pack(row,
true,
false);
61 scriptInput->setInput(s);
63 window->setForceFocus(
true);
67 void ScriptSelector::onPick(
const std::string& s) {
68 scriptInput->setInput(s);
70 window->setForceFocus(
true);
74 void ScriptSelector::checkSyntax() {
75 bl::script::Script script(scriptInput->getInput());
77 errorLabel->setText(
"No error");
78 errorLabel->setColor(sf::Color::Green, sf::Color::Transparent);
81 errorLabel->setText(script.errorMessage());
82 errorLabel->setColor(sf::Color::Red, sf::Color::Transparent);
Core classes and functionality for both the editor and game.
All classes and functionality used for implementing the game editor.
std::function< void()> OnCancel
Called when the window is closed without a selection.
void open(bl::gui::GUI *parent, const std::string &value={})
Opens the dialog to select a script.
std::function< void(const std::string &)> OnSelect
Callback type for when a script is chosen.
ScriptSelector(const OnSelect &onSelect, const OnCancel &onCancel)
Construct a new Script Selector dialog.