Fixed the issue with the board display

This commit is contained in:
2025-12-24 14:39:40 +08:00
parent 3e9b69bcc9
commit f89c20af6a
3 changed files with 15 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
#include "SceneManager.h" #include "SceneManager.h"
#include "utils/Config.h"
SceneManager::SceneManager(SDL_Renderer* renderer, UIRenderer* uiRenderer, SDL_Window* window) : SceneManager::SceneManager(SDL_Renderer* renderer, UIRenderer* uiRenderer, SDL_Window* window) :
m_renderer(renderer), m_renderer(renderer),
m_uiRenderer(uiRenderer), m_uiRenderer(uiRenderer),
@@ -92,8 +92,8 @@ void SceneManager::pushScene(const std::string& sceneName) {
m_scene = it->second; 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()) { if (!m_scenes.empty()) {
m_scene = m_scenes.top(); m_scene = m_scenes.top();
m_scenes.pop(); m_scenes.pop();
auto [w, h] = getWindowDimensions();
if (m_scene) { 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; 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() { void SceneManager::renderUI() {
if (m_scene) m_scene->renderUI(); if (m_scene) m_scene->renderUI();
} }
/*
std::pair<int, int> SceneManager::getWindowDimensions() const { std::pair<int, int> SceneManager::getWindowDimensions() const {
// 获取窗口尺寸的辅助方法 // 获取窗口尺寸的辅助方法
int w = 0, h = 0; int w = 0, h = 0;
@@ -178,7 +178,7 @@ std::pair<int, int> SceneManager::getWindowDimensions() const {
} }
return {w > 0 ? w : 1600, h > 0 ? h : 900}; return {w > 0 ? w : 1600, h > 0 ? h : 900};
} }
*/
void SceneManager::handleSceneEvent(const SceneEvent& event) { void SceneManager::handleSceneEvent(const SceneEvent& event) {
// 根据事件类型处理场景事件 // 根据事件类型处理场景事件
switch (event.type) switch (event.type)

View File

@@ -130,10 +130,11 @@ private:
std::stack<std::shared_ptr<Scene>> m_scenes; ///< 场景栈,存储场景层级关系(使用 shared_ptr std::stack<std::shared_ptr<Scene>> m_scenes; ///< 场景栈,存储场景层级关系(使用 shared_ptr
std::unordered_map<std::string, std::shared_ptr<Scene>> m_sceneCache; ///< 场景缓存,按名字缓存场景以便切换时复用 std::unordered_map<std::string, std::shared_ptr<Scene>> m_sceneCache; ///< 场景缓存,按名字缓存场景以便切换时复用
std::unordered_map<std::string, std::function<std::shared_ptr<Scene>()>> m_sceneFactories; ///< 场景工厂映射,按名字动态创建场景实例 std::unordered_map<std::string, std::function<std::shared_ptr<Scene>()>> m_sceneFactories; ///< 场景工厂映射,按名字动态创建场景实例
/** /**
* @brief 获取窗口尺寸的辅助方法 * @brief 获取窗口尺寸的辅助方法
* @return 返回 {宽度, 高度},如果获取失败则返回默认值 {1600, 900} * @return 返回 {宽度, 高度},如果获取失败则返回默认值 {1600, 900}
*/ */
std::pair<int, int> getWindowDimensions() const; //std::pair<int, int> getWindowDimensions() const;
}; };

View File

@@ -40,12 +40,14 @@ namespace UI
constexpr int SlotSize = 16; constexpr int SlotSize = 16;
constexpr int PanelPadding = 4; constexpr int PanelPadding = 4;
constexpr int FontHeight = 8; constexpr int FontHeight = 8;
constexpr int LogicalWidth = 640;
constexpr int LogicalHeight = 360;
constexpr int StartWindowWidth = 320 * 4; // 初始窗口宽度(像素) constexpr int StartWindowWidth = 320 * 4; // 初始窗口宽度(像素)
constexpr int StartWindowHeight = 180 * 4; // 初始窗口高度(像素) constexpr int StartWindowHeight = 180 * 4; // 初始窗口高度(像素)
// 字体大小(逻辑像素) // 字体大小(逻辑像素)
constexpr int DIALOG_FONT_SIZE = 14; constexpr int DIALOG_FONT_SIZE = 14;
constexpr int UI_SMALL_FONT_SIZE = 8; 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; constexpr int UI_LARGE_FONT_SIZE = 16;