Skip to content

Commit f647583

Browse files
committed
rotate UI complete
1 parent bc0e24a commit f647583

File tree

5 files changed

+82
-47
lines changed

5 files changed

+82
-47
lines changed

app/components/mappings/rotate.js

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from 'react';
1+
import React, { useEffect, useRef } from 'react';
22
import { environment } from '#store/environment';
33
import { observer } from 'mobx-react';
44
import { exportSprite } from '#formats/image';
@@ -7,14 +7,12 @@ import rotSprite, {
77
addMarginToImageData,
88
getRotateDiagonal,
99
} from '#util/rotsprite';
10-
import { Input, Slider, Item, SelectBase, Button, Modal } from '#ui';
10+
import { Input, Slider, Item, Button, Modal } from '#ui';
1111
import { mappingState } from './state';
1212

1313
export const Rotate = observer(() => {
1414
const canvasRef = useRef();
1515

16-
const [value, setValue] = useState(0);
17-
1816
useEffect(() => {
1917
if (!canvasRef.current) return;
2018
const spriteCanv = exportSprite(environment.currentSprite);
@@ -75,42 +73,55 @@ export const Rotate = observer(() => {
7573
return value;
7674
};
7775

78-
// mappingState.rotateShow
76+
const { active } = mappingState.rotate;
7977

8078
return (
81-
<>
82-
{String(!!value)}
83-
<SelectBase
84-
options={[...Array(2).keys()].map((d) => String(d))}
85-
value={value}
86-
onChange={(e) => setValue(e.value === '1')}
87-
/>
88-
89-
<Modal
90-
className="rotsprite"
91-
spring={{
92-
top: value ? -150 : 50,
93-
opacity: value ? 1 : 0.5,
94-
}}
95-
>
96-
<Item>Rotate Sprite</Item>
97-
<canvas ref={canvasRef} />
98-
<Input
99-
store={mappingState.rotate}
100-
assert={assertInput}
101-
accessor="angle"
102-
isNumber
103-
/>
104-
<Slider
105-
min="0"
106-
step="1"
107-
max="360"
108-
store={mappingState.rotate}
109-
accessor="angle"
110-
/>
79+
<Modal
80+
className="rotsprite"
81+
spring={{
82+
top: active ? 15 : -100,
83+
opacity: active ? 1 : 0,
84+
}}
85+
>
86+
<Item>Rotate Sprite</Item>
87+
<canvas ref={canvasRef} />
88+
<div className="angles">
89+
<div className="numbers">
90+
{Array.from({ length: 8 }, (_, i) => {
91+
const angle = i * 45;
92+
return (
93+
<Button
94+
key={i}
95+
onClick={() => {
96+
mappingState.rotate.angle = angle;
97+
}}
98+
>
99+
{angle}
100+
</Button>
101+
);
102+
})}
103+
<Input
104+
store={mappingState.rotate}
105+
assert={assertInput}
106+
accessor="angle"
107+
isNumber
108+
/>
109+
</div>
110+
111+
<Slider
112+
min="0"
113+
step="1"
114+
max="360"
115+
store={mappingState.rotate}
116+
accessor="angle"
117+
/>
118+
</div>
119+
<div className="actions">
120+
<Button color="magenta" onClick={mappingState.toggleRotate}>
121+
close
122+
</Button>
111123
<Button color="red">Reimport</Button>
112-
<Button color="magenta">close</Button>
113-
</Modal>
114-
</>
124+
</div>
125+
</Modal>
115126
);
116127
});

app/components/mappings/state/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class MappingState {
6363
scale: observable,
6464
x: observable,
6565
y: observable,
66-
rotate: observable,
6766
resetPanAndZoom: action,
6867
setWidth: action,
6968
setZoom: action,
@@ -81,6 +80,8 @@ class MappingState {
8180
selectAll: action,
8281
selectNone: action,
8382
selectToggle: action,
83+
rotate: observable,
84+
toggleRotate: action,
8485
rawEditor: observable,
8586
toggleRawEditor: action,
8687
newMapping: observable,
@@ -181,6 +182,10 @@ class MappingState {
181182
active: false,
182183
};
183184

185+
toggleRotate = () => {
186+
this.rotate.active = !this.rotate.active;
187+
};
188+
184189
// raw editor
185190

186191
rawEditor = {

app/controls/commands.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ export const commands = [
280280
mappingState.toggleRawEditor();
281281
},
282282
},
283+
{
284+
map: 'R', name: 'Rotate Sprite', color: 'white', noMultiplier: true,
285+
func: () => {
286+
mappingState.toggleRotate();
287+
},
288+
},
283289
],
284290

285291
[

styles/components/mappings.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
top: 15px;
4141
left: 15px;
4242
padding: 5px;
43-
z-index: 1;
4443
.mapping {
4544
position: relative;
4645
margin: 5px;
@@ -75,7 +74,6 @@
7574
justify-content: space-between;
7675
margin-bottom: 10px;
7776
}
78-
z-index: 2;
7977
left: 15px;
8078
right: 15px;
8179
}

styles/components/rotsprite.scss

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
.rotsprite {
2-
z-index: 3;
3-
// left: 15px;
4-
// right: 15px;
5-
62
canvas {
73
background-image: url(../images/t.png);
84
border: 3px solid $grey;
95
width: 400px;
106
height: 400px;
7+
margin: 10px;
8+
}
9+
10+
.angles {
11+
margin: 10px;
12+
.numbers {
13+
display: flex;
14+
justify-content: space-between;
15+
margin-bottom: 10px;
16+
}
17+
.ui-input {
18+
display: inline;
19+
}
20+
.ui-input input, .button {
21+
text-align: center;
22+
width: 30px;
23+
margin: 0;
24+
}
1125
}
1226

13-
.close {
27+
.actions {
1428
display: flex;
1529
justify-content: space-between;
16-
margin-bottom: 10px;
30+
margin: 10px;
31+
margin-bottom: 0;
1732
}
1833
}

0 commit comments

Comments
 (0)