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

92 lines
2.7 KiB
TypeScript
Raw Normal View History

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 {
// 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-05-14 21:03:03 +00:00
// Player indicator
2018-05-15 14:57:45 +00:00
player_indicator: UIImage
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
// Damage flashing indicator
2018-05-15 14:57:45 +00:00
damage_indicator: UIImage
2015-02-04 00:00:00 +00:00
// Hover indicator
2018-05-15 14:57:45 +00:00
hover_indicator: UIImage
// 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);
2018-05-15 14:57:45 +00:00
this.damage_indicator = builder.image("battle-shiplist-damage", 8, 9);
this.damage_indicator.visible = false;
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
this.view.inputs.setHoverClick(this,
2017-10-25 22:45:53 +00:00
() => ship_buttons.cursorOnShip(ship),
() => ship_buttons.cursorOffShip(ship),
() => ship_buttons.cursorClicked()
);
}
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
*/
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
});
}
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);
} 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
}
}
2015-01-07 00:00:00 +00:00
}