phantasmal-world/src/application/gui/MainContentView.ts

53 lines
1.6 KiB
TypeScript
Raw Normal View History

import { create_element } from "../../core/gui/dom";
2019-08-20 04:56:40 +08:00
import { gui_store, GuiTool } from "../../core/stores/GuiStore";
import { LazyView } from "../../core/gui/LazyView";
import { ResizableView } from "../../core/gui/ResizableView";
const TOOLS: [GuiTool, () => Promise<ResizableView>][] = [
2019-08-20 04:56:40 +08:00
[GuiTool.Viewer, async () => new (await import("../../viewer/gui/ViewerView")).ViewerView()],
[
GuiTool.QuestEditor,
async () => new (await import("../../quest_editor/gui/QuestEditorView")).QuestEditorView(),
],
2019-08-20 04:56:40 +08:00
];
export class MainContentView extends ResizableView {
element = create_element("div", { class: "application_MainContentView" });
2019-08-20 04:56:40 +08:00
private tool_views = new Map(
TOOLS.map(([tool, create_view]) => [tool, this.disposable(new LazyView(create_view))]),
);
constructor() {
super();
for (const tool_view of this.tool_views.values()) {
this.element.append(tool_view.element);
}
const tool_view = this.tool_views.get(gui_store.tool.val);
if (tool_view) tool_view.visible.val = true;
2019-08-20 21:02:58 +08:00
this.disposable(gui_store.tool.observe(this.tool_changed));
2019-08-20 04:56:40 +08:00
}
resize(width: number, height: number): this {
super.resize(width, height);
for (const tool_view of this.tool_views.values()) {
tool_view.resize(width, height);
}
return this;
}
private tool_changed = (new_tool: GuiTool) => {
for (const tool of this.tool_views.values()) {
tool.visible.val = false;
}
2019-08-20 04:56:40 +08:00
const new_view = this.tool_views.get(new_tool);
if (new_view) new_view.visible.val = true;
2019-08-20 04:56:40 +08:00
};
}