Skip to content

Commit 50ccf31

Browse files
committed
implemented the first part of scripting.
1 parent 3e848b9 commit 50ccf31

File tree

14 files changed

+424
-19
lines changed

14 files changed

+424
-19
lines changed
7.29 MB
Binary file not shown.

resources/messages/messages.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ModelFileEditorNodeVertexBuffer=Vertex buffer
159159
SceneFileEditorName=Scene editor
160160
SceneFileEditorToolObjects=Objects
161161
SceneFileEditorToolEditing=Editing
162+
SceneFileEditorToolScripting=Scripting
162163
SceneFileEditorToolAppStates=States
163164
SceneFileEditorToolFilters=Filters
164165
SceneFileEditorToolLayers=Layers
@@ -546,4 +547,8 @@ FileDeleteHandlerDeleteMaterials=Do you want to remove all materials which used
546547
547548
CheckNewVersionDialogTitle=Information
548549
CheckNewVersionDialogHyperText=You can download the new version from:
549-
CheckNewVersionDialogHeaderText=Available the new version:
550+
CheckNewVersionDialogHeaderText=Available the new version:
551+
552+
EditorScriptingComponentHeaders=Headers
553+
EditorScriptingComponentBody=Script body
554+
EditorScriptingComponentRun=Run the script

resources/messages/messages_de.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ModelFileEditorNodeVertexBuffer=Vertexbuffer
159159
SceneFileEditorName=Szeneeditor
160160
SceneFileEditorToolObjects=Objekte
161161
SceneFileEditorToolEditing=Bearbeitung
162+
SceneFileEditorToolScripting=Scripting
162163
SceneFileEditorToolAppStates=States
163164
SceneFileEditorToolFilters=Filter
164165
SceneFileEditorToolLayers=Schichten
@@ -546,4 +547,8 @@ FileDeleteHandlerDeleteMaterials=Wollen Sie alle von Model %file_name% benutzten
546547

547548
CheckNewVersionDialogTitle=Informationen
548549
CheckNewVersionDialogHyperText=Sie können die neue version aus:
549-
CheckNewVersionDialogHeaderText=Verfügbar ist die neue version:
550+
CheckNewVersionDialogHeaderText=Verfügbar ist die neue version:
551+
552+
EditorScriptingComponentHeaders=Headers
553+
EditorScriptingComponentBody=Script body
554+
EditorScriptingComponentRun=Run the script

resources/messages/messages_ru.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ModelFileEditorNodeVertexBuffer=Буффер вертексов
159159
SceneFileEditorName=Редактор сцены
160160
SceneFileEditorToolObjects=Объекты
161161
SceneFileEditorToolEditing=Редактирование
162+
SceneFileEditorToolScripting=Скриптование
162163
SceneFileEditorToolAppStates=Стейты
163164
SceneFileEditorToolFilters=Фильтры
164165
SceneFileEditorToolLayers=Слои
@@ -546,4 +547,8 @@ FileDeleteHandlerDeleteMaterials=Хотите ли вы удалить все м
546547
547548
CheckNewVersionDialogTitle=Информация
548549
CheckNewVersionDialogHyperText=Вы можете скачать новую версию по ссылке:
549-
CheckNewVersionDialogHeaderText=Доступна новая версия:
550+
CheckNewVersionDialogHeaderText=Доступна новая версия:
551+
552+
EditorScriptingComponentHeaders=Заголовки
553+
EditorScriptingComponentBody=Тело скрипта
554+
EditorScriptingComponentRun=Запустить скрипт

resources/ui/css/custom_ids.bss

566 Bytes
Binary file not shown.

resources/ui/css/custom_ids.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,4 +804,24 @@
804804

805805
#SceneEditorStatsContainer {
806806
-fx-alignment: bottom-left;
807+
}
808+
809+
#EditorScriptingComponent {
810+
-fx-background-color: -fx-background-background;
811+
-fx-padding: 5px;
812+
-fx-vgap: 3px;
813+
}
814+
815+
#EditorScriptingComponentButtonRun {
816+
-fx-min-height: 32;
817+
-fx-pref-height: -fx-min-height;
818+
-fx-max-height: -fx-min-height;
819+
-fx-min-width: 150;
820+
-fx-pref-width: -fx-min-width;
821+
-fx-max-width: -fx-min-width;
822+
}
823+
824+
#GroovyEditorComponent {
825+
-fx-border-width: 1px;
826+
-fx-border-color: black;
807827
}

