Fix dangling wires when remove input-connected part.

This commit is contained in:
kenkeiras 2017-10-31 00:06:46 +01:00
parent f63854c863
commit 82b6e7188c
9 changed files with 54 additions and 3 deletions

View File

@ -249,13 +249,14 @@ class CanvasView extends View implements PartGrid {
}
else if (motionMode == MotionMode.Type.LongTouch) {
if (selectedPart != null) {
selectedPart.getMoveable().drop(x, y);
if (inDropZone(x, y)) {
Log.d("Canvas", "Deleting element" + selectedPart);
parts.remove(selectedPart);
selectedPart.unlink();
}
else {
selectedPart.getMoveable().drop(x, y);
}
invalidate();
}
}

View File

@ -240,4 +240,12 @@ public class RoundButton implements Part {
public Moveable getMoveable() {
return this;
}
@Override
public void unlink() {
for (InputConnector input : getSignalInputConnectors()) {
input.unlink();
}
}
}

View File

@ -6,6 +6,7 @@ import android.graphics.Paint;
import android.graphics.Rect;
import android.util.Log;
import com.codigoparallevar.minicards.types.Wire;
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
import com.codigoparallevar.minicards.types.Moveable;
import com.codigoparallevar.minicards.types.connectors.input.SignalInputConnector;
@ -209,6 +210,13 @@ public class ColorBox implements Part {
return this;
}
@Override
public void unlink() {
for (InputConnector input : getSignalInputConnectors()) {
input.unlink();
}
}
public int getInputConnectorCenterX() {
return getLeft();
}

View File

@ -165,4 +165,11 @@ public class Placeholder implements Part {
public Moveable getMoveable() {
return this;
}
@Override
public void unlink() {
for (InputConnector input : getSignalInputConnectors()) {
input.unlink();
}
}
}

View File

@ -2,4 +2,5 @@ package com.codigoparallevar.minicards.types;
public interface Dropper<T extends Wire> {
void drop(T wire);
void unlinkWire(T wire);
}

View File

@ -35,6 +35,13 @@ public class RoundInputConnector implements SignalInputConnector {
return new Wire(this, _xposition, _yposition);
}
@Override
public void unlink() {
for (Wire wire : _attachments) {
wire.unlink();
}
}
@Override
public void updatePosition(int x, int y) {
_xposition = x;
@ -80,4 +87,9 @@ public class RoundInputConnector implements SignalInputConnector {
public void drop(Wire wire) {
Log.d("InputConnector", "Dropped wire " + wire);
}
@Override
public void unlinkWire(Wire wire) {
_attachments.remove(wire);
}
}

View File

@ -49,6 +49,9 @@ public class RoundOutputConnector implements Drawable, SignalOutputConnector {
return _currentWire;
}
@Override
public void unlink() {}
private void startWire() {
_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
public void drawWires(Canvas canvas, boolean devMode) {
for (SignalWire wire : _wires) {

View File

@ -3,4 +3,5 @@ package com.codigoparallevar.minicards.types;
public interface Selectable {
boolean containsPoint(int x, int y);
Moveable getMoveable();
void unlink();
}

View File

@ -81,4 +81,9 @@ public class Wire<T extends WireDataType, InputConnectorType extends InputConnec
public InputConnector getAttachedTo() {
return _attachedTo;
}
public void unlink() {
_attachedTo = null;
_dropper.unlinkWire(this);
}
}