Skip to content

Commit d9eae85

Browse files
committed
рефакторинг, доработки, реализовано подхватывание редактирования материала в редакторе моделей
1 parent 87a651b commit d9eae85

20 files changed

+203
-110
lines changed

build-native.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
name="jME3-SpaceShift-Editor"
118118
mainClass="com.ss.editor.Starter"
119119
toolkit="fx"
120-
version="0.2"
120+
version="0.3"
121121
/>
122122

123123
<mkdir dir="build/classes/META-INF"/>
@@ -130,7 +130,7 @@
130130
<manifest>
131131
<attribute name="Implementation-Vendor" value="spaceshift.ru"/>
132132
<attribute name="Implementation-Title" value="jME3 SpaceShift Editor"/>
133-
<attribute name="Implementation-Version" value="0.2"/>
133+
<attribute name="Implementation-Version" value="0.3"/>
134134
</manifest>
135135
</fx:jar>
136136

src/com/ss/editor/config/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class Config {
1717
public static final String CONFIG_RESOURCE_PATH = "/com/ss/editor/config/config.xml";
1818

1919
public static final String TITLE = "jME3 SpaceShift Editor";
20-
public static final String VERSION = "v.0.2.0";
20+
public static final String VERSION = "v.0.3.0";
2121

2222
/**
2323
* Путь к папке с программой.
@@ -39,7 +39,7 @@ public abstract class Config {
3939
final VarTable vars = new DocumentConfig(EditorUtil.getInputStream(CONFIG_RESOURCE_PATH)).parse();
4040

4141
DEV_DEBUG = vars.getBoolean("Dev.debug", false);
42-
ENABLE_PBR = vars.getBoolean("Graphics.enablePBR", false);
42+
ENABLE_PBR = vars.getBoolean("Graphics.enablePBR", true);
4343

4444
PROJECT_PATH = Util.getRootFolderFromClass(Editor.class).toString();
4545
}

src/com/ss/editor/manager/FileIconManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public Image getIcon(final Path path, int size) {
124124
Path iconPath = mimeTypes.resolve(valueOf(size)).resolve(contentType + ".png");
125125
String url = toClasspath(iconPath);
126126

127+
if (!EditorUtil.checkExists(url)) {
128+
contentType = EXTENSION_TO_CONTENT_TYPE.get(FileUtils.getExtension(path));
129+
iconPath = mimeTypes.resolve(valueOf(size)).resolve(contentType + ".png");
130+
url = toClasspath(iconPath);
131+
}
132+
127133
if (!EditorUtil.checkExists(url)) {
128134
LOGGER.warning("not found image for contentType " + contentType + " and path " + path);
129135
iconPath = mimeTypes.resolve(valueOf(size)).resolve("none.png");

src/com/ss/editor/ui/builder/EditorFXSceneBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.ss.editor.ui.component.bar.EditorBarComponent;
77
import com.ss.editor.ui.component.editor.area.EditorAreaComponent;
88
import com.ss.editor.ui.css.CSSFont;
9+
import com.ss.editor.ui.css.CSSIds;
910
import com.ss.editor.ui.scene.EditorFXScene;
1011
import com.ss.editor.util.EditorUtil;
1112

@@ -17,7 +18,6 @@
1718
import javafx.scene.text.Font;
1819
import rlib.ui.util.FXUtils;
1920

20-
import static com.ss.editor.ui.css.CSSIds.MAIN_SPLIT_PANEL;
2121
import static javafx.geometry.Pos.TOP_CENTER;
2222
import static javafx.scene.paint.Color.TRANSPARENT;
2323
import static rlib.ui.util.FXUtils.bindFixedSize;
@@ -89,7 +89,7 @@ private static void build(final EditorFXScene scene, final StackPane container)
8989
final EditorAreaComponent editorAreaComponent = new EditorAreaComponent();
9090

9191
final SplitPane splitContainer = new SplitPane(assetComponent, editorAreaComponent);
92-
splitContainer.setId(MAIN_SPLIT_PANEL);
92+
splitContainer.setId(CSSIds.MAIN_SPLIT_PANEL);
9393

9494
EXECUTOR_MANAGER.schedule(() -> EXECUTOR_MANAGER.addFXTask(() -> splitContainer.setDividerPosition(0, 0.1)), 500);
9595

src/com/ss/editor/ui/component/editor/impl/material/MaterialRenderParamsComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private Runnable getChangeHandler() {
136136
* Уведомление о внесении изменений.
137137
*/
138138
private void change() {
139-
EXECUTOR_MANAGER.addEditorThreadTask(getChangeHandler());
139+
EXECUTOR_MANAGER.addFXTask(getChangeHandler());
140140
}
141141

142142
/**

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.jme3.asset.AssetManager;
44
import com.jme3.asset.ModelKey;
55
import com.jme3.export.binary.BinaryExporter;
6+
import com.jme3.material.Material;
7+
import com.jme3.scene.Geometry;
68
import com.jme3.scene.Spatial;
79
import com.jme3.util.SkyFactory;
810
import com.ss.editor.FileExtensions;
@@ -16,6 +18,7 @@
1618
import com.ss.editor.ui.control.model.tree.ModelTreeChangeListener;
1719
import com.ss.editor.ui.css.CSSClasses;
1820
import com.ss.editor.ui.css.CSSIds;
21+
import com.ss.editor.ui.event.impl.FileChangedEvent;
1922
import com.ss.editor.util.EditorUtil;
2023

2124
import java.io.IOException;
@@ -25,6 +28,8 @@
2528
import java.util.function.Consumer;
2629

2730
import javafx.collections.ObservableList;
31+
import javafx.event.Event;
32+
import javafx.event.EventHandler;
2833
import javafx.geometry.Insets;
2934
import javafx.scene.control.Accordion;
3035
import javafx.scene.control.ComboBox;
@@ -36,6 +41,7 @@
3641
import javafx.scene.layout.StackPane;
3742
import javafx.scene.layout.VBox;
3843
import rlib.ui.util.FXUtils;
44+
import rlib.util.FileUtils;
3945
import rlib.util.array.Array;
4046
import rlib.util.array.ArrayFactory;
4147

@@ -67,6 +73,11 @@ public class ModelFileEditor extends AbstractFileEditor<StackPane> {
6773
FAST_SKY_LIST.add("graphics/textures/sky/studio.hdr");
6874
}
6975

76+
/**
77+
* Слушатель изменений файлов.
78+
*/
79+
private final EventHandler<Event> fileChangedHandler;
80+
7081
/**
7182
* Слушатель изменений в структуре модели.
7283
*/
@@ -129,9 +140,54 @@ public class ModelFileEditor extends AbstractFileEditor<StackPane> {
129140

130141
public ModelFileEditor() {
131142
this.editorState = new ModelEditorState(this);
143+
this.fileChangedHandler = event -> processChangedFile((FileChangedEvent) event);
132144
addEditorState(editorState);
133145
}
134146

147+
/**
148+
* Обработка изменений файла.
149+
*/
150+
private void processChangedFile(final FileChangedEvent event) {
151+
152+
final Path file = event.getFile();
153+
final String extension = FileUtils.getExtension(file);
154+
155+
if(!extension.endsWith(FileExtensions.JME_MATERIAL)) {
156+
return;
157+
}
158+
159+
final Path assetFile = EditorUtil.getAssetFile(file);
160+
final String assetPath = EditorUtil.toClasspath(assetFile);
161+
162+
final Array<Geometry> geometries = ArrayFactory.newArray(Geometry.class);
163+
164+
final Spatial currentModel = getCurrentModel();
165+
166+
EditorUtil.addGeometryWithMaterial(currentModel, geometries, assetPath);
167+
168+
if(geometries.isEmpty()) {
169+
return;
170+
}
171+
172+
final AssetManager assetManager = EDITOR.getAssetManager();
173+
assetManager.clearCache();
174+
175+
final Material material = assetManager.loadMaterial(assetPath);
176+
177+
EXECUTOR_MANAGER.addEditorThreadTask(() -> {
178+
geometries.forEach(geometry -> {
179+
geometry.setMaterial(material);
180+
});
181+
});
182+
}
183+
184+
/**
185+
* @return слушатель изменений файлов.
186+
*/
187+
private EventHandler<Event> getFileChangedHandler() {
188+
return fileChangedHandler;
189+
}
190+
135191
@Override
136192
protected StackPane createRoot() {
137193
return new StackPane();
@@ -193,6 +249,13 @@ public void openFile(final Path file) {
193249
} finally {
194250
setIgnoreListeners(false);
195251
}
252+
253+
FX_EVENT_MANAGER.addEventHandler(FileChangedEvent.EVENT_TYPE, getFileChangedHandler());
254+
}
255+
256+
@Override
257+
public void notifyClosed() {
258+
FX_EVENT_MANAGER.removeEventHandler(FileChangedEvent.EVENT_TYPE, getFileChangedHandler());
196259
}
197260

198261
/**

src/com/ss/editor/ui/component/editor/impl/post/filter/MaterialListCell.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
package com.ss.editor.ui.component.editor.impl.post.filter;
22

33
import com.jme3.material.Material;
4-
import com.ss.editor.manager.ExecutorManager;
54
import com.ss.editor.ui.Icons;
65
import com.ss.editor.ui.css.CSSClasses;
76
import com.ss.editor.ui.css.CSSIds;
87

98
import java.nio.file.Path;
109
import java.nio.file.Paths;
1110

11+
import javafx.geometry.Pos;
1212
import javafx.scene.control.Button;
1313
import javafx.scene.control.ListCell;
1414
import javafx.scene.image.ImageView;
1515
import rlib.ui.util.FXUtils;
1616
import rlib.util.StringUtils;
1717

18-
import static javafx.geometry.Pos.CENTER_LEFT;
19-
2018
/**
2119
* Реализация ячейки для списка материалов.
2220
*
2321
* @author Ronn
2422
*/
2523
public class MaterialListCell extends ListCell<Material> {
26-
27-
private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance();
28-
24+
2925
/**
3026
* Ссылка на редактор.
3127
*/
@@ -39,7 +35,7 @@ public class MaterialListCell extends ListCell<Material> {
3935
public MaterialListCell(final PostFilterEditor editor) {
4036
this.editor = editor;
4137

42-
setAlignment(CENTER_LEFT);
38+
setAlignment(Pos.CENTER_LEFT);
4339

4440
removeButton = new Button();
4541
removeButton.setId(CSSIds.POST_FILTER_EDITOR_CELL_REMOVE_BUTTON);
@@ -76,7 +72,8 @@ private void processRemove() {
7672
return;
7773
}
7874

79-
EXECUTOR_MANAGER.addEditorThreadTask(() -> getEditor().remove(item));
75+
final PostFilterEditor editor = getEditor();
76+
editor.remove(item);
8077
}
8178

8279
@Override

src/com/ss/editor/ui/component/editor/impl/post/filter/PostFilterEditor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public void doSave() {
254254
LOGGER.warning(this, e);
255255
}
256256

257+
setOriginalContent(newContent);
257258
setDirty(false);
258259
notifyFileChanged();
259260
}

src/com/ss/editor/ui/control/material/BooleanMaterialParamControl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import com.jme3.material.Material;
55
import com.ss.editor.manager.ExecutorManager;
66
import com.ss.editor.ui.css.CSSClasses;
7+
import com.ss.editor.ui.css.CSSIds;
78

89
import javafx.geometry.Insets;
910
import javafx.scene.control.CheckBox;
1011
import javafx.scene.layout.HBox;
1112
import rlib.ui.util.FXUtils;
1213

13-
import static com.ss.editor.ui.css.CSSIds.MATERIAL_PARAM_CONTROL_CHECKBOX;
14-
1514
/**
1615
* Реализация контрола для установки флага.
1716
*
@@ -37,15 +36,14 @@ protected void createComponents() {
3736
super.createComponents();
3837

3938
checkBox = new CheckBox();
40-
checkBox.setId(MATERIAL_PARAM_CONTROL_CHECKBOX);
39+
checkBox.setId(CSSIds.MATERIAL_PARAM_CONTROL_CHECKBOX);
4140
checkBox.selectedProperty().addListener((observable, oldValue, newValue) -> processChange(newValue));
4241

4342
FXUtils.addToPane(checkBox, this);
44-
45-
HBox.setMargin(checkBox, ELEMENT_OFFSET);
46-
4743
FXUtils.addClassTo(checkBox, CSSClasses.MAIN_FONT_13);
4844
FXUtils.bindFixedWidth(getParamNameLabel(), widthProperty().subtract(30));
45+
46+
HBox.setMargin(checkBox, ELEMENT_OFFSET);
4947
}
5048

5149
/**
@@ -71,8 +69,11 @@ private void processChangeImpl(final Boolean newValue) {
7169
EXECUTOR_MANAGER.addFXTask(() -> {
7270
changed();
7371
setIgnoreListeners(true);
74-
reload();
75-
setIgnoreListeners(false);
72+
try {
73+
reload();
74+
} finally {
75+
setIgnoreListeners(false);
76+
}
7677
});
7778
}
7879

src/com/ss/editor/ui/control/material/ColorMaterialParamControl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ protected void createComponents() {
5757

5858
FXUtils.addToPane(colorPicker, this);
5959
FXUtils.addToPane(removeButton, this);
60+
FXUtils.addClassTo(colorPicker, CSSClasses.MAIN_FONT_13);
61+
FXUtils.addClassTo(removeButton, CSSClasses.TOOLBAR_BUTTON);
6062

6163
HBox.setMargin(colorPicker, ELEMENT_OFFSET);
6264
HBox.setMargin(removeButton, ELEMENT_OFFSET);
6365

64-
FXUtils.addClassTo(colorPicker, CSSClasses.MAIN_FONT_13);
65-
FXUtils.addClassTo(removeButton, CSSClasses.TOOLBAR_BUTTON);
6666
}
6767

6868
/**
@@ -93,8 +93,11 @@ private void processChangeImpl(final Color newValue) {
9393
EXECUTOR_MANAGER.addFXTask(() -> {
9494
changed();
9595
setIgnoreListeners(true);
96-
reload();
97-
setIgnoreListeners(false);
96+
try {
97+
reload();
98+
} finally {
99+
setIgnoreListeners(false);
100+
}
98101
});
99102
}
100103

@@ -116,8 +119,11 @@ private void removeColorImpl() {
116119
EXECUTOR_MANAGER.addFXTask(() -> {
117120
changed();
118121
setIgnoreListeners(true);
119-
reload();
120-
setIgnoreListeners(false);
122+
try {
123+
reload();
124+
} finally {
125+
setIgnoreListeners(false);
126+
}
121127
});
122128
}
123129

0 commit comments

Comments
 (0)