1
0
Fork 0
spacetac/src/ui/map/CurrentLocationMarker.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
2017-03-15 23:45:52 +00:00
/**
* Marker to show current location on the map
*/
2018-05-15 14:57:45 +00:00
export class CurrentLocationMarker extends UIImage {
2017-03-15 23:45:52 +00:00
private zoom = -1;
private moving = false;
private fleet: FleetDisplay;
2018-05-15 14:57:45 +00:00
constructor(private view: UniverseMapView, fleet: FleetDisplay) {
super(view, 0, 0, view.getImageInfo("map-current-location").key, view.getImageInfo("map-current-location").frame);
2017-03-15 23:45:52 +00:00
this.fleet = fleet;
2018-05-15 14:57:45 +00:00
this.setOrigin(0.5, 0.5);
2017-03-15 23:45:52 +00:00
this.alpha = 0;
}
tweenTo(alpha: number, scale: number) {
2018-05-15 14:57:45 +00:00
this.view.animations.addAnimation<UIImage>(this, { alpha: alpha, scaleX: scale, scaleY: scale }, 500);
2017-03-15 23:45:52 +00:00
}
show() {
2017-06-05 22:05:34 +00:00
let scale = 1;
if (this.zoom == 2) {
2018-05-15 14:57:45 +00:00
this.setPosition(this.fleet.x, this.fleet.y);
scale = this.fleet.scaleX * 4;
2017-06-05 22:05:34 +00:00
} else {
2018-05-15 14:57:45 +00:00
this.setPosition(this.fleet.location.star.x, this.fleet.location.star.y);
2017-06-05 22:05:34 +00:00
scale = (this.zoom == 1) ? 0.002 : 0.016;
}
2018-05-15 14:57:45 +00:00
this.setAlpha(0);
this.setScale(scale * 10);
2017-03-15 23:45:52 +00:00
this.tweenTo(1, scale);
}
hide() {
2018-05-15 14:57:45 +00:00
this.tweenTo(0, this.scaleX * 10);
2017-03-15 23:45:52 +00:00
}
setZoom(level: number) {
if (level != this.zoom) {
this.zoom = level;
if (!this.moving) {
this.show();
}
}
}
setFleetMoving(moving: boolean) {
if (moving != this.moving) {
this.moving = moving;
if (moving) {
this.hide();
} else {
this.show();
}
}
}
}
}