Mostly worked out how to do looting but now need how to take out of inventory and put into loot.
This commit is contained in:
parent
c509162be1
commit
94385b195d
7 changed files with 139 additions and 54 deletions
147
gui/fsm.cpp
147
gui/fsm.cpp
|
@ -39,15 +39,20 @@ namespace gui {
|
|||
FSM_STATE(State, COMBAT_ROTATE, ev);
|
||||
FSM_STATE(State, NEXT_LEVEL, ev);
|
||||
FSM_STATE(State, END, ev);
|
||||
FSM_STATE(State, LOOTING, ev, std::make_any<bool>(true));
|
||||
FSM_STATE(State, LOOTING, ev, std::make_any<int>(-1));
|
||||
FSM_STATE(State, LOOT_GRAB, ev, std::make_any<int>(-1));
|
||||
FSM_STATE(State, INV_GRAB, ev, std::make_any<int>(-1));
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::event(Event ev, std::any data) {
|
||||
switch($state) {
|
||||
FSM_STATE(State, LOOTING, ev, data);
|
||||
FSM_STATE(State, LOOT_GRAB, ev, data);
|
||||
FSM_STATE(State, INV_GRAB, ev, data);
|
||||
FSM_STATE(State, IDLE, ev);
|
||||
default:
|
||||
dbc::log(fmt::format("event given with data but event={} is not handled", int(ev)));
|
||||
dbc::log(fmt::format("event received with data but state={} is not handled", int($state)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +123,7 @@ namespace gui {
|
|||
}
|
||||
}
|
||||
|
||||
void FSM::LOOTING(Event ev, std::any data) {
|
||||
void FSM::LOOT_GRAB(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
|
||||
switch(ev) {
|
||||
|
@ -127,40 +132,118 @@ namespace gui {
|
|||
state(State::IDLE);
|
||||
break;
|
||||
case LOOT_SELECT: {
|
||||
fmt::println("loot is selected");
|
||||
int slot_id = std::any_cast<int>(data);
|
||||
|
||||
if(auto entity = $loot_ui.select_slot(slot_id)) {
|
||||
fmt::println("LOOT SELECT slot={} has entity={}", slot_id, entity.value());
|
||||
$status_ui.select_slot(slot_id, entity.value());
|
||||
$status_ui.select_slot(slot_id, *entity);
|
||||
$dumb_sprite = $loot_ui.grab_sprite(slot_id);
|
||||
|
||||
$window.setMouseCursorVisible(false);
|
||||
$dumb_sprite->setOrigin({128, 128});
|
||||
$dumb_sprite->setPosition({
|
||||
float($router.position.x),
|
||||
float($router.position.y)
|
||||
});
|
||||
}
|
||||
} break;
|
||||
case LOOT_PLACE: {
|
||||
case INV_SELECT: {
|
||||
std::string slot_name = std::any_cast<std::string>(data);
|
||||
int slot_id = $status_ui.place_slot(slot_name);
|
||||
// BUG: fix this bullshit
|
||||
if(slot_id != -1) {
|
||||
$loot_ui.remove_slot(slot_id);
|
||||
}
|
||||
$window.setMouseCursorVisible(true);
|
||||
$dumb_sprite = nullptr;
|
||||
state(State::LOOTING);
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE:
|
||||
case MOUSE_MOVE: {
|
||||
if($dumb_sprite) {
|
||||
$dumb_sprite->setPosition({
|
||||
float($router.position.x),
|
||||
float($router.position.y)
|
||||
});
|
||||
}
|
||||
mouse_action(true);
|
||||
break;
|
||||
case MOUSE_DRAG_START:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_DRAG:
|
||||
} break;
|
||||
case MOUSE_DRAG_START: {
|
||||
mouse_action(false);
|
||||
} break;
|
||||
case MOUSE_DRAG: {
|
||||
if($dumb_sprite) {
|
||||
$dumb_sprite->setPosition({
|
||||
float($router.position.x),
|
||||
float($router.position.y)
|
||||
});
|
||||
}
|
||||
mouse_action(true);
|
||||
break;
|
||||
} break;
|
||||
case MOUSE_DROP:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case TICK:
|
||||
// do nothing
|
||||
break;
|
||||
default:
|
||||
state(State::LOOT_GRAB);
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::INV_GRAB(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
(void)data;
|
||||
|
||||
switch(ev) {
|
||||
case LOOT_OPEN:
|
||||
$loot_ui.active = false;
|
||||
state(State::IDLE);
|
||||
break;
|
||||
case LOOT_SELECT: {
|
||||
state(State::IDLE);
|
||||
} break;
|
||||
case INV_SELECT: {
|
||||
state(State::IDLE);
|
||||
} break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE: {
|
||||
mouse_action(true);
|
||||
} break;
|
||||
case MOUSE_DRAG_START: {
|
||||
mouse_action(false);
|
||||
} break;
|
||||
case MOUSE_DRAG: {
|
||||
mouse_action(true);
|
||||
} break;
|
||||
case MOUSE_DROP:
|
||||
mouse_action(false);
|
||||
break;
|
||||
default:
|
||||
state(State::INV_GRAB);
|
||||
}
|
||||
}
|
||||
|
||||
void FSM::LOOTING(Event ev, std::any data) {
|
||||
using enum Event;
|
||||
|
||||
switch(ev) {
|
||||
case LOOT_OPEN:
|
||||
$loot_ui.active = false;
|
||||
state(State::IDLE);
|
||||
break;
|
||||
case LOOT_SELECT:
|
||||
LOOT_GRAB(ev, data);
|
||||
state(State::LOOT_GRAB);
|
||||
break;
|
||||
case INV_SELECT:
|
||||
state(State::INV_GRAB);
|
||||
INV_GRAB(ev, data);
|
||||
break;
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
default:
|
||||
state(State::LOOTING);
|
||||
}
|
||||
|
@ -213,39 +296,31 @@ namespace gui {
|
|||
sound::stop("ambient");
|
||||
state(State::NEXT_LEVEL);
|
||||
break;
|
||||
case STOP_COMBAT:
|
||||
case TICK:
|
||||
// do nothing
|
||||
break;
|
||||
case LOOT_OPEN: {
|
||||
dbc::log("IDLE LOOT OPEN!");
|
||||
Config items("assets/items.json");
|
||||
auto& data = items["TORCH_BAD"];
|
||||
auto torch = $level.world->entity();
|
||||
components::configure_entity(*$level.world, torch, data["components"]);
|
||||
$loot_ui.contents.push_back(torch);
|
||||
|
||||
for(int i = 0; $loot_ui.contents.size() < 10; i++) {
|
||||
auto torch = $level.world->entity();
|
||||
components::configure_entity(*$level.world, torch, data["components"]);
|
||||
$loot_ui.contents.push_back(torch);
|
||||
}
|
||||
|
||||
$loot_ui.update();
|
||||
$loot_ui.active = true;
|
||||
|
||||
state(State::LOOTING);
|
||||
|
||||
} break;
|
||||
case LOOT_PLACE:
|
||||
// ignored
|
||||
case INV_SELECT:
|
||||
state(State::INV_GRAB);
|
||||
break;
|
||||
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE:
|
||||
mouse_action(true);
|
||||
break;
|
||||
case MOUSE_DRAG: // ignored
|
||||
case MOUSE_DRAG_START: // ignored
|
||||
case MOUSE_DROP: // ignored
|
||||
break;
|
||||
default:
|
||||
dbc::sentinel("unhandled event in IDLE");
|
||||
break; // ignore everything else
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,8 +573,8 @@ namespace gui {
|
|||
case eGUI::LOOT_SELECT:
|
||||
event(Event::LOOT_SELECT, data);
|
||||
break;
|
||||
case eGUI::LOOT_PLACE:
|
||||
event(Event::LOOT_PLACE, data);
|
||||
case eGUI::INV_SELECT:
|
||||
event(Event::INV_SELECT, data);
|
||||
break;
|
||||
case eGUI::LOOT: {
|
||||
$map_ui.log(L"You picked up an item.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue