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 {
|
2014-12-31 00:00:00 +00:00
|
|
|
// Reference to the ship game object
|
2017-02-09 00:00:35 +00:00
|
|
|
ship: Ship;
|
2015-01-28 00:00:00 +00:00
|
|
|
|
|
|
|
// Hull display
|
|
|
|
hull: ValueBar;
|
|
|
|
|
|
|
|
// Shield display
|
|
|
|
shield: ValueBar;
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
// Power display
|
|
|
|
power: ValueBar;
|
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Portrait
|
|
|
|
layer_portrait: Phaser.Image;
|
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
// Damage flashing indicator
|
|
|
|
layer_damage: Phaser.Image;
|
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Hover indicator
|
|
|
|
layer_hover: Phaser.Image;
|
|
|
|
|
2015-04-22 20:03:59 +00:00
|
|
|
// Active effects group
|
|
|
|
active_effects: Phaser.Group;
|
|
|
|
|
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) {
|
2015-04-26 17:15:45 +00:00
|
|
|
super(list.battleview.game, x, y, owned ? "battle-shiplist-own" : "battle-shiplist-enemy");
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2016-10-26 21:15:04 +00:00
|
|
|
this.ship = ship;
|
|
|
|
|
2017-01-31 21:07:59 +00:00
|
|
|
this.active_effects = new Phaser.Group(this.game);
|
|
|
|
this.addChild(this.active_effects);
|
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
this.layer_portrait = new Phaser.Image(this.game, 8, 8, "ship-" + ship.model + "-portrait", 0);
|
2017-01-08 22:04:07 +00:00
|
|
|
this.layer_portrait.scale.set(0.3, 0.3);
|
2015-02-04 00:00:00 +00:00
|
|
|
this.addChild(this.layer_portrait);
|
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
this.layer_damage = new Phaser.Image(this.game, 8, 8, "battle-shiplist-damage", 0);
|
|
|
|
this.layer_damage.alpha = 0;
|
|
|
|
this.addChild(this.layer_damage);
|
|
|
|
|
|
|
|
this.layer_hover = new Phaser.Image(this.game, 5, 5, "battle-arena-ship-hover", 0);
|
2015-02-04 00:00:00 +00:00
|
|
|
this.layer_hover.visible = false;
|
|
|
|
this.addChild(this.layer_hover);
|
|
|
|
|
2017-01-11 00:38:08 +00:00
|
|
|
this.hull = ValueBar.newStyled(this.game, "battle-shiplist-hull", 90, 39, true);
|
|
|
|
this.addChild(this.hull);
|
2017-01-08 22:04:07 +00:00
|
|
|
|
|
|
|
this.shield = ValueBar.newStyled(this.game, "battle-shiplist-shield", 98, 39, true);
|
2015-01-28 00:00:00 +00:00
|
|
|
this.addChild(this.shield);
|
2015-02-28 00:00:00 +00:00
|
|
|
|
2017-02-07 19:15:21 +00:00
|
|
|
this.power = ValueBar.newStyled(this.game, "battle-shiplist-energy", 106, 39, true);
|
|
|
|
this.addChild(this.power);
|
2015-04-26 17:15:45 +00:00
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
this.updateAttributes();
|
2015-04-22 20:03:59 +00:00
|
|
|
this.updateEffects();
|
2017-01-19 00:17:24 +00:00
|
|
|
|
2017-03-17 00:07:00 +00:00
|
|
|
let level = new Phaser.Text(this.game, 103, 22, `${ship.level.get()}`, { align: "center", font: "bold 10pt Arial", fill: "#000000" });
|
|
|
|
level.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(level);
|
|
|
|
|
2017-01-19 00:17:24 +00:00
|
|
|
Tools.setHoverClick(this, () => list.battleview.cursorOnShip(ship), () => list.battleview.cursorOffShip(ship), () => list.battleview.cursorClicked());
|
2015-02-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update attributes from associated ship
|
|
|
|
updateAttributes() {
|
2017-02-07 19:15:21 +00:00
|
|
|
this.hull.setValue(this.ship.values.hull.get(), this.ship.attributes.hull_capacity.get());
|
|
|
|
this.shield.setValue(this.ship.values.shield.get(), this.ship.attributes.shield_capacity.get());
|
|
|
|
this.power.setValue(this.ship.values.power.get(), this.ship.attributes.power_capacity.get());
|
2015-04-22 20:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update effects applied on the ship
|
|
|
|
updateEffects() {
|
|
|
|
this.active_effects.removeAll(true);
|
2017-01-23 23:07:54 +00:00
|
|
|
var count = this.ship.sticky_effects.length;
|
2017-01-16 23:20:33 +00:00
|
|
|
var spacing = (8 * (count - 1) > 72) ? 72 / (count - 1) : 8;
|
2017-01-23 23:07:54 +00:00
|
|
|
this.ship.sticky_effects.forEach((effect, index) => {
|
2017-01-16 23:20:33 +00:00
|
|
|
var x = 46 - (count - 1) * spacing / 2 + index * spacing;
|
2017-01-31 21:07:59 +00:00
|
|
|
var badge = new Phaser.Image(this.game, x, 46, `battle-shiplist-effect-${effect.isBeneficial() ? "good" : "bad"}`);
|
2017-01-16 23:20:33 +00:00
|
|
|
badge.anchor.set(0.5, 0.5);
|
|
|
|
this.active_effects.addChild(badge);
|
2015-04-22 20:03:59 +00:00
|
|
|
});
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
// Flash a damage indicator
|
|
|
|
setDamageHit() {
|
|
|
|
this.game.tweens.create(this.layer_damage).to({ alpha: 1 }, 100).to({ alpha: 0 }, 150).repeatAll(2).start();
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-02-20 00:00:00 +00:00
|
|
|
Animation.setVisibility(this.game, this.layer_hover, 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
|
|
|
}
|