File size: 6,891 Bytes
6bcb42f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Popover from 'react-popover';
import {injectIntl, intlShape, defineMessages, FormattedMessage} from 'react-intl';

import Label from '../forms/label.jsx';
import Input from '../forms/input.jsx';
import BufferedInputHOC from '../forms/buffered-input-hoc.jsx';
import Dial from './dial.jsx';

import styles from './direction-picker.css';

import allAroundIcon from './icon--all-around.svg';
import leftRightIcon from './icon--left-right.svg';
import upDownIcon from './icon--up-down.svg';
import dontRotateIcon from './icon--dont-rotate.svg';
import lookAtIcon from './icon--look-at.svg';

const BufferedInput = BufferedInputHOC(Input);

const directionLabel = (
    <FormattedMessage
        defaultMessage="Direction"
        description="Sprite info direction label"
        id="gui.SpriteInfo.direction"
    />
);

const RotationStyles = {
    ALL_AROUND: 'all around',
    LOOK_AT: 'look at',
    LEFT_RIGHT: 'left-right',
    UP_DOWN: 'up-down',
    DONT_ROTATE: "don't rotate",
};

const messages = defineMessages({
    allAround: {
        id: 'gui.directionPicker.rotationStyles.allAround',
        description: 'Button to change to the all around rotation style',
        defaultMessage: 'All Around'
    },
    lookAt: {
        id: 'gui.directionPicker.rotationStyles.lookAt',
        description: 'Button to change to the look at rotation style',
        defaultMessage: 'Look At'
    },
    leftRight: {
        id: 'gui.directionPicker.rotationStyles.leftRight',
        description: 'Button to change to the left-right rotation style',
        defaultMessage: 'Left/Right'
    },
    upDown: {
        id: 'gui.directionPicker.rotationStyles.upDown',
        description: 'Button to change to the up-down rotation style',
        defaultMessage: 'Up/Down'
    },
    dontRotate: {
        id: 'gui.directionPicker.rotationStyles.dontRotate',
        description: 'Button to change to the dont rotate rotation style',
        defaultMessage: 'Do not rotate'
    }
});

const DirectionPicker = props => (
    <Label
        secondary
        above={props.labelAbove}
        text={directionLabel}
    >
        <Popover
            body={
                <div>
                    <Dial
                        direction={props.direction}
                        onChange={props.onChangeDirection}
                    />
                    <div className={styles.buttonRow}>
                        <button
                            className={classNames(styles.iconButton, {
                                [styles.active]: props.rotationStyle === RotationStyles.ALL_AROUND
                            })}
                            title={props.intl.formatMessage(messages.allAround)}
                            onClick={props.onClickAllAround}
                        >
                            <img
                                draggable={false}
                                src={allAroundIcon}
                            />
                        </button>
                        <button
                            className={classNames(styles.iconButton, {
                                [styles.active]: props.rotationStyle === RotationStyles.LOOK_AT
                            })}
                            title={props.intl.formatMessage(messages.lookAt)}
                            onClick={props.onClickLookAt}
                        >
                            <img
                                draggable={false}
                                src={lookAtIcon}
                            />
                        </button>
                        <button
                            className={classNames(styles.iconButton, {
                                [styles.active]: props.rotationStyle === RotationStyles.LEFT_RIGHT
                            })}
                            title={props.intl.formatMessage(messages.leftRight)}
                            onClick={props.onClickLeftRight}
                        >
                            <img
                                draggable={false}
                                src={leftRightIcon}
                            />
                        </button>
                        <button
                            className={classNames(styles.iconButton, {
                                [styles.active]: props.rotationStyle === RotationStyles.UP_DOWN
                            })}
                            title={props.intl.formatMessage(messages.upDown)}
                            onClick={props.onClickUpDown}
                        >
                            <img
                                draggable={false}
                                src={upDownIcon}
                            />
                        </button>
                        <button
                            className={classNames(styles.iconButton, {
                                [styles.active]: props.rotationStyle === RotationStyles.DONT_ROTATE
                            })}
                            title={props.intl.formatMessage(messages.dontRotate)}
                            onClick={props.onClickDontRotate}
                        >
                            <img
                                draggable={false}
                                src={dontRotateIcon}
                            />
                        </button>
                    </div>
                </div>
            }
            isOpen={props.popoverOpen}
            preferPlace="above"
            onOuterAction={props.onClosePopover}
        >
            <BufferedInput
                small
                disabled={props.disabled}
                label={directionLabel}
                tabIndex="0"
                type="text"
                value={props.disabled ? '' : props.direction}
                onFocus={props.onOpenPopover}
                onSubmit={props.onChangeDirection}
            />
        </Popover>
    </Label>

);

DirectionPicker.propTypes = {
    direction: PropTypes.number,
    disabled: PropTypes.bool.isRequired,
    intl: intlShape,
    labelAbove: PropTypes.bool,
    onChangeDirection: PropTypes.func.isRequired,
    onClickAllAround: PropTypes.func.isRequired,
    onClickDontRotate: PropTypes.func.isRequired,
    onClickLeftRight: PropTypes.func.isRequired,
    onClickLookAt: PropTypes.func.isRequired,
    onClickUpDown: PropTypes.func.isRequired,
    onClosePopover: PropTypes.func.isRequired,
    onOpenPopover: PropTypes.func.isRequired,
    popoverOpen: PropTypes.bool.isRequired,
    rotationStyle: PropTypes.string
};

DirectionPicker.defaultProps = {
    labelAbove: false
};

const WrappedDirectionPicker = injectIntl(DirectionPicker);

export {
    WrappedDirectionPicker as default,
    RotationStyles
};