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

69 lines
2.2 KiB
TypeScript
Raw Permalink Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.UI {
2017-07-11 22:28:45 +00:00
/**
* Marker to show a mission location on the map
*/
export class MissionLocationMarker {
2018-05-15 14:57:45 +00:00
private builder: UIBuilder
2018-01-31 18:19:50 +00:00
private markers: [StarLocation | Star, string][] = []
2017-07-11 22:28:45 +00:00
private zoomed = true
2018-01-31 18:19:50 +00:00
private current_star?: Star
2017-07-11 22:28:45 +00:00
2018-05-15 14:57:45 +00:00
constructor(private view: BaseView, parent: UIContainer) {
2017-08-21 22:41:44 +00:00
this.view = view;
2018-05-15 14:57:45 +00:00
let builder = new UIBuilder(view, parent);
this.builder = builder.in(builder.container("mission_markers"));
2017-07-11 22:28:45 +00:00
}
/**
2017-08-21 22:41:44 +00:00
* Set the active markers (location and image name)
2017-07-11 22:28:45 +00:00
*/
2017-08-21 22:41:44 +00:00
setMarkers(markers: [StarLocation | Star, string][]): void {
2017-07-11 22:28:45 +00:00
this.markers = markers;
this.refresh();
}
/**
* Set the zoom level
*/
setZoom(level: number, star: Star): void {
this.zoomed = level >= 2;
this.current_star = star;
this.refresh();
}
/**
* Refresh the display
*/
refresh(): void {
2018-05-15 14:57:45 +00:00
this.builder.clear();
2017-07-11 22:28:45 +00:00
2017-08-21 22:41:44 +00:00
this.markers.forEach(([location, name], index) => {
2017-07-11 22:28:45 +00:00
let focus = this.zoomed ? location : (location instanceof StarLocation ? location.star : location);
if (location !== this.current_star || !this.zoomed) {
let marker = this.getMarker(focus, index - 1);
2018-05-15 14:57:45 +00:00
let image = this.builder.image(name, marker.x, marker.y);
image.setScale(marker.scale);
2017-07-11 22:28:45 +00:00
}
});
}
private getMarker(focus: Star | StarLocation, offset: number): { x: number, y: number, scale: number } {
if (focus instanceof StarLocation) {
let system = focus.star;
return {
x: focus.universe_x + offset * system.radius * 0.05,
y: focus.universe_y - system.radius * 0.08,
scale: system.radius * 0.001
}
} else {
return {
x: focus.x + offset * focus.radius * 0.6,
y: focus.y - focus.radius * 0.7,
scale: focus.radius * 0.01
}
}
}
}
}