10 T parseInput(
const bl::gui::TextEntry::Ptr& input) {
11 const long long val = std::atoll(input->getInput().c_str());
12 return static_cast<T
>(val);
15 using namespace bl::gui;
19 , onChange(onChange) {
20 window = Window::create(LinePacker::create(LinePacker::Vertical, 4.f),
"Editing Item");
21 window->getSignal(Event::Closed).willAlwaysCall(std::bind(&ItemEditorWindow::onCancel,
this));
23 LinePacker::Ptr rowPack = LinePacker::create(LinePacker::Horizontal, 4.f);
24 const auto onEdit = std::bind(&ItemEditorWindow::makeDirty,
this);
25 applyBut = Button::create(
"Save");
27 window->pack(Label::create(
"ID ranges:\n\t[1, 100] - Regular Items\n\t[101, 200] - Key "
28 "Items\n\t [201, inf] - TM's (MoveId = ItemId - 200)"));
30 Box::Ptr row = Box::create(rowPack);
31 idEntry = TextEntry::create();
32 idEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
33 idEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
34 idEntry->setRequisition({60.f, 1.f});
35 nameEntry = TextEntry::create();
36 nameEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
37 nameEntry->setRequisition({160.f, 1.f});
38 valueEntry = TextEntry::create();
39 valueEntry->setMode(TextEntry::Mode::Unsigned | TextEntry::Mode::Integer);
40 valueEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
41 valueEntry->setRequisition({60.f, 1.f});
42 row->pack(Label::create(
"Id:"),
false,
true);
43 row->pack(idEntry,
false,
true);
44 row->pack(Label::create(
"Name:"),
false,
true);
45 row->pack(nameEntry,
false,
true);
46 row->pack(Label::create(
"Value:"),
false,
true);
47 row->pack(valueEntry,
false,
true);
48 window->pack(row,
true,
false);
50 row = Box::create(rowPack);
51 descEntry = TextEntry::create();
52 descEntry->getSignal(Event::TextEntered).willAlwaysCall(onEdit);
53 descEntry->setRequisition({400.f, 1.f});
54 row->pack(Label::create(
"Description:"),
false,
true);
55 row->pack(descEntry,
false,
true);
56 window->pack(row,
true,
false);
58 row = Box::create(LinePacker::create(
59 LinePacker::Horizontal, 4.f, LinePacker::Compact, LinePacker::RightAlign));
60 Button::Ptr cancelBut = Button::create(
"Cancel");
61 cancelBut->getSignal(Event::LeftClicked)
62 .willAlwaysCall(std::bind(&ItemEditorWindow::onCancel,
this));
63 row->pack(cancelBut,
false,
true);
64 applyBut->getSignal(Event::LeftClicked)
65 .willAlwaysCall(std::bind(&ItemEditorWindow::onSave,
this));
66 row->pack(applyBut,
false,
true);
67 window->pack(row,
true,
false);
76 idEntry->setInput(doingNewItem ?
"" : std::to_string(
static_cast<int>(item)));
77 nameEntry->setInput(doingNewItem ?
"" : Item::getName(item));
78 descEntry->setInput(doingNewItem ?
"" : Item::getDescription(item));
79 valueEntry->setInput(doingNewItem ?
"100" : std::to_string(Item::getValue(item)));
82 applyBut->setColor(sf::Color(20, 240, 50), sf::Color::Black);
84 window->setForceFocus(
true);
87 void ItemEditorWindow::makeDirty() {
89 applyBut->setColor(sf::Color(230, 30, 30), sf::Color::Black);
92 void ItemEditorWindow::onSave() {
93 const auto error = [](
const std::string& e) {
94 bl::dialog::tinyfd_messageBox(
"Error", e.c_str(),
"ok",
"error", 1);
98 const int value = parseInput<int>(valueEntry);
100 if (nameEntry->getInput().empty()) {
101 error(
"Please enter a name");
104 if (descEntry->getInput().empty()) {
105 error(
"Please enter a description");
108 if (idEntry->getInput().empty()) {
109 error(
"Please enter an id");
112 if (valueEntry->getInput().empty()) { error(
"Please enter a value"); }
113 if (openId !=
id && itemDb.
names.find(
id) != itemDb.
names.end()) {
114 if (1 != bl::dialog::tinyfd_messageBox(
115 "Warning",
"Id already exists. Overwrite it?",
"yesno",
"warning", 0)) {
120 itemDb.
names[id] = nameEntry->getInput();
122 itemDb.
values[id] = value;
128 void ItemEditorWindow::onCancel() {
130 if (1 != bl::dialog::tinyfd_messageBox(
131 "Warning",
"Discard unsaved changes?",
"yesno",
"warning", 0)) {
138 void ItemEditorWindow::close() {
139 window->setForceFocus(
false);
Id
Represents an item in its simplist form.
All classes and functionality used for implementing the game editor.
Loads and stores metadata surrounding items in the game.
std::unordered_map< item::Id, std::string > names
std::unordered_map< item::Id, std::string > descriptions
std::unordered_map< item::Id, std::int32_t > values
Collection of static methods centered around items.
void open(bl::gui::GUI *parent, core::item::Id item)
Open the editor window.
std::function< void()> OnChange
Callback signature for when an item is modified.
ItemEditorWindow(core::file::ItemDB &db, const OnChange &onChange)
Construct a new Item Editor Window.