| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { Col, Form, Input, Row, Checkbox, Slider, Select, Drawer, Space, Button, InputNumber, Switch } from 'antd'; |
| | | import { Col, Form, Input, Row, Checkbox, Slider, Select, Drawer, Space, Button, InputNumber, Card } from 'antd'; |
| | | import { FormattedMessage, useIntl, useModel } from '@umijs/max'; |
| | | import { createStyles } from 'antd-style'; |
| | | import './index.css'; |
| | |
| | | const useStyles = createStyles(({ token, css }) => { |
| | | |
| | | }) |
| | | |
| | | const Settings = (props) => { |
| | | const intl = useIntl(); |
| | | const { styles } = useStyles(); |
| | | const [activeTabKey, setActiveTabKey] = useState('map'); |
| | | |
| | | const contentList = { |
| | | map: ( |
| | | <SpriteSettings |
| | | refCurr={props.refCurr} |
| | | curSprite={props.curSprite} |
| | | setSpriteBySettings={props.setSpriteBySettings} |
| | | setDidClickSprite={props.setDidClickSprite} |
| | | onSubmit={props.onSubmit} |
| | | /> |
| | | ), |
| | | config: ( |
| | | <h1>Hello</h1> |
| | | ), |
| | | }; |
| | | |
| | | const handleCancel = () => { |
| | | props.onCancel(); |
| | | }; |
| | | |
| | | const handleOk = () => { |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | <Drawer |
| | | open={props.open} |
| | | onClose={handleCancel} |
| | | getContainer={props.refCurr} |
| | | rootStyle={{ position: "absolute" }} |
| | | mask={false} |
| | | width={570} |
| | | extra={ |
| | | <Space> |
| | | <Button onClick={handleCancel}> |
| | | <FormattedMessage id='common.cancel' defaultMessage='取消' /> |
| | | </Button> |
| | | <Button onClick={handleOk} type="primary"> |
| | | <FormattedMessage id='common.submit' defaultMessage='保存' /> |
| | | </Button> |
| | | </Space> |
| | | } |
| | | > |
| | | <Card |
| | | hoverable |
| | | bordered={false} |
| | | tabList={[ |
| | | { |
| | | key: 'map', |
| | | tab: '地图参数', |
| | | }, |
| | | { |
| | | key: 'config', |
| | | tab: '配置参数', |
| | | }, |
| | | ]} |
| | | activeTabKey={activeTabKey} |
| | | onTabChange={(key) => { |
| | | setActiveTabKey(key) |
| | | }} |
| | | tabProps={{ |
| | | centered: true, |
| | | size: 'large', |
| | | type: "card", |
| | | style: { |
| | | } |
| | | }} |
| | | > |
| | | {contentList[activeTabKey]} |
| | | </Card> |
| | | |
| | | </Drawer > |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | const SpriteSettings = (props) => { |
| | | const intl = useIntl(); |
| | |
| | | } |
| | | }, [form, props]) |
| | | |
| | | const handleCancel = () => { |
| | | props.onCancel(); |
| | | }; |
| | | |
| | | const handleOk = () => { |
| | | form.submit(); |
| | | } |
| | |
| | | curSprite.position.x = value; |
| | | break; |
| | | case 'y': |
| | | curSprite.position.x = value; |
| | | curSprite.position.y = value; |
| | | break; |
| | | case 'scaleSlider': |
| | | form.setFieldsValue({ |
| | |
| | | |
| | | return ( |
| | | <> |
| | | <Drawer |
| | | open={props.open} |
| | | onClose={handleCancel} |
| | | getContainer={props.refCurr} |
| | | rootStyle={{ position: "absolute" }} |
| | | mask={false} |
| | | width={570} |
| | | extra={ |
| | | <Space> |
| | | <Button onClick={handleCancel}> |
| | | <FormattedMessage id='common.cancel' defaultMessage='取消' /> |
| | | </Button> |
| | | <Button onClick={handleOk} type="primary"> |
| | | <FormattedMessage id='common.submit' defaultMessage='保存' /> |
| | | </Button> |
| | | </Space> |
| | | } |
| | | <Form |
| | | form={form} |
| | | onFieldsChange={formValuesChange} |
| | | initialValues={{ |
| | | }} |
| | | onFinish={handleFinish} |
| | | onFinishFailed={onFinishFailed} |
| | | autoComplete="off" |
| | | style={{ |
| | | maxWidth: 600, |
| | | }} |
| | | size='default' // small | default | large |
| | | variant='filled' // outlined | borderless | filled |
| | | labelWrap // label 换行 |
| | | disabled={false} |
| | | layout='horizontal' |
| | | > |
| | | <Form |
| | | form={form} |
| | | onFieldsChange={formValuesChange} |
| | | initialValues={{ |
| | | }} |
| | | onFinish={handleFinish} |
| | | onFinishFailed={onFinishFailed} |
| | | autoComplete="off" |
| | | style={{ |
| | | maxWidth: 600, |
| | | }} |
| | | size='default' // small | default | large |
| | | variant='filled' // outlined | borderless | filled |
| | | labelWrap // label 换行 |
| | | disabled={false} |
| | | layout='horizontal' |
| | | > |
| | | <Row gutter={[24, 16]}> |
| | | <Row gutter={[24, 16]}> |
| | | |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.type', defaultMessage: '类型' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <span>{curSprite?.data?.type}</span> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.type', defaultMessage: '类型' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <span>{curSprite?.data?.type}</span> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* position */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.position', defaultMessage: '坐标' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Space.Compact> |
| | | <Form.Item |
| | | name='x' |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | > |
| | | <InputNumber |
| | | addonBefore={<Space.Compact>x</Space.Compact>} |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | <Form.Item |
| | | name='y' |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | > |
| | | <InputNumber |
| | | addonBefore={<Space.Compact>y</Space.Compact>} |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Space.Compact> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* scale */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.scale', defaultMessage: '缩放' })} |
| | | name="scaleSlider" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Slider |
| | | min={0.1} |
| | | max={10} |
| | | step={0.1} |
| | | marks={{ |
| | | 0.1: '0.1', |
| | | 1: '1', |
| | | 10: '10', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item |
| | | name="scale" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <InputNumber |
| | | changeOnWheel |
| | | min={0.1} max={10} defaultValue={1} step={0.1} |
| | | {/* position */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.position', defaultMessage: '坐标' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Space.Compact> |
| | | <Form.Item |
| | | name='x' |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* rotation */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.rotation', defaultMessage: '角度' })} |
| | | name="rotationSlider" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Slider |
| | | min={0} |
| | | max={360} |
| | | step={1} |
| | | marks={{ |
| | | 0: '0°', |
| | | 90: '90°', |
| | | 180: '180°', |
| | | 270: '270°', |
| | | 360: '360°', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item |
| | | name="rotation" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <InputNumber |
| | | changeOnWheel |
| | | min={0} max={360} defaultValue={0} |
| | | > |
| | | <InputNumber |
| | | addonBefore={<Space.Compact>x</Space.Compact>} |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | <Form.Item |
| | | name='y' |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | > |
| | | <InputNumber |
| | | addonBefore={<Space.Compact>y</Space.Compact>} |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Space.Compact> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* copy */} |
| | | <Col span={24}> |
| | | <Row gutter={0}> |
| | | <Col span={20}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.copy', defaultMessage: '复制' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Space.Compact> |
| | | <Form.Item |
| | | noStyle |
| | | name="copyDire" |
| | | > |
| | | <Select |
| | | style={{ width: 100 }} |
| | | options={[ |
| | | { value: 'left', label: intl.formatMessage({ id: 'map.settings.left', defaultMessage: '左' }) }, |
| | | { value: 'right', label: intl.formatMessage({ id: 'map.settings.right', defaultMessage: '右' }) }, |
| | | { value: 'top', label: intl.formatMessage({ id: 'map.settings.top', defaultMessage: '上' }) }, |
| | | { value: 'bottom', label: intl.formatMessage({ id: 'map.settings.bottom', defaultMessage: '下' }) }, |
| | | ]} |
| | | /> |
| | | </Form.Item> |
| | | <Form.Item |
| | | name='copyCount' |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | {/* scale */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.scale', defaultMessage: '缩放' })} |
| | | name="scaleSlider" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Slider |
| | | min={0.1} |
| | | max={10} |
| | | step={0.1} |
| | | marks={{ |
| | | 0.1: '0.1', |
| | | 1: '1', |
| | | 10: '10', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item |
| | | name="scale" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <InputNumber |
| | | changeOnWheel |
| | | min={0.1} max={10} defaultValue={1} step={0.1} |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* rotation */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.rotation', defaultMessage: '角度' })} |
| | | name="rotationSlider" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Slider |
| | | min={0} |
| | | max={360} |
| | | step={1} |
| | | marks={{ |
| | | 0: '0°', |
| | | 90: '90°', |
| | | 180: '180°', |
| | | 270: '270°', |
| | | 360: '360°', |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | <Col span={6}> |
| | | <Form.Item |
| | | name="rotation" |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <InputNumber |
| | | changeOnWheel |
| | | min={0} max={360} defaultValue={0} |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | /> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* copy */} |
| | | <Col span={24}> |
| | | <Row gutter={0}> |
| | | <Col span={20}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.copy', defaultMessage: '复制' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Space.Compact> |
| | | <Form.Item |
| | | noStyle |
| | | name="copyDire" |
| | | > |
| | | <Select |
| | | style={{ width: 100 }} |
| | | options={[ |
| | | { value: 'left', label: intl.formatMessage({ id: 'map.settings.left', defaultMessage: '左' }) }, |
| | | { value: 'right', label: intl.formatMessage({ id: 'map.settings.right', defaultMessage: '右' }) }, |
| | | { value: 'top', label: intl.formatMessage({ id: 'map.settings.top', defaultMessage: '上' }) }, |
| | | { value: 'bottom', label: intl.formatMessage({ id: 'map.settings.bottom', defaultMessage: '下' }) }, |
| | | ]} |
| | | /> |
| | | </Form.Item> |
| | | <Form.Item |
| | | name='copyCount' |
| | | noStyle |
| | | rules={[ |
| | | { |
| | | required: true, |
| | | }, |
| | | ]} |
| | | > |
| | | <InputNumber |
| | | addonBefore={<Space.Compact></Space.Compact>} |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | min={1} |
| | | step={1} |
| | | /> |
| | | </Form.Item> |
| | | <Form.Item> |
| | | <Button |
| | | onClick={() => { |
| | | setChildrenDrawer(true); |
| | | }} |
| | | > |
| | | <InputNumber |
| | | addonBefore={<Space.Compact></Space.Compact>} |
| | | style={{ |
| | | width: '50%', |
| | | }} |
| | | min={1} |
| | | step={1} |
| | | /> |
| | | </Form.Item> |
| | | <Form.Item> |
| | | <Button |
| | | onClick={() => { |
| | | setChildrenDrawer(true); |
| | | }} |
| | | > |
| | | <FormattedMessage id='common.execute' defaultMessage='执行' /> |
| | | </Button> |
| | | <SubSpriteSettings |
| | | open={childrenDrawer} |
| | | refCurr={props.refCurr} |
| | | curSprite={props.curSprite} |
| | | values={form.getFieldsValue()} |
| | | submit={handleOnCopy} |
| | | onClose={() => { |
| | | setChildrenDrawer(false) |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | <FormattedMessage id='common.execute' defaultMessage='执行' /> |
| | | </Button> |
| | | <SubSpriteSettings |
| | | open={childrenDrawer} |
| | | refCurr={props.refCurr} |
| | | curSprite={props.curSprite} |
| | | values={form.getFieldsValue()} |
| | | submit={handleOnCopy} |
| | | onClose={() => { |
| | | setChildrenDrawer(false) |
| | | }} |
| | | /> |
| | | </Form.Item> |
| | | |
| | | </Space.Compact> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | <Row gutter={0}> |
| | | <Col offset={16} span={8}> |
| | | <Form.Item> |
| | | <Button |
| | | type="dashed" |
| | | onClick={() => { |
| | | if (lastCopiedSprites) { |
| | | lastCopiedSprites.forEach(copiedSprite => { |
| | | Utils.getMapContainer().removeChild(copiedSprite); |
| | | }) |
| | | setLastCopiedSprites([]); |
| | | } |
| | | }} |
| | | > |
| | | <FormattedMessage id='map.settings.sub.copy.undo.last.copies' defaultMessage='撤回复制' /> |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | {/* more */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.more', defaultMessage: '更多' })} |
| | | labelCol={{ span: 4 }} |
| | | </Space.Compact> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | <Row gutter={0}> |
| | | <Col offset={16} span={8}> |
| | | <Form.Item> |
| | | <Button |
| | | type="dashed" |
| | | onClick={() => { |
| | | if (lastCopiedSprites) { |
| | | lastCopiedSprites.forEach(copiedSprite => { |
| | | Utils.getMapContainer().removeChild(copiedSprite); |
| | | }) |
| | | setLastCopiedSprites([]); |
| | | } |
| | | }} |
| | | > |
| | | <Button |
| | | type="dashed" |
| | | danger |
| | | onClick={() => { |
| | | Utils.getMapContainer().removeChild(curSprite); |
| | | props.setSpriteBySettings(null); |
| | | Utils.removeSelectedEffect(); |
| | | form.resetFields(); |
| | | }} |
| | | > |
| | | <FormattedMessage id='map.settings.delete' defaultMessage='删除' /> |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | <FormattedMessage id='map.settings.sub.copy.undo.last.copies' defaultMessage='撤回复制' /> |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | </Row> |
| | | </Form> |
| | | </Drawer > |
| | | {/* more */} |
| | | <Col span={24}> |
| | | <Row gutter={24}> |
| | | <Col span={18}> |
| | | <Form.Item |
| | | label={intl.formatMessage({ id: 'map.settings.more', defaultMessage: '更多' })} |
| | | labelCol={{ span: 4 }} |
| | | > |
| | | <Button |
| | | type="dashed" |
| | | danger |
| | | onClick={() => { |
| | | Utils.getMapContainer().removeChild(curSprite); |
| | | props.setSpriteBySettings(null); |
| | | Utils.removeSelectedEffect(); |
| | | form.resetFields(); |
| | | }} |
| | | > |
| | | <FormattedMessage id='map.settings.delete' defaultMessage='删除' /> |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | </Row> |
| | | </Col> |
| | | |
| | | </Row> |
| | | </Form> |
| | | </> |
| | | ) |
| | | } |
| | | |
| | | export default SpriteSettings; |
| | | export default Settings; |