Fix dangling wires when remove input-connected part.
This commit is contained in:
parent
f63854c863
commit
82b6e7188c
@ -249,13 +249,14 @@ class CanvasView extends View implements PartGrid {
|
|||||||
}
|
}
|
||||||
else if (motionMode == MotionMode.Type.LongTouch) {
|
else if (motionMode == MotionMode.Type.LongTouch) {
|
||||||
if (selectedPart != null) {
|
if (selectedPart != null) {
|
||||||
|
selectedPart.getMoveable().drop(x, y);
|
||||||
|
|
||||||
if (inDropZone(x, y)) {
|
if (inDropZone(x, y)) {
|
||||||
Log.d("Canvas", "Deleting element" + selectedPart);
|
Log.d("Canvas", "Deleting element" + selectedPart);
|
||||||
parts.remove(selectedPart);
|
parts.remove(selectedPart);
|
||||||
|
selectedPart.unlink();
|
||||||
}
|
}
|
||||||
else {
|
invalidate();
|
||||||
selectedPart.getMoveable().drop(x, y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,4 +240,12 @@ public class RoundButton implements Part {
|
|||||||
public Moveable getMoveable() {
|
public Moveable getMoveable() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {
|
||||||
|
for (InputConnector input : getSignalInputConnectors()) {
|
||||||
|
input.unlink();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.codigoparallevar.minicards.types.Wire;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
|
||||||
import com.codigoparallevar.minicards.types.Moveable;
|
import com.codigoparallevar.minicards.types.Moveable;
|
||||||
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
|
||||||
@ -209,6 +210,13 @@ public class ColorBox implements Part {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {
|
||||||
|
for (InputConnector input : getSignalInputConnectors()) {
|
||||||
|
input.unlink();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getInputConnectorCenterX() {
|
public int getInputConnectorCenterX() {
|
||||||
return getLeft();
|
return getLeft();
|
||||||
}
|
}
|
||||||
|
@ -165,4 +165,11 @@ public class Placeholder implements Part {
|
|||||||
public Moveable getMoveable() {
|
public Moveable getMoveable() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {
|
||||||
|
for (InputConnector input : getSignalInputConnectors()) {
|
||||||
|
input.unlink();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,5 @@ package com.codigoparallevar.minicards.types;
|
|||||||
|
|
||||||
public interface Dropper<T extends Wire> {
|
public interface Dropper<T extends Wire> {
|
||||||
void drop(T wire);
|
void drop(T wire);
|
||||||
|
void unlinkWire(T wire);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,13 @@ public class RoundInputConnector implements SignalInputConnector {
|
|||||||
return new Wire(this, _xposition, _yposition);
|
return new Wire(this, _xposition, _yposition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {
|
||||||
|
for (Wire wire : _attachments) {
|
||||||
|
wire.unlink();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePosition(int x, int y) {
|
public void updatePosition(int x, int y) {
|
||||||
_xposition = x;
|
_xposition = x;
|
||||||
@ -80,4 +87,9 @@ public class RoundInputConnector implements SignalInputConnector {
|
|||||||
public void drop(Wire wire) {
|
public void drop(Wire wire) {
|
||||||
Log.d("InputConnector", "Dropped wire " + wire);
|
Log.d("InputConnector", "Dropped wire " + wire);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlinkWire(Wire wire) {
|
||||||
|
_attachments.remove(wire);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,9 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
|
|||||||
return _currentWire;
|
return _currentWire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlink() {}
|
||||||
|
|
||||||
private void startWire() {
|
private void startWire() {
|
||||||
_currentWire = new SignalWire(this, _centerX, _centerY);
|
_currentWire = new SignalWire(this, _centerX, _centerY);
|
||||||
}
|
}
|
||||||
@ -85,6 +88,11 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unlinkWire(SignalWire wire) {
|
||||||
|
_wires.remove(wire);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawWires(Canvas canvas, boolean devMode) {
|
public void drawWires(Canvas canvas, boolean devMode) {
|
||||||
for (SignalWire wire : _wires) {
|
for (SignalWire wire : _wires) {
|
||||||
|
@ -3,4 +3,5 @@ package com.codigoparallevar.minicards.types;
|
|||||||
public interface Selectable {
|
public interface Selectable {
|
||||||
boolean containsPoint(int x, int y);
|
boolean containsPoint(int x, int y);
|
||||||
Moveable getMoveable();
|
Moveable getMoveable();
|
||||||
|
void unlink();
|
||||||
}
|
}
|
||||||
|
@ -81,4 +81,9 @@ public class Wire<T extends WireDataType, InputConnectorType extends InputConnec
|
|||||||
public InputConnector getAttachedTo() {
|
public InputConnector getAttachedTo() {
|
||||||
return _attachedTo;
|
return _attachedTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unlink() {
|
||||||
|
_attachedTo = null;
|
||||||
|
_dropper.unlinkWire(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user