MapComplete/UI/CenterMessageBox.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

2020-06-24 00:35:19 +02:00
import {UIElement} from "./UIElement";
2020-07-20 23:43:42 +02:00
import Translations from "./i18n/Translations";
import State from "../State";
2020-06-24 00:35:19 +02:00
export default class CenterMessageBox extends UIElement {
2020-06-24 00:35:19 +02:00
constructor() {
super(State.state.centerMessage);
2020-06-24 00:35:19 +02:00
this.ListenTo(State.state.locationControl);
this.ListenTo(State.state.layerUpdater.timeout);
2020-07-31 16:17:16 +02:00
this.ListenTo(State.state.layerUpdater.runningQuery);
this.ListenTo(State.state.layerUpdater.sufficientlyZoomed);
2020-06-24 00:35:19 +02:00
}
2021-06-10 01:36:20 +02:00
private static prep(): { innerHtml: string | UIElement, done: boolean } {
if (State.state.centerMessage.data != "") {
return {innerHtml: State.state.centerMessage.data, done: false};
2020-06-24 00:35:19 +02:00
}
2020-07-31 16:17:16 +02:00
const lu = State.state.layerUpdater;
if (lu.timeout.data > 0) {
return {
2021-06-10 01:36:20 +02:00
innerHtml: Translations.t.centerMessage.retrying.Subs({count: "" + lu.timeout.data}),
done: false
};
2020-07-31 16:17:16 +02:00
}
2020-07-31 16:17:16 +02:00
if (lu.runningQuery.data) {
2021-06-10 01:36:20 +02:00
return {innerHtml: Translations.t.centerMessage.loadingData, done: false};
}
if (!lu.sufficientlyZoomed.data) {
2021-06-10 01:36:20 +02:00
return {innerHtml: Translations.t.centerMessage.zoomIn, done: false};
} else {
2021-06-10 01:36:20 +02:00
return {innerHtml: Translations.t.centerMessage.ready, done: true};
2020-06-24 00:35:19 +02:00
}
}
2021-06-10 01:36:20 +02:00
InnerRender(): string | UIElement {
2020-09-25 12:44:04 +02:00
return CenterMessageBox.prep().innerHtml;
2020-06-24 00:35:19 +02:00
}
InnerUpdate(htmlElement: HTMLElement) {
2021-06-10 01:36:20 +02:00
if(htmlElement.parentElement === null){
return;
}
2020-06-24 00:35:19 +02:00
const pstyle = htmlElement.parentElement.style;
if (State.state.centerMessage.data != "") {
2020-06-24 00:35:19 +02:00
pstyle.opacity = "1";
pstyle.pointerEvents = "all";
return;
}
pstyle.pointerEvents = "none";
2020-09-25 12:44:04 +02:00
if (CenterMessageBox.prep().done) {
2020-06-24 00:35:19 +02:00
pstyle.opacity = "0";
} else {
pstyle.opacity = "0.5";
2020-06-24 00:35:19 +02:00
}
}
}