Can now round-trip a torch from loot to inventory and back.
This commit is contained in:
parent
4b0d76bbcc
commit
2a6b892e7f
5 changed files with 80 additions and 22 deletions
44
gui/fsm.cpp
44
gui/fsm.cpp
|
@ -154,7 +154,6 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
$window.setMouseCursorVisible(true);
|
$window.setMouseCursorVisible(true);
|
||||||
dbc::log("INV_SELECT back to looting");
|
|
||||||
state(State::LOOTING);
|
state(State::LOOTING);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
@ -184,10 +183,6 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSM::INV_GRAB(Event ev, std::any data) {
|
void FSM::INV_GRAB(Event ev, std::any data) {
|
||||||
dbc::log("INV_SELECT NOT IMPlEMENTED");
|
|
||||||
state(State::LOOTING);
|
|
||||||
return;
|
|
||||||
|
|
||||||
using enum Event;
|
using enum Event;
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
|
@ -197,21 +192,48 @@ namespace gui {
|
||||||
state(State::IDLE);
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case LOOT_SELECT: {
|
case LOOT_SELECT: {
|
||||||
state(State::IDLE);
|
auto gui_id = std::any_cast<DinkyECS::Entity>(data);
|
||||||
|
|
||||||
|
if($grab_source) {
|
||||||
|
if($loot_ui.commit_drop(gui_id)) {
|
||||||
|
$status_ui.commit_grab(*$grab_source);
|
||||||
|
$grab_source = std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
//$window.setMouseCursorVisible(true);
|
||||||
|
state(State::LOOTING);
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT: {
|
case INV_SELECT: {
|
||||||
state(State::IDLE);
|
$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;
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
break;
|
break;
|
||||||
case MOUSE_MOVE: {
|
case MOUSE_MOVE: {
|
||||||
|
if($grab_source) {
|
||||||
|
auto& source = $status_ui.get_grab_source(*$grab_source);
|
||||||
|
source.move($router.position);
|
||||||
|
}
|
||||||
mouse_action(true);
|
mouse_action(true);
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_DRAG_START: {
|
case MOUSE_DRAG_START: {
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_DRAG: {
|
case MOUSE_DRAG: {
|
||||||
|
if($grab_source) {
|
||||||
|
auto& source = $status_ui.get_grab_source(*$grab_source);
|
||||||
|
source.move($router.position);
|
||||||
|
}
|
||||||
mouse_action(true);
|
mouse_action(true);
|
||||||
} break;
|
} break;
|
||||||
case MOUSE_DROP:
|
case MOUSE_DROP:
|
||||||
|
@ -235,9 +257,8 @@ namespace gui {
|
||||||
state(State::LOOT_GRAB);
|
state(State::LOOT_GRAB);
|
||||||
break;
|
break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
dbc::log("INV_SELECT disabled in FSM::LOOTING");
|
state(State::INV_GRAB);
|
||||||
state(State::IDLE);
|
INV_GRAB(ev, data);
|
||||||
// INV_GRAB(ev, data);
|
|
||||||
break;
|
break;
|
||||||
case MOUSE_DRAG_START:
|
case MOUSE_DRAG_START:
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
|
@ -313,8 +334,7 @@ namespace gui {
|
||||||
state(State::LOOTING);
|
state(State::LOOTING);
|
||||||
} break;
|
} break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
dbc::log("INV_SELECT disabled in IDLE");
|
state(State::INV_GRAB);
|
||||||
// state(State::INV_GRAB);
|
|
||||||
break;
|
break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
|
|
|
@ -78,10 +78,25 @@ namespace gui {
|
||||||
auto& sprite = $level.world->get<components::Sprite>(item);
|
auto& sprite = $level.world->get<components::Sprite>(item);
|
||||||
guecs::GrabSource grabber{sprite.name};
|
guecs::GrabSource grabber{sprite.name};
|
||||||
$gui.set_init<guecs::Sprite>(id, grabber);
|
$gui.set_init<guecs::Sprite>(id, grabber);
|
||||||
|
} else {
|
||||||
|
$gui.set<guecs::DropTarget>(id, {
|
||||||
|
[&, id]() -> bool { return place_slot(id); }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LootUI::place_slot(DinkyECS::Entity id) {
|
||||||
|
if(contents.size() < INV_SLOTS && !contents.contains(id)) {
|
||||||
|
contents.try_emplace(id, $selected_entity);
|
||||||
|
dbc::log(fmt::format("adding entity {}", id));
|
||||||
|
update();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool LootUI::has_grab_source(DinkyECS::Entity gui_id) {
|
bool LootUI::has_grab_source(DinkyECS::Entity gui_id) {
|
||||||
return $gui.has<guecs::Sprite>(gui_id);
|
return $gui.has<guecs::Sprite>(gui_id);
|
||||||
}
|
}
|
||||||
|
@ -109,4 +124,19 @@ namespace gui {
|
||||||
guecs::DropTarget& LootUI::get_drop_target(DinkyECS::Entity gui_id) {
|
guecs::DropTarget& LootUI::get_drop_target(DinkyECS::Entity gui_id) {
|
||||||
return $gui.get<guecs::DropTarget>(gui_id);
|
return $gui.get<guecs::DropTarget>(gui_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LootUI::begin_drop(DinkyECS::Entity world_entity) {
|
||||||
|
dbc::log("begin the loot drop");
|
||||||
|
$selected_entity = world_entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LootUI::commit_drop(DinkyECS::Entity gui_id) {
|
||||||
|
if($gui.has<guecs::DropTarget>(gui_id)) {
|
||||||
|
auto& drop = get_drop_target(gui_id);
|
||||||
|
return drop.commit();
|
||||||
|
} else {
|
||||||
|
// NOTE: I think I need to cancel the drop or something?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace gui {
|
||||||
guecs::UI $gui;
|
guecs::UI $gui;
|
||||||
GameLevel $level;
|
GameLevel $level;
|
||||||
std::unordered_map<DinkyECS::Entity, DinkyECS::Entity> contents;
|
std::unordered_map<DinkyECS::Entity, DinkyECS::Entity> contents;
|
||||||
|
DinkyECS::Entity $selected_entity;
|
||||||
|
|
||||||
LootUI(GameLevel level);
|
LootUI(GameLevel level);
|
||||||
|
|
||||||
|
@ -30,7 +31,8 @@ namespace gui {
|
||||||
|
|
||||||
|
|
||||||
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
guecs::DropTarget& get_drop_target(DinkyECS::Entity gui_id);
|
||||||
void begin_drop(DinkyECS::Entity entity);
|
void begin_drop(DinkyECS::Entity world_entity);
|
||||||
void commit_drop(DinkyECS::Entity entity);
|
bool commit_drop(DinkyECS::Entity gui_id);
|
||||||
|
bool place_slot(DinkyECS::Entity id);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,13 +100,13 @@ namespace gui {
|
||||||
return $gui.get<guecs::DropTarget>(gui_id);
|
return $gui.get<guecs::DropTarget>(gui_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUI::begin_drop(DinkyECS::Entity entity) {
|
void StatusUI::begin_drop(DinkyECS::Entity world_entity) {
|
||||||
$selected_entity = entity;
|
$selected_entity = world_entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StatusUI::commit_drop(DinkyECS::Entity gui_id) {
|
bool StatusUI::commit_drop(DinkyECS::Entity gui_id) {
|
||||||
|
// BUG: just roll this into DropTarget
|
||||||
auto& drop = get_drop_target(gui_id);
|
auto& drop = get_drop_target(gui_id);
|
||||||
|
|
||||||
return drop.commit();
|
return drop.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,11 +121,17 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<DinkyECS::Entity> StatusUI::begin_grab(DinkyECS::Entity slot_id) {
|
std::optional<DinkyECS::Entity> StatusUI::begin_grab(DinkyECS::Entity slot_id) {
|
||||||
(void)slot_id;
|
// BET CHAT: I'll have to change this to a full if-else later
|
||||||
return std::nullopt;
|
|
||||||
|
if(!$slots.contains(slot_id)) return std::nullopt;
|
||||||
|
|
||||||
|
auto& source = get_grab_source(slot_id);
|
||||||
|
source.grab();
|
||||||
|
return $slots.at(slot_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
|
void StatusUI::commit_grab(DinkyECS::Entity slot_id) {
|
||||||
(void)slot_id;
|
$slots.erase(slot_id);
|
||||||
|
$gui.remove<guecs::Sprite>(slot_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace gui {
|
||||||
void commit_grab(DinkyECS::Entity slot_id);
|
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);
|
void begin_drop(DinkyECS::Entity world_entity);
|
||||||
bool commit_drop(DinkyECS::Entity entity);
|
bool commit_drop(DinkyECS::Entity gui_id);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue