Can now drag an item out of inventory and drop on the ground, then pick it back up, and put it in a loot container, and then back again. Still buggy but working for now.
This commit is contained in:
parent
68e50342e5
commit
119b3ed11d
7 changed files with 58 additions and 6 deletions
|
@ -114,6 +114,8 @@ namespace gui {
|
|||
case MOUSE_DROP: {
|
||||
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
grab.commit();
|
||||
bool dropped = $status_ui.drop_item(grab.world_entity);
|
||||
dbc::check(dropped, "DROP FAILED!");
|
||||
END(Event::CLOSE);
|
||||
} break;
|
||||
default:
|
||||
|
|
11
gui/fsm.cpp
11
gui/fsm.cpp
|
@ -68,6 +68,8 @@ namespace gui {
|
|||
$mini_map.init($main_ui.$overlay_ui.$gui);
|
||||
|
||||
run_systems();
|
||||
|
||||
this_crap_must_die();
|
||||
state(State::IDLE);
|
||||
}
|
||||
|
||||
|
@ -430,7 +432,8 @@ namespace gui {
|
|||
event(Event::START_COMBAT);
|
||||
break;
|
||||
case eGUI::ENEMY_SPAWN:
|
||||
$main_ui.update_level($level);
|
||||
$main_ui.$rayview.update_level($level);
|
||||
$main_ui.dirty();
|
||||
run_systems();
|
||||
break;
|
||||
case eGUI::NO_NEIGHBORS:
|
||||
|
@ -514,4 +517,10 @@ namespace gui {
|
|||
|
||||
run_systems();
|
||||
}
|
||||
|
||||
void FSM::this_crap_must_die() {
|
||||
auto torch_id = System::spawn_item($level, "TORCH_BAD");
|
||||
auto hand_l = $status_ui.$gui.entity("hand_l");
|
||||
$status_ui.place_slot(hand_l, torch_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,5 +79,6 @@ namespace gui {
|
|||
void handle_world_events();
|
||||
void next_level();
|
||||
void debug_render();
|
||||
void this_crap_must_die();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "rand.hpp"
|
||||
#include <fmt/xchar.h>
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "systems.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace guecs;
|
||||
|
@ -85,7 +86,7 @@ namespace gui {
|
|||
init();
|
||||
}
|
||||
|
||||
bool StatusUI::place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||
if($level.world->has<components::Sprite>(world_entity)) {
|
||||
auto& sprite = $level.world->get<components::Sprite>(world_entity);
|
||||
$gui.set_init<guecs::Sprite>(gui_id, {sprite.name});
|
||||
|
@ -101,7 +102,11 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void StatusUI::remove_slot(DinkyECS::Entity slot_id) {
|
||||
bool StatusUI::drop_item(DinkyECS::Entity item_id) {
|
||||
return System::drop_item($level, item_id);
|
||||
}
|
||||
|
||||
void StatusUI::remove_slot(guecs::Entity slot_id) {
|
||||
if(contents.contains(slot_id)) {
|
||||
contents.erase(slot_id);
|
||||
$gui.remove<guecs::GrabSource>(slot_id);
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace gui {
|
|||
public:
|
||||
guecs::UI $gui;
|
||||
GameLevel $level;
|
||||
std::unordered_map<DinkyECS::Entity, DinkyECS::Entity> contents;
|
||||
std::unordered_map<guecs::Entity, DinkyECS::Entity> contents;
|
||||
ritual::UI $ritual_ui;
|
||||
|
||||
StatusUI(GameLevel level);
|
||||
|
@ -23,7 +23,8 @@ namespace gui {
|
|||
void update();
|
||||
bool mouse(float x, float y, bool hover);
|
||||
|
||||
void remove_slot(DinkyECS::Entity slot_id);
|
||||
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
||||
void remove_slot(guecs::Entity slot_id);
|
||||
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
||||
bool drop_item(DinkyECS::Entity item_id);
|
||||
};
|
||||
}
|
||||
|
|
32
systems.cpp
32
systems.cpp
|
@ -460,3 +460,35 @@ std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::En
|
|||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
DinkyECS::Entity System::spawn_item(GameLevel& level, const std::string& name) {
|
||||
Config config("assets/items.json");
|
||||
auto& item_config = config[name];
|
||||
auto item_id = level.world->entity();
|
||||
level.world->set<InventoryItem>(item_id, {1, item_config});
|
||||
components::configure_entity(*level.world, item_id, item_config["components"]);
|
||||
|
||||
return item_id;
|
||||
}
|
||||
|
||||
bool System::drop_item(GameLevel& level, DinkyECS::Entity item) {
|
||||
auto& world = *level.world;
|
||||
auto& map = *level.map;
|
||||
auto& collision = *level.collision;
|
||||
|
||||
auto player = world.get_the<Player>();
|
||||
auto player_pos = world.get<Position>(player.entity);
|
||||
|
||||
// doesn't compass already avoid walls?
|
||||
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)) {
|
||||
world.set<Position>(item, pos);
|
||||
collision.insert(pos.location, item);
|
||||
level.world->send<Events::GUI>(Events::GUI::ENEMY_SPAWN, item, {});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ namespace System {
|
|||
void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
|
||||
void plan_motion(DinkyECS::World& world, Point move_to);
|
||||
std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir);
|
||||
DinkyECS::Entity spawn_item(GameLevel& level, const std::string& name);
|
||||
bool drop_item(GameLevel& level, DinkyECS::Entity item);
|
||||
|
||||
void enemy_ai(GameLevel &level);
|
||||
void combat(GameLevel &level, int attack_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue