Refactor fase 3: Extraer UIManager de Engine
Migra toda la lógica de interfaz de usuario (HUD, FPS, debug, notificaciones) a UIManager siguiendo el principio de Single Responsibility (SRP). ## Archivos Nuevos **source/ui/ui_manager.h:** - Declaración de clase UIManager - Gestión de HUD debug, FPS counter, notificaciones, texto obsoleto - Constructor/destructor con gestión de TextRenderers y Notifier - Métodos públicos: initialize(), update(), render(), toggleDebug() - Getters: isDebugActive(), getCurrentFPS(), isTextObsoleteVisible() **source/ui/ui_manager.cpp:** - Implementación completa de UI (~250 líneas) - renderDebugHUD(): Renderiza toda la información de debug - renderObsoleteText(): Sistema antiguo de texto (DEPRECATED) - update(): Calcula FPS y actualiza notificaciones - Gestión de 3 TextRenderers (display, debug, notifier) - Integración con Notifier para mensajes tipo iOS/Android ## Archivos Modificados **source/defines.h:** - Movido: enum class AppMode (antes estaba en engine.h) - Ahora AppMode es global y accesible para todos los componentes **source/engine.h:** - Agregado: #include "ui/ui_manager.h" - Agregado: std::unique_ptr<UIManager> ui_manager_ - Removido: enum class AppMode (movido a defines.h) - Removido: bool show_debug_, bool show_text_ - Removido: TextRenderer text_renderer_, text_renderer_debug_, text_renderer_notifier_ - Removido: Notifier notifier_ - Removido: std::string text_, int text_pos_, Uint64 text_init_time_ - Removido: Uint64 fps_last_time_, int fps_frame_count_, int fps_current_ - Removido: std::string fps_text_, vsync_text_ - Removidos métodos privados: setText(), gravityDirectionToString() **source/engine.cpp:** - initialize(): Crea ui_manager_ con renderer y theme_manager - update(): Delega a ui_manager_->update() - render(): Reemplaza 90+ líneas de debug HUD con ui_manager_->render() - toggleDebug(): Delega a ui_manager_->toggleDebug() - toggleVSync(): Actualiza texto con ui_manager_->updateVSyncText() - showNotificationForAction(): Delega a ui_manager_->showNotification() - updatePhysicalWindowSize(): Simplificado, delega a ui_manager_ - toggleIntegerScaling(): Usa ui_manager_ en lugar de texto obsoleto - toggleShapeModeInternal(): Usa ui_manager_->showNotification() - activateShapeInternal(): Usa ui_manager_->showNotification() - Removidos métodos completos: setText() (~27 líneas), gravityDirectionToString() - Removidas ~90 líneas de renderizado debug manual - Removidas ~65 líneas de gestión de TextRenderers/Notifier ## Resultado - Engine.cpp reducido de ~1950 → ~1700 líneas (-250 líneas, -12.8%) - UIManager: 250 líneas de lógica UI separada - Separación clara: Engine coordina, UIManager renderiza UI - AppMode ahora es enum global en defines.h - 100% funcional: Compila sin errores ni warnings - Preparado para Fase 4 (StateManager) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -16,17 +16,8 @@
|
||||
#include "input/input_handler.h" // for InputHandler
|
||||
#include "scene/scene_manager.h" // for SceneManager
|
||||
#include "shapes/shape.h" // for Shape (interfaz polimórfica)
|
||||
#include "text/textrenderer.h" // for TextRenderer
|
||||
#include "theme_manager.h" // for ThemeManager
|
||||
#include "ui/notifier.h" // for Notifier
|
||||
|
||||
// Modos de aplicación mutuamente excluyentes
|
||||
enum class AppMode {
|
||||
SANDBOX, // Control manual del usuario (modo sandbox)
|
||||
DEMO, // Modo demo completo (auto-play)
|
||||
DEMO_LITE, // Modo demo lite (solo física/figuras)
|
||||
LOGO // Modo logo (easter egg)
|
||||
};
|
||||
#include "ui/ui_manager.h" // for UIManager
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
@@ -81,6 +72,7 @@ class Engine {
|
||||
// === Componentes del sistema (Composición) ===
|
||||
std::unique_ptr<InputHandler> input_handler_; // Manejo de entradas SDL
|
||||
std::unique_ptr<SceneManager> scene_manager_; // Gestión de bolas y física
|
||||
std::unique_ptr<UIManager> ui_manager_; // Gestión de UI (HUD, FPS, notificaciones)
|
||||
|
||||
// Recursos SDL
|
||||
SDL_Window* window_ = nullptr;
|
||||
@@ -98,27 +90,11 @@ class Engine {
|
||||
Uint64 last_frame_time_ = 0;
|
||||
float delta_time_ = 0.0f;
|
||||
|
||||
// UI y debug
|
||||
bool show_debug_ = false;
|
||||
bool show_text_ = true; // OBSOLETO: usar notifier_ en su lugar
|
||||
TextRenderer text_renderer_; // Sistema de renderizado de texto para display (centrado)
|
||||
TextRenderer text_renderer_debug_; // Sistema de renderizado de texto para debug (HUD)
|
||||
TextRenderer text_renderer_notifier_; // Sistema de renderizado de texto para notificaciones (tamaño fijo)
|
||||
Notifier notifier_; // Sistema de notificaciones estilo iOS/Android
|
||||
|
||||
// Sistema de zoom dinámico
|
||||
int current_window_zoom_ = DEFAULT_WINDOW_ZOOM;
|
||||
std::string text_;
|
||||
int text_pos_ = 0;
|
||||
Uint64 text_init_time_ = 0;
|
||||
|
||||
// FPS y V-Sync
|
||||
Uint64 fps_last_time_ = 0;
|
||||
int fps_frame_count_ = 0;
|
||||
int fps_current_ = 0;
|
||||
std::string fps_text_ = "FPS: 0";
|
||||
// V-Sync
|
||||
bool vsync_enabled_ = true;
|
||||
std::string vsync_text_ = "VSYNC ON";
|
||||
bool fullscreen_enabled_ = false;
|
||||
bool real_fullscreen_enabled_ = false;
|
||||
ScalingMode current_scaling_mode_ = ScalingMode::INTEGER; // Modo de escalado actual (F5)
|
||||
@@ -188,9 +164,7 @@ class Engine {
|
||||
void render();
|
||||
|
||||
// Métodos auxiliares privados (llamados por la interfaz pública)
|
||||
void setText(); // DEPRECATED - usar showNotificationForAction() en su lugar
|
||||
void showNotificationForAction(const std::string& text); // Mostrar notificación solo en modo MANUAL
|
||||
std::string gravityDirectionToString(GravityDirection direction) const;
|
||||
|
||||
// Sistema de gestión de estados (MANUAL/DEMO/DEMO_LITE/LOGO)
|
||||
void setState(AppMode new_mode); // Cambiar modo de aplicación (mutuamente excluyente)
|
||||
|
||||
Reference in New Issue
Block a user