2014-12-31 00:00:00 +00:00
|
|
|
module SpaceTac.View {
|
2015-01-07 00:00:00 +00:00
|
|
|
"use strict";
|
|
|
|
|
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
|
2015-01-28 00:00:00 +00:00
|
|
|
ship: Game.Ship;
|
|
|
|
|
|
|
|
// Hull display
|
|
|
|
hull: ValueBar;
|
|
|
|
|
|
|
|
// Shield display
|
|
|
|
shield: ValueBar;
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
// Action points display
|
|
|
|
ap: ValueBar;
|
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Portrait
|
|
|
|
layer_portrait: Phaser.Image;
|
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Hover indicator
|
|
|
|
layer_hover: Phaser.Image;
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
// Playing indicator
|
|
|
|
layer_playing: Phaser.Image;
|
|
|
|
|
|
|
|
// Non-playing indicator
|
|
|
|
layer_normal: Phaser.Image;
|
|
|
|
|
|
|
|
// Enemy indicator
|
|
|
|
layer_enemy: Phaser.Image;
|
|
|
|
|
2014-12-30 00:00:00 +00:00
|
|
|
// Create a ship button for the battle ship list
|
2015-01-14 00:00:00 +00:00
|
|
|
constructor(list: ShipList, x: number, y: number, ship: Game.Ship, owned: boolean) {
|
2014-12-31 00:00:00 +00:00
|
|
|
this.ship = ship;
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
super(list.battleview.game, x, y, "battle-shiplist-base");
|
2014-12-31 00:00:00 +00:00
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
this.input.useHandCursor = true;
|
2014-12-31 00:00:00 +00:00
|
|
|
this.onInputOver.add(() => {
|
2015-01-14 00:00:00 +00:00
|
|
|
list.battleview.cursorOnShip(ship);
|
2014-12-31 00:00:00 +00:00
|
|
|
});
|
|
|
|
this.onInputOut.add(() => {
|
2015-01-14 00:00:00 +00:00
|
|
|
list.battleview.cursorOffShip(ship);
|
2014-12-31 00:00:00 +00:00
|
|
|
});
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
this.layer_playing = new Phaser.Image(this.game, 0, 0, "battle-shiplist-playing", 0);
|
|
|
|
this.layer_playing.alpha = 0;
|
|
|
|
this.addChild(this.layer_playing);
|
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
this.layer_portrait = new Phaser.Image(this.game, 14, 15, "ship-scout-portrait", 0);
|
|
|
|
this.addChild(this.layer_portrait);
|
|
|
|
|
2015-02-03 00:00:00 +00:00
|
|
|
this.layer_normal = new Phaser.Image(this.game, 0, 0, "battle-shiplist-normal", 0);
|
|
|
|
this.addChild(this.layer_normal);
|
|
|
|
|
|
|
|
this.layer_enemy = new Phaser.Image(this.game, 0, 0, owned ? "battle-shiplist-own" : "battle-shiplist-enemy", 0);
|
|
|
|
this.addChild(this.layer_enemy);
|
|
|
|
|
2015-02-23 00:00:00 +00:00
|
|
|
this.layer_hover = new Phaser.Image(this.game, 14, 14, "battle-arena-shipspritehover", 0);
|
2015-02-04 00:00:00 +00:00
|
|
|
this.layer_hover.visible = false;
|
|
|
|
this.addChild(this.layer_hover);
|
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
this.hull = ValueBar.newStyled(list.battleview.game, "battle-shiplist-hull", 76, 23);
|
2015-01-28 00:00:00 +00:00
|
|
|
this.addChild(this.hull);
|
|
|
|
|
2015-02-28 00:00:00 +00:00
|
|
|
this.shield = ValueBar.newStyled(list.battleview.game, "battle-shiplist-shield", 76, 35);
|
2015-01-28 00:00:00 +00:00
|
|
|
this.addChild(this.shield);
|
2015-02-28 00:00:00 +00:00
|
|
|
|
|
|
|
this.ap = ValueBar.newStyled(list.battleview.game, "battle-shiplist-ap", 76, 47);
|
|
|
|
this.addChild(this.ap);
|
|
|
|
|
|
|
|
this.updateAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update attributes from associated ship
|
|
|
|
updateAttributes() {
|
|
|
|
this.attributeChanged(this.ship.hull);
|
|
|
|
this.attributeChanged(this.ship.shield);
|
|
|
|
this.attributeChanged(this.ship.ap_current);
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
2015-02-28 00:00:00 +00:00
|
|
|
} else if (attribute.code === Game.AttributeCode.AP) {
|
|
|
|
this.ap.setValue(attribute.current, attribute.maximal);
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
2014-12-30 00:00:00 +00:00
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
|
|
|
|
// Set the playing status
|
|
|
|
setPlaying(playing: boolean) {
|
2015-02-20 00:00:00 +00:00
|
|
|
Animation.setVisibility(this.game, this.layer_playing, playing, 500);
|
|
|
|
Animation.setVisibility(this.game, this.layer_normal, !playing, 500);
|
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
|
|
|
}
|