2014-12-31 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
2015-01-07 00:00:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Card to display detailed information about a ship
|
|
|
|
export class ShipCard extends Phaser.Sprite {
|
|
|
|
// Displayed ship
|
2015-02-23 00:00:00 +00:00
|
|
|
ship: Game.Ship;
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
// Hull gauge
|
|
|
|
hull: ValueBar;
|
|
|
|
|
|
|
|
// Shield gauge
|
|
|
|
shield: ValueBar;
|
|
|
|
|
|
|
|
// AP gauge
|
|
|
|
ap: ValueBar;
|
|
|
|
|
|
|
|
// Ship portrait
|
|
|
|
portrait: Phaser.Image;
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Build an empty ship card
|
|
|
|
constructor(battleview: BattleView, x: number, y: number) {
|
2015-01-23 00:00:00 +00:00
|
|
|
super(battleview.game, x, y, "battle-ship-card");
|
2014-12-31 00:00:00 +00:00
|
|
|
|
|
|
|
this.ship = null;
|
|
|
|
this.visible = false;
|
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
this.portrait = null;
|
|
|
|
|
|
|
|
this.hull = ValueBar.newStyled(this.game, "battle-shipcard-hull", 122, 8, true);
|
|
|
|
this.addChild(this.hull);
|
|
|
|
|
|
|
|
this.shield = ValueBar.newStyled(this.game, "battle-shipcard-shield", 156, 8, true);
|
|
|
|
this.addChild(this.shield);
|
|
|
|
|
|
|
|
this.ap = ValueBar.newStyled(this.game, "battle-shipcard-ap", 189, 8, true);
|
|
|
|
this.addChild(this.ap);
|
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
battleview.ui.add(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the currently displayed ship (null to hide)
|
|
|
|
setShip(ship: Game.Ship) {
|
|
|
|
this.ship = ship;
|
2015-02-20 00:00:00 +00:00
|
|
|
Animation.setVisibility(this.game, this, ship !== null, 200);
|
2015-02-28 00:00:00 +00:00
|
|
|
|
|
|
|
if (this.ship) {
|
|
|
|
this.updateAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.portrait) {
|
|
|
|
this.portrait.destroy();
|
|
|
|
}
|
|
|
|
this.portrait = new Phaser.Image(this.game, 47, 47, "ship-scout-portrait", 0);
|
|
|
|
this.portrait.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.portrait);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update attributes from associated ship
|
|
|
|
updateAttributes() {
|
|
|
|
this.attributeChanged(this.ship.hull);
|
|
|
|
this.attributeChanged(this.ship.shield);
|
|
|
|
this.attributeChanged(this.ship.ap_current);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called when an attribute for this ship changed through the battle log
|
|
|
|
attributeChanged(attribute: Game.Attribute): void {
|
|
|
|
if (attribute.code === Game.AttributeCode.Hull) {
|
|
|
|
this.hull.setValue(attribute.current, attribute.maximal);
|
|
|
|
} else if (attribute.code === Game.AttributeCode.Shield) {
|
|
|
|
this.shield.setValue(attribute.current, attribute.maximal);
|
|
|
|
} else if (attribute.code === Game.AttributeCode.AP) {
|
|
|
|
this.ap.setValue(attribute.current, attribute.maximal);
|
|
|
|
}
|
2014-12-31 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|