2020-08-31 02:59:47 +02:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import {TabbedComponent} from "../Base/TabbedComponent";
|
|
|
|
import {SubtleButton} from "../Base/SubtleButton";
|
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
|
|
|
import {LayoutConfigJson} from "../../Customizations/JSON/LayoutConfigJson";
|
2020-09-02 11:37:34 +02:00
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import {GenerateEmpty} from "./GenerateEmpty";
|
2020-09-03 00:00:37 +02:00
|
|
|
import LayerPanelWithPreview from "./LayerPanelWithPreview";
|
2020-08-31 02:59:47 +02:00
|
|
|
|
|
|
|
export default class AllLayersPanel extends UIElement {
|
|
|
|
|
|
|
|
|
|
|
|
private panel: UIElement;
|
2020-09-02 11:37:34 +02:00
|
|
|
private readonly _config: UIEventSource<LayoutConfigJson>;
|
|
|
|
private readonly languages: UIEventSource<string[]>;
|
2020-08-31 02:59:47 +02:00
|
|
|
|
2020-09-02 11:37:34 +02:00
|
|
|
constructor(config: UIEventSource<LayoutConfigJson>,
|
2020-08-31 02:59:47 +02:00
|
|
|
languages: UIEventSource<any>) {
|
|
|
|
super(undefined);
|
|
|
|
this._config = config;
|
|
|
|
this.languages = languages;
|
|
|
|
|
|
|
|
this.createPanels();
|
|
|
|
const self = this;
|
|
|
|
config.map<number>(config => config.layers.length).addCallback(() => self.createPanels());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private createPanels() {
|
|
|
|
const self = this;
|
|
|
|
const tabs = [];
|
|
|
|
|
|
|
|
const layers = this._config.data.layers;
|
|
|
|
for (let i = 0; i < layers.length; i++) {
|
2020-09-03 00:00:37 +02:00
|
|
|
|
2020-08-31 02:59:47 +02:00
|
|
|
tabs.push({
|
|
|
|
header: "<img src='./assets/bug.svg'>",
|
2020-09-03 00:00:37 +02:00
|
|
|
content: new LayerPanelWithPreview(this._config, this.languages, i)});
|
2020-08-31 02:59:47 +02:00
|
|
|
}
|
|
|
|
tabs.push({
|
2020-09-03 00:00:37 +02:00
|
|
|
header: "<img src='./assets/layersAdd.svg'>",
|
2020-09-02 11:37:34 +02:00
|
|
|
content: new Combine([
|
|
|
|
"<h2>Layer editor</h2>",
|
|
|
|
"In this tab page, you can add and edit the layers of the theme. Click the layers above or add a new layer to get started.",
|
|
|
|
new SubtleButton(
|
|
|
|
"./assets/add.svg",
|
|
|
|
"Add a new layer"
|
|
|
|
).onClick(() => {
|
|
|
|
self._config.data.layers.push(GenerateEmpty.createEmptyLayer())
|
|
|
|
self._config.ping();
|
|
|
|
})])
|
2020-08-31 02:59:47 +02:00
|
|
|
})
|
2020-09-02 11:37:34 +02:00
|
|
|
|
|
|
|
this.panel = new TabbedComponent(tabs, new UIEventSource<number>(Math.max(0, layers.length - 1)));
|
2020-08-31 02:59:47 +02:00
|
|
|
this.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
return this.panel.Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|