@overmvp/kumi 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/module-declarations.mjs +2 -2
- package/builder/module-declarations.test.mjs +4 -2
- package/package.json +1 -1
- package/router/router-view.ts +5 -3
- package/scripts/addon-build.mjs +2 -0
- package/scripts/kumi-cli.mjs +0 -0
- package/src/elements.ts +11 -1
- package/src/module-ui.ts +4 -0
- package/src/module.ts +14 -4
- package/templates/addon/src/app/app.module.ts +3 -5
- package/templates/addon/src/modules/greeting/greeting.module.ts +2 -2
- package/templates/addon/src/modules/playtime/playtime.module.ts +3 -5
- package/utils/format.ts +13 -0
- package/utils/index.ts +1 -1
- package/wow/animation.ts +16 -4
- package/wow/app-ui.ts +132 -22
- package/wow/aura-container.ts +132 -38
- package/wow/aura-countdown.ts +19 -3
- package/wow/aura-follower.ts +32 -0
- package/wow/aura-view.ts +49 -0
- package/wow/css-box.ts +7 -4
- package/wow/css-surfaces.ts +10 -4
- package/wow/frames.ts +2 -0
- package/wow/hooks.ts +17 -0
- package/wow/hotkeys.ts +221 -0
- package/wow/index.ts +9 -5
- package/wow/initial-view.ts +99 -0
- package/wow/layout-view.ts +1 -1
- package/wow/native.ts +1 -0
- package/wow/pixel.ts +25 -0
- package/wow/scroll-view.ts +5 -4
- package/wow/status-bar.ts +65 -0
- package/wow/unit-button.ts +25 -4
- package/wow/view-nodes.ts +11 -4
- package/wow/view.ts +113 -116
package/wow/aura-container.ts
CHANGED
|
@@ -3,13 +3,14 @@ import { fail, ok, type Failure, type Result } from "../src/result";
|
|
|
3
3
|
import type { AuraDispelTarget } from "./aura-button";
|
|
4
4
|
import type { FontString, Frame, FrameMap, FrameParent, Texture } from "./frames";
|
|
5
5
|
import { rawField, weakKeys } from "./lua-table";
|
|
6
|
-
import { api, isSecret } from "./native";
|
|
6
|
+
import { api, isSecret, reveal } from "./native";
|
|
7
7
|
import { protect } from "./protect";
|
|
8
8
|
|
|
9
9
|
export type AuraButton = Frame & AuraDispelTarget & {
|
|
10
10
|
SetIcon?(this: object, texture: Texture): void;
|
|
11
11
|
SetDurationCooldown?(this: object, cooldown: FrameMap["Cooldown"]): void;
|
|
12
12
|
SetApplicationCount?(this: object, text: FontString): void;
|
|
13
|
+
SetDurationText?: Parameters<typeof import("./aura-countdown").bindAuraDurationText>[0]["SetDurationText"];
|
|
13
14
|
SetTooltipAnchorPoint?(this: object, anchor: "ANCHOR_BOTTOMRIGHT", x: number, y: number): void;
|
|
14
15
|
};
|
|
15
16
|
|
|
@@ -28,6 +29,7 @@ export interface AuraCandidateFilters {
|
|
|
28
29
|
readonly isFromPlayerOrPlayerPet?: boolean;
|
|
29
30
|
readonly isStealable?: boolean;
|
|
30
31
|
readonly isNameplateOnly?: boolean;
|
|
32
|
+
readonly nameplateShowPersonal?: boolean;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export interface AuraGroupFilter {
|
|
@@ -73,14 +75,26 @@ export interface AuraContainerOptions {
|
|
|
73
75
|
onActivated?(this: void, frame: Frame, unit: string): void;
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
export interface AuraFlowLayout {
|
|
79
|
+
readonly gap: number;
|
|
80
|
+
readonly rowGap: number;
|
|
81
|
+
readonly lineWidth: number;
|
|
82
|
+
readonly maxFrameCount: number;
|
|
83
|
+
readonly groupLimits?: Readonly<Partial<Record<string, number>>>;
|
|
84
|
+
}
|
|
85
|
+
|
|
76
86
|
export interface AuraContainer {
|
|
77
87
|
readonly frame: Frame;
|
|
78
88
|
/** Register a fixed aura slot on this display. */
|
|
79
89
|
addSlot(this: void, slot: AuraContainerSlot): Result<void>;
|
|
80
90
|
/** Force a reread when a new occupant uses the same unit token. */
|
|
81
91
|
activate(this: void, unit: string, force?: boolean): Result<void>;
|
|
82
|
-
/** Update
|
|
83
|
-
rebind(this: void, unit: string, filters: readonly AuraGroupFilter[]): Result<void>;
|
|
92
|
+
/** Update filters and refresh the binding. Exact updates fail closed if the client rejects a filter. */
|
|
93
|
+
rebind(this: void, unit: string, filters: readonly AuraGroupFilter[], exact?: true): Result<void>;
|
|
94
|
+
setGroupEnabled(this: void, key: string, enabled: boolean): Result<void>;
|
|
95
|
+
/** Retune existing native groups out of combat without rebuilding their buttons. */
|
|
96
|
+
setFlowLayout(this: void, layout: AuraFlowLayout): Result<void>;
|
|
97
|
+
setPlacement(this: void, point: AuraContainerOptions["anchor"], grow?: AuraContainerOptions["grow"]): Result<void>;
|
|
84
98
|
/** Hide the display and keep its native groups and slots for reuse. */
|
|
85
99
|
disable(this: void): Result<void>;
|
|
86
100
|
/** Release the native groups and slots and prevent further activation. */
|
|
@@ -104,19 +118,21 @@ interface NativeSlotOptions {
|
|
|
104
118
|
initializeFrame(this: void, button: AuraButton): void;
|
|
105
119
|
}
|
|
106
120
|
|
|
121
|
+
interface NativeGroupLayout {
|
|
122
|
+
elementWidth: number;
|
|
123
|
+
elementHeight: number;
|
|
124
|
+
elementSpacing: number;
|
|
125
|
+
lineSpacing: number;
|
|
126
|
+
groupSpacing: number;
|
|
127
|
+
groupLineSpacing: number;
|
|
128
|
+
layoutIndex: number;
|
|
129
|
+
}
|
|
130
|
+
|
|
107
131
|
interface NativeGroupOptions extends NativeSlotOptions {
|
|
108
132
|
maxFrameCount: number;
|
|
109
133
|
sortMethod?: number;
|
|
110
134
|
sortDirection?: number;
|
|
111
|
-
layout:
|
|
112
|
-
elementWidth: number;
|
|
113
|
-
elementHeight: number;
|
|
114
|
-
elementSpacing: number;
|
|
115
|
-
elementSpacingX: number;
|
|
116
|
-
elementSpacingY: number;
|
|
117
|
-
lineSpacing: number;
|
|
118
|
-
layoutIndex: number;
|
|
119
|
-
};
|
|
135
|
+
layout: NativeGroupLayout;
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
type NativeContainer = Frame & {
|
|
@@ -132,6 +148,7 @@ type NativeContainer = Frame & {
|
|
|
132
148
|
SetAuraGroupFilterString?(this: object, key: string, filter: string): void;
|
|
133
149
|
SetAuraGroupCandidateFilters?(this: object, key: string, candidateFilters?: AuraCandidateFilters): void;
|
|
134
150
|
SetAuraGroupMaxFrameCount?(this: object, key: string, count: number): void;
|
|
151
|
+
SetAuraGroupLayout?(this: object, key: string, layout: NativeGroupLayout): void;
|
|
135
152
|
SetAuraGroupEnabled?(this: object, key: string, enabled: boolean): void;
|
|
136
153
|
SetAuraSlotEnabled?(this: object, key: string, enabled: boolean): void;
|
|
137
154
|
};
|
|
@@ -176,13 +193,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
176
193
|
const anchorUtil = rawField<{ FlowDirection?: FlowDirection; FlowLayoutAxis?: FlowLayoutAxis }>(api, "AnchorUtil");
|
|
177
194
|
const direction = anchorUtil?.FlowDirection ?? rawField<FlowDirection>(api, "FlowDirection");
|
|
178
195
|
const axis = anchorUtil?.FlowLayoutAxis ?? rawField<FlowLayoutAxis>(api, "FlowLayoutAxis");
|
|
179
|
-
|
|
180
|
-
const [growX, growY] = options.grow ?? [defaultHorizontal, "Down"];
|
|
181
|
-
const horizontal = direction?.[growX];
|
|
182
|
-
const vertical = direction?.[growY];
|
|
183
|
-
if (create === undefined || (hasGroups && (horizontal === undefined || vertical === undefined))) {
|
|
184
|
-
return fail("Native aura layout is unavailable");
|
|
185
|
-
}
|
|
196
|
+
if (create === undefined) return fail("Native aura layout is unavailable");
|
|
186
197
|
const sortMethods = rawField<Partial<Record<NonNullable<AuraContainerGroup["sort"]>, number>>>(api, "AuraContainerSortMethod");
|
|
187
198
|
const sortDirections = rawField<{ Normal?: number; Reverse?: number }>(api, "AuraContainerSortDirection");
|
|
188
199
|
|
|
@@ -192,6 +203,8 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
192
203
|
const container = created.value;
|
|
193
204
|
|
|
194
205
|
const registeredGroups = new Map<string, AuraGroupFilter>();
|
|
206
|
+
const disabledGroups = new Set<string>();
|
|
207
|
+
const groupLimits = new Map<string, number>();
|
|
195
208
|
const registeredSlots = new Set<string>();
|
|
196
209
|
const initialized = weakKeys({});
|
|
197
210
|
let initializationFailure: Failure | undefined;
|
|
@@ -238,7 +251,11 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
238
251
|
for (const key of registeredSlots) release(() => container.SetAuraSlotEnabled?.(key, false));
|
|
239
252
|
release(() => container.SetUnit(noUnit));
|
|
240
253
|
released = result.ok;
|
|
241
|
-
if (released)
|
|
254
|
+
if (released) {
|
|
255
|
+
registeredGroups.clear();
|
|
256
|
+
disabledGroups.clear();
|
|
257
|
+
groupLimits.clear();
|
|
258
|
+
}
|
|
242
259
|
return result;
|
|
243
260
|
}
|
|
244
261
|
|
|
@@ -333,10 +350,10 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
333
350
|
const { key } = requested;
|
|
334
351
|
const accepted = registeredGroups.get(key);
|
|
335
352
|
const setFilter = container.SetAuraGroupFilterString;
|
|
336
|
-
if (accepted === undefined
|
|
353
|
+
if (accepted === undefined) return undefined;
|
|
337
354
|
|
|
338
355
|
let { filter, candidateFilters } = accepted;
|
|
339
|
-
if (filter !== requested.filter && protect(() => setFilter.call(container, key, requested.filter)).ok) {
|
|
356
|
+
if (filter !== requested.filter && setFilter !== undefined && protect(() => setFilter.call(container, key, requested.filter)).ok) {
|
|
340
357
|
filter = requested.filter;
|
|
341
358
|
}
|
|
342
359
|
const setCandidates = container.SetAuraGroupCandidateFilters;
|
|
@@ -351,7 +368,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
351
368
|
return changed;
|
|
352
369
|
}
|
|
353
370
|
|
|
354
|
-
function rebind(this: void, unit: string, supplied: readonly AuraGroupFilter[]): Result<void> {
|
|
371
|
+
function rebind(this: void, unit: string, supplied: readonly AuraGroupFilter[], exact?: true): Result<void> {
|
|
355
372
|
if (retired) return fail("Aura container is retired");
|
|
356
373
|
if (building) return fail("Aura container is still building");
|
|
357
374
|
if (initializationFailure !== undefined) {
|
|
@@ -369,11 +386,19 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
369
386
|
}
|
|
370
387
|
|
|
371
388
|
const changed: AuraGroupFilter[] = [];
|
|
389
|
+
let rejected: string | undefined;
|
|
372
390
|
const rebound = protect(() => {
|
|
373
391
|
container.Hide();
|
|
374
392
|
for (const group of filters) {
|
|
375
393
|
const accepted = updateGroup(group);
|
|
376
394
|
if (accepted !== undefined) changed.push(accepted);
|
|
395
|
+
if (exact) {
|
|
396
|
+
const current = registeredGroups.get(group.key);
|
|
397
|
+
if (current?.filter !== group.filter || current?.candidateFilters !== group.candidateFilters) {
|
|
398
|
+
rejected = group.key;
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
377
402
|
}
|
|
378
403
|
resetUnit(unit);
|
|
379
404
|
disabled = false;
|
|
@@ -381,7 +406,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
381
406
|
container.Show();
|
|
382
407
|
queueVisibilityRefresh("rebind");
|
|
383
408
|
});
|
|
384
|
-
const failure = rebound.ok ?
|
|
409
|
+
const failure = !rebound.ok ? rebound : rejected !== undefined ? fail("The client rejected the aura filter for " + rejected) : initializationFailure;
|
|
385
410
|
if (failure !== undefined) disable();
|
|
386
411
|
else if (!retired) active = true;
|
|
387
412
|
|
|
@@ -397,6 +422,78 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
397
422
|
return ok(undefined);
|
|
398
423
|
}
|
|
399
424
|
|
|
425
|
+
function setGroupEnabled(this: void, key: string, enabled: boolean): Result<void> {
|
|
426
|
+
const setEnabled = container.SetAuraGroupEnabled;
|
|
427
|
+
const cap = container.SetAuraGroupMaxFrameCount;
|
|
428
|
+
const limit = groupLimits.get(key);
|
|
429
|
+
if (retired || limit === undefined || (setEnabled === undefined && cap === undefined)) return fail("Aura group is unavailable");
|
|
430
|
+
const changed = protect(() => {
|
|
431
|
+
if (setEnabled !== undefined) setEnabled.call(container, key, enabled);
|
|
432
|
+
else cap?.call(container, key, enabled ? limit : 0);
|
|
433
|
+
});
|
|
434
|
+
if (changed.ok) {
|
|
435
|
+
if (enabled) disabledGroups.delete(key);
|
|
436
|
+
else disabledGroups.add(key);
|
|
437
|
+
}
|
|
438
|
+
return changed;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function nativeGroupLayout(index: number, spacing: number, rows: number, lines: number): NativeGroupLayout {
|
|
442
|
+
return { elementWidth: cellWidth, elementHeight: cellHeight, elementSpacing: spacing,
|
|
443
|
+
lineSpacing: lines, groupSpacing: 0, groupLineSpacing: rows, layoutIndex: index };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function setFlowLayout(this: void, layout: AuraFlowLayout): Result<void> {
|
|
447
|
+
if (retired || building || !hasGroups) return fail("Aura groups are unavailable");
|
|
448
|
+
if (reveal(api.InCombatLockdown()) !== false) return fail("Aura flow layout requires an unlocked client");
|
|
449
|
+
const { gap, rowGap, lineWidth, maxFrameCount, groupLimits: limits } = layout;
|
|
450
|
+
if (!Number.isFinite(gap) || gap < 0 || !Number.isFinite(rowGap) || rowGap < 0
|
|
451
|
+
|| !Number.isFinite(lineWidth) || lineWidth <= 0 || !Number.isInteger(maxFrameCount) || maxFrameCount <= 0) {
|
|
452
|
+
return fail("Invalid aura flow layout");
|
|
453
|
+
}
|
|
454
|
+
if (limits !== undefined) {
|
|
455
|
+
for (const key of Object.keys(limits)) {
|
|
456
|
+
const limit = limits[key];
|
|
457
|
+
if (limit !== undefined && (!registeredGroups.has(key) || !Number.isInteger(limit) || limit <= 0)) {
|
|
458
|
+
return fail("Invalid aura flow limit for " + key);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const width = container.SetFlowLayoutMaximumLineSize;
|
|
463
|
+
const arrange = container.SetAuraGroupLayout;
|
|
464
|
+
const cap = container.SetAuraGroupMaxFrameCount;
|
|
465
|
+
const nativeEnabled = container.SetAuraGroupEnabled !== undefined;
|
|
466
|
+
if (width === undefined || arrange === undefined || cap === undefined) return fail("Native aura flow updates are unavailable");
|
|
467
|
+
const result = protect(() => {
|
|
468
|
+
width.call(container, lineWidth);
|
|
469
|
+
let index = 0;
|
|
470
|
+
for (const { key } of groups) {
|
|
471
|
+
const limit = limits?.[key] ?? maxFrameCount;
|
|
472
|
+
arrange.call(container, key, nativeGroupLayout(++index, gap, rowGap, rowGap));
|
|
473
|
+
cap.call(container, key, nativeEnabled || !disabledGroups.has(key) ? limit : 0);
|
|
474
|
+
groupLimits.set(key, limit);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
if (!result.ok) disable();
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function setPlacement(this: void, point: AuraContainerOptions["anchor"], grow?: AuraContainerOptions["grow"]): Result<void> {
|
|
482
|
+
if (retired) return fail("Aura container is retired");
|
|
483
|
+
const [x, y] = grow ?? [point === "TOPRIGHT" || point === "RIGHT" || point === "BOTTOMRIGHT" ? "Left" : "Right", "Down"];
|
|
484
|
+
const primary = direction?.[x];
|
|
485
|
+
const secondary = direction?.[y];
|
|
486
|
+
if (hasGroups && (primary === undefined || secondary === undefined)) return fail("Native aura growth is unavailable");
|
|
487
|
+
return protect(() => {
|
|
488
|
+
if (hasGroups && primary !== undefined && secondary !== undefined) {
|
|
489
|
+
container.SetFlowLayoutAnchorPoint(point);
|
|
490
|
+
container.SetFlowLayoutGrowthDirection(primary, secondary);
|
|
491
|
+
}
|
|
492
|
+
container.ClearAllPoints();
|
|
493
|
+
container.SetPoint(point, parent, point);
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
400
497
|
const idle = disable();
|
|
401
498
|
if (!idle.ok) {
|
|
402
499
|
retire();
|
|
@@ -407,20 +504,24 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
407
504
|
if (hasGroups && add === undefined) return undefined;
|
|
408
505
|
container.SetUnit(initialUnit);
|
|
409
506
|
if (initialUnit !== noUnit) boundUnit = initialUnit;
|
|
410
|
-
if (hasGroups
|
|
507
|
+
if (hasGroups) {
|
|
508
|
+
// The native aura container needs a rectangle before its first layout pass.
|
|
509
|
+
container.SetSize(1, 1);
|
|
411
510
|
container.SetFlattensRenderLayers?.(true);
|
|
412
511
|
if (axis?.Horizontal !== undefined) container.SetFlowLayoutAxis?.(axis.Horizontal);
|
|
413
|
-
container.SetFlowLayoutAnchorPoint(anchor);
|
|
414
|
-
container.SetFlowLayoutGrowthDirection(horizontal, vertical);
|
|
415
512
|
if (lineWidth !== undefined) container.SetFlowLayoutMaximumLineSize?.(lineWidth);
|
|
416
513
|
}
|
|
417
|
-
container.SetPoint(anchor, parent, anchor);
|
|
418
514
|
return { add };
|
|
419
515
|
});
|
|
420
516
|
if (!configured.ok || configured.value === undefined) {
|
|
421
517
|
retire();
|
|
422
518
|
return configured.ok ? fail("Native aura groups are unavailable") : configured;
|
|
423
519
|
}
|
|
520
|
+
const placed = setPlacement(anchor, options.grow);
|
|
521
|
+
if (!placed.ok) {
|
|
522
|
+
retire();
|
|
523
|
+
return placed;
|
|
524
|
+
}
|
|
424
525
|
const add = configured.value.add;
|
|
425
526
|
|
|
426
527
|
function registerGroup(group: AuraContainerGroup): Result<void> {
|
|
@@ -428,6 +529,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
428
529
|
const { candidateFilters, filter, initializeFrame, key, maxFrameCount, sort, sortDirection, templates } = group;
|
|
429
530
|
// Keep the attempted key for retirement even if the native registration fails.
|
|
430
531
|
registeredGroups.set(key, { key, filter, candidateFilters });
|
|
532
|
+
groupLimits.set(key, maxFrameCount);
|
|
431
533
|
const added = protect(() => add.call(container, key, filter, {
|
|
432
534
|
maxFrameCount,
|
|
433
535
|
candidateFilters,
|
|
@@ -445,15 +547,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
445
547
|
const result = protect(() => initializeFrame(button));
|
|
446
548
|
if (!result.ok) initializationFailure = result;
|
|
447
549
|
},
|
|
448
|
-
layout:
|
|
449
|
-
elementWidth: cellWidth,
|
|
450
|
-
elementHeight: cellHeight,
|
|
451
|
-
elementSpacing: gap,
|
|
452
|
-
elementSpacingX: gap,
|
|
453
|
-
elementSpacingY: rowGap,
|
|
454
|
-
lineSpacing,
|
|
455
|
-
layoutIndex: registeredGroups.size,
|
|
456
|
-
},
|
|
550
|
+
layout: nativeGroupLayout(registeredGroups.size, gap, rowGap, lineSpacing),
|
|
457
551
|
}));
|
|
458
552
|
return added.ok ? initializationFailure ?? added : added;
|
|
459
553
|
}
|
|
@@ -518,7 +612,7 @@ export function createAuraContainer(parent: FrameParent, options: AuraContainerO
|
|
|
518
612
|
return registerSlot(slot, false);
|
|
519
613
|
}
|
|
520
614
|
|
|
521
|
-
const auraContainer: AuraContainer = { frame: container, addSlot, activate, rebind, disable, retire };
|
|
615
|
+
const auraContainer: AuraContainer = { frame: container, addSlot, activate, rebind, setGroupEnabled, setFlowLayout, setPlacement, disable, retire };
|
|
522
616
|
if (defer === undefined) {
|
|
523
617
|
for (const group of groups) {
|
|
524
618
|
const added = registerGroup(group);
|
package/wow/aura-countdown.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { rawField } from "./lua-table";
|
|
|
9
9
|
import { api, reveal } from "./native";
|
|
10
10
|
import { protect } from "./protect";
|
|
11
11
|
|
|
12
|
-
type CountdownStyle = "compact" | "minutes" | "seconds";
|
|
12
|
+
type CountdownStyle = "abbreviated" | "compact" | "minutes" | "seconds";
|
|
13
13
|
type Countdown = Partial<Pick<Cooldown, "SetCountdownFormatter">>;
|
|
14
14
|
// The client inherits the breakpoint rounding when its component omits the override.
|
|
15
15
|
type Rule = Omit<Data_NumericRuleFormatBreakpoint, "components"> & {
|
|
@@ -20,11 +20,21 @@ type Formatter = NumericFormatterAPI & { SetBreakpoints(this: object, rules: Rul
|
|
|
20
20
|
declare function tonumber(this: void, value: unknown): number | undefined;
|
|
21
21
|
|
|
22
22
|
const formatters: Record<CountdownStyle, Partial<Record<number, NumericFormatterAPI>>> = {
|
|
23
|
+
abbreviated: {},
|
|
23
24
|
compact: {},
|
|
24
25
|
minutes: {},
|
|
25
26
|
seconds: {},
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
function abbreviatedRules(rounding: Rule["rounding"]): Rule[] {
|
|
30
|
+
return [
|
|
31
|
+
{ threshold: 0, format: "%d", rounding, step: 1 },
|
|
32
|
+
{ threshold: 60, format: "%dM", rounding, step: 60, components: [{ div: 60 }] },
|
|
33
|
+
{ threshold: 3600, format: "%dH", rounding, step: 3600, components: [{ div: 3600 }] },
|
|
34
|
+
{ threshold: 86400, format: "%dD", rounding, step: 86400, components: [{ div: 86400 }] },
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
function createRuleFormatter(rules: Rule[]): NumericFormatterAPI | undefined {
|
|
29
39
|
const create = rawField<(this: void) => Formatter | undefined>(api.C_StringUtil, "CreateNumericRuleFormatter");
|
|
30
40
|
if (typeof create !== "function") return undefined;
|
|
@@ -40,14 +50,20 @@ function createRuleFormatter(rules: Rule[]): NumericFormatterAPI | undefined {
|
|
|
40
50
|
|
|
41
51
|
function countdownFormatter(decimals?: number, style?: string): NumericFormatterAPI | undefined {
|
|
42
52
|
const value = tonumber(reveal(decimals)) ?? 0;
|
|
43
|
-
const precision = Number.isNaN(value) ? 0 : Math.max(0, Math.min(2, Math.floor(value)));
|
|
44
53
|
const mode = reveal(style);
|
|
45
|
-
const format: CountdownStyle = mode === "minutes" || mode === "seconds" ? mode : "compact";
|
|
54
|
+
const format: CountdownStyle = mode === "abbreviated" || mode === "minutes" || mode === "seconds" ? mode : "compact";
|
|
55
|
+
const precision = format === "abbreviated" || Number.isNaN(value) ? 0 : Math.max(0, Math.min(2, Math.floor(value)));
|
|
46
56
|
const byPrecision = formatters[format];
|
|
47
57
|
const cached = byPrecision[precision];
|
|
48
58
|
if (cached !== undefined) return cached;
|
|
49
59
|
|
|
50
60
|
const rounding = api.Enum?.NumericRuleFormatRounding;
|
|
61
|
+
if (format === "abbreviated") {
|
|
62
|
+
if (rounding?.Down === undefined) return undefined;
|
|
63
|
+
const formatter = createRuleFormatter(abbreviatedRules(rounding.Down));
|
|
64
|
+
if (formatter !== undefined) byPrecision[precision] = formatter;
|
|
65
|
+
return formatter;
|
|
66
|
+
}
|
|
51
67
|
if (rounding?.Up === undefined || rounding.Nearest === undefined) return undefined;
|
|
52
68
|
|
|
53
69
|
const rules: Rule[] = [{
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Anchor } from "../src/elements";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import type { AuraContainer } from "./aura-container";
|
|
4
|
+
import { createFrame, type Frame, type FrameParent } from "./frames";
|
|
5
|
+
import { api, reveal } from "./native";
|
|
6
|
+
import { protect } from "./protect";
|
|
7
|
+
|
|
8
|
+
/** The template opts into Blizzard's untrusted-layout aspect at construction. */
|
|
9
|
+
export function createAuraFollowerFrame(this: void, parent: FrameParent): Frame {
|
|
10
|
+
const created = protect(() => createFrame("Frame", undefined, parent, "DisableUntrustedLayoutScriptsTemplate"));
|
|
11
|
+
return created.ok ? created.value : createFrame("Frame", undefined, parent);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Follow the native bottom edge, or use the authored parent-relative anchor on older clients. */
|
|
15
|
+
export function anchorAuraFollower(this: void, frame: Frame, container: AuraContainer | undefined, gap: number, fallback: Anchor): Result<"native" | "fallback"> {
|
|
16
|
+
if (reveal(api.InCombatLockdown()) !== false) return fail("Aura follower placement requires an unlocked client");
|
|
17
|
+
if (!Number.isFinite(gap) || gap < 0) return fail("Invalid aura follower gap");
|
|
18
|
+
if (container !== undefined) {
|
|
19
|
+
const followed = protect(() => {
|
|
20
|
+
frame.ClearAllPoints();
|
|
21
|
+
frame.SetPoint("TOPLEFT", container.frame, "BOTTOMLEFT", 0, -gap);
|
|
22
|
+
});
|
|
23
|
+
if (followed.ok) return ok("native");
|
|
24
|
+
}
|
|
25
|
+
return protect(() => {
|
|
26
|
+
const parent = reveal(frame.GetParent()) as FrameParent | undefined;
|
|
27
|
+
if (parent === undefined || parent === null) throw new Error("Aura follower has no readable parent");
|
|
28
|
+
frame.ClearAllPoints();
|
|
29
|
+
frame.SetPoint(fallback.point, parent, fallback.point, fallback.x ?? 0, fallback.y ?? 0);
|
|
30
|
+
return "fallback" as const;
|
|
31
|
+
});
|
|
32
|
+
}
|
package/wow/aura-view.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ElementRef, UIElement } from "../src/elements";
|
|
2
|
+
import type { OwnedRecord } from "../src/owned-collections";
|
|
3
|
+
import { fail } from "../src/result";
|
|
4
|
+
import { appContext } from "./app-ui";
|
|
5
|
+
import { configureAuraMouse } from "./aura-button";
|
|
6
|
+
import type { AuraButton } from "./aura-container";
|
|
7
|
+
import { bindAuraDurationText, bindAuraStackText } from "./aura-countdown";
|
|
8
|
+
import type { FontString, Texture } from "./frames";
|
|
9
|
+
import { protect } from "./protect";
|
|
10
|
+
import { mountNative, type NativeViewOptions } from "./view";
|
|
11
|
+
|
|
12
|
+
export interface AuraButtonRegions {
|
|
13
|
+
readonly icon: ElementRef<"image">;
|
|
14
|
+
readonly count: ElementRef<"text">;
|
|
15
|
+
readonly duration: ElementRef<"text">;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Mount static JSX regions before Blizzard binds and restricts the button. */
|
|
19
|
+
export function mountAuraButton(this: void, button: AuraButton, size: number,
|
|
20
|
+
render: (this: void, regions: AuraButtonRegions) => UIElement) {
|
|
21
|
+
const context = appContext();
|
|
22
|
+
if (context === undefined) return fail("Aura buttons require a running addon");
|
|
23
|
+
if (!Number.isFinite(size) || size <= 0) return fail("Invalid aura button size");
|
|
24
|
+
const sized = protect(() => button.SetSize(size, size));
|
|
25
|
+
if (!sized.ok) return sized;
|
|
26
|
+
let icon: Texture | undefined;
|
|
27
|
+
let count: FontString | undefined;
|
|
28
|
+
let duration: FontString | undefined;
|
|
29
|
+
const mounted = mountNative(button, context.runtime, () => render({
|
|
30
|
+
icon: region => { icon = region; },
|
|
31
|
+
count: region => { count = region; },
|
|
32
|
+
duration: region => { duration = region; },
|
|
33
|
+
}), { ...context.theme as OwnedRecord<NativeViewOptions>, regionsOnly: "native-owned" });
|
|
34
|
+
if (!mounted.ok) return mounted;
|
|
35
|
+
const image = icon, stack = count, clock = duration;
|
|
36
|
+
// Stop JSX bindings while the regions are still readable. Native updates own them from here.
|
|
37
|
+
const stopped = mounted.value.dispose();
|
|
38
|
+
if (!stopped.ok) return stopped;
|
|
39
|
+
if (image === undefined || stack === undefined || clock === undefined || button.SetIcon === undefined) {
|
|
40
|
+
return fail("Aura button display regions are unavailable");
|
|
41
|
+
}
|
|
42
|
+
const setIcon = button.SetIcon;
|
|
43
|
+
const iconBound = protect(() => setIcon.call(button, image));
|
|
44
|
+
if (!iconBound.ok) return iconBound;
|
|
45
|
+
const stackBound = bindAuraStackText(button, stack);
|
|
46
|
+
if (!stackBound.ok) return stackBound;
|
|
47
|
+
const clockBound = bindAuraDurationText(button, clock);
|
|
48
|
+
return clockBound.ok ? configureAuraMouse(button, "shown") : clockBound;
|
|
49
|
+
}
|
package/wow/css-box.ts
CHANGED
|
@@ -117,7 +117,7 @@ export function mountCssContent(this: void, scope: RuntimeScope, frame: Frame, s
|
|
|
117
117
|
if (!content.ok) return content;
|
|
118
118
|
if (overflow !== "scroll") return ok({ frame: content.value, layout });
|
|
119
119
|
|
|
120
|
-
const scroll = mountScrollView(content.value, scope, { contentHeight: 1 }, createScroll);
|
|
120
|
+
const scroll = mountScrollView(content.value, scope, { contentHeight: 1 }, createScroll, true);
|
|
121
121
|
if (scroll.failure !== undefined) return scroll.failure;
|
|
122
122
|
scroll.frame.SetAllPoints(content.value);
|
|
123
123
|
const display = style.display === "grid" ? "grid" : "flex";
|
|
@@ -137,9 +137,12 @@ export function mountCssContent(this: void, scope: RuntimeScope, frame: Frame, s
|
|
|
137
137
|
scroll.frame.SetContentHeight(Math.max(1, next));
|
|
138
138
|
}, scope);
|
|
139
139
|
if (!resize.ok) return resize;
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
// The default viewport fills the CSS box. Read that box directly, including when the
|
|
141
|
+
// native ScrollFrame has yet to resolve its anchors during staged mounting.
|
|
142
|
+
// A custom host may reserve part of the CSS box for its scrollbar.
|
|
143
|
+
const widthOwner = createScroll === undefined ? content.value
|
|
144
|
+
: (reveal(scroll.content.GetParent()) as FrameParent | undefined) ?? scroll.frame;
|
|
145
|
+
const root = mountLayoutRoot(scroll.content, widthOwner, { style: contentStyle, fullWidth: true }, scope, undefined, stageInitial);
|
|
143
146
|
if (!root.ok) return root;
|
|
144
147
|
scroll.notifyVisible();
|
|
145
148
|
return ok({ frame: scroll.content, layout: root.value.group });
|
package/wow/css-surfaces.ts
CHANGED
|
@@ -264,7 +264,12 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
264
264
|
target.SetAllPoints(frame);
|
|
265
265
|
hasMaskAnchor = true;
|
|
266
266
|
}
|
|
267
|
-
for (const layer of layers)
|
|
267
|
+
for (const layer of layers) {
|
|
268
|
+
if (layer === outline) continue;
|
|
269
|
+
// A square background already fits the frame. Sampling a stretched mask softens its edges.
|
|
270
|
+
if (radius === 0 && (layer === color || layer === image)) detach(layer, target);
|
|
271
|
+
else attach(layer, target);
|
|
272
|
+
}
|
|
268
273
|
maskRadius = radius;
|
|
269
274
|
return ok(undefined);
|
|
270
275
|
}
|
|
@@ -537,10 +542,11 @@ export function createCssSurface(this: void, scope: RuntimeScope, frame: Frame,
|
|
|
537
542
|
if (switching && outline !== undefined) shown(outline, false);
|
|
538
543
|
restoreFill();
|
|
539
544
|
sliceActive = false;
|
|
545
|
+
const canOverflow = logical.some(width => width > 1);
|
|
546
|
+
const masked = setMask(radius > 0 ? radius : canOverflow ? 0 : undefined);
|
|
547
|
+
if (!masked.ok) return masked;
|
|
540
548
|
if (switching || radius !== previousRadius || !sameInsets(previousInsets, insets)) {
|
|
541
|
-
|
|
542
|
-
if (!masked.ok) return masked;
|
|
543
|
-
// Keep the side bands and outer mask. The corner texture provides only the inner cutout.
|
|
549
|
+
// A rounded corner texture provides only the inner cutout. The mask defines the outer edge.
|
|
544
550
|
const onePixel = pixel !== undefined && pixel > 0 && radius > pixel && combined && options.borderPaint?.width === 1
|
|
545
551
|
&& logical[0] === 1 && logical[1] === 1 && logical[2] === 1 && logical[3] === 1;
|
|
546
552
|
const art = onePixel ? options.rounded?.resolveBorderCorner?.(Math.round(radius / pixel)) : undefined;
|
package/wow/frames.ts
CHANGED
package/wow/hooks.ts
CHANGED
|
@@ -4,8 +4,10 @@ import type { OwnedReadonlyArray } from "../src/owned-collections";
|
|
|
4
4
|
import type { RuntimeScope } from "../src/runtime";
|
|
5
5
|
import { appContext } from "./app-ui";
|
|
6
6
|
import type { EventOptions, WoWEvent, WoWEventMap } from "./contract";
|
|
7
|
+
import type { Frame } from "./frames";
|
|
7
8
|
import { setRawField } from "./lua-table";
|
|
8
9
|
import { api, reveal } from "./native";
|
|
10
|
+
import { physicalPixel } from "./pixel";
|
|
9
11
|
|
|
10
12
|
function owner(name: string): RuntimeScope {
|
|
11
13
|
const scope = currentScope();
|
|
@@ -35,6 +37,21 @@ export function onCleanup(this: void, cleanup: (this: void) => void): void {
|
|
|
35
37
|
if (!registered.ok) throw new Error(registered.reason);
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
/** Follow UIParent size and the size of one display pixel in its coordinate space. */
|
|
41
|
+
export function useScreenSize(this: void) {
|
|
42
|
+
const screen = api.UIParent as Frame;
|
|
43
|
+
function read(this: void) {
|
|
44
|
+
const [width, height] = screen.GetSize();
|
|
45
|
+
return { width: reveal(width), height: reveal(height), pixel: physicalPixel(screen) };
|
|
46
|
+
}
|
|
47
|
+
const size = ref(read());
|
|
48
|
+
function refresh(this: void): void { size.value = read(); }
|
|
49
|
+
useEvent("UI_SCALE_CHANGED", refresh);
|
|
50
|
+
useEvent("DISPLAY_SIZE_CHANGED", refresh);
|
|
51
|
+
useEvent("PLAYER_ENTERING_WORLD", refresh);
|
|
52
|
+
return { size, refresh };
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
interface Clock {
|
|
39
56
|
readonly time: SignalRef<number>;
|
|
40
57
|
users: number;
|