|
|
@ -165,43 +165,44 @@ void GUI::handle_world_events() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool GUI::handle_ui_events() { |
|
|
|
bool GUI::handle_ui_events() { |
|
|
|
|
|
|
|
using KB = sf::Keyboard; |
|
|
|
|
|
|
|
using MOUSE = sf::Mouse; |
|
|
|
bool event_happened = false; |
|
|
|
bool event_happened = false; |
|
|
|
sf::Event event; |
|
|
|
sf::Event event; |
|
|
|
auto player = $world.get_the<Player>(); |
|
|
|
auto player = $world.get_the<Player>(); |
|
|
|
int map_font_size = $renderer.font_size(); |
|
|
|
int map_font_size = $renderer.font_size(); |
|
|
|
|
|
|
|
auto& player_motion = $world.get<Motion>(player.entity); |
|
|
|
|
|
|
|
|
|
|
|
while($renderer.poll_event(event)) { |
|
|
|
while($renderer.poll_event(event)) { |
|
|
|
if(event.type == sf::Event::Closed) { |
|
|
|
if(event.type == sf::Event::Closed) { |
|
|
|
$renderer.close(); |
|
|
|
$renderer.close(); |
|
|
|
} else if(event.type == sf::Event::KeyPressed) { |
|
|
|
} else if(event.type == sf::Event::KeyPressed) { |
|
|
|
// ZED: Uh we can just do this...?
|
|
|
|
|
|
|
|
auto& player_motion = $world.get<Motion>(player.entity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { |
|
|
|
if(KB::isKeyPressed(KB::Left)) { |
|
|
|
player_motion.dx = -1; |
|
|
|
player_motion.dx = -1; |
|
|
|
event_happened = true; |
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Right)) { |
|
|
|
player_motion.dx = 1; |
|
|
|
player_motion.dx = 1; |
|
|
|
event_happened = true; |
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Up)) { |
|
|
|
player_motion.dy = -1; |
|
|
|
player_motion.dy = -1; |
|
|
|
event_happened = true; |
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Down)) { |
|
|
|
player_motion.dy = 1; |
|
|
|
player_motion.dy = 1; |
|
|
|
event_happened = true; |
|
|
|
event_happened = true; |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Equal)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Equal)) { |
|
|
|
resize_map(map_font_size + 10); |
|
|
|
resize_map(map_font_size + 10); |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Hyphen)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Hyphen)) { |
|
|
|
resize_map(map_font_size - 10); |
|
|
|
resize_map(map_font_size - 10); |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) { |
|
|
|
} else if(KB::isKeyPressed(KB::S)) { |
|
|
|
save_world(); |
|
|
|
save_world(); |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Tab)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Tab)) { |
|
|
|
$status_ui.$component->OnEvent(Event::Tab); |
|
|
|
$status_ui.$component->OnEvent(Event::Tab); |
|
|
|
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) { |
|
|
|
} else if(KB::isKeyPressed(KB::Enter)) { |
|
|
|
$status_ui.$component->OnEvent(Event::Return); |
|
|
|
$status_ui.$component->OnEvent(Event::Return); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) { |
|
|
|
} else if(MOUSE::isButtonPressed(MOUSE::Left)) { |
|
|
|
sf::Vector2i pos = sf::Mouse::getPosition($renderer.$window); |
|
|
|
sf::Vector2i pos = MOUSE::getPosition($renderer.$window); |
|
|
|
Mouse mev; |
|
|
|
Mouse mev; |
|
|
|
mev.button = Mouse::Button::Left, |
|
|
|
mev.button = Mouse::Button::Left, |
|
|
|
mev.x=pos.x / $renderer.$ui_bounds.width; // this needs to be in...panel coordinates?
|
|
|
|
mev.x=pos.x / $renderer.$ui_bounds.width; // this needs to be in...panel coordinates?
|
|
|
|