Swapping and putting back now work in the status_ui inventory, but now I need to refactor so this operation works on any inventory::Model.

master
Zed A. Shaw 18 hours ago
parent 784f753e72
commit 2421a33bb0
  1. 14
      gui/dnd_loot.cpp
  2. 21
      gui/status_ui.cpp
  3. 3
      gui/status_ui.hpp

@ -111,10 +111,16 @@ namespace gui {
dbc::check(worked, "Need to fix this, should be able to abort.");
END(CLOSE);
} break;
case INV_SELECT:
if(commit_move($status_ui.$gui, $grab_source, data)) {
END(CLOSE);
}
case INV_SELECT: {
auto drop_id = std::any_cast<guecs::Entity>(data);
if($status_ui.occupied(drop_id)) {
$status_ui.swap(*$grab_source, drop_id);
END(CLOSE);
} else if(commit_move($status_ui.$gui, $grab_source, data)) {
END(CLOSE);
}
} break;
break;
default:
handle_mouse(ev, $status_ui.$gui);

@ -135,4 +135,25 @@ namespace gui {
$gui.remove<guecs::GrabSource>(slot_id);
$gui.remove<guecs::Sprite>(slot_id);
}
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
if(gui_a != gui_b) {
auto& inventory = $level.world->get_the<inventory::Model>();
auto& a_name = $slot_to_name.at(gui_a);
auto& b_name = $slot_to_name.at(gui_b);
auto a_ent = inventory.get(a_name);
auto b_ent = inventory.get(b_name);
inventory.swap(a_ent, b_ent);
}
update();
}
bool StatusUI::occupied(guecs::Entity slot) {
dbc::check($slot_to_name.contains(slot), "jank ass slot to name thing isn't loaded right you idiot.");
auto& inventory = $level.world->get_the<inventory::Model>();
auto& slot_name = $slot_to_name.at(slot);
return inventory.has(slot_name);
}
}

@ -26,5 +26,8 @@ namespace gui {
void remove_slot(guecs::Entity slot_id);
bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity);
bool drop_item(DinkyECS::Entity item_id);
void swap(guecs::Entity gui_a, guecs::Entity gui_b);
bool occupied(guecs::Entity slot);
};
}

Loading…
Cancel
Save