All of the UIs should be cleared out, and that just leaves the tests.
This commit is contained in:
parent
d5ff57e025
commit
564f9842a2
23 changed files with 126 additions and 145 deletions
|
@ -6,13 +6,14 @@
|
|||
#include "gui/guecstra.hpp"
|
||||
#include "systems.hpp"
|
||||
#include "inventory.hpp"
|
||||
#include "game_level.hpp"
|
||||
#include "levelmanager.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
using std::any, std::any_cast, std::string, std::make_any;
|
||||
|
||||
StatusUI::StatusUI(GameLevel level) :
|
||||
$level(level), $ritual_ui(level)
|
||||
StatusUI::StatusUI()
|
||||
{
|
||||
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
|
||||
$gui.layout(
|
||||
|
@ -45,7 +46,7 @@ namespace gui {
|
|||
} else {
|
||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||
$gui.set<Clickable>(gui_id, {
|
||||
guecs::make_action($level, gui_id, Events::GUI::INV_SELECT, {gui_id})
|
||||
guecs::make_action(gui_id, Events::GUI::INV_SELECT, {gui_id})
|
||||
});
|
||||
$gui.set<DropTarget>(gui_id, {
|
||||
.commit=[&, gui_id](DinkyECS::Entity world_target) -> bool {
|
||||
|
@ -74,8 +75,9 @@ namespace gui {
|
|||
}
|
||||
|
||||
void StatusUI::update() {
|
||||
auto player = $level.world->get_the<components::Player>();
|
||||
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||
auto world = Game::current_world();
|
||||
auto player = world->get_the<components::Player>();
|
||||
auto& inventory = world->get<inventory::Model>(player.entity);
|
||||
|
||||
for(const auto& [slot, cell] : $gui.cells()) {
|
||||
|
||||
|
@ -83,7 +85,7 @@ namespace gui {
|
|||
auto gui_id = $gui.entity(slot);
|
||||
auto world_entity = inventory.get(slot);
|
||||
|
||||
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
||||
auto& sprite = world->get<components::Sprite>(world_entity);
|
||||
$gui.set_init<guecs::Icon>(gui_id, {sprite.name});
|
||||
guecs::GrabSource grabber{ world_entity,
|
||||
[&, gui_id]() { return remove_slot(gui_id); }};
|
||||
|
@ -106,18 +108,17 @@ namespace gui {
|
|||
$ritual_ui.render(window);
|
||||
}
|
||||
|
||||
void StatusUI::update_level(GameLevel &level) {
|
||||
$level = level;
|
||||
void StatusUI::update_level() {
|
||||
init();
|
||||
$ritual_ui.update_level(level);
|
||||
}
|
||||
|
||||
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||
auto& level = Game::current();
|
||||
auto& slot_name = $gui.name_for(gui_id);
|
||||
auto& inventory = $level.world->get<inventory::Model>($level.player);
|
||||
auto& inventory = level.world->get<inventory::Model>(level.player);
|
||||
|
||||
if(inventory.add(slot_name, world_entity)) {
|
||||
$level.world->make_constant(world_entity);
|
||||
level.world->make_constant(world_entity);
|
||||
update();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -133,23 +134,25 @@ namespace gui {
|
|||
|
||||
// NOTE: do I need this or how does it relate to drop_item?
|
||||
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
||||
auto player = Game::the_player();
|
||||
auto& slot_name = $gui.name_for(slot_id);
|
||||
System::remove_from_container(*$level.world, $level.player, slot_name);
|
||||
System::remove_from_container(player, slot_name);
|
||||
update();
|
||||
}
|
||||
|
||||
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
|
||||
if(gui_a != gui_b) {
|
||||
auto player = Game::the_player();
|
||||
auto& a_name = $gui.name_for(gui_a);
|
||||
auto& b_name = $gui.name_for(gui_b);
|
||||
System::inventory_swap($level.player, a_name, b_name);
|
||||
System::inventory_swap(player, a_name, b_name);
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
bool StatusUI::occupied(guecs::Entity slot) {
|
||||
auto player = $level.world->get_the<components::Player>();
|
||||
return System::inventory_occupied(player.entity, $gui.name_for(slot));
|
||||
auto player = Game::the_player();
|
||||
return System::inventory_occupied(player, $gui.name_for(slot));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue