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
+36
View File
@@ -1301,3 +1301,39 @@ Outstanding: no device run; minimap is still the original round one; labels
are English; chat input line can overlap the wheel's page button while typing;
no auto-hunt / target-lock buttons; Android keeps the 1024x768 letterboxed
logical size (step 5 scaling); the HUD reads the safe area only when built.
### 2026-10-12 Mobile step 5 — UI scaling and live safe area
- Logical UI size on phones / tablets (`platform::ChooseMobileLogicalSize`):
instead of letterboxing metin2.cfg's 1024x768, height =
clamp(round(height in dp x 1.5), 600, 768) and width = height x screen
aspect (landscape, even, at least 1024). A 2400x1080 phone at density 2.75
gets 1332x600, a 2400x1080 at 2.25 gets 1600x720, a 4:3 tablet 1024x768.
`--ui-height N` / `AVA2_UI_HEIGHT` override the height (600..1080).
`CPythonSystem::SetDisplaySizeOverride` makes `systemSetting.GetWidth/Height`
and the window manager report it without rewriting metin2.cfg.
Android / iOS read the primary display (`QueryDisplay`); desktop simulates
with `--phone WxH[@density]` (implies `--touch`) and `--safe-insets L,T,R,B`.
- Live safe area: on `SDL_EVENT_WINDOW_SAFE_AREA_CHANGED` / resize the host
resets the touch layout for the new insets; `MobileHUD.OnUpdate` sees
`touch.GetSafeArea()` change and rebuilds itself under a fresh root window
(old root hidden), re-registers the attack button and re-runs
`AdoptDefaultWindows` / `AdoptGameWindows` (minimap, chat, hint buttons,
buffs, event icon). Covers rotating 180 degrees with a side notch.
- HUD gauge backgrounds and frames are now kept referenced (they were
destroyed right after creation).
- Fixed the step-4 `touch_game` disc pixel check (threshold too high; the
earlier run used a stale test binary because the build stopped at the known
speedtree_forest_test errors without `-k`).
Verified: `ava2.platform` (size choice for phones, portrait-reported
displays, tablets, override clamp, near-square foldable, `--phone` parsing),
`ava2.touch_game` (running HUD relayouts on new insets and back, minimap and
buffs follow, attack button re-registered), 53/53 desktop tests,
`ava2_client --phone 2400x1080@2.75 --safe-insets 50,0,0,24 --phase game
--preview-data` renders 1332x600 full-bleed with the HUD inset.
Outstanding: not run on a device (display mode vs. immersive window size,
real cutout insets); a window size change at runtime (split screen,
foldable) keeps the logical size chosen at start; no in-game UI size option
yet (only `--ui-height` / env); original PC windows (inventory etc.) are
not rearranged for 600 px height.