10 std::vector<core::item::Id> ids;
11 ids.reserve(db.
names.size());
12 for (
const auto& p : db.
names) { ids.emplace_back(p.first); }
13 std::sort(ids.begin(), ids.end());
18 using namespace bl::gui;
22 , itemWindow(itemDb, std::bind(&
Items::onChange, this)) {
23 content = Box::create(LinePacker::create(LinePacker::Vertical));
25 Box::Ptr row = Box::create(LinePacker::create(LinePacker::Horizontal, 8.f));
26 Button::Ptr but = Button::create(
"New Item");
27 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&Items::newItem,
this));
28 row->pack(but,
false,
true);
29 saveBut = Button::create(
"Save");
30 saveBut->setColor(sf::Color::Green, sf::Color::Black);
31 saveBut->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&Items::save,
this));
32 row->pack(saveBut,
false,
true);
33 but = Button::create(
"Reset");
34 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&Items::reset,
this));
35 but->setColor(sf::Color::Red, sf::Color::Black);
36 row->pack(but,
false,
true);
37 content->pack(row,
true,
false);
39 rowArea = ScrollArea::create(LinePacker::create(LinePacker::Vertical, 4.f));
40 content->pack(rowArea,
true,
true);
42 if (!itemDb.
load()) BL_LOG_ERROR <<
"Failed to load item database";
48 rowArea->clearChildren(
true);
49 const std::vector<core::item::Id> allIds = getSorted(itemDb);
52 LinePacker::Ptr rowPack = LinePacker::create(LinePacker::Horizontal, 4.f, LinePacker::Uniform);
54 Box::Ptr row = Box::create(rowPack);
55 row->setColor(i % 2 == 0 ? sf::Color(185, 185, 185) : sf::Color(70, 70, 70),
56 sf::Color(20, 85, 230));
57 Label::Ptr lbl = Label::create(
"Id: " + std::to_string(
static_cast<int>(
id)));
58 lbl->setColor(sf::Color(30, 85, 255), sf::Color::Transparent);
59 row->pack(lbl,
false,
true);
61 lbl->setColor(sf::Color(255, 60, 90), sf::Color::Transparent);
62 row->pack(lbl,
false,
true);
64 lbl->setColor(sf::Color(60, 255, 90), sf::Color::Transparent);
65 row->pack(lbl,
false,
true);
66 Button::Ptr but = Button::create(
"Edit");
67 but->setColor(sf::Color(230, 230, 30), sf::Color::Black);
68 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&Items::editItem,
this,
id));
69 row->pack(but,
false,
true);
70 but = Button::create(
"Delete");
71 but->setColor(sf::Color(230, 30, 30), sf::Color::Black);
72 but->getSignal(Event::LeftClicked).willAlwaysCall(std::bind(&Items::deleteItem,
this,
id));
73 row->pack(but,
false,
true);
74 rowArea->pack(row,
true,
false);
79 void Items::makeDirty() { saveBut->setColor(sf::Color::Yellow, sf::Color::Black); }
82 if (!itemDb.
save()) { BL_LOG_ERROR <<
"Failed to save item database"; }
84 saveBut->setColor(sf::Color::Green, sf::Color::Black);
93 if (!itemDb.
load()) { BL_LOG_ERROR <<
"Failed to load item database"; }
96 saveBut->setColor(sf::Color::Green, sf::Color::Black);
103 itemDb.
names.erase(item);
105 itemDb.
values.erase(item);
110 void Items::onChange() {
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.
bool save() const
Writes the item metadata to the data file.
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
bool load()
Loads the item metadata from the data file.
static void setDataSource(file::ItemDB &source)
Set the data source for the item methods.
static const std::string & getName(item::Id item)
Returns the name of the given item.
static int getValue(item::Id item)
Returns the value of the given item.
Owns all primary systems and a reference to the engine.
void open(bl::gui::GUI *parent, core::item::Id item)
Open the editor window.
Page for editing item names, descriptions, and values.
virtual void update(float dt) override
Does nothing.
Items(core::system::Systems &systems)
Construct a new Items page.
Base class for all editor pages.
bl::gui::Box::Ptr content