diff --git a/events.hpp b/events.hpp index 892a8c5..99d25e0 100644 --- a/events.hpp +++ b/events.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 { diff --git a/gui/combat_ui.cpp b/gui/combat_ui.cpp index 495ffe7..096ec81 100644 --- a/gui/combat_ui.cpp +++ b/gui/combat_ui.cpp @@ -30,7 +30,7 @@ namespace gui { $gui.set(button, {sound}); $gui.set(button, {.duration=0.5f, .name=effect_name}); $gui.set(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(hp_gauge, {"stone_doll_cursed"}); $gui.set(hp_gauge, - guecs::make_action(*$level.world, Events::GUI::HP_STATUS, {})); + guecs::make_action($level, Events::GUI::HP_STATUS, {})); $gui.init(); } diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 7bd06e9..0111515 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -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(entity)) { auto gui_id = $loot_ui.$gui.entity("item_0"); diff --git a/gui/guecstra.cpp b/gui/guecstra.cpp index 5b32023..4b5e106 100644 --- a/gui/guecstra.cpp +++ b/gui/guecstra.cpp @@ -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(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(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(event, ent, data); + Clickable make_action(GameLevel& target, Events::GUI event, std::any data) { + return {[&, event, data](auto gui_id, auto){ + target.world->send(event, gui_id, data); }}; } diff --git a/gui/guecstra.hpp b/gui/guecstra.hpp index c96d6d2..49f0456 100644 --- a/gui/guecstra.hpp +++ b/gui/guecstra.hpp @@ -3,10 +3,11 @@ #include "events.hpp" #include #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; diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index a17bf18..2a2b19f 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -30,7 +30,7 @@ namespace gui { $gui.set(close, {}); $gui.set(close, {L"CLOSE"}); $gui.set(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(id, {0.4f, "ui_shader"}); $gui.set(id, { - guecs::make_action(*$level.world, Events::GUI::LOOT_SELECT, {id}) + guecs::make_action($level, Events::GUI::LOOT_SELECT, {id}) }); } diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 3ecbd76..5e0695e 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -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(pos); - } else { $needs_render = true; return std::nullopt; @@ -101,6 +104,7 @@ namespace gui { $compass_dir = 0; + $overlay_ui.update_level(level); dirty(); } diff --git a/gui/main_ui.hpp b/gui/main_ui.hpp index b78b79a..0d55604 100644 --- a/gui/main_ui.hpp +++ b/gui/main_ui.hpp @@ -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(); diff --git a/gui/overlay_ui.cpp b/gui/overlay_ui.cpp index 3a305e5..87016b8 100644 --- a/gui/overlay_ui.cpp +++ b/gui/overlay_ui.cpp @@ -1,4 +1,5 @@ #include "gui/overlay_ui.hpp" +#include "gui/guecstra.hpp" #include "constants.hpp" #include "events.hpp" #include @@ -17,6 +18,13 @@ namespace gui { void OverlayUI::init() { $gui.init(); + auto bottom = $gui.entity("bottom"); + $gui.set(bottom, { + [&](auto ent, auto data) { + $level.world->send( + 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