Skip to content

Commit d056e7c

Browse files
committed
- Added Refpoint to interactive actors
- Support for fast leave scene when double click
1 parent 9c1c12e commit d056e7c

File tree

15 files changed

+188
-79
lines changed

15 files changed

+188
-79
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/CanvasDrawer.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.badlogic.gdx.math.Matrix4;
2727
import com.badlogic.gdx.math.Polygon;
2828
import com.badlogic.gdx.math.Rectangle;
29+
import com.badlogic.gdx.math.Vector2;
2930
import com.bladecoder.engine.model.AnchorActor;
3031
import com.bladecoder.engine.model.BaseActor;
3132
import com.bladecoder.engine.model.InteractiveActor;
@@ -77,8 +78,9 @@ public void drawBBoxActors(Scene scn) {
7778
continue;
7879

7980
drawer.setColor(Scene.ACTOR_BBOX_COLOR);
80-
if(p.getTransformedVertices().length > 2)
81+
if (p.getTransformedVertices().length > 2)
8182
drawer.polygon(p.getTransformedVertices());
83+
8284
} else if (a instanceof AnchorActor) {
8385
drawer.setColor(Scene.ANCHOR_COLOR);
8486
drawer.line(p.getX() - Scene.ANCHOR_RADIUS, p.getY(), p.getX() + Scene.ANCHOR_RADIUS, p.getY());
@@ -119,19 +121,21 @@ public void drawSelectedActor(BaseActor selectedActor) {
119121
// Gdx.gl20.glLineWidth(3);
120122
Gdx.gl20.glEnable(GL20.GL_BLEND);
121123
// Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
122-
124+
123125
drawer.setProjectionMatrix(camera.combined);
124-
// drawer.setTransformMatrix(new Matrix4());
125-
126+
// drawer.setTransformMatrix(new Matrix4());
127+
126128
if (selectedActor instanceof AnchorActor) {
127129
drawer.begin(ShapeRenderer.ShapeType.Line);
128130
drawer.setColor(MOUSESELECTION_STROKE_COLOR);
129-
drawer.rect(selectedActor.getX() - Scene.ANCHOR_RADIUS, selectedActor.getY() - Scene.ANCHOR_RADIUS,
131+
drawer.rect(selectedActor.getX() - Scene.ANCHOR_RADIUS, selectedActor.getY() - Scene.ANCHOR_RADIUS,
130132
Scene.ANCHOR_RADIUS * 2, Scene.ANCHOR_RADIUS * 2);
131133
drawer.end();
132134
} else {
133135

134-
Rectangle rect = selectedActor.getBBox().getBoundingRectangle();
136+
Polygon p = selectedActor.getBBox();
137+
138+
Rectangle rect = p.getBoundingRectangle();
135139

136140
drawer.begin(ShapeRenderer.ShapeType.Filled);
137141
drawer.setColor(MOUSESELECTION_FILL_COLOR);
@@ -149,7 +153,16 @@ public void drawSelectedActor(BaseActor selectedActor) {
149153
for (int i = 0; i < verts.length; i += 2)
150154
drawer.rect(verts[i] - CORNER_DIST / 2, verts[i + 1] - CORNER_DIST / 2, CORNER_DIST, CORNER_DIST);
151155
}
152-
156+
157+
// DRAW REFPOINT
158+
if (selectedActor instanceof InteractiveActor) {
159+
Vector2 refPoint = ((InteractiveActor) selectedActor).getRefPoint();
160+
float orgX = selectedActor.getX() + refPoint.x;
161+
float orgY = selectedActor.getY() + refPoint.y;
162+
drawer.line(orgX - Scene.ANCHOR_RADIUS, orgY, orgX + Scene.ANCHOR_RADIUS, orgY);
163+
drawer.line(orgX, orgY - Scene.ANCHOR_RADIUS, orgX, orgY + Scene.ANCHOR_RADIUS);
164+
}
165+
153166
drawer.end();
154167
}
155168

adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ScnWidgetInputListener.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.badlogic.gdx.scenes.scene2d.utils.UIUtils;
2828
import com.bladecoder.engine.model.AnchorActor;
2929
import com.bladecoder.engine.model.BaseActor;
30+
import com.bladecoder.engine.model.InteractiveActor;
3031
import com.bladecoder.engine.model.Scene;
3132
import com.bladecoder.engine.model.SpriteActor;
3233
import com.bladecoder.engine.util.PolygonUtils;
@@ -41,7 +42,7 @@ public class ScnWidgetInputListener extends ClickListener {
4142
private final ScnWidget scnWidget;
4243

4344
private static enum DraggingModes {
44-
NONE, DRAGGING_ACTOR, DRAGGING_BBOX_POINT, DRAGGING_WALKZONE, DRAGGING_WALKZONE_POINT, DRAGGING_MARKER_0, DRAGGING_MARKER_100
45+
NONE, DRAGGING_ACTOR, DRAGGING_BBOX_POINT, DRAGGING_WALKZONE, DRAGGING_WALKZONE_POINT, DRAGGING_MARKER_0, DRAGGING_MARKER_100, DRAGGING_ORIGIN
4546
};
4647

4748
private DraggingModes draggingMode = DraggingModes.NONE;
@@ -162,6 +163,21 @@ public boolean touchDown(InputEvent event, float x, float y, int pointer, int bu
162163
}
163164

164165
}
166+
167+
// SELACTOR ORIGIN DRAGGING
168+
if (selActor != null && selActor instanceof InteractiveActor) {
169+
Vector2 refPoint = ((InteractiveActor) selActor).getRefPoint();
170+
171+
float orgX = selActor.getX() + refPoint.x;
172+
float orgY = selActor.getY() + refPoint.y;
173+
174+
float dst = Vector2.dst(p.x, p.y, orgX, orgY);
175+
176+
if (dst < Scene.ANCHOR_RADIUS) {
177+
draggingMode = DraggingModes.DRAGGING_ORIGIN;
178+
return true;
179+
}
180+
}
165181

166182
// SELACTOR VERTEXs DRAGGING
167183
if (selActor != null
@@ -237,11 +253,13 @@ public void touchDragged(InputEvent event, float x, float y, int pointer) {
237253
d.sub(org);
238254
org.add(d);
239255

240-
if (draggingMode == DraggingModes.DRAGGING_ACTOR) {
241-
256+
if (draggingMode == DraggingModes.DRAGGING_ACTOR) {
242257
selActor.setPosition(selActor.getX()+ d.x, selActor.getY() + d.y);
243258
Ctx.project.setModified(this, Project.POSITION_PROPERTY, null, selActor);
244-
259+
} else if (draggingMode == DraggingModes.DRAGGING_ORIGIN) {
260+
Vector2 refPoint = ((InteractiveActor)selActor).getRefPoint();
261+
refPoint.add(d.x, d.y);
262+
Ctx.project.setModified();
245263
} else if (draggingMode == DraggingModes.DRAGGING_BBOX_POINT) {
246264
Polygon poly = selActor.getBBox();
247265

adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/WorldProps.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ protected void updateModel(String property, String value) {
5252
} else if (property.equals(Config.UI_MODE)) {
5353
Ctx.project.getProjectConfig().setProperty(Config.UI_MODE, value);
5454
} else if (property.equals(Config.SINGLE_ACTION_INVENTORY)) {
55-
Ctx.project.getProjectConfig().setProperty(Config.SINGLE_ACTION_INVENTORY, value);
55+
Ctx.project.getProjectConfig().setProperty(Config.SINGLE_ACTION_INVENTORY, value);
56+
} else if (property.equals(Config.FAST_LEAVE)) {
57+
Ctx.project.getProjectConfig().setProperty(Config.FAST_LEAVE, value);
5658
} else if (property.equals(Config.DEBUG_PROP)) {
5759
Ctx.project.getProjectConfig().setProperty(Config.DEBUG_PROP, value);
5860
} else if (property.equals(Config.SHOW_DESC_PROP)) {
@@ -78,6 +80,8 @@ private void setProject() {
7880
addProperty(Config.UI_MODE, Ctx.project.getProjectConfig().getProperty(Config.UI_MODE, "TWO_BUTTONS").toUpperCase(), new String[] {"TWO_BUTTONS", "PIE", "SINGLE_CLICK"});
7981
addProperty(Config.SINGLE_ACTION_INVENTORY, Boolean
8082
.parseBoolean(Ctx.project.getProjectConfig().getProperty(Config.SINGLE_ACTION_INVENTORY, "false")));
83+
addProperty(Config.FAST_LEAVE, Boolean
84+
.parseBoolean(Ctx.project.getProjectConfig().getProperty(Config.FAST_LEAVE, "false")));
8185
addProperty(Config.DEBUG_PROP,
8286
Boolean.parseBoolean(Ctx.project.getProjectConfig().getProperty(Config.DEBUG_PROP, "false")));
8387
addProperty(Config.SHOW_DESC_PROP,

adventure-editor/src/main/resources/projectTmpl/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ gdxVersion=%LIBGDX_VERSION%
44
roboVMVersion=%ROBOVM_VERSION%
55

66
org.gradle.daemon=true
7-
org.gradle.jvmargs=-Xms128m -Xmx512m
7+
org.gradle.jvmargs=-Xms128m -Xmx1500m
88
org.gradle.configureondemand=true
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#Autogenerated by build.gradle
2-
#Fri May 13 13:49:35 CEST 2016
2+
#Thu May 19 14:54:45 CEST 2016
33
roboVMVersion=1.12.0
44
gwtVersion=2.6.0
5-
libgdxVersion=1.9.3-SNAPSHOT
5+
libgdxVersion=1.9.3
66
androidAPILevel=20
77
buildToolsVersion=23.0.1
88
roboVMGradlePluginVersion=1.12.0
9-
version=0.9.11
9+
version=0.9.12-SNAPSHOT
1010
gwtGradlePluginVersion=0.6
1111
androidGradlePluginVersion=1.5.0

blade-engine/src/com/bladecoder/engine/actions/GotoAction.java

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import com.badlogic.gdx.math.Vector2;
2020
import com.bladecoder.engine.actions.Param.Type;
2121
import com.bladecoder.engine.assets.EngineAssetManager;
22-
import com.bladecoder.engine.model.AnchorActor;
2322
import com.bladecoder.engine.model.BaseActor;
2423
import com.bladecoder.engine.model.CharacterActor;
25-
import com.bladecoder.engine.model.SpriteActor;
24+
import com.bladecoder.engine.model.InteractiveActor;
2625
import com.bladecoder.engine.model.VerbRunner;
2726
import com.bladecoder.engine.model.World;
2827

@@ -40,61 +39,45 @@ public enum Align {
4039
@ActionPropertyDescription("The position to walk to")
4140
private Vector2 pos;
4241

43-
@ActionPropertyDescription("Walks to the target actor position")
42+
@ActionPropertyDescription("Walks to this actor")
4443
@ActionProperty(type = Type.ACTOR)
4544
private String target;
4645

47-
@ActionProperty(defaultValue = "CENTER")
48-
@ActionPropertyDescription("When selecting a target actor, an align can be selected")
49-
private Align align = Align.CENTER;
50-
51-
@ActionProperty
52-
@ActionPropertyDescription("When selecting a target actor, the relative distance to the anchor in each axis")
53-
private Vector2 distance;
54-
5546
@ActionProperty(required = true, defaultValue = "true")
5647
@ActionPropertyDescription("If this param is 'false' the text is showed and the action continues inmediatly")
5748
private boolean wait = true;
5849

5950
@Override
6051
public boolean run(VerbRunner cb) {
6152

62-
float scale = EngineAssetManager.getInstance().getScale();
63-
6453
CharacterActor actor = (CharacterActor) World.getInstance().getCurrentScene().getActor(this.actor, false);
54+
55+
float x = actor.getX();
56+
float y = actor.getY();
6557

6658
if (target != null) {
6759
BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
68-
float x = target.getX();
69-
float y = target.getY();
70-
float targetBBoxWidth2 = 0;
71-
final float actorBBoxWidth2 = actor.getBBox().getBoundingRectangle().width / 2;
72-
73-
if (!(target instanceof AnchorActor)) {
74-
targetBBoxWidth2 = target.getBBox().getBoundingRectangle().width / 2;
60+
61+
x = target.getX();
62+
y = target.getY();
63+
64+
if(target instanceof InteractiveActor) {
65+
Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
66+
x+= refPoint.x;
67+
y+= refPoint.y;
7568
}
76-
77-
switch (align) {
78-
case LEFT:
79-
x = x - targetBBoxWidth2 - actorBBoxWidth2;
80-
break;
81-
case RIGHT:
82-
x = x + targetBBoxWidth2 + actorBBoxWidth2;
83-
break;
84-
case CENTER:
85-
if (!(target instanceof SpriteActor))
86-
x = x + targetBBoxWidth2;
87-
break;
88-
}
89-
90-
if (distance != null) {
91-
x += distance.x;
92-
y += distance.y;
93-
}
94-
95-
actor.goTo(new Vector2(x, y), wait ? cb : null);
96-
} else
97-
actor.goTo(new Vector2(pos.x * scale, pos.y * scale), wait ? cb : null);
69+
} else if(pos != null){
70+
float scale = EngineAssetManager.getInstance().getScale();
71+
72+
x = pos.x * scale;
73+
y = pos.y * scale;
74+
}
75+
76+
// returns if the actor is already in the target position.
77+
if(actor.getX() == x && actor.getY() == y)
78+
return false;
79+
80+
actor.goTo(new Vector2(x, y), wait ? cb : null);
9881

9982
return wait;
10083
}

blade-engine/src/com/bladecoder/engine/actions/PositionAction.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,52 @@
1818
import com.badlogic.gdx.math.Vector2;
1919
import com.bladecoder.engine.assets.EngineAssetManager;
2020
import com.bladecoder.engine.model.BaseActor;
21+
import com.bladecoder.engine.model.InteractiveActor;
2122
import com.bladecoder.engine.model.Scene;
2223
import com.bladecoder.engine.model.VerbRunner;
2324

2425
@ActionDescription("Sets actor position.")
2526
public class PositionAction implements Action {
2627
@ActionProperty( required = true)
27-
@ActionPropertyDescription("The target actor")
28+
@ActionPropertyDescription("The actor to change his position")
2829
private SceneActorRef actor;
2930

3031
@ActionProperty
3132
@ActionPropertyDescription("The position to set")
3233
private Vector2 position;
3334

3435
@ActionProperty
35-
@ActionPropertyDescription("Sets the position of this actor")
36-
private SceneActorRef anchor;
36+
@ActionPropertyDescription("Sets the position from this actor")
37+
private SceneActorRef target;
3738

3839
@Override
3940
public boolean run(VerbRunner cb) {
4041
Scene s = actor.getScene();
4142

4243
BaseActor a = s.getActor(actor.getActorId(), true);
44+
45+
float x = a.getX();
46+
float y = a.getY();
4347

4448
if (position != null) {
4549
float scale = EngineAssetManager.getInstance().getScale();
50+
x = position.x * scale;
51+
y = position.y * scale;
4652

47-
a.setPosition(position.x * scale, position.y * scale);
48-
} else if(anchor != null) {
49-
BaseActor anchorActor = s.getActor(anchor.getActorId(), true);
53+
} else if(target != null) {
54+
BaseActor anchorActor = s.getActor(target.getActorId(), true);
5055

51-
a.setPosition(anchorActor.getX(), anchorActor.getY());
56+
x = anchorActor.getX();
57+
y = anchorActor.getY();
58+
59+
if(anchorActor instanceof InteractiveActor) {
60+
Vector2 refPoint = ((InteractiveActor) anchorActor).getRefPoint();
61+
x+= refPoint.x;
62+
y+= refPoint.y;
63+
}
5264
}
65+
66+
a.setPosition(x, y);
5367

5468
return false;
5569
}

blade-engine/src/com/bladecoder/engine/actions/PositionAnimAction.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.bladecoder.engine.anim.Tween;
2121
import com.bladecoder.engine.assets.EngineAssetManager;
2222
import com.bladecoder.engine.model.BaseActor;
23+
import com.bladecoder.engine.model.InteractiveActor;
2324
import com.bladecoder.engine.model.SpriteActor;
2425
import com.bladecoder.engine.model.VerbRunner;
2526
import com.bladecoder.engine.model.World;
@@ -31,15 +32,15 @@ public enum Mode {
3132
DURATION, SPEED
3233
}
3334

34-
@ActionPropertyDescription("The actor to move")
35-
@ActionProperty(type = Type.ACTOR)
35+
@ActionPropertyDescription("The moving actor")
36+
@ActionProperty(type = Type.ACTOR, required=true)
3637
private String actor;
3738

38-
@ActionProperty(required = true)
39+
@ActionProperty
3940
@ActionPropertyDescription("The target position")
4041
private Vector2 pos;
4142

42-
@ActionPropertyDescription("Sets the actor position as target")
43+
@ActionPropertyDescription("Sets the position from this actor")
4344
@ActionProperty(type = Type.ACTOR)
4445
private String target;
4546

@@ -76,15 +77,23 @@ public boolean run(VerbRunner cb) {
7677

7778
BaseActor a = World.getInstance().getCurrentScene().getActor(actor, false);
7879

79-
float x,y;
80+
float x = a.getX();
81+
float y = a.getY();
8082

81-
if (target == null) {
83+
if (pos != null) {
8284
x = pos.x * scale;
8385
y = pos.y * scale;
84-
} else {
86+
} else if(target != null){
8587
BaseActor target = World.getInstance().getCurrentScene().getActor(this.target, false);
88+
8689
x = target.getX();
8790
y = target.getY();
91+
92+
if(target instanceof InteractiveActor) {
93+
Vector2 refPoint = ((InteractiveActor) target).getRefPoint();
94+
x+= refPoint.x;
95+
y+= refPoint.y;
96+
}
8897
}
8998

9099
if (speed == 0 || !(a instanceof SpriteActor)) {

0 commit comments

Comments
 (0)