From 38556e0ae9739452705b71fd6287288a8f844ecb Mon Sep 17 00:00:00 2001 From: Jon Robison Date: Sat, 6 Dec 2014 13:00:39 -0500 Subject: [PATCH] -Add rope joint support refs #9 --- .../mode/joint/window/rope/RopePlugin.java | 25 +++++++++++ .../mode/joint/window/rope/RopeWindow.java | 41 +++++++++++++++++++ .../gdxworld/world/joint/RopeJoint.java | 35 ++++++++-------- 3 files changed, 84 insertions(+), 17 deletions(-) create mode 100644 src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopePlugin.java create mode 100644 src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopeWindow.java diff --git a/src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopePlugin.java b/src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopePlugin.java new file mode 100644 index 0000000..4fa04c2 --- /dev/null +++ b/src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopePlugin.java @@ -0,0 +1,25 @@ +package com.blastedstudios.gdxworld.plugin.mode.joint.window.rope; + +import net.xeoh.plugins.base.annotations.PluginImplementation; + +import com.badlogic.gdx.physics.box2d.JointDef.JointType; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.blastedstudios.gdxworld.plugin.mode.joint.BaseJointWindow; +import com.blastedstudios.gdxworld.plugin.mode.joint.IJointWindow; +import com.blastedstudios.gdxworld.plugin.mode.joint.JointMode; +import com.blastedstudios.gdxworld.world.joint.RopeJoint; + +@PluginImplementation +public class RopePlugin implements IJointWindow{ + @Override public JointType getJointType() { + return JointType.RopeJoint; + } + + @Override public RopeJoint createJoint(RopeJoint joint) { + return joint == null ? new RopeJoint() : joint; + } + + @Override public BaseJointWindow createJointWindow(Skin skin, JointMode mode, RopeJoint joint) { + return new RopeWindow(skin, mode, joint); + } +} \ No newline at end of file diff --git a/src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopeWindow.java b/src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopeWindow.java new file mode 100644 index 0000000..a554cf1 --- /dev/null +++ b/src/com/blastedstudios/gdxworld/plugin/mode/joint/window/rope/RopeWindow.java @@ -0,0 +1,41 @@ +package com.blastedstudios.gdxworld.plugin.mode.joint.window.rope; + +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.physics.box2d.JointDef.JointType; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.blastedstudios.gdxworld.plugin.mode.joint.BaseJointWindow; +import com.blastedstudios.gdxworld.plugin.mode.joint.JointMode; +import com.blastedstudios.gdxworld.ui.leveleditor.VertexTable; +import com.blastedstudios.gdxworld.world.joint.RopeJoint; + +class RopeWindow extends BaseJointWindow { + private final VertexTable centerTable; + private final RopeJoint joint; + + public RopeWindow(Skin skin, JointMode mode, RopeJoint joint) { + super("Rope Editor", skin, JointType.RopeJoint, mode, joint); + this.joint = joint; + centerTable = new VertexTable(joint.getCenter(), skin); + add(new Label("Anchor: ", skin)); + add(centerTable); + row(); + add(createControlTable()).colspan(2); + pack(); + } + + @Override public void apply(){ + super.apply(); + joint.setCenter(centerTable.getVertex()); + } + + @Override public boolean clicked(Vector2 pos) { + if(!super.clicked(pos)) + centerTable.setVertex(pos.x, pos.y); + return true; + } + + @Override public Vector2 getCenter() { + return centerTable.getVertex(); + } +} diff --git a/src/com/blastedstudios/gdxworld/world/joint/RopeJoint.java b/src/com/blastedstudios/gdxworld/world/joint/RopeJoint.java index 2bdcb8f..fb37ad2 100644 --- a/src/com/blastedstudios/gdxworld/world/joint/RopeJoint.java +++ b/src/com/blastedstudios/gdxworld/world/joint/RopeJoint.java @@ -8,11 +8,7 @@ public class RopeJoint extends GDXJoint { private static final long serialVersionUID = 1L; private float maxLength; - private transient Vector2 center; - - public RopeJoint(Vector2 center){ - this.center = center; - } + private Vector2 center = new Vector2(); @Override public Joint attach(World world) { RopeJointDef def = new RopeJointDef(); @@ -20,29 +16,34 @@ public RopeJoint(Vector2 center){ return attach(world, def); } - public float getMaxLength() { - return maxLength; + @Override public Object clone() { + RopeJoint clone = new RopeJoint(); + clone.setMaxLength(maxLength); + clone.setCenter(center.cpy()); + return super.clone(clone); } - public void setMaxLength(float maxLength) { - this.maxLength = maxLength; + @Override public void translate(Vector2 center) { + center.add(center); + } + + @Override public void scl(float scalar) { + center.scl(scalar); } @Override public Vector2 getCenter() { return center.cpy(); } - @Override public Object clone() { - RopeJoint clone = new RopeJoint(center.cpy()); - clone.setMaxLength(maxLength); - return super.clone(clone); + public void setCenter(Vector2 center) { + this.center = center; } - @Override public void translate(Vector2 center) { - center.add(center); + public float getMaxLength() { + return maxLength; } - @Override public void scl(float scalar) { - center.scl(scalar); + public void setMaxLength(float maxLength) { + this.maxLength = maxLength; } }