Made quest ID, name, short description and long description undoable.

This commit is contained in:
Daan Vanden Bosch 2019-08-14 17:37:06 +02:00
parent cd2849cae4
commit 791968dd4e
7 changed files with 192 additions and 22 deletions

View File

@ -0,0 +1,24 @@
import * as React from "react";
import { Component, ReactNode, FocusEvent } from "react";
import { InputNumber } from "antd";
export class NumberInput extends Component<{
value: number;
min?: number;
max?: number;
on_change?: (new_value?: number) => void;
on_blur?: (e: FocusEvent<HTMLInputElement>) => void;
}> {
render(): ReactNode {
return (
<InputNumber
value={this.props.value}
min={this.props.min}
max={this.props.max}
onChange={this.props.on_change}
onBlur={this.props.on_blur}
size="small"
/>
);
}
}

23
src/core/ui/TextArea.tsx Normal file
View File

@ -0,0 +1,23 @@
import * as React from "react";
import { ChangeEvent, Component, FocusEvent, ReactNode } from "react";
import { Input } from "antd";
export class TextArea extends Component<{
value: string;
max_length: number;
rows: number;
on_change?: (e: ChangeEvent<HTMLTextAreaElement>) => void;
on_blur?: (e: FocusEvent<HTMLTextAreaElement>) => void;
}> {
render(): ReactNode {
return (
<Input.TextArea
value={this.props.value}
maxLength={this.props.max_length}
rows={this.props.rows}
onChange={this.props.on_change}
onBlur={this.props.on_blur}
/>
);
}
}

22
src/core/ui/TextInput.tsx Normal file
View File

@ -0,0 +1,22 @@
import * as React from "react";
import { ChangeEvent, Component, FocusEvent, ReactNode } from "react";
import { Input } from "antd";
export class TextInput extends Component<{
value: string;
max_length: number;
on_change: (e: ChangeEvent<HTMLInputElement>) => void;
on_blur?: (e: FocusEvent<HTMLInputElement>) => void;
}> {
render(): ReactNode {
return (
<Input
value={this.props.value}
maxLength={this.props.max_length}
onChange={this.props.on_change}
onBlur={this.props.on_blur}
size="small"
/>
);
}
}

View File

@ -14,6 +14,23 @@ Logger.useDefaults({
defaultLevel: (Logger as any)[process.env["LOG_LEVEL"] || "OFF"],
});
// Disable native undo/redo.
document.addEventListener("keydown", e => {
const kbe = e as KeyboardEvent;
if (kbe.ctrlKey && !kbe.altKey && kbe.key.toUpperCase() === "Z") {
kbe.preventDefault();
}
});
// This doesn't work in FireFox:
document.addEventListener("beforeinput", e => {
const ie = e as any;
if (ie.inputType === "historyUndo" || ie.inputType === "historyRedo") {
e.preventDefault();
}
});
const root_element = document.createElement("div");
root_element.id = styles.phantasmal_world_root;
document.body.append(root_element);

View File

@ -275,7 +275,7 @@ export class QuestEntityControls {
quest_editor_store.push_entity_move_action(
entity,
this.pick.initial_position,
entity.position,
entity.world_position,
);
}

View File

@ -220,16 +220,94 @@ class QuestEditorStore {
this.save_dialog_open = false;
};
@action
push_id_edit_action = (old_id: number, new_id: number) => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_id(new_id);
this.undo.push_action(
`Edit ID`,
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_id(old_id);
},
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_id(new_id);
},
);
};
@action
push_name_edit_action = (old_name: string, new_name: string) => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_name(new_name);
this.undo.push_action(
`Edit name`,
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_name(old_name);
},
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_name(new_name);
},
);
};
@action
push_short_description_edit_action = (
old_short_description: string,
new_short_description: string,
) => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_short_description(new_short_description);
this.undo.push_action(
`Edit short description`,
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_short_description(old_short_description);
},
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_short_description(new_short_description);
},
);
};
@action
push_long_description_edit_action = (
old_long_description: string,
new_long_description: string,
) => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_long_description(new_long_description);
this.undo.push_action(
`Edit long description`,
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_long_description(old_long_description);
},
() => {
const quest = quest_editor_store.current_quest;
if (quest) quest.set_long_description(new_long_description);
},
);
};
@action
push_entity_move_action = (
entity: ObservableQuestEntity,
initial_position: Vec3,
old_position: Vec3,
new_position: Vec3,
) => {
this.undo.push_action(
`Move ${entity_data(entity.type).name}`,
() => {
entity.world_position = initial_position;
entity.world_position = old_position;
quest_editor_store.set_selected_entity(entity);
},
() => {

View File

@ -1,10 +1,12 @@
import { Input, InputNumber } from "antd";
import { observer } from "mobx-react";
import React, { ChangeEvent, Component, ReactNode } from "react";
import { quest_editor_store } from "../stores/QuestEditorStore";
import { DisabledTextComponent } from "../../core/ui/DisabledTextComponent";
import styles from "./QuestInfoComponent.css";
import { Episode } from "../../core/data_formats/parsing/quest/Episode";
import { NumberInput } from "../../core/ui/NumberInput";
import { TextInput } from "../../core/ui/TextInput";
import { TextArea } from "../../core/ui/TextArea";
@observer
export class QuestInfoComponent extends Component {
@ -26,23 +28,21 @@ export class QuestInfoComponent extends Component {
<tr>
<th>ID:</th>
<td>
<InputNumber
<NumberInput
value={quest.id}
max={4294967295}
min={0}
onChange={this.id_changed}
size="small"
max={4294967295}
on_change={this.id_changed}
/>
</td>
</tr>
<tr>
<th>Name:</th>
<td>
<Input
<TextInput
value={quest.name}
maxLength={32}
onChange={this.name_changed}
size="small"
max_length={32}
on_change={this.name_changed}
/>
</td>
</tr>
@ -51,11 +51,11 @@ export class QuestInfoComponent extends Component {
</tr>
<tr>
<td colSpan={2}>
<Input.TextArea
<TextArea
value={quest.short_description}
maxLength={128}
max_length={128}
rows={3}
onChange={this.short_description_changed}
on_change={this.short_description_changed}
/>
</td>
</tr>
@ -64,11 +64,11 @@ export class QuestInfoComponent extends Component {
</tr>
<tr>
<td colSpan={2}>
<Input.TextArea
<TextArea
value={quest.long_description}
maxLength={288}
max_length={288}
rows={5}
onChange={this.long_description_changed}
on_change={this.long_description_changed}
/>
</td>
</tr>
@ -90,7 +90,7 @@ export class QuestInfoComponent extends Component {
const quest = quest_editor_store.current_quest;
if (quest && value != undefined) {
quest.set_id(value);
quest_editor_store.push_id_edit_action(quest.id, value);
}
}
@ -98,7 +98,7 @@ export class QuestInfoComponent extends Component {
const quest = quest_editor_store.current_quest;
if (quest) {
quest.set_name(e.target.value);
quest_editor_store.push_name_edit_action(quest.name, e.currentTarget.value);
}
}
@ -106,7 +106,10 @@ export class QuestInfoComponent extends Component {
const quest = quest_editor_store.current_quest;
if (quest) {
quest.set_short_description(e.target.value);
quest_editor_store.push_short_description_edit_action(
quest.short_description,
e.currentTarget.value,
);
}
}
@ -114,7 +117,10 @@ export class QuestInfoComponent extends Component {
const quest = quest_editor_store.current_quest;
if (quest) {
quest.set_long_description(e.target.value);
quest_editor_store.push_long_description_edit_action(
quest.long_description,
e.currentTarget.value,
);
}
}
}