2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI {
|
2014-12-30 00:00:00 +00:00
|
|
|
// One item in a ship list (used in BattleView)
|
|
|
|
export class ShipListItem extends Phaser.Button {
|
2017-04-10 17:38:33 +00:00
|
|
|
// Reference to the view
|
2017-05-14 21:03:03 +00:00
|
|
|
view: BattleView
|
2017-04-10 17:38:33 +00:00
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Reference to the ship game object
|
2017-05-14 21:03:03 +00:00
|
|
|
ship: Ship
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2017-05-14 21:03:03 +00:00
|
|
|
// Player indicator
|
|
|
|
player_indicator: Phaser.Image
|
2017-02-07 19:15:21 +00:00
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Portrait
|
2017-05-14 21:03:03 +00:00
|
|
|
portrait: Phaser.Image
|
2015-02-04 00:00:00 +00:00
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
// Damage flashing indicator
|
2017-05-14 21:03:03 +00:00
|
|
|
damage_indicator: Phaser.Image
|
2017-01-15 22:05:00 +00:00
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Hover indicator
|
2017-05-14 21:03:03 +00:00
|
|
|
hover_indicator: Phaser.Image
|
2015-04-22 20:03:59 +00:00
|
|
|
|
2014-12-30 00:00:00 +00:00
|
|
|
// Create a ship button for the battle ship list
|
2017-02-09 00:00:35 +00:00
|
|
|
constructor(list: ShipList, x: number, y: number, ship: Ship, owned: boolean) {
|
2017-05-14 21:03:03 +00:00
|
|
|
super(list.battleview.game, x, y, "battle-shiplist-item-background");
|
2017-04-10 17:38:33 +00:00
|
|
|
this.view = list.battleview;
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2016-10-26 21:15:04 +00:00
|
|
|
this.ship = ship;
|
|
|
|
|
2017-08-24 18:26:07 +00:00
|
|
|
this.player_indicator = this.view.newImage(owned ? "battle-hud-ship-own-mini" : "battle-hud-ship-enemy-mini", 8, 52);
|
2017-05-14 21:03:03 +00:00
|
|
|
this.player_indicator.anchor.set(0.5, 0.5);
|
|
|
|
this.player_indicator.angle = 90;
|
|
|
|
this.addChild(this.player_indicator);
|
2015-02-04 00:00:00 +00:00
|
|
|
|
2017-07-26 22:54:56 +00:00
|
|
|
this.portrait = this.view.newImage(`ship-${ship.model.code}-portrait`, 18, 9);
|
2017-05-14 21:03:03 +00:00
|
|
|
this.portrait.scale.set(0.332, 0.332);
|
|
|
|
this.addChild(this.portrait);
|
2017-01-08 22:04:07 +00:00
|
|
|
|
2017-05-14 21:03:03 +00:00
|
|
|
this.damage_indicator = new Phaser.Image(this.game, 18, 9, "battle-shiplist-damage", 0);
|
|
|
|
this.damage_indicator.alpha = 0;
|
|
|
|
this.addChild(this.damage_indicator);
|
2015-02-28 00:00:00 +00:00
|
|
|
|
2017-05-14 21:03:03 +00:00
|
|
|
this.hover_indicator = new Phaser.Image(this.game, 17, 8, "battle-shiplist-hover", 0);
|
|
|
|
this.hover_indicator.visible = false;
|
|
|
|
this.addChild(this.hover_indicator);
|
2017-03-17 00:07:00 +00:00
|
|
|
|
2017-05-04 23:19:28 +00:00
|
|
|
UITools.setHoverClick(this, () => list.battleview.cursorOnShip(ship), () => list.battleview.cursorOffShip(ship), () => list.battleview.cursorClicked());
|
2015-02-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
// Flash a damage indicator
|
|
|
|
setDamageHit() {
|
2017-05-14 21:03:03 +00:00
|
|
|
this.game.tweens.create(this.damage_indicator).to({ alpha: 1 }, 100).to({ alpha: 0 }, 150).repeatAll(2).start();
|
2017-01-15 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
2015-04-26 17:15:45 +00:00
|
|
|
// Move to a given location on screen
|
|
|
|
moveTo(x: number, y: number, animate: boolean) {
|
|
|
|
if (animate) {
|
|
|
|
var tween = this.game.tweens.create(this);
|
2017-01-08 22:04:07 +00:00
|
|
|
tween.to({ x: x, y: y });
|
2015-04-26 17:15:45 +00:00
|
|
|
tween.start();
|
|
|
|
} else {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
}
|
2015-02-04 00:00:00 +00:00
|
|
|
|
|
|
|
// Set the hovered status
|
|
|
|
setHovered(hovered: boolean) {
|
2017-05-14 21:03:03 +00:00
|
|
|
this.view.animations.setVisible(this.hover_indicator, hovered, 200);
|
2015-02-04 00:00:00 +00:00
|
|
|
}
|
2014-12-30 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|