import { Button, Form, Icon, Input, Modal, Select, Upload } from "antd"; import { UploadChangeParam } from "antd/lib/upload"; import { UploadFile } from "antd/lib/upload/interface"; import { observer } from "mobx-react"; import React, { ChangeEvent, ReactNode, Component } from "react"; import { quest_editor_store } from "../../stores/QuestEditorStore"; import { EntityInfoComponent } from "./EntityInfoComponent"; import "./QuestEditorComponent.css"; import { QuestInfoComponent } from "./QuestInfoComponent"; import { RendererComponent } from "../RendererComponent"; import { get_quest_renderer } from "../../rendering/QuestRenderer"; @observer export class QuestEditorComponent extends Component< {}, { filename?: string; save_dialog_open: boolean; save_dialog_filename: string; } > { state = { save_dialog_open: false, save_dialog_filename: "Untitled", }; render(): ReactNode { const quest = quest_editor_store.current_quest; return (
); } private save_as_clicked = (filename?: string) => { const name = filename ? filename.endsWith(".qst") ? filename.slice(0, -4) : filename : this.state.save_dialog_filename; this.setState({ save_dialog_open: true, save_dialog_filename: name, }); }; private save_dialog_filename_changed = (filename: string) => { this.setState({ save_dialog_filename: filename }); }; private save_dialog_affirmed = () => { quest_editor_store.save_current_quest_to_file(this.state.save_dialog_filename); this.setState({ save_dialog_open: false }); }; private save_dialog_cancelled = () => { this.setState({ save_dialog_open: false }); }; } @observer class Toolbar extends Component<{ onSaveAsClicked: (filename?: string) => void }> { state = { filename: undefined, }; render(): ReactNode { const quest = quest_editor_store.current_quest; const areas = quest && Array.from(quest.area_variants).map(a => a.area); const area = quest_editor_store.current_area; const area_id = area && area.id; return (
false} > {areas && ( )} {quest && ( )}
); } private set_filename = (info: UploadChangeParam) => { if (info.file.originFileObj) { this.setState({ filename: info.file.name }); quest_editor_store.load_file(info.file.originFileObj as File); } }; private save_as_clicked = () => { this.props.onSaveAsClicked(this.state.filename); }; } class SaveAsForm extends React.Component<{ is_open: boolean; filename: string; on_filename_change: (name: string) => void; on_ok: () => void; on_cancel: () => void; }> { render(): ReactNode { return ( Save as... } visible={this.props.is_open} onOk={this.props.on_ok} onCancel={this.props.on_cancel} >
); } private name_changed = (e: ChangeEvent) => { this.props.on_filename_change(e.currentTarget.value); }; }