2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI {
|
2015-01-21 00:00:00 +00:00
|
|
|
// Ship sprite in the arena (BattleView)
|
|
|
|
export class ArenaShip extends Phaser.Group {
|
|
|
|
// Link to displayed ship
|
2017-02-09 00:00:35 +00:00
|
|
|
ship: Ship;
|
2015-01-21 00:00:00 +00:00
|
|
|
|
2017-01-10 00:22:59 +00:00
|
|
|
// Boolean to indicate if it is an enemy ship
|
|
|
|
enemy: boolean;
|
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Ship sprite
|
|
|
|
sprite: Phaser.Button;
|
|
|
|
|
|
|
|
// Hover effect
|
|
|
|
hover: Phaser.Image;
|
|
|
|
|
2017-01-10 00:22:59 +00:00
|
|
|
// Frame to indicate the owner of the ship, and if it is playing
|
|
|
|
frame: Phaser.Image;
|
2015-01-23 00:00:00 +00:00
|
|
|
|
2017-02-12 22:18:36 +00:00
|
|
|
// Effects display
|
|
|
|
effects: Phaser.Group;
|
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Create a ship sprite usable in the Arena
|
2017-02-12 22:18:36 +00:00
|
|
|
constructor(parent: Arena, ship: Ship) {
|
|
|
|
super(parent.game);
|
|
|
|
let battleview = parent.battleview;
|
2015-01-21 00:00:00 +00:00
|
|
|
|
2016-10-26 21:15:04 +00:00
|
|
|
this.ship = ship;
|
2017-01-10 00:22:59 +00:00
|
|
|
this.enemy = this.ship.getPlayer() != battleview.player;
|
2016-10-26 21:15:04 +00:00
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Add ship sprite
|
2017-02-12 22:18:36 +00:00
|
|
|
this.sprite = new Phaser.Button(this.game, 0, 0, "ship-" + ship.model + "-sprite");
|
2015-01-21 00:00:00 +00:00
|
|
|
this.sprite.rotation = ship.arena_angle;
|
|
|
|
this.sprite.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.sprite);
|
|
|
|
|
2017-01-10 00:22:59 +00:00
|
|
|
// Add playing effect
|
2017-02-12 22:18:36 +00:00
|
|
|
this.frame = new Phaser.Image(this.game, 0, 0, `battle-arena-ship-normal-${this.enemy ? "enemy" : "own"}`, 0);
|
2017-01-10 00:22:59 +00:00
|
|
|
this.frame.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(this.frame);
|
|
|
|
|
2015-02-23 00:00:00 +00:00
|
|
|
// Add hover effect
|
2017-02-12 22:18:36 +00:00
|
|
|
this.hover = new Phaser.Image(this.game, 0, 0, "battle-arena-ship-hover", 0);
|
2015-02-23 00:00:00 +00:00
|
|
|
this.hover.anchor.set(0.5, 0.5);
|
|
|
|
this.hover.visible = false;
|
|
|
|
this.addChild(this.hover);
|
|
|
|
|
2017-02-12 22:18:36 +00:00
|
|
|
// Effects display
|
|
|
|
this.effects = new Phaser.Group(this.game);
|
|
|
|
this.addChild(this.effects);
|
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Handle input on ship sprite
|
2017-01-19 00:17:24 +00:00
|
|
|
Tools.setHoverClick(this.sprite, () => battleview.cursorOnShip(ship), () => battleview.cursorOffShip(ship), () => battleview.cursorClicked());
|
2015-01-21 00:00:00 +00:00
|
|
|
|
|
|
|
// Set location
|
|
|
|
this.position.set(ship.arena_x, ship.arena_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the hovered state on this ship
|
|
|
|
// This will toggle the hover effect
|
|
|
|
setHovered(hovered: boolean) {
|
2015-02-20 00:00:00 +00:00
|
|
|
Animation.setVisibility(this.game, this.hover, hovered, 200);
|
2015-01-21 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 00:00:00 +00:00
|
|
|
// Set the playing state on this ship
|
|
|
|
// This will toggle the "playing" indicator
|
|
|
|
setPlaying(playing: boolean) {
|
2017-01-10 00:22:59 +00:00
|
|
|
this.frame.loadTexture(`battle-arena-ship-${playing ? "playing" : "normal"}-${this.enemy ? "enemy" : "own"}`);
|
2015-01-23 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Move the sprite to a location
|
2017-02-13 19:31:45 +00:00
|
|
|
moveTo(x: number, y: number, facing_angle: number, animate: boolean = true, on_complete: Function | null = null) {
|
2015-01-21 00:00:00 +00:00
|
|
|
if (animate) {
|
|
|
|
var tween_group = this.game.tweens.create(this);
|
|
|
|
var tween_sprite = this.game.tweens.create(this.sprite);
|
2017-01-09 00:37:15 +00:00
|
|
|
tween_group.to({ x: x, y: y });
|
2015-01-21 00:00:00 +00:00
|
|
|
tween_group.start();
|
2015-01-26 00:00:00 +00:00
|
|
|
Tools.rotationTween(tween_sprite, facing_angle);
|
2017-02-13 19:31:45 +00:00
|
|
|
if (on_complete) {
|
|
|
|
tween_sprite.onComplete.addOnce(on_complete);
|
|
|
|
}
|
2015-01-21 00:00:00 +00:00
|
|
|
tween_sprite.start();
|
|
|
|
} else {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2015-01-26 00:00:00 +00:00
|
|
|
this.sprite.rotation = facing_angle;
|
2017-02-13 19:31:45 +00:00
|
|
|
if (on_complete) {
|
|
|
|
on_complete();
|
|
|
|
}
|
2015-01-21 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
|
2017-02-12 22:18:36 +00:00
|
|
|
/**
|
|
|
|
* Briefly show an effect on this ship
|
|
|
|
*/
|
|
|
|
displayEffect(message: string, beneficial: boolean) {
|
|
|
|
let text = new Phaser.Text(this.game, 0, 20 * this.effects.children.length, message, { font: "14pt Arial", fill: beneficial ? "#afe9c6" : "#e9afaf" });
|
|
|
|
this.effects.addChild(text);
|
|
|
|
|
2017-02-13 19:31:45 +00:00
|
|
|
this.effects.position.set(-this.effects.width / 2, this.sprite.height * 0.8);
|
2017-02-12 22:18:36 +00:00
|
|
|
|
|
|
|
this.game.tweens.removeFrom(this.effects);
|
|
|
|
this.effects.alpha = 1;
|
|
|
|
let tween = this.game.tweens.create(this.effects).to({ alpha: 0 }, 500).delay(1000).start();
|
|
|
|
tween.onComplete.addOnce(() => this.effects.removeAll(true));
|
2015-02-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 22:18:36 +00:00
|
|
|
/**
|
|
|
|
* Display interesting changes in ship values
|
|
|
|
*/
|
|
|
|
displayValueChanged(event: ValueChangeEvent) {
|
|
|
|
let diff = event.diff;
|
|
|
|
let name = event.value.name;
|
|
|
|
this.displayEffect(`${name} ${diff < 0 ? "-" : "+"}${Math.abs(diff)}`, diff >= 0);
|
2015-02-03 00:00:00 +00:00
|
|
|
}
|
2015-01-21 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|