Refactored the mouse handling to use the new guecss Modifiers system and improved Clickable.
This commit is contained in:
parent
ad0069e899
commit
a86912705c
20 changed files with 67 additions and 64 deletions
|
@ -68,7 +68,7 @@ namespace gui {
|
|||
auto button = $status.entity(name);
|
||||
$status.set<Rectangle>(button, {});
|
||||
$status.set<Clickable>(button, {
|
||||
[this, name](auto, auto){
|
||||
[this, name](auto){
|
||||
dbc::log(fmt::format("STATUS: {}", name));
|
||||
}
|
||||
});
|
||||
|
@ -83,7 +83,7 @@ namespace gui {
|
|||
for(auto& [name, cell] : $overlay.cells()) {
|
||||
auto region = $overlay.entity(name);
|
||||
$overlay.set<Clickable>(region, {
|
||||
[this, name](auto, auto){
|
||||
[this, name](auto){
|
||||
dbc::log(fmt::format("OVERLAY: {}", name));
|
||||
}
|
||||
});
|
||||
|
@ -139,12 +139,12 @@ namespace gui {
|
|||
$overlay.render(window);
|
||||
}
|
||||
|
||||
bool BossFightUI::mouse(float x, float y, bool hover) {
|
||||
if($status.mouse(x, y, hover)) {
|
||||
bool BossFightUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
if($status.mouse(x, y, mods)) {
|
||||
dbc::log("STATUS button pressed");
|
||||
}
|
||||
|
||||
if($overlay.mouse(x, y, hover)) {
|
||||
if($overlay.mouse(x, y, mods)) {
|
||||
$animation.play();
|
||||
sound::play("Sword_Hit_1");
|
||||
$boss_hit = !$boss_hit;
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace gui {
|
|||
|
||||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void bounce_boss(sf::RenderWindow& window);
|
||||
bool boss_dead() { return $combat.hp < 0; }
|
||||
void configure_sprite();
|
||||
|
|
|
@ -31,7 +31,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, event, {action}));
|
||||
guecs::make_action($level, button, event, {action}));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
@ -67,7 +67,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, Events::GUI::HP_STATUS, {}));
|
||||
guecs::make_action($level, hp_gauge, Events::GUI::HP_STATUS, {}));
|
||||
|
||||
$gui.init();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ namespace gui {
|
|||
init();
|
||||
}
|
||||
|
||||
bool CombatUI::mouse(float x, float y, bool hover) {
|
||||
return $gui.mouse(x, y, hover);
|
||||
bool CombatUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $gui.mouse(x, y, mods);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace gui {
|
|||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
guecs::Entity make_button(std::string name, Events::GUI event,
|
||||
int action, const std::string &icon_name,
|
||||
const std::string &sound, const std::string &effect_name);
|
||||
|
|
|
@ -35,7 +35,9 @@ namespace gui {
|
|||
|
||||
void DebugUI::add_spawn_button(std::string enemy_key, std::string sprite_name, std::string region) {
|
||||
auto button = $gui.entity(region);
|
||||
$gui.set<guecs::Clickable>(button, { [this, enemy_key](auto, auto){ spawn(enemy_key); } });
|
||||
$gui.set<guecs::Clickable>(button, {
|
||||
[this, enemy_key](auto){ spawn(enemy_key); }
|
||||
});
|
||||
$gui.set<guecs::Sprite>(button, { sprite_name});
|
||||
}
|
||||
|
||||
|
@ -91,8 +93,8 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
bool DebugUI::mouse(float x, float y, bool hover) {
|
||||
return $gui.mouse(x, y, hover);
|
||||
bool DebugUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $gui.mouse(x, y, mods);
|
||||
}
|
||||
|
||||
Stats::TimeBullshit DebugUI::time_start() {
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace gui {
|
|||
|
||||
void init(lel::Cell cell);
|
||||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void debug();
|
||||
void spawn(const std::string& enemy_key);
|
||||
void add_spawn_button(std::string enemy_key, std::string sprite_name, std::string region);
|
||||
|
|
34
gui/fsm.cpp
34
gui/fsm.cpp
|
@ -124,7 +124,7 @@ namespace gui {
|
|||
case MOUSE_DRAG_START:
|
||||
case MOUSE_CLICK:
|
||||
case MOUSE_DROP:
|
||||
mouse_action(false);
|
||||
mouse_action(guecs::NO_MODS);
|
||||
break;
|
||||
default:
|
||||
if(!$dnd_loot.event(ev, data)) {
|
||||
|
@ -202,11 +202,11 @@ namespace gui {
|
|||
} break;
|
||||
case MOUSE_CLICK:
|
||||
fmt::println("CLICK: {}", $router.left_button);
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE:
|
||||
mouse_action(true);
|
||||
mouse_action(guecs::NO_MODS);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
mouse_action({1 << guecs::ModBit::hover});
|
||||
} break;
|
||||
case AIM_CLICK:
|
||||
System::pickup($level);
|
||||
break;
|
||||
|
@ -226,7 +226,7 @@ namespace gui {
|
|||
break;
|
||||
case MOUSE_CLICK: {
|
||||
sf::Vector2f pos = mouse_position();
|
||||
$boss_fight_ui->mouse(pos.x, pos.y, false);
|
||||
$boss_fight_ui->mouse(pos.x, pos.y, guecs::NO_MODS);
|
||||
|
||||
if($boss_fight_ui->boss_dead()) {
|
||||
event(Event::STAIRS_DOWN);
|
||||
|
@ -242,11 +242,11 @@ namespace gui {
|
|||
|
||||
switch(ev) {
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE:
|
||||
mouse_action(true);
|
||||
mouse_action(guecs::NO_MODS);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
mouse_action({1 << guecs::ModBit::hover});
|
||||
} break;
|
||||
case ATTACK:
|
||||
$main_ui.dirty();
|
||||
sound::play("Sword_Hit_1");
|
||||
|
@ -295,16 +295,16 @@ namespace gui {
|
|||
return $window.mapPixelToCoords($router.position);
|
||||
}
|
||||
|
||||
void FSM::mouse_action(bool hover) {
|
||||
void FSM::mouse_action(guecs::Modifiers mods) {
|
||||
sf::Vector2f pos = mouse_position();
|
||||
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, hover);
|
||||
$combat_ui.mouse(pos.x, pos.y, hover);
|
||||
$status_ui.mouse(pos.x, pos.y, hover);
|
||||
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, mods);
|
||||
$combat_ui.mouse(pos.x, pos.y, mods);
|
||||
$status_ui.mouse(pos.x, pos.y, mods);
|
||||
|
||||
if($loot_ui.active) {
|
||||
$loot_ui.mouse(pos.x, pos.y, hover);
|
||||
$loot_ui.mouse(pos.x, pos.y, mods);
|
||||
} else {
|
||||
$main_ui.mouse(pos.x, pos.y, hover);
|
||||
$main_ui.mouse(pos.x, pos.y, mods);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,6 +444,8 @@ namespace gui {
|
|||
auto [evt, entity, data] = world.recv<eGUI>();
|
||||
auto player = world.get_the<Player>();
|
||||
|
||||
// HERE: this has to go, unify these events and just use them in the state machine directly
|
||||
|
||||
switch(evt) {
|
||||
case eGUI::COMBAT: {
|
||||
auto &damage = std::any_cast<Events::Combat&>(data);
|
||||
|
|
|
@ -70,7 +70,7 @@ namespace gui {
|
|||
|
||||
void try_move(int dir, bool strafe);
|
||||
sf::Vector2f mouse_position();
|
||||
void mouse_action(bool hover);
|
||||
void mouse_action(guecs::Modifiers mods);
|
||||
void handle_keyboard_mouse();
|
||||
void draw_gui();
|
||||
void render();
|
||||
|
|
|
@ -2,15 +2,14 @@
|
|||
|
||||
namespace guecs {
|
||||
|
||||
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(GameLevel& target, guecs::Entity gui_id, Events::GUI event) {
|
||||
return {[&, gui_id, event](auto){
|
||||
target.world->send<Events::GUI>(event, gui_id, {});
|
||||
}};
|
||||
}
|
||||
|
||||
Clickable make_action(GameLevel& target, Events::GUI event, std::any data) {
|
||||
return {[&, event, data](auto gui_id, auto){
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event, std::any data) {
|
||||
return {[&, event, data](auto){
|
||||
target.world->send<Events::GUI>(event, gui_id, data);
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "levelmanager.hpp"
|
||||
|
||||
namespace guecs {
|
||||
Clickable make_action(GameLevel& target, Events::GUI event);
|
||||
Clickable make_action(GameLevel& target, Events::GUI event, std::any data);
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event);
|
||||
Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event, std::any data);
|
||||
|
||||
struct GrabSource {
|
||||
DinkyECS::Entity world_entity;
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace gui {
|
|||
$gui.set<guecs::Rectangle>(button, {});
|
||||
$gui.set<guecs::Text>(button, {label});
|
||||
$gui.set<guecs::Clickable>(button,
|
||||
guecs::make_action($level, event));
|
||||
guecs::make_action($level, button, event));
|
||||
}
|
||||
|
||||
void LootUI::init() {
|
||||
|
@ -52,7 +52,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, Events::GUI::LOOT_SELECT, {id})
|
||||
guecs::make_action($level, id, Events::GUI::LOOT_SELECT, {id})
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -132,8 +132,8 @@ namespace gui {
|
|||
update();
|
||||
}
|
||||
|
||||
bool LootUI::mouse(float x, float y, bool hover) {
|
||||
return $gui.mouse(x, y, hover);
|
||||
bool LootUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $gui.mouse(x, y, mods);
|
||||
}
|
||||
|
||||
bool LootUI::occupied(guecs::Entity slot) {
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace gui {
|
|||
void update();
|
||||
void render(sf::RenderWindow& window);
|
||||
void update_level(GameLevel &level);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void make_button(const std::string &name, const std::wstring& label, Events::GUI event);
|
||||
|
||||
void remove_slot(guecs::Entity slot_id);
|
||||
|
|
|
@ -112,7 +112,7 @@ namespace gui {
|
|||
dirty();
|
||||
}
|
||||
|
||||
void MainUI::mouse(int x, int y, bool hover) {
|
||||
$overlay_ui.$gui.mouse(x, y, hover);
|
||||
void MainUI::mouse(int x, int y, guecs::Modifiers mods) {
|
||||
$overlay_ui.$gui.mouse(x, y, mods);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace gui {
|
|||
|
||||
MainUI(sf::RenderWindow& window);
|
||||
|
||||
void mouse(int x, int y, bool hover);
|
||||
void mouse(int x, int y, guecs::Modifiers mods);
|
||||
void debug();
|
||||
void render_debug();
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ namespace gui {
|
|||
auto area = gui.entity(name);
|
||||
|
||||
gui.set<Clickable>(area, {
|
||||
[&](auto ent, auto data) {
|
||||
level.world->send<Events::GUI>(Events::GUI::AIM_CLICK, ent, data);
|
||||
[&](auto) {
|
||||
level.world->send<Events::GUI>(Events::GUI::AIM_CLICK, area, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace gui {
|
|||
|
||||
auto open_close_toggle = $gui.entity("ritual_ui");
|
||||
$gui.set<Clickable>(open_close_toggle, {
|
||||
[&](auto, auto){ event(Event::TOGGLE); }
|
||||
[&](auto){ event(Event::TOGGLE); }
|
||||
});
|
||||
|
||||
|
||||
|
@ -110,8 +110,8 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
bool UI::mouse(float x, float y, bool hover) {
|
||||
return $gui.mouse(x, y, hover);
|
||||
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
return $gui.mouse(x, y, mods);
|
||||
}
|
||||
|
||||
bool UI::is_open() {
|
||||
|
@ -172,7 +172,7 @@ namespace gui {
|
|||
|
||||
$gui.set_init<Sprite>(slot_id, {item});
|
||||
$gui.set<Clickable>(slot_id, {
|
||||
[&, slot_id, item_id](auto, auto) {
|
||||
[&, slot_id, item_id](auto) {
|
||||
auto data = std::make_any<SelectedItem>(slot_id, item_id);
|
||||
event(Event::SELECT, data);
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ namespace gui {
|
|||
}
|
||||
|
||||
$gui.set<Clickable>(combine, {
|
||||
[&](auto, auto){ event(Event::COMBINE); }
|
||||
[&](auto){ event(Event::COMBINE); }
|
||||
});
|
||||
} else {
|
||||
$gui.show_text("result_text", L"That won't work.");
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace gui {
|
|||
void OPENING(Event);
|
||||
void CLOSING(Event);
|
||||
|
||||
bool mouse(float x, float y, bool hover);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void render(sf::RenderWindow &window);
|
||||
bool is_open();
|
||||
void load_blanket();
|
||||
|
|
|
@ -35,17 +35,17 @@ namespace gui {
|
|||
$gui.set<Sprite>(gui_id, {"armored_knight"});
|
||||
} else {
|
||||
$gui.set<Rectangle>(gui_id, {});
|
||||
$gui.set<ActionData>(gui_id, {make_any<string>(name)});
|
||||
dbc::log("!!!!!!!!!!!!!!!!! is this used: $gui.set<ActionData>(gui_id, {make_any<string>(name)});");
|
||||
|
||||
if(name == "ritual_ui") {
|
||||
$gui.set<Clickable>(gui_id, {
|
||||
[this](auto, auto){ select_ritual(); }
|
||||
[this](auto){ select_ritual(); }
|
||||
});
|
||||
$gui.set<Sound>(gui_id, {"pickup"});
|
||||
} else {
|
||||
$gui.set<Text>(gui_id, {guecs::to_wstring(name)});
|
||||
$gui.set<Clickable>(gui_id, {
|
||||
guecs::make_action($level, Events::GUI::INV_SELECT, {gui_id})
|
||||
guecs::make_action($level, gui_id, Events::GUI::INV_SELECT, {gui_id})
|
||||
});
|
||||
$gui.set<DropTarget>(gui_id, {
|
||||
.commit=[&, gui_id](DinkyECS::Entity world_target) -> bool {
|
||||
|
@ -61,11 +61,11 @@ namespace gui {
|
|||
update();
|
||||
}
|
||||
|
||||
bool StatusUI::mouse(float x, float y, bool hover) {
|
||||
bool StatusUI::mouse(float x, float y, guecs::Modifiers mods) {
|
||||
if($ritual_ui.is_open()) {
|
||||
return $ritual_ui.mouse(x, y, hover);
|
||||
return $ritual_ui.mouse(x, y, mods);
|
||||
} else {
|
||||
return $gui.mouse(x, y, hover);
|
||||
return $gui.mouse(x, y, mods);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace gui {
|
|||
void init();
|
||||
void render(sf::RenderWindow &window);
|
||||
void update();
|
||||
bool mouse(float x, float y, bool hover);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
|
||||
void remove_slot(guecs::Entity slot_id);
|
||||
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[wrap-git]
|
||||
directory=lel-guecs-0.5.0
|
||||
directory=lel-guecs-0.6.0
|
||||
url=https://git.learnjsthehardway.com/learn-code-the-hard-way/lel-guecs.git
|
||||
revision=HEAD
|
||||
depth=1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue