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 {
|
2017-04-10 17:38:33 +00:00
|
|
|
// Link to the view
|
|
|
|
battleview: BattleView;
|
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// 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;
|
|
|
|
|
2017-02-15 22:34:27 +00:00
|
|
|
// Statis effect
|
|
|
|
stasis: Phaser.Image;
|
|
|
|
|
2017-05-09 18:17:49 +00:00
|
|
|
// Target effect
|
|
|
|
target: Phaser.Image;
|
|
|
|
|
2017-05-15 18:30:44 +00:00
|
|
|
// Hover information
|
|
|
|
info: Phaser.Group;
|
|
|
|
info_hull: ValueBar;
|
|
|
|
info_shield: ValueBar;
|
2015-01-21 00:00:00 +00:00
|
|
|
|
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);
|
2017-04-10 17:38:33 +00:00
|
|
|
this.battleview = parent.battleview;
|
2015-01-21 00:00:00 +00:00
|
|
|
|
2016-10-26 21:15:04 +00:00
|
|
|
this.ship = ship;
|
2017-04-10 17:38:33 +00:00
|
|
|
this.enemy = this.ship.getPlayer() != this.battleview.player;
|
2016-10-26 21:15:04 +00:00
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Add ship sprite
|
2017-04-25 23:27:42 +00:00
|
|
|
this.sprite = new Phaser.Button(this.game, 0, 0, "ship-" + ship.model.code + "-sprite");
|
2015-01-21 00:00:00 +00:00
|
|
|
this.sprite.rotation = ship.arena_angle;
|
|
|
|
this.sprite.anchor.set(0.5, 0.5);
|
2017-04-16 15:03:18 +00:00
|
|
|
this.sprite.scale.set(64 / this.sprite.width);
|
2017-05-15 18:30:44 +00:00
|
|
|
this.add(this.sprite);
|
2015-01-21 00:00:00 +00:00
|
|
|
|
2017-05-09 18:17:49 +00:00
|
|
|
// Add stasis effect
|
2017-02-15 22:34:27 +00:00
|
|
|
this.stasis = new Phaser.Image(this.game, 0, 0, "battle-arena-stasis");
|
|
|
|
this.stasis.anchor.set(0.5, 0.5);
|
|
|
|
this.stasis.visible = false;
|
2017-05-15 18:30:44 +00:00
|
|
|
this.add(this.stasis);
|
2017-02-15 22:34:27 +00:00
|
|
|
|
2017-05-09 18:17:49 +00:00
|
|
|
// Add target effect
|
|
|
|
this.target = new Phaser.Image(this.game, 0, 0, "battle-arena-target");
|
|
|
|
this.target.anchor.set(0.5, 0.5);
|
|
|
|
this.target.visible = false;
|
2017-05-15 18:30:44 +00:00
|
|
|
this.add(this.target);
|
2017-05-09 18:17:49 +00:00
|
|
|
|
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);
|
2017-05-15 18:30:44 +00:00
|
|
|
this.add(this.frame);
|
|
|
|
|
|
|
|
// Hover informations
|
|
|
|
this.info = new Phaser.Group(this.game);
|
|
|
|
this.info_hull = new ValueBar(this.game, -59, -47, "battle-arena-ship-hull-base", true);
|
|
|
|
this.info_hull.setBarImage("battle-arena-ship-hull-full", 3);
|
|
|
|
this.info_hull.setValue(this.ship.getValue("hull"), this.ship.getAttribute("hull_capacity"));
|
|
|
|
this.info.add(this.info_hull);
|
|
|
|
this.info_shield = new ValueBar(this.game, 40, -47, "battle-arena-ship-shield-base", true);
|
|
|
|
this.info_shield.setBarImage("battle-arena-ship-shield-full", 3);
|
|
|
|
this.info_shield.setValue(this.ship.getValue("shield"), this.ship.getAttribute("shield_capacity"));
|
|
|
|
this.info.add(this.info_shield);
|
|
|
|
this.info.visible = false;
|
|
|
|
this.add(this.info);
|
2015-02-23 00:00:00 +00:00
|
|
|
|
2017-02-12 22:18:36 +00:00
|
|
|
// Effects display
|
|
|
|
this.effects = new Phaser.Group(this.game);
|
2017-05-15 18:30:44 +00:00
|
|
|
this.add(this.effects);
|
2017-02-12 22:18:36 +00:00
|
|
|
|
2015-01-21 00:00:00 +00:00
|
|
|
// Handle input on ship sprite
|
2017-05-04 23:19:28 +00:00
|
|
|
UITools.setHoverClick(this.sprite,
|
2017-04-10 17:38:33 +00:00
|
|
|
() => this.battleview.cursorOnShip(ship),
|
|
|
|
() => this.battleview.cursorOffShip(ship),
|
|
|
|
() => this.battleview.cursorClicked()
|
|
|
|
);
|
2015-01-21 00:00:00 +00:00
|
|
|
|
|
|
|
// Set location
|
|
|
|
this.position.set(ship.arena_x, ship.arena_y);
|
|
|
|
}
|
|
|
|
|
2017-05-15 18:30:44 +00:00
|
|
|
/**
|
|
|
|
* Set the hovered state on this ship
|
|
|
|
*
|
|
|
|
* This will show the information HUD accordingly
|
|
|
|
*/
|
2015-01-21 00:00:00 +00:00
|
|
|
setHovered(hovered: boolean) {
|
2017-05-15 18:30:44 +00:00
|
|
|
this.battleview.animations.setVisible(this.info, 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
|
|
|
}
|
|
|
|
|
2017-05-09 18:17:49 +00:00
|
|
|
/**
|
|
|
|
* Set the ship as target of current action
|
|
|
|
*
|
|
|
|
* This will toggle the visibility of target indicator
|
|
|
|
*/
|
|
|
|
setTargetted(targetted: boolean): void {
|
|
|
|
this.target.visible = targetted;
|
|
|
|
}
|
|
|
|
|
2017-02-15 22:34:27 +00:00
|
|
|
/**
|
|
|
|
* Activate the dead effect (stasis)
|
|
|
|
*/
|
|
|
|
setDead(dead = true) {
|
|
|
|
if (dead) {
|
|
|
|
this.displayEffect("stasis", false);
|
|
|
|
}
|
|
|
|
this.frame.alpha = dead ? 0.5 : 1.0;
|
2017-04-10 17:38:33 +00:00
|
|
|
this.battleview.animations.setVisible(this.stasis, dead, 400);
|
2017-02-15 22:34:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 00:30:50 +00:00
|
|
|
/**
|
|
|
|
* Move the sprite to a location
|
|
|
|
*
|
|
|
|
* Return the duration of animation
|
|
|
|
*/
|
|
|
|
moveTo(x: number, y: number, facing_angle: number, animate = true): number {
|
2015-01-21 00:00:00 +00:00
|
|
|
if (animate) {
|
2017-04-10 17:38:33 +00:00
|
|
|
return Animations.moveInSpace(this, x, y, facing_angle, this.sprite);
|
2015-01-21 00:00:00 +00:00
|
|
|
} else {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2015-01-26 00:00:00 +00:00
|
|
|
this.sprite.rotation = facing_angle;
|
2017-02-14 00:30:50 +00:00
|
|
|
return 0;
|
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-05-15 18:30:44 +00:00
|
|
|
this.effects.position.set(-this.effects.width / 2, this.sprite.height * 0.7);
|
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);
|
2017-05-15 18:30:44 +00:00
|
|
|
|
|
|
|
if (name == "hull") {
|
|
|
|
this.info_hull.setValue(event.value.get(), this.ship.getAttribute("hull_capacity"));
|
|
|
|
} else if (name == "shield") {
|
|
|
|
this.info_shield.setValue(event.value.get(), this.ship.getAttribute("shield_capacity"));
|
|
|
|
}
|
2015-02-03 00:00:00 +00:00
|
|
|
}
|
2015-01-21 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|