/
yaseeeeechka
/
CenterControl
Обзор
Документация
Войти
/
yaseeeeechka
/
CenterControl
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
CenterControl_TCP/include/client/WindowApp.h
72 строки
2 KB
Yaroslava
New structure of Repo. TCP impl
11 дек 2025, 21:12
11 дек 2025, 21:12
6fdf9d7
Код
Авторство
О чём код?
#ifndef CENTERCONTROL_WINDOWAPP_H #define CENTERCONTROL_WINDOWAPP_H // ==================== WindowApp ======================================= class WindowApp : public IScreenApp { public: WindowApp() : window_(sf::VideoMode(sf::Vector2u{900, 720}), "Center Control - Client") { window_.setFramerateLimit(60); if (!font_.openFromFile(kFontPath)) { std::cout << "Could not load font, using default" << std::endl; throw std::runtime_error("Could not load font"); } } void SetSession(Session *s) { session_ = s; session_->SetClearWindowCallback([this]() { SwitchScreen("main"); }); screens_["auth"] = std::make_unique<AuthScreen>(session_, this, font_); screens_["main"] = std::make_unique<RoomsListScreen>(this, font_); screens_["topscores"] = std::make_unique<TopScoresScreen>(this, font_); screens_["room"] = std::make_unique<RoomScreen>(this, font_); screens_["game"] = std::make_unique<GameScreen>(this, font_); active_ = screens_["auth"].get(); } void Run() { sf::Clock dtClock; while (window_.isOpen()) { while (auto ev = window_.pollEvent()) { if (ev->is<sf::Event::Closed>()) { if (!active_ || active_->AllowWindowClose()) { window_.close(); } } if (active_) active_->HandleEvent(*ev); } float dt = dtClock.restart().asSeconds(); if (active_) active_->Update(dt); window_.clear(sf::Color(235, 235, 235)); if (active_) active_->Render(window_); window_.display(); } } void SwitchScreen(const std::string &name) { if (screens_.contains(name)) { if (active_) active_->OnHide(); active_ = screens_[name].get(); active_->OnShow(); } } sf::RenderWindow &GetWindow() { return window_; } Session *GetSession() const override { return session_; } private: sf::RenderWindow window_; Session *session_ = nullptr; std::unordered_map<std::string, std::unique_ptr<IScreen> > screens_; IScreen *active_ = nullptr; sf::Font font_; }; #endif //CENTERCONTROL_WINDOWAPP_H