From 4b333c6684af75897011772764c9da178d03a138 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 21 Feb 2025 12:32:55 -0500 Subject: [PATCH] Fix the mouse so that it's discrete and one click means on action. --- Makefile | 2 +- gui_fsm.cpp | 26 +++++++++++++------------- gui_fsm.hpp | 3 +-- main.cpp | 3 +-- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index d4a9c62..a1533ce 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ tracy_build: meson compile -j 10 -C builddir test: build - ./builddir/runtests "[textures]" + ./builddir/runtests run: build test powershell "cp ./builddir/zedcaster.exe ." diff --git a/gui_fsm.cpp b/gui_fsm.cpp index aa59245..ae56605 100644 --- a/gui_fsm.cpp +++ b/gui_fsm.cpp @@ -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()) { + void FSM::keyboard_mouse() { + while(const auto ev = $window.pollEvent()) { + if(ev->is()) { event(Event::QUIT); } - if(const auto* key = keyev->getIf()) { + if(const auto* mouse = ev->getIf()) { + 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()) { 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); diff --git a/gui_fsm.hpp b/gui_fsm.hpp index 92229e0..dac5ce5 100644 --- a/gui_fsm.hpp +++ b/gui_fsm.hpp @@ -68,11 +68,10 @@ namespace gui { void END(Event ev); void try_move(int dir, bool strafe); - void keyboard(); + void keyboard_mouse(); void draw_gui(); void draw_blood(); void render(); - void mouse(); void generate_map(); bool active(); void run_systems(); diff --git a/main.cpp b/main.cpp index e340ae7..9ff9d67 100644 --- a/main.cpp +++ b/main.cpp @@ -14,13 +14,12 @@ int main() { || main.in_state(gui::State::MAPPING) || main.in_state(gui::State::IN_COMBAT)) { - main.keyboard(); + main.keyboard_mouse(); } else{ main.event(gui::Event::TICK); } main.handle_world_events(); - main.mouse(); } return 0;