PhoneFraming.component
README.md
gallery.PhoneFraming
Sits on the player prototype's camera rig and lays the Bastion Works gallery out for this player's screen, whatever its shape. It acts only while its rig is the camera drawing this screen, so another player's rig never touches the layout. Nothing it changes is synced, and it never writes a turret's own fields (only a turret's owner may change a synced entity): turret labels are placed for this screen with TK.setLabelPlacement, so it works the same for the host and for a player who joined.
How a layout is made
- Frame. When the screen changes shape it hides every label it owns (text and outline alpha to 0), picks the text for the shape, frames the camera and aims the floor pads at a share of the screen's height:
- upright: a wider view from further back (
portraitHalfWidth,portraitRadius,portraitHeight), pads atpadsAt; - sideways and desktop: the camera as built, pads at
landscapePadsAt; on a short screen (undershortScreenpx) further back and a little higher (shortRadius,shortHeight,shortPadsAt). On a sideways screen undershortScreenpx tall, this player's own kill feed showsshortFeedRowsrows (2), whatever size the UI is drawn at; this is re-applied four times a second and the scene's own count comes back when the screen grows.
- upright: a wider view from further back (
- Measure once, from a camera that has stopped (a quarter of a second still, in position and turn). Every turret label, pad sign and title line is measured as the engine's
billboardshader draws it (facing the camera, horizontal edge level). - Work it out. The whole layout is arithmetic on those measurements, binary-searched for the largest text that fits (lines at least
minLinepx):- pad signs stack upward from just above their pads;
- turret labels go in rows above the models (the wall's label clears Second Wind's health bar). Upright, a label moves up a row only when a neighbour is in the way. Sideways, neighbours alternate rows, each row spreads across the free width, and labels slide sideways by their anchor (Text3D's offset). Rows at the kill feed's height end left of it;
- the title block goes above the top row: stacked upright; sideways, one band (subtitle | title | hint) beside the kill feed, or two tiers when that doesn't fit;
- nothing may touch (gap max(3 px, 0.8% W)), come near an edge, or sit under the kill feed or this player's name tag. The work hands the frame back every 12 ms, so the game keeps running.
- Apply and check. The layout is applied in one go and measured again on screen from a still camera, the labels are shown, and
laidOutreadsok. If the screen disagrees with the arithmetic it starts over (up to three times). Sideways, the arithmetic keeps a couple of pixels of margin over the on-screen check, and a label slid sideways is re-aimed at its row (sliding along its face moves it nearer or further from the camera, so it drifts up or down). If nothing fits cleanly even after more room (up to four rounds upright; up to seven smaller steps back sideways), it shows its closest layout at the smallest size and readsclosest. If something it is measuring disappears mid-layout (a look swap rebuilds the labels), it shows the labels and lays out again.
It lays out again, without hiding, when a label's words change (a look swapped, a pad pressed, a joining player's turrets arriving) or the camera has moved and settled somewhere new. solveTrace lists each try (scale:result) and how long the layout took.
Checked
With a measuring script that projects every text box the same way, on the final build of 2.1.0, as the host, 17 runs, all clean (no overlap, no touch, nothing near an edge or under the kill feed, every gallery line at least 10 px):
- 844×390 (sideways), 9 runs: desktop-sized UI toy ×3 (one right after a swap from sci-fi), medieval, sci-fi; phone-sized UI toy ×2, medieval, sci-fi. The kill feed held 2 rows in each. Laid out in about 5 to 20 s.
- 390×844 (upright), 5 runs: phone-sized UI medieval ×2, toy, sci-fi; desktop-sized UI toy. About 6 to 15 s.
- 1280×720, 3 runs: all three looks. About 4 to 6 s.
As a joining player, upright, sideways and desktop were checked clean on the build before the sideways fixes, and not repeated on the final build.