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.
This commit is contained in:
parent
2458f01ebd
commit
2aa4f0a2e8
13 changed files with 78 additions and 43 deletions
|
@ -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);
|
||||
} else {
|
||||
$rayview.aiming_at = 0;
|
||||
}
|
||||
|
||||
if($level.collision->occupied(aimed_at)) {
|
||||
return $level.collision->get(aimed_at);
|
||||
} else {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue