Skip to content

Commit e7b76b8

Browse files
committed
some changes to improve usability
1 parent 580a4a2 commit e7b76b8

7 files changed

Lines changed: 69 additions & 23 deletions

File tree

src/main/java/com/ss/editor/state/editor/impl/scene/AbstractSceneEditor3DState.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,20 @@ public void moveCameraTo(@NotNull final Vector3f location) {
17851785
EXECUTOR_MANAGER.addJMETask(() -> getNodeForCamera().setLocalTranslation(location));
17861786
}
17871787

1788+
/**
1789+
* Look at the position from the camera.
1790+
*
1791+
* @param location the location.
1792+
*/
1793+
@FromAnyThread
1794+
public void cameraLookAt(@NotNull final Vector3f location) {
1795+
EXECUTOR_MANAGER.addJMETask(() -> {
1796+
final EditorCamera editorCamera = notNull(getEditorCamera());
1797+
editorCamera.setTargetDistance(location.distance(getCamera().getLocation()));
1798+
getNodeForCamera().setLocalTranslation(location);
1799+
});
1800+
}
1801+
17881802
/**
17891803
* Remove a light.
17901804
*

src/main/java/com/ss/editor/ui/component/asset/tree/context/menu/action/DeleteFileAction.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import com.ss.editor.ui.Icons;
99
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
1010
import com.ss.editor.ui.dialog.ConfirmDialog;
11-
import com.ss.editor.ui.scene.EditorFXScene;
11+
import com.ss.rlib.util.FileUtils;
12+
import com.ss.rlib.util.array.Array;
1213
import javafx.scene.control.MenuItem;
1314
import javafx.scene.image.ImageView;
1415
import org.jetbrains.annotations.NotNull;
15-
import com.ss.rlib.util.FileUtils;
16-
import com.ss.rlib.util.array.Array;
1716

1817
import java.nio.file.Path;
1918

@@ -64,9 +63,8 @@ private void processDelete() {
6463
String question = Messages.ASSET_COMPONENT_RESOURCE_TREE_CONTEXT_MENU_DELETE_FILE_QUESTION;
6564
question = question.replace("%file_name%", file.getFileName().toString());
6665

67-
final EditorFXScene scene = JFX_APPLICATION.getScene();
6866
final ConfirmDialog confirmDialog = new ConfirmDialog(result -> handle(file, result), question);
69-
confirmDialog.show(scene.getWindow());
67+
confirmDialog.show(JFX_APPLICATION.getLastWindow());
7068
}
7169

7270
/**

src/main/java/com/ss/editor/ui/component/editor/impl/AbstractFileEditor.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,13 @@ protected void createContent() {
202202
}
203203

204204
root = createRoot();
205-
root.setOnKeyPressed(this::processKeyPressed);
206-
root.setOnKeyReleased(this::processKeyReleased);
207-
root.setOnMouseReleased(this::processMouseReleased);
208-
root.setOnMousePressed(this::processMousePressed);
205+
206+
if (needListenEventsFromPage()) {
207+
root.setOnKeyPressed(this::processKeyPressed);
208+
root.setOnKeyReleased(this::processKeyReleased);
209+
root.setOnMouseReleased(this::processMouseReleased);
210+
root.setOnMousePressed(this::processMousePressed);
211+
}
209212

210213
createContent(root);
211214

@@ -220,6 +223,13 @@ protected void createContent() {
220223
root.prefWidthProperty().bind(container.widthProperty());
221224
}
222225

226+
/**
227+
* @return true if need to listen to events from root page of this editor.
228+
*/
229+
protected boolean needListenEventsFromPage() {
230+
return true;
231+
}
232+
223233
/**
224234
* Handle the mouse released event.
225235
*/

src/main/java/com/ss/editor/ui/component/editor/impl/material/MaterialFileEditor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ protected boolean needToolbar() {
663663
return true;
664664
}
665665

