From f89c20af6a392da461c20cfa9f57b77bf4ec8238 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Wed, 24 Dec 2025 14:39:40 +0800 Subject: [PATCH] Fixed the issue with the board display --- src/scenes/base/SceneManager.cpp | 18 +++++++++--------- src/scenes/base/SceneManager.h | 5 +++-- src/utils/Config.h | 4 +++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/scenes/base/SceneManager.cpp b/src/scenes/base/SceneManager.cpp index 0830685..daddd91 100644 --- a/src/scenes/base/SceneManager.cpp +++ b/src/scenes/base/SceneManager.cpp @@ -1,5 +1,5 @@ #include "SceneManager.h" - +#include "utils/Config.h" SceneManager::SceneManager(SDL_Renderer* renderer, UIRenderer* uiRenderer, SDL_Window* window) : m_renderer(renderer), m_uiRenderer(uiRenderer), @@ -92,8 +92,8 @@ void SceneManager::pushScene(const std::string& sceneName) { m_scene = it->second; - auto [w, h] = getWindowDimensions(); - m_scene->onEnter(m_renderer, w, h, m_uiRenderer); + + m_scene->onEnter(m_renderer, UI::LogicalWidth, UI::LogicalHeight, m_uiRenderer); } @@ -108,9 +108,9 @@ void SceneManager::popScene() { if (!m_scenes.empty()) { m_scene = m_scenes.top(); m_scenes.pop(); - auto [w, h] = getWindowDimensions(); + if (m_scene) { - m_scene->onEnter(m_renderer, w, h, m_uiRenderer); + m_scene->onEnter(m_renderer, UI::LogicalWidth, UI::LogicalHeight, m_uiRenderer); } } } @@ -141,8 +141,8 @@ void SceneManager::changeScene(const std::string& sceneName) { // 切换到目标场景 m_scene = target; - auto [w, h] = getWindowDimensions(); - m_scene->onEnter(m_renderer, w, h, m_uiRenderer); + + m_scene->onEnter(m_renderer, UI::LogicalWidth, UI::LogicalHeight, m_uiRenderer); } @@ -169,7 +169,7 @@ void SceneManager::renderWorld() { void SceneManager::renderUI() { if (m_scene) m_scene->renderUI(); } - +/* std::pair SceneManager::getWindowDimensions() const { // 获取窗口尺寸的辅助方法 int w = 0, h = 0; @@ -178,7 +178,7 @@ std::pair SceneManager::getWindowDimensions() const { } return {w > 0 ? w : 1600, h > 0 ? h : 900}; } - +*/ void SceneManager::handleSceneEvent(const SceneEvent& event) { // 根据事件类型处理场景事件 switch (event.type) diff --git a/src/scenes/base/SceneManager.h b/src/scenes/base/SceneManager.h index 4e80b3a..fc2eebe 100644 --- a/src/scenes/base/SceneManager.h +++ b/src/scenes/base/SceneManager.h @@ -130,10 +130,11 @@ private: std::stack> m_scenes; ///< 场景栈,存储场景层级关系(使用 shared_ptr) std::unordered_map> m_sceneCache; ///< 场景缓存,按名字缓存场景以便切换时复用 std::unordered_map()>> m_sceneFactories; ///< 场景工厂映射,按名字动态创建场景实例 - + /** * @brief 获取窗口尺寸的辅助方法 * @return 返回 {宽度, 高度},如果获取失败则返回默认值 {1600, 900} */ - std::pair getWindowDimensions() const; + //std::pair getWindowDimensions() const; + }; \ No newline at end of file diff --git a/src/utils/Config.h b/src/utils/Config.h index aadba75..2f42a54 100644 --- a/src/utils/Config.h +++ b/src/utils/Config.h @@ -40,12 +40,14 @@ namespace UI constexpr int SlotSize = 16; constexpr int PanelPadding = 4; constexpr int FontHeight = 8; + constexpr int LogicalWidth = 640; + constexpr int LogicalHeight = 360; constexpr int StartWindowWidth = 320 * 4; // 初始窗口宽度(像素) constexpr int StartWindowHeight = 180 * 4; // 初始窗口高度(像素) // 字体大小(逻辑像素) constexpr int DIALOG_FONT_SIZE = 14; constexpr int UI_SMALL_FONT_SIZE = 8; - constexpr int UI_NORMAL_FONT_SIZE = 12; + constexpr int UI_NORMAL_FONT_SIZE = 14; constexpr int UI_LARGE_FONT_SIZE = 16;