module TK.SpaceTac.UI { // One item in a ship list (used in BattleView) export class ShipListItem extends Phaser.Button { // Reference to the view view: BaseView // Reference to the ship game object ship: Ship // Player indicator player_indicator: Phaser.Image // Portrait portrait: Phaser.Image // Damage flashing indicator damage_indicator: Phaser.Image // Hover indicator hover_indicator: Phaser.Image // Create a ship button for the battle ship list constructor(list: ShipList, x: number, y: number, ship: Ship, owned: boolean, ship_buttons: IShipButton) { let info = list.view.getImageInfo("battle-shiplist-item-background"); super(list.view.game, x, y, info.key, undefined, undefined, info.frame, info.frame); this.view = list.view; this.ship = ship; this.player_indicator = this.view.newImage(owned ? "battle-hud-ship-own-mini" : "battle-hud-ship-enemy-mini", 102, 52); this.player_indicator.anchor.set(0.5); this.player_indicator.angle = -90; this.addChild(this.player_indicator); this.portrait = this.view.newImage(`ship-${ship.model.code}-sprite`, 52, 52); this.portrait.anchor.set(0.5); this.portrait.scale.set(0.8); this.portrait.angle = 180; this.addChild(this.portrait); this.damage_indicator = this.view.newImage("battle-shiplist-damage", 8, 9); this.damage_indicator.alpha = 0; this.addChild(this.damage_indicator); this.hover_indicator = this.view.newImage("battle-shiplist-hover", 7, 8); this.hover_indicator.visible = false; this.addChild(this.hover_indicator); this.view.inputs.setHoverClick(this, () => ship_buttons.cursorOnShip(ship), () => ship_buttons.cursorOffShip(ship), () => ship_buttons.cursorClicked() ); } // Flash a damage indicator setDamageHit() { this.game.tweens.create(this.damage_indicator).to({ alpha: 1 }, 100).to({ alpha: 0 }, 150).repeatAll(2).start(); } // Move to a given location on screen moveTo(x: number, y: number, duration: number) { if (duration && (this.x != x || this.y != y)) { this.view.animations.addAnimation(this, { x: x, y: y }, duration); } else { this.x = x; this.y = y; } } // Set the hovered status setHovered(hovered: boolean) { this.view.animations.setVisible(this.hover_indicator, hovered, 200); } } }