Skip to content

Commit 14ab7dd

Browse files
committed
added hotkeys R/S/G to a scene editor.
1 parent ceab1b6 commit 14ab7dd

14 files changed

+124
-55
lines changed

src/com/ss/editor/state/editor/impl/AdvancedAbstractEditorAppState.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public abstract class AdvancedAbstractEditorAppState<T extends FileEditor> exten
5252
protected static final String KEY_CTRL = "SSEditor.editorState.keyCtrl";
5353
protected static final String KEY_ALT = "SSEditor.editorState.keyAlt";
5454
protected static final String KEY_SHIFT = "SSEditor.editorState.keyShift";
55-
protected static final String KEY_S = "SSEditor.editorState.S";
56-
protected static final String KEY_Z = "SSEditor.editorState.Z";
57-
protected static final String KEY_Y = "SSEditor.editorState.Y";
55+
protected static final String KEY_CTRL_S = "SSEditor.editorState.Ctrl.S";
56+
protected static final String KEY_CTRL_Z = "SSEditor.editorState.Ctrl.Z";
57+
protected static final String KEY_CTRL_Y = "SSEditor.editorState.Ctrl.Y";
5858

5959
protected static final String KEY_NUM_1 = "SSEditor.editorState.num1";
6060
protected static final String KEY_NUM_2 = "SSEditor.editorState.num2";
@@ -80,9 +80,9 @@ public abstract class AdvancedAbstractEditorAppState<T extends FileEditor> exten
8080
MULTI_TRIGGERS.put(KEY_SHIFT, toArray(new KeyTrigger(KeyInput.KEY_RSHIFT), new KeyTrigger(KeyInput.KEY_LSHIFT)));
8181
MULTI_TRIGGERS.put(KEY_ALT, toArray(new KeyTrigger(KeyInput.KEY_RMENU), new KeyTrigger(KeyInput.KEY_LMENU)));
8282

83-
TRIGGERS.put(KEY_S, new KeyTrigger(KeyInput.KEY_S));
84-
TRIGGERS.put(KEY_Z, new KeyTrigger(KeyInput.KEY_Z));
85-
TRIGGERS.put(KEY_Y, new KeyTrigger(KeyInput.KEY_Y));
83+
TRIGGERS.put(KEY_CTRL_S, new KeyTrigger(KeyInput.KEY_S));
84+
TRIGGERS.put(KEY_CTRL_Z, new KeyTrigger(KeyInput.KEY_Z));
85+
TRIGGERS.put(KEY_CTRL_Y, new KeyTrigger(KeyInput.KEY_Y));
8686

8787
TRIGGERS.put(KEY_NUM_1, new KeyTrigger(KeyInput.KEY_NUMPAD1));
8888
TRIGGERS.put(KEY_NUM_2, new KeyTrigger(KeyInput.KEY_NUMPAD2));
@@ -111,13 +111,13 @@ public abstract class AdvancedAbstractEditorAppState<T extends FileEditor> exten
111111
* The action scene listeners.
112112
*/
113113
@NotNull
114-
private final ActionListener actionListener;
114+
protected final ActionListener actionListener;
115115

116116
/**
117117
* The analog scene listeners.
118118
*/
119119
@NotNull
120-
private final AnalogListener analogListener;
120+
protected final AnalogListener analogListener;
121121

122122
/**
123123
* The editor camera.
@@ -187,7 +187,7 @@ public abstract class AdvancedAbstractEditorAppState<T extends FileEditor> exten
187187
*/
188188
private boolean buttonMiddleDown;
189189

