2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI {
|
2017-02-16 22:59:41 +00:00
|
|
|
/**
|
|
|
|
* Base class for all game views
|
|
|
|
*/
|
2015-04-07 00:00:00 +00:00
|
|
|
export class BaseView extends Phaser.State {
|
|
|
|
// Link to the root UI
|
2017-02-09 00:00:35 +00:00
|
|
|
gameui: MainUI;
|
2015-04-07 00:00:00 +00:00
|
|
|
|
2015-04-15 00:00:00 +00:00
|
|
|
// Message notifications
|
|
|
|
messages: Messages;
|
|
|
|
|
2015-04-23 22:36:57 +00:00
|
|
|
// Input and key bindings
|
|
|
|
inputs: InputManager;
|
|
|
|
|
2017-04-10 17:38:33 +00:00
|
|
|
// Animations
|
|
|
|
animations: Animations;
|
|
|
|
|
2017-02-16 22:59:41 +00:00
|
|
|
// Timing
|
|
|
|
timer: Timer;
|
|
|
|
|
2017-03-15 21:40:19 +00:00
|
|
|
// Tooltip
|
|
|
|
tooltip: Tooltip;
|
|
|
|
|
|
|
|
// Layers
|
|
|
|
layers: Phaser.Group;
|
|
|
|
|
2015-04-07 00:00:00 +00:00
|
|
|
// Get the size of display
|
|
|
|
getWidth(): number {
|
|
|
|
return this.game.width || 1280;
|
|
|
|
}
|
|
|
|
getHeight(): number {
|
|
|
|
return this.game.height || 720;
|
|
|
|
}
|
|
|
|
getMidWidth(): number {
|
|
|
|
return this.getWidth() / 2;
|
|
|
|
}
|
|
|
|
getMidHeight(): number {
|
|
|
|
return this.getHeight() / 2;
|
|
|
|
}
|
|
|
|
|
2015-04-07 00:00:00 +00:00
|
|
|
init(...args: any[]) {
|
2017-02-09 00:00:35 +00:00
|
|
|
this.gameui = <MainUI>this.game;
|
2017-02-21 21:16:18 +00:00
|
|
|
this.timer = new Timer(this.gameui.headless);
|
2015-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
create() {
|
2017-03-15 21:40:19 +00:00
|
|
|
this.game.stage.backgroundColor = 0x000000;
|
|
|
|
|
|
|
|
// View layers
|
|
|
|
this.layers = this.add.group();
|
|
|
|
|
2015-04-15 00:00:00 +00:00
|
|
|
// Notifications
|
|
|
|
this.messages = new Messages(this);
|
|
|
|
|
2017-04-10 17:38:33 +00:00
|
|
|
// Animations
|
|
|
|
this.animations = new Animations(this.game.tweens);
|
|
|
|
|
2015-04-23 22:36:57 +00:00
|
|
|
// Input manager
|
|
|
|
this.inputs = new InputManager(this);
|
2017-02-05 22:03:35 +00:00
|
|
|
|
2017-03-15 21:40:19 +00:00
|
|
|
// Tooltip
|
|
|
|
this.tooltip = new Tooltip(this);
|
|
|
|
|
2017-02-05 22:03:35 +00:00
|
|
|
// Browser console variable (for debugging purpose)
|
|
|
|
if (typeof window != "undefined") {
|
|
|
|
let session = this.gameui.session;
|
|
|
|
if (session) {
|
|
|
|
(<any>window).universe = session.universe;
|
|
|
|
(<any>window).player = session.player;
|
|
|
|
(<any>window).battle = session.player.getBattle();
|
2017-02-09 19:16:49 +00:00
|
|
|
(<any>window).view = this;
|
2017-02-05 22:03:35 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-16 22:59:41 +00:00
|
|
|
|
|
|
|
super.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
shutdown() {
|
|
|
|
super.shutdown();
|
|
|
|
|
|
|
|
this.timer.cancelAll(true);
|
2015-04-07 00:00:00 +00:00
|
|
|
}
|
2017-03-15 21:40:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new layer in the view
|
|
|
|
*/
|
|
|
|
addLayer(): Phaser.Group {
|
|
|
|
let layer = this.add.group(this.layers);
|
|
|
|
return layer;
|
|
|
|
}
|
2015-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|