666+
@Override
667+
protected boolean needListenEventsFromPage() {
668+
return false;
669+
}
670+
666671
@Override
667672
@FXThread
668673
protected void createToolbar(@NotNull final HBox container) {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ protected StackPane createRoot() {
319319
return new StackPane();
320320
}
321321

322+
@Override
323+
protected boolean needListenEventsFromPage() {
324+
return false;
325+
}
326+
322327
/**
323328
* Gets editor app state.
324329
*
@@ -906,7 +911,7 @@ public void selectNodeFromTree(@Nullable final Object object) {
906911
updateSelection(spatial);
907912

908913
if (spatial != null && !isIgnoreCameraMove() && !isVisibleOnEditor(spatial)) {
909-
editor3DState.moveCameraTo(spatial.getWorldTranslation());
914+
editor3DState.cameraLookAt(spatial.getWorldTranslation());
910915
}
911916

912917
final ModelPropertyEditor modelPropertyEditor = getModelPropertyEditor();
@@ -925,7 +930,7 @@ private boolean isVisibleOnEditor(@NotNull final Spatial spatial) {
925930
final Vector3f position = spatial.getWorldTranslation();
926931
final Vector3f coordinates = camera.getScreenCoordinates(position, new Vector3f());
927932

928-
boolean invisible = coordinates.getZ() < 0;
933+
boolean invisible = coordinates.getZ() < 0F || coordinates.getZ() > 1F;
929934
invisible = invisible || !isInside(coordinates.getX(), camera.getHeight() - coordinates.getY(), Event.class);
930935

931936
return !invisible;

src/main/java/com/ss/editor/ui/event/EventRedirector.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.ss.editor.config.Config;
44
import com.ss.editor.ui.component.editor.FileEditor;
55
import com.ss.editor.ui.component.editor.area.EditorAreaComponent;
6+
import com.ss.editor.ui.util.UIUtils;
67
import com.ss.rlib.logging.Logger;
78
import com.ss.rlib.logging.LoggerManager;
89
import javafx.event.Event;
@@ -170,10 +171,12 @@ private void redirect(@NotNull final InputEvent event) {
170171
if (target == destination) {
171172
return;
172173
} else if (target instanceof TextInputControl) {
173-
if (Config.DEV_DEBUG_JFX_KEY_INPUT && LOGGER.isEnabledDebug()) {
174-
LOGGER.debug("Key event was skipped because it was from " + target);
174+
if (event instanceof KeyEvent && UIUtils.isNotHotKey((KeyEvent) event)) {
175+
if (Config.DEV_DEBUG_JFX_KEY_INPUT && LOGGER.isEnabledDebug()) {
176+
LOGGER.debug("Key event was skipped because it was from " + target);
177+
}
178+
return;
175179
}
176-
return;
177180
}
178181

179182
final EventType<? extends InputEvent> eventType = event.getEventType();

src/main/java/com/ss/editor/ui/util/UIUtils.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,31 +481,42 @@ public static Color from(@Nullable final ColorRGBA color) {
481481
}
482482

483483
/**
484-
* Consume an event if the event is not hotkey.
485-
*
486484
* @param event the event.
485+
* @return true if the event is not hotkey.
487486
*/
488487
@FXThread
489-
public static void consumeIfIsNotHotKey(@Nullable final KeyEvent event) {
490-
if (event == null) return;
488+
public static boolean isNotHotKey(@Nullable final KeyEvent event) {
489+
if (event == null) return false;
491490

492491
final String text = event.getText();
493-
if (text.isEmpty()) return;
492+
if (text.isEmpty()) return false;
494493

495494
final KeyCode code = event.getCode();
496495
final EventTarget target = event.getTarget();
497496

498497
if (code == KeyCode.TAB && !(target instanceof TextInputControl)) {
499-
return;
498+
return false;
500499
}
501500

502501
if (event.isControlDown()) {
503-
return;
502+
return false;
504503
} else if (event.isShiftDown()) {
505-
return;
504+
return false;
506505
}
507506

508-
event.consume();
507+
return true;
508+
}
509+
510+
/**
511+
* Consume an event if the event is not hotkey.
512+
*
513+
* @param event the event.
514+
*/
515+
@FXThread
516+
public static void consumeIfIsNotHotKey(@Nullable final KeyEvent event) {
517+
if (isNotHotKey(event)) {
518+
event.consume();
519+
}
509520
}
510521

511522
/**

0 commit comments

Comments
 (0)