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

master
Zed A. Shaw 2 weeks ago
parent b43553a563
commit 4b333c6684
  1. 2
      Makefile
  2. 26
      gui_fsm.cpp
  3. 3
      gui_fsm.hpp
  4. 3
      main.cpp

@ -22,7 +22,7 @@ tracy_build:
meson compile -j 10 -C builddir meson compile -j 10 -C builddir
test: build test: build
./builddir/runtests "[textures]" ./builddir/runtests
run: build test run: build test
powershell "cp ./builddir/zedcaster.exe ." powershell "cp ./builddir/zedcaster.exe ."

@ -212,13 +212,22 @@ namespace gui {
fmt::println("END: received event after done: {}", int(ev)); fmt::println("END: received event after done: {}", int(ev));
} }
void FSM::keyboard() { void FSM::keyboard_mouse() {
while(const auto keyev = $window.pollEvent()) { while(const auto ev = $window.pollEvent()) {
if(keyev->is<sf::Event::Closed>()) { if(ev->is<sf::Event::Closed>()) {
event(Event::QUIT); 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; using KEY = sf::Keyboard::Scan;
switch(key->scancode) { switch(key->scancode) {
case KEY::W: case KEY::W:
@ -279,15 +288,6 @@ namespace gui {
$window.display(); $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() { void FSM::run_systems() {
System::enemy_pathing($level); System::enemy_pathing($level);
System::collision($level); System::collision($level);

@ -68,11 +68,10 @@ namespace gui {
void END(Event ev); void END(Event ev);
void try_move(int dir, bool strafe); void try_move(int dir, bool strafe);
void keyboard(); void keyboard_mouse();
void draw_gui(); void draw_gui();
void draw_blood(); void draw_blood();
void render(); void render();
void mouse();
void generate_map(); void generate_map();
bool active(); bool active();
void run_systems(); void run_systems();

@ -14,13 +14,12 @@ int main() {
|| main.in_state(gui::State::MAPPING) || main.in_state(gui::State::MAPPING)
|| main.in_state(gui::State::IN_COMBAT)) || main.in_state(gui::State::IN_COMBAT))
{ {
main.keyboard(); main.keyboard_mouse();
} else{ } else{
main.event(gui::Event::TICK); main.event(gui::Event::TICK);
} }
main.handle_world_events(); main.handle_world_events();
main.mouse();
} }
return 0; return 0;

Loading…
Cancel
Save