190-
public AdvancedAbstractEditorAppState(final T fileEditor) {
190+
public AdvancedAbstractEditorAppState(@NotNull final T fileEditor) {
191191
super(fileEditor);
192192
this.editorCamera = needEditorCamera() ? createEditorCamera() : null;
193193
this.lightForCamera = needLightForCamera() ? createLightForCamera() : null;
@@ -226,14 +226,14 @@ protected void registerActionHandlers(@NotNull final ObjectDictionary<String, Bo
226226
actionHandlers.put(KEY_NUM_4, (isPressed, tpf) -> rotateTo(EditorCamera.Direction.LEFT, isPressed));
227227
actionHandlers.put(KEY_NUM_6, (isPressed, tpf) -> rotateTo(EditorCamera.Direction.RIGHT, isPressed));
228228

229-
actionHandlers.put(KEY_Z, (isPressed, tpf) -> {
229+
actionHandlers.put(KEY_CTRL_Z, (isPressed, tpf) -> {
230230
if (!isPressed && isControlDown()) undo();
231231
});
232-
actionHandlers.put(KEY_Y, (isPressed, tpf) -> {
232+
actionHandlers.put(KEY_CTRL_Y, (isPressed, tpf) -> {
233233
if (!isPressed && isControlDown()) redo();
234234
});
235235

236-
actionHandlers.put(KEY_S, (isPressed, tpf) -> {
236+
actionHandlers.put(KEY_CTRL_S, (isPressed, tpf) -> {
237237

238238
final FileEditor fileEditor = getFileEditor();
239239

@@ -493,7 +493,7 @@ protected void registerAnalogListener(@NotNull final InputManager inputManager)
493493
*/
494494
protected void registerActionListener(@NotNull final InputManager inputManager) {
495495
inputManager.addListener(actionListener, MOUSE_RIGHT_CLICK, MOUSE_LEFT_CLICK, MOUSE_MIDDLE_CLICK);
496-
inputManager.addListener(actionListener, KEY_CTRL, KEY_SHIFT, KEY_ALT, KEY_S, KEY_Z, KEY_Y, KEY_NUM_1,
496+
inputManager.addListener(actionListener, KEY_CTRL, KEY_SHIFT, KEY_ALT, KEY_CTRL_S, KEY_CTRL_Z, KEY_CTRL_Y, KEY_NUM_1,
497497
KEY_NUM_2, KEY_NUM_3, KEY_NUM_4, KEY_NUM_5, KEY_NUM_6, KEY_NUM_7, KEY_NUM_8, KEY_NUM_9);
498498
}
499499

src/com/ss/editor/state/editor/impl/model/ModelEditorAppState.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ private Array<Spatial> getCustomSky() {
8888
return customSky;
8989
}
9090

91-
@Override
92-
public void notifyTransformed(@NotNull final Spatial spatial) {
93-
getFileEditor().notifyTransformed(spatial);
94-
}
95-
9691
/**
9792
* Activate the node with models.
9893
*/
@@ -286,11 +281,6 @@ protected void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final
286281
EXECUTOR_MANAGER.addFXTask(() -> getFileEditor().notifyChangedCamera(cameraLocation, hRotation, vRotation, targetDistance));
287282
}
288283

289-
@Override
290-
protected void notifySelected(@Nullable final Object object) {
291-
getFileEditor().notifySelected(object);
292-
}
293-
294284
@Override
295285
public String toString() {
296286
return "ModelEditorAppState{" +

src/com/ss/editor/state/editor/impl/model/ModelEditorUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.ss.editor.scene.EditorAudioNode;
1010
import com.ss.editor.scene.EditorLightNode;
1111
import com.ss.editor.state.editor.impl.scene.AbstractSceneEditorAppState;
12-
import com.ss.editor.ui.component.editor.FileEditor;
12+
import com.ss.editor.ui.component.editor.impl.scene.AbstractSceneFileEditor;
1313
import com.ss.editor.util.NodeUtils;
1414

1515
import org.jetbrains.annotations.NotNull;
@@ -26,7 +26,7 @@
2626
public class ModelEditorUtils {
2727

2828
@Nullable
29-
public static <T extends FileEditor & ModelChangeConsumer, M extends Spatial> Object findToSelect(
29+
public static <T extends AbstractSceneFileEditor & ModelChangeConsumer, M extends Spatial> Object findToSelect(
3030
@NotNull final AbstractSceneEditorAppState<T, M> state, @NotNull final Object object) {
3131

3232
if (object instanceof ParticleGeometry) {

src/com/ss/editor/state/editor/impl/scene/AbstractSceneEditorAppState.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.jme3.collision.CollisionResults;
1313
import com.jme3.effect.ParticleEmitter;
1414
import com.jme3.input.InputManager;
15+
import com.jme3.input.KeyInput;
16+
import com.jme3.input.controls.KeyTrigger;
1517
import com.jme3.light.DirectionalLight;
1618
import com.jme3.light.Light;
1719
import com.jme3.light.PointLight;
@@ -45,13 +47,15 @@
4547
import com.ss.editor.scene.EditorAudioNode;
4648
import com.ss.editor.scene.EditorLightNode;
4749
import com.ss.editor.state.editor.impl.AdvancedAbstractEditorAppState;
48-
import com.ss.editor.ui.component.editor.FileEditor;
50+
import com.ss.editor.ui.component.editor.impl.scene.AbstractSceneFileEditor;
4951
import com.ss.editor.ui.control.model.property.operation.ModelPropertyOperation;
5052
import com.ss.editor.util.NodeUtils;
5153

5254
import org.jetbrains.annotations.NotNull;
5355
import org.jetbrains.annotations.Nullable;
5456

57+
import javafx.scene.input.KeyCode;
58+
import rlib.function.BooleanFloatConsumer;
5559
import rlib.geom.util.AngleUtils;
5660
import rlib.util.array.Array;
5761
import rlib.util.array.ArrayFactory;
@@ -64,12 +68,22 @@
6468
*
6569
* @author JavaSaBr
6670
*/
67-
public abstract class AbstractSceneEditorAppState<T extends FileEditor & ModelChangeConsumer, M extends Spatial>
71+
public abstract class AbstractSceneEditorAppState<T extends AbstractSceneFileEditor & ModelChangeConsumer, M extends Spatial>
6872
extends AdvancedAbstractEditorAppState<T> implements SceneEditorControl {
6973

74+
protected static final String KEY_S = "SSEditor.editorState.S";
75+
protected static final String KEY_G = "SSEditor.editorState.G";
76+
protected static final String KEY_R = "SSEditor.editorState.R";
77+
7078
private static final float H_ROTATION = AngleUtils.degreeToRadians(45);
7179
private static final float V_ROTATION = AngleUtils.degreeToRadians(15);
7280

81+
static {
82+
TRIGGERS.put(KEY_S, new KeyTrigger(KeyInput.KEY_S));
83+
TRIGGERS.put(KEY_G, new KeyTrigger(KeyInput.KEY_G));
84+
TRIGGERS.put(KEY_R, new KeyTrigger(KeyInput.KEY_R));
85+
}
86+
7387
/**
7488
* The table with models to present lights on a scene.
7589
*/
@@ -263,6 +277,23 @@ public AbstractSceneEditorAppState(@NotNull final T fileEditor) {
263277
setTransformType(TransformType.MOVE_TOOL);
264278
}
265279

280+
@Override
281+
protected void registerActionHandlers(@NotNull final ObjectDictionary<String, BooleanFloatConsumer> actionHandlers) {
282+
super.registerActionHandlers(actionHandlers);
283+
284+
final T fileEditor = getFileEditor();
285+
286+
actionHandlers.put(KEY_S, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.S, isControlDown()));
287+
actionHandlers.put(KEY_G, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.G, isControlDown()));
288+
actionHandlers.put(KEY_R, (isPressed, tpf) -> fileEditor.handleKeyAction(KeyCode.R, isControlDown()));
289+
}
290+
291+
@Override
292+
protected void registerActionListener(@NotNull final InputManager inputManager) {
293+
super.registerActionListener(inputManager);
294+
inputManager.addListener(actionListener, KEY_S, KEY_G, KEY_R);
295+
}
296+
266297
@Override
267298
@NotNull
268299
protected Node getNodeForCamera() {
@@ -299,6 +330,11 @@ public Node getAudioNode() {
299330
return audioNode;
300331
}
301332

333+
@Override
334+
public void notifyTransformed(@NotNull final Spatial spatial) {
335+
getFileEditor().notifyTransformed(spatial);
336+
}
337+
302338
/**
303339
* Create collision plane.
304340
*/
@@ -1040,6 +1076,7 @@ public Geometry getGeometryByScreenPos(final float worldX, final float worldY) {
10401076
}
10411077

10421078
protected void notifySelected(@Nullable final Object object) {
1079+
getFileEditor().notifySelected(object);
10431080
}
10441081

10451082
/**

src/com/ss/editor/state/editor/impl/scene/SceneEditorAppState.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.jme3.post.filters.FXAAFilter;
77
import com.jme3.post.filters.ToneMapFilter;
88
import com.jme3.scene.Node;
9-
import com.jme3.scene.Spatial;
109
import com.ss.editor.annotation.FromAnyThread;
1110
import com.ss.editor.config.EditorConfig;
1211
import com.ss.editor.ui.component.editor.impl.scene.SceneFileEditor;
@@ -15,7 +14,6 @@
1514
import com.ss.extension.scene.filter.SceneFilter;
1615

1716
import org.jetbrains.annotations.NotNull;
18-
import org.jetbrains.annotations.Nullable;
1917

2018
import rlib.util.array.Array;
2119

@@ -34,21 +32,11 @@ public SceneEditorAppState(@NotNull final SceneFileEditor fileEditor) {
3432
stateNode.attachChild(getToolNode());
3533
}
3634

37-
@Override
38-
public void notifyTransformed(@NotNull final Spatial spatial) {
39-
getFileEditor().notifyTransformed(spatial);
40-
}
41-
4235
@Override
4336
protected int getGridSize() {
4437
return 1000;
4538
}
4639

47-
@Override
48-
protected void notifySelected(@Nullable final Object object) {
49-
getFileEditor().notifySelected(object);
50-
}
51-
5240
@Override
5341
protected void undo() {
5442
final SceneFileEditor fileEditor = getFileEditor();

src/com/ss/editor/ui/component/editor/impl/scene/AbstractSceneFileEditor.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.jme3.scene.Spatial;
2222
import com.ss.editor.FileExtensions;
2323
import com.ss.editor.Messages;
24+
import com.ss.editor.annotation.EditorThread;
2425
import com.ss.editor.annotation.FXThread;
2526
import com.ss.editor.annotation.FromAnyThread;
2627
import com.ss.editor.control.transform.SceneEditorControl.TransformType;
@@ -369,19 +370,59 @@ public void notifyChangedCamera(@NotNull final Vector3f cameraLocation, final fl
369370
@Override
370371
protected void processKeyReleased(@NotNull final KeyEvent event) {
371372
super.processKeyReleased(event);
372-
if (!event.isControlDown()) return;
373373

374374
final KeyCode code = event.getCode();
375375

376-
if (code == KeyCode.Z) {
377-
undo();
376+
if (handleKeyActionImpl(code, event.isControlDown())) {
378377
event.consume();
379-
} else if (code == KeyCode.Y) {
378+
}
379+
}
380+
381+
/**
382+
* Handle a key code.
383+
*
384+
* @param isControlDown true if control is down.
385+
* @param keyCode the key code.
386+
*/
387+
@FromAnyThread
388+
public void handleKeyAction(@NotNull final KeyCode keyCode, final boolean isControlDown) {
389+
EXECUTOR_MANAGER.addFXTask(() -> handleKeyActionImpl(keyCode, isControlDown));
390+
}
391+
392+
/**
393+
* Handle a key code.
394+
*
395+
* @param keyCode the key code.
396+
* @param isControlDown true if control is down.
397+
* @return true if can consume an event.
398+
*/
399+
@EditorThread
400+
protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final boolean isControlDown) {
401+
402+
if (isControlDown && keyCode == KeyCode.Z) {
403+
undo();
404+
return true;
405+
} else if (isControlDown && keyCode == KeyCode.Y) {
380406
redo();
381-
event.consume();
407+
return true;
408+
} else if (keyCode == KeyCode.G) {
409+
final ToggleButton moveToolButton = getMoveToolButton();
410+
moveToolButton.setSelected(true);
411+
return true;
412+
} else if (keyCode == KeyCode.R) {
413+
final ToggleButton rotationToolButton = getRotationToolButton();
414+
rotationToolButton.setSelected(true);
415+
return true;
416+
} else if (keyCode == KeyCode.S) {
417+
final ToggleButton scaleToolButton = getScaleToolButton();
418+
scaleToolButton.setSelected(true);
419+
return true;
382420
}
421+
422+
return false;
383423
}
384424

425+
385426
/**
386427
* Redo the last operation.
387428
*/

src/com/ss/editor/ui/control/model/tree/action/LoadModelAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ss.editor.ui.control.model.tree.action;
22

3+
import static com.ss.editor.control.transform.SceneEditorControl.LOADED_MODEL_KEY;
34
import static com.ss.editor.util.EditorUtil.getAssetFile;
45
import static com.ss.editor.util.EditorUtil.toAssetPath;
56
import static java.util.Objects.requireNonNull;
@@ -91,6 +92,7 @@ protected void processOpen(@NotNull final Path file) {
9192
assetManager.deleteFromCache(modelKey);
9293

9394
final Spatial loadedModel = assetManager.loadModel(modelKey);
95+
loadedModel.setUserData(LOADED_MODEL_KEY, true);
9496

9597
final ModelNode<?> modelNode = getNode();
9698
final Node parent = (Node) modelNode.getElement();

src/com/ss/editor/ui/control/property/impl/AbstractFloatPropertyControl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.util.function.BiConsumer;
1313

14+
import javafx.event.Event;
1415
import javafx.scene.layout.HBox;
1516
import rlib.function.SixObjectConsumer;
1617
import rlib.ui.control.input.FloatTextField;
@@ -41,6 +42,7 @@ protected void createComponents(@NotNull final HBox container) {
4142

4243
valueField = new FloatTextField();
4344
valueField.setId(CSSIds.ABSTRACT_PARAM_CONTROL_COMBO_BOX);
45+
valueField.setOnKeyPressed(Event::consume);
4446
valueField.addChangeListener((observable, oldValue, newValue) -> updateValue());
4547
valueField.prefWidthProperty().bind(widthProperty().multiply(CONTROL_WIDTH_PERCENT));
4648

src/com/ss/editor/ui/control/property/impl/AbstractIntArrayPropertyControl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected void reload() {
8484
* Update the value.
8585
*/
8686
private void updateValue(final KeyEvent event) {
87+
if (event != null) event.consume();
8788
if (isIgnoreListener() || (event != null && event.getCode() != KeyCode.ENTER)) return;
8889

8990
final String textValue = valueField.getText();

src/com/ss/editor/ui/control/property/impl/AbstractIntegerPropertyControl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.function.BiConsumer;
1212

13+
import javafx.event.Event;
1314
import javafx.scene.layout.HBox;
1415
import rlib.function.SixObjectConsumer;
1516
import rlib.ui.control.input.IntegerTextField;
@@ -40,6 +41,7 @@ protected void createComponents(@NotNull final HBox container) {
4041

4142
valueField = new IntegerTextField();
4243
valueField.setId(CSSIds.ABSTRACT_PARAM_CONTROL_COMBO_BOX);
44+
valueField.setOnKeyPressed(Event::consume);
4345
valueField.addChangeListener((observable, oldValue, newValue) -> updateValue());
4446
valueField.prefWidthProperty().bind(widthProperty().multiply(CONTROL_WIDTH_PERCENT));
4547

0 commit comments

Comments
 (0)