b639bc6c4f
The old widget system (archive/dusk/ui/) depended on infrastructure this rewrite deleted -- a static X-macro element list, a 9-slice UI_FRAME, and a global gamepad/keyboard focus stack -- so everything below is rebuilt on top of the new native uielement_t pool + parent/child tree instead, gamepad/keyboard-only (no mouse support exists in the input system). New JS widgets (assets/scripts/), all pure composites of Label/Rectangle following the Button.js pattern: Checkbox, Tab, Slider, Dropdown. Slider/ Dropdown expose a directionInput(dx, dy) hook so a menu can hand them LEFT/RIGHT before falling back to cursor movement. New Menu.js replaces the old global uifocus_t stack: a small push/pop stack of Menu instances where only the topmost consumes CANCEL/ACCEPT/ direction input each tick (needed for nested modals -- a Settings sub-page menu plus a "discard changes?" Confirm can be open at once). Held-direction repeat timing matches the old 0.5s delay / 0.1s repeat. New overlay composites (added via a new UI.addOverlay()/UI.removeOverlay(), always drawn/updated after normal roots): FpsCounter, ConsoleOverlay (one Label per console history line, driven directly rather than via add() since History (16) exceeds the 8-children-per-element cap), Crop (letterbox/pillarbox bars), and Fullbox (a reusable tweened full-screen fade covering both the old fullbox and transition effects -- reuses shared instances rather than allocate-and-dispose, since disposing an element from inside its own render() callback risks the same JerryScript refcount corruption hit earlier in this rewrite). New Confirm.js (Yes/No dialog) and Settings.js (+ SettingsGeneral/ SettingsInput sub-pages) built on Menu. Display/Audio settings pages are intentionally not ported -- neither had a real backing engine system even in the old code. Frame is a flat Rectangle for now, not real 9-slice (a genuinely bigger native lift, deliberately deferred). Small native binding additions needed by the above, each with its own unit test: Time.renderDelta, Console.lineCount/getLine/visible/ consumeDirty, a new Screen module, a new Locale module, Input.deadzone, a new Save module, and Label.color (was missing entirely). Also fixes a real gap from the UI.addOverlay() work: uiElementDispose() wasn't removing disposed elements from the new overlay root array, which would have left dangling ids behind. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
// Copyright (c) 2026 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
// One Label per console history slot, refreshed only when
|
|
// Console.consumeDirty() says the history actually changed -- reuses
|
|
// the normal Label/spritebatch render path instead of the old
|
|
// hand-rolled mesh-cache renderer.
|
|
//
|
|
// These Labels are NOT add()ed as children -- UIElement.add() caps at 8
|
|
// children per element, and CONSOLE_HISTORY_MAX (Console.lineCount) is
|
|
// 16, over that cap. Instead they're driven directly: render()/update()
|
|
// called explicitly below, and their world position is just their own
|
|
// x/y (never having a parent means nothing offsets it).
|
|
class ConsoleOverlay extends UIElement {
|
|
init() {
|
|
this.lines = [];
|
|
for(let i = 0; i < Console.lineCount; i++) {
|
|
const label = new Label();
|
|
label.x = 4;
|
|
label.y = 4 + i * ConsoleOverlay.LINE_HEIGHT;
|
|
this.lines.push(label);
|
|
}
|
|
|
|
this._refresh();
|
|
}
|
|
|
|
update() {
|
|
this.updateChildren();
|
|
if(Console.consumeDirty()) this._refresh();
|
|
for(let i = 0; i < this.lines.length; i++) this.lines[i].update();
|
|
}
|
|
|
|
// Overridden (rather than left to auto-render) so the console can be
|
|
// hidden entirely without disposing/rebuilding its Labels.
|
|
render() {
|
|
this.renderChildren();
|
|
if(!Console.visible) return;
|
|
for(let i = 0; i < this.lines.length; i++) this.lines[i].render();
|
|
}
|
|
|
|
// this.lines was never add()ed, so the normal dispose() cascade can't
|
|
// reach them -- release them explicitly first, or they'd leak their
|
|
// pool slots.
|
|
dispose() {
|
|
for(let i = 0; i < this.lines.length; i++) this.lines[i].dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
_refresh() {
|
|
for(let i = 0; i < this.lines.length; i++) {
|
|
this.lines[i].text = Console.getLine(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
ConsoleOverlay.LINE_HEIGHT = 12;
|
|
|
|
module.exports = ConsoleOverlay;
|