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 {
|
namespace Events {
|
||||||
enum GUI {
|
enum GUI {
|
||||||
START, COMBAT, LOOT
|
START, COMBAT, LOOT, DEATH
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Combat {
|
struct Combat {
|
||||||
int player_did;
|
int player_did;
|
||||||
int enemy_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 ftxui;
|
||||||
using namespace components;
|
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() {
|
void InventoryUI::create_render() {
|
||||||
has_border = true;
|
has_border = true;
|
||||||
MenuOption option;
|
MenuOption option;
|
||||||
|
@ -196,9 +211,9 @@ void GUI::create_renderer() {
|
||||||
$map_view.create_render();
|
$map_view.create_render();
|
||||||
$status_ui.create_render();
|
$status_ui.create_render();
|
||||||
$inventory_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() {
|
void GUI::handle_world_events() {
|
||||||
|
@ -227,6 +242,15 @@ void GUI::handle_world_events() {
|
||||||
$sounds.play("combat_miss");
|
$sounds.play("combat_miss");
|
||||||
$status_ui.log("You MISSED the enemy.");
|
$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;
|
} break;
|
||||||
case eGUI::LOOT: {
|
case eGUI::LOOT: {
|
||||||
auto &item = std::any_cast<InventoryItem&>(data);
|
auto &item = std::any_cast<InventoryItem&>(data);
|
||||||
|
@ -279,15 +303,7 @@ bool GUI::handle_ui_events() {
|
||||||
auto &debug = $world.get_the<Debug>();
|
auto &debug = $world.get_the<Debug>();
|
||||||
debug.LIGHT = !debug.LIGHT;
|
debug.LIGHT = !debug.LIGHT;
|
||||||
} else if(KB::isKeyPressed(KB::I)) {
|
} else if(KB::isKeyPressed(KB::I)) {
|
||||||
// yes, using an if to avoid double grabbing screen
|
toggle_modal(&$inventory_ui, $inventory_open);
|
||||||
if($show_modal) {
|
|
||||||
$panels = {&$map_view, &$status_ui};
|
|
||||||
$show_modal = false;
|
|
||||||
} else {
|
|
||||||
pause_screen();
|
|
||||||
$panels = {&$inventory_ui};
|
|
||||||
$show_modal = true;
|
|
||||||
}
|
|
||||||
} else if(KB::isKeyPressed(KB::P)) {
|
} else if(KB::isKeyPressed(KB::P)) {
|
||||||
auto &debug = $world.get_the<Debug>();
|
auto &debug = $world.get_the<Debug>();
|
||||||
debug.PATHS = !debug.PATHS;
|
debug.PATHS = !debug.PATHS;
|
||||||
|
@ -299,7 +315,7 @@ bool GUI::handle_ui_events() {
|
||||||
$status_ui.key_press(Event::Return);
|
$status_ui.key_press(Event::Return);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(Panel *panel : $panels) {
|
for(Panel *panel : $active_panels) {
|
||||||
if($renderer.mouse_position(*panel, pos)) {
|
if($renderer.mouse_position(*panel, pos)) {
|
||||||
if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
if(MOUSE::isButtonPressed(MOUSE::Left)) {
|
||||||
panel->mouse_click(Mouse::Button::Left, pos);
|
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() {
|
void GUI::render_scene() {
|
||||||
$renderer.clear();
|
$renderer.clear();
|
||||||
|
|
||||||
if($show_modal) {
|
if($inventory_open) {
|
||||||
draw_paused();
|
draw_paused();
|
||||||
$inventory_ui.render();
|
$inventory_ui.render();
|
||||||
$renderer.draw($inventory_ui);
|
$renderer.draw($inventory_ui);
|
||||||
|
} else if($player_died) {
|
||||||
|
draw_paused();
|
||||||
|
$death_ui.render();
|
||||||
|
$renderer.draw($death_ui);
|
||||||
} else {
|
} else {
|
||||||
$map_view.render();
|
$map_view.render();
|
||||||
$renderer.draw($map_view);
|
$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 {
|
class InventoryUI : public Panel {
|
||||||
public:
|
public:
|
||||||
|
@ -105,13 +116,15 @@ class GUI {
|
||||||
LightRender $lights;
|
LightRender $lights;
|
||||||
MapViewUI $map_view;
|
MapViewUI $map_view;
|
||||||
InventoryUI $inventory_ui;
|
InventoryUI $inventory_ui;
|
||||||
|
DeathUI $death_ui;
|
||||||
Canvas $canvas;
|
Canvas $canvas;
|
||||||
bool $show_modal = false;
|
bool $inventory_open = false;
|
||||||
|
bool $player_died = false;
|
||||||
Component $test_button;
|
Component $test_button;
|
||||||
SoundManager $sounds;
|
SoundManager $sounds;
|
||||||
SFMLRender $renderer;
|
SFMLRender $renderer;
|
||||||
UnDumbTSS $paused;
|
UnDumbTSS $paused;
|
||||||
std::vector<Panel*> $panels;
|
std::vector<Panel*> $active_panels;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GUI(DinkyECS::World& world, Map& game_map);
|
GUI(DinkyECS::World& world, Map& game_map);
|
||||||
|
@ -133,4 +146,5 @@ public:
|
||||||
void pause_screen();
|
void pause_screen();
|
||||||
void draw_paused();
|
void draw_paused();
|
||||||
void init_shaders();
|
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: maybe that can be allowed and looting just shows
|
||||||
// BUG: all dead things there?
|
// BUG: all dead things there?
|
||||||
auto &collider = world.get_the<SpatialMap>();
|
auto &collider = world.get_the<SpatialMap>();
|
||||||
|
auto player = world.get_the<Player>();
|
||||||
|
|
||||||
world.query<Position, Combat>([&](const auto &ent, auto &position, auto &combat) {
|
world.query<Position, Combat>([&](const auto &ent, auto &position, auto &combat) {
|
||||||
// bring out yer dead
|
// bring out yer dead
|
||||||
|
@ -107,8 +108,12 @@ void System::death(DinkyECS::World &world) {
|
||||||
// take them out of collision map
|
// take them out of collision map
|
||||||
collider.remove(position.location);
|
collider.remove(position.location);
|
||||||
|
|
||||||
// remove their motion so they're dead
|
if(ent == player.entity) {
|
||||||
world.remove<Motion>(ent);
|
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
|
// configure player in the world
|
||||||
Player player{player_ent};
|
Player player{player_ent};
|
||||||
world.set_the<Player>(player);
|
world.set_the<Player>(player);
|
||||||
world.set<Combat>(player.entity, {100, 10});
|
|
||||||
world.set<LightSource>(player.entity, {50,1.0});
|
world.set<LightSource>(player.entity, {50,1.0});
|
||||||
world.set<Inventory>(player.entity, {5});
|
world.set<Inventory>(player.entity, {5});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue