There's a UISystem now for to compliment the entities and components in GUECS. I now use that to do the drag/drop transfers instead of raw code right in the FSM.
This commit is contained in:
parent
e01e697535
commit
4a48910273
11 changed files with 62 additions and 60 deletions
47
gui/fsm.cpp
47
gui/fsm.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include "systems.hpp"
|
#include "systems.hpp"
|
||||||
|
#include "gui/uisystems.hpp"
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
#include "sound.hpp"
|
#include "sound.hpp"
|
||||||
#include "shaders.hpp"
|
#include "shaders.hpp"
|
||||||
|
@ -133,23 +134,19 @@ namespace gui {
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT: {
|
||||||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||||
auto& source = $loot_ui.get_grab_source(*$grab_source);
|
$grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
|
||||||
source.grab();
|
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT: {
|
case INV_SELECT: {
|
||||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
|
||||||
|
|
||||||
if($grab_source) {
|
if($grab_source) {
|
||||||
auto& drop = $status_ui.get_drop_target(gui_id);
|
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||||
auto& grab = $loot_ui.get_grab_source(*$grab_source);
|
bool dropped = UISystem::loot_drop(
|
||||||
|
$loot_ui.$gui, $status_ui.$gui,
|
||||||
|
*$grab_source, gui_id);
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(dropped) {
|
||||||
grab.commit();
|
state(State::LOOTING);
|
||||||
$grab_source = std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state(State::LOOTING);
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
|
@ -158,7 +155,7 @@ namespace gui {
|
||||||
case MOUSE_DRAG:
|
case MOUSE_DRAG:
|
||||||
case MOUSE_MOVE: {
|
case MOUSE_MOVE: {
|
||||||
if($grab_source) {
|
if($grab_source) {
|
||||||
auto& source = $loot_ui.get_grab_source(*$grab_source);
|
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||||
source.move($router.position);
|
source.move($router.position);
|
||||||
}
|
}
|
||||||
mouse_action(true);
|
mouse_action(true);
|
||||||
|
@ -186,24 +183,20 @@ namespace gui {
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT: {
|
||||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
|
||||||
|
|
||||||
if($grab_source) {
|
if($grab_source) {
|
||||||
auto& drop = $loot_ui.get_drop_target(gui_id);
|
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||||
auto& grab = $status_ui.get_grab_source(*$grab_source);
|
bool dropped = UISystem::loot_drop(
|
||||||
|
$status_ui.$gui, $loot_ui.$gui,
|
||||||
|
*$grab_source, gui_id);
|
||||||
|
|
||||||
if(drop.commit(grab.world_entity)) {
|
if(dropped) {
|
||||||
grab.commit();
|
state(State::LOOTING);
|
||||||
$grab_source = std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state(State::LOOTING);
|
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT: {
|
case INV_SELECT: {
|
||||||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
||||||
auto& source = $status_ui.get_grab_source(*$grab_source);
|
$grab_source = UISystem::loot_grab($status_ui.$gui, gui_id);
|
||||||
source.grab();
|
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
|
@ -211,7 +204,7 @@ namespace gui {
|
||||||
case MOUSE_DRAG:
|
case MOUSE_DRAG:
|
||||||
case MOUSE_MOVE: {
|
case MOUSE_MOVE: {
|
||||||
if($grab_source) {
|
if($grab_source) {
|
||||||
auto& source = $status_ui.get_grab_source(*$grab_source);
|
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||||
source.move($router.position);
|
source.move($router.position);
|
||||||
}
|
}
|
||||||
mouse_action(true);
|
mouse_action(true);
|
||||||
|
@ -236,6 +229,8 @@ namespace gui {
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT:
|
case LOOT_SELECT:
|
||||||
|
// BUG: this actually should init the select, so that in LOOT_GRAB
|
||||||
|
// I can allow people to place it back into the loot ui
|
||||||
state(State::LOOT_GRAB);
|
state(State::LOOT_GRAB);
|
||||||
LOOT_GRAB(ev, data);
|
LOOT_GRAB(ev, data);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -49,8 +49,7 @@ namespace gui {
|
||||||
LootUI $loot_ui;
|
LootUI $loot_ui;
|
||||||
sf::Font $font;
|
sf::Font $font;
|
||||||
gui::routing::Router $router;
|
gui::routing::Router $router;
|
||||||
std::optional<DinkyECS::Entity> $grab_source;
|
std::optional<guecs::Entity> $grab_source;
|
||||||
std::optional<DinkyECS::Entity> $drop_target;
|
|
||||||
|
|
||||||
FSM();
|
FSM();
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace guecs {
|
||||||
return world_entity;
|
return world_entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GrabSource::setSprite(guecs::UI& gui, DinkyECS::Entity gui_id) {
|
void GrabSource::setSprite(guecs::UI& gui, guecs::Entity gui_id) {
|
||||||
dbc::check(gui.has<guecs::Sprite>(gui_id), "GrabSource given sprite gui_id that doesn't exist");
|
dbc::check(gui.has<guecs::Sprite>(gui_id), "GrabSource given sprite gui_id that doesn't exist");
|
||||||
|
|
||||||
auto& sp = gui.get<guecs::Sprite>(gui_id);
|
auto& sp = gui.get<guecs::Sprite>(gui_id);
|
||||||
|
|
|
@ -14,11 +14,11 @@ namespace guecs {
|
||||||
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
std::shared_ptr<sf::Sprite> sprite = nullptr;
|
||||||
|
|
||||||
DinkyECS::Entity grab();
|
DinkyECS::Entity grab();
|
||||||
void setSprite(guecs::UI& gui, DinkyECS::Entity gui_id);
|
void setSprite(guecs::UI& gui, guecs::Entity gui_id);
|
||||||
void move(sf::Vector2i pos);
|
void move(sf::Vector2i pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DropTarget {
|
struct DropTarget {
|
||||||
std::function<bool(DinkyECS::Entity entity)> commit;
|
std::function<bool(DinkyECS::Entity world_entity)> commit;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,12 +90,6 @@ namespace gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guecs::GrabSource& LootUI::get_grab_source(DinkyECS::Entity gui_id) {
|
|
||||||
dbc::check($gui.has<guecs::Sprite>(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
|
||||||
|
|
||||||
return $gui.get<guecs::GrabSource>(gui_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LootUI::render(sf::RenderWindow& window) {
|
void LootUI::render(sf::RenderWindow& window) {
|
||||||
$gui.render(window);
|
$gui.render(window);
|
||||||
}
|
}
|
||||||
|
@ -109,8 +103,4 @@ namespace gui {
|
||||||
bool LootUI::mouse(float x, float y, bool hover) {
|
bool LootUI::mouse(float x, float y, bool hover) {
|
||||||
return $gui.mouse(x, y, hover);
|
return $gui.mouse(x, y, hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
guecs::DropTarget& LootUI::get_drop_target(DinkyECS::Entity gui_id) {
|
|
||||||
return $gui.get<guecs::DropTarget>(gui_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,7 @@ namespace gui {
|
||||||
void update_level(GameLevel &level);
|
void update_level(GameLevel &level);
|
||||||
bool mouse(float x, float y, bool hover);
|
bool mouse(float x, float y, bool hover);
|
||||||
|
|
||||||
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
|
||||||
|
|
||||||
std::optional<DinkyECS::Entity> begin_grab(DinkyECS::Entity slot);
|
|
||||||
void remove_slot(DinkyECS::Entity slot_id);
|
void remove_slot(DinkyECS::Entity slot_id);
|
||||||
|
|
||||||
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
|
||||||
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,16 +101,6 @@ namespace gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guecs::DropTarget& StatusUI::get_drop_target(DinkyECS::Entity gui_id) {
|
|
||||||
return $gui.get<guecs::DropTarget>(gui_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
guecs::GrabSource& StatusUI::get_grab_source(DinkyECS::Entity gui_id) {
|
|
||||||
dbc::check($gui.has<guecs::GrabSource>(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
|
||||||
|
|
||||||
return $gui.get<guecs::GrabSource>(gui_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void StatusUI::remove_slot(DinkyECS::Entity slot_id) {
|
void StatusUI::remove_slot(DinkyECS::Entity slot_id) {
|
||||||
if(contents.contains(slot_id)) {
|
if(contents.contains(slot_id)) {
|
||||||
contents.erase(slot_id);
|
contents.erase(slot_id);
|
||||||
|
|
|
@ -23,10 +23,7 @@ namespace gui {
|
||||||
void update();
|
void update();
|
||||||
bool mouse(float x, float y, bool hover);
|
bool mouse(float x, float y, bool hover);
|
||||||
|
|
||||||
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
|
||||||
void remove_slot(DinkyECS::Entity slot_id);
|
void remove_slot(DinkyECS::Entity slot_id);
|
||||||
|
|
||||||
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
|
||||||
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
25
gui/uisystems.cpp
Normal file
25
gui/uisystems.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "gui/uisystems.hpp"
|
||||||
|
#include "gui/guecstra.hpp"
|
||||||
|
|
||||||
|
namespace UISystem {
|
||||||
|
std::optional<guecs::Entity> loot_grab(guecs::UI& gui, guecs::Entity gui_id) {
|
||||||
|
if(auto source = gui.get_if<guecs::GrabSource>(gui_id)) {
|
||||||
|
source->grab();
|
||||||
|
return gui_id;
|
||||||
|
} else {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loot_drop(guecs::UI& source, guecs::UI& target, guecs::Entity source_id, guecs::Entity target_id) {
|
||||||
|
auto& drop = target.get<guecs::DropTarget>(target_id);
|
||||||
|
auto& grab = source.get<guecs::GrabSource>(source_id);
|
||||||
|
|
||||||
|
if(drop.commit(grab.world_entity)) {
|
||||||
|
grab.commit();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
gui/uisystems.hpp
Normal file
10
gui/uisystems.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
#include <guecs/ui.hpp>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace UISystem {
|
||||||
|
std::optional<guecs::Entity> loot_grab(guecs::UI& gui, guecs::Entity gui_id);
|
||||||
|
|
||||||
|
|
||||||
|
bool loot_drop(guecs::UI& source, guecs::UI& target, guecs::Entity grab_source, guecs::Entity target_id);
|
||||||
|
}
|
|
@ -93,10 +93,10 @@ sources = [
|
||||||
'dbc.cpp',
|
'dbc.cpp',
|
||||||
'devices.cpp',
|
'devices.cpp',
|
||||||
'goap.cpp',
|
'goap.cpp',
|
||||||
'gui/event_router.cpp',
|
|
||||||
'gui/boss_fight_ui.cpp',
|
'gui/boss_fight_ui.cpp',
|
||||||
'gui/combat_ui.cpp',
|
'gui/combat_ui.cpp',
|
||||||
'gui/debug_ui.cpp',
|
'gui/debug_ui.cpp',
|
||||||
|
'gui/event_router.cpp',
|
||||||
'gui/fsm.cpp',
|
'gui/fsm.cpp',
|
||||||
'gui/guecstra.cpp',
|
'gui/guecstra.cpp',
|
||||||
'gui/loot_ui.cpp',
|
'gui/loot_ui.cpp',
|
||||||
|
@ -106,6 +106,7 @@ sources = [
|
||||||
'gui/overlay_ui.cpp',
|
'gui/overlay_ui.cpp',
|
||||||
'gui/ritual_ui.cpp',
|
'gui/ritual_ui.cpp',
|
||||||
'gui/status_ui.cpp',
|
'gui/status_ui.cpp',
|
||||||
|
'gui/uisystems.cpp',
|
||||||
'levelmanager.cpp',
|
'levelmanager.cpp',
|
||||||
'lights.cpp',
|
'lights.cpp',
|
||||||
'map.cpp',
|
'map.cpp',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue