2017-10-09 22:59:49 +00:00
|
|
|
module TK.SpaceTac.UI {
|
|
|
|
/**
|
|
|
|
* Dialog asking for a confirmation
|
|
|
|
*/
|
|
|
|
export class UIConfirmDialog extends UIDialog {
|
|
|
|
private result: Promise<boolean>
|
2018-01-31 18:19:50 +00:00
|
|
|
private result_resolver?: (confirmed: boolean) => void
|
2017-10-09 22:59:49 +00:00
|
|
|
|
|
|
|
constructor(view: BaseView, message: string) {
|
|
|
|
super(view);
|
|
|
|
|
2018-06-04 21:15:06 +00:00
|
|
|
this.content.text(message, this.width * 0.5, this.height * 0.4, { color: "#9FC4D6", size: 32, shadow: true });
|
2017-10-09 22:59:49 +00:00
|
|
|
|
2018-06-04 21:15:06 +00:00
|
|
|
this.result = new Promise(resolve => {
|
2017-10-09 22:59:49 +00:00
|
|
|
this.result_resolver = resolve;
|
2018-06-04 21:15:06 +00:00
|
|
|
|
|
|
|
this.content.button("menu-button-small", this.width * 0.4, this.height * 0.6, () => resolve(false),
|
|
|
|
undefined, undefined, { center: true, text: "Cancel", text_style: { color: "#9FC4D6", size: 22, shadow: true } });
|
|
|
|
this.content.button("menu-button-small", this.width * 0.6, this.height * 0.6, () => resolve(true),
|
|
|
|
undefined, undefined, { center: true, text: "OK", text_style: { color: "#9FC4D6", size: 22, shadow: true } });
|
2017-10-09 22:59:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force the result (simulate clicking the appropriate button)
|
|
|
|
*/
|
|
|
|
async forceResult(confirmed: boolean): Promise<void> {
|
2018-01-31 18:19:50 +00:00
|
|
|
if (this.result_resolver) {
|
|
|
|
this.result_resolver(confirmed);
|
|
|
|
await this.result;
|
|
|
|
}
|
2017-10-09 22:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenient function to ask for a confirmation, and have a promise of result
|
|
|
|
*/
|
|
|
|
static ask(view: BaseView, message: string): Promise<boolean> {
|
|
|
|
let dlg = new UIConfirmDialog(view, message);
|
|
|
|
let result = dlg.result;
|
|
|
|
return result.then(confirmed => {
|
|
|
|
dlg.close();
|
|
|
|
return confirmed;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|