Fix the mouse so that it's discrete and one click means on action.

This commit is contained in:
Zed A. Shaw 2025-02-21 12:32:55 -05:00
parent b43553a563
commit 4b333c6684
4 changed files with 16 additions and 18 deletions

View file

@ -212,13 +212,22 @@ namespace gui {
fmt::println("END: received event after done: {}", int(ev));
}
void FSM::keyboard() {
while(const auto keyev = $window.pollEvent()) {
if(keyev->is<sf::Event::Closed>()) {
void FSM::keyboard_mouse() {
while(const auto ev = $window.pollEvent()) {
if(ev->is<sf::Event::Closed>()) {
event(Event::QUIT);
}
if(const auto* key = keyev->getIf<sf::Event::KeyPressed>()) {
if(const auto* mouse = ev->getIf<sf::Event::MouseButtonPressed>()) {
if(mouse->button == sf::Mouse::Button::Left) {
sf::Vector2f pos = $window.mapPixelToCoords(mouse->position);
$combat_ui.$gui.mouse(pos.x, pos.y);
$status_ui.$gui.mouse(pos.x, pos.y);
$main_ui.mouse(pos.x, pos.y);
}
}
if(const auto* key = ev->getIf<sf::Event::KeyPressed>()) {
using KEY = sf::Keyboard::Scan;
switch(key->scancode) {
case KEY::W:
@ -279,15 +288,6 @@ namespace gui {
$window.display();
}
void FSM::mouse() {
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
sf::Vector2f pos = $window.mapPixelToCoords(sf::Mouse::getPosition($window));
$combat_ui.$gui.mouse(pos.x, pos.y);
$status_ui.$gui.mouse(pos.x, pos.y);
$main_ui.mouse(pos.x, pos.y);
}
}
void FSM::run_systems() {
System::enemy_pathing($level);
System::collision($level);