Mobile UI scaling and live safe-area relayout (mobile step 5)

Phones and tablets pick the logical UI size from the screen (height
600..768 from the dp height, width from the aspect ratio) instead of
letterboxing 1024x768; metin2.cfg is left untouched via a display-size
override. --phone/--safe-insets/--ui-height simulate on desktop. The
mobile HUD rebuilds and re-adopts the original windows when the safe
area changes. Keeps HUD gauge backgrounds alive and fixes the step-4
disc pixel check threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 21:39:58 +09:00
co-authored by Claude Opus 5.5
parent 11bd94d1ce
commit ed2c185135
10 changed files with 232 additions and 23 deletions
+28
View File
@@ -77,12 +77,40 @@ void TestTouchLayout() {
assert(safe.joy_y + safe.joy_h <= 720 - 30 + 0.01f);
}
void TestMobileLogicalSize() {
using ava2::platform::ChooseMobileLogicalSize;
using ava2::platform::LogicalSize;
// 20:9 phone, 2400x1080 at density 2.75 (393 dp tall): height floor 600, width by aspect.
assert((ChooseMobileLogicalSize(2400, 1080, 2.75f) == LogicalSize{1332, 600}));
// Reported in portrait before the landscape activity rotates: same result.
assert((ChooseMobileLogicalSize(1080, 2400, 2.75f) == LogicalSize{1332, 600}));
// A larger 1.5x-density phone (480 dp tall) gets more UI pixels.
assert((ChooseMobileLogicalSize(2400, 1080, 2.25f) == LogicalSize{1600, 720}));
// 4:3 tablet: height cap 768 -> 1024x768, no letterbox.
assert((ChooseMobileLogicalSize(2048, 1536, 2.0f) == LogicalSize{1024, 768}));
// 16:10 tablet.
assert((ChooseMobileLogicalSize(1920, 1200, 1.5f) == LogicalSize{1228, 768}));
// Override (setting / --ui-height), clamped to 600..1080.
assert((ChooseMobileLogicalSize(2400, 1080, 2.75f, 720) == LogicalSize{1600, 720}));
assert((ChooseMobileLogicalSize(2400, 1080, 2.75f, 100) == LogicalSize{1332, 600}));
// Near-square foldable: the width floor 1024 wins.
assert((ChooseMobileLogicalSize(2208, 1768, 2.6f) == LogicalSize{1024, 820}));
assert((ChooseMobileLogicalSize(0, 0, 1.0f) == LogicalSize{1024, 768}));
float w = 0, h = 0, d = 0;
assert(ava2::platform::ParsePhoneSpec("2400x1080@2.75", &w, &h, &d) && Near(w, 2400) && Near(h, 1080) && Near(d, 2.75f));
assert(ava2::platform::ParsePhoneSpec("1600x720", &w, &h, &d) && Near(d, 1.0f));
assert(!ava2::platform::ParsePhoneSpec("phone", &w, &h, &d));
assert(!ava2::platform::ParsePhoneSpec("0x720", &w, &h, &d));
}
} // namespace
int main() {
TestLifecycle();
TestSafeInsets();
TestTouchLayout();
TestMobileLogicalSize();
std::cout << "Platform lifecycle and safe area insets behave\n";
return 0;
}