import { Button, Dialog, Intent } from '@blueprintjs/core'; import { observer } from 'mobx-react'; import React, { ChangeEvent, KeyboardEvent } from 'react'; import { saveCurrentQuestToFile, setCurrentAreaId } from '../actions/appState'; import { loadFile } from '../actions/loadFile'; import { appStateStore } from '../stores/AppStateStore'; import './ApplicationComponent.css'; import { RendererComponent } from './RendererComponent'; import { EntityInfoComponent } from './EntityInfoComponent'; import { QuestInfoComponent } from './QuestInfoComponent'; @observer export class ApplicationComponent extends React.Component<{}, { filename?: string, saveDialogOpen: boolean, saveDialogFilename: string }> { state = { filename: undefined, saveDialogOpen: false, saveDialogFilename: 'Untitled', }; render() { const quest = appStateStore.currentQuest; const model = appStateStore.currentModel; const areas = quest ? Array.from(quest.areaVariants).map(a => a.area) : undefined; const area = appStateStore.currentArea; const areaId = area ? String(area.id) : undefined; return (
); } private onFileChange = (e: ChangeEvent) => { if (e.currentTarget.files) { const file = e.currentTarget.files[0]; if (file) { this.setState({ filename: file.name }); loadFile(file); } } } private onAreaSelectChange = (e: ChangeEvent) => { const areaId = parseInt(e.currentTarget.value, 10); setCurrentAreaId(areaId); } private onSaveAsClick = () => { let name = this.state.filename || 'Untitled'; name = name.endsWith('.qst') ? name.slice(0, -4) : name; this.setState({ saveDialogOpen: true, saveDialogFilename: name }); } private onSaveDialogNameChange = (e: ChangeEvent) => { this.setState({ saveDialogFilename: e.currentTarget.value }); } private onSaveDialogNameKeyUp = (e: KeyboardEvent) => { if (e.key === 'Enter') { this.onSaveDialogSaveClick(); } } private onSaveDialogSaveClick = () => { saveCurrentQuestToFile(this.state.saveDialogFilename); this.setState({ saveDialogOpen: false }); } private onSaveDialogClose = () => { this.setState({ saveDialogOpen: false }); } }