2019-07-03 00:08:06 +08:00
|
|
|
import { InputNumber } from "antd";
|
|
|
|
import { observer } from "mobx-react";
|
2019-07-03 02:56:33 +08:00
|
|
|
import React, { ReactNode, Component } from "react";
|
2019-07-03 00:08:06 +08:00
|
|
|
import { QuestNpc, QuestObject, QuestEntity } from "../../domain";
|
|
|
|
import "./EntityInfoComponent.css";
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-07-02 23:00:24 +08:00
|
|
|
export type Props = {
|
2019-07-03 00:08:06 +08:00
|
|
|
entity?: QuestEntity;
|
|
|
|
};
|
2019-05-29 00:40:29 +08:00
|
|
|
|
|
|
|
@observer
|
2019-07-03 02:56:33 +08:00
|
|
|
export class EntityInfoComponent extends Component<Props> {
|
|
|
|
render(): ReactNode {
|
2019-05-29 00:40:29 +08:00
|
|
|
const entity = this.props.entity;
|
|
|
|
|
|
|
|
if (entity) {
|
2019-06-26 23:47:53 +08:00
|
|
|
const section_id = entity.section ? entity.section.id : entity.section_id;
|
2019-05-29 00:40:29 +08:00
|
|
|
let name = null;
|
|
|
|
|
|
|
|
if (entity instanceof QuestObject) {
|
|
|
|
name = (
|
|
|
|
<tr>
|
2019-07-03 00:08:06 +08:00
|
|
|
<td>Object: </td>
|
|
|
|
<td colSpan={2}>{entity.type.name}</td>
|
2019-05-29 00:40:29 +08:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
} else if (entity instanceof QuestNpc) {
|
|
|
|
name = (
|
|
|
|
<tr>
|
2019-07-03 00:08:06 +08:00
|
|
|
<td>NPC: </td>
|
|
|
|
<td>{entity.type.name}</td>
|
2019-05-29 00:40:29 +08:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-05-29 23:59:47 +08:00
|
|
|
<div className="EntityInfoComponent-container">
|
|
|
|
<table className="EntityInfoComponent-table">
|
2019-05-29 00:40:29 +08:00
|
|
|
<tbody>
|
|
|
|
{name}
|
|
|
|
<tr>
|
2019-07-03 00:08:06 +08:00
|
|
|
<td>Section: </td>
|
|
|
|
<td>{section_id}</td>
|
2019-05-29 00:40:29 +08:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colSpan={2}>World position: </td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colSpan={2}>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
2019-07-03 00:08:06 +08:00
|
|
|
<CoordRow
|
|
|
|
entity={entity}
|
|
|
|
position_type="position"
|
|
|
|
coord="x"
|
|
|
|
/>
|
|
|
|
<CoordRow
|
|
|
|
entity={entity}
|
|
|
|
position_type="position"
|
|
|
|
coord="y"
|
|
|
|
/>
|
|
|
|
<CoordRow
|
|
|
|
entity={entity}
|
|
|
|
position_type="position"
|
|
|
|
coord="z"
|
|
|
|
/>
|
2019-05-29 00:40:29 +08:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colSpan={2}>Section position: </td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colSpan={2}>
|
|
|
|
<table>
|
|
|
|
<tbody>
|
2019-07-03 00:08:06 +08:00
|
|
|
<CoordRow
|
|
|
|
entity={entity}
|
|
|
|
position_type="section_position"
|
|
|
|
coord="x"
|
|
|
|
/>
|
|
|
|
<CoordRow
|
|
|
|
entity={entity}
|
|
|
|
position_type="section_position"
|
|
|
|
coord="y"
|
|
|
|
/>
|
|
|
|
<CoordRow
|
|
|
|
entity={entity}
|
|
|
|
position_type="section_position"
|
|
|
|
coord="z"
|
|
|
|
/>
|
2019-05-29 00:40:29 +08:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
2019-05-29 23:59:47 +08:00
|
|
|
return <div className="EntityInfoComponent-container" />;
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-01 05:20:13 +08:00
|
|
|
}
|
2019-05-29 00:40:29 +08:00
|
|
|
|
2019-06-01 05:20:13 +08:00
|
|
|
@observer
|
2019-07-03 02:56:33 +08:00
|
|
|
class CoordRow extends Component<{
|
2019-07-03 00:08:06 +08:00
|
|
|
entity: QuestEntity;
|
|
|
|
position_type: "position" | "section_position";
|
|
|
|
coord: "x" | "y" | "z";
|
2019-06-01 05:20:13 +08:00
|
|
|
}> {
|
2019-07-03 02:56:33 +08:00
|
|
|
render(): ReactNode {
|
2019-06-01 05:20:13 +08:00
|
|
|
const entity = this.props.entity;
|
2019-06-26 23:47:53 +08:00
|
|
|
const value = entity[this.props.position_type][this.props.coord];
|
2019-06-01 05:20:13 +08:00
|
|
|
return (
|
|
|
|
<tr>
|
|
|
|
<td>{this.props.coord.toUpperCase()}: </td>
|
|
|
|
<td>
|
|
|
|
<InputNumber
|
|
|
|
value={value}
|
|
|
|
size="small"
|
|
|
|
precision={3}
|
|
|
|
className="EntityInfoComponent-coord"
|
|
|
|
onChange={this.changed}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
|
|
|
|
2019-06-01 05:20:13 +08:00
|
|
|
private changed = (value?: number) => {
|
|
|
|
if (value != null) {
|
|
|
|
const entity = this.props.entity;
|
2019-06-26 23:47:53 +08:00
|
|
|
const pos_type = this.props.position_type;
|
|
|
|
const pos = entity[pos_type].clone();
|
2019-06-01 05:20:13 +08:00
|
|
|
pos[this.props.coord] = value;
|
2019-06-26 23:47:53 +08:00
|
|
|
entity[pos_type] = pos;
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|
2019-07-03 00:08:06 +08:00
|
|
|
};
|
2019-05-29 00:40:29 +08:00
|
|
|
}
|