import { Text } from "@thegraid/easeljs-module"; import { ChoiceStyle, ChoiceType, Chooser, ChooserConst } from "./chooser.js"; import { DropdownItem, DropdownStyle } from "./dropdown.js"; import { NamedContainer } from "./named-container.js"; export type ParamType = ChoiceType; /** Supplied by user: affects spec/line/item; opts.style -> chooser */ export interface ParamOpts { name?: string; fontName?: string; fontSize?: number; fontColor?: string; style?: ChoiceStyle; onChange?: (item: ParamItem) => void; target?: object; chooser?: ChooserConst; } /** Created by ParamGUI */ export interface ParamSpec extends ParamOpts { fieldName: string; target: object; name?: string; type?: string; choices?: ParamItem[]; } /** ParamGUI extension */ export interface ParamItem extends DropdownItem { /** text displayed when Item is expanded (& _rootButton.text when selected) */ text: string; /** value associated, if different from text */ value: any; /** set/get fieldName from target Object */ fieldName?: string; } /** each row of ParamGUI: * - spec: ParamSpec { fieldName, target } * - chooser: DropdownChoice { items: { value[] } } */ export declare class ParamLine extends NamedContainer { constructor(spec: ParamSpec); get height(): number; get width(): number; chooser_w: number; chooser_x: number; chooser: Chooser; spec: ParamSpec; nameText: Text; } /** * ParamGUI is a set of Choosers arranged as lines of [Chooser, Label] * * When the selected choice [a DropdownChoice] is changed, * the selected value is assigned to the indicated field of the Target. * * Each line item can be individually configured using ParamOpts * to target a specific object, and font { fontSize, fontName, fontColor } * and DropdownStyle. * * The 'onChange' action defaults to setValue(item) { this.target[item.fieldName] = item.value } * but can be any function(item) => void. */ export declare class ParamGUI extends NamedContainer { /** * A Stack of Choosers to set various game parameters. * @param target change fields of this object (by default... ParamLine can override) * @param style changes from DropdownButton.defStyle */ constructor(target: object, style?: DropdownStyle); target: object; defStyle: DropdownStyle; specs: ParamSpec[]; lines: ParamLine[]; linew: number; lineh: number; lead: number; ymax: number; /** retrieve spec by fieldName */ spec(fieldName: string): ParamSpec; /** make a spec and push onto list of specs * @param fieldName * @param valueAry array of choices (or [value] mutable by the chooser) * @param opts style for this spec/line/item; opts.style -> this.defStyle -> chooser * - name * - fontName * - fontColor * - fontSize * - target * - chooser: Constructor\ * - onChange * - style: ChoiceStyle (Text, rootColor, rootTextColor, arrowColor, spacing) */ makeParamSpec(fieldName: string, valueAry: any[], opts?: ParamOpts): ParamSpec; /** * Item displays 'item.text', invokes target[item.fieldName] = item.value * @param fieldName * @param valueAry Array< TextIsValue | { text: text, value: value } > * @returns Array< { text, fieldName, value } > */ makeChoiceItems(fieldName: string, valueAry: any[]): ParamItem[]; /** for each ParamSpec add a Chooser and Text label. * @return all the lines */ makeLines(specs?: ParamSpec[]): ParamLine[]; findLine(fieldName: string): ParamLine; /** set text for the label of the indicated line/Chooser * @return the Text */ setNameText(fieldName: string, name?: string, line?: ParamLine): Text; /** create ParamLine with Chooser(spec.choices) and Text label * as the last line of this ParamGUI * @return the line */ addLine(spec: ParamSpec): ParamLine; /** create and configure a Chooser(choices) for the given line. */ addChooser(line: ParamLine): Chooser; /** when a new value is selected, set it into the target object. * auto-invoke onItemChanged() => (item)=>setValue(item) [or spec.onChange(...) ] * suitable entry-point for eval_params: (fieldName, value) */ selectValue(fieldName: string, value: ParamType, line?: ParamLine): ParamItem | undefined; /** return target[fieldName]; suitable for override */ getValue(fieldName: string, target?: object): any; /** update target[item.fieldname] = item.value; suitable for override * @return the value */ setValue(item: ParamItem, target?: object): void; /** set item.value in [the super/prototype of] target [that contains item.fieldName] * @return the value */ setInheritedValue(item: ParamItem, target?: object): void; }