From b0a72b07db9467cd5d5f2d460f572eb05534f535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Wed, 9 Nov 2022 20:43:55 +0100 Subject: [PATCH] Added Setting for enabling placing Define tags into DefineSprite --- CHANGELOG.md | 1 + .../flash/configuration/Configuration.java | 4 + .../locales/AdvancedSettingsDialog.properties | 3 + .../AdvancedSettingsDialog_cs.properties | 5 +- .../flash/gui/taglistview/TagListTree.java | 12 ++- .../flash/gui/tagtree/TagTreeContextMenu.java | 89 ++++++++++--------- 6 files changed, 68 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f0c82452..ee9f55d50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. - Keyboard shortcuts for tag clipboard operations - Hilight clipboard panel on copy/cut action for a few seconds - Drag and drop to move/copy tags in the tag list view +- Setting for enabling placing Define tags into DefineSprite ## [16.2.0] - 2022-11-08 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 526f8003c..0113140a6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -767,6 +767,10 @@ public final class Configuration { @ConfigurationDefaultBoolean(true) @ConfigurationCategory("ui") public static ConfigurationItem expandFirstLevelOfTreeOnLoad = null; + + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("ui") + public static ConfigurationItem allowPlacingDefinesIntoSprites = null; private enum OSId { WINDOWS, OSX, UNIX diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 7ad9be0c3..36c076d72 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -583,3 +583,6 @@ config.description.autoPlaySwfs = Automatically play SWF preview on SWF node sel config.name.expandFirstLevelOfTreeOnLoad = Expand first level of tree on SWF load config.description.expandFirstLevelOfTreeOnLoad = Automatically expands first level of nodes in the tree on SWF open. + +config.name.allowPlacingDefinesIntoSprites = Allow placing define tags into DefineSprite +config.description.allowPlacingDefinesIntoSprites = Allows placing (moving/copying/dragging into) define type tags into DefineSprite. diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties index c29c04323..110d55019 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_cs.properties @@ -569,4 +569,7 @@ config.name.autoPlaySwfs = Automaticky p\u0159ehr\u00e1vat n\u00e1hledy SWF config.description.autoPlaySwfs = Automaticicky p\u0159ehr\u00e1vat n\u00e1hled SWF p\u0159i v\u00fdb\u011bru SWF polo\u017eky. config.name.expandFirstLevelOfTreeOnLoad = Rozbalit prvn\u00ed \u00farove\u0148 stromu p\u0159i na\u010dten\u00ed SWF -config.description.expandFirstLevelOfTreeOnLoad = Automaticky rozbal\u00ed prvn\u00ed \u00farove\u0148 polo\u017eek stromu p\u0159i otev\u0159en\u00ed SWF. \ No newline at end of file +config.description.expandFirstLevelOfTreeOnLoad = Automaticky rozbal\u00ed prvn\u00ed \u00farove\u0148 polo\u017eek stromu p\u0159i otev\u0159en\u00ed SWF. + +config.name.allowPlacingDefinesIntoSprites = Povolit umis\u0165ov\u00e1n\u00ed defini\u010dn\u00edch tag\u016f do DefineSprite +config.description.allowPlacingDefinesIntoSprites = Povol\u00ed umis\u0165ov\u00e1n\u00ed (p\u0159esun/kop\u00edrov\u00e1n\u00ed/ta\u017een\u00ed dovnit\u0159) defini\u010dn\u00edch tag\u016f do DefineSprite. diff --git a/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTree.java b/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTree.java index bc5dd7e29..2e4cf5af8 100644 --- a/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTree.java +++ b/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTree.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.gui.MainPanel; import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTree; import static com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTree.getSelection; +import com.jpexs.decompiler.flash.tags.DefineSpriteTag; import com.jpexs.decompiler.flash.tags.DoInitActionTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.timeline.Frame; @@ -115,7 +116,11 @@ class TreeTransferHandler extends TransferHandler { // Do not allow a drop on the drag source selections. JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation(); - if ((dl.getPath().getLastPathComponent() instanceof Tag) && dl.getChildIndex() == -1) { + if ( + ((dl.getPath().getLastPathComponent() instanceof Tag) && + !(dl.getPath().getLastPathComponent() instanceof DefineSpriteTag)) && + dl.getChildIndex() == -1 + ) { return false; } @@ -181,7 +186,10 @@ class TreeTransferHandler extends TransferHandler { Timelined timelined; Tag position; if (childIndex == -1) { - if (dest instanceof Tag) { + if (dest instanceof DefineSpriteTag) { + timelined = (Timelined) dest; + position = null; + } else if (dest instanceof Tag) { timelined = ((Tag) dest).getTimelined(); position = (Tag) dest; } else if (dest instanceof Frame) { diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 44b317635..1f82e0622 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -359,7 +359,7 @@ public class TagTreeContextMenu extends JPopupMenu { add(copyTagToWithDependenciesMenu); cutTagToClipboardMenuItem = new JMenuItem(mainPanel.translate("contextmenu.cutTag") + " (CTRL+X)"); - cutTagToClipboardMenuItem.setIcon(View.getIcon("cut16")); + cutTagToClipboardMenuItem.setIcon(View.getIcon("cut16")); cutTagToClipboardMenuItem.addActionListener(this::cutTagToClipboardActionPerformed); add(cutTagToClipboardMenuItem); @@ -853,9 +853,9 @@ public class TagTreeContextMenu extends JPopupMenu { if (allSelectedIsTag) { List tagItems = new ArrayList<>(); - for(TreeItem item:items) { + for (TreeItem item : items) { if (item instanceof TagScript) { - tagItems.add(((TagScript)item).getTag()); + tagItems.add(((TagScript) item).getTag()); } else { tagItems.add((Tag) item); } @@ -882,7 +882,7 @@ public class TagTreeContextMenu extends JPopupMenu { cutTagToClipboardMenuItem.setVisible(true); cutTagToClipboardWithDependenciesMenuItem.setVisible(true); - + copyTagToMenu.setVisible(true); copyTagToWithDependenciesMenu.setVisible(true); } @@ -2741,7 +2741,7 @@ public class TagTreeContextMenu extends JPopupMenu { ReadOnlyTagList tags = timelined.getTags(); position = positionInt < tags.size() ? tags.get(positionInt) : null; copyOrMoveTagsBeforeAfter(mainPanel.getClipboardContents(), mainPanel.isClipboardCut(), timelined, position); - + if (mainPanel.isClipboardCut()) { mainPanel.emptyClipboard(); } @@ -2763,7 +2763,7 @@ public class TagTreeContextMenu extends JPopupMenu { ReadOnlyTagList tags = timelined.getTags(); position = positionInt < tags.size() ? tags.get(positionInt) : null; copyOrMoveTagsBeforeAfter(mainPanel.getClipboardContents(), mainPanel.isClipboardCut(), timelined, position); - + if (mainPanel.isClipboardCut()) { mainPanel.emptyClipboard(); } @@ -2782,69 +2782,72 @@ public class TagTreeContextMenu extends JPopupMenu { position = null; } copyOrMoveTagsBeforeAfter(mainPanel.getClipboardContents(), mainPanel.isClipboardCut(), timelined, position); - + if (mainPanel.isClipboardCut()) { mainPanel.emptyClipboard(); } } public void copyOrMoveTagsBeforeAfter(Set items, boolean move, Timelined targetTimelined, Tag position) { - //do not move to self - if (items.size() == 1 && move) { - Tag tag = (Tag) items.iterator().next(); - if (targetTimelined == tag.getTimelined()) { - if (tag == position) { - return; - } - int index = tag.getTimelined().indexOfTag(tag); - ReadOnlyTagList tags = tag.getTimelined().getTags(); - Tag nextPosition; - if (index + 1 < tags.size()) { - nextPosition = tags.get(index + 1); - if (nextPosition == position) { - return; - } - } - } - } Set sourceSwfs = new LinkedHashSet<>(); SWF targetSwf = (targetTimelined instanceof SWF) ? (SWF) targetTimelined : ((DefineSpriteTag) targetTimelined).getSwf(); try { List newTags = new ArrayList<>(); Map changedCharacterIds = new HashMap<>(); for (TreeItem item : items) { - Tag tag = (Tag) item; + Tag tag = (Tag) item; if (tag.getSwf() == null) { continue; } SWF sourceSwf = tag.getSwf(); sourceSwfs.add(sourceSwf); - + + Timelined realTargetTimelined = targetTimelined; + Tag realPosition = position; + + if (!Configuration.allowPlacingDefinesIntoSprites.get()) { + //do not place Define tags in DefineSprites + if ((tag instanceof CharacterTag) && (targetTimelined instanceof DefineSpriteTag)) { + Tag spriteTag = ((DefineSpriteTag) targetTimelined); + //get to the topmost level DefineSprite + while (spriteTag.getTimelined() instanceof DefineSpriteTag) { + spriteTag = (DefineSpriteTag) spriteTag.getTimelined(); + } + realTargetTimelined = spriteTag.getTimelined(); //should be SWF + realPosition = spriteTag; + } + } + + //do not move to self + if (items.size() == 1 && move) { + if (realTargetTimelined == tag.getTimelined()) { + if (tag == position) { + return; + } + int index = tag.getTimelined().indexOfTag(tag); + ReadOnlyTagList tags = tag.getTimelined().getTags(); + Tag nextPosition; + if (index + 1 < tags.size()) { + nextPosition = tags.get(index + 1); + if (nextPosition == realPosition) { + return; + } + } + } + } + if (move) { - if (tag == position) { + /*if (tag == position) { int index = tag.getTimelined().indexOfTag(position); if (tag.getTimelined().getTags().size() > index + 1) { position = tag.getTimelined().getTags().get(index + 1); } else { position = null; } - } + }*/ tag.getTimelined().removeTag(tag); } - Timelined realTargetTimelined = targetTimelined; - Tag realPosition = position; - - //do not place Define tags in DefineSprites - if ((tag instanceof CharacterTag) && (targetTimelined instanceof DefineSpriteTag)) { - Tag spriteTag = ((DefineSpriteTag) targetTimelined); - //get to the topmost level DefineSprite - while (spriteTag.getTimelined() instanceof DefineSpriteTag) { - spriteTag = (DefineSpriteTag) spriteTag.getTimelined(); - } - realTargetTimelined = spriteTag.getTimelined(); //should be SWF - realPosition = spriteTag; - } if (sourceSwf != targetSwf || !move) { ReadOnlyTagList tags = realTargetTimelined.getTags(); int positionInt = realPosition == null ? tags.size() : tags.indexOf(realPosition); @@ -2894,7 +2897,7 @@ public class TagTreeContextMenu extends JPopupMenu { targetSwf.clearImageCache(); targetSwf.updateCharacters(); targetSwf.resetTimelines(targetSwf); - + mainPanel.refreshTree(targetSwf); } catch (InterruptedException | IOException ex) { Logger.getLogger(TagTreeContextMenu.class.getName()).log(Level.SEVERE, null, ex);