#include "gui/main_ui.hpp" #include "components.hpp" #include "easings.hpp" #include #include "constants.hpp" #include "game_level.hpp" namespace gui { using namespace components; MainUI::MainUI(sf::RenderWindow& window) : $window(window), $rayview(std::make_shared(RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)) { $window.setVerticalSyncEnabled(VSYNC); $window.setFramerateLimit(FRAME_LIMIT); } void MainUI::dirty() { $needs_render = true; } void MainUI::init() { auto& player_position = GameDB::player_position(); auto player = player_position.location; $rayview->init_shaders(); $rayview->set_position(RAY_VIEW_X, RAY_VIEW_Y); $rayview->position_camera(player.x + 0.5, player.y + 0.5); $overlay_ui.init(); } DinkyECS::Entity MainUI::camera_aim() { auto& level = GameDB::current_level(); // what happens if there's two things at that spot if(level.collision->something_there($rayview->aiming_at)) { return level.collision->get($rayview->aiming_at); } else { return 0; } } void MainUI::render() { if($needs_render) $rayview->render(); $rayview->draw($window); $overlay_ui.render($window); } lel::Cell MainUI::overlay_cell(const std::string& name) { return $overlay_ui.$gui.cell_for(name); } std::optional MainUI::play_rotate() { if($rayview->play_rotate()) { $needs_render = false; return std::make_optional($rayview->aiming_at); } else { $needs_render = true; return std::nullopt; } } std::optional MainUI::play_move() { if($rayview->play_move()) { $needs_render = false; return std::make_optional( $rayview->camera_target(), $rayview->aiming_at); } else { $needs_render = true; return std::nullopt; } } void MainUI::plan_rotate(int dir, float amount) { // -1 is left, 1 is right int extra = (amount == 0.5) * dir; $compass_dir = ($compass_dir + dir + extra) % COMPASS.size(); $rayview->plan_rotate(dir, amount); } Point MainUI::plan_move(int dir, bool strafe) { return $rayview->plan_move(dir, strafe); } void MainUI::abort_plan() { $rayview->abort_plan(); } void MainUI::dead_entity(DinkyECS::Entity entity) { auto world = GameDB::current_world(); if(world->has(entity)) { auto &sprite = world->get(entity); $rayview->update_sprite(entity, sprite); } } void MainUI::update_level() { auto& level = GameDB::current_level(); auto& player_position = GameDB::player_position(); auto player = player_position.location; $rayview->update_level(level); $rayview->position_camera(player.x + 0.5, player.y + 0.5); player_position.aiming_at = $rayview->aiming_at; $compass_dir = 0; $overlay_ui.update_level(); dirty(); } void MainUI::mouse(int x, int y, guecs::Modifiers mods) { $overlay_ui.$gui.mouse(x, y, mods); } }