Figured out that I don't need a special screen, just send events to the component directly with OnEvent. However, you have to component->Add() or call Render(component, []) with it or else it's not considered a child.
This commit is contained in:
parent
e3cff8142c
commit
96ee16e598
9 changed files with 32 additions and 1078 deletions
18
gui.cpp
18
gui.cpp
|
@ -33,7 +33,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
|
|||
$game_map(game_map),
|
||||
$log({{"Welcome to the game!"}}),
|
||||
$status_ui(SCREEN_X, SCREEN_Y, 0, 0),
|
||||
$map_view(30, 10, GAME_MAP_POS, 0, false),
|
||||
$map_view(0, 0, GAME_MAP_POS, 0, false),
|
||||
$view_port{0,0},
|
||||
$world(world),
|
||||
$sounds("./assets"),
|
||||
|
@ -65,12 +65,14 @@ void GUI::create_renderer() {
|
|||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||
auto player = $world.get_the<Player>();
|
||||
|
||||
$map_view.set_renderer([&] {
|
||||
$map_view.set_renderer(Renderer([&] {
|
||||
System::draw_map($world, $game_map, $canvas, $view_port.x, $view_port.y);
|
||||
return canvas($canvas);
|
||||
});
|
||||
}));
|
||||
|
||||
$status_ui.set_renderer([&, player]{
|
||||
auto test_button = Button("TEST", [&]{ println("pressed"); });
|
||||
|
||||
auto status_rend = Renderer(test_button, [&, test_button, player]{
|
||||
const auto& player_combat = $world.get<Combat>(player.entity);
|
||||
const auto& inventory = $world.get<Inventory>(player.entity);
|
||||
$status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!";
|
||||
|
@ -85,6 +87,7 @@ void GUI::create_renderer() {
|
|||
return hbox({
|
||||
hflow(
|
||||
vbox(
|
||||
test_button->Render(),
|
||||
text(format("HP: {: >3} GOLD: {: >3}",
|
||||
player_combat.hp, inventory.gold)) | border,
|
||||
text($status_text) | border,
|
||||
|
@ -96,6 +99,8 @@ void GUI::create_renderer() {
|
|||
hbox(),
|
||||
});
|
||||
});
|
||||
|
||||
$status_ui.set_renderer(status_rend);
|
||||
}
|
||||
|
||||
void GUI::handle_world_events() {
|
||||
|
@ -151,6 +156,7 @@ bool GUI::handle_ui_events() {
|
|||
if(event.type == sf::Event::Closed) {
|
||||
$renderer.close();
|
||||
} else if(event.type == sf::Event::KeyPressed) {
|
||||
// ZED: Uh we can just do this...?
|
||||
auto& player_motion = $world.get<Motion>(player.entity);
|
||||
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
|
||||
|
@ -171,6 +177,10 @@ bool GUI::handle_ui_events() {
|
|||
resize_map(map_font_size - 10);
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
|
||||
save_world();
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Tab)) {
|
||||
$status_ui.$component->OnEvent(Event::Tab);
|
||||
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) {
|
||||
$status_ui.$component->OnEvent(Event::Return);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue