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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,4 +240,12 @@ public class RoundButton implements Part {
|
||||
public Moveable getMoveable() {
|
||||
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.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();
|
||||
}
|
||||
|
@ -165,4 +165,11 @@ public class Placeholder implements Part {
|
||||
public Moveable getMoveable() {
|
||||
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> {
|
||||
void drop(T wire);
|
||||
void unlinkWire(T wire);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -3,4 +3,5 @@ package com.codigoparallevar.minicards.types;
|
||||
public interface Selectable {
|
||||
boolean containsPoint(int x, int y);
|
||||
Moveable getMoveable();
|
||||
void unlink();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user