Skip to content

Commit 941c4d0

Browse files
committed
finished integration with BetterCharacterControl
1 parent da6ec88 commit 941c4d0

4 files changed

Lines changed: 73 additions & 33 deletions

File tree

src/main/java/com/ss/editor/plugin/api/dialog/GenericFactoryDialog.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public class GenericFactoryDialog extends AbstractSimpleEditorDialog {
4040
* The list of all definitions.
4141
*/
4242
@NotNull
43-
private final Array<@NotNull PropertyDefinition> definitions;
43+
private final Array<PropertyDefinition> definitions;
4444

4545
/**
4646
* The handler to handle result properties.
4747
*/
4848
@NotNull
49-
private final Consumer<@NotNull VarTable> handler;
49+
private final Consumer<VarTable> handler;
5050

5151
/**
5252
* THe callback to call re-validating.
@@ -58,22 +58,22 @@ public class GenericFactoryDialog extends AbstractSimpleEditorDialog {
5858
* The validator of all properties.
5959
*/
6060
@NotNull
61-
private Predicate<@NotNull VarTable> validator;
61+
private Predicate<VarTable> validator;
6262

6363
/**
6464
* The root content container.
6565
*/
6666
@Nullable
6767
private VBox root;
6868

69-
public GenericFactoryDialog(@NotNull final Array<@NotNull PropertyDefinition> definitions,
70-
@NotNull final Consumer<@NotNull VarTable> handler) {
69+
public GenericFactoryDialog(@NotNull final Array<PropertyDefinition> definitions,
70+
@NotNull final Consumer<VarTable> handler) {
7171
this(definitions, handler, varTable -> true);
7272
}
7373

74-
public GenericFactoryDialog(@NotNull final Array<@NotNull PropertyDefinition> definitions,
75-
@NotNull final Consumer<@NotNull VarTable> handler,
76-
@NotNull final Predicate<@NotNull VarTable> validator) {
74+
public GenericFactoryDialog(@NotNull final Array<PropertyDefinition> definitions,
75+
@NotNull final Consumer<VarTable> handler,
76+
@NotNull final Predicate<VarTable> validator) {
7777
this.definitions = definitions;
7878
this.handler = handler;
7979
this.validator = validator;
@@ -84,7 +84,7 @@ public GenericFactoryDialog(@NotNull final Array<@NotNull PropertyDefinition> de
8484
}
8585

8686
/**
87-
* Sets the title.
87+
* Set the title.
8888
*
8989
* @param title the new title.
9090
*/
@@ -94,7 +94,7 @@ public void setTitle(@NotNull final String title) {
9494
}
9595

9696
/**
97-
* Sets the text to the OK button.
97+
* Set the text to the OK button.
9898
*
9999
* @param text the new text.
100100
*/
@@ -104,7 +104,7 @@ public void setButtonOkText(@NotNull final String text) {
104104
}
105105

106106
/**
107-
* Sets the text to the Close button.
107+
* Set the text to the close button.
108108
*
109109
* @param text the new text.
110110
*/
@@ -127,7 +127,7 @@ protected void createContent(@NotNull final VBox root) {
127127
}
128128

129129
/**
130-
* Gets the root to place controls.
130+
* Get the root to place controls.
131131
*
132132
* @return the root.
133133
*/
@@ -159,6 +159,8 @@ private void createControls() {
159159
}
160160

161161
/**
162+
* Get the list of all definitions.
163+
*
162164
* @return the list of all definitions.
163165
*/
164166
@FxThread

src/main/java/com/ss/editor/ui/control/property/builder/impl/DefaultControlPropertyBuilder.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static com.ss.editor.extension.property.EditablePropertyType.*;
44
import com.jme3.animation.Animation;
5-
import com.jme3.animation.LoopMode;
65
import com.jme3.animation.SkeletonControl;
76
import com.jme3.bullet.control.BetterCharacterControl;
87
import com.jme3.bullet.control.PhysicsControl;
@@ -12,9 +11,6 @@
1211
import com.jme3.bullet.objects.VehicleWheel;
1312
import com.jme3.cinematic.events.AbstractCinematicEvent;
1413
import com.jme3.cinematic.events.MotionEvent;
15-
import com.jme3.math.Quaternion;
16-
import com.jme3.math.Vector3f;
17-
import com.jme3.scene.Spatial;
1814
import com.jme3.scene.control.AbstractControl;
1915
import com.jme3.scene.control.Control;
2016
import com.jme3.scene.control.LightControl;
@@ -24,9 +20,6 @@
2420
import com.ss.editor.extension.property.SimpleProperty;
2521
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
2622
import com.ss.editor.ui.control.property.builder.PropertyBuilder;
27-
import com.ss.editor.ui.control.property.impl.*;
28-
import com.ss.rlib.ui.util.FXUtils;
29-
import javafx.scene.layout.VBox;
3023
import org.jetbrains.annotations.NotNull;
3124
import org.jetbrains.annotations.Nullable;
3225

@@ -78,7 +71,7 @@ private DefaultControlPropertyBuilder() {
7871

7972
final List<EditableProperty<?, ?>> properties = new ArrayList<>();
8073

81-
if(object instanceof VehicleWheel) {
74+
if (object instanceof VehicleWheel) {
8275

8376
final VehicleWheel control = (VehicleWheel) object;
8477

@@ -140,7 +133,7 @@ private DefaultControlPropertyBuilder() {
140133
Animation::getLength));
141134
}
142135

143-
if(object instanceof MotionEvent) {
136+
if (object instanceof MotionEvent) {
144137

145138
final MotionEvent control = (MotionEvent) object;
146139

@@ -173,7 +166,7 @@ private DefaultControlPropertyBuilder() {
173166
properties.add(new SimpleProperty<>(LIGHT_FROM_SCENE, Messages.MODEL_PROPERTY_LIGHT, control,
174167
LightControl::getLight, LightControl::setLight));
175168

176-
} else if(object instanceof BetterCharacterControl) {
169+
} else if (object instanceof BetterCharacterControl) {
177170

178171
final BetterCharacterControl control = (BetterCharacterControl) object;
179172

@@ -201,14 +194,14 @@ private DefaultControlPropertyBuilder() {
201194
properties.add(new SimpleProperty<>(BOOLEAN, Messages.MODEL_PROPERTY_IS_KINEMATIC_SPATIAL, control,
202195
RigidBodyControl::isKinematicSpatial, RigidBodyControl::setKinematicSpatial));
203196

204-
} else if(object instanceof SkeletonControl) {
197+
} else if (object instanceof SkeletonControl) {
205198

206199
final SkeletonControl control = (SkeletonControl) object;
207200

208201
properties.add(new SimpleProperty<>(BOOLEAN, Messages.MODEL_PROPERTY_IS_HARDWARE_SKINNING_PREFERRED, control,
209202
SkeletonControl::isHardwareSkinningPreferred, SkeletonControl::setHardwareSkinningPreferred));
210203

211-
} else if(object instanceof VehicleControl) {
204+
} else if (object instanceof VehicleControl) {
212205

213206
final VehicleControl control = (VehicleControl) object;
214207

src/main/java/com/ss/editor/ui/control/tree/action/impl/control/AbstractCreateControlAction.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import com.jme3.scene.control.Control;
66
import com.ss.editor.annotation.FxThread;
77
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
8-
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
98
import com.ss.editor.model.undo.impl.AddControlOperation;
109
import com.ss.editor.ui.control.tree.NodeTree;
10+
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
1111
import com.ss.editor.ui.control.tree.node.TreeNode;
1212
import org.jetbrains.annotations.NotNull;
1313

@@ -27,6 +27,10 @@ public AbstractCreateControlAction(@NotNull final NodeTree<?> nodeTree, @NotNull
2727
protected void process() {
2828
super.process();
2929

30+
if (isRequiredDialog()) {
31+
return;
32+
}
33+
3034
final TreeNode<?> treeNode = getNode();
3135
final Spatial parent = (Spatial) treeNode.getElement();
3236

@@ -38,11 +42,23 @@ protected void process() {
3842
}
3943

4044
/**
41-
* Create control control.
45+
* Return true if need a dialog to create a control.
46+
*
47+
* @return true if need a dialog to create a control.
48+
*/
49+
@FxThread
50+
protected boolean isRequiredDialog() {
51+
return false;
52+
}
53+
54+
/**
55+
* Create a control.
4256
*
43-
* @param parent the parent
44-
* @return the control
57+
* @param parent the parent.
58+
* @return the control.
4559
*/
4660
@FxThread
47-
protected abstract @NotNull Control createControl(@NotNull final Spatial parent);
61+
protected @NotNull Control createControl(@NotNull final Spatial parent) {
62+
throw new UnsupportedOperationException();
63+
}
4864
}

src/main/java/com/ss/editor/ui/control/tree/action/impl/control/physics/CreateCharacterControlAction.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package com.ss.editor.ui.control.tree.action.impl.control.physics;
22

3+
import static com.ss.editor.extension.property.EditablePropertyType.FLOAT;
4+
import static com.ss.rlib.util.ObjectUtils.notNull;
35
import com.jme3.bullet.control.BetterCharacterControl;
46
import com.jme3.bullet.control.CharacterControl;
57
import com.jme3.scene.Spatial;
6-
import com.jme3.scene.control.Control;
78
import com.ss.editor.Messages;
89
import com.ss.editor.annotation.FxThread;
10+
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
11+
import com.ss.editor.model.undo.impl.AddControlOperation;
12+
import com.ss.editor.plugin.api.dialog.GenericFactoryDialog;
13+
import com.ss.editor.plugin.api.property.PropertyDefinition;
914
import com.ss.editor.ui.Icons;
1015
import com.ss.editor.ui.control.tree.NodeTree;
1116
import com.ss.editor.ui.control.tree.action.impl.control.AbstractCreateControlAction;
1217
import com.ss.editor.ui.control.tree.node.TreeNode;
18+
import com.ss.rlib.util.array.Array;
19+
import com.ss.rlib.util.array.ArrayFactory;
1320
import javafx.scene.image.Image;
1421
import org.jetbrains.annotations.NotNull;
1522
import org.jetbrains.annotations.Nullable;
@@ -21,6 +28,10 @@
2128
*/
2229
public class CreateCharacterControlAction extends AbstractCreateControlAction {
2330

31+
private static final String PROPERTY_RADIUS = "radius";
32+
private static final String PROPERTY_HEIGHT = "height";
33+
private static final String PROPERTY_MASS = "mass";
34+
2435
public CreateCharacterControlAction(@NotNull final NodeTree<?> nodeTree, @NotNull final TreeNode<?> node) {
2536
super(nodeTree, node);
2637
}
@@ -39,8 +50,26 @@ public CreateCharacterControlAction(@NotNull final NodeTree<?> nodeTree, @NotNul
3950
}
4051

4152
@Override
42-
@FxThread
43-
protected @NotNull Control createControl(@NotNull final Spatial parent) {
44-
return new BetterCharacterControl(1F, 1F, 1F);
53+
protected void process() {
54+
55+
final Array<PropertyDefinition> definitions = ArrayFactory.newArray(PropertyDefinition.class);
56+
definitions.add(new PropertyDefinition(FLOAT, Messages.MODEL_PROPERTY_RADIUS, PROPERTY_RADIUS, 1F));
57+
definitions.add(new PropertyDefinition(FLOAT, Messages.MODEL_PROPERTY_HEIGHT, PROPERTY_HEIGHT, 1F));
58+
definitions.add(new PropertyDefinition(FLOAT, Messages.MODEL_PROPERTY_MASS, PROPERTY_MASS, 1F));
59+
60+
final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, vars -> {
61+
62+
final float radius = vars.getFloat(PROPERTY_RADIUS);
63+
final float height = vars.getFloat(PROPERTY_HEIGHT);
64+
final float mass = vars.getFloat(PROPERTY_MASS);
65+
66+
final TreeNode<?> treeNode = getNode();
67+
final Spatial parent = (Spatial) treeNode.getElement();
68+
69+
final NodeTree<ModelChangeConsumer> nodeTree = getNodeTree();
70+
final ModelChangeConsumer consumer = notNull(nodeTree.getChangeConsumer());
71+
consumer.execute(new AddControlOperation(new BetterCharacterControl(radius, height, mass), parent));
72+
});
73+
dialog.show();
4574
}
4675
}

0 commit comments

Comments
 (0)