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.

master
Zed A. Shaw 1 day ago
parent 68e50342e5
commit 119b3ed11d
  1. 2
      gui/dnd_loot.cpp
  2. 11
      gui/fsm.cpp
  3. 1
      gui/fsm.hpp
  4. 9
      gui/status_ui.cpp
  5. 7
      gui/status_ui.hpp
  6. 32
      systems.cpp
  7. 2
      systems.hpp

@ -114,6 +114,8 @@ namespace gui {
case MOUSE_DROP: { case MOUSE_DROP: {
auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source); auto& grab = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
grab.commit(); grab.commit();
bool dropped = $status_ui.drop_item(grab.world_entity);
dbc::check(dropped, "DROP FAILED!");
END(Event::CLOSE); END(Event::CLOSE);
} break; } break;
default: default:

@ -68,6 +68,8 @@ namespace gui {
$mini_map.init($main_ui.$overlay_ui.$gui); $mini_map.init($main_ui.$overlay_ui.$gui);
run_systems(); run_systems();
this_crap_must_die();
state(State::IDLE); state(State::IDLE);
} }
@ -430,7 +432,8 @@ namespace gui {
event(Event::START_COMBAT); event(Event::START_COMBAT);
break; break;
case eGUI::ENEMY_SPAWN: case eGUI::ENEMY_SPAWN:
$main_ui.update_level($level); $main_ui.$rayview.update_level($level);
$main_ui.dirty();
run_systems(); run_systems();
break; break;
case eGUI::NO_NEIGHBORS: case eGUI::NO_NEIGHBORS:
@ -514,4 +517,10 @@ namespace gui {
run_systems(); 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 handle_world_events();
void next_level(); void next_level();
void debug_render(); void debug_render();
void this_crap_must_die();
}; };
} }

@ -4,6 +4,7 @@
#include "rand.hpp" #include "rand.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>
#include "gui/guecstra.hpp" #include "gui/guecstra.hpp"
#include "systems.hpp"
namespace gui { namespace gui {
using namespace guecs; using namespace guecs;
@ -85,7 +86,7 @@ namespace gui {
init(); 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)) { if($level.world->has<components::Sprite>(world_entity)) {
auto& sprite = $level.world->get<components::Sprite>(world_entity); auto& sprite = $level.world->get<components::Sprite>(world_entity);
$gui.set_init<guecs::Sprite>(gui_id, {sprite.name}); $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)) { if(contents.contains(slot_id)) {
contents.erase(slot_id); contents.erase(slot_id);
$gui.remove<guecs::GrabSource>(slot_id); $gui.remove<guecs::GrabSource>(slot_id);

@ -12,7 +12,7 @@ namespace gui {
public: public:
guecs::UI $gui; guecs::UI $gui;
GameLevel $level; GameLevel $level;
std::unordered_map<DinkyECS::Entity, DinkyECS::Entity> contents; std::unordered_map<guecs::Entity, DinkyECS::Entity> contents;
ritual::UI $ritual_ui; ritual::UI $ritual_ui;
StatusUI(GameLevel level); StatusUI(GameLevel level);
@ -23,7 +23,8 @@ namespace gui {
void update(); void update();
bool mouse(float x, float y, bool hover); bool mouse(float x, float y, bool hover);
void remove_slot(DinkyECS::Entity slot_id); void remove_slot(guecs::Entity slot_id);
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity); bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
bool drop_item(DinkyECS::Entity item_id);
}; };
} }

@ -460,3 +460,35 @@ std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::En
return nullptr; 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 device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item);
void plan_motion(DinkyECS::World& world, Point move_to); 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); 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 enemy_ai(GameLevel &level);
void combat(GameLevel &level, int attack_id); void combat(GameLevel &level, int attack_id);

Loading…
Cancel
Save