Even better API, but still not the best organization. This will let me implement both sides, then I can pull it out and try to generalize it into a few guecs components.
This commit is contained in:
parent
3e0adf0c22
commit
4b0d76bbcc
7 changed files with 63 additions and 22 deletions
16
gui/fsm.cpp
16
gui/fsm.cpp
|
@ -135,12 +135,9 @@ namespace gui {
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT: {
|
||||||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
||||||
|
|
||||||
if(auto world_entity = $loot_ui.start_grab(*$grab_source)) {
|
if(auto world_entity = $loot_ui.begin_grab(*$grab_source)) {
|
||||||
auto& source = $loot_ui.get_grab_source(*$grab_source);
|
$window.setMouseCursorVisible(false);
|
||||||
source.grab($window);
|
$status_ui.begin_drop(*world_entity);
|
||||||
source.move($router.position);
|
|
||||||
|
|
||||||
$status_ui.start_drop(*world_entity);
|
|
||||||
} else {
|
} else {
|
||||||
// BUG: need a cancel operation here
|
// BUG: need a cancel operation here
|
||||||
$window.setMouseCursorVisible(true);
|
$window.setMouseCursorVisible(true);
|
||||||
|
@ -149,11 +146,10 @@ namespace gui {
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT: {
|
case INV_SELECT: {
|
||||||
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
||||||
if($grab_source) {
|
|
||||||
auto& drop = $status_ui.get_drop_target(gui_id);
|
|
||||||
|
|
||||||
if(drop.commit()) {
|
if($grab_source) {
|
||||||
$loot_ui.commit_drop(*$grab_source);
|
if($status_ui.commit_drop(gui_id)) {
|
||||||
|
$loot_ui.commit_grab(*$grab_source);
|
||||||
$grab_source = std::nullopt;
|
$grab_source = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@ namespace guecs {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GrabSource::grab(sf::RenderWindow& window) {
|
void GrabSource::grab() {
|
||||||
window.setMouseCursorVisible(false);
|
|
||||||
sprite->setOrigin({128, 128});
|
sprite->setOrigin({128, 128});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace guecs {
|
||||||
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
|
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
|
||||||
|
|
||||||
struct GrabSource : public Sprite {
|
struct GrabSource : public Sprite {
|
||||||
void grab(sf::RenderWindow& window);
|
void grab();
|
||||||
void move(sf::Vector2i position);
|
void move(sf::Vector2i position);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,15 +46,17 @@ namespace gui {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<DinkyECS::Entity> LootUI::start_grab(DinkyECS::Entity slot_id) {
|
std::optional<DinkyECS::Entity> LootUI::begin_grab(DinkyECS::Entity slot_id) {
|
||||||
if(contents.contains(slot_id)) {
|
if(contents.contains(slot_id)) {
|
||||||
|
auto& source = get_grab_source(slot_id);
|
||||||
|
source.grab();
|
||||||
return contents.at(slot_id);
|
return contents.at(slot_id);
|
||||||
} else {
|
} else {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LootUI::commit_drop(DinkyECS::Entity slot_id) {
|
void LootUI::commit_grab(DinkyECS::Entity slot_id) {
|
||||||
contents.erase(slot_id);
|
contents.erase(slot_id);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -103,4 +105,8 @@ 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,9 +21,16 @@ namespace gui {
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
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);
|
||||||
std::optional<DinkyECS::Entity> start_grab(DinkyECS::Entity slot);
|
|
||||||
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
||||||
bool has_grab_source(DinkyECS::Entity gui_id);
|
bool has_grab_source(DinkyECS::Entity gui_id);
|
||||||
void commit_drop(DinkyECS::Entity slot_id);
|
|
||||||
|
std::optional<DinkyECS::Entity> begin_grab(DinkyECS::Entity slot);
|
||||||
|
void commit_grab(DinkyECS::Entity slot_id);
|
||||||
|
|
||||||
|
|
||||||
|
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
||||||
|
void begin_drop(DinkyECS::Entity entity);
|
||||||
|
void commit_drop(DinkyECS::Entity entity);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,10 +83,6 @@ namespace gui {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUI::start_drop(DinkyECS::Entity entity) {
|
|
||||||
$selected_entity = entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StatusUI::place_slot(DinkyECS::Entity gui_id) {
|
bool StatusUI::place_slot(DinkyECS::Entity gui_id) {
|
||||||
if($level.world->has<components::Sprite>($selected_entity)) {
|
if($level.world->has<components::Sprite>($selected_entity)) {
|
||||||
auto& sprite = $level.world->get<components::Sprite>($selected_entity);
|
auto& sprite = $level.world->get<components::Sprite>($selected_entity);
|
||||||
|
@ -103,4 +99,33 @@ namespace gui {
|
||||||
guecs::DropTarget& StatusUI::get_drop_target(DinkyECS::Entity gui_id) {
|
guecs::DropTarget& StatusUI::get_drop_target(DinkyECS::Entity gui_id) {
|
||||||
return $gui.get<guecs::DropTarget>(gui_id);
|
return $gui.get<guecs::DropTarget>(gui_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StatusUI::begin_drop(DinkyECS::Entity entity) {
|
||||||
|
$selected_entity = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StatusUI::commit_drop(DinkyECS::Entity gui_id) {
|
||||||
|
auto& drop = get_drop_target(gui_id);
|
||||||
|
|
||||||
|
return drop.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StatusUI::has_grab_source(DinkyECS::Entity gui_id) {
|
||||||
|
return $gui.has<guecs::Sprite>(gui_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
guecs::GrabSource& StatusUI::get_grab_source(DinkyECS::Entity gui_id) {
|
||||||
|
dbc::check(has_grab_source(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
||||||
|
|
||||||
|
return static_cast<guecs::GrabSource&>($gui.get<guecs::Sprite>(gui_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<DinkyECS::Entity> StatusUI::begin_grab(DinkyECS::Entity slot_id) {
|
||||||
|
(void)slot_id;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
|
||||||
|
(void)slot_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,16 @@ namespace gui {
|
||||||
void init();
|
void init();
|
||||||
void render(sf::RenderWindow &window);
|
void render(sf::RenderWindow &window);
|
||||||
void update();
|
void update();
|
||||||
void start_drop(DinkyECS::Entity entity);
|
|
||||||
bool place_slot(DinkyECS::Entity gui_id);
|
bool place_slot(DinkyECS::Entity gui_id);
|
||||||
|
|
||||||
|
guecs::GrabSource& get_grab_source(DinkyECS::Entity entity);
|
||||||
|
bool has_grab_source(DinkyECS::Entity gui_id);
|
||||||
|
|
||||||
|
std::optional<DinkyECS::Entity> begin_grab(DinkyECS::Entity slot);
|
||||||
|
void commit_grab(DinkyECS::Entity slot_id);
|
||||||
|
|
||||||
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
||||||
|
void begin_drop(DinkyECS::Entity entity);
|
||||||
|
bool commit_drop(DinkyECS::Entity entity);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue