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
test: build
./builddir/runtests "[textures]"
./builddir/runtests
run: build test
powershell "cp ./builddir/zedcaster.exe ."

@ -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);

@ -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();

@ -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;

Loading…
Cancel
Save