src/com/ss/editor/Messages.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public class Messages {
177177
public static final String SCENE_FILE_EDITOR_NAME;
178178
public static final String SCENE_FILE_EDITOR_TOOL_OBJECTS;
179179
public static final String SCENE_FILE_EDITOR_TOOL_EDITING;
180+
public static final String SCENE_FILE_EDITOR_TOOL_SCRIPTING;
180181
public static final String SCENE_FILE_EDITOR_TOOL_APP_STATES;
181182
public static final String SCENE_FILE_EDITOR_TOOL_FILTERS;
182183
public static final String SCENE_FILE_EDITOR_TOOL_LAYERS;
@@ -569,6 +570,10 @@ public class Messages {
569570
public static final String CHECK_NEW_VERSION_DIALOG_HYPERLINK;
570571
public static final String CHECK_NEW_VERSION_DIALOG_HEADER_TEXT;
571572

573+
public static final String EDITOR_SCRIPTING_COMPONENT_HEADERS;
574+
public static final String EDITOR_SCRIPTING_COMPONENT_BODY;
575+
public static final String EDITOR_SCRIPTING_COMPONENT_RUN;
576+
572577
static {
573578

574579
final Locale locale = Locale.getDefault();
@@ -749,6 +754,7 @@ public class Messages {
749754
SCENE_FILE_EDITOR_NAME = bundle.getString("SceneFileEditorName");
750755
SCENE_FILE_EDITOR_TOOL_OBJECTS = bundle.getString("SceneFileEditorToolObjects");
751756
SCENE_FILE_EDITOR_TOOL_EDITING = bundle.getString("SceneFileEditorToolEditing");
757+
SCENE_FILE_EDITOR_TOOL_SCRIPTING = bundle.getString("SceneFileEditorToolScripting");
752758
SCENE_FILE_EDITOR_TOOL_APP_STATES = bundle.getString("SceneFileEditorToolAppStates");
753759
SCENE_FILE_EDITOR_TOOL_FILTERS = bundle.getString("SceneFileEditorToolFilters");
754760
SCENE_FILE_EDITOR_TOOL_LAYERS = bundle.getString("SceneFileEditorToolLayers");
@@ -1139,5 +1145,9 @@ public class Messages {
11391145
CHECK_NEW_VERSION_DIALOG_TITLE = bundle.getString("CheckNewVersionDialogTitle");
11401146
CHECK_NEW_VERSION_DIALOG_HYPERLINK = bundle.getString("CheckNewVersionDialogHyperText");
11411147
CHECK_NEW_VERSION_DIALOG_HEADER_TEXT = bundle.getString("CheckNewVersionDialogHeaderText");
1148+
1149+
EDITOR_SCRIPTING_COMPONENT_HEADERS = bundle.getString("EditorScriptingComponentHeaders");
1150+
EDITOR_SCRIPTING_COMPONENT_BODY = bundle.getString("EditorScriptingComponentBody");
1151+
EDITOR_SCRIPTING_COMPONENT_RUN = bundle.getString("EditorScriptingComponentRun");
11421152
}
11431153
}

src/com/ss/editor/ui/component/editor/impl/model/ModelFileEditor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.ss.editor.ui.component.editor.impl.scene.AbstractSceneFileEditor;
2323
import com.ss.editor.ui.component.editor.state.EditorState;
2424
import com.ss.editor.ui.component.editor.state.impl.ModelFileEditorState;
25-
import com.ss.editor.ui.control.model.tree.ModelNodeTree;
2625
import com.ss.editor.ui.css.CSSClasses;
2726
import com.ss.editor.ui.css.CSSIds;
2827
import com.ss.editor.util.MaterialUtils;
@@ -139,8 +138,7 @@ public void openFile(@NotNull final Path file) {
139138
final ComboBox<String> fastSkyComboBox = getFastSkyComboBox();
140139
fastSkyComboBox.getSelectionModel().select(FAST_SKY_LIST.first());
141140

142-
final ModelNodeTree modelNodeTree = getModelNodeTree();
143-
modelNodeTree.fill(model);
141+
refreshTree();
144142

145143
} finally {
146144
setIgnoreListeners(false);

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import com.jme3.asset.ModelKey;
1212
import com.jme3.audio.AudioNode;
1313
import com.jme3.export.binary.BinaryExporter;
14+
import com.jme3.light.DirectionalLight;
1415
import com.jme3.light.Light;
16+
import com.jme3.light.PointLight;
17+
import com.jme3.light.SpotLight;
1518
import com.jme3.material.Material;
1619
import com.jme3.math.Vector3f;
1720
import com.jme3.renderer.Camera;
@@ -40,6 +43,7 @@
4043
import com.ss.editor.ui.component.editing.EditingContainer;
4144
import com.ss.editor.ui.component.editing.terrain.TerrainEditingComponent;
4245
import com.ss.editor.ui.component.editor.impl.AbstractFileEditor;
46+
import com.ss.editor.ui.component.editor.scripting.EditorScriptingComponent;
4347
import com.ss.editor.ui.component.editor.state.EditorState;
4448
import com.ss.editor.ui.component.editor.state.impl.AbstractModelFileEditorState;
4549
import com.ss.editor.ui.component.split.pane.EditorToolSplitPane;
@@ -160,6 +164,12 @@ public abstract class AbstractSceneFileEditor<IM extends AbstractSceneFileEditor
160164
@Nullable
161165
private EditingContainer editingContainer;
162166

167+
/**
168+
* The scripting component.
169+
*/
170+
@NotNull
171+
private EditorScriptingComponent scriptingComponent;
172+
163173
/**
164174
* The container of property editor in objects tool.
165175
*/
@@ -437,6 +447,17 @@ protected void handleRemovedObject(@NotNull final Spatial model) {
437447
*/
438448
protected void loadState() {
439449

450+
scriptingComponent.addVariable("root", getCurrentModel());
451+
scriptingComponent.addImport(Spatial.class);
452+
scriptingComponent.addImport(Geometry.class);
453+
scriptingComponent.addImport(Control.class);
454+
scriptingComponent.addImport(Light.class);
455+
scriptingComponent.addImport(DirectionalLight.class);
456+
scriptingComponent.addImport(PointLight.class);
457+
scriptingComponent.addImport(SpotLight.class);
458+
scriptingComponent.setExampleCode("root.attachChild(new Node(\"created from Groovy\"));");
459+
scriptingComponent.buildHeader();
460+
440461
final WorkspaceManager workspaceManager = WorkspaceManager.getInstance();
441462
final Workspace currentWorkspace = requireNonNull(workspaceManager.getCurrentWorkspace(),
442463
"Current workspace can't be null.");
@@ -1020,6 +1041,8 @@ protected void createContent(@NotNull final StackPane root) {
10201041
editingContainer = new EditingContainer(this, this);
10211042
editingContainer.addComponent(new TerrainEditingComponent());
10221043

1044+
scriptingComponent = new EditorScriptingComponent(this::refreshTree);
1045+
10231046
final SplitPane objectsSplitContainer = new SplitPane(modelNodeTreeObjectsContainer, propertyEditorObjectsContainer);
10241047
objectsSplitContainer.setId(CSSIds.FILE_EDITOR_TOOL_SPLIT_PANE);
10251048
objectsSplitContainer.prefHeightProperty().bind(root.heightProperty());
@@ -1037,6 +1060,7 @@ protected void createContent(@NotNull final StackPane root) {
10371060
editorToolComponent.prefHeightProperty().bind(root.heightProperty());
10381061
editorToolComponent.addComponent(objectsSplitContainer, Messages.SCENE_FILE_EDITOR_TOOL_OBJECTS);
10391062
editorToolComponent.addComponent(editingSplitContainer, Messages.SCENE_FILE_EDITOR_TOOL_EDITING);
1063+
editorToolComponent.addComponent(scriptingComponent, Messages.SCENE_FILE_EDITOR_TOOL_SCRIPTING);
10401064
editorToolComponent.addChangeListener((observable, oldValue, newValue) -> processChangeTool(oldValue, newValue));
10411065

10421066
mainSplitContainer.initFor(editorToolComponent, editorAreaPane);
@@ -1048,6 +1072,17 @@ protected void createContent(@NotNull final StackPane root) {
10481072
root.heightProperty().addListener((observableValue, oldValue, newValue) -> calcVSplitSize(editingSplitContainer));
10491073
}
10501074

1075+
/**
1076+
* Refresh tree.
1077+
*/
1078+
protected void refreshTree() {
1079+
1080+
final M currentModel = getCurrentModel();
1081+
1082+
final ModelNodeTree modelNodeTree = getModelNodeTree();
1083+
modelNodeTree.fill(currentModel);
1084+
}
1085+
10511086
/**
10521087
* @return the editor tool component.
10531088
*/

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,28 @@ public void openFile(@NotNull final Path file) {
155155
setCurrentModel(model);
156156
setIgnoreListeners(true);
157157
try {
158+
refreshTree();
159+
} finally {
160+
setIgnoreListeners(false);
161+
}
158162

159-
final ModelNodeTree modelNodeTree = getModelNodeTree();
160-
modelNodeTree.fill(model);
163+
EXECUTOR_MANAGER.addFXTask(this::loadState);
164+
}
161165

162-
final AppStateList appStateList = getAppStateList();
163-
appStateList.fill(model);
166+
@Override
167+
protected void refreshTree() {
168+
super.refreshTree();
164169

165-
final FilterList filterList = getFilterList();
166-
filterList.fill(model);
170+
final SceneNode model = getCurrentModel();
167171

168-
final LayerNodeTree layerNodeTree = getLayerNodeTree();
169-
layerNodeTree.fill(new LayersRoot(this));
172+
final AppStateList appStateList = getAppStateList();
173+
appStateList.fill(model);
170174

171-
} finally {
172-
setIgnoreListeners(false);
173-
}
175+
final FilterList filterList = getFilterList();
176+
filterList.fill(model);
174177

175-
EXECUTOR_MANAGER.addFXTask(this::loadState);
178+
final LayerNodeTree layerNodeTree = getLayerNodeTree();
179+
layerNodeTree.fill(new LayersRoot(this));
176180
}
177181

178182
private void updateVisibility(@NotNull final Spatial spatial) {

0 commit comments

Comments
 (0)