2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI {
|
2017-05-30 22:40:28 +00:00
|
|
|
/**
|
|
|
|
* Graphical hints for movement and weapon range
|
|
|
|
*/
|
|
|
|
export class RangeHint {
|
|
|
|
// Link to the view
|
|
|
|
private view: BaseView
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
// Visual information
|
|
|
|
private info: Phaser.Graphics
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
// Size of the arena
|
|
|
|
private width: number
|
|
|
|
private height: number
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-22 18:14:42 +00:00
|
|
|
constructor(arena: Arena) {
|
2017-09-19 15:09:06 +00:00
|
|
|
this.view = arena.view;
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
let boundaries = arena.getBoundaries();
|
|
|
|
this.width = boundaries.width;
|
|
|
|
this.height = boundaries.height;
|
2015-03-03 00:00:00 +00:00
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
this.info = new Phaser.Graphics(arena.game, 0, 0);
|
|
|
|
this.info.visible = false;
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
/**
|
|
|
|
* Set the layer in which the info will be displayed
|
|
|
|
*/
|
|
|
|
setLayer(layer: Phaser.Group, x = 0, y = 0) {
|
|
|
|
this.info.position.set(x, y);
|
|
|
|
layer.add(this.info);
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
/**
|
|
|
|
* Clear displayed information
|
|
|
|
*/
|
|
|
|
clear() {
|
|
|
|
this.info.clear();
|
|
|
|
this.info.visible = false;
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
/**
|
|
|
|
* Update displayed information
|
|
|
|
*/
|
2017-10-01 18:16:41 +00:00
|
|
|
update(ship: Ship, action: BaseAction, radius = action.getRangeRadius(ship)): void {
|
2017-05-30 22:40:28 +00:00
|
|
|
let yescolor = 0x000000;
|
|
|
|
let nocolor = 0x242022;
|
|
|
|
this.info.clear();
|
2015-03-03 00:00:00 +00:00
|
|
|
|
|
|
|
if (radius) {
|
2017-05-30 22:40:28 +00:00
|
|
|
this.info.beginFill(nocolor);
|
|
|
|
this.info.drawRect(0, 0, this.width, this.height);
|
|
|
|
|
|
|
|
this.info.beginFill(yescolor);
|
2017-10-01 18:16:41 +00:00
|
|
|
this.info.drawCircle(ship.arena_x, ship.arena_y, radius * 2);
|
2017-05-30 22:40:28 +00:00
|
|
|
|
|
|
|
if (action instanceof MoveAction) {
|
2017-08-17 17:51:22 +00:00
|
|
|
let exclusions = action.getExclusionAreas(ship);
|
|
|
|
|
2017-05-30 22:40:28 +00:00
|
|
|
this.info.beginFill(nocolor);
|
2017-08-17 17:51:22 +00:00
|
|
|
this.info.drawRect(0, 0, this.width, exclusions.hard_border);
|
|
|
|
this.info.drawRect(0, this.height - exclusions.hard_border, this.width, exclusions.hard_border);
|
|
|
|
this.info.drawRect(0, exclusions.hard_border, exclusions.hard_border, this.height - exclusions.hard_border * 2);
|
|
|
|
this.info.drawRect(this.width - exclusions.hard_border, exclusions.hard_border, exclusions.hard_border, this.height - exclusions.hard_border * 2);
|
2017-05-30 22:40:28 +00:00
|
|
|
|
2017-08-17 17:51:22 +00:00
|
|
|
exclusions.obstacles.forEach(obstacle => {
|
|
|
|
this.info.drawCircle(obstacle.x, obstacle.y, exclusions.effective_obstacle * 2);
|
|
|
|
});
|
2017-05-30 22:40:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.info.visible = true;
|
2015-03-03 00:00:00 +00:00
|
|
|
} else {
|
2017-05-30 22:40:28 +00:00
|
|
|
this.info.visible = false;
|
2015-03-03 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|