#pragma once #include #include #include #include // Clase dedicada para manejar el sistema de pausa class PauseManager { public: // Enum encapsulado dentro de la clase enum class Source : uint8_t { NONE = 0, PLAYER = 1 << 0, // 0001 SERVICE_MENU = 1 << 1, // 0010 FOCUS_LOST = 1 << 2 // 0100 }; // Operadores para trabajar con las banderas (funciones friend) friend auto operator|(Source a, Source b) -> Source { return static_cast(static_cast(a) | static_cast(b)); } friend auto operator&(Source a, Source b) -> Source { return static_cast(static_cast(a) & static_cast(b)); } friend auto operator~(Source a) -> uint8_t { return ~static_cast(a); } friend auto operator&=(Source& a, uint8_t b) -> Source& { a = static_cast(static_cast(a) & b); return a; } friend auto operator|=(Source& a, Source b) -> Source& { return a = a | b; } friend auto operator&=(Source& a, Source b) -> Source& { return a = a & b; } private: Source flags_ = Source::NONE; std::function on_pause_changed_callback_; [[nodiscard]] auto hasFlag(Source flag) const -> bool { return (flags_ & flag) != Source::NONE; } void notifyPauseChanged() { if (on_pause_changed_callback_) { on_pause_changed_callback_(isPaused()); } } public: // Constructor con callback opcional explicit PauseManager(std::function callback = nullptr) : on_pause_changed_callback_(std::move(callback)) {} // Establece/quita una fuente de pausa específica void setFlag(Source source, bool enable) { bool was_paused = isPaused(); if (enable) { flags_ |= source; } else { flags_ &= ~source; // Ahora funciona: Source &= uint8_t } if (was_paused != isPaused()) { notifyPauseChanged(); } } // Métodos específicos para cada fuente void setPlayerPause(bool enable) { setFlag(Source::PLAYER, enable); } void setServiceMenuPause(bool enable) { setFlag(Source::SERVICE_MENU, enable); } void setFocusLossPause(bool enable) { setFlag(Source::FOCUS_LOST, enable); } // Toggle para el jugador (más común) void togglePlayerPause() { setPlayerPause(!isPlayerPaused()); } // Getters [[nodiscard]] auto isPaused() const -> bool { return flags_ != Source::NONE; } [[nodiscard]] auto isPlayerPaused() const -> bool { return hasFlag(Source::PLAYER); } [[nodiscard]] auto isServiceMenuPaused() const -> bool { return hasFlag(Source::SERVICE_MENU); } [[nodiscard]] auto isFocusLossPaused() const -> bool { return hasFlag(Source::FOCUS_LOST); } // Obtiene las banderas actuales [[nodiscard]] auto getFlags() const -> Source { return flags_; } // Limpia todas las pausas (útil para reset) void clearAll() { if (isPaused()) { flags_ = Source::NONE; notifyPauseChanged(); } } // Método para debug [[nodiscard]] auto getStatusString() const -> std::string { if (flags_ == Source::NONE) { return "Active"; } std::string result = "Paused by: "; bool first = true; if (hasFlag(Source::PLAYER)) { if (!first) { result += ", "; } result += "Player"; first = false; } if (hasFlag(Source::SERVICE_MENU)) { if (!first) { result += ", "; } result += "ServiceMenu"; first = false; } if (hasFlag(Source::FOCUS_LOST)) { if (!first) { result += ", "; } result += "FocusLoss"; } return result; } // Permite cambiar el callback en runtime void setCallback(std::function callback) { on_pause_changed_callback_ = callback; } };