|
| 1 | +import { AAMember, BrsBoolean, BrsString, Float } from "brs-engine"; |
| 2 | +import { FieldModel } from "../SGTypes"; |
| 3 | +import { SGNodeType } from "."; |
| 4 | +import { Dialog } from "./Dialog"; |
| 5 | +import { BusySpinner } from "./BusySpinner"; |
| 6 | + |
| 7 | +export class ProgressDialog extends Dialog { |
| 8 | + readonly defaultFields: FieldModel[] = [{ name: "busySpinner", type: "node" }]; |
| 9 | + |
| 10 | + protected readonly minHeight: number; |
| 11 | + private readonly spinner: BusySpinner; |
| 12 | + |
| 13 | + constructor(initializedFields: AAMember[] = [], readonly name: string = SGNodeType.ProgressDialog) { |
| 14 | + super([], name); |
| 15 | + this.setExtendsType(name, SGNodeType.Dialog); |
| 16 | + |
| 17 | + this.registerDefaultFields(this.defaultFields); |
| 18 | + this.registerInitializedFields(initializedFields); |
| 19 | + |
| 20 | + this.spinner = new BusySpinner(); |
| 21 | + |
| 22 | + // Resize the dialog and position the spinner, resolution-aware |
| 23 | + let spinnerSize: number; |
| 24 | + let spinnerY: number; |
| 25 | + |
| 26 | + if (this.resolution === "FHD") { |
| 27 | + spinnerSize = 120; |
| 28 | + spinnerY = this.dialogTrans[1] + 105 + this.vertOffset + this.gap; |
| 29 | + this.minHeight = 159 + spinnerSize + this.vertOffset * 2; |
| 30 | + } else { |
| 31 | + spinnerSize = 80; |
| 32 | + spinnerY = this.dialogTrans[1] + 70 + this.vertOffset + this.gap; |
| 33 | + this.minHeight = 106 + spinnerSize + this.vertOffset * 2; |
| 34 | + } |
| 35 | + this.height = this.minHeight; |
| 36 | + |
| 37 | + // Center spinner horizontally within the dialog |
| 38 | + const spinnerX = this.dialogTrans[0] + (this.width - spinnerSize) / 2; |
| 39 | + this.spinner.setTranslation([spinnerX, spinnerY]); |
| 40 | + this.spinner.setValue("control", new BrsString("start")); |
| 41 | + this.setValueSilent("busySpinner", this.spinner); |
| 42 | + |
| 43 | + // Adjust background height |
| 44 | + this.background.setValueSilent("height", new Float(this.minHeight)); |
| 45 | + |
| 46 | + // Hide elements not used by ProgressDialog |
| 47 | + this.message.setValueSilent("visible", BrsBoolean.False); |
| 48 | + this.icon.setValueSilent("visible", BrsBoolean.False); |
| 49 | + this.setValueSilent("iconUri", new BrsString("")); |
| 50 | + |
| 51 | + this.appendChildToParent(this.spinner); |
| 52 | + } |
| 53 | + |
| 54 | + protected updateChildren() { |
| 55 | + this.height = this.minHeight; |
| 56 | + const width = this.getValueJS("width") as number; |
| 57 | + if (width) { |
| 58 | + this.background.setValue("width", new Float(width)); |
| 59 | + this.width = width; |
| 60 | + } |
| 61 | + this.copyField(this.background, "uri", "backgroundUri"); |
| 62 | + this.copyField(this.title, "text", "title"); |
| 63 | + this.copyField(this.title, "color", "titleColor"); |
| 64 | + this.copyField(this.title, "font", "titleFont"); |
| 65 | + this.copyField(this.divider, "uri", "dividerUri"); |
| 66 | + |
| 67 | + // Set dialog height and reposition elements |
| 68 | + const newY = (this.sceneRect.height - this.height) / 2; |
| 69 | + const offsetY = newY - this.dialogTrans[1]; |
| 70 | + this.dialogTrans[1] = newY; |
| 71 | + this.background.setTranslation(this.dialogTrans); |
| 72 | + this.background.setValue("height", new Float(this.height)); |
| 73 | + this.title.setTranslationOffset(0, offsetY); |
| 74 | + this.divider.setTranslationOffset(0, offsetY); |
| 75 | + this.spinner.setTranslationOffset(0, offsetY); |
| 76 | + } |
| 77 | +} |
0 commit comments