Created a separate FSM for the DND functionality that compiles but need to wire it in to work.

This commit is contained in:
Zed A. Shaw 2025-06-13 00:57:45 -04:00
parent 1ab708c4eb
commit 82ee8f68f7
7 changed files with 221 additions and 139 deletions

View file

@ -1,3 +1,4 @@
#define FSM_DEBUG 1
#include "gui/fsm.hpp"
#include <iostream>
#include <chrono>
@ -26,12 +27,13 @@ namespace gui {
$map_ui($level),
$mini_map($level),
$loot_ui($level),
$font{FONT_FILE_NAME}
$font{FONT_FILE_NAME},
$dnd_loot($status_ui, $loot_ui, $window, $router)
{
$window.setPosition({0,0});
}
void FSM::event(Event ev) {
void FSM::event(Event ev, std::any data) {
switch($state) {
FSM_STATE(State, START, ev);
FSM_STATE(State, MOVING, ev);
@ -42,20 +44,7 @@ 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<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 received with data but state={} is not handled", int($state)));
}
}
@ -125,113 +114,11 @@ namespace gui {
}
}
void FSM::LOOT_GRAB(Event ev, std::any data) {
using enum Event;
switch(ev) {
case LOOT_OPEN:
$loot_ui.active = false;
state(State::IDLE);
break;
case LOOT_SELECT:
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
if($grab_source) state(State::LOOTING);
break;
case INV_SELECT:
if(UISystem::loot_drop($loot_ui.$gui,
$status_ui.$gui, $grab_source, data))
{
state(State::LOOTING);
}
break;
case MOUSE_CLICK:
mouse_action(false);
break;
case MOUSE_DRAG:
case MOUSE_MOVE: {
if($grab_source) {
auto& source = $loot_ui.$gui.get<guecs::GrabSource>(*$grab_source);
source.move($window.mapPixelToCoords($router.position));
}
mouse_action(true);
} break;
case MOUSE_DRAG_START:
mouse_action(false);
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;
switch(ev) {
case LOOT_OPEN:
$loot_ui.active = false;
state(State::IDLE);
break;
case LOOT_SELECT:
if(UISystem::loot_drop($status_ui.$gui,
$loot_ui.$gui, $grab_source, data))
{
state(State::LOOTING);
}
break;
case INV_SELECT:
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
state(State::LOOTING);
break;
case MOUSE_CLICK:
mouse_action(false);
break;
case MOUSE_DRAG:
case MOUSE_MOVE: {
if($grab_source) {
auto& source = $status_ui.$gui.get<guecs::GrabSource>(*$grab_source);
source.move($window.mapPixelToCoords($router.position));
}
mouse_action(true);
} break;
case MOUSE_DRAG_START: {
mouse_action(false);
} 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:
$grab_source = UISystem::loot_grab($loot_ui.$gui, data);
if($grab_source) state(State::LOOT_GRAB);
break;
case INV_SELECT:
$grab_source = UISystem::loot_grab($status_ui.$gui, data);
if($grab_source) state(State::INV_GRAB);
break;
case MOUSE_DRAG_START:
case MOUSE_CLICK:
mouse_action(false);
break;
default:
state(State::LOOTING);
if(!$dnd_loot.event(ev, data)) {
state(State::IDLE);
} else {
dbc::log("!!!!!!!!! LOOTING ENDED!");
}
}
@ -283,6 +170,7 @@ namespace gui {
state(State::NEXT_LEVEL);
break;
case LOOT_OPEN:
$dnd_loot.event(Event::STARTED);
$loot_ui.active = true;
state(State::LOOTING);
break;
@ -386,8 +274,11 @@ namespace gui {
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, hover);
$combat_ui.mouse(pos.x, pos.y, hover);
$status_ui.mouse(pos.x, pos.y, hover);
$main_ui.mouse(pos.x, pos.y, hover);
if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, hover);
if($loot_ui.active) {
$loot_ui.mouse(pos.x, pos.y, hover);
} else {
$main_ui.mouse(pos.x, pos.y, hover);
}
}
void FSM::handle_keyboard_mouse() {
@ -582,10 +473,6 @@ namespace gui {
case eGUI::NEW_RITUAL:
$combat_ui.init();
break;
case eGUI::EVADE:
case eGUI::BLOCK:
dbc::log("YOU NEED TO IMPLEMENT THIS!!!!!");
break;
case eGUI::ATTACK:
$temp_attack_id = std::any_cast<int>(data);
event(Event::ATTACK);