2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac.UI {
|
2015-03-03 00:00:00 +00:00
|
|
|
// Graphical hints for movement and weapon range
|
|
|
|
export class RangeHint extends Phaser.Group {
|
|
|
|
// Link to the arena
|
2017-05-22 18:14:42 +00:00
|
|
|
arena: Arena;
|
2015-03-03 00:00:00 +00:00
|
|
|
|
|
|
|
// Displayed circle
|
|
|
|
circle: Phaser.Graphics;
|
|
|
|
|
|
|
|
// Stored information of primary circle, when secondary one overrides it
|
2017-03-09 17:11:00 +00:00
|
|
|
primary: Phaser.Circle | null;
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-22 18:14:42 +00:00
|
|
|
constructor(arena: Arena) {
|
|
|
|
super(arena.game);
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-22 18:14:42 +00:00
|
|
|
this.arena = arena;
|
2015-03-03 00:00:00 +00:00
|
|
|
|
|
|
|
this.circle = new Phaser.Graphics(this.game, 0, 0);
|
2017-05-18 21:10:16 +00:00
|
|
|
this.add(this.circle);
|
2015-03-03 00:00:00 +00:00
|
|
|
|
|
|
|
this.primary = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the primary hint
|
|
|
|
clearPrimary(): void {
|
|
|
|
this.primary = null;
|
|
|
|
this.circle.visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the secondary hint
|
|
|
|
clearSecondary(): void {
|
|
|
|
if (this.primary) {
|
|
|
|
this.draw(this.primary);
|
|
|
|
} else {
|
|
|
|
this.circle.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set currently selected action
|
2017-02-09 00:00:35 +00:00
|
|
|
setPrimary(ship: Ship, action: BaseAction): void {
|
2015-03-03 00:00:00 +00:00
|
|
|
var radius = action.getRangeRadius(ship);
|
|
|
|
if (radius) {
|
|
|
|
this.primary = new Phaser.Circle(ship.arena_x, ship.arena_y, radius * 2);
|
|
|
|
this.draw(this.primary);
|
|
|
|
} else {
|
|
|
|
this.circle.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set currently hovered action
|
2017-02-09 00:00:35 +00:00
|
|
|
setSecondary(ship: Ship, action: BaseAction): void {
|
2015-03-03 00:00:00 +00:00
|
|
|
var radius = action.getRangeRadius(ship);
|
|
|
|
if (radius) {
|
|
|
|
this.draw(new Phaser.Circle(ship.arena_x, ship.arena_y, radius * 2));
|
|
|
|
} else {
|
|
|
|
this.circle.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw a circle, hinting available range
|
|
|
|
private draw(circle: Phaser.Circle): void {
|
|
|
|
this.circle.clear();
|
2017-05-09 18:17:49 +00:00
|
|
|
this.circle.lineStyle(5, 0xffffff, 0.2);
|
2015-03-03 00:00:00 +00:00
|
|
|
this.circle.drawCircle(circle.x, circle.y, circle.diameter);
|
|
|
|
this.circle.visible = true;
|
2017-05-22 18:14:42 +00:00
|
|
|
this.add(this.circle);
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|