Skip to content

Commit

Permalink
wip: fix some dropping bug in main chain when dropped from non main c…
Browse files Browse the repository at this point in the history
…hain
  • Loading branch information
SyntaxGalaxy committed Nov 29, 2024
1 parent 7e436a6 commit 5aacf3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public void dropBlock(float x, float y) {
}
} else if (draggingBean instanceof ActionBlockBean block) {
if (dropZone.canDrop(block, x, y)) {
hasNearbyTarget = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index) {
if (actionBlockBeanView == null)
continue;

actionBlockBeanView.setInsideCanva(true);
super.addView(actionBlockBeanView, i + index);

if (i == 0 && index == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public void dropToNearestTarget(ArrayList<ActionBlockBean> blocks, float x, floa
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.setMargins(0, BlockMarginConstants.CHAINED_ACTION_BLOCK_TOP_MARGIN, 0, 0);
int index = getIndex(x, y);
if (index == 0) {
index = 1;
if (index != 0) {
index -= 1;
}
addBlockBeans(blocks, index);
}
Expand All @@ -197,8 +197,8 @@ public void dropToNearestTarget(ArrayList<ActionBlockBean> blocks, float x, floa
public void dropToNearestTarget(ActionBlockBean block, float x, float y) {
if (canDrop(block, x, y)) {
int index = getIndex(x, y);
if (index == 0) {
index = 1;
if (index != 0) {
index -= 1;
}
ArrayList<ActionBlockBean> blocks = new ArrayList<ActionBlockBean>();
blocks.add(block);
Expand Down Expand Up @@ -249,15 +249,19 @@ public void addActionBlocksBeans(ArrayList<ActionBlockBean> actionBlocks, int in
else
addBlockBeans(actionBlocks, index);
} else {
if (actionBlocks.size() == 0)
return;
if (!(actionBlocks.get(actionBlocks.size() - 1) instanceof TerminatorBlockBean))
addBlockBeans(actionBlocks, index);
if (isTerminated())
throw new TerminatedDropZoneException();
else
throw new UnexpectedTerminatedException();
addBlockBeans(actionBlocks, blockBeans.size());
}
} else
throw new IndexOutOfBoundsException(index);
} else {
if (actionBlocks.size() == 0)
return;
if (!(actionBlocks.get(actionBlocks.size() - 1) instanceof TerminatorBlockBean))
addBlockBeans(actionBlocks, index);
else
throw new UnexpectedTerminatedException();
}
}

private void addBlockBeans(ArrayList<ActionBlockBean> actionBlocks, int index) {
Expand Down

0 comments on commit 5aacf3d

Please sign in to comment.