Finally can pick things up, but it's really bad so far. Need a bunch of refactoring in how the collision system works, and make it so collision and maps can have multiple entities in the same square.

master
Zed A. Shaw 11 months ago
parent 2458f01ebd
commit 2aa4f0a2e8
  1. 2
      events.hpp
  2. 4
      gui/combat_ui.cpp
  3. 8
      gui/fsm.cpp
  4. 19
      gui/guecstra.cpp
  5. 5
      gui/guecstra.hpp
  6. 4
      gui/loot_ui.cpp
  7. 12
      gui/main_ui.cpp
  8. 1
      gui/main_ui.hpp
  9. 13
      gui/overlay_ui.cpp
  10. 4
      gui/overlay_ui.hpp
  11. 4
      gui/status_ui.cpp
  12. 30
      systems.cpp
  13. 1
      systems.hpp

@ -6,7 +6,7 @@ namespace Events {
COMBAT_START, NO_NEIGHBORS, HP_STATUS,
ATTACK, BLOCK, EVADE, NEW_RITUAL,
UPDATE_SPRITE, ENEMY_SPAWN, NOOP,
LOOT_CLOSE, LOOT_SELECT, INV_SELECT
LOOT_CLOSE, LOOT_SELECT, INV_SELECT, AIM_CLICK
};
struct Combat {

@ -30,7 +30,7 @@ namespace gui {
$gui.set<Sound>(button, {sound});
$gui.set<Effect>(button, {.duration=0.5f, .name=effect_name});
$gui.set<Clickable>(button,
guecs::make_action(*$level.world, event, {action}));
guecs::make_action($level, event, {action}));
return button;
}
@ -66,7 +66,7 @@ namespace gui {
auto hp_gauge = $gui.entity("hp_gauge");
$gui.set<Sprite>(hp_gauge, {"stone_doll_cursed"});
$gui.set<Clickable>(hp_gauge,
guecs::make_action(*$level.world, Events::GUI::HP_STATUS, {}));
guecs::make_action($level, Events::GUI::HP_STATUS, {}));
$gui.init();
}

