From 032a4880f86813123219538837d8fc346798b119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 12 Nov 2022 12:14:56 +0100 Subject: [PATCH] Added Removing BUTTONRECORDs Added Jump to character on BUTTTONRECORDs --- .../flash/tags/DefineEditTextTag.java | 5 ++- .../decompiler/flash/tags/base/ButtonTag.java | 10 ++++- .../flash/tags/base/CharacterIdTag.java | 8 ++-- .../decompiler/flash/types/BUTTONRECORD.java | 26 ++++++++----- .../flash/types/HasCharacterId.java | 11 ++++++ .../flash/gui/tagtree/TagTreeContextMenu.java | 39 ++++++++++++++++--- 6 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/HasCharacterId.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 0e0dd9d4d..49151a4a4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -370,6 +370,9 @@ public class DefineEditTextTag extends TextTag { } private List getTextWithStyle() { + if (swf == null) { + return new ArrayList<>(); + } String str = ""; TextStyle style = new TextStyle(); if (fontClass != null) { @@ -1029,7 +1032,7 @@ public class DefineEditTextTag extends TextTag { } } - public List getTextRecords() { + public List getTextRecords() { DynamicTextModel textModel = new DynamicTextModel(); List txt = getTextWithStyle(); TextStyle lastStyle = null; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonTag.java index 9269778f9..14cabbd00 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ButtonTag.java @@ -202,5 +202,13 @@ public abstract class ButtonTag extends DrawableTag implements Timelined { for(BUTTONRECORD record:getRecords()) { record.setSwfAndTag(swf, this); } - } + } + + @Override + public void setModified(boolean value) { + super.setModified(value); + for(BUTTONRECORD record:getRecords()) { + record.setModified(value); + } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java index 9d23add7a..18025e885 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java @@ -16,13 +16,13 @@ */ package com.jpexs.decompiler.flash.tags.base; +import com.jpexs.decompiler.flash.types.HasCharacterId; + /** * * @author JPEXS */ -public interface CharacterIdTag { +public interface CharacterIdTag extends HasCharacterId { - public int getCharacterId(); - - public void setCharacterId(int characterId); + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java index 5a428373b..48e9532f0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONRECORD.java @@ -35,7 +35,7 @@ import java.util.List; * * @author JPEXS */ -public class BUTTONRECORD implements Serializable, TreeItem, HasSwfAndTag { +public class BUTTONRECORD implements Serializable, TreeItem, HasSwfAndTag, HasCharacterId { @Reserved @SWFType(value = BasicType.UB, count = 2) @@ -114,6 +114,9 @@ public class BUTTONRECORD implements Serializable, TreeItem, HasSwfAndTag { @Internal private ButtonTag tag; + + @Internal + private boolean modified; public BUTTONRECORD(SWF swf, ButtonTag tag) { this.swf = swf; @@ -135,18 +138,13 @@ public class BUTTONRECORD implements Serializable, TreeItem, HasSwfAndTag { return swf; } - public void setModified() { - if (tag != null) { - tag.setModified(true); - } + public void setModified(boolean value) { + modified = value; } @Override public boolean isModified() { - if (tag != null) { - return tag.isModified(); - } - return false; + return modified; } @Override @@ -159,4 +157,14 @@ public class BUTTONRECORD implements Serializable, TreeItem, HasSwfAndTag { this.swf = swf; this.tag = (ButtonTag) tag; } + + @Override + public int getCharacterId() { + return characterId; + } + + @Override + public void setCharacterId(int characterId) { + this.characterId = characterId; + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/HasCharacterId.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/HasCharacterId.java new file mode 100644 index 000000000..02dc83df5 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/HasCharacterId.java @@ -0,0 +1,11 @@ +package com.jpexs.decompiler.flash.types; + +/** + * + * @author JPEXS + */ +public interface HasCharacterId { + public int getCharacterId(); + + public void setCharacterId(int characterId); +} diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 6d4e2950f..a7a607da8 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -58,6 +58,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.TagTypeInfo; import com.jpexs.decompiler.flash.tags.UnknownTag; import com.jpexs.decompiler.flash.tags.base.ASMSource; +import com.jpexs.decompiler.flash.tags.base.ButtonTag; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ImageTag; @@ -76,9 +77,11 @@ import com.jpexs.decompiler.flash.treeitems.HeaderItem; import com.jpexs.decompiler.flash.treeitems.SWFList; import com.jpexs.decompiler.flash.treeitems.TreeItem; import com.jpexs.decompiler.flash.types.BUTTONCONDACTION; +import com.jpexs.decompiler.flash.types.BUTTONRECORD; import com.jpexs.decompiler.flash.types.CLIPACTIONRECORD; import com.jpexs.decompiler.flash.types.CLIPACTIONS; import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA; +import com.jpexs.decompiler.flash.types.HasCharacterId; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.helpers.Helper; @@ -547,6 +550,10 @@ public class TagTreeContextMenu extends JPopupMenu { if (item instanceof FrameScript) { continue; } + + if (item instanceof BUTTONRECORD) { + continue; + } canRemove = false; break; @@ -848,7 +855,7 @@ public class TagTreeContextMenu extends JPopupMenu { expandRecursiveMenuItem.setVisible(true); } - if (firstItem instanceof CharacterIdTag && !(firstItem instanceof CharacterTag)) { + if (firstItem instanceof HasCharacterId && !(firstItem instanceof CharacterTag)) { jumpToCharacterMenuItem.setVisible(true); } @@ -1503,12 +1510,12 @@ public class TagTreeContextMenu extends JPopupMenu { private void jumpToCharacterActionPerformed(ActionEvent evt) { TreeItem itemj = getTree().getCurrentTreeItem(); - if (itemj == null || !(itemj instanceof CharacterIdTag)) { + if (itemj == null || !(itemj instanceof HasCharacterId)) { return; } - CharacterIdTag characterIdTag = (CharacterIdTag) itemj; - mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), itemj.getSwf().getCharacter(characterIdTag.getCharacterId())); + HasCharacterId hasCharacterId = (HasCharacterId) itemj; + mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), itemj.getSwf().getCharacter(hasCharacterId.getCharacterId())); } private void expandRecursiveActionPerformed(ActionEvent evt) { @@ -2158,6 +2165,10 @@ public class TagTreeContextMenu extends JPopupMenu { itemsToRemoveParents.add(new Object()); itemsToRemoveSprites.add(new Object()); } + } else if (item instanceof BUTTONRECORD) { + itemsToRemove.add(item); + itemsToRemoveParents.add(((BUTTONRECORD) item).getTag()); + itemsToRemoveSprites.add(new Object()); } } @@ -2215,6 +2226,22 @@ public class TagTreeContextMenu extends JPopupMenu { for (int i = 0; i < itemsToRemove.size(); i++) { Object item = itemsToRemove.get(i); Object parent = itemsToRemoveParents.get(i); + + if (item instanceof BUTTONRECORD) { + ButtonTag button = (ButtonTag) parent; + button.getRecords().remove((BUTTONRECORD) item); + List unmodifiedRecords = new ArrayList<>(); + for (BUTTONRECORD rec : button.getRecords()) { + if (!rec.isModified()) { + unmodifiedRecords.add(rec); + } + } + button.setModified(true); + for (BUTTONRECORD rec : unmodifiedRecords) { + rec.setModified(false); + } + } + if (item instanceof BUTTONCONDACTION) { DefineButton2Tag button = (DefineButton2Tag) parent; BUTTONCONDACTION buttonCondAction = (BUTTONCONDACTION) item; @@ -2225,7 +2252,7 @@ public class TagTreeContextMenu extends JPopupMenu { } } button.setModified(true); - } + } if (item instanceof CLIPACTIONRECORD) { PlaceObjectTypeTag place = (PlaceObjectTypeTag) parent; Timelined tim = (itemsToRemoveSprites.get(i) instanceof DefineSpriteTag) ? (DefineSpriteTag) itemsToRemoveSprites.get(i) : place.getSwf(); @@ -2240,7 +2267,7 @@ public class TagTreeContextMenu extends JPopupMenu { clipActions.calculateAllEventFlags(); place.setModified(true); tim.resetTimeline(); - } + } if (item instanceof ScriptPack) { ScriptPack sp = (ScriptPack) item; sp.delete(sp.abc, true);