The event router is working well and I can do drag-n-drop but I'll have to rethink where to use it.
This commit is contained in:
parent
5aa54d875f
commit
c509162be1
8 changed files with 126 additions and 63 deletions
97
gui/fsm.cpp
97
gui/fsm.cpp
|
@ -127,6 +127,7 @@ 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)) {
|
||||
|
@ -137,8 +138,26 @@ namespace gui {
|
|||
case LOOT_PLACE: {
|
||||
std::string slot_name = std::any_cast<std::string>(data);
|
||||
int slot_id = $status_ui.place_slot(slot_name);
|
||||
$loot_ui.remove_slot(slot_id);
|
||||
// BUG: fix this bullshit
|
||||
if(slot_id != -1) {
|
||||
$loot_ui.remove_slot(slot_id);
|
||||
}
|
||||
} 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;
|
||||
case TICK:
|
||||
// do nothing
|
||||
break;
|
||||
|
@ -214,6 +233,17 @@ namespace gui {
|
|||
case LOOT_PLACE:
|
||||
// ignored
|
||||
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");
|
||||
}
|
||||
|
@ -227,6 +257,15 @@ namespace gui {
|
|||
sound::play("ambient");
|
||||
next_level();
|
||||
state(State::IDLE);
|
||||
break;
|
||||
case MOUSE_CLICK: {
|
||||
sf::Vector2f pos = mouse_position();
|
||||
$boss_fight_ui->mouse(pos.x, pos.y, false);
|
||||
|
||||
if($boss_fight_ui->boss_dead()) {
|
||||
event(Event::STAIRS_DOWN);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break; // do nothing for now
|
||||
}
|
||||
|
@ -236,6 +275,12 @@ namespace gui {
|
|||
using enum Event;
|
||||
|
||||
switch(ev) {
|
||||
case MOUSE_CLICK:
|
||||
mouse_action(false);
|
||||
break;
|
||||
case MOUSE_MOVE:
|
||||
mouse_action(true);
|
||||
break;
|
||||
case ATTACK:
|
||||
$main_ui.dirty();
|
||||
sound::play("Sword_Hit_1");
|
||||
|
@ -280,45 +325,27 @@ namespace gui {
|
|||
dbc::log(fmt::format("END: received event after done: {}", int(ev)));
|
||||
}
|
||||
|
||||
sf::Vector2f FSM::mouse_position() {
|
||||
return $window.mapPixelToCoords($router.position);
|
||||
}
|
||||
|
||||
void FSM::mouse_action(bool hover) {
|
||||
sf::Vector2f pos = mouse_position();
|
||||
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);
|
||||
}
|
||||
|
||||
void FSM::handle_keyboard_mouse() {
|
||||
while(const auto ev = $window.pollEvent()) {
|
||||
auto gui_ev = $router.process_event(ev);
|
||||
|
||||
if(gui_ev != gui::Event::TICK) {
|
||||
event(gui_ev);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(const auto* mouse = ev->getIf<sf::Event::MouseButtonPressed>()) {
|
||||
if(mouse->button == sf::Mouse::Button::Left) {
|
||||
sf::Vector2f pos = $window.mapPixelToCoords(mouse->position);
|
||||
|
||||
if(in_state(State::NEXT_LEVEL)) {
|
||||
$boss_fight_ui->mouse(pos.x, pos.y, false);
|
||||
|
||||
if($boss_fight_ui->boss_dead()) {
|
||||
event(Event::STAIRS_DOWN);
|
||||
}
|
||||
} else {
|
||||
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, false);
|
||||
$combat_ui.mouse(pos.x, pos.y, false);
|
||||
$status_ui.mouse(pos.x, pos.y, false);
|
||||
$main_ui.mouse(pos.x, pos.y, false);
|
||||
if($loot_ui.active) $loot_ui.mouse(pos.x, pos.y, false);
|
||||
}
|
||||
}
|
||||
} else if(const auto* mouse = ev->getIf<sf::Event::MouseMoved>()) {
|
||||
sf::Vector2f pos = $window.mapPixelToCoords(mouse->position);
|
||||
if($debug_ui.active) $debug_ui.mouse(pos.x, pos.y, true);
|
||||
$combat_ui.mouse(pos.x, pos.y, true);
|
||||
$status_ui.mouse(pos.x, pos.y, true);
|
||||
$main_ui.mouse(pos.x, pos.y, true);
|
||||
}
|
||||
|
||||
if(const auto* key = ev->getIf<sf::Event::KeyPressed>()) {
|
||||
if(gui_ev == Event::KEY_PRESS) {
|
||||
using KEY = sf::Keyboard::Scan;
|
||||
|
||||
switch(key->scancode) {
|
||||
switch($router.scancode) {
|
||||
case KEY::W:
|
||||
event(Event::MOVE_FORWARD);
|
||||
break;
|
||||
|
@ -368,6 +395,8 @@ namespace gui {
|
|||
default:
|
||||
break; // ignored
|
||||
}
|
||||
} else {
|
||||
event(gui_ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue