commit be15fec65c089600d02ac609cabed90fc596c736
parent 946f0db40a3be135b8db0c7bd171ff1e6aa979ac
Author: anon <anon@example.com>
Date: Fri, 6 Nov 2026 03:41:18 +0000
Keep Options aligned with the toolbar after browser resize
Diffstat:
6 files changed, 135 insertions(+), 3 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -288,10 +288,14 @@ rewriting this document does not close them.
creation, without numeric suffixes. Completion: new visitors receive short
pronounceable names; focused tests cover collisions and concurrent creation,
and a capacity check establishes the usable name pool.
-- [ ] **Keep the custom overlay "opt" button visible after window resizing.**
+- [x] **Keep the custom overlay "opt" button visible after window resizing.**
Reported: the button appears to disappear after resizing the window.
Reproduce and fix the resize behavior. Completion: the button remains visible
and clickable after shrinking and enlarging the window.
+ November 5: reproduced stale native toolbar bounds after enlargement and
+ selection of individual buttons at narrow widths. Opt now follows the strip
+ attached to the current screen edge. Native hover/click checks pass through
+ seven sizes from 320x480 to 1600x900; see [resize verification](docs/browser-accounts.md#options-after-resizing).
- [ ] **Use a browser-native mouse cursor independent of game FPS.**
Replace the WebGL-rendered pointer while preserving AO's context-sensitive
cursor artwork and hotspots, visibility during right-button camera control,
diff --git a/client/browser/index.html b/client/browser/index.html
@@ -533,10 +533,11 @@ show();
gameToolbar.hidden = !ready;
touchControls.hidden = !isMobileBrowser || !ready || !touchEnabled.checked || playerMenu.open || !chatForm.hidden;
if (!isMobileBrowser && touchRegions) {
- // Use the native top strip's hit rectangles so resolution changes retain its alignment.
+ // Anchor to the current screen edge; native resize retains older hit rectangles.
let left = touchRegions.screenWidth;
for (const region of touchRegions.regions) {
- if (!region.world && !region.chat && region.top <= 0 && region.bottom > 0 && region.left > touchRegions.screenWidth / 2)
+ if (!region.world && !region.chat && region.top <= 0 && region.bottom > 0 &&
+ region.left > 0 && region.right === touchRegions.screenWidth)
left = Math.min(left, region.left);
}
gameToolbar.style.right = `${(touchRegions.screenWidth - left) * canvas.clientWidth / touchRegions.screenWidth + 6}px`;
diff --git a/client/tests/browser_controls.mjs b/client/tests/browser_controls.mjs
@@ -1300,3 +1300,31 @@ test('desktop Options follows native toolbar coordinates and the 150 CSS pixel r
assert.equal(toolbar.dataset.menuVisible, undefined);
assert.equal(game.document.activeElement, game.canvas);
});
+
+for (const width of [1600, 320]) {
+ test(`desktop Options stays beside the current toolbar after resizing to ${width}`, () => {
+ const game = page({navigator: {userAgent: 'Mozilla/5.0 (X11; Linux x86_64)'}});
+ const toolbar = game.element('#game-toolbar');
+ game.element('#menu-button').getBoundingClientRect = () => ({
+ left: width - parseFloat(toolbar.style.right) - 34, right: width - parseFloat(toolbar.style.right), top: 0, bottom: 24});
+ game.touchRegions({screenWidth: 1280, screenHeight: 900, regions: [
+ {left: 1088, top: 0, right: 1280, bottom: 20},
+ {left: 0, top: 0, right: 1280, bottom: 880, world: true}
+ ]});
+
+ game.canvas.clientWidth = width;
+ game.window.dispatchEvent(new Event('resize'));
+ game.touchRegions({screenWidth: width, screenHeight: 480, regions: [
+ {left: 1088, top: 0, right: 1280, bottom: 20},
+ {left: width - 192, top: 0, right: width, bottom: 20},
+ {left: 0, top: 0, right: width, bottom: 460, world: true}
+ ]});
+ game.fire('#canvas', 'pointermove', {pointerType: 'mouse', clientX: width - 210, clientY: 12});
+
+ assert.equal(toolbar.style.right, '198px');
+ assert.equal(toolbar.hidden, false);
+ assert.equal(toolbar.dataset.menuVisible, '');
+ game.fire('#menu-button', 'click');
+ assert.equal(game.element('#player-menu').open, true);
+ });
+}
diff --git a/docs/browser-accounts.md b/docs/browser-accounts.md
@@ -44,6 +44,26 @@ password changes, unchanged browser credential and uninterrupted game stream.
The success message was visually inspected. Logs are under
`local/alpha-account-source/`; native captures are under `local/password-options/`.
+## Options after resizing
+
+The native client retains an older top-strip hit rectangle after resizing.
+Selecting the leftmost upper-right rectangle placed Opt 320 pixels left of the
+visible toolbar when enlarging from 1280 to 1600 pixels. Its 150-pixel hover
+reveal then missed the expected location. Below 384 pixels, the old right-half
+filter also skipped the complete toolbar and selected individual button bounds.
+The overlay now anchors to the strip ending at the current native screen edge,
+keeping its six-CSS-pixel gap and existing hover, focus and dialog visibility.
+
+`TestBrowserOptionsResize` resizes a real client through 1280x900, 800x600,
+640x480, 390x500, 320x480, 1600x900 and 1024x768. At every size it verifies
+on-screen bounds and the gap, hovers beside the visible native toolbar, then
+clicks Opt and closes Options. The fixed run passes in 11.66 seconds with no
+browser errors; the narrow rendering was visually inspected. All 76 control
+checks and 13 account checks pass, including the focused stale/narrow bounds
+regressions that fail against the prior source. The regenerated page is
+published with its matching build metadata. Logs and captures are under
+`local/options-resize/`, with the native passing run in `20261105-193959/`.
+
## Account state and transactions
Private `characters.password_salt` and `password_hash` columns store a random
diff --git a/server/browser_options_resize_test.go b/server/browser_options_resize_test.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "context"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserOptionsResize(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for native Options resizing")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/options-resize", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ host := httptest.NewServer(world.httpHandler())
+ defer host.Close()
+ defer closeTestSessions(t, world)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_options_resize.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ t.Logf("Browser artifacts: %s", output)
+ if err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/tools/client/test_options_resize.mjs b/tools/client/test_options_resize.mjs
@@ -0,0 +1,44 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+const [url, output] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [
+ '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage']});
+let game;
+const observations = [];
+try {
+ const page = await browser.newPage({viewport: {width: 1280, height: 900}});
+ game = await GameTest.attach(page);
+ await page.goto(url);
+ await game.ready();
+ await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ for (const [width, height] of [[1280, 900], [800, 600], [640, 480], [390, 500], [320, 480], [1600, 900], [1024, 768]]) {
+ await page.setViewportSize({width, height});
+ await game.wait('native viewport resized', state => state.screen[0] === width && state.screen[1] === height);
+ const bounds = await page.locator('#menu-button').boundingBox();
+ const observation = {width, height, bounds, layout: await page.evaluate(() => ({
+ hidden: document.querySelector('#game-toolbar').hidden,
+ right: document.querySelector('#game-toolbar').style.right, touchRegions}))};
+ observations.push(observation);
+ console.log('RESIZE', width, height, bounds, observation.layout.right);
+ assert(bounds && bounds.x >= 0 && bounds.x + bounds.width <= width && bounds.y >= 0 && bounds.y + bounds.height <= height);
+ // The original top strip is 192 native pixels wide in CSS-pixel mode.
+ assert.equal(bounds.x + bounds.width, width - 192 - 6);
+ await page.mouse.move(width - 210, 12);
+ await page.waitForFunction(() => getComputedStyle(document.querySelector('#menu-button')).opacity === '1');
+ await page.locator('#menu-button').click();
+ assert(await page.locator('#player-menu').evaluate(menu => menu.open));
+ await page.locator('#player-menu').getByRole('button', {name: 'Close', exact: true}).click();
+ await game.save(output + '/' + width + 'x' + height);
+ }
+ assert.deepEqual(game.errors, []);
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/observations.json', JSON.stringify(observations, null, 2) + '\n');
+ if (game) await game.save(output + '/final');
+ } finally { await browser.close(); }
+}