mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
change logictexture to 640x360
This commit is contained in:
@@ -35,7 +35,8 @@ bool WindowManager::Initialize(GameConfig& config) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关键设置:启用像素模式
|
|
||||||
|
|
||||||
|
|
||||||
/* // 设置逻辑呈现模式,实现分辨率自适应[3](@ref)
|
/* // 设置逻辑呈现模式,实现分辨率自适应[3](@ref)
|
||||||
SDL_SetRenderLogicalPresentation(m_renderer,
|
SDL_SetRenderLogicalPresentation(m_renderer,
|
||||||
|
|||||||
@@ -69,7 +69,65 @@ void TextRenderer::renderText(const std::string& text, TextStyle style, int x, i
|
|||||||
|
|
||||||
TextRenderer::CachedText TextRenderer::createAndCacheTexture(const std::string& text, TextStyle style) {
|
TextRenderer::CachedText TextRenderer::createAndCacheTexture(const std::string& text, TextStyle style) {
|
||||||
CachedText result = {nullptr, 0, 0, std::time(nullptr)};
|
CachedText result = {nullptr, 0, 0, std::time(nullptr)};
|
||||||
|
/*
|
||||||
|
// 获取字体 - 需要大号字体用于高清渲染
|
||||||
|
const int TARGET_SCALE = 4; // 4倍超采样
|
||||||
|
int largeFontSize = style.fontSize * TARGET_SCALE;
|
||||||
|
TTF_Font* largeFont = m_fontManager->getFont(style.fontID, largeFontSize);
|
||||||
|
|
||||||
|
if (!largeFont) {
|
||||||
|
SDL_Log("错误:字体未找到 %s\n", style.fontID.c_str());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 创建高清离屏纹理(大尺寸)
|
||||||
|
int targetWidth = 0, targetHeight = 0;
|
||||||
|
|
||||||
|
// SDL3 使用 TTF_GetTextSize 替代 TTF_SizeText
|
||||||
|
|
||||||
|
if (TTF_GetTextSize(largeFont, text.c_str(), &targetWidth, &targetHeight) < 0) {
|
||||||
|
SDL_Log("错误:无法测量文本尺寸: %s\n", text.c_str());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算高清纹理尺寸
|
||||||
|
int hiResWidth = targetWidth * TARGET_SCALE;
|
||||||
|
int hiResHeight = targetHeight * TARGET_SCALE;
|
||||||
|
|
||||||
|
// 创建高清渲染目标纹理
|
||||||
|
SDL_Texture* hiResTexture = SDL_CreateTexture(
|
||||||
|
m_renderer,
|
||||||
|
SDL_PIXELFORMAT_RGBA8888,
|
||||||
|
SDL_TEXTUREACCESS_TARGET,
|
||||||
|
hiResWidth,
|
||||||
|
hiResHeight
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hiResTexture) {
|
||||||
|
SDL_Log("错误:无法创建高清纹理\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置高清纹理属性
|
||||||
|
SDL_SetTextureScaleMode(hiResTexture, SDL_SCALEMODE_NEAREST);
|
||||||
|
SDL_SetTextureBlendMode(hiResTexture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
// 2. 渲染到大尺寸高清纹理
|
||||||
|
SDL_Texture* prevTarget = SDL_GetRenderTarget(m_renderer);
|
||||||
|
SDL_SetRenderTarget(m_renderer, hiResTexture);
|
||||||
|
|
||||||
|
// 用透明色清空高清纹理
|
||||||
|
SDL_SetRenderDrawColor(m_renderer, 0, 0, 0, 0);
|
||||||
|
SDL_RenderClear(m_renderer);
|
||||||
|
|
||||||
|
|
||||||
|
// 创建文字表面
|
||||||
|
SDL_Surface* surface = TTF_RenderText_Solid(largeFont, text.c_str(),text.length(), style.color);
|
||||||
|
if (!surface) {
|
||||||
|
SDL_Log("错误:无法创建文字表面 '%s'\n", text.c_str());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
*/
|
||||||
// 获取字体
|
// 获取字体
|
||||||
TTF_Font* font = m_fontManager->getFont(style.fontID, style.fontSize);
|
TTF_Font* font = m_fontManager->getFont(style.fontID, style.fontSize);
|
||||||
if (!font) {
|
if (!font) {
|
||||||
|
|||||||
26
src/ui/base/UIWidgetFactory.h
Normal file
26
src/ui/base/UIWidgetFactory.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ui/components/Button.h"
|
||||||
|
#include "ui/components/Label.h"
|
||||||
|
class UIWidgetFactory {
|
||||||
|
public:
|
||||||
|
|
||||||
|
static std::unique_ptr<Button> createStandardButton(const std::string& name, const std::string& text, int x, int y, std::function<void()> callback) {
|
||||||
|
auto button = std::make_unique<Button>();
|
||||||
|
button->setBackgroundColor({0, 150, 255, 255});
|
||||||
|
button->setBorder(2, {0, 0, 0, 255});
|
||||||
|
button->setRect(x, y, UI::ButtonSize * 6, UI::ButtonSize * 4);
|
||||||
|
button->setName(name);
|
||||||
|
button->setText(text, {"SourceHanSansSC-Regular.otf", UI::UI_NORMAL_FONT_SIZE, {255, 255, 255, 255}});
|
||||||
|
button->setCallback(callback);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::unique_ptr<Label> createStandardLabel(const std::string& name, const std::string& text, int x, int y) {
|
||||||
|
auto label = std::make_unique<Label>();
|
||||||
|
label->setRect(x, y, UI::ButtonSize * 4, UI::ButtonSize * 2);
|
||||||
|
label->setText(text, {"SourceHanSansSC-Regular.otf", UI::UI_NORMAL_FONT_SIZE, {0, 0, 0, 255}});
|
||||||
|
label->setName(name);
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "MainMenuUIManager.h"
|
#include "MainMenuUIManager.h"
|
||||||
#include "utils/CoordinateTools.h"
|
#include "utils/CoordinateTools.h"
|
||||||
|
#include "ui/base/UIWidgetFactory.h"
|
||||||
MainMenuUIManager::MainMenuUIManager(SDL_Renderer* renderer,
|
MainMenuUIManager::MainMenuUIManager(SDL_Renderer* renderer,
|
||||||
TextRenderer* textRenderer,
|
TextRenderer* textRenderer,
|
||||||
SceneEventCallback eventCallback) {
|
SceneEventCallback eventCallback) {
|
||||||
@@ -13,28 +14,13 @@ MainMenuUIManager::~MainMenuUIManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenuUIManager::init() {
|
void MainMenuUIManager::init() {
|
||||||
auto button = std::make_unique<Button>();
|
auto startButton = UIWidgetFactory::createStandardButton(
|
||||||
|
"StartButton", "开始游戏", 0, 0,
|
||||||
|
[this]() { m_eventCallback("GameScene"); }
|
||||||
|
);
|
||||||
|
|
||||||
button->setBackgroundColor({0, 150, 255, 255});
|
m_buttons.emplace(startButton->getNameHash(), std::move(startButton));
|
||||||
|
auto label = UIWidgetFactory::createStandardLabel("MousePositionLabel", "0 0", 240, 0);
|
||||||
button->setBorder(2, {0, 0, 0, 255});
|
|
||||||
|
|
||||||
button->setRect(0, 0, UI::ButtonSize * 4, UI::ButtonSize * 2);
|
|
||||||
|
|
||||||
button->setName("StartButton");
|
|
||||||
|
|
||||||
button->setText("Start Game", {"SourceHanSansSC-Regular.otf", UI::UI_NORMAL_FONT_SIZE, {255, 255, 255, 255}});
|
|
||||||
|
|
||||||
button->setCallback([this](){
|
|
||||||
SDL_Log("Start Game button clicked!");
|
|
||||||
m_eventCallback("GameScene");
|
|
||||||
});
|
|
||||||
|
|
||||||
m_buttons.emplace(button->getNameHash(), std::move(button));
|
|
||||||
auto label = std::make_unique<Label>();
|
|
||||||
label->setRect(1200, 20, 200, 50);
|
|
||||||
label->setText("0 0", {"SourceHanSansSC-Regular.otf", 48, {0, 0, 0, 255}});
|
|
||||||
label->setName("MousePositionLabel");
|
|
||||||
m_labels.emplace(label->getNameHash(), std::move(label));
|
m_labels.emplace(label->getNameHash(), std::move(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ struct GameConfig {
|
|||||||
/*
|
/*
|
||||||
tileSize: 16x16 每个格子的逻辑大小(像素)
|
tileSize: 16x16 每个格子的逻辑大小(像素)
|
||||||
屏幕 = 20 × 11 tiles = 320x176 逻辑分辨率
|
屏幕 = 20 × 11 tiles = 320x176 逻辑分辨率
|
||||||
|
640x360 逻辑分辨率(窗口大小的1/2)
|
||||||
|
画面更高清晰
|
||||||
*/
|
*/
|
||||||
int logicalWidth = 320;
|
int logicalWidth = 640;
|
||||||
int logicalHeight = 180;
|
int logicalHeight = 360;
|
||||||
std::string windowTitle = "孢子棋";
|
std::string windowTitle = "孢子棋";
|
||||||
bool vsync = true;
|
bool vsync = true;
|
||||||
int scale = 2;
|
int scale = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user