Moved to SFML 3.0 now.
This commit is contained in:
parent
7c56f350ab
commit
e05b2c304c
12 changed files with 167 additions and 173 deletions
55
gui.cpp
55
gui.cpp
|
@ -312,42 +312,42 @@ void GUI::shutdown() {
|
|||
|
||||
bool GUI::game_ui_events() {
|
||||
auto& world = *$level.world;
|
||||
using KB = sf::Keyboard;
|
||||
using KB = sf::Keyboard::Key;
|
||||
|
||||
auto player = world.get_the<Player>();
|
||||
int map_font_size = $renderer.font_size();
|
||||
auto& player_motion = world.get<Motion>(player.entity);
|
||||
bool event_happened = false;
|
||||
|
||||
if(KB::isKeyPressed(KB::Left)) {
|
||||
if(sf::Keyboard::isKeyPressed(KB::Left)) {
|
||||
player_motion.dx = -1;
|
||||
event_happened = true;
|
||||
} else if(KB::isKeyPressed(KB::Right)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Right)) {
|
||||
player_motion.dx = 1;
|
||||
event_happened = true;
|
||||
} else if(KB::isKeyPressed(KB::Up)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Up)) {
|
||||
player_motion.dy = -1;
|
||||
event_happened = true;
|
||||
} else if(KB::isKeyPressed(KB::Down)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Down)) {
|
||||
player_motion.dy = 1;
|
||||
event_happened = true;
|
||||
} else if(KB::isKeyPressed(KB::Equal)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Equal)) {
|
||||
resize_map(map_font_size + 10);
|
||||
} else if(KB::isKeyPressed(KB::Hyphen)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Hyphen)) {
|
||||
resize_map(map_font_size - 10);
|
||||
} else if(KB::isKeyPressed(KB::L)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::L)) {
|
||||
auto &debug = world.get_the<Debug>();
|
||||
debug.LIGHT = !debug.LIGHT;
|
||||
} else if(KB::isKeyPressed(KB::I)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::I)) {
|
||||
toggle_modal(&$inventory_ui, $inventory_open);
|
||||
} else if(KB::isKeyPressed(KB::P)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::P)) {
|
||||
auto &debug = world.get_the<Debug>();
|
||||
debug.PATHS = !debug.PATHS;
|
||||
} else if(KB::isKeyPressed(KB::S)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::S)) {
|
||||
save_world();
|
||||
} else if(KB::isKeyPressed(KB::Tab)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Tab)) {
|
||||
$status_ui.key_press(Event::Tab);
|
||||
} else if(KB::isKeyPressed(KB::Enter)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Enter)) {
|
||||
$status_ui.key_press(Event::Return);
|
||||
}
|
||||
|
||||
|
@ -356,17 +356,17 @@ bool GUI::game_ui_events() {
|
|||
|
||||
|
||||
bool GUI::modal_ui_events() {
|
||||
using KB = sf::Keyboard;
|
||||
using KB = sf::Keyboard::Key;
|
||||
bool event_happened = false;
|
||||
|
||||
for(Panel *panel : $active_panels) {
|
||||
if(KB::isKeyPressed(KB::Tab)) {
|
||||
if(sf::Keyboard::isKeyPressed(KB::Tab)) {
|
||||
event_happened = true;
|
||||
panel->key_press(Event::Tab);
|
||||
} else if(KB::isKeyPressed(KB::Enter)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Enter)) {
|
||||
event_happened = true;
|
||||
panel->key_press(Event::Return);
|
||||
} else if(KB::isKeyPressed(KB::Escape)) {
|
||||
} else if(sf::Keyboard::isKeyPressed(KB::Escape)) {
|
||||
// BUG: this is dogshit, rewerite it
|
||||
if($inventory_open) {
|
||||
toggle_modal(panel, $inventory_open);
|
||||
|
@ -378,15 +378,13 @@ bool GUI::modal_ui_events() {
|
|||
}
|
||||
|
||||
bool GUI::handle_ui_events() {
|
||||
using MOUSE = sf::Mouse;
|
||||
bool event_happened = false;
|
||||
sf::Event event;
|
||||
Point pos;
|
||||
|
||||
while($renderer.poll_event(event)) {
|
||||
if(event.type == sf::Event::Closed) {
|
||||
while(const auto event = $renderer.poll_event()) {
|
||||
if(event->is<sf::Event::Closed>()) {
|
||||
shutdown();
|
||||
} else if(event.type == sf::Event::KeyPressed) {
|
||||
} else if(event->is<sf::Event::KeyPressed>()) {
|
||||
if($modal_shown) {
|
||||
event_happened = modal_ui_events();
|
||||
} else {
|
||||
|
@ -395,7 +393,7 @@ bool GUI::handle_ui_events() {
|
|||
} else {
|
||||
for(Panel *panel : $active_panels) {
|
||||
if($renderer.mouse_position(*panel, pos)) {
|
||||
if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
||||
if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
|
||||
panel->mouse_click(Mouse::Button::Left, pos);
|
||||
event_happened = true;
|
||||
} else {
|
||||
|
@ -410,23 +408,12 @@ bool GUI::handle_ui_events() {
|
|||
}
|
||||
|
||||
void GUI::init_shaders() {
|
||||
auto& shader = $paused.load_shader("./shaders/modal.frag");
|
||||
shader.setUniform("offsetFactor", sf::Glsl::Vec2{0.001f, 0.001f});
|
||||
shader.setUniform("darkness", 0.05f);
|
||||
}
|
||||
|
||||
void GUI::pause_screen() {
|
||||
auto &window = $renderer.$window;
|
||||
auto size = window.getSize();
|
||||
|
||||
$paused.texture.create(size.x, size.y);
|
||||
$paused.texture.update(window);
|
||||
$paused.sprite.setTexture($paused.texture);
|
||||
$paused.sprite.setPosition(0,0);
|
||||
}
|
||||
|
||||
void GUI::draw_paused() {
|
||||
$renderer.draw_sprite($paused.sprite, &$paused.shader);
|
||||
}
|
||||
|
||||
void GUI::run_systems() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue