Cleaned up and unified the source before the big refactor.
This commit is contained in:
parent
0d6a71b06f
commit
343f3a246f
5 changed files with 11 additions and 29 deletions
|
@ -136,11 +136,9 @@ namespace gui {
|
|||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
||||
|
||||
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);
|
||||
$grab_source = std::nullopt;
|
||||
state(State::LOOTING);
|
||||
}
|
||||
|
@ -154,7 +152,6 @@ namespace gui {
|
|||
$grab_source = std::nullopt;
|
||||
}
|
||||
|
||||
$window.setMouseCursorVisible(true);
|
||||
state(State::LOOTING);
|
||||
}
|
||||
} break;
|
||||
|
@ -200,7 +197,6 @@ namespace gui {
|
|||
$grab_source = std::nullopt;
|
||||
}
|
||||
|
||||
//$window.setMouseCursorVisible(true);
|
||||
state(State::LOOTING);
|
||||
}
|
||||
} break;
|
||||
|
@ -208,11 +204,9 @@ namespace gui {
|
|||
$grab_source = std::any_cast<DinkyECS::Entity>(data);
|
||||
|
||||
if(auto world_entity = $status_ui.begin_grab(*$grab_source)) {
|
||||
//$window.setMouseCursorVisible(false);
|
||||
$loot_ui.begin_drop(*world_entity);
|
||||
} else {
|
||||
// BUG: need a cancel operation here
|
||||
//$window.setMouseCursorVisible(true);
|
||||
$grab_source = std::nullopt;
|
||||
state(State::LOOTING);
|
||||
}
|
||||
|
|
|
@ -97,12 +97,8 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
bool LootUI::has_grab_source(DinkyECS::Entity gui_id) {
|
||||
return $gui.has<guecs::Sprite>(gui_id);
|
||||
}
|
||||
|
||||
guecs::GrabSource& LootUI::get_grab_source(DinkyECS::Entity gui_id) {
|
||||
dbc::check(has_grab_source(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
||||
dbc::check($gui.has<guecs::Sprite>(gui_id), "invalid GrabSource requested, entity isn't in the GUI.");
|
||||
|
||||
return static_cast<guecs::GrabSource&>($gui.get<guecs::Sprite>(gui_id));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ namespace gui {
|
|||
DinkyECS::Entity $selected_entity;
|
||||
|
||||
LootUI(GameLevel level);
|
||||
|
||||
void init();
|
||||
void update();
|
||||
void render(sf::RenderWindow& window);
|
||||
|
@ -24,7 +23,6 @@ namespace gui {
|
|||
bool mouse(float x, float y, bool hover);
|
||||
|
||||
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);
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace gui {
|
|||
|
||||
$gui.set_init<guecs::Sprite>(gui_id, {sprite.name});
|
||||
|
||||
$slots.insert_or_assign(gui_id, $selected_entity);
|
||||
contents.insert_or_assign(gui_id, $selected_entity);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -110,28 +110,22 @@ namespace gui {
|
|||
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.");
|
||||
dbc::check($gui.has<guecs::Sprite>(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) {
|
||||
// BET CHAT: I'll have to change this to a full if-else later
|
||||
|
||||
if(!$slots.contains(slot_id)) return std::nullopt;
|
||||
if(!contents.contains(slot_id)) return std::nullopt;
|
||||
|
||||
auto& source = get_grab_source(slot_id);
|
||||
source.grab();
|
||||
return $slots.at(slot_id);
|
||||
return contents.at(slot_id);
|
||||
}
|
||||
|
||||
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
|
||||
$slots.erase(slot_id);
|
||||
contents.erase(slot_id);
|
||||
$gui.remove<guecs::Sprite>(slot_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,22 +11,21 @@ namespace gui {
|
|||
class StatusUI {
|
||||
public:
|
||||
guecs::UI $gui;
|
||||
std::unordered_map<DinkyECS::Entity, DinkyECS::Entity> $slots;
|
||||
GameLevel $level;
|
||||
ritual::UI $ritual_ui;
|
||||
std::unordered_map<DinkyECS::Entity, DinkyECS::Entity> contents;
|
||||
DinkyECS::Entity $selected_entity;
|
||||
ritual::UI $ritual_ui;
|
||||
|
||||
StatusUI(GameLevel level);
|
||||
void select_ritual();
|
||||
void update_level(GameLevel &level);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
void init();
|
||||
void render(sf::RenderWindow &window);
|
||||
void update();
|
||||
bool place_slot(DinkyECS::Entity gui_id);
|
||||
bool mouse(float x, float y, bool hover);
|
||||
|
||||
|
||||
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);
|
||||
|
@ -34,5 +33,6 @@ namespace gui {
|
|||
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
||||
void begin_drop(DinkyECS::Entity world_entity);
|
||||
bool commit_drop(DinkyECS::Entity gui_id);
|
||||
bool place_slot(DinkyECS::Entity gui_id);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue