GUI now handles modals better and there's now a death screen that makes you exit. More to come.

main
Zed A. Shaw 2 weeks ago
parent 6cabd62c7f
commit 1f7214fcd4
  1. 64
      gui.cpp
  2. 3
      gui.hpp

@ -243,15 +243,18 @@ void GUI::handle_world_events() {
$status_ui.log("You MISSED the enemy.");
}
}
break;
case eGUI::DEATH: {
// auto &dead_data = std::any_cast<Events::Death&>(data);
println("PLAYER DEAD!");
auto player = $world.get_the<Player>();
dbc::check(player.entity == entity, "received death event for something not the player");
auto player_combat = $world.get<Combat>(entity);
if(player_combat.dead) {
toggle_modal(&$death_ui, $player_died);
println("PLAYER DEAD show UI, after is {}", $player_died);
}
} break;
}
break;
case eGUI::LOOT: {
auto &item = std::any_cast<InventoryItem&>(data);
$sounds.play("loot_gold");
@ -269,20 +272,13 @@ void GUI::shutdown() {
$renderer.close();
}
bool GUI::handle_ui_events() {
bool GUI::game_ui_events() {
using KB = sf::Keyboard;
using MOUSE = sf::Mouse;
bool event_happened = false;
sf::Event event;
auto player = $world.get_the<Player>();
int map_font_size = $renderer.font_size();
auto& player_motion = $world.get<Motion>(player.entity);
Point pos;
bool event_happened = false;
while($renderer.poll_event(event)) {
if(event.type == sf::Event::Closed) {
shutdown();
} else if(event.type == sf::Event::KeyPressed) {
if(KB::isKeyPressed(KB::Left)) {
player_motion.dx = -1;
event_happened = true;
@ -314,6 +310,48 @@ bool GUI::handle_ui_events() {
} else if(KB::isKeyPressed(KB::Enter)) {
$status_ui.key_press(Event::Return);
}
return event_happened;
}
bool GUI::modal_ui_events() {
using KB = sf::Keyboard;
bool event_happened = false;
for(Panel *panel : $active_panels) {
if(KB::isKeyPressed(KB::Tab)) {
event_happened = true;
panel->key_press(Event::Tab);
} else if(KB::isKeyPressed(KB::Enter)) {
event_happened = true;
panel->key_press(Event::Return);
} else if(KB::isKeyPressed(KB::Escape)) {
// BUG: this is dogshit, rewerite it
if($inventory_open) {
toggle_modal(panel, $inventory_open);
}
}
}
return event_happened;
}
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) {
shutdown();
} else if(event.type == sf::Event::KeyPressed) {
if($modal_shown) {
event_happened = modal_ui_events();
} else {
event_happened = game_ui_events();
}
} else {
for(Panel *panel : $active_panels) {
if($renderer.mouse_position(*panel, pos)) {
@ -380,6 +418,8 @@ void GUI::toggle_modal(Panel *panel, bool &is_open_out) {
$active_panels = {panel};
is_open_out = true;
}
$modal_shown = is_open_out;
}
void GUI::render_scene() {

@ -120,6 +120,7 @@ class GUI {
Canvas $canvas;
bool $inventory_open = false;
bool $player_died = false;
bool $modal_shown = false;
Component $test_button;
SoundManager $sounds;
SFMLRender $renderer;
@ -134,6 +135,8 @@ public:
void resize_map(int new_size);
void create_renderer();
void render_scene();
bool modal_ui_events();
bool game_ui_events();
bool handle_ui_events();
void handle_world_events();
void draw_screen(bool clear=true, float map_off_x=0.0f, float map_off_y=0.0f);

Loading…
Cancel
Save