1
0
Fork 0
spacetac/src/ui/battle/ShipListItem.ts

79 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
// One item in a ship list (used in BattleView)
export class ShipListItem extends Phaser.Button {
// Reference to the view
2017-10-25 22:45:53 +00:00
view: BaseView
2014-12-31 00:00:00 +00:00
// Reference to the ship game object
2017-05-14 21:03:03 +00:00
ship: Ship
2017-10-25 22:45:53 +00:00
// Callbacks to act as buttons
ship_buttons: IShipButton
2017-05-14 21:03:03 +00:00
// Player indicator
player_indicator: Phaser.Image
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
// Damage flashing indicator
2017-05-14 21:03:03 +00:00
damage_indicator: Phaser.Image
2015-02-04 00:00:00 +00:00
// Hover indicator
2017-05-14 21:03:03 +00:00
hover_indicator: Phaser.Image
// Create a ship button for the battle ship list
2017-10-25 22:45:53 +00:00
constructor(list: ShipList, x: number, y: number, ship: Ship, owned: boolean, ship_buttons: IShipButton) {
super(list.view.game, x, y, "battle-shiplist-item-background");
this.view = list.view;
2014-12-31 00:00:00 +00:00
2016-10-26 21:15:04 +00:00
this.ship = ship;
2017-09-28 23:18:46 +00:00
this.player_indicator = this.view.newImage(owned ? "battle-hud-ship-own-mini" : "battle-hud-ship-enemy-mini", 10, 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
2018-01-28 20:19:28 +00:00
this.portrait = this.view.newImage(`ship-${ship.model.code}-sprite`, 62, 52);
this.portrait.anchor.set(0.5, 0.5);
this.portrait.scale.set(0.8, 0.8);
this.portrait.angle = 180;
2017-05-14 21:03:03 +00:00
this.addChild(this.portrait);
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);
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
this.view.inputs.setHoverClick(this,
2017-10-25 22:45:53 +00:00
() => ship_buttons.cursorOnShip(ship),
() => ship_buttons.cursorOffShip(ship),
() => ship_buttons.cursorClicked()
);
}
// 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();
}
// Move to a given location on screen
2017-10-25 22:45:53 +00:00
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;
}
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
}
}
2015-01-07 00:00:00 +00:00
}