2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI {
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* One item in a ship list (used in BattleView)
|
|
|
|
*/
|
|
|
|
export class ShipListItem extends UIContainer {
|
2017-04-10 17:38:33 +00:00
|
|
|
// Reference to the view
|
2017-10-25 22:45:53 +00:00
|
|
|
view: BaseView
|
2017-04-10 17:38:33 +00:00
|
|
|
|
2014-12-31 00:00:00 +00:00
|
|
|
// Reference to the ship game object
|
2017-05-14 21:03:03 +00:00
|
|
|
ship: Ship
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2017-05-14 21:03:03 +00:00
|
|
|
// Player indicator
|
2018-05-15 14:57:45 +00:00
|
|
|
player_indicator: UIImage
|
2017-02-07 19:15:21 +00:00
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Portrait
|
2018-05-15 14:57:45 +00:00
|
|
|
portrait: UIImage
|
2015-02-04 00:00:00 +00:00
|
|
|
|
2017-01-15 22:05:00 +00:00
|
|
|
// Damage flashing indicator
|
2018-05-15 14:57:45 +00:00
|
|
|
damage_indicator: UIImage
|
2017-01-15 22:05:00 +00:00
|
|
|
|
2015-02-04 00:00:00 +00:00
|
|
|
// Hover indicator
|
2018-05-15 14:57:45 +00:00
|
|
|
hover_indicator: UIImage
|
2015-04-22 20:03:59 +00:00
|
|
|
|
2014-12-30 00:00:00 +00:00
|
|
|
// 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) {
|
2018-05-15 14:57:45 +00:00
|
|
|
// TODO Make it an UIButton
|
|
|
|
super(list.view, x, y);
|
2017-10-25 22:45:53 +00:00
|
|
|
this.view = list.view;
|
2016-10-26 21:15:04 +00:00
|
|
|
this.ship = ship;
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
let builder = new UIBuilder(list.view, this);
|
|
|
|
|
|
|
|
builder.image("battle-shiplist-item-background");
|
|
|
|
|
|
|
|
this.player_indicator = builder.image(owned ? "battle-hud-ship-own-mini" : "battle-hud-ship-enemy-mini", 102, 52, true);
|
|
|
|
this.player_indicator.setAngle(-90);
|
2015-02-04 00:00:00 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
this.portrait = builder.image(`ship-${ship.model.code}-sprite`, 52, 52, true);
|
|
|
|
this.portrait.setScale(0.8)
|
|
|
|
this.portrait.setAngle(180);
|
2017-01-08 22:04:07 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
this.damage_indicator = builder.image("battle-shiplist-damage", 8, 9);
|
|
|
|
this.damage_indicator.visible = false;
|
2015-02-28 00:00:00 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
this.hover_indicator = builder.image("battle-shiplist-hover", 7, 8);
|
2017-05-14 21:03:03 +00:00
|
|
|
this.hover_indicator.visible = false;
|
2017-03-17 00:07:00 +00:00
|
|
|
|
2017-10-01 20:52:50 +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()
|
2017-10-01 20:52:50 +00:00
|
|
|
);
|
2015-02-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
get location(): { x: number, y: number } {
|
|
|
|
return { x: this.x, y: this.y };
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flash a damage indicator
|
|
|
|
*/
|
2017-01-15 22:05:00 +00:00
|
|
|
setDamageHit() {
|
2018-05-15 14:57:45 +00:00
|
|
|
this.view.tweens.add({
|
|
|
|
targets: this.damage_indicator,
|
|
|
|
duration: 100,
|
|
|
|
alpha: 1,
|
|
|
|
repeat: 2,
|
|
|
|
yoyo: true
|
|
|
|
});
|
2017-01-15 22:05:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* Move to a given location on screen
|
|
|
|
*/
|
|
|
|
moveAt(x: number, y: number, duration: number) {
|
2017-10-25 22:45:53 +00:00
|
|
|
if (duration && (this.x != x || this.y != y)) {
|
2018-05-15 14:57:45 +00:00
|
|
|
this.view.animations.addAnimation<UIContainer>(this, { x: x, y: y }, duration);
|
2015-04-26 17:15:45 +00:00
|
|
|
} else {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
}
|
2015-02-04 00:00:00 +00:00
|
|
|
|
2018-05-15 14:57:45 +00:00
|
|
|
/**
|
|
|
|
* Set the hovered status
|
|
|
|
*/
|
2015-02-04 00:00:00 +00:00
|
|
|
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
|
|
|
}
|
2014-12-30 00:00:00 +00:00
|
|
|
}
|
2015-01-07 00:00:00 +00:00
|
|
|
}
|