|
|
|
@ -30,6 +30,21 @@ using namespace std::chrono_literals; |
|
|
|
|
using namespace ftxui; |
|
|
|
|
using namespace components; |
|
|
|
|
|
|
|
|
|
void DeathUI::create_render() { |
|
|
|
|
has_border = true; |
|
|
|
|
$exit_button = Button("EXIT", []{ std::exit(0); }); |
|
|
|
|
|
|
|
|
|
$render = Renderer([&] { |
|
|
|
|
return vflow({ |
|
|
|
|
paragraph($quip) | border, |
|
|
|
|
$exit_button->Render() |
|
|
|
|
}) | flex; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
set_renderer($render); |
|
|
|
|
add($exit_button); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void InventoryUI::create_render() { |
|
|
|
|
has_border = true; |
|
|
|
|
MenuOption option; |
|
|
|
@ -196,9 +211,9 @@ void GUI::create_renderer() { |
|
|
|
|
$map_view.create_render(); |
|
|
|
|
$status_ui.create_render(); |
|
|
|
|
$inventory_ui.create_render(); |
|
|
|
|
// don't activate this one
|
|
|
|
|
$death_ui.create_render(); |
|
|
|
|
|
|
|
|
|
$panels = {&$map_view, &$status_ui}; |
|
|
|
|
$active_panels = {&$map_view, &$status_ui}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GUI::handle_world_events() { |
|
|
|
@ -227,6 +242,15 @@ void GUI::handle_world_events() { |
|
|
|
|
$sounds.play("combat_miss"); |
|
|
|
|
$status_ui.log("You MISSED the enemy."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
case eGUI::DEATH: { |
|
|
|
|
// auto &dead_data = std::any_cast<Events::Death&>(data);
|
|
|
|
|
println("PLAYER DEAD!"); |
|
|
|
|
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; |
|
|
|
|
case eGUI::LOOT: { |
|
|
|
|
auto &item = std::any_cast<InventoryItem&>(data); |
|
|
|
@ -279,15 +303,7 @@ bool GUI::handle_ui_events() { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.LIGHT = !debug.LIGHT; |
|
|
|
|
} else if(KB::isKeyPressed(KB::I)) { |
|
|
|
|
// yes, using an if to avoid double grabbing screen
|
|
|
|
|
if($show_modal) { |
|
|
|
|
$panels = {&$map_view, &$status_ui}; |
|
|
|
|
$show_modal = false; |
|
|
|
|
} else { |
|
|
|
|
pause_screen(); |
|
|
|
|
$panels = {&$inventory_ui}; |
|
|
|
|
$show_modal = true; |
|
|
|
|
} |
|
|
|
|
toggle_modal(&$inventory_ui, $inventory_open); |
|
|
|
|
} else if(KB::isKeyPressed(KB::P)) { |
|
|
|
|
auto &debug = $world.get_the<Debug>(); |
|
|
|
|
debug.PATHS = !debug.PATHS; |
|
|
|
@ -299,7 +315,7 @@ bool GUI::handle_ui_events() { |
|
|
|
|
$status_ui.key_press(Event::Return); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
for(Panel *panel : $panels) { |
|
|
|
|
for(Panel *panel : $active_panels) { |
|
|
|
|
if($renderer.mouse_position(*panel, pos)) { |
|
|
|
|
if(MOUSE::isButtonPressed(MOUSE::Left)) { |
|
|
|
|
panel->mouse_click(Mouse::Button::Left, pos); |
|
|
|
@ -355,13 +371,28 @@ void GUI::shake() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GUI::toggle_modal(Panel *panel, bool &is_open_out) { |
|
|
|
|
if(is_open_out) { |
|
|
|
|
$active_panels = {&$map_view, &$status_ui}; |
|
|
|
|
is_open_out = false; |
|
|
|
|
} else { |
|
|
|
|
pause_screen(); |
|
|
|
|
$active_panels = {panel}; |
|
|
|
|
is_open_out = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GUI::render_scene() { |
|
|
|
|
$renderer.clear(); |
|
|
|
|
|
|
|
|
|
if($show_modal) { |
|
|
|
|
if($inventory_open) { |
|
|
|
|
draw_paused(); |
|
|
|
|
$inventory_ui.render(); |
|
|
|
|
$renderer.draw($inventory_ui); |
|
|
|
|
} else if($player_died) { |
|
|
|
|
draw_paused(); |
|
|
|
|
$death_ui.render(); |
|
|
|
|
$renderer.draw($death_ui); |
|
|
|
|
} else { |
|
|
|
|
$map_view.render(); |
|
|
|
|
$renderer.draw($map_view); |
|
|
|
|