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.

main
Zed A. Shaw 5 days ago
parent 135d9a128b
commit aaa6d9f9f3
  1. 70
      gui.cpp
  2. 13
      gui.hpp
  3. 2
      systems.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<Player>();
auto &inventory = $world.get<Inventory>(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<Player>();
while($world.has_event<eGUI>()) {
auto [evt, entity, data] = $world.recv<eGUI>();
@ -241,9 +233,9 @@ void GUI::handle_world_events() {
} break;
case eGUI::LOOT: {
auto &item = std::any_cast<InventoryItem&>(data);
auto &inventory = $world.get<Inventory>(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:

@ -50,14 +50,21 @@ struct UnDumbTSS {
class InventoryUI : public Panel {
public:
std::vector<string> $inventory_list;
int $selected = 0;
Component $inventory_box;
Component $inventory_table;
string $fake_text;
DinkyECS::World& $world;
std::vector<std::string> $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 {

@ -135,7 +135,7 @@ void System::collision(DinkyECS::World &world, Player &player) {
world.send<Events::GUI>(Events::GUI::COMBAT, entity, result);
} else if(world.has<InventoryItem>(entity)) {
auto& item = world.get<InventoryItem>(entity);
auto item = world.get<InventoryItem>(entity);
auto& item_pos = world.get<Position>(entity);
auto& inventory = world.get<Inventory>(player.entity);

Loading…
Cancel
Save