Big BIG refactor to make inventory use a model that's placed into the world, following a more sane MVC style.
This commit is contained in:
parent
119b3ed11d
commit
a0eff927b6
21 changed files with 270 additions and 123 deletions
|
@ -1,7 +1,5 @@
|
|||
#define FSM_DEBUG 1
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "gui/dnd_loot.hpp"
|
||||
#include "gui/uisystems.hpp"
|
||||
|
||||
namespace gui {
|
||||
|
||||
|
@ -43,11 +41,11 @@ namespace gui {
|
|||
END(Event::CLOSE);
|
||||
break;
|
||||
case LOOT_SELECT:
|
||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||
$grab_source = start_grab($loot_ui.$gui, data);
|
||||
if($grab_source) state(DNDState::LOOT_GRAB);
|
||||
break;
|
||||
case INV_SELECT:
|
||||
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
|
||||
$grab_source = start_grab($status_ui.$gui, data);
|
||||
if($grab_source) state(DNDState::INV_GRAB);
|
||||
break;
|
||||
case MOUSE_DRAG_START:
|
||||
|
@ -67,11 +65,11 @@ namespace gui {
|
|||
END(Event::CLOSE);
|
||||
break;
|
||||
case LOOT_SELECT:
|
||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
|
||||
$grab_source = start_grab($loot_ui.$gui, data);
|
||||
if($grab_source) state(DNDState::LOOTING);
|
||||
break;
|
||||
case INV_SELECT:
|
||||
if(UISystem::loot_drop($loot_ui.$gui,
|
||||
if(commit_drop($loot_ui.$gui,
|
||||
$status_ui.$gui, $grab_source, data))
|
||||
{
|
||||
state(DNDState::LOOTING);
|
||||
|
@ -90,14 +88,14 @@ namespace gui {
|
|||
END(Event::CLOSE);
|
||||
break;
|
||||
case LOOT_SELECT:
|
||||
if(UISystem::loot_drop($status_ui.$gui,
|
||||
if(commit_drop($status_ui.$gui,
|
||||
$loot_ui.$gui, $grab_source, data))
|
||||
{
|
||||
state(DNDState::LOOTING);
|
||||
}
|
||||
break;
|
||||
case INV_SELECT:
|
||||
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
|
||||
$grab_source = start_grab($status_ui.$gui, data);
|
||||
state(DNDState::LOOTING);
|
||||
break;
|
||||
default:
|
||||
|
@ -128,8 +126,7 @@ namespace gui {
|
|||
|
||||
switch(ev) {
|
||||
case INV_SELECT:
|
||||
if(UISystem::loot_drop($loot_ui.$gui,
|
||||
$status_ui.$gui, $grab_source, data))
|
||||
commit_drop($loot_ui.$gui, $status_ui.$gui, $grab_source, data);
|
||||
{
|
||||
END(Event::CLOSE);
|
||||
}
|
||||
|
@ -149,7 +146,7 @@ namespace gui {
|
|||
case LOOT_ITEM: {
|
||||
// NOTE: if > 1 items, go to LOOT_OPEN instead
|
||||
auto gui_id = $loot_ui.$gui.entity("item_0");
|
||||
$grab_source = UISystem::loot_grab($loot_ui.$gui, gui_id);
|
||||
$grab_source = start_grab($loot_ui.$gui, gui_id);
|
||||
|
||||
if($grab_source) {
|
||||
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
|
@ -160,7 +157,7 @@ namespace gui {
|
|||
}
|
||||
} break;
|
||||
case INV_SELECT: {
|
||||
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
|
||||
$grab_source = start_grab($status_ui.$gui, data);
|
||||
|
||||
if($grab_source) {
|
||||
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
|
||||
|
@ -206,7 +203,6 @@ namespace gui {
|
|||
case MOUSE_DRAG:
|
||||
case MOUSE_MOVE: {
|
||||
if($grab_source) {
|
||||
fmt::println("MOVING that thing");
|
||||
auto& source = gui.get<guecs::GrabSource>(*$grab_source);
|
||||
source.move($window.mapPixelToCoords($router.position));
|
||||
}
|
||||
|
@ -240,4 +236,32 @@ namespace gui {
|
|||
$window.draw(*$grab_sprite);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<guecs::Entity> DNDLoot::start_grab(guecs::UI& gui, std::any data) {
|
||||
auto gui_id = std::any_cast<guecs::Entity>(data);
|
||||
|
||||
if(auto source = gui.get_if<guecs::GrabSource>(gui_id)) {
|
||||
source->grab();
|
||||
return gui_id;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
bool DNDLoot::commit_drop(guecs::UI& source, guecs::UI& target,
|
||||
std::optional<guecs::Entity> source_id, std::any data)
|
||||
{
|
||||
if(!source_id) return false;
|
||||
auto target_id = std::any_cast<guecs::Entity>(data);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue