Skip to content

Commit

Permalink
Copy/paste frames fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jindrapetrik committed Nov 9, 2023
1 parent 0a66e48 commit 6a3c2ac
Showing 1 changed file with 59 additions and 51 deletions.
110 changes: 59 additions & 51 deletions src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3743,47 +3743,78 @@ public void copyOrMoveFrames(Set<TreeItem> items, boolean move, Timelined target
return;
}

Timelined sourceTimelined = ((Frame) items.iterator().next()).timeline.timelined;

final boolean USE_REMOVE_TAG = false;

int positionMinus = 0;


int posPrevFrame = position - 1;

int posTargetFrame = position;
if (move && sourceTimelined == targetTimelined) {
Set<Integer> removedFrames = new LinkedHashSet<>();
for (TreeItem item : items) {
Frame frame = (Frame) item;
int removedFrameNum = frame.frame + 1;
removedFrames.add(removedFrameNum);
if (removedFrameNum < position) {
positionMinus++;
}
}
while (removedFrames.contains(posPrevFrame)) {
posPrevFrame--;
}
while (removedFrames.contains(posTargetFrame)) {
posTargetFrame++;
}
}

Frame targetFrame = targetTimelined.getTimeline().getFrame(posTargetFrame - 1);

Frame targetFrame = targetTimelined.getTimeline().getFrame(position - 1);
Frame prevTargetFrame;
if (position == 1) {
if (posPrevFrame == 0) {
prevTargetFrame = null;
} else {
prevTargetFrame = targetTimelined.getTimeline().getFrame(position - 2);
prevTargetFrame = targetTimelined.getTimeline().getFrame(posPrevFrame - 1);
}

int positionAfterDelete = position - positionMinus;

if (move) {
removeFrames(items);
}
int f = 1;
int fc = 0;
boolean endsWithShowframe = false;
int prevShowFrameIndex = -1;
ShowFrameTag prevShowFrame = null;
ShowFrameTag prevShowFrame = null;
int f = 1;
for (int i = 0; i < targetTimelined.getTags().size(); i++) {
Tag t = targetTimelined.getTags().get(i);
endsWithShowframe = false;
if (t instanceof ShowFrameTag) {
f++;
endsWithShowframe = true;
if (f == position) {
prevShowFrameIndex = i;
if (f == positionAfterDelete) {
prevShowFrame = (ShowFrameTag) t;
}
}
}


if (move) {
removeFrames(items);
}
SWF swf = targetTimelined.getSwf();

List<Tag> newFrameTags = new ArrayList<>();

int prevShowFrameIndex;
if (targetFrame == null) {
if (!endsWithShowframe) {
ShowFrameTag showFrame = new ShowFrameTag(swf);
newFrameTags.add(showFrame);
}
prevShowFrameIndex = targetTimelined.getTags().size() - 1;
} else {
prevShowFrameIndex = targetTimelined.getTags().indexOf(prevShowFrame);
}

}


SWF swf = targetTimelined.getSwf();
List<Tag> newFrameTags = new ArrayList<>();
Frame frame = null;
for (TreeItem item : items) {
frame = (Frame) item;
Expand Down Expand Up @@ -3842,11 +3873,6 @@ public void copyOrMoveFrames(Set<TreeItem> items, boolean move, Timelined target
if (sourceState == null && targetState == null) {
continue;
}
boolean changed = false;
if (sourceState != null && !sourceState.equals(targetState)
|| (targetState.placeFrame.frame < targetFrame.frame)) {
changed = true;
}
if (sourceState != null && targetState != null
&& sourceState.equals(targetState)
&& targetState.placeFrame.frame == targetFrame.frame
Expand All @@ -3861,40 +3887,23 @@ public void copyOrMoveFrames(Set<TreeItem> items, boolean move, Timelined target
&& !sourceState.equals(targetState)
) {
PlaceObjectTypeTag fullPlace = targetState.toPlaceObjectTag(depth);
if (changed) {
if (USE_REMOVE_TAG) {
RemoveObject2Tag rem = new RemoveObject2Tag(swf);
rem.depth = depth;
newFrameTags.add(rem);
} else {
fullPlace.setPlaceFlagMove(true);
}
if (USE_REMOVE_TAG) {
RemoveObject2Tag rem = new RemoveObject2Tag(swf);
rem.depth = depth;
newFrameTags.add(rem);
} else {
fullPlace.setPlaceFlagMove(true);
}
newFrameTags.add(fullPlace);
} else if (targetState.placeFrame.frame == targetFrame.frame) {
if (targetState.placeObjectTag.flagMove()) {
PlaceObjectTypeTag fullPlace = targetState.toPlaceObjectTag(depth);
fullPlace.setTimelined(targetTimelined);
if (changed) {
if (USE_REMOVE_TAG) {
RemoveObject2Tag rem = new RemoveObject2Tag(swf);
rem.depth = depth;
newFrameTags.add(rem);
} else {
fullPlace.setPlaceFlagMove(true);
}
}
fullPlace.setPlaceFlagMove(true);

targetTimelined.replaceTag(targetState.placeObjectTag, fullPlace);
} else {
if (changed) {
if (USE_REMOVE_TAG) {
RemoveObject2Tag rem = new RemoveObject2Tag(swf);
rem.depth = depth;
newFrameTags.add(rem);
} else {
targetState.placeObjectTag.setPlaceFlagMove(true);
}
}
targetState.placeObjectTag.setPlaceFlagMove(true);
}
}
}
Expand Down Expand Up @@ -3922,8 +3931,7 @@ public void copyOrMoveFrames(Set<TreeItem> items, boolean move, Timelined target
fixDefineBeforeUsage(swf);
fixHeaderTags(swf);
swf.resetTimelines(targetTimelined);

Timelined sourceTimelined = ((Frame) items.iterator().next()).timeline.timelined;
targetTimelined.setFrameCount(targetTimelined.getTimeline().getFrameCount());
swf.resetTimelines(sourceTimelined);
sourceTimelined.setFrameCount(sourceTimelined.getTimeline().getFrameCount());

Expand Down

0 comments on commit 6a3c2ac

Please sign in to comment.