Now items drop where you aim, and won't let you drop on a floor. But maybe one more change.
This commit is contained in:
parent
23ead1f0ca
commit
1788b8fb28
3 changed files with 21 additions and 41 deletions
|
@ -112,8 +112,7 @@ namespace gui {
|
||||||
case AIM_CLICK: {
|
case AIM_CLICK: {
|
||||||
// take from inventory, drop on floor
|
// take from inventory, drop on floor
|
||||||
bool worked = throw_on_floor($status_ui.$gui, true);
|
bool worked = throw_on_floor($status_ui.$gui, true);
|
||||||
dbc::check(worked, "Need to fix this, should be able to abort.");
|
if(worked) END(CLOSE);
|
||||||
END(CLOSE);
|
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT: {
|
case INV_SELECT: {
|
||||||
auto drop_id = std::any_cast<guecs::Entity>(data);
|
auto drop_id = std::any_cast<guecs::Entity>(data);
|
||||||
|
@ -139,8 +138,7 @@ namespace gui {
|
||||||
case AIM_CLICK: {
|
case AIM_CLICK: {
|
||||||
// THIS IS PUT IT BACK ON THE FLOOR
|
// THIS IS PUT IT BACK ON THE FLOOR
|
||||||
bool worked = throw_on_floor($loot_ui.$gui, false);
|
bool worked = throw_on_floor($loot_ui.$gui, false);
|
||||||
dbc::check(worked, "Failed to drop it back on the floor.");
|
if(worked) END(CLOSE);
|
||||||
END(CLOSE);
|
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
handle_mouse(ev, $loot_ui.$gui);
|
handle_mouse(ev, $loot_ui.$gui);
|
||||||
|
@ -196,7 +194,6 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DNDLoot::clear_grab() {
|
void DNDLoot::clear_grab() {
|
||||||
dbc::log("CLEARED!");
|
|
||||||
$grab_source = std::nullopt;
|
$grab_source = std::nullopt;
|
||||||
$grab_sprite = nullptr;
|
$grab_sprite = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +288,6 @@ namespace gui {
|
||||||
"StatusUI doesn't actually have that GrabSource in the gui.");
|
"StatusUI doesn't actually have that GrabSource in the gui.");
|
||||||
|
|
||||||
auto& grab = gui.get<guecs::GrabSource>(*$grab_source);
|
auto& grab = gui.get<guecs::GrabSource>(*$grab_source);
|
||||||
grab.commit();
|
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
@ -301,7 +297,11 @@ namespace gui {
|
||||||
result = $loot_ui.drop_item(grab.world_entity);
|
result = $loot_ui.drop_item(grab.world_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_grab();
|
if(result) {
|
||||||
|
grab.commit();
|
||||||
|
clear_grab();
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,7 @@ namespace gui {
|
||||||
|
|
||||||
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||||
auto& slot_name = $gui.name_for(gui_id);
|
auto& slot_name = $gui.name_for(gui_id);
|
||||||
auto player = $level.world->get_the<components::Player>();
|
auto& inventory = $level.world->get<inventory::Model>($level.player);
|
||||||
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
|
||||||
|
|
||||||
if(inventory.add(slot_name, world_entity)) {
|
if(inventory.add(slot_name, world_entity)) {
|
||||||
$level.world->make_constant(world_entity);
|
$level.world->make_constant(world_entity);
|
||||||
|
@ -123,18 +122,8 @@ namespace gui {
|
||||||
|
|
||||||
// NOTE: do I need this or how does it relate to drop_item?
|
// NOTE: do I need this or how does it relate to drop_item?
|
||||||
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
||||||
// NOTE: really the System should coordinate either dropping on the
|
|
||||||
// ground or moving from one container or another, so when loot_ui
|
|
||||||
// moves to use an ECS id to a container I can have the System
|
|
||||||
// do it.
|
|
||||||
auto& slot_name = $gui.name_for(slot_id);
|
auto& slot_name = $gui.name_for(slot_id);
|
||||||
|
System::remove_from_container(*$level.world, $level.player, slot_name);
|
||||||
auto player = $level.world->get_the<components::Player>();
|
|
||||||
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
|
||||||
|
|
||||||
auto world_entity = inventory.get(slot_name);
|
|
||||||
inventory.remove(world_entity);
|
|
||||||
|
|
||||||
$gui.remove<guecs::GrabSource>(slot_id);
|
$gui.remove<guecs::GrabSource>(slot_id);
|
||||||
$gui.remove<guecs::Icon>(slot_id);
|
$gui.remove<guecs::Icon>(slot_id);
|
||||||
}
|
}
|
||||||
|
@ -143,8 +132,7 @@ namespace gui {
|
||||||
if(gui_a != gui_b) {
|
if(gui_a != gui_b) {
|
||||||
auto& a_name = $gui.name_for(gui_a);
|
auto& a_name = $gui.name_for(gui_a);
|
||||||
auto& b_name = $gui.name_for(gui_b);
|
auto& b_name = $gui.name_for(gui_b);
|
||||||
auto player = $level.world->get_the<components::Player>();
|
System::inventory_swap($level, $level.player, a_name, b_name);
|
||||||
System::inventory_swap($level, player.entity, a_name, b_name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
30
systems.cpp
30
systems.cpp
|
@ -444,30 +444,22 @@ bool System::drop_item(GameLevel& level, Entity item) {
|
||||||
auto& map = *level.map;
|
auto& map = *level.map;
|
||||||
auto& collision = *level.collision;
|
auto& collision = *level.collision;
|
||||||
|
|
||||||
auto player = world.get_the<Player>();
|
auto player_pos = world.get<Position>(level.player);
|
||||||
auto player_pos = world.get<Position>(player.entity);
|
|
||||||
auto& player_inv = world.get<inventory::Model>(player.entity);
|
|
||||||
|
|
||||||
// doesn't compass already avoid walls?
|
Position pos{player_pos.aiming_at.x, player_pos.aiming_at.y};
|
||||||
for(matrix::box it{map.walls(), player_pos.location.x, player_pos.location.y, 1}; it.next();)
|
|
||||||
{
|
|
||||||
Position pos{it.x, it.y};
|
|
||||||
|
|
||||||
if(map.can_move(pos.location) && !collision.occupied(pos.location)) {
|
if(map.can_move(pos.location)) {
|
||||||
world.set<Position>(item, pos);
|
world.set<Position>(item, pos);
|
||||||
collision.insert(pos.location, item, false);
|
collision.insert(pos.location, item, false);
|
||||||
// BUG: really there should be another system that handles loot->inv moves
|
level.world->not_constant(item);
|
||||||
if(player_inv.has(item)) player_inv.remove(item);
|
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, item, {});
|
||||||
level.world->send<Events::GUI>(Events::GUI::ENTITY_SPAWN, item, {});
|
return true;
|
||||||
level.world->not_constant(item);
|
} else {
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: I tink pickup and this need to be different
|
// NOTE: I think pickup and this need to be different
|
||||||
bool System::place_in_container(World& world, Entity cont_id, const std::string& name, Entity world_entity) {
|
bool System::place_in_container(World& world, Entity cont_id, const std::string& name, Entity world_entity) {
|
||||||
auto& container = world.get<inventory::Model>(cont_id);
|
auto& container = world.get<inventory::Model>(cont_id);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue