1
0
Fork 0
spacetac/src/ui/common/UIDialog.ts

55 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-06-08 17:32:57 +00:00
/// <reference path="../common/UIComponent.ts" />
2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
2017-06-08 17:32:57 +00:00
/**
* Base class for modal dialogs
*
* When a modal dialog opens, an overlay is displayed behind it to prevent clicking through it
*/
export class UIDialog extends UIComponent {
2017-07-06 22:55:29 +00:00
constructor(parent: BaseView, width = 1495, height = 1080, background = "common-dialog") {
2017-06-08 17:32:57 +00:00
super(parent, width, height, background);
if (parent.dialogs_layer.children.length == 0) {
this.addOverlay(parent.dialogs_layer);
}
2017-07-19 23:22:18 +00:00
this.view.audio.playOnce("ui-dialog-open");
2017-06-08 17:32:57 +00:00
this.moveToLayer(parent.dialogs_layer);
this.setPositionInsideParent(0.5, 0.5);
}
/**
* Add a control-capturing overlay
*/
addOverlay(layer: Phaser.Group): void {
let info = this.view.getImageInfo("translucent");
let overlay = layer.game.add.button(0, 0, info.key, () => null, undefined, info.frame, info.frame);
2017-07-06 22:55:29 +00:00
overlay.input.useHandCursor = false;
2017-06-08 17:32:57 +00:00
overlay.scale.set(this.view.getWidth() / overlay.width, this.view.getHeight() / overlay.height);
layer.add(overlay);
}
/**
* Add a close button
*/
2017-07-06 22:55:29 +00:00
addCloseButton(key = "common-dialog-close", x = 1325, y = 131, frame = 0, frame_hover = 1): void {
2017-06-08 17:32:57 +00:00
this.addButton(x, y, () => this.close(), key, frame, frame_hover, "Close this dialog");
}
/**
* Close the dialog, removing the overlay if needed
*/
close() {
this.destroy();
2017-07-19 23:22:18 +00:00
this.view.audio.playOnce("ui-dialog-close");
2017-06-08 17:32:57 +00:00
if (this.view.dialogs_layer.children.length == 1) {
this.view.dialogs_layer.removeAll(true);
}
}
}
}