From 68363bf20d274956d56917d94cd2cf1dbaf21bec Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:13:38 +0000 Subject: [PATCH 01/13] Update README to reflect current project plans Removed outdated features from planned expansions section. --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 3bcbc7d1..927ded5c 100644 --- a/README.md +++ b/README.md @@ -134,11 +134,8 @@ asyncao -debug # pprof on localhost:6060 Planned, not yet built but future expansions: - **Eventual mobile support** — native Android / iOS binaries. -- Eventual Legacy AO2 demo file converter to MP4/Video, for Archival. THIS IS MOSTLY DONE. PROBABLY NEEDS SOME IMPROVEMENTS BUT THIS IS A GOOD STATE. - Dedicated built in theme builder so people can easily make AsyncAO themes by importing images, fonts, colours and exporting them for later. Encourages people to stop relying on QT based themes, while making the proccess streamlined and easy for anyone. -- Lua plugin system so people can add lua plugins and make modifications to the client behaviour or features. -- Migrate to SDL3 -- + ## Credits All credit to the original Attorney Online developers — AsyncAO exists because From e4e0ae32afbea19079ff31cf20e7b83e1aebb04e Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 03:43:12 +0100 Subject: [PATCH 02/13] assets: a one-frame animated WebP decodes to its frame A WebP with the animation flag and a single frame produced no texture at all. Decode drops frame 0 when the first-frame decode says the file isn't animated (so a GIF or APNG that turns out static isn't uploaded twice), but the file still went down the streaming path, which appends only frames after frame 0 and then closes a page that was never made. The speaker's sprite then never arrived: strict sequencing held every message using it for the full 10 s, and each re-ask decoded the file again for nothing. Seen with Patty Thompson's "(a)/embarrassed" on miku.pizza. The stream now runs only when frame 0 went out as its first chunk; otherwise the file decodes as a still. Co-Authored-By: Claude Opus 5.5 --- internal/assets/decoder.go | 8 +++- internal/assets/webp_cgo_test.go | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/internal/assets/decoder.go b/internal/assets/decoder.go index 3d95290f..1b16361a 100644 --- a/internal/assets/decoder.go +++ b/internal/assets/decoder.go @@ -659,6 +659,8 @@ func (p *DecoderPool) runJob(req DecodeRequest) { defer p.animGate.release() } + // established is whether frame 0 went out as a stream's first chunk; the stream appends only frames after it. + established := false if animated { if first, err := DecodeImage(req.Data, false); err == nil { // GIF/APNG can sniff "maybe" but decode static, and a static would upload the same texture twice. @@ -673,6 +675,7 @@ func (p *DecoderPool) runJob(req DecodeRequest) { if streamable { // Streaming pages grow frame by frame; frame 0 is the first chunk. first.Stream = true + established = true } req.OnDone(req.URL, first, nil) } else { @@ -681,8 +684,9 @@ func (p *DecoderPool) runJob(req DecodeRequest) { } } - // The definitely-animated CGO formats stream: frames land one at a time and the page plays what has arrived. - if streamable { + // The definitely-animated CGO formats stream: frames land one at a time and the page plays what has arrived. A file + // with the animation flag and one frame decodes as a still, as no stream ever sends its frame 0. + if streamable && established { p.streamAnimated(req) return } diff --git a/internal/assets/webp_cgo_test.go b/internal/assets/webp_cgo_test.go index 128ea4d1..ec817ddd 100644 --- a/internal/assets/webp_cgo_test.go +++ b/internal/assets/webp_cgo_test.go @@ -3,6 +3,7 @@ package assets import ( + "encoding/binary" "os" "path/filepath" "testing" @@ -213,3 +214,73 @@ func BenchmarkDecodeWebPAnim_256x192_3f(b *testing.B) { d.Release() } } + +// oneFrameAnimatedWebP wraps a still lossy WebP in the animation chunks, as encoders that keep the ANIM flag for a single +// frame write it; webpmux and img2webp both collapse one frame to a still, so the fixture is built here. +func oneFrameAnimatedWebP(t *testing.T, still []byte, w, h int) []byte { + t.Helper() + const ( + riffHeader = 12 + vp8xAnimFlag = 0x02 + frameMs = 150 + ) + if string(still[riffHeader:riffHeader+4]) != "VP8 " { + t.Fatalf("fixture chunk %q, want a lossy VP8 still", still[riffHeader:riffHeader+4]) + } + frame := still[riffHeader:] // the VP8 chunk, header and padding included + u24 := func(b []byte, v int) []byte { return append(b, byte(v), byte(v>>8), byte(v>>16)) } + chunk := func(b []byte, kind string, body []byte) []byte { + b = append(b, kind...) + b = binary.LittleEndian.AppendUint32(b, uint32(len(body))) + b = append(b, body...) + if len(body)%2 == 1 { + b = append(b, 0) + } + return b + } + vp8x := u24(u24([]byte{vp8xAnimFlag, 0, 0, 0}, w-1), h-1) + anim := []byte{0, 0, 0, 0, 0, 0} // background colour, loop forever + anmf := u24(u24(u24(u24(u24(nil, 0), 0), w-1), h-1), frameMs) + anmf = append(append(anmf, 0), frame...) + body := chunk(chunk(chunk([]byte("WEBP"), "VP8X", vp8x), "ANIM", anim), "ANMF", anmf) + out := binary.LittleEndian.AppendUint32([]byte("RIFF"), uint32(len(body))) + return append(out, body...) +} + +func TestAOneFrameAnimationDecodesToItsFrame(t *testing.T) { + const w, h = 256, 192 + data := oneFrameAnimatedWebP(t, fixture(t, "sprite_256x192.webp"), w, h) + if Sniff(data) != FormatWebPAnim { + t.Fatalf("built %v, want an animated webp", Sniff(data)) + } + const wait = 5 * time.Second + pool := NewDecoderPool(1) + defer pool.Close() + got := make(chan *Decoded, 4) + pool.Submit(DecodeRequest{ + URL: "x", Data: data, Type: AssetTypeCharSprite, PlayAnimations: true, + OnDone: func(_ string, d *Decoded, err error) { + if err != nil { + t.Errorf("decode: %v", err) + d = &Decoded{} + } + got <- d + }, + }) + var frames int + var final *Decoded + for final == nil { + select { + case d := <-got: + frames += len(d.Frames) + if !d.Partial { + final = d + } + case <-time.After(wait): + t.Fatalf("no final page after %d frames", frames) + } + } + if final == nil || frames != 1 || final.Width != w || final.Height != h { + t.Fatalf("delivered %d frames, final %+v; want one %dx%d frame and a final page", frames, final, w, h) + } +} From 6f0d1b8aef0efb2de63c80fd0378e8999cbb8a7c Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 03:59:29 +0100 Subject: [PATCH 03/13] wardrobe: a setting to wear a character with one click Settings > General > Wardrobe gets "Click: Selects / Wears". With Wears, one click on a character does what double-click does: switch to it when its slot is free, else wear it as an iniswap. Only the first click of a same-spot streak wears, so a double-click out of habit doesn't wear the character a second time, which would turn the switch into an iniswap. The hint shown with nothing selected follows the setting. Off by default; stored as wardrobeSingleClick. Co-Authored-By: Claude Opus 5.5 --- internal/config/settings.go | 2 ++ internal/config/settings_clone.go | 3 ++ internal/ui/settingswardrobe.go | 28 ++++++++++++++++++ internal/ui/wardrobedraw.go | 16 ++++++++-- internal/ui/wardrobewin_test.go | 49 +++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 3 deletions(-) diff --git a/internal/config/settings.go b/internal/config/settings.go index 1a2b1786..2294e06c 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -261,6 +261,8 @@ type Settings struct { WardrobeIconPxVal int `json:"wardrobeIconPx,omitempty"` // WardrobeNameAbove puts a grid card's name above its icon instead of below. WardrobeNameAbove bool `json:"wardrobeNameAbove,omitempty"` + // WardrobeSingleClick makes one click on a character wear it, as double-click does. + WardrobeSingleClick bool `json:"wardrobeSingleClick,omitempty"` // WardrobeAccentVal is the Wardrobe's highlight colour, packed 0xRRGGBB; 0 is the default blue. WardrobeAccentVal int `json:"wardrobeAccent,omitempty"` CustomChromeHex [7]string `json:"customChrome"` diff --git a/internal/config/settings_clone.go b/internal/config/settings_clone.go index 6a395d8e..b8ba2bb5 100644 --- a/internal/config/settings_clone.go +++ b/internal/config/settings_clone.go @@ -1230,6 +1230,9 @@ func (s *Settings) equal(o *Settings) bool { if s.WardrobeNameAbove != o.WardrobeNameAbove { return false } + if s.WardrobeSingleClick != o.WardrobeSingleClick { + return false + } if s.WardrobeAccentVal != o.WardrobeAccentVal { return false } diff --git a/internal/ui/settingswardrobe.go b/internal/ui/settingswardrobe.go index 600a06ed..0f445b0d 100644 --- a/internal/ui/settingswardrobe.go +++ b/internal/ui/settingswardrobe.go @@ -87,6 +87,7 @@ func (a *App) drawWardrobeSettings(y, w int32) int32 { "Character icons are 40 × 40; the larger sizes double or triple them. The List view keeps them at 40.") y += btnH + wardSetRowGap y = a.drawWardrobeNamePlacement(y) + y = a.drawWardrobeClick(y) return a.drawWardrobeAccentPicker(y) } @@ -117,6 +118,33 @@ func (a *App) drawWardrobeNamePlacement(y int32) int32 { return y + btnH + wardSetRowGap } +// drawWardrobeClick picks whether one click on a character selects it or wears it. +func (a *App) drawWardrobeClick(y int32) int32 { + c := a.ctx + pad := a.formX + c.Label(pad, y+wardSetLabelY, "Click", ColText) + single := a.d.Prefs.Load().WardrobeSingleClick + x := pad + panelFontLabelW + for _, ch := range [...]struct { + single bool + label string + }{{false, "Selects"}, {true, "Wears"}} { + r := sdl.Rect{X: x, Y: y, W: wardSetChoiceW, H: btnH} + bg, fg := ColPanel, ColText + if ch.single == single { + bg, fg = ColAccent, ColBackground + } + if c.ButtonCol(r, ch.label, bg, ColPanelHi, ColAccent, fg) && ch.single != single { + next := ch.single + a.d.Prefs.Update(func(sn *config.Settings) { sn.WardrobeSingleClick = next }) + } + x += wardSetChoiceW + wardSetGap + } + c.Tooltip(sdl.Rect{X: pad + panelFontLabelW, Y: y, W: x - pad - panelFontLabelW, H: btnH}, + "What one click on a character does. Wears: it switches to the character, or wears it as an iniswap when its slot is taken, as double-click does.") + return y + btnH + wardSetRowGap +} + // drawWardrobeAccentPicker is the Wardrobe's highlight colour: selections, the active buttons, focused fields and // drop outlines. It reuses the log highlight's wheel, slider and hex field. func (a *App) drawWardrobeAccentPicker(y int32) int32 { diff --git a/internal/ui/wardrobedraw.go b/internal/ui/wardrobedraw.go index 3c329e5c..73823e95 100644 --- a/internal/ui/wardrobedraw.go +++ b/internal/ui/wardrobedraw.go @@ -1150,7 +1150,7 @@ func (a *App) drawWardrobeItem(idx int, it wardrobe.Item, r sdl.Rect) { a.wardrobeItemInput(it, r) } -// wardrobeItemInput selects on click, uses on double-click, and arms a drag on press. +// wardrobeItemInput selects on click, uses on double-click (or on click with single click on), and arms a drag on press. func (a *App) wardrobeItemInput(it wardrobe.Item, r sdl.Rect) { c := a.ctx ward := &a.ward @@ -1173,14 +1173,20 @@ func (a *App) wardrobeItemInput(it wardrobe.Item, r sdl.Rect) { if c.mouseDown && !c.prevMouseDown && ward.source == wardrobe.SourceUser { a.startWardrobeDrag(wardDragChar, it.Char) } + single := a.d.Prefs.Load().WardrobeSingleClick switch { - case c.dblClick: + case c.dblClick && !single: c.dblClick = false a.wardrobeUse(it.Char) case c.ClickedIn(r): if ward.sel != it.Char { ward.sel, ward.confirmRemove, ward.nickOpen, ward.moveMenu = it.Char, false, false, false } + // Only a streak's first click wears: the second click of a double-click would wear it again, or as an iniswap. + if single && c.clickStreak == 1 { + a.wardrobeUse(it.Char) + } + c.dblClick = false } } @@ -1309,7 +1315,11 @@ func (a *App) drawWardrobeBar(r sdl.Rect) { right := r.X + r.W - 2*wardPanelPad ward.moreN = 0 if !ok { - c.LabelClipped(x, r.Y+(r.H-lh)/2, r.W-4*wardPanelPad, "Select a character to see what you can do with it. Double-click wears it.", wcDim) + hint := "Select a character to see what you can do with it. Double-click wears it." + if a.d.Prefs.Load().WardrobeSingleClick { + hint = "Click a character to wear it; what else you can do with it shows here." + } + c.LabelClipped(x, r.Y+(r.H-lh)/2, r.W-4*wardPanelPad, hint, wcDim) return } switch { diff --git a/internal/ui/wardrobewin_test.go b/internal/ui/wardrobewin_test.go index 9004bc0f..ff96d409 100644 --- a/internal/ui/wardrobewin_test.go +++ b/internal/ui/wardrobewin_test.go @@ -9,6 +9,7 @@ import ( "github.com/SyntaxNyah/AsyncAO/internal/config" "github.com/SyntaxNyah/AsyncAO/internal/courtroom" "github.com/SyntaxNyah/AsyncAO/internal/render" + "github.com/SyntaxNyah/AsyncAO/internal/sdl" "github.com/SyntaxNyah/AsyncAO/internal/ui/wardrobe" ) @@ -237,3 +238,51 @@ func TestWardrobeWearWithEveryCharacterTakenWearsNothing(t *testing.T) { t.Fatalf("no free slot: wore anyway or said nothing (queued %q, warning %q)", a.ward.wearAfter, a.warnLine) } } + +// wardrobeClickTestApp is a rehearsal App whose pointer rests on a Wardrobe card; slot 1 (Maya) is free. +func wardrobeClickTestApp(t *testing.T, single bool) (*App, sdl.Rect) { + t.Helper() + const charINILoads = 2 + a := emotePreviewFollowTestApp(t) // switching enters the courtroom, which fetches the char.ini + a.iniChar = "" + a.sess = courtroom.NewRehearsalSession("", []string{"Phoenix", "Maya"}) + a.d.Viewport = render.NewViewport(nil, false) + a.charINIres = make(chan charINIFetch, charINILoads) + a.room, a.screen = nil, ScreenCharSelect + a.d.Prefs.Update(func(sn *config.Settings) { sn.WardrobeSingleClick = single }) + const side = 100 + card := sdl.Rect{W: side, H: side} + a.ctx.mouseX, a.ctx.mouseY = side/2, side/2 + a.ctx.downX, a.ctx.downY = side/2, side/2 + return a, card +} + +// click releases the button on the card as the streak's nth same-spot click. +func wardrobeClickOn(a *App, card sdl.Rect, nth int) { + const double = 2 + a.ctx.clicked, a.ctx.clickStreak, a.ctx.dblClick = true, nth, nth == double + a.wardrobeItemInput(wardrobe.Item{Char: "Maya"}, card) + a.ctx.clicked, a.ctx.dblClick = false, false +} + +func TestWardrobeSingleClickWearsOnce(t *testing.T) { + const maya = 1 + a, card := wardrobeClickTestApp(t, true) + wardrobeClickOn(a, card, 1) + if a.sess.MyCharID != maya { + t.Fatalf("one click left slot %d, want Maya's slot %d", a.sess.MyCharID, maya) + } + wardrobeClickOn(a, card, 2) // the second click of a double-click + if a.iniChar != "" { + t.Fatalf("a double-click wore Maya again as an iniswap (%q)", a.iniChar) + } +} + +func TestWardrobeClickOnlySelectsByDefault(t *testing.T) { + a, card := wardrobeClickTestApp(t, false) + before := a.sess.MyCharID + wardrobeClickOn(a, card, 1) + if a.sess.MyCharID != before || a.ward.sel != "Maya" { + t.Fatalf("a click switched to slot %d or didn't select (sel %q)", a.sess.MyCharID, a.ward.sel) + } +} From a52a5cf4f7db3dc7fc70f6bb767cb4706c27301e Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:22:50 +0100 Subject: [PATCH 04/13] courtroom: a held message asks again for what it waits on The wait gate asked for a message's needs when it armed and again only once its current blocker settled. A missing warning dropped on the way (the warning hand-off drops when full) left that blocker unsettled, so nothing asked again and the message waited out the whole limit, 10 s under strict sequencing. The hold now builds a fresh list and asks again once a second; asking for something already known missing sends its warning again, which settles it. A held tick stays allocation-free in between. Co-Authored-By: Claude Opus 5.5 --- internal/courtroom/courtroom.go | 19 ++++++++---- internal/courtroom/messageneeds_test.go | 39 +++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/internal/courtroom/courtroom.go b/internal/courtroom/courtroom.go index 7a749e28..62eba6f8 100644 --- a/internal/courtroom/courtroom.go +++ b/internal/courtroom/courtroom.go @@ -30,7 +30,10 @@ const ( // missingSpritesCap bounds the 404'd base set (hard rule 4); past it SpriteWaitTimeout bounds any unrecorded miss. // sequentialWaitLimit releases a strict-sequencing hold: a transient error or dropped warning never settles an asset. sequentialWaitLimit = 10 * time.Second - missingSpritesCap = 512 + // waitReaskInterval is how often a hold asks again for what it still waits on: an answer lost on the way, such as a + // dropped missing warning, would otherwise keep the message until the limit. + waitReaskInterval = time.Second + missingSpritesCap = 512 // missingDesksCap bounds the 404'd desk set (hard rule 4); past it the render-side release covers the layer. missingDesksCap = 512 // blipVolumeFull is the unattenuated blip scale, used with no BlipVolumeFor callback. @@ -324,9 +327,11 @@ type Courtroom struct { // CatchUpLinger holds each fast-forwarded message before the next; default zero drains one per frame. CatchUpLinger time.Duration - // waitLeft counts down an armed hold; waitFor is its message by pointer, so a new head re-arms. - waitLeft time.Duration - waitFor *protocol.ChatMessage + // waitLeft counts down an armed hold, and waitAskLeft to its next ask; waitFor is its message by pointer, so a new + // head re-arms. + waitLeft time.Duration + waitAskLeft time.Duration + waitFor *protocol.ChatMessage // waitBlocker is the need holding the message, needs messageNeeds' reused list. waitBlocker messageNeed needs []messageNeed @@ -591,7 +596,10 @@ func (c *Courtroom) waitHolds(msg *protocol.ChatMessage, behind int, dt time.Dur // This runs every frame of a hold: the need that stopped the last check is one lookup, the full list 174 allocations. // A release is always decided on a fresh list. armed := c.waitFor == msg - if !armed || c.needSettled(c.waitBlocker) { + if armed { + c.waitAskLeft -= dt + } + if !armed || c.needSettled(c.waitBlocker) || c.waitAskLeft <= 0 { needs := c.messageNeeds(msg) blocker, blocked := c.firstUnsettled(needs) if !blocked { @@ -609,6 +617,7 @@ func (c *Courtroom) waitHolds(msg *protocol.ChatMessage, behind int, dt time.Dur // Every fresh list, not only the first: a need that joins once char.ini lands (chat skin, blip) has no other // requester until begin, which runs only after the gate releases. c.requestNeeds(needs) + c.waitAskLeft = waitReaskInterval } c.waitLeft -= dt if c.waitLeft <= 0 { diff --git a/internal/courtroom/messageneeds_test.go b/internal/courtroom/messageneeds_test.go index 8106f45a..fcec839e 100644 --- a/internal/courtroom/messageneeds_test.go +++ b/internal/courtroom/messageneeds_test.go @@ -210,3 +210,42 @@ func TestHeldNeedCoversTheHeldMessageOnly(t *testing.T) { t.Error("a released message still counts as held") } } + +// TestWaitGateAsksAgainWhileItHolds: a missing warning that never reaches the gate (a full hand-off drops it) leaves the +// blocker unsettled, so the hold asks again, which re-sends the warning, instead of waiting out the limit. +func TestWaitGateAsksAgainWhileItHolds(t *testing.T) { + const ( + tick = 16 * time.Millisecond + wait = 5 * time.Second + ) + room, _ := recordingRoom(t) + room.SequentialWait = true + room.Assets = assetFake{sprite: func(string) bool { return false }} + idle := room.urls.Emote("Phoenix", "normal", EmoteIdle) + warnedFor := func() bool { + deadline := time.After(wait) + for { + select { + case w := <-room.mgr.Warnings(): + if w.Base == idle { + return true + } + case <-deadline: + return false + } + } + } + + room.HandleEvent(Event{Kind: EventMessage, Message: waitMsg("Phoenix", "normal", "hi")}) + room.Update(tick) + if !warnedFor() { + t.Fatal("the first ask never reported the sprite missing") + } + room.Update(waitReaskInterval) // the warning was lost: nothing settled the sprite + if room.QueueLen() != 1 { + t.Fatal("the message stopped waiting before the limit") + } + if !warnedFor() { + t.Fatal("the hold never asked again, so the lost warning was never sent again") + } +} From 7c52206ec092e11e29e99b3b363335d7c685513e Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:58:08 +0100 Subject: [PATCH 05/13] ui: the theme fit preview shows its drag hint only with a design (#153) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A theme without courtroom_design.ini drew "Drag to pan · scroll to zoom" over its own "no courtroom_design.ini" notice, four pixels apart. With no design there is nothing to pan, so the notice now shows alone. Fixes #153 Co-Authored-By: Claude Opus 5.5 --- internal/ui/settingstabs.go | 12 +++++++++-- internal/ui/themefitpreview_test.go | 33 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 internal/ui/themefitpreview_test.go diff --git a/internal/ui/settingstabs.go b/internal/ui/settingstabs.go index 4637198a..2203446e 100644 --- a/internal/ui/settingstabs.go +++ b/internal/ui/settingstabs.go @@ -754,6 +754,11 @@ func (a *App) drawSettingsStageFX(y int32) int32 { return y } +const ( + themeFitPreviewHint = "Drag to pan · scroll to zoom" + themeFitNoDesignText = "This theme has no courtroom_design.ini — the fit modes don't apply to it." +) + // drawThemeFitPreview draws the Custom theme fit preview; drag pans, scroll zooms, both write prefs and re-fit live. func (a *App) drawThemeFitPreview(box sdl.Rect) { c := a.ctx @@ -782,10 +787,13 @@ func (a *App) drawThemeFitPreview(box sdl.Rect) { } c.popClip(clipPrev, clipHad) } else { - c.LabelClipped(box.X+8, box.Y+8, box.W-16, "This theme has no courtroom_design.ini — the fit modes don't apply to it.", ColTextDim) + c.LabelClipped(box.X+8, box.Y+8, box.W-16, themeFitNoDesignText, ColTextDim) } c.Border(box, ColAccent) - c.Label(box.X+6, box.Y+4, "Drag to pan · scroll to zoom", ColTextDim) + // Without a design there is nothing to pan, and the hint would sit on the line above. + if ok { + c.Label(box.X+6, box.Y+4, themeFitPreviewHint, ColTextDim) + } // Wheel zooms and drag pans via the setters, then invalidate the geometry cache. if c.hovering(box) && c.wheelY != 0 { diff --git a/internal/ui/themefitpreview_test.go b/internal/ui/themefitpreview_test.go new file mode 100644 index 00000000..d0f36134 --- /dev/null +++ b/internal/ui/themefitpreview_test.go @@ -0,0 +1,33 @@ +package ui + +import ( + "testing" + + "github.com/SyntaxNyah/AsyncAO/internal/sdl" +) + +// TestThemeFitPreviewHintOnlyWithADesign: a theme without courtroom_design.ini shows its notice alone, not the +// drag-to-pan hint on top of it (#153). +func TestThemeFitPreviewHintOnlyWithADesign(t *testing.T) { + const boxW, boxH = 560, 340 + a, cleanup := stageThemedCourtroom(t) + defer cleanup() + box := sdl.Rect{W: boxW, H: boxH} + + delete(a.themeRects, ao2CanvasKey) + a.ctx.purgeTextCache() + a.drawThemeFitPreview(box) + if !textCacheHasLabel(a.ctx, themeFitNoDesignText) { + t.Fatal("no notice for a theme without a design") + } + if textCacheHasLabel(a.ctx, themeFitPreviewHint) { + t.Error("the drag-to-pan hint is drawn over the no-design notice") + } + + a.themeRects[ao2CanvasKey] = a.themeRectsOrig[ao2CanvasKey] + a.ctx.purgeTextCache() + a.drawThemeFitPreview(box) + if !textCacheHasLabel(a.ctx, themeFitPreviewHint) { + t.Error("the drag-to-pan hint is missing for a theme with a design") + } +} From 633742bfd33ddb8159b69f75c55264dc0670b555 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:00:11 +0100 Subject: [PATCH 06/13] ui, render: effect dropdown icons keep their shape (#77) The effects dropdown copied each icon into its whole row cell, so square art came out stretched to the cell's 23x28. AO2's QIcon keeps the aspect ratio. The icon is now fitted inside the cell and centred, through the preview window's fit helper, which takes a box and is exported for it. Fixes #77 Co-Authored-By: Claude Opus 5.5 --- internal/render/previewwindow.go | 22 +++++++++++----------- internal/render/previewwindow_test.go | 26 ++++++++++++++++++-------- internal/ui/effectspicker.go | 6 ++++-- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/internal/render/previewwindow.go b/internal/render/previewwindow.go index 175f6cac..f95c947b 100644 --- a/internal/render/previewwindow.go +++ b/internal/render/previewwindow.go @@ -303,27 +303,27 @@ func (p *PreviewWindow) Present() { _ = p.ren.Clear() if p.tex != nil { winW, winH := p.win.GetSize() - dst := previewFitRect(winW, winH, p.texW, p.texH) + dst := FitRect(sdl.Rect{W: winW, H: winH}, p.texW, p.texH) _ = p.ren.Copy(p.tex, nil, &dst) } _ = p.ren.Present() // the preview has its own renderer; a failed present only drops a preview frame } -// previewFitRect fits src in win on both axes, centred, as the window can be narrower than the art. -func previewFitRect(winW, winH, srcW, srcH int32) sdl.Rect { - if winW <= 0 || winH <= 0 || srcW <= 0 || srcH <= 0 { - return sdl.Rect{W: winW, H: winH} +// FitRect fits src in box on both axes, centred, keeping its aspect; a source with no size fills the box. +func FitRect(box sdl.Rect, srcW, srcH int32) sdl.Rect { + if box.W <= 0 || box.H <= 0 || srcW <= 0 || srcH <= 0 { + return box } // Cross-multiply to compare the ratios using only integer math. var w, h int32 - if int64(winW)*int64(srcH) <= int64(winH)*int64(srcW) { - w = winW - h = int32((int64(srcH)*int64(winW) + int64(srcW)/2) / int64(srcW)) // rounded, not truncated + if int64(box.W)*int64(srcH) <= int64(box.H)*int64(srcW) { + w = box.W + h = int32((int64(srcH)*int64(box.W) + int64(srcW)/2) / int64(srcW)) // rounded, not truncated } else { - h = winH - w = int32((int64(srcW)*int64(winH) + int64(srcH)/2) / int64(srcH)) + h = box.H + w = int32((int64(srcW)*int64(box.H) + int64(srcH)/2) / int64(srcH)) } - return sdl.Rect{X: (winW - w) / 2, Y: (winH - h) / 2, W: w, H: h} + return sdl.Rect{X: box.X + (box.W-w)/2, Y: box.Y + (box.H-h)/2, W: w, H: h} } // HandleEvent handles this window's events; the caller routes by window id, so no id check is needed. diff --git a/internal/render/previewwindow_test.go b/internal/render/previewwindow_test.go index 71db7152..02bce32b 100644 --- a/internal/render/previewwindow_test.go +++ b/internal/render/previewwindow_test.go @@ -571,9 +571,9 @@ func TestClampPositionToDisplaysRecentresAnUnreachablePosition(t *testing.T) { } } -// --- previewFitRect (aspect-preserving, non-stretch Present) ----------------- +// --- FitRect (aspect-preserving, non-stretch Present) ----------------- -func TestPreviewFitRectPreservesAspectAndCentres(t *testing.T) { +func TestFitRectPreservesAspectAndCentres(t *testing.T) { cases := []struct { name string winW, winH, srcW, srcH int32 @@ -586,9 +586,9 @@ func TestPreviewFitRectPreservesAspectAndCentres(t *testing.T) { } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - got := previewFitRect(c.winW, c.winH, c.srcW, c.srcH) + got := FitRect(sdl.Rect{W: c.winW, H: c.winH}, c.srcW, c.srcH) if got.W != c.wantW || got.H != c.wantH { - t.Fatalf("previewFitRect(%d,%d,%d,%d) size = %dx%d, want %dx%d", + t.Fatalf("FitRect(%d,%d,%d,%d) size = %dx%d, want %dx%d", c.winW, c.winH, c.srcW, c.srcH, got.W, got.H, c.wantW, c.wantH) } // Centred on both axes. @@ -602,18 +602,28 @@ func TestPreviewFitRectPreservesAspectAndCentres(t *testing.T) { } } -// TestPreviewFitRectDegenerateInputsFillTheWindow pins the fallback: a +// TestFitRectDegenerateInputsFillTheWindow pins the fallback: a // source with no usable size must not divide by zero or return a // zero-area rect nobody can see — it fills the window instead. -func TestPreviewFitRectDegenerateInputsFillTheWindow(t *testing.T) { +func TestFitRectDegenerateInputsFillTheWindow(t *testing.T) { for _, c := range []struct{ srcW, srcH int32 }{{0, 100}, {100, 0}, {-5, 100}} { - got := previewFitRect(320, 240, c.srcW, c.srcH) + got := FitRect(sdl.Rect{W: 320, H: 240}, c.srcW, c.srcH) if got.W != 320 || got.H != 240 { - t.Errorf("previewFitRect(320,240,%d,%d) = %+v, want the whole 320x240 window", c.srcW, c.srcH, got) + t.Errorf("FitRect(320,240,%d,%d) = %+v, want the whole 320x240 window", c.srcW, c.srcH, got) } } } +// TestFitRectKeepsTheBoxOffset: a square icon in the effects dropdown's 23x28 cell keeps its shape, inside the cell (#77). +func TestFitRectKeepsTheBoxOffset(t *testing.T) { + const cellX, cellY, cellW, cellH, iconSide = 40, 60, 23, 28, 64 + got := FitRect(sdl.Rect{X: cellX, Y: cellY, W: cellW, H: cellH}, iconSide, iconSide) + want := sdl.Rect{X: cellX, Y: cellY + (cellH-cellW)/2, W: cellW, H: cellW} + if got != want { + t.Errorf("FitRect = %+v, want %+v", got, want) + } +} + func TestPreviewWindowOpenFailureStaysClosed(t *testing.T) { want := errors.New("no window") pw := NewPreviewWindow(func(string, int32, int32) (*sdl.Window, *sdl.Renderer, error) { return nil, nil, want }) diff --git a/internal/ui/effectspicker.go b/internal/ui/effectspicker.go index 30dedca3..d8fa6492 100644 --- a/internal/ui/effectspicker.go +++ b/internal/ui/effectspicker.go @@ -13,6 +13,7 @@ import ( "github.com/SyntaxNyah/AsyncAO/internal/assets" "github.com/SyntaxNyah/AsyncAO/internal/courtroom" "github.com/SyntaxNyah/AsyncAO/internal/network" + "github.com/SyntaxNyah/AsyncAO/internal/render" "github.com/SyntaxNyah/AsyncAO/internal/sdl" "github.com/SyntaxNyah/AsyncAO/internal/theme" ) @@ -522,8 +523,9 @@ func (a *App) overlayIconDraw(i int, tr sdl.Rect) { a.overlayDemandTheme(path, base) } if page, ok := a.cachedPage(&a.overlayIconPages, &a.overlayIconGen, n, i, base); ok && len(page.Frames) > 0 { - // Through the shared cgo scratch, never &tr: a parameter's address heap-escapes on every cgo call. - c.cgoRect = tr + // Kept to its aspect like AO2's QIcon. Through the shared cgo scratch, never &tr: a parameter's address + // heap-escapes on every cgo call. + c.cgoRect = render.FitRect(tr, page.W, page.H) c.copy(page.Frames[0], nil, &c.cgoRect) } else { c.Fill(tr, overlayIconChipColor) From 96ec55bb72d559b9ffc78a1dad6aebdb4322ad27 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:03:43 +0100 Subject: [PATCH 07/13] ui, render: the sprite preview uses the character's scaling (#88) The preview drew a sprite with whatever filter its texture had: the default until the sprite had been on stage, where the courtroom sets the char.ini filter. A pixel-art character previewed smooth until it was sent. The preview now applies the courtroom's rule for the previewed character (user setting, then char.ini scaling, then point-sampled when enlarged), so emote and portrait previews match the stage from the first frame. Effect and background previews keep the filter they have. Fixes #88 Co-Authored-By: Claude Opus 5.5 --- internal/render/prescale.go | 2 +- internal/render/scalemode.go | 10 +++---- internal/render/scenery.go | 2 +- internal/render/spritescale_test.go | 20 +++++-------- internal/render/streaming_test.go | 2 +- internal/render/textures.go | 2 +- internal/render/viewport.go | 6 ++-- internal/ui/app.go | 2 ++ internal/ui/app_room.go | 1 + internal/ui/previewscaling_test.go | 45 +++++++++++++++++++++++++++++ internal/ui/screensemote.go | 2 ++ internal/ui/screenslobby.go | 33 +++++++++++++++++++++ 12 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 internal/ui/previewscaling_test.go diff --git a/internal/render/prescale.go b/internal/render/prescale.go index 4d87283d..2de7b7ce 100644 --- a/internal/render/prescale.go +++ b/internal/render/prescale.go @@ -115,7 +115,7 @@ func scaledPixels(n int32, s float32) int32 { // drawScaled copies frame of page to dst through sf, a pre-scaled copy, and reports whether it drew; false leaves the // draw to the caller (not SDL's software renderer, or too big to keep). src carries the colour mod to bake in, and -// page's applyScaleMode must have run, as its remembered filter is the one baked in. alpha fades the copy. +// page's ApplyScaleMode must have run, as its remembered filter is the one baked in. alpha fades the copy. func (v *Viewport) drawScaled(ren *sdl.Renderer, sf *scaledFrame, page *TexturePage, frame int, src *sdl.Texture, dst sdl.Rect, flip sdl.RendererFlip, modR, modG, modB, alpha uint8) bool { if !v.prescale { diff --git a/internal/render/scalemode.go b/internal/render/scalemode.go index 39afc552..247730de 100644 --- a/internal/render/scalemode.go +++ b/internal/render/scalemode.go @@ -12,9 +12,9 @@ func setTextureScaleMode(tex *sdl.Texture, mode sdl.ScaleMode) bool { return tex != nil && tex.SetScaleMode(mode) == nil } -// spriteScaleMode applies AO2's rule (animationlayer.cpp:229-273): smooth, but point-sampled when enlarged. -func (v *Viewport) spriteScaleMode(layer *courtroom.SpriteLayer, nativeH, targetH int32) sdl.ScaleMode { - switch courtroom.ResolveScalingMode(v.fx.UserScaling, layer.Scaling) { +// SpriteScaleMode applies AO2's rule (animationlayer.cpp:229-273): smooth, but point-sampled when enlarged. +func SpriteScaleMode(user, char courtroom.ScalingMode, nativeH, targetH int32) sdl.ScaleMode { + switch courtroom.ResolveScalingMode(user, char) { case courtroom.ScalingPixel: return sdl.ScaleModeNearest case courtroom.ScalingSmooth: @@ -26,8 +26,8 @@ func (v *Viewport) spriteScaleMode(layer *courtroom.SpriteLayer, nativeH, target return sdl.ScaleModeLinear } -// applyScaleMode sets every frame's filter, memoised so the steady state does no cgo; render thread only. -func (p *TexturePage) applyScaleMode(ren *sdl.Renderer, mode sdl.ScaleMode) { +// ApplyScaleMode sets every frame's filter, memoised so the steady state does no cgo; render thread only. +func (p *TexturePage) ApplyScaleMode(ren *sdl.Renderer, mode sdl.ScaleMode) { if p == nil || ren == nil { return } diff --git a/internal/render/scenery.go b/internal/render/scenery.go index 35472ad1..26a3ece4 100644 --- a/internal/render/scenery.go +++ b/internal/render/scenery.go @@ -46,7 +46,7 @@ func (v *Viewport) drawScenery(ren *sdl.Renderer, scene *courtroom.Scene, base s return } v.fillRect = sceneryRect(vp, page.W, page.H, scene.SceneryStretch, v.panorama, v.origin) - page.applyScaleMode(ren, sceneryScaleMode(v.fx.UserScaling, scene.SceneryScaling, scene.SceneryStretch, page.H, v.fillRect.H)) + page.ApplyScaleMode(ren, sceneryScaleMode(v.fx.UserScaling, scene.SceneryScaling, scene.SceneryStretch, page.H, v.fillRect.H)) tex := page.Frames[frame] d := uint8(channelMax) if dimPct < percentMax { diff --git a/internal/render/spritescale_test.go b/internal/render/spritescale_test.go index 149444af..239e4d40 100644 --- a/internal/render/spritescale_test.go +++ b/internal/render/spritescale_test.go @@ -8,7 +8,7 @@ import ( ) // TestSpriteNativeHLatchesToTheIdle pins that one character keeps ONE native -// height while its bases swap under it. spriteScaleMode decides the filter from +// height while its bases swap under it. SpriteScaleMode decides the filter from // this height, and re-reading it from whichever page was drawing let a // talk/preanim page that decoded at a different size flip the filter // mid-animation — the reported "swaps to smooth scaling for animations". @@ -89,9 +89,7 @@ func TestSpriteScaleModeFollowsAO2(t *testing.T) { {"unknown native height", courtroom.ScalingAuto, courtroom.ScalingAuto, 0, sdl.ScaleModeLinear}, } { t.Run(tc.name, func(t *testing.T) { - v := &Viewport{fx: SpriteFX{UserScaling: tc.user}} - layer := &courtroom.SpriteLayer{Scaling: tc.char} - if got := v.spriteScaleMode(layer, tc.nativeH, stageH); got != tc.want { + if got := SpriteScaleMode(tc.user, tc.char, tc.nativeH, stageH); got != tc.want { t.Errorf("got %d, want %d", got, tc.want) } }) @@ -101,7 +99,7 @@ func TestSpriteScaleModeFollowsAO2(t *testing.T) { // TestApplyScaleModeIsMemoised guards the cost, not the correctness. The apply // runs on the render loop for every sprite of every frame, and each real change // forces a renderer flush (mandatory under HINT_RENDER_BATCHING — see -// applyScaleMode). Without the memo a stable stage would flush twice per frame +// ApplyScaleMode). Without the memo a stable stage would flush twice per frame // forever, quietly undoing the batching the client turns on at startup. func TestApplyScaleModeIsMemoised(t *testing.T) { ren, cleanup := newHeadlessRenderer(t) @@ -122,7 +120,7 @@ func TestApplyScaleModeIsMemoised(t *testing.T) { if page.scaleModeSet { t.Error("a fresh page must start unlatched — otherwise the first apply is skipped") } - page.applyScaleMode(ren, sdl.ScaleModeNearest) + page.ApplyScaleMode(ren, sdl.ScaleModeNearest) if !page.scaleModeSet || page.scaleMode != sdl.ScaleModeNearest { t.Fatalf("first apply did not latch: set=%v mode=%d", page.scaleModeSet, page.scaleMode) } @@ -142,14 +140,14 @@ func TestApplyScaleModeIsMemoised(t *testing.T) { // memo's back, then ask for the memoised mode. If the memo works nothing runs // and the sabotage survives; if it were removed the loop would overwrite it. setTextureScaleMode(page.Frames[0], sdl.ScaleModeLinear) - page.applyScaleMode(ren, sdl.ScaleModeNearest) + page.ApplyScaleMode(ren, sdl.ScaleModeNearest) if got, _ := textureScaleMode(page.Frames[0]); got != sdl.ScaleModeLinear { t.Error("re-applying the memoised mode did real work (cgo + a mandatory renderer flush) " + "— that runs per sprite per frame and defeats HINT_RENDER_BATCHING") } // A genuine change still takes. - page.applyScaleMode(ren, sdl.ScaleModeLinear) + page.ApplyScaleMode(ren, sdl.ScaleModeLinear) if page.scaleMode != sdl.ScaleModeLinear { t.Errorf("a changed mode must re-apply, got %d", page.scaleMode) } @@ -163,11 +161,9 @@ func TestApplyScaleModeIsMemoised(t *testing.T) { // TestSpriteScaleModeZeroAlloc keeps the resolver honest against the // zero-allocation render loop (CLAUDE.md hard rule). It runs per sprite per frame. func TestSpriteScaleModeZeroAlloc(t *testing.T) { - v := &Viewport{} - layer := &courtroom.SpriteLayer{Scaling: courtroom.ScalingAuto} if n := testing.AllocsPerRun(200, func() { - _ = v.spriteScaleMode(layer, 256, 1080) + _ = SpriteScaleMode(courtroom.ScalingAuto, courtroom.ScalingAuto, 256, 1080) }); n != 0 { - t.Errorf("spriteScaleMode allocates %v/op, want 0", n) + t.Errorf("SpriteScaleMode allocates %v/op, want 0", n) } } diff --git a/internal/render/streaming_test.go b/internal/render/streaming_test.go index 70856fa1..95a6c457 100644 --- a/internal/render/streaming_test.go +++ b/internal/render/streaming_test.go @@ -99,7 +99,7 @@ func TestAppendStreamKeepsLatchedScaleMode(t *testing.T) { t.Fatal("establish: page must be resident") } // A draw latches the filter exactly the way viewport.go does. - page.applyScaleMode(ren, sdl.ScaleModeNearest) + page.ApplyScaleMode(ren, sdl.ScaleModeNearest) if err := store.AppendStream(base, streamChunk(1, true, 3)); err != nil { t.Fatalf("append: %v", err) diff --git a/internal/render/textures.go b/internal/render/textures.go index 8e4597a4..f8ecb986 100644 --- a/internal/render/textures.go +++ b/internal/render/textures.go @@ -713,7 +713,7 @@ func (s *TextureStore) AppendStream(base string, d *assets.Decoded) error { if err != nil { return err } - // applyScaleMode skips a page already set, so appended frames must inherit its filter or stay bilinear. + // ApplyScaleMode skips a page already set, so appended frames must inherit its filter or stay bilinear. // No Flush is needed: new textures have no queued copies. if page.scaleModeSet { for _, t := range frames { diff --git a/internal/render/viewport.go b/internal/render/viewport.go index be4ffe1c..3575dc50 100644 --- a/internal/render/viewport.go +++ b/internal/render/viewport.go @@ -986,7 +986,7 @@ func (v *Viewport) drawOverlay(ren *sdl.Renderer, scene *courtroom.Scene, vp sdl } tex := page.Frames[clampFrame(v.overlayAnim.frame, len(page.Frames))] dst := overlayDstRect(o, vp, page.W, page.H) - page.applyScaleMode(ren, v.overlayScaleMode(o, page.H, dst.H)) + page.ApplyScaleMode(ren, v.overlayScaleMode(o, page.H, dst.H)) v.ovRect = dst if o.Flip { _ = v.copies.CopyFlip(ren, tex, nil, &v.ovRect, sdl.FLIP_HORIZONTAL) @@ -1148,7 +1148,7 @@ func (v *Viewport) drawBackgroundDoF(ren *sdl.Renderer, scene *courtroom.Scene, } tex := page.Frames[frame] dst := sceneryRect(vp, page.W, page.H, scene.SceneryStretch, v.panorama, v.origin) - page.applyScaleMode(ren, sceneryScaleMode(v.fx.UserScaling, scene.SceneryScaling, scene.SceneryStretch, page.H, dst.H)) + page.ApplyScaleMode(ren, sceneryScaleMode(v.fx.UserScaling, scene.SceneryScaling, scene.SceneryStretch, page.H, dst.H)) r := vp.H / dofBlurDivisor if r < dofBlurMin { r = dofBlurMin @@ -1306,7 +1306,7 @@ func (v *Viewport) drawSprite(ren *sdl.Renderer, layer *courtroom.SpriteLayer, a } // AO2 filters per sprite, from frame height against the widget height (calculateFrameGeometry, courtroom.cpp:778). // Must be vp.H, not v.dstRect.H: dstRect grows with a transmitted scale or zoom, changing the filter. - drawPage.applyScaleMode(ren, v.spriteScaleMode(layer, anim.spriteNativeH(layer, page), vp.H)) + drawPage.ApplyScaleMode(ren, SpriteScaleMode(v.fx.UserScaling, layer.Scaling, anim.spriteNativeH(layer, page), vp.H)) // A transmitted style takes precedence over the viewer's local wash for this layer. var ( diff --git a/internal/ui/app.go b/internal/ui/app.go index 19d40751..d07f102d 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -260,6 +260,8 @@ type App struct { // previewBase, so every other previewBase setter invalidates the caption automatically. previewName string previewNameFor string + // previewScaling is the char.ini filter of the character the preview shows, so it draws as the courtroom would. + previewScaling previewScaling previewFor string // base the preview clock was started for previewAt time.Time // loop anchor — animated previews play, not freeze previewZoom int // magnifier factor (1 = fit; >1 shows a cursor-panned window) diff --git a/internal/ui/app_room.go b/internal/ui/app_room.go index 5867d36b..04051ff5 100644 --- a/internal/ui/app_room.go +++ b/internal/ui/app_room.go @@ -1494,6 +1494,7 @@ func (a *App) previewPortraitAnim(name string) string { func (a *App) setCharPortraitPreview(name string) { anim := a.previewPortraitAnim(name) a.previewBase = a.urls.Emote(name, anim, courtroom.EmoteIdle) + a.notePreviewChar(name) a.d.Manager.PrefetchChain(a.previewBase, a.urls.EmoteAlts(name, anim, courtroom.EmoteIdle), assets.AssetTypeCharSprite, network.PriorityHigh) // AssetType: CharSprite (preview) } diff --git a/internal/ui/previewscaling_test.go b/internal/ui/previewscaling_test.go new file mode 100644 index 00000000..48b3451a --- /dev/null +++ b/internal/ui/previewscaling_test.go @@ -0,0 +1,45 @@ +package ui + +import ( + "testing" + + "github.com/SyntaxNyah/AsyncAO/internal/courtroom" + "github.com/SyntaxNyah/AsyncAO/internal/sdl" +) + +// TestSpritePreviewUsesTheCharactersScaling: the preview draws a character's sprite with its char.ini filter before +// the sprite has ever been on stage (#88). +func TestSpritePreviewUsesTheCharactersScaling(t *testing.T) { + const winW, winH = 800, 600 + for _, tc := range []struct { + name string + scaling courtroom.ScalingMode + before sdl.ScaleMode + want sdl.ScaleMode + }{ + {"pixel", courtroom.ScalingPixel, sdl.ScaleModeLinear, sdl.ScaleModeNearest}, + {"smooth", courtroom.ScalingSmooth, sdl.ScaleModeNearest, sdl.ScaleModeLinear}, + } { + t.Run(tc.name, func(t *testing.T) { + a := newPreviewFeedApp(t) + a.urls = courtroom.NewURLBuilder("http://test.example/base/") + a.charMetaCache = map[string]charMeta{a.charINIURL(tc.name): {done: true, scaling: tc.scaling}} + page, ok := a.d.Store.Get(previewFeedFixtureBase) + if !ok { + t.Fatal("fixture page missing") + } + page.ApplyScaleMode(a.ctx.Ren, tc.before) + + a.notePreviewChar(tc.name) + a.drawSpritePreview(winW, winH, "") + + got, err := page.Frames[0].GetScaleMode() + if err != nil { + t.Skipf("scale mode unreadable: %v", err) + } + if got != tc.want { + t.Errorf("preview filter = %d, want %d", got, tc.want) + } + }) + } +} diff --git a/internal/ui/screensemote.go b/internal/ui/screensemote.go index aa41b1f6..1fbe2649 100644 --- a/internal/ui/screensemote.go +++ b/internal/ui/screensemote.go @@ -29,11 +29,13 @@ func (a *App) previewEmote(char string, e *courtroom.Emote) { if e.Preanim != "" && e.Preanim != "-" { // "-" / "" = no preanim (AO convention) a.previewBase = a.urls.Emote(char, e.Preanim, courtroom.EmotePreanim) a.previewName, a.previewNameFor = name, a.previewBase + a.notePreviewChar(char) a.d.Manager.Prefetch(a.previewBase, assets.AssetTypeCharSprite, network.PriorityHigh) // AssetType: CharSprite (preanim preview) return } a.previewBase = a.urls.Emote(char, e.Anim, courtroom.EmoteTalk) a.previewName, a.previewNameFor = name, a.previewBase + a.notePreviewChar(char) a.d.Manager.PrefetchChain(a.previewBase, a.urls.EmoteAlts(char, e.Anim, courtroom.EmoteTalk), assets.AssetTypeCharSprite, network.PriorityHigh) // AssetType: CharSprite (preview) } diff --git a/internal/ui/screenslobby.go b/internal/ui/screenslobby.go index 74ebba65..e27e57b3 100644 --- a/internal/ui/screenslobby.go +++ b/internal/ui/screenslobby.go @@ -12,6 +12,7 @@ import ( "github.com/SyntaxNyah/AsyncAO/internal/helper/value" "github.com/SyntaxNyah/AsyncAO/internal/network" "github.com/SyntaxNyah/AsyncAO/internal/protocol" + "github.com/SyntaxNyah/AsyncAO/internal/render" "github.com/SyntaxNyah/AsyncAO/internal/sdl" ) @@ -931,6 +932,7 @@ func (a *App) drawSpritePreview(w, h int32, name string) { if zh < 1 { zh = 1 } + a.applyPreviewScaleMode(page, zh, dst.H) relX := float64(c.mouseX-dst.X) / float64(dst.W) relY := float64(c.mouseY-dst.Y) / float64(dst.H) relX = value.Clamp(relX, 0, 1) @@ -938,6 +940,7 @@ func (a *App) drawSpritePreview(w, h int32, name string) { src := sdl.Rect{X: value.Clamp(int32(relX*float64(page.W))-zw/2, 0, page.W-zw), Y: value.Clamp(int32(relY*float64(page.H))-zh/2, 0, page.H-zh), W: zw, H: zh} c.copy(tex, &src, &dst) } else { + a.applyPreviewScaleMode(page, page.H, dst.H) c.copy(tex, nil, &dst) } a.drawPreviewZoom(frame, page.W, page.H, dst.H) @@ -980,6 +983,36 @@ func (a *App) drawSpritePreview(w, h int32, name string) { c.Tooltip(closeB, "Close the preview") } +// previewScaling is the char.ini filter of the character behind one preview base; settled once its char.ini answered. +type previewScaling struct { + base, char string + mode courtroom.ScalingMode + settled bool +} + +// notePreviewChar records whose sprite the preview now shows; idempotent, as the portrait preview is set every frame. +func (a *App) notePreviewChar(char string) { + if a.previewScaling.base == a.previewBase && a.previewScaling.char == char { + return + } + a.previewScaling = previewScaling{base: a.previewBase, char: char} +} + +// applyPreviewScaleMode gives a character preview the courtroom's filter, which the page otherwise only gets once the +// sprite is on stage (#88). Other previews keep the filter they have. +func (a *App) applyPreviewScaleMode(page *render.TexturePage, nativeH, targetH int32) { + ps := &a.previewScaling + if ps.base != a.previewBase { + return + } + if !ps.settled { + m := a.charMetaFor(ps.char) + ps.mode, ps.settled = m.scaling, m.done + } + user := courtroom.ScalingMode(a.d.Prefs.SpriteScalingMode()) + page.ApplyScaleMode(a.ctx.Ren, render.SpriteScaleMode(user, ps.mode, nativeH, targetH)) +} + // previewGripRect is the resize grip's hit rect, shared by the draw and the input handler. func previewGripRect(frame sdl.Rect) sdl.Rect { return sdl.Rect{X: frame.X + frame.W - 16, Y: frame.Y + frame.H - previewCaptionH - 16, W: 16, H: 16} From dfd2e8bd6abd51f55aa90838910b925d9117e8e2 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:05:04 +0100 Subject: [PATCH 08/13] ui: the SFX Browser opens in front of the Extras box (#32) The SFX Browser takes the screen like the Wardrobe, Jukebox and Background picker, but it was missing from the popups that hide the Extras box, so the box opened over the browser it had just launched. It is now in that set: the box hides while the browser is open and returns when it closes, as with the other three. Fixes #32 Co-Authored-By: Claude Opus 5.5 --- internal/ui/floatbox.go | 6 +++--- internal/ui/overlayfence_test.go | 7 ++----- internal/ui/screens.go | 3 +-- internal/ui/sfxbrowserfront_test.go | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 internal/ui/sfxbrowserfront_test.go diff --git a/internal/ui/floatbox.go b/internal/ui/floatbox.go index c37caa83..71f615cb 100644 --- a/internal/ui/floatbox.go +++ b/internal/ui/floatbox.go @@ -179,9 +179,9 @@ func (a *App) extrasPalette() extrasPalette { func (a *App) blockingCourtPopup() bool { // Floating panels (pair, mod, CM, evidence, ban box, timer, login, pair popup, pinned pieces) stay out: they fence // by footprint, and adding one would make extrasSurfaceLive false and disable its own fence. - // Not courtroomModalUp's set: this adds classicEdit and omits showSfxBrowser, which would hide the panels too. - // Ask courtroomModalUp whether drawCourtroomModals will take the screen. - return a.ward.show || a.showJukebox || a.bgPick.show || + // Not courtroomModalUp's set: this adds classicEdit. Ask courtroomModalUp whether drawCourtroomModals will take the + // screen. + return a.ward.show || a.showJukebox || a.bgPick.show || a.showSfxBrowser || a.classicEdit } diff --git a/internal/ui/overlayfence_test.go b/internal/ui/overlayfence_test.go index acbd682f..a5b2b204 100644 --- a/internal/ui/overlayfence_test.go +++ b/internal/ui/overlayfence_test.go @@ -435,15 +435,12 @@ func TestCourtroomModalUpMatchesDraw(t *testing.T) { } } // blockingCourtPopup is a DIFFERENT question and must not be mistaken for this - // one: it omits the SFX browser and adds classicEdit. Pinned so a future "just - // reuse it" refactor has to confront that. + // one: it adds classicEdit. Pinned so a future "just reuse it" refactor has to + // confront that. a.showSfxBrowser = true if !a.courtroomModalUp() { t.Error("the SFX browser IS in the return-to-top modal set (drawCourtroomModals draws it)") } - if a.blockingCourtPopup() { - t.Error("blockingCourtPopup deliberately does NOT list the SFX browser — do not reuse it as the modal predicate") - } a.showSfxBrowser = false a.classicEdit = true if a.courtroomModalUp() { diff --git a/internal/ui/screens.go b/internal/ui/screens.go index a4e3ebc7..8a19dfb9 100644 --- a/internal/ui/screens.go +++ b/internal/ui/screens.go @@ -473,8 +473,7 @@ func (a *App) modalReturnSkippedWhileEditing() bool { return a.layoutEditorArmed // courtroomModalUp reports whether drawCourtroomModals will take the screen, for decisions made before the pass reaches // it. -// Not blockingCourtPopup (floatbox.go): that set omits showSfxBrowser and adds classicEdit, so it would answer wrongly -// here. +// Not blockingCourtPopup (floatbox.go): that set adds classicEdit, so it would answer wrongly here. func (a *App) courtroomModalUp() bool { for i := range courtroomModals { if courtroomModals[i].open(a) { diff --git a/internal/ui/sfxbrowserfront_test.go b/internal/ui/sfxbrowserfront_test.go new file mode 100644 index 00000000..31afda59 --- /dev/null +++ b/internal/ui/sfxbrowserfront_test.go @@ -0,0 +1,25 @@ +package ui + +import ( + "testing" + + "github.com/SyntaxNyah/AsyncAO/internal/courtroom" +) + +// TestSfxBrowserHidesTheExtrasBox: opened from the Extras box, the SFX Browser shows in front, as the Wardrobe and +// Jukebox do; the box comes back when it closes (#32). +func TestSfxBrowserHidesTheExtrasBox(t *testing.T) { + a := testTabApp(t) + a.sess = courtroom.NewRehearsalSession("", nil) + a.room = &courtroom.Courtroom{} + a.showWidgets = true + + a.toggleSfxBrowser() + if a.extrasSurfaceLive() { + t.Error("the Extras box still draws over the open SFX Browser") + } + a.toggleSfxBrowser() + if !a.extrasSurfaceLive() { + t.Error("the Extras box did not come back after the SFX Browser closed") + } +} From ca655a6d979949733b283e741e96cbea878e6f11 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sun, 15 Nov 2026 18:08:01 +0100 Subject: [PATCH 09/13] =?UTF-8?q?ui:=20each=20list's=20=E2=8B=AE=20menu=20?= =?UTF-8?q?shows=20only=20its=20own=20options=20(#85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Music view, the Areas view and the player list open one shared menu, and the music and roster blocks showed in all three: the player list offered fade-in and loop, the music list offered roster refresh and follow. The menu now remembers which view opened it and shows only that view's block, and a divider no longer opens the menu. Fixes #85 Co-Authored-By: Claude Opus 5.5 --- internal/ui/apptypes.go | 1 + internal/ui/areamenu.go | 2 +- internal/ui/areamenu_test.go | 130 +++++++++++++++----------------- internal/ui/musicheader.go | 57 ++++++++++---- internal/ui/musicheader_test.go | 4 +- internal/ui/playerlist.go | 4 +- internal/ui/screensmusic.go | 4 +- 7 files changed, 112 insertions(+), 90 deletions(-) diff --git a/internal/ui/apptypes.go b/internal/ui/apptypes.go index 9c5d29aa..500ea591 100644 --- a/internal/ui/apptypes.go +++ b/internal/ui/apptypes.go @@ -702,6 +702,7 @@ type sessionState struct { musicMenuAt sdl.Point // preferred top-left (clamped at draw) musicMenuTab int // tab the menu opened on — auto-close on switch musicMenuThemed bool // the panel drew inside a theme canvas when it opened (gates the volume-view row) + musicMenuFrom musicMenuSource liveDetailsArea string // area of the last auto /getarea pull; re-pull on area change suppressAreaEchoUntil time.Time // keep /gas/getarea reply lines out of OOC until this time — the WHOLE reply burst (a multi-area /gas spans several messages), not just the first // Follow-a-player: followUID is the player we trail across areas ("" = off); we auto-jump to their area on each diff --git a/internal/ui/areamenu.go b/internal/ui/areamenu.go index b6210b6c..63891dd7 100644 --- a/internal/ui/areamenu.go +++ b/internal/ui/areamenu.go @@ -162,6 +162,6 @@ func splitAreaHeaderRow(row sdl.Rect) areaHeaderLayout { // click-away closes it on the frame it opened (musicheader.go). func (a *App) drawAreaMenuButton(btn sdl.Rect, themed bool) { if a.musicIconButton(btn, iconKebab, "Area options — background, refresh the list, per-area chat log, CM controls") { - a.openMusicMenuFromButton(sdl.Point{X: btn.X, Y: btn.Y + btn.H}, themed) + a.openMusicMenuFromButton(sdl.Point{X: btn.X, Y: btn.Y + btn.H}, themed, musicMenuFromAreas) } } diff --git a/internal/ui/areamenu_test.go b/internal/ui/areamenu_test.go index c14cd9f5..cf4e8411 100644 --- a/internal/ui/areamenu_test.go +++ b/internal/ui/areamenu_test.go @@ -125,82 +125,72 @@ func TestAreaMenuButtonTakesRoomFromItsOwnRow(t *testing.T) { } } -// TestMusicViewMenuCarriesNoAreaRow is the gate the shared pane demands back in -// exchange for hosting the block. Three triggers open ONE popup — the Music -// header's ⋮, the roster toolbar's ⋮ and now the Areas view's — so a block that -// forgets to gate itself is not a dead row, it is five rows appearing in a menu -// about a list the user is not looking at. That is exactly how the first cut of -// this kit shipped. -// -// It drives musicMenuRowDrawn (the pane's own row filter) rather than re-deciding -// liveness, and asserts BOTH directions: nothing of the block on the Music view, -// all of it — divider included — on the Areas view. The divider matters on its own, -// because it carries the shared musicMenuSeparator kind and so is invisible to -// every per-kind predicate: gate the four rows and forget the fifth and the music -// menu ends in a rule under its last row with nothing beneath it. -func TestMusicViewMenuCarriesNoAreaRow(t *testing.T) { +// TestEachListMenuHoldsOnlyItsOwnRows: the Music, Areas and player-list views open one shared popup, and each sees only +// its own block (#85), with no divider at either end. +func TestEachListMenuHoldsOnlyItsOwnRows(t *testing.T) { const themed = false // the classic panel; the volume row's answer is not what's under test - drawn := func(a *App) (areaRows int, height int32) { - for i, row := range musicMenuRows { - if !a.musicMenuRowDrawn(i, themed) { - continue + blockOf := func(k musicMenuKind) musicMenuSource { + switch { + case isAreaMenuKind(k): + return musicMenuFromAreas + case isRosterMenuKind(k): + return musicMenuFromRoster + } + return musicMenuFromMusic + } + for _, tc := range []struct { + name string + tab int + from musicMenuSource + torn bool + }{ + {"music", logTabMusic, musicMenuFromMusic, false}, + {"areas", logTabAreas, musicMenuFromAreas, false}, + {"roster", logTabPlayers, musicMenuFromRoster, false}, + // A torn Areas panel draws whatever logTab says and carries its own ⋮ (torntabs.go). + {"torn areas", logTabMusic, musicMenuFromAreas, true}, + } { + t.Run(tc.name, func(t *testing.T) { + a := &App{} + a.logTab = tc.tab + if tc.torn { + a.classicOv = map[string][4]float64{tornKeyFor(logTabAreas): {}} } - if isAreaMenuKind(row.kind) { - areaRows++ + a.musicMenuFrom = tc.from + first, last := -1, -1 + for i, row := range musicMenuRows { + drawn := a.musicMenuRowDrawn(i, themed) + if drawn { + if first < 0 { + first = i + } + last = i + } + if row.kind == musicMenuSeparator { + continue + } + if own := blockOf(row.kind) == tc.from; drawn != own { + t.Errorf("%q drawn = %v, want %v", row.label, drawn, own) + } } - } - return areaRows, a.musicMenuHeight(themed) - } - - // logTab lives on the EMBEDDED sessionState (app.go), so it cannot be set by name - // in an App literal — onView builds the whole view state one way for all five - // cases below. - onView := func(tab int) *App { - a := &App{} - a.logTab = tab - return a - } - - music := onView(logTabMusic) - if n, _ := drawn(music); n != 0 { - t.Errorf("the Music view's ⋮ offers %d area row(s) — they act on a list it is not showing", n) - } - if n, _ := drawn(onView(logTabPlayers)); n != 0 { - t.Errorf("the roster toolbar's ⋮ offers %d area row(s)", n) - } - - areas := onView(logTabAreas) - wantRows := 0 - for _, row := range areaMenuRows { - if isAreaMenuKind(row.kind) { - wantRows++ - } - } - gotRows, areasH := drawn(areas) - if gotRows != wantRows { - t.Fatalf("the Areas view's own ⋮ offers %d of its %d rows — the gate is too tight to be useful", gotRows, wantRows) - } - // The block's divider must go dark WITH the block: the height difference is the - // four rows AND one separator, never the rows alone. - _, musicH := drawn(music) - if want := int32(wantRows)*musicMenuItemH + musicMenuSepH; areasH-musicH != want { - t.Errorf("the AREA block costs %d px on the Areas view and 0 on the Music view, want %d px "+ - "(%d rows + its divider) — a divider left behind draws a rule under the last roster row", - areasH-musicH, want, wantRows) + if first < 0 { + t.Fatal("the menu is empty") + } + if musicMenuRows[first].kind == musicMenuSeparator || musicMenuRows[last].kind == musicMenuSeparator { + t.Error("the menu starts or ends with a divider") + } + }) } - // A TORN Areas panel draws whatever logTab says and carries its own ⋮ - // (torntabs.go), so the rows have to be live there too or that button is inert. - torn := onView(logTabMusic) - torn.classicOv = map[string][4]float64{tornKeyFor(logTabAreas): {}} - if n, _ := drawn(torn); n != wantRows { - t.Errorf("a torn-off Areas panel offers %d of its %d rows — its ⋮ opens a menu with nothing in it", n, wantRows) - } - // …and a fully hidden Areas tab draws in none of the three places, torn or not. - hidden := onView(logTabAreas) + // A fully hidden Areas tab draws in none of the three places, torn or not. + hidden := &App{} + hidden.logTab = logTabAreas + hidden.musicMenuFrom = musicMenuFromAreas hidden.hidden = map[string]bool{panelTabAreas: true} - if n, _ := drawn(hidden); n != 0 { - t.Errorf("a hidden Areas tab still offers %d area row(s)", n) + for i := range musicMenuRows { + if hidden.musicMenuRowDrawn(i, themed) { + t.Errorf("a hidden Areas tab still draws %q", musicMenuRows[i].label) + } } } diff --git a/internal/ui/musicheader.go b/internal/ui/musicheader.go index 24492621..3341c80c 100644 --- a/internal/ui/musicheader.go +++ b/internal/ui/musicheader.go @@ -204,20 +204,40 @@ var musicMenuRows = append([]musicMenuRow{ {musicMenuFollow, "Follow players"}, }, areaMenuRows[:]...) -// musicMenuRowLive reports whether a row is offered this frame. The volume view isn't offered in a theme's canvas, -// whose slider rects win. Roster rows are live everywhere; area rows only from the Areas view (areamenu.go). +// musicMenuSource is the list view whose ⋮ or right-click opened the shared menu. +type musicMenuSource uint8 + +const ( + musicMenuFromMusic musicMenuSource = iota + musicMenuFromAreas + musicMenuFromRoster +) + +// isRosterMenuKind reports whether k belongs to the roster block. +func isRosterMenuKind(k musicMenuKind) bool { + return k >= musicMenuRosterRefresh && k <= musicMenuFollow +} + +// musicMenuRowLive reports whether a row is offered this frame: each view's menu holds only its own block (#85). The +// volume view isn't offered in a theme's canvas, whose slider rects win. func (a *App) musicMenuRowLive(k musicMenuKind, themed bool) bool { - if isAreaMenuKind(k) { - return a.areaMenuRowLive(k) // areamenu.go owns the AREA block - } - if k == musicMenuVolumeView { + switch { + case k == musicMenuSeparator: + return true + case isAreaMenuKind(k): + return a.musicMenuFrom == musicMenuFromAreas && a.areaMenuRowLive(k) // areamenu.go owns the AREA block + case isRosterMenuKind(k): + return a.musicMenuFrom == musicMenuFromRoster + case a.musicMenuFrom != musicMenuFromMusic: + return false + case k == musicMenuVolumeView: return !themed } return true } -// musicMenuRowDrawn reports whether row i paints: it is live and, if a separator, some live item follows. A separator -// has no kind of its own, so this takes a block's divider down with the block. +// musicMenuRowDrawn reports whether row i paints: it is live and, if a separator, live items lie on both sides of it. +// A separator has no kind of its own, so this takes a block's divider down with the block. func (a *App) musicMenuRowDrawn(i int, themed bool) bool { row := musicMenuRows[i] if !a.musicMenuRowLive(row.kind, themed) { @@ -226,6 +246,16 @@ func (a *App) musicMenuRowDrawn(i int, themed bool) bool { if row.kind != musicMenuSeparator { return true } + itemAbove := false + for _, prev := range musicMenuRows[:i] { + if prev.kind != musicMenuSeparator && a.musicMenuRowLive(prev.kind, themed) { + itemAbove = true + break + } + } + if !itemAbove { + return false // a divider never opens the menu + } for _, next := range musicMenuRows[i+1:] { if next.kind == musicMenuSeparator { return false // the run to this divider's right is empty; the next one owns it @@ -301,19 +331,20 @@ func (a *App) musicEffectsSupported() bool { return a.sess != nil && a.sess.Features.Has(protocol.FeatureEffects) } -// openMusicMenu opens the menu at `at` (the draw clamps it). The tab is stored so a popup can't survive a tab switch, -// and themed because the menu paints after the panel has returned. -func (a *App) openMusicMenu(at sdl.Point, themed bool) { +// openMusicMenu opens from's menu at `at` (the draw clamps it). The tab is stored so a popup can't survive a tab +// switch, and themed because the menu paints after the panel has returned. +func (a *App) openMusicMenu(at sdl.Point, themed bool, from musicMenuSource) { a.musicMenuAt = at a.musicMenuTab = a.activeTab a.musicMenuThemed = themed + a.musicMenuFrom = from a.musicMenuOpen = true } // openMusicMenuFromButton opens the menu and consumes the press: musicIconButton never clears c.clicked, and the panel // anchors below the button, so drawMusicMenu's click-away would close it the frame it opened. -func (a *App) openMusicMenuFromButton(at sdl.Point, themed bool) { - a.openMusicMenu(at, themed) +func (a *App) openMusicMenuFromButton(at sdl.Point, themed bool, from musicMenuSource) { + a.openMusicMenu(at, themed, from) a.ctx.clicked = false // the opening click is the menu's, not the click-away's } diff --git a/internal/ui/musicheader_test.go b/internal/ui/musicheader_test.go index 59395573..a986e84b 100644 --- a/internal/ui/musicheader_test.go +++ b/internal/ui/musicheader_test.go @@ -215,7 +215,7 @@ func TestMusicKebabSurvivesItsOwnOpeningClick(t *testing.T) { return a } - if a := frame(func(a *App, at sdl.Point) { a.openMusicMenuFromButton(at, false) }); !a.musicMenuOpen { + if a := frame(func(a *App, at sdl.Point) { a.openMusicMenuFromButton(at, false, musicMenuFromMusic) }); !a.musicMenuOpen { t.Error("the ⋮ menu closed on the frame it opened — every row it hosts (volume " + "view, the four MC playback flags, stop, random) is then reachable only by " + "right-clicking the track list") @@ -224,7 +224,7 @@ func TestMusicKebabSurvivesItsOwnOpeningClick(t *testing.T) { // the assertion above is load-bearing rather than vacuously true. If this one // goes red, the click-away rule changed — re-derive whether the consumption is // still what keeps the button alive. - if a := frame(func(a *App, at sdl.Point) { a.openMusicMenu(at, false) }); a.musicMenuOpen { + if a := frame(func(a *App, at sdl.Point) { a.openMusicMenu(at, false, musicMenuFromMusic) }); a.musicMenuOpen { t.Error("an unconsumed opening click no longer closes the menu, so this test can " + "no longer prove openMusicMenuFromButton's consumption is what fixes the ⋮") } diff --git a/internal/ui/playerlist.go b/internal/ui/playerlist.go index b9df163a..25983cb1 100644 --- a/internal/ui/playerlist.go +++ b/internal/ui/playerlist.go @@ -197,8 +197,8 @@ func (a *App) drawPlayerList(r sdl.Rect) { case plItemMenu: // Same helper as the Music header, click consumption included, or click-away closes the menu at once. // themed is derived: inside the theme's music_list, drawMusicList discards the Volume-sliders row. - if a.musicIconButton(it.r, iconKebab, "Roster & playback options — refresh details, legacy snapshot, pair status, follow") { - a.openMusicMenuFromButton(sdl.Point{X: it.r.X, Y: it.r.Y + it.r.H}, a.rosterMenuThemed()) + if a.musicIconButton(it.r, iconKebab, "Roster options — refresh details, legacy snapshot, pair status, follow") { + a.openMusicMenuFromButton(sdl.Point{X: it.r.X, Y: it.r.Y + it.r.H}, a.rosterMenuThemed(), musicMenuFromRoster) } } } diff --git a/internal/ui/screensmusic.go b/internal/ui/screensmusic.go index a89ca3bd..16c7602b 100644 --- a/internal/ui/screensmusic.go +++ b/internal/ui/screensmusic.go @@ -259,7 +259,7 @@ func (a *App) drawMusicList(r sdl.Rect, themed, searchExternal, nowPlayingExtern if br, ok := plan.rect(musicItemMenu); ok { if a.musicIconButton(br, iconKebab, "More: playback options, volume sliders (right-click the list opens this too)") { // FromButton: the press must be consumed or drawMusicMenu's click-away closes the menu the frame it opened. - a.openMusicMenuFromButton(sdl.Point{X: br.X, Y: br.Y + br.H}, themed) + a.openMusicMenuFromButton(sdl.Point{X: br.X, Y: br.Y + br.H}, themed, musicMenuFromMusic) } } // "music_name" is AO2's id for this line (courtroom.cpp:1201). elemLabelFont keeps the chrome face when the theme @@ -370,7 +370,7 @@ func (a *App) drawMusicList(r sdl.Rect, themed, searchExternal, nowPlayingExtern // Right-click opens the same menu as the ⋮ button; AO2's entry point is on_music_list_context_menu_requested // (courtroom.cpp:5821). if c.rightClicked && c.hovering(r) { - a.openMusicMenu(sdl.Point{X: c.mouseX, Y: c.mouseY}, themed) + a.openMusicMenu(sdl.Point{X: c.mouseX, Y: c.mouseY}, themed, musicMenuFromMusic) c.rightClicked = false } } From 08e2c0e53b7c78d83a84e5d15354318502d1efc4 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:52:13 +0000 Subject: [PATCH 10/13] ui: fold repeated blankposts in the IC log AO2 suppresses a blankpost when it repeats the previous blankpost from the same speaker. Match that in both the active and parked-tab IC logs while still delivering every blankpost to the courtroom for its emote change. The folded entry carries the queue weight so ghost text stays paired with the play queue. Refs #64 --- internal/ui/app_connect.go | 37 +++++++++++++++++---------------- internal/ui/app_ic.go | 42 ++++++++++++++++++++++++++++++++++++-- internal/ui/ghosttext.go | 5 ++++- internal/ui/tabs.go | 12 ++++++----- 4 files changed, 70 insertions(+), 26 deletions(-) diff --git a/internal/ui/app_connect.go b/internal/ui/app_connect.go index a52a128c..e9ba75fb 100644 --- a/internal/ui/app_connect.go +++ b/internal/ui/app_connect.go @@ -734,24 +734,25 @@ func (a *App) handleSessionEvents(events []courtroom.Event) { force := a.d.Prefs.Load().ForceCharNames // The log's name resolves through the same char.ini rung as the plate (remoteIniShownameFor). line, speaker, bodyRuneStart, styles := icLogEntry(ev.Message, force, a.friendNick(ev.Message), a.remoteIniShownameFor) - a.pushICStyled(line, ev.Message.TextColor, fr, fc, speaker, styles, bodyRuneStart) - // Store the speaker's position (wire Side) per entry for the advanced pos filter. - a.icLog[len(a.icLog)-1].pos = icPos(ev.Message) - // This line has a message in the play queue behind it: the log is written on arrival, the courtroom - // speaks it later, and ghost text (ghosttext.go) pairs the two by counting. Stamped only here because - // the EventMessage branch is the only push that enqueues. - a.icLog[len(a.icLog)-1].speech = true - // Reactions: stamp the entry with its content-stable ref, computed from the raw wire fields (CharName + - // marker-free text), not the display line, which bakes in client-local showname, nick and timestamp and - // wouldn't match a peer's ref. A speaker line becomes a reaction target and the "last message"; float - // any reaction this message carries. - if speaker != "" { - ref := courtroom.MakeReactionRef(ev.Message.CharName, courtroom.StripSpriteStyle(ev.Message.Message)) - a.icLog[len(a.icLog)-1].ref = ref - a.lastReactRef, a.lastReactName = ref, speaker - } - if r, ok := courtroom.DecodeReactionMarker(ev.Message.Message); ok { - a.onIncomingReaction(r) + if a.pushICStyled(line, ev.Message.TextColor, fr, fc, speaker, styles, bodyRuneStart) { + // Store the speaker's position (wire Side) per entry for the advanced pos filter. + a.icLog[len(a.icLog)-1].pos = icPos(ev.Message) + // This line has a message in the play queue behind it: the log is written on arrival, the courtroom + // speaks it later, and ghost text (ghosttext.go) pairs the two by counting. Stamped only here because + // the EventMessage branch is the only push that enqueues. + a.icLog[len(a.icLog)-1].speech = true + // Reactions: stamp the entry with its content-stable ref, computed from the raw wire fields (CharName + + // marker-free text), not the display line, which bakes in client-local showname, nick and timestamp and + // wouldn't match a peer's ref. A speaker line becomes a reaction target and the "last message"; float + // any reaction this message carries. + if speaker != "" { + ref := courtroom.MakeReactionRef(ev.Message.CharName, courtroom.StripSpriteStyle(ev.Message.Message)) + a.icLog[len(a.icLog)-1].ref = ref + a.lastReactRef, a.lastReactName = ref, speaker + } + if r, ok := courtroom.DecodeReactionMarker(ev.Message.Message); ok { + a.onIncomingReaction(r) + } } a.noteShowname(ev.Message.CharName, ev.Message.Showname) // live-roster name cache a.notePairPartner(ev.Message) // #20: track each player's current pair diff --git a/internal/ui/app_ic.go b/internal/ui/app_ic.go index b37de789..29238294 100644 --- a/internal/ui/app_ic.go +++ b/internal/ui/app_ic.go @@ -7,6 +7,7 @@ import ( "sort" "strings" "time" + "unicode" "github.com/SyntaxNyah/AsyncAO/internal/assets" "github.com/SyntaxNyah/AsyncAO/internal/config" @@ -837,6 +838,9 @@ type icEntry struct { ref uint32 // content-stable reaction ref (#2): MakeReactionRef(CharName, clean text); 0 = system line // speech marks a line from an IC message, which has a counterpart in the play queue (see ghosttext.go). speech bool + // speechExtra counts additional queued messages folded into this entry's repeated blankposts, so ghost + // text still pairs one log row with every message the log collapsed. + speechExtra int // styles holds inline-colour runs over the body; bodyRuneStart is the rune offset of the body within text. styles []courtroom.StyleRun bodyRuneStart int @@ -1064,8 +1068,39 @@ func (a *App) pushIC(line string, color int, friend bool, friendColor int32, spe a.pushICStyled(line, color, friend, friendColor, speaker, nil, 0) } +// icBodyBlank reports whether the body at bodyRuneStart has no visible text. The head before it is the +// speaker prefix; a blank body is a blankpost. +func icBodyBlank(line string, bodyRuneStart int) bool { + if bodyRuneStart <= 0 { + return false + } + n := 0 + for _, r := range line { + if n >= bodyRuneStart && !unicode.IsSpace(r) { + return false + } + n++ + } + return n >= bodyRuneStart +} + +// appendICEntry appends e, folding a repeated blankpost from the same speaker into the previous entry. +// It returns false when folded; the previous entry then represents one more queued message. +func appendICEntry(log *[]icEntry, e icEntry) bool { + if n := len(*log); n > 0 { + last := &(*log)[n-1] + if e.speaker == last.speaker && icBodyBlank(e.text, e.bodyRuneStart) && icBodyBlank(last.text, last.bodyRuneStart) { + last.speechExtra++ + return false + } + } + *log = append(*log, e) + return true +} + // pushICStyled is pushIC plus the inline-colour runs and the body's rune offset within the line. -func (a *App) pushICStyled(line string, color int, friend bool, friendColor int32, speaker string, styles []courtroom.StyleRun, bodyRuneStart int) { +// It returns false when a repeated blankpost was folded into the previous entry. +func (a *App) pushICStyled(line string, color int, friend bool, friendColor int32, speaker string, styles []courtroom.StyleRun, bodyRuneStart int) bool { // Cap first: everything else describes the stored text. extractURLs splits on Fields and no codec rune is // whitespace, // so a trailing marker would fuse onto a link, @@ -1075,12 +1110,15 @@ func (a *App) pushICStyled(line string, color int, friend bool, friendColor int3 if urls := extractURLs(line, 1); len(urls) > 0 { url = urls[0] } - a.icLog = append(a.icLog, icEntry{text: line, color: color, url: url, friend: friend, friendColor: friendColor, speaker: speaker, stamp: a.icStamp(), styles: styles, bodyRuneStart: bodyRuneStart}) + if !appendICEntry(&a.icLog, icEntry{text: line, color: color, url: url, friend: friend, friendColor: friendColor, speaker: speaker, stamp: a.icStamp(), styles: styles, bodyRuneStart: bodyRuneStart}) { + return false + } if cap := a.icLogCapFor(); cap > 0 && len(a.icLog) > cap { copy(a.icLog, a.icLog[len(a.icLog)-cap:]) a.icLog = a.icLog[:cap] } a.icLogSeq++ // invalidate the filter cache (len alone lies at the cap) + return true } // icLogCapFor returns the live IC scrollback cap, 0 for no cap; diff --git a/internal/ui/ghosttext.go b/internal/ui/ghosttext.go index 0010fcc2..f2b9eef1 100644 --- a/internal/ui/ghosttext.go +++ b/internal/ui/ghosttext.go @@ -42,6 +42,7 @@ func queuedCount(queued int) int { } // firstQueuedEntry returns the index of the oldest of the n most recent speech lines, skipping system lines. +// A folded blankpost entry stands for its whole run, so its weight is 1 + speechExtra. // Returns len(log) when n is 0 or the log holds too few: it can under-hide, never hide a line already said. func firstQueuedEntry(log []icEntry, n int) int { if n <= 0 { @@ -51,9 +52,11 @@ func firstQueuedEntry(log []icEntry, n int) int { if !log[i].speech { continue } - if n--; n == 0 { + weight := 1 + log[i].speechExtra + if n <= weight { return i } + n -= weight } return len(log) } diff --git a/internal/ui/tabs.go b/internal/ui/tabs.go index 7754f820..8dcc08e0 100644 --- a/internal/ui/tabs.go +++ b/internal/ui/tabs.go @@ -426,12 +426,14 @@ func (a *App) routeBackgroundEvent(t *courtTab, ev courtroom.Event) { // One name for both the entry's speaker and capLogLine's head marker, so the two can't drift. speaker := icSpeakerName(ev.Message, force, nil) line, _, bodyRuneStart, styles := icLogEntry(ev.Message, force, "", nil) - s.icLog = append(s.icLog, icEntry{text: capLogLine(line, speaker), color: ev.Message.TextColor, friend: fr, friendColor: fc, speaker: speaker, pos: icPos(ev.Message), stamp: a.icStamp(), styles: styles, bodyRuneStart: bodyRuneStart}) - if cap := a.icLogCapFor(); cap > 0 && len(s.icLog) > cap { - copy(s.icLog, s.icLog[len(s.icLog)-cap:]) - s.icLog = s.icLog[:cap] + entry := icEntry{text: capLogLine(line, speaker), color: ev.Message.TextColor, friend: fr, friendColor: fc, speaker: speaker, pos: icPos(ev.Message), stamp: a.icStamp(), styles: styles, bodyRuneStart: bodyRuneStart} + if appendICEntry(&s.icLog, entry) { + if cap := a.icLogCapFor(); cap > 0 && len(s.icLog) > cap { + copy(s.icLog, s.icLog[len(s.icLog)-cap:]) + s.icLog = s.icLog[:cap] + } + s.icLogSeq++ } - s.icLogSeq++ t.unread++ if fr { a.signalFriend(s.serverName, ev.Message) // alert even from a backgrounded server From 09d88104c3f017b432eb9247efc07b6fc2ad6e86 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:05:19 +0000 Subject: [PATCH 11/13] deps: bump aolib to v2.6.5 Picks up the aolib fix that serializes jsonschema.Compiler, preventing concurrent map read/write fatals when multiple sessions validate their first JSON packets. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9e5d5b48..e09deb2f 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( require github.com/coder/websocket v1.8.12 -require github.com/AO-Underground/aolib/go/v2 v2.6.1 +require github.com/AO-Underground/aolib/go/v2 v2.6.5 require ( github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect diff --git a/go.sum b/go.sum index 2118f5a7..c1209344 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/AO-Underground/aolib/go/v2 v2.6.1 h1:Pn/BZ5desmvnCS21iZdVpuX6HpLSUhTva9To1YXJl8o= -github.com/AO-Underground/aolib/go/v2 v2.6.1/go.mod h1:8zK2xBlP1VOw+YZNhyv+slbFv7OP6B8AnDGRuFq7q3A= +github.com/AO-Underground/aolib/go/v2 v2.6.5 h1:1iUlL9LzDNkAo+4tgtqQQARKbJj6/FzHNl7X8d1x2so= +github.com/AO-Underground/aolib/go/v2 v2.6.5/go.mod h1:8zK2xBlP1VOw+YZNhyv+slbFv7OP6B8AnDGRuFq7q3A= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/coder/websocket v1.8.12 h1:5bUXkEPPIbewrnkU8LTCLVaxi4N4J8ahufH2vlo4NAo= From 207a6c879c881abe33b99fccac87e4a2ab6a2a57 Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Wed, 18 Nov 2026 21:37:07 +0100 Subject: [PATCH 12/13] changelog: v2.1.1-rc.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test build's notes list the bug fixes on v2.1.1-devel: the one-frame animated WebP, the held message that asks again, folded blankposts, the sprite preview's scaling (#88), effect icon shape (#77), the SFX Browser in front of the Extras box (#32), each list's own ⋮ menu (#85), the theme fit preview's hint (#153), the aolib crash fix and the one-click Wardrobe setting. The shipped-changelog test now pins the newest entry and allows a pre-release header. Co-Authored-By: Claude Opus 5.5 --- internal/ui/assets/CHANGELOG.md | 24 ++++++++++++++++++++++++ internal/ui/markdown_test.go | 18 +++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/internal/ui/assets/CHANGELOG.md b/internal/ui/assets/CHANGELOG.md index 4c39fdb1..21e8c058 100644 --- a/internal/ui/assets/CHANGELOG.md +++ b/internal/ui/assets/CHANGELOG.md @@ -4,6 +4,30 @@ What changed, newest first. The "What's New" screen renders this embedded file, so every build ships its own history offline. The version you're running is tagged "installed" below. +## v2.1.1-rc.1 - 2026-11-18 + +A test build of a bug-fix release for v2.1.0. Only players with +**Include pre-releases** switched on get this update. + +- A sprite saved as an animated WebP with a single frame shows again. Before, + it never appeared, and with strict sequencing every message using it waited + 10 seconds. +- A message waiting on a missing file no longer sits out the whole 10 seconds + when the missing-file notice gets lost; it asks again every second. +- Repeated blankposts from the same speaker show once in the IC log, as in AO2. +- The sprite preview uses the character's own scaling from the first frame, so + pixel-art characters no longer preview blurry until they speak. +- Effect icons in the effects dropdown keep their shape instead of stretching. +- The SFX Browser opens in front of the Extras box instead of behind it. +- Each list's ⋮ menu shows only its own options: the player list no longer + offers music fade and loop, and the music list no longer offers roster + options. +- A theme without `courtroom_design.ini` no longer draws the drag hint over + its notice in the theme fit preview. +- Fixed a crash when several servers sent their first packets at once. +- New Wardrobe setting in Settings ▸ General: **Click: Selects / Wears**. With + Wears, one click wears a character. Off by default. + ## v2.1.0 - 2026-11-14 AsyncAO moves from SDL2 to SDL3. It draws with Direct3D 11 on Windows and diff --git a/internal/ui/markdown_test.go b/internal/ui/markdown_test.go index 64c5c05e..72710223 100644 --- a/internal/ui/markdown_test.go +++ b/internal/ui/markdown_test.go @@ -79,26 +79,22 @@ func TestParseMarkdownBlocks(t *testing.T) { } } -// TestShippedChangelog pins what the What's New screen shows: v2.1.0 is the first entry, no pre-release entry is left, -// and no heading keeps markdown markup. +// TestShippedChangelog pins what the What's New screen shows: the newest release is the first entry, and no heading +// keeps markdown markup. func TestShippedChangelog(t *testing.T) { + const newest = "v2.1.1-rc.1 " blocks := parseMarkdownBlocks(changelogMD) first := "" for _, b := range blocks { - if b.level == markdownSection { - if first == "" { - first = b.text - } - if strings.Contains(b.text, "-rc.") { - t.Errorf("pre-release entry %q is still in the changelog", b.text) - } + if b.level == markdownSection && first == "" { + first = b.text } if b.level > 0 && strings.ContainsAny(b.text, "*`") { t.Errorf("heading %q keeps markup", b.text) } } - if !strings.HasPrefix(first, "v2.1.0 ") { - t.Errorf("first entry %q, want v2.1.0", first) + if !strings.HasPrefix(first, newest) { + t.Errorf("first entry %q, want %s", first, newest) } } From 0f402676da1b3024b2a2d92c6440431275dfe98b Mon Sep 17 00:00:00 2001 From: SyntaxNyah <235356625+SyntaxNyah@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:15:25 +0000 Subject: [PATCH 13/13] changelog: v2.1.1 Promote the v2.1.1-rc.1 test build to the stable v2.1.1 release. The changelog drops the pre-release wording, and the shipped-changelog test pins the stable heading. --- internal/ui/assets/CHANGELOG.md | 5 ++--- internal/ui/markdown_test.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/ui/assets/CHANGELOG.md b/internal/ui/assets/CHANGELOG.md index 21e8c058..04411e17 100644 --- a/internal/ui/assets/CHANGELOG.md +++ b/internal/ui/assets/CHANGELOG.md @@ -4,10 +4,9 @@ What changed, newest first. The "What's New" screen renders this embedded file, so every build ships its own history offline. The version you're running is tagged "installed" below. -## v2.1.1-rc.1 - 2026-11-18 +## v2.1.1 - 2026-11-28 -A test build of a bug-fix release for v2.1.0. Only players with -**Include pre-releases** switched on get this update. +A bug-fix release for v2.1.0. - A sprite saved as an animated WebP with a single frame shows again. Before, it never appeared, and with strict sequencing every message using it waited diff --git a/internal/ui/markdown_test.go b/internal/ui/markdown_test.go index 72710223..973cba27 100644 --- a/internal/ui/markdown_test.go +++ b/internal/ui/markdown_test.go @@ -82,7 +82,7 @@ func TestParseMarkdownBlocks(t *testing.T) { // TestShippedChangelog pins what the What's New screen shows: the newest release is the first entry, and no heading // keeps markdown markup. func TestShippedChangelog(t *testing.T) { - const newest = "v2.1.1-rc.1 " + const newest = "v2.1.1 " blocks := parseMarkdownBlocks(changelogMD) first := "" for _, b := range blocks {