From aaa6d9f9f319e072300f2038663d06544f06bd5f Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 3 Jan 2025 21:09:42 -0500 Subject: [PATCH] Can display items picked up but man is this some garbage code. I need to rethink how inventory is stored so that it'll work with the Menu. --- gui.cpp | 70 ++++++++++++++++++++++++----------------------------- gui.hpp | 13 +++++++--- systems.cpp | 2 +- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/gui.cpp b/gui.cpp index 852e48e..314e466 100644 --- a/gui.cpp +++ b/gui.cpp @@ -31,51 +31,44 @@ using namespace ftxui; using namespace components; void InventoryUI::create_render() { - $inventory_list = { - "Sword (10)", - "Hat (1)", - "Fruit (4)", - "Dead Rabbit (1)" - }; - - $fake_text = R"( -Franzen kickstarter keffiyeh poutine actually master cleanse, irony butcher live-edge glossier stumptown organic PBR&B. Cloud bread cupping praxis hammock, offal tilde fam ennui vexillologist chartreuse chillwave. Chambray swag umami chartreuse cupping photo booth butcher fashion axe godard banh mi portland sartorial banjo shabby chic intelligentsia. Praxis synth helvetica 3 wolf moon raclette tousled. Tousled cliche jawn, coloring book meh pitchfork chartreuse. Kitsch try-hard poke celiac tote bag listicle photo booth. - )"; - - - $inventory_table = Renderer([&]{ - auto table = Table({ - {"Version", "Marketing name", "Release date", "API level", "Runtime"}, - {"2.3", "Gingerbread", "February 9 2011", "10", "Dalvik 1.4.0"}, - {"4.0", "Ice Cream Sandwich", "October 19 2011", "15", "Dalvik"}, - {"4.1", "Jelly Bean", "July 9 2012", "16", "Dalvik"}, - {"4.2", "Jelly Bean", "November 13 2012", "17", "Dalvik"}, - {"4.3", "Jelly Bean", "July 24 2013", "18", "Dalvik"}, - {"4.4", "KitKat", "October 31 2013", "19", "Dalvik and ART"}, - {"5.0", "Lollipop", "November 3 2014", "21", "ART"}, - {"5.1", "Lollipop", "March 9 2015", "22", "ART"}, - }); - - table.SelectAll().Border(LIGHT); - table.SelectRow(0).Border(DOUBLE); - return table.Render(); - }); + auto inventory_render = Renderer([&] { + auto &player = $world.get_the(); + auto &inventory = $world.get(player.entity); + update_menu_list(inventory); - MenuOption option; - $inventory_box = Menu(&$inventory_list, &$selected, option); + MenuOption option; + $inventory_box = Menu(&$menu_list, &$selected, option); - auto inventory_test = Renderer([&] { return hbox({ $inventory_box->Render() | frame | size(WIDTH, EQUAL, 35) | yflex_grow, separator() | yflex_grow, vflow({ - paragraph($fake_text) | border, - $inventory_table->Render() + paragraph($item_text) | border }) | flex }) | border | flex; }); - set_renderer(inventory_test); + set_renderer(inventory_render); +} + +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) { + $menu_list.push_back(fmt::format("{} {} ({})", + string(val.data["display"]), + string(val.data["name"]), + val.count)); + + // GARBAGE HOT + if($selected == i) { + $item_text = val.data["description"]; + } + + i++; + } } void StatusUI::create_render() { @@ -177,6 +170,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) : $status_ui(world), $lights(game_map.width(), game_map.height()), $map_view($world, $lights, $game_map), + $inventory_ui(world), $sounds("./assets") { // this needs a config file soon @@ -212,8 +206,6 @@ void GUI::create_renderer() { void GUI::handle_world_events() { using eGUI = Events::GUI; - auto player = $world.get_the(); - while($world.has_event()) { auto [evt, entity, data] = $world.recv(); @@ -241,9 +233,9 @@ void GUI::handle_world_events() { } break; case eGUI::LOOT: { auto &item = std::any_cast(data); - auto &inventory = $world.get(player.entity); - fmt::println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UPDATE INVENTORY HERE."); $sounds.play("loot_gold"); + $status_ui.log(fmt::format("You picked up a {}.", + std::string(item.data["name"]))); } break; default: diff --git a/gui.hpp b/gui.hpp index 0cb233f..317bb13 100644 --- a/gui.hpp +++ b/gui.hpp @@ -50,14 +50,21 @@ struct UnDumbTSS { class InventoryUI : public Panel { public: - std::vector $inventory_list; + int $selected = 0; Component $inventory_box; Component $inventory_table; - string $fake_text; + DinkyECS::World& $world; + std::vector $menu_list; + std::string $item_text = "No item selected."; + + InventoryUI(DinkyECS::World& world) : + Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT), + $world(world) + {} - InventoryUI() : Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT) {} void create_render(); + void update_menu_list(components::Inventory& inventory); }; class StatusUI : public Panel { diff --git a/systems.cpp b/systems.cpp index 15cc257..309800a 100644 --- a/systems.cpp +++ b/systems.cpp @@ -135,7 +135,7 @@ void System::collision(DinkyECS::World &world, Player &player) { world.send(Events::GUI::COMBAT, entity, result); } else if(world.has(entity)) { - auto& item = world.get(entity); + auto item = world.get(entity); auto& item_pos = world.get(entity); auto& inventory = world.get(player.entity);