diff --git a/CHANGELOG.md b/CHANGELOG.md index 87df76ab5..fb9845290 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ All notable changes to this project will be documented in this file. - Copy / Move to tag tree refreshing - Preview of PlaceObject and ShowFrame in the Dump view - FileAttributes tag exception in the Dump view +- Adding new frames did not set correct timelined to ShowFrame ### Changed - [#1455] All tag types are now allowed inside DefineSprite diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 2e360cbef..0f372290a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -3217,83 +3217,24 @@ public final class SWF implements SWFContainerItem, Timelined { public int indexOfTag(Tag tag) { return tags.indexOf(tag); - } - - /** - * Adds a tag to the SWF If targetTreeItem is: - * - Frame: adds the tag to the - * Frame. Frame can be a frame of the main timeline or a DefineSprite frame - * - DefineSprite: adds the tag to the end of the DefineSprite's tag list - * - Any other tag in the SWF: adds the new tag exactly before the specified - * tag - * - Other: adds the tag to the end of the SWF's tag list - * - * @param tag - * @param targetTreeItem - */ - public void addTag(Tag tag, TreeItem targetTreeItem) { - SWF swf = tag.getSwf(); - Frame frame = targetTreeItem instanceof Frame ? (Frame) targetTreeItem : null; - Timelined timelined; - if (frame != null) { - timelined = frame.timeline.timelined; - } else { - timelined = swf.getTimelined(targetTreeItem); + } + + public static void addTagBefore(Tag newTag, Tag targetTag) { + Timelined tim = targetTag.getTimelined(); + int index = tim.indexOfTag(targetTag); + if (index < 0) { + return; } - - tag.setTimelined(timelined); - - int index; - if ((tag instanceof DefineScalingGridTag) && (timelined instanceof DefineSpriteTag)) { - index = this.tags.indexOf(timelined) + 1; - } else if (frame != null) { - if (frame.showFrameTag != null) { - index = timelined.indexOfTag(frame.showFrameTag); - } else { - index = -1; - } - } else if (timelined instanceof DefineSpriteTag) { - index = -1; - } else if (targetTreeItem instanceof Tag) { - if (tag instanceof CharacterIdTag && !(tag instanceof CharacterTag) && targetTreeItem instanceof CharacterTag) { - ((CharacterIdTag) tag).setCharacterId(((CharacterTag) targetTreeItem).getCharacterId()); - } - - index = timelined.indexOfTag((Tag) targetTreeItem); // todo: honfika: why not index + 1? - } else { - index = -1; - if (tag instanceof CharacterTag) { - // add before the last ShowFrame tag - ReadOnlyTagList tags = timelined.getTags(); - for (int i = tags.size() - 1; i >= 0; i--) { - if (tags.get(i) instanceof ShowFrameTag) { - index = i; - break; - } - } - } - } - - if ((tag instanceof DefineScalingGridTag) && (timelined instanceof DefineSpriteTag)) { - DefineScalingGridTag scalingGrid = (DefineScalingGridTag) tag; - scalingGrid.characterId = ((DefineSpriteTag) timelined).spriteId; - this.addTag(index, tag); - } else { - if (index > -1) { - timelined.addTag(index, tag); - } else { - timelined.addTag(tag); - } - timelined.resetTimeline(); - - if (timelined instanceof DefineSpriteTag) { - DefineSpriteTag sprite = (DefineSpriteTag) timelined; - sprite.frameCount = timelined.getTimeline().getFrameCount(); - } - if (timelined == this) { - frameCount = getTimeline().getFrameCount(); - } + tim.addTag(index, newTag); + tim.resetTimeline(); + if (tim instanceof DefineSpriteTag) { + DefineSpriteTag sprite = (DefineSpriteTag) tim; + sprite.frameCount = tim.getTimeline().getFrameCount(); + } else if (tim instanceof SWF) { + SWF swf = (SWF) tim; + swf.frameCount = tim.getTimeline().getFrameCount(); } + newTag.setTimelined(tim); } public Timelined getTimelined(TreeItem treeItem) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java index 945cf7899..b9ca2b6b9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java @@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.tags.enums.ImageFormat; +import com.jpexs.decompiler.flash.timeline.Timelined; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; import java.awt.Dimension; @@ -121,7 +122,7 @@ public class ShapeImporter { throw new Error("Unsupported image type tag."); } - swf.addTag(imageTag, st); + swf.addTagBefore(imageTag, st); swf.updateCharacters(); return imageTag; } diff --git a/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java b/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java index a060ac90f..b54e790d7 100644 --- a/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java +++ b/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java @@ -204,8 +204,8 @@ public class DebuggerTools { } } //Add to target SWF - ((Tag) ds).setSwf(swf); - swf.addTag((Tag) ds, (Tag) firstAbc); + ((Tag) ds).setSwf(swf); + swf.addTagBefore((Tag) ds, (Tag) firstAbc); swf.getAbcList().add(swf.getAbcList().indexOf(firstAbc), ds); ((Tag) ds).setModified(true); diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 1e9d28141..a94f9f85f 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -2454,7 +2454,7 @@ public class TagTreeContextMenu extends JPopupMenu { SWF swf = timelined.getTimeline().swf; for (int i = 0; i < frameCount; i++) { ShowFrameTag showFrameTag = new ShowFrameTag(swf); - showFrameTag.setTimelined(swf); + showFrameTag.setTimelined(timelined); timelined.addTag(positionToAdd, showFrameTag); } timelined.resetTimeline(); diff --git a/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java b/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java index 25c9200cd..20afb5e0b 100644 --- a/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java +++ b/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java @@ -171,7 +171,7 @@ public class AdobeFlashExecutor { actions2.add(new ActionReturn()); doaTag.setActions(actions2); - swf.addTag(doaTag, asm); + swf.addTagBefore(doaTag, (Tag) asm); i++; }