mapcomplete/UI/DefaultGUI.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-12-16 13:44:25 +01:00
import { Utils } from "../Utils"
import Toggle from "./Input/Toggle"
import LeftControls from "./BigComponents/LeftControls"
import RightControls from "./BigComponents/RightControls"
import CenterMessageBox from "./CenterMessageBox"
2021-10-15 14:52:11 +02:00
import ScrollableFullScreen from "./Base/ScrollableFullScreen"
import Translations from "./i18n/Translations"
2022-12-16 13:44:25 +01:00
import { DefaultGuiState } from "./DefaultGuiState"
import Combine from "./Base/Combine"
import ExtraLinkButton from "./BigComponents/ExtraLinkButton"
import GeoLocationHandler from "../Logic/Actors/GeoLocationHandler"
import CopyrightPanel from "./BigComponents/CopyrightPanel"
/**
2022-12-08 02:56:49 +01:00
* The default MapComplete GUI initializer
*
2022-12-08 02:56:49 +01:00
* Adds a welcome pane, control buttons, ... etc to index.html
*/
export default class DefaultGUI {
2022-04-08 17:59:14 +02:00
private readonly guiState: DefaultGuiState
private readonly geolocationHandler: GeoLocationHandler | undefined
constructor(guiState: DefaultGuiState) {
2022-04-08 17:59:14 +02:00
this.guiState = guiState
}
public setup() {
this.SetupUIElements()
2022-01-14 02:40:55 +01:00
2022-04-08 17:59:14 +02:00
if (
this.state.layoutToUse.customCss !== undefined &&
window.location.pathname.indexOf("index") >= 0
) {
Utils.LoadCustomCss(this.state.layoutToUse.customCss)
}
}
2021-11-07 16:34:51 +01:00
private SetupUIElements() {
const extraLink = Toggle.If(
state.featureSwitchExtraLinkEnabled,
() => new ExtraLinkButton(state, state.layoutToUse.extraLink)
)
new Combine([extraLink]).SetClass("flex flex-col").AttachTo("top-left")
2022-03-10 23:18:40 +01:00
new Combine([
2022-03-10 23:59:18 +01:00
new ExtraLinkButton(state, {
...state.layoutToUse.extraLink,
newTab: true,
requirements: new Set<
"iframe" | "no-iframe" | "welcome-message" | "no-welcome-message"
>(),
}),
2022-03-10 23:18:40 +01:00
])
.SetClass("flex items-center justify-center normal-background h-full")
.AttachTo("on-small-screen")
const guiState = this.guiState
new LeftControls(state, guiState).AttachTo("bottom-left")
new RightControls(state, this.geolocationHandler).AttachTo("bottom-right")
new CenterMessageBox(state).AttachTo("centermessage")
document?.getElementById("centermessage")?.classList?.add("pointer-events-none")
}
}