@ -567,6 +567,14 @@ namespace gui {
case eGUI::INV_SELECT:
event(Event::INV_SELECT, data);
break;
case eGUI::AIM_CLICK:
if(auto aimed_at = $main_ui.camera_aim()) {
dbc::log("clicked on a thing");
System::pickup($level, aimed_at);
} else {
dbc::log("there's no thing there!");
}
break;
case eGUI::LOOT: {
if(world.has<components::InventoryItem>(entity)) {
auto gui_id = $loot_ui.$gui.entity("item_0");

@ -2,21 +2,16 @@
namespace guecs {
Clickable make_action(DinkyECS::World& target, Events::GUI event) {
return {[&, event](auto ent, auto data){
// BUG: I think entityt here shifted and isn't part of the world anymore
// BUG: it's actually coming from the GUI so passing it here is wrong
// remember that ent is passed in from the UI::mouse handler
target.send<Events::GUI>(event, ent, data);
Clickable make_action(GameLevel& target, Events::GUI event) {
return {[&, event](auto gui_id, auto data){
// BUG: either get rid of gui_id or also send a reference the the $gui that is sending the event
target.world->send<Events::GUI>(event, gui_id, data);
}};
}
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data) {
return {[&, event, data](auto ent, auto){
// BUG: I think entityt here shifted and isn't part of the world anymore
// BUG: it's actually coming from the GUI so passing it here is wrong
// remember that ent is passed in from the UI::mouse handler
target.send<Events::GUI>(event, ent, data);
Clickable make_action(GameLevel& target, Events::GUI event, std::any data) {
return {[&, event, data](auto gui_id, auto){
target.world->send<Events::GUI>(event, gui_id, data);
}};
}

@ -3,10 +3,11 @@
#include "events.hpp"
#include <guecs/ui.hpp>
#include "textures.hpp"
#include "levelmanager.hpp"
namespace guecs {
Clickable make_action(DinkyECS::World& target, Events::GUI event);
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
Clickable make_action(GameLevel& target, Events::GUI event);
Clickable make_action(GameLevel& target, Events::GUI event, std::any data);
struct GrabSource {
DinkyECS::Entity world_entity;

@ -30,7 +30,7 @@ namespace gui {
$gui.set<guecs::Rectangle>(close, {});
$gui.set<guecs::Label>(close, {L"CLOSE"});
$gui.set<guecs::Clickable>(close,
guecs::make_action(*$level.world, Events::GUI::LOOT_CLOSE));
guecs::make_action($level, Events::GUI::LOOT_CLOSE));
for(int i = 0; i < INV_SLOTS; i++) {
auto id = $gui.entity("item_", i);
@ -38,7 +38,7 @@ namespace gui {
THEME.TRANSPARENT, THEME.LIGHT_MID });
$gui.set<guecs::Effect>(id, {0.4f, "ui_shader"});
$gui.set<guecs::Clickable>(id, {
guecs::make_action(*$level.world, Events::GUI::LOOT_SELECT, {id})
guecs::make_action($level, Events::GUI::LOOT_SELECT, {id})
});
}

@ -31,14 +31,18 @@ namespace gui {
$overlay_ui.init();
}
void MainUI::render() {
DinkyECS::Entity MainUI::camera_aim() {
auto aimed_at = $camera.aimed_at();
if($level.collision->occupied(aimed_at)) {
$rayview.aiming_at = $level.collision->get(aimed_at);
return $level.collision->get(aimed_at);
} else {
$rayview.aiming_at = 0;
return 0;
}
}
void MainUI::render() {
$rayview.aiming_at = camera_aim();
if($needs_render) $rayview.render();
$rayview.draw($window);
@ -64,7 +68,6 @@ namespace gui {
size_t($camera.target_x),
size_t($camera.target_y)};
return std::make_optional<Point>(pos);
} else {
$needs_render = true;
return std::nullopt;
@ -101,6 +104,7 @@ namespace gui {
$compass_dir = 0;
$overlay_ui.update_level(level);
dirty();
}

@ -35,6 +35,7 @@ namespace gui {
Point plan_move(int dir, bool strafe);
void abort_plan();
void update_level(GameLevel level);
DinkyECS::Entity camera_aim();
void init();
void render();

@ -1,4 +1,5 @@
#include "gui/overlay_ui.hpp"
#include "gui/guecstra.hpp"
#include "constants.hpp"
#include "events.hpp"
#include <optional>
@ -17,6 +18,13 @@ namespace gui {
void OverlayUI::init() {
$gui.init();
auto bottom = $gui.entity("bottom");
$gui.set<Clickable>(bottom, {
[&](auto ent, auto data) {
$level.world->send<Events::GUI>(
Events::GUI::AIM_CLICK, ent, data);
}
});
}
void OverlayUI::render(sf::RenderWindow& window) {
@ -47,4 +55,9 @@ namespace gui {
void OverlayUI::close_label(string region) {
$gui.close<Label>(region);
}
void OverlayUI::update_level(GameLevel level) {
$level = level;
// BUG: I think I have to redo the clickable
}
}

@ -2,6 +2,7 @@
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Font.hpp>
#include <guecs/ui.hpp>
#include "levelmanager.hpp"
namespace gui {
using std::string;
@ -9,10 +10,13 @@ namespace gui {
class OverlayUI {
public:
guecs::UI $gui;
GameLevel $level;
OverlayUI();
void init();
void update_level(GameLevel level);
void render(sf::RenderWindow& window);
void show_sprite(string region, string sprite_name);
void close_sprite(string region);

@ -15,7 +15,7 @@ namespace gui {
$gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT);
$gui.layout(
"[ritual_ui]"
"[earing|armor_head|amulet]"
"[earring|armor_head|amulet]"
"[back|*%(200,300)character_view|_|armor_bdy]"
"[hand_r|_|_ |hand_l]"
"[ring_r|_|_ |ring_l]"
@ -43,7 +43,7 @@ namespace gui {
} else {
$gui.set<Textual>(button, {guecs::to_wstring(name)});
$gui.set<Clickable>(button, {
guecs::make_action(*$level.world, Events::GUI::INV_SELECT, {button})
guecs::make_action($level, Events::GUI::INV_SELECT, {button})
});
$gui.set<DropTarget>(button, {
.commit=[&, button](DinkyECS::Entity world_target) -> bool {

@ -302,6 +302,24 @@ void System::collision(GameLevel &level) {
world.send<Events::GUI>(Events::GUI::COMBAT_START, entity, entity);
}
} else if(world.has<InventoryItem>(entity)) {
dbc::log("Hit an inventory item, use Sysem::pickup?");
} else if(world.has<Device>(entity)) {
System::device(world, player.entity, entity);
} else {
dbc::log(fmt::format("UNKNOWN COLLISION TYPE {}", entity));
}
}
if(combat_count == 0) {
// BUG: this is probably how we get stuck in combat
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, player.entity, player.entity);
}
}
void System::pickup(GameLevel &level, DinkyECS::Entity entity) {
auto &world = *level.world;
if(world.has<InventoryItem>(entity)) {
auto item = world.get<InventoryItem>(entity);
auto& item_pos = world.get<Position>(entity);
@ -314,19 +332,9 @@ void System::collision(GameLevel &level) {
}
}
collider.remove(item_pos.location);
level.collision->remove(item_pos.location);
world.remove<Tile>(entity);
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
} else if(world.has<Device>(entity)) {
System::device(world, player.entity, entity);
} else {
dbc::log(fmt::format("UNKNOWN COLLISION TYPE {}", entity));
}
}
if(combat_count == 0) {
// BUG: this is probably how we get stuck in combat
world.send<Events::GUI>(Events::GUI::NO_NEIGHBORS, player.entity, player.entity);
}
}

@ -26,4 +26,5 @@ namespace System {
void player_status(GameLevel &level);
void distribute_loot(DinkyECS::World &world, DinkyECS::Entity& ent, nlohmann::json& entity_data);
void pickup(GameLevel &level, DinkyECS::Entity entity);
}