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.

master
Zed A. Shaw 1 week ago
parent 3e0adf0c22
commit 4b0d76bbcc
  1. 16
      gui/fsm.cpp
  2. 3
      gui/guecstra.cpp
  3. 2
      gui/guecstra.hpp
  4. 10
      gui/loot_ui.cpp
  5. 11
      gui/loot_ui.hpp
  6. 33
      gui/status_ui.cpp
  7. 10
      gui/status_ui.hpp

@ -135,12 +135,9 @@ namespace gui {
case LOOT_SELECT: {
$grab_source = std::any_cast<DinkyECS::Entity>(data);
if(auto world_entity = $loot_ui.start_grab(*$grab_source)) {
auto& source = $loot_ui.get_grab_source(*$grab_source);
source.grab($window);
source.move($router.position);
$status_ui.start_drop(*world_entity);
if(auto world_entity = $loot_ui.begin_grab(*$grab_source)) {
$window.setMouseCursorVisible(false);
$status_ui.begin_drop(*world_entity);
} else {
// BUG: need a cancel operation here
$window.setMouseCursorVisible(true);
@ -149,11 +146,10 @@ namespace gui {
} break;
case INV_SELECT: {
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
if($grab_source) {
auto& drop = $status_ui.get_drop_target(gui_id);
if(drop.commit()) {
$loot_ui.commit_drop(*$grab_source);
if($grab_source) {
if($status_ui.commit_drop(gui_id)) {
$loot_ui.commit_grab(*$grab_source);
$grab_source = std::nullopt;
}

@ -21,8 +21,7 @@ namespace guecs {
}
void GrabSource::grab(sf::RenderWindow& window) {
window.setMouseCursorVisible(false);
void GrabSource::grab() {
sprite->setOrigin({128, 128});
}

@ -9,7 +9,7 @@ namespace guecs {
Clickable make_action(DinkyECS::World& target, Events::GUI event, std::any data);
struct GrabSource : public Sprite {
void grab(sf::RenderWindow& window);
void grab();
void move(sf::Vector2i position);
};

@ -46,15 +46,17 @@ namespace gui {
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)) {
auto& source = get_grab_source(slot_id);
source.grab();
return contents.at(slot_id);
} else {
return std::nullopt;
}
}
void LootUI::commit_drop(DinkyECS::Entity slot_id) {
void LootUI::commit_grab(DinkyECS::Entity slot_id) {
contents.erase(slot_id);
update();
}
@ -103,4 +105,8 @@ namespace gui {
bool LootUI::mouse(float x, float y, bool 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 update_level(GameLevel &level);
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);
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();
}
void StatusUI::start_drop(DinkyECS::Entity entity) {
$selected_entity = entity;
}
bool StatusUI::place_slot(DinkyECS::Entity gui_id) {
if($level.world->has<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) {
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 render(sf::RenderWindow &window);
void update();
void start_drop(DinkyECS::Entity entity);
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);
void begin_drop(DinkyECS::Entity entity);
bool commit_drop(DinkyECS::Entity entity);
};
}

Loading…
Cancel
Save