There's a simple death screen now and you can exit. More work on what death means later.
This commit is contained in:
parent
f2864a62ee
commit
6cabd62c7f
5 changed files with 72 additions and 19 deletions
|
@ -2,11 +2,15 @@
|
|||
|
||||
namespace Events {
|
||||
enum GUI {
|
||||
START, COMBAT, LOOT
|
||||
START, COMBAT, LOOT, DEATH
|
||||
};
|
||||
|
||||
struct Combat {
|
||||
int player_did;
|
||||
int enemy_did;
|
||||
};
|
||||
|
||||
struct Death {
|
||||
int placeholder = 0;
|
||||
};
|
||||
}
|
||||
|
|
57
gui.cpp
57
gui.cpp
|
@ -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);
|
||||
|
|
18
gui.hpp
18
gui.hpp
|
@ -47,6 +47,17 @@ struct UnDumbTSS {
|
|||
}
|
||||
};
|
||||
|
||||
class DeathUI : public Panel {
|
||||
public:
|
||||
Component $render = nullptr;
|
||||
Component $exit_button = nullptr;
|
||||
std::string $quip = "You died like a dog.";
|
||||
|
||||
DeathUI() :
|
||||
Panel(INVENTORY_PIXEL_X, INVENTORY_PIXEL_Y, INVENTORY_WIDTH, INVENTORY_HEIGHT) {}
|
||||
|
||||
void create_render();
|
||||
};
|
||||
|
||||
class InventoryUI : public Panel {
|
||||
public:
|
||||
|
@ -105,13 +116,15 @@ class GUI {
|
|||
LightRender $lights;
|
||||
MapViewUI $map_view;
|
||||
InventoryUI $inventory_ui;
|
||||
DeathUI $death_ui;
|
||||
Canvas $canvas;
|
||||
bool $show_modal = false;
|
||||
bool $inventory_open = false;
|
||||
bool $player_died = false;
|
||||
Component $test_button;
|
||||
SoundManager $sounds;
|
||||
SFMLRender $renderer;
|
||||
UnDumbTSS $paused;
|
||||
std::vector<Panel*> $panels;
|
||||
std::vector<Panel*> $active_panels;
|
||||
|
||||
public:
|
||||
GUI(DinkyECS::World& world, Map& game_map);
|
||||
|
@ -133,4 +146,5 @@ public:
|
|||
void pause_screen();
|
||||
void draw_paused();
|
||||
void init_shaders();
|
||||
void toggle_modal(Panel *panel, bool &is_open_out);
|
||||
};
|
||||
|
|
|
@ -99,6 +99,7 @@ void System::death(DinkyECS::World &world) {
|
|||
// BUG: maybe that can be allowed and looting just shows
|
||||
// BUG: all dead things there?
|
||||
auto &collider = world.get_the<SpatialMap>();
|
||||
auto player = world.get_the<Player>();
|
||||
|
||||
world.query<Position, Combat>([&](const auto &ent, auto &position, auto &combat) {
|
||||
// bring out yer dead
|
||||
|
@ -107,9 +108,13 @@ void System::death(DinkyECS::World &world) {
|
|||
// take them out of collision map
|
||||
collider.remove(position.location);
|
||||
|
||||
if(ent == player.entity) {
|
||||
world.send<Events::GUI>(Events::GUI::DEATH, ent, {});
|
||||
} else {
|
||||
// remove their motion so they're dead
|
||||
world.remove<Motion>(ent);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -215,7 +215,6 @@ void WorldBuilder::place_entities(DinkyECS::World &world) {
|
|||
// configure player in the world
|
||||
Player player{player_ent};
|
||||
world.set_the<Player>(player);
|
||||
world.set<Combat>(player.entity, {100, 10});
|
||||
world.set<LightSource>(player.entity, {50,1.0});
|
||||
world.set<Inventory>(player.entity, {5});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue