All of the GUI panels are now their own classes and pulled out of the main GUI so I can devise how they're managed.

main
Zed A. Shaw 1 week ago
parent 941be008f8
commit 380e18b91a
  1. 32
      gui.cpp
  2. 16
      gui.hpp

@ -79,15 +79,31 @@ void StatusUI::create_render() {
set_renderer(status_rend);
}
MapViewUI::MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map) :
Panel(GAME_MAP_PIXEL_POS, 0, 0, 0, true),
$world(world), $lights(lights), $game_map(game_map)
{}
void MapViewUI::create_render() {
set_renderer(Renderer([&] {
System::draw_map($world, $game_map, $lights.lighting(), $canvas, width, height);
return canvas($canvas);
}));
}
void MapViewUI::resize_canvas() {
// set canvas to best size
$canvas = Canvas(width * 2, height * 4);
}
GUI::GUI(DinkyECS::World &world, Map& game_map) :
$world(world),
$game_map(game_map),
$status_ui(world),
$lights(game_map.width(), game_map.height()),
$world(world),
$sounds("./assets"),
$renderer()
$map_view($world, $lights, $game_map),
$sounds("./assets")
{
// this needs a config file soon
// $sounds.load("ambient", "ambient_sound.mp3");
@ -101,8 +117,7 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
void GUI::resize_map(int new_size) {
$renderer.resize_grid(new_size, $map_view);
// set canvas to best size
$canvas = Canvas($map_view.width * 2, $map_view.height * 4);
$map_view.resize_canvas();
}
void GUI::save_world() {
@ -113,11 +128,7 @@ void GUI::save_world() {
void GUI::create_renderer() {
$renderer.init_terminal();
$map_view.set_renderer(Renderer([&] {
System::draw_map($world, $game_map, $lights.lighting(), $canvas, $map_view.width, $map_view.height);
return canvas($canvas);
}));
$map_view.create_render();
$status_ui.create_render();
$inventory_ui.create_render();
// don't activate this one
@ -186,7 +197,6 @@ bool GUI::handle_ui_events() {
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;

@ -65,6 +65,7 @@ class StatusUI : public Panel {
Panel(0, 0, STATUS_UI_WIDTH, STATUS_UI_HEIGHT),
$log({{"Welcome to the game!"}}),
$world(world) {}
void create_render();
void log(string msg) {
$log.log(msg);
@ -73,19 +74,26 @@ class StatusUI : public Panel {
class MapViewUI : public Panel {
public:
MapViewUI() : Panel(GAME_MAP_PIXEL_POS, 0, 0, 0, true) {}
Canvas $canvas;
DinkyECS::World& $world;
LightRender& $lights;
Map& $game_map;
MapViewUI(DinkyECS::World& world, LightRender& lights, Map& game_map);
void create_render();
void resize_canvas();
};
class GUI {
Canvas $canvas;
DinkyECS::World& $world;
Map& $game_map;
StatusUI $status_ui;
LightRender $lights;
MapViewUI $map_view;
InventoryUI $inventory_ui;
LightRender $lights;
Canvas $canvas;
bool $show_modal = false;
Component $test_button;
DinkyECS::World& $world;
SoundManager $sounds;
SFMLRender $renderer;
UnDumbTSS $paused;

Loading…
Cancel
Save