|
|
|
@ -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,50 +272,85 @@ 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); |
|
|
|
|
bool event_happened = false; |
|
|
|
|
|
|
|
|
|
if(KB::isKeyPressed(KB::Left)) { |
|
|
|
|
player_motion.dx = -1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Right)) { |
|
|
|
|
player_motion.dx = 1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Up)) { |
|
|
|
|
player_motion.dy = -1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Down)) { |
|
|
|
|
player_motion.dy = 1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Equal)) { |
|
|
|
|
resize_map(map_font_size + 10); |
|
|
|
|
} else if(KB::isKeyPressed(KB::Hyphen)) { |
|
|
|
|
resize_map(map_font_size - 10); |
|
|
|
|
} else if(KB::isKeyPressed(KB::L)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.LIGHT = !debug.LIGHT; |
|
|
|
|
} else if(KB::isKeyPressed(KB::I)) { |
|
|
|
|
toggle_modal(&$inventory_ui, $inventory_open); |
|
|
|
|
} else if(KB::isKeyPressed(KB::P)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.PATHS = !debug.PATHS; |
|
|
|
|
} else if(KB::isKeyPressed(KB::S)) { |
|
|
|
|
save_world(); |
|
|
|
|
} else if(KB::isKeyPressed(KB::Tab)) { |
|
|
|
|
$status_ui.key_press(Event::Tab); |
|
|
|
|
} 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(KB::isKeyPressed(KB::Left)) { |
|
|
|
|
player_motion.dx = -1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Right)) { |
|
|
|
|
player_motion.dx = 1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Up)) { |
|
|
|
|
player_motion.dy = -1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Down)) { |
|
|
|
|
player_motion.dy = 1; |
|
|
|
|
event_happened = true; |
|
|
|
|
} else if(KB::isKeyPressed(KB::Equal)) { |
|
|
|
|
resize_map(map_font_size + 10); |
|
|
|
|
} else if(KB::isKeyPressed(KB::Hyphen)) { |
|
|
|
|
resize_map(map_font_size - 10); |
|
|
|
|
} else if(KB::isKeyPressed(KB::L)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.LIGHT = !debug.LIGHT; |
|
|
|
|
} else if(KB::isKeyPressed(KB::I)) { |
|
|
|
|
toggle_modal(&$inventory_ui, $inventory_open); |
|
|
|
|
} else if(KB::isKeyPressed(KB::P)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.PATHS = !debug.PATHS; |
|
|
|
|
} else if(KB::isKeyPressed(KB::S)) { |
|
|
|
|
save_world(); |
|
|
|
|
} else if(KB::isKeyPressed(KB::Tab)) { |
|
|
|
|
$status_ui.key_press(Event::Tab); |
|
|
|
|
} else if(KB::isKeyPressed(KB::Enter)) { |
|
|
|
|
$status_ui.key_press(Event::Return); |
|
|
|
|
if($modal_shown) { |
|
|
|
|
event_happened = modal_ui_events(); |
|
|
|
|
} else { |
|
|
|
|
event_happened = game_ui_events(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for(Panel *panel : $active_panels) { |
|
|
|
@ -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() { |
|
|
|
|