Skip to content

Commit d27570c

Browse files
committed
Implemented a dialog to creatre a custom control,
added an example of an editable control.
1 parent 3372bdc commit d27570c

File tree

15 files changed

+351
-13
lines changed

15 files changed

+351
-13
lines changed

jme3-spaceshift-extension/src/com/ss/extension/scene/control/EditableControl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public interface EditableControl extends Control {
1717

1818
Array<EditableProperty<?, ?>> EMPTY_PROPERTIES = ArrayFactory.newArray(EditableProperty.class);
1919

20+
/**
21+
* @return the control's name.
22+
*/
23+
default String getName() {
24+
return getClass().getSimpleName();
25+
}
26+
2027
/**
2128
* Get list of editable properties.
2229
*
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.ss.extension.scene.control.impl;
2+
3+
import com.jme3.scene.control.BillboardControl;
4+
import com.ss.extension.property.EditableProperty;
5+
import com.ss.extension.property.EditablePropertyType;
6+
import com.ss.extension.property.SimpleProperty;
7+
import com.ss.extension.scene.control.EditableControl;
8+
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import rlib.util.array.Array;
12+
import rlib.util.array.ArrayFactory;
13+
14+
/**
15+
* The editable implementation of the {@link BillboardControl}.
16+
*
17+
* @author JavaSaBr
18+
*/
19+
public class EditableBillboardControl extends BillboardControl implements EditableControl {
20+
21+
@Override
22+
public String getName() {
23+
return "Billboard";
24+
}
25+
26+
@NotNull
27+
@Override
28+
public Array<EditableProperty<?, ?>> getEditableProperties() {
29+
30+
final Array<EditableProperty<?, ?>> result = ArrayFactory.newArray(EditableProperty.class);
31+
32+
result.add(new SimpleProperty<>(EditablePropertyType.ENUM, "Alignment", this,
33+
BillboardControl::getAlignment, BillboardControl::setAlignment));
34+
35+
return result;
36+
}
37+
}
679 Bytes
Binary file not shown.
1.58 KB
Binary file not shown.

resources/messages/messages.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ ModelNodeTreeActionAddControl=Control
184184
ModelNodeTreeActionAddControlRigidBody=Rigid body
185185
ModelNodeTreeActionAddControlMotion=Motion
186186
ModelNodeTreeActionAddControlCharacter=Character
187+
ModelNodeTreeActionAddControlCustom=Custom
187188
188189
ModelPropertyCullHint=Cull Hint
189190
ModelPropertyShadowMode=Shadow mode
@@ -409,4 +410,9 @@ AddUserDataDialogName=Name
409410
AddUserDataDialogDataType=Data type
410411
AddUserDataDialogButtonOk=Add
411412
413+
CreateCustomControlDialogTitle=Add new custom control
414+
CreateCustomControlDialogBuiltIn=Built in
415+
CreateCustomControlDialogCustomBox=Custom
416+
CreateCustomControlDialogCustomField=Class full name
417+
412418
AnalyticsConfirmDialogMessage=Do you allow to activate Google Analytics for this editor? It helps us to improve a quality of this editor.

resources/messages/messages_ru.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ ModelNodeTreeActionAddControl=Контрол
184184
ModelNodeTreeActionAddControlRigidBody=Твердое тело
185185
ModelNodeTreeActionAddControlMotion=Движение
186186
ModelNodeTreeActionAddControlCharacter=Персонаж
187+
ModelNodeTreeActionAddControlCustom=Пользовательский
187188
188189
ModelPropertyCullHint=Cull Hint
189190
ModelPropertyShadowMode=Режим теней
@@ -409,4 +410,9 @@ AddUserDataDialogName=Название
409410
AddUserDataDialogDataType=Тип данных
410411
AddUserDataDialogButtonOk=Добавить
411412
413+
CreateCustomControlDialogTitle=Добавление нового польз. контрола
414+
CreateCustomControlDialogBuiltIn=Встроенные
415+
CreateCustomControlDialogCustomBox=Свой
416+
CreateCustomControlDialogCustomField=Полное название класса
417+
412418
AnalyticsConfirmDialogMessage=Разрешите ли вы активировать Google аналитику для этого редактора? Это поможет нам улучшить качество редактора.

src/com/ss/editor/Messages.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public class Messages {
201201
public static final String MODEL_NODE_TREE_ACTION_ADD_CONTROL_RIGID_BODY;
202202
public static final String MODEL_NODE_TREE_ACTION_ADD_CONTROL_NOTION;
203203
public static final String MODEL_NODE_TREE_ACTION_ADD_CONTROL_CHARACTER;
204+
public static final String MODEL_NODE_TREE_ACTION_ADD_CONTROL_CUSTOM;
204205

205206
public static final String MODEL_PROPERTY_CULL_HINT;
206207
public static final String MODEL_PROPERTY_SHADOW_MODE;
@@ -426,6 +427,11 @@ public class Messages {
426427
public static final String ADD_USER_DATA_DIALOG_DATA_TYPE;
427428
public static final String ADD_USER_DATA_DIALOG_BUTTON_OK;
428429

430+
public static final String CREATE_CUSTOM_CONTROL_DIALOG_TITLE;
431+
public static final String CREATE_CUSTOM_CONTROL_DIALOG_BUILT_IN;
432+
public static final String CREATE_CUSTOM_CONTROL_DIALOG_CUSTOM_BOX;
433+
public static final String CREATE_CUSTOM_CONTROL_DIALOG_CUSTOM_FIELD;
434+
429435
public static final String ANALYTICS_CONFIRM_DIALOG_MESSAGE;
430436

431437
static {
@@ -631,6 +637,7 @@ public class Messages {
631637
MODEL_NODE_TREE_ACTION_ADD_CONTROL_RIGID_BODY = bundle.getString("ModelNodeTreeActionAddControlRigidBody");
632638
MODEL_NODE_TREE_ACTION_ADD_CONTROL_NOTION = bundle.getString("ModelNodeTreeActionAddControlMotion");
633639
MODEL_NODE_TREE_ACTION_ADD_CONTROL_CHARACTER = bundle.getString("ModelNodeTreeActionAddControlCharacter");
640+
MODEL_NODE_TREE_ACTION_ADD_CONTROL_CUSTOM = bundle.getString("ModelNodeTreeActionAddControlCustom");
634641

635642
MODEL_PROPERTY_CULL_HINT = bundle.getString("ModelPropertyCullHint");
636643
MODEL_PROPERTY_SHADOW_MODE = bundle.getString("ModelPropertyShadowMode");
@@ -856,6 +863,11 @@ public class Messages {
856863
ADD_USER_DATA_DIALOG_DATA_TYPE = bundle.getString("AddUserDataDialogDataType");
857864
ADD_USER_DATA_DIALOG_BUTTON_OK = bundle.getString("AddUserDataDialogButtonOk");
858865

866+
CREATE_CUSTOM_CONTROL_DIALOG_TITLE = bundle.getString("CreateCustomControlDialogTitle");
867+
CREATE_CUSTOM_CONTROL_DIALOG_BUILT_IN = bundle.getString("CreateCustomControlDialogBuiltIn");
868+
CREATE_CUSTOM_CONTROL_DIALOG_CUSTOM_BOX = bundle.getString("CreateCustomControlDialogCustomBox");
869+
CREATE_CUSTOM_CONTROL_DIALOG_CUSTOM_FIELD = bundle.getString("CreateCustomControlDialogCustomField");
870+
859871
ANALYTICS_CONFIRM_DIALOG_MESSAGE = bundle.getString("AnalyticsConfirmDialogMessage");
860872
}
861873
}

src/com/ss/editor/ui/control/model/node/control/ControlModelNode.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.ss.editor.ui.control.model.tree.action.RemoveControlAction;
66
import com.ss.editor.ui.control.tree.AbstractNodeTree;
77
import com.ss.editor.ui.control.tree.node.ModelNode;
8+
import com.ss.extension.scene.control.EditableControl;
89

910
import org.jetbrains.annotations.NotNull;
1011
import org.jetbrains.annotations.Nullable;
@@ -39,6 +40,13 @@ public Image getIcon() {
3940
@NotNull
4041
@Override
4142
public String getName() {
42-
return getElement().getClass().getSimpleName();
43+
44+
final T element = getElement();
45+
46+
if (element instanceof EditableControl) {
47+
return ((EditableControl) element).getName();
48+
}
49+
50+
return element.getClass().getSimpleName();
4351
}
4452
}

src/com/ss/editor/ui/control/model/node/spatial/SpatialModelNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.ss.editor.ui.control.model.tree.action.RemoveNodeAction;
1919
import com.ss.editor.ui.control.model.tree.action.RenameNodeAction;
2020
import com.ss.editor.ui.control.model.tree.action.control.CreateCharacterAction;
21+
import com.ss.editor.ui.control.model.tree.action.control.CreateCustomControlAction;
2122
import com.ss.editor.ui.control.model.tree.action.control.CreateMotionControlAction;
2223
import com.ss.editor.ui.control.model.tree.action.control.CreateRigidBodyControlAction;
2324
import com.ss.editor.ui.control.model.tree.action.operation.RenameNodeOperation;
@@ -66,7 +67,8 @@ protected Menu createCreationMenu(@NotNull final AbstractNodeTree<?> nodeTree) {
6667
final Menu menu = new Menu(Messages.MODEL_NODE_TREE_ACTION_CREATE, new ImageView(Icons.ADD_18));
6768

6869
final Menu createControlsMenu = new Menu(Messages.MODEL_NODE_TREE_ACTION_ADD_CONTROL, new ImageView(Icons.ADD_18));
69-
createControlsMenu.getItems().addAll(new CreateRigidBodyControlAction(nodeTree, this),
70+
createControlsMenu.getItems().addAll(new CreateCustomControlAction(nodeTree, this),
71+
new CreateRigidBodyControlAction(nodeTree, this),
7072
new CreateMotionControlAction(nodeTree, this),
7173
new CreateCharacterAction(nodeTree, this));
7274

src/com/ss/editor/ui/control/model/property/builder/impl/EditableControlPropertyBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.jme3.math.Vector2f;
55
import com.jme3.math.Vector3f;
66
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
7-
import com.ss.editor.model.undo.editor.SceneChangeConsumer;
87
import com.ss.editor.ui.control.model.property.control.BooleanModelPropertyControl;
98
import com.ss.editor.ui.control.model.property.control.ColorModelPropertyControl;
109
import com.ss.editor.ui.control.model.property.control.EnumControlPropertyControl;
@@ -34,7 +33,7 @@
3433
*
3534
* @author JavaSaBr
3635
*/
37-
public class EditableControlPropertyBuilder extends AbstractPropertyBuilder<SceneChangeConsumer> {
36+
public class EditableControlPropertyBuilder extends AbstractPropertyBuilder<ModelChangeConsumer> {
3837

3938
private static final EditableControlPropertyBuilder INSTANCE = new EditableControlPropertyBuilder();
4039

@@ -43,12 +42,12 @@ public static EditableControlPropertyBuilder getInstance() {
4342
}
4443

4544
protected EditableControlPropertyBuilder() {
46-
super(SceneChangeConsumer.class);
45+
super(ModelChangeConsumer.class);
4746
}
4847

4948
@Override
5049
protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent, @NotNull final VBox container,
51-
@NotNull final SceneChangeConsumer changeConsumer) {
50+
@NotNull final ModelChangeConsumer changeConsumer) {
5251

5352
if (!(object instanceof EditableControl)) return;
5453

0 commit comments

Comments
 (0)