Reimplement the archived UI widget stack on the new element-tree system
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>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
var Player = require('./Player.js');
|
||||
var PlayerCamera = require('./PlayerCamera.js');
|
||||
var TestPlane = require('./TestPlane.js');
|
||||
var TestUIElement = require('./TestUIElement.js');
|
||||
var FpsCounter = require('./FpsCounter.js');
|
||||
var ConsoleOverlay = require('./ConsoleOverlay.js');
|
||||
|
||||
class OverworldScene {
|
||||
constructor() {
|
||||
@@ -11,15 +14,14 @@ class OverworldScene {
|
||||
this.plane = new TestPlane();
|
||||
this.camera = new PlayerCamera(this.player);
|
||||
|
||||
this.rect = new Rectangle();
|
||||
this.rect.color = { r: 255, g: 0, b: 0, a: 255 };
|
||||
this.rect.width = 100;
|
||||
this.rect.height = 100;
|
||||
UI.add(this.rect);
|
||||
|
||||
this.label = new Label();
|
||||
this.label.text = 'Hello World!';
|
||||
this.rect.add(this.label);
|
||||
this.testUi = new TestUIElement();
|
||||
UI.add(this.testUi);
|
||||
|
||||
this.fpsCounter = new FpsCounter();
|
||||
UI.addOverlay(this.fpsCounter);
|
||||
|
||||
this.consoleOverlay = new ConsoleOverlay();
|
||||
UI.addOverlay(this.consoleOverlay);
|
||||
}
|
||||
|
||||
lateUpdate() {
|
||||
@@ -31,16 +33,19 @@ class OverworldScene {
|
||||
this.player.dispose();
|
||||
this.plane.dispose();
|
||||
|
||||
// rect.dispose() cascades to label (added as its child) and removes
|
||||
// itself from UI's render roots -- no separate UI.remove()/dispose()
|
||||
// needed for either.
|
||||
this.rect.dispose();
|
||||
// testUi.dispose() cascades to its background/label children and
|
||||
// removes itself from UI's render roots -- no separate UI.remove()
|
||||
// needed.
|
||||
this.testUi.dispose();
|
||||
this.fpsCounter.dispose();
|
||||
this.consoleOverlay.dispose();
|
||||
|
||||
this.camera = null;
|
||||
this.camera = null;
|
||||
this.player = null;
|
||||
this.plane = null;
|
||||
this.label = null;
|
||||
this.rect = null;
|
||||
this.testUi = null;
|
||||
this.fpsCounter = null;
|
||||
this.consoleOverlay = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user