Inventory system is mostly working and I can pick up everything and use it.
This commit is contained in:
parent
aaa6d9f9f3
commit
14b3ea7676
8 changed files with 56 additions and 47 deletions
30
gui.cpp
30
gui.cpp
|
@ -31,14 +31,14 @@ using namespace ftxui;
|
|||
using namespace components;
|
||||
|
||||
void InventoryUI::create_render() {
|
||||
auto inventory_render = Renderer([&] {
|
||||
MenuOption option;
|
||||
$inventory_box = Menu(&$menu_list, &$selected, option);
|
||||
|
||||
$inventory_render = Renderer([&] {
|
||||
auto &player = $world.get_the<Player>();
|
||||
auto &inventory = $world.get<Inventory>(player.entity);
|
||||
update_menu_list(inventory);
|
||||
|
||||
MenuOption option;
|
||||
$inventory_box = Menu(&$menu_list, &$selected, option);
|
||||
|
||||
return hbox({
|
||||
$inventory_box->Render() | frame | size(WIDTH, EQUAL, 35) | yflex_grow,
|
||||
separator() | yflex_grow,
|
||||
|
@ -48,26 +48,22 @@ void InventoryUI::create_render() {
|
|||
}) | border | flex;
|
||||
});
|
||||
|
||||
set_renderer(inventory_render);
|
||||
set_renderer($inventory_render);
|
||||
add($inventory_box);
|
||||
}
|
||||
|
||||
void InventoryUI::update_menu_list(Inventory& inventory) {
|
||||
// BUG: probably need to have a dirty marker on inventory
|
||||
// so we don't update this all the damn time
|
||||
$menu_list.clear();
|
||||
int i = 0; // SOOOOO BADDDDD
|
||||
for(auto& [key, val] : inventory.items) {
|
||||
for(size_t i = 0; i < inventory.count(); i++) {
|
||||
auto& item = inventory.get(i);
|
||||
$menu_list.push_back(fmt::format("{} {} ({})",
|
||||
string(val.data["display"]),
|
||||
string(val.data["name"]),
|
||||
val.count));
|
||||
string(item.data["display"]),
|
||||
string(item.data["name"]),
|
||||
item.count));
|
||||
|
||||
// GARBAGE HOT
|
||||
if($selected == i) {
|
||||
$item_text = val.data["description"];
|
||||
if($selected == int(i)) {
|
||||
$item_text = item.data["description"];
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue