移动端界面大小设置:默认 600 逻辑高,系统选项可选 600/700/800
Android 上 40250 界面原先固定按 800 逻辑像素高排版,弹窗文字在手机上只有约 1 mm 高。 - UIScaleMode.h + host ui_scale.cpp:逻辑高度来自保存的设置(默认 600),ui_height.cfg 保存,下次启动生效; 桌面可用 MT_UI_HEIGHT 测试 - app.GetUIHeight/GetAppliedUIHeight/SetUIHeight - mt_uiscale PORT 模块:系统选项对话框加高一行,"界面大小 大/中/小",修改后聊天提示重启生效 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e33e41c12b
commit
71d8f8c6e7
@@ -25,6 +25,7 @@ set(MT_NATIVE_RENDER_SOURCES
|
||||
vulkan_window.cpp
|
||||
sdl_window.cpp
|
||||
ui_batches.cpp
|
||||
ui_scale.cpp
|
||||
vk_device.cpp
|
||||
vk_frame.cpp
|
||||
vk_pipelines.cpp
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "native_audio.h"
|
||||
#include "perf_log.h"
|
||||
#include "texture_decode.h"
|
||||
#include "ui_scale.h"
|
||||
#include "vulkan_window.h"
|
||||
|
||||
#include "platform/MilesLib/AudioCommands.h"
|
||||
@@ -452,6 +453,7 @@ int run_live_client(
|
||||
};
|
||||
while ((frames == 0 || completed < frames) && renderer.poll(true) && PythonBoot::IsAppLooping()) {
|
||||
apply_policy();
|
||||
save_ui_height_if_changed();
|
||||
double pace_ms = 0.0;
|
||||
if (cap_period.count()) {
|
||||
// Fixed cadence: a late frame starts the next one at once, a frame more than one period
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "input_keymap.h"
|
||||
#include "texture_decode.h"
|
||||
#include "ui_scale.h"
|
||||
|
||||
#ifdef MT_NATIVE_HAS_LIVE_CLIENT
|
||||
#include "platform/ScriptLib/PythonBoot.h"
|
||||
@@ -141,20 +142,17 @@ void VulkanWindow::request_screenshot(std::string path, std::uint64_t frame) {
|
||||
std::uint32_t VulkanWindow::logical_width() const {
|
||||
int w = 0, h = 0;
|
||||
if (window_) SDL_GetWindowSize(window_, &w, &h);
|
||||
#ifdef __ANDROID__
|
||||
// Keep the 40250 UI at the same height as the macOS 1280x800 window,
|
||||
// while retaining the device aspect ratio on wider phone displays.
|
||||
if (w > 0 && h > 0) return std::max(1, int(std::lround(double(w) * 800.0 / h)));
|
||||
#endif
|
||||
// The UI size setting (ui_scale.h; always on Android, MT_UI_HEIGHT on the desktop) fixes the logical
|
||||
// height and keeps the device aspect ratio on wider phone displays.
|
||||
if (const int ui_h = mt_host::ui_height(); ui_h > 0 && w > 0 && h > 0)
|
||||
return std::max(1, int(std::lround(double(w) * ui_h / h)));
|
||||
return w > 0 ? static_cast<std::uint32_t>(w) : extent_.width;
|
||||
}
|
||||
|
||||
std::uint32_t VulkanWindow::logical_height() const {
|
||||
int w = 0, h = 0;
|
||||
if (window_) SDL_GetWindowSize(window_, &w, &h);
|
||||
#ifdef __ANDROID__
|
||||
if (w > 0 && h > 0) return 800;
|
||||
#endif
|
||||
if (const int ui_h = mt_host::ui_height(); ui_h > 0 && w > 0 && h > 0) return std::uint32_t(ui_h);
|
||||
return h > 0 ? static_cast<std::uint32_t>(h) : extent_.height;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "ui_scale.h"
|
||||
|
||||
#include "platform/EterBase/UIScaleMode.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace mt_host {
|
||||
namespace {
|
||||
|
||||
std::string settings_path() {
|
||||
std::string dir;
|
||||
if (char* pref = SDL_GetPrefPath("metin2port", "client")) {
|
||||
dir = pref;
|
||||
SDL_free(pref);
|
||||
}
|
||||
return dir + "ui_height.cfg";
|
||||
}
|
||||
|
||||
int g_saved = 0;
|
||||
|
||||
} // namespace
|
||||
|
||||
int ui_height() {
|
||||
static const int height = [] {
|
||||
int saved = 0;
|
||||
#ifdef __ANDROID__
|
||||
saved = MtUIScale::c_iDefaultHeight;
|
||||
if (std::ifstream in{settings_path()}; in) {
|
||||
int value = 0;
|
||||
if (in >> value && MtUIScale::IsValid(value)) saved = value;
|
||||
}
|
||||
#endif
|
||||
int applied = saved;
|
||||
if (const char* env = std::getenv("MT_UI_HEIGHT"); env && *env) {
|
||||
const int value = std::atoi(env);
|
||||
if (MtUIScale::IsValid(value)) applied = saved = value;
|
||||
}
|
||||
g_saved = saved;
|
||||
MtUIScale::Applied().store(applied);
|
||||
MtUIScale::Chosen().store(saved);
|
||||
return applied;
|
||||
}();
|
||||
return height;
|
||||
}
|
||||
|
||||
void save_ui_height_if_changed() {
|
||||
const int chosen = MtUIScale::Chosen().load(std::memory_order_relaxed);
|
||||
if (!chosen || chosen == g_saved) return;
|
||||
g_saved = chosen;
|
||||
std::ofstream out{settings_path(), std::ios::trunc};
|
||||
out << chosen << '\n';
|
||||
}
|
||||
|
||||
} // namespace mt_host
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace mt_host {
|
||||
|
||||
// The logical UI height (platform/EterBase/UIScaleMode.h): the saved setting on Android, MT_UI_HEIGHT on
|
||||
// the desktop (a test override that also shows the option), 0 when the window's own size is the UI size.
|
||||
// Loaded on first use, which needs SDL initialised.
|
||||
int ui_height();
|
||||
|
||||
// Writes the player's choice from the system option dialog when it differs from the saved one.
|
||||
void save_ui_height_if_changed();
|
||||
|
||||
} // namespace mt_host
|
||||
Reference in New Issue
Block a user