Added: #2333 Changing Shape tag type (DefineShape, DefineShape2, ...)

This commit is contained in:
Jindra Petřík
2024-10-13 20:43:18 +02:00
parent 77d72c5224
commit d2f7f01d32
21 changed files with 749 additions and 16 deletions
@@ -0,0 +1,130 @@
/*
* Copyright (C) 2010-2024 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.tags.converters.ShapeTypeConverter;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
/**
*
* @author JPEXS
*/
public class ConvertShapeTypeDialog extends AppDialog {
private List<JRadioButton> radios = new ArrayList<>();
private int result = 0;
public ConvertShapeTypeDialog(Window owner, int currentShapeNum, int minForced, int min) {
super(owner);
setTitle(translate("dialog.title"));
JPanel radioPanel = new JPanel();
radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
ButtonGroup radioGroup = new ButtonGroup();
JButton okButton = new JButton(translate("button.ok"));
ShapeTypeConverter converter = new ShapeTypeConverter();
for (int i = 1; i <= 4; i++) {
String text = "DefineShape" + (i > 1 ? "" + i : "");
if (i < minForced) {
text += " " + translate("unsupported");
}
if (i == min) {
text += " " + translate("minimum");
}
text += " - " + translate("shape" + i);
JRadioButton radio = new JRadioButton(text);
radio.setAlignmentX(Component.LEFT_ALIGNMENT);
if (i < minForced) {
radio.setEnabled(false);
}
if (i == currentShapeNum) {
radio.setSelected(true);
}
final int fi = i;
radio.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
okButton.setEnabled(fi != currentShapeNum);
}
});
radioPanel.add(radio);
radioGroup.add(radio);
radios.add(radio);
}
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
cnt.add(radioPanel, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel(new FlowLayout());
okButton.setEnabled(false);
okButton.addActionListener(this::okButtonActionPerformed);
JButton cancelButton = new JButton(translate("button.cancel"));
cancelButton.addActionListener(this::cancelButtonActionPerformed);
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
cnt.add(buttonsPanel, BorderLayout.SOUTH);
pack();
View.centerScreen(this);
View.setWindowIcon(this, "shape");
setModal(true);
}
private void okButtonActionPerformed(ActionEvent evt) {
result = 0;
for (int i = 0; i < radios.size(); i++) {
if (radios.get(i).isSelected()) {
result = i + 1;
break;
}
}
setVisible(false);
}
private void cancelButtonActionPerformed(ActionEvent evt) {
setVisible(false);
}
public int getResult() {
return result;
}
public int showDialog() {
setVisible(true);
return result;
}
}
@@ -2920,6 +2920,9 @@ public class Main {
decodeLaunch5jArgs(args);
setSessionLoaded(false);
System.setProperty("sun.io.serialization.extendedDebugInfo", "true");
clearTemp();
try {
@@ -0,0 +1,27 @@
# Copyright (C) 2024 JPEXS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
dialog.title = Convert shape type
shape1 = first version
shape2 = more than 255 styles in style list, multiple style lists
shape3 = transparency in colors
shape4 = LINESTYLE2 (joins, caps, scaling, stroke fills), edge bounds, focal gradient, spread mode, interpolation mode, numgradients > 8
minimum = (Minimum)
unsupported = (Unsupported)
button.ok = OK
button.cancel = Cancel
@@ -0,0 +1,27 @@
# Copyright (C) 2024 JPEXS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
dialog.title = Konvertovat typ tvaru
shape1 = prvn\u00ed verze
shape2 = v\u00edce ne\u017e 255 styl\u016f v seznamu styl\u016f, vice seznam\u016f styl\u016f
shape3 = pr\u016fhlednost v barv\u00e1ch
shape4 = LINESTYLE2 (joins, caps, scaling, v\u00fdpl\u0148 tah\u016f), edge bounds, focal gradient, spread mode, interpolation mode, po\u010det gradient\u016f > 8
minimum = (Minimum)
unsupported = (Nepodporov\u00e1no)
button.ok = OK
button.cancel = Storno
@@ -1002,3 +1002,6 @@ packer.key = Enter key for the packer "%packer%":
contextmenu.exportVsCode = Export to VS Code
work.exporting.vsCode = Exporting VS Code
menu.file.export.vsCode = Export to VS Code
#after 21.1.0
contextmenu.convertShapeType = Convert shape type
@@ -954,14 +954,14 @@ warning.cleanAbc = Tato akce odstran\u00ed z ABC polo\u017eky, kter\u00e9 maj\u0
tagInfo.idType = Typ id
contextmenu.configurePathResolving = Nastavit resolvov\u00e1n\u00ed cest...
contextmenu.setAsLinkage = Nastavit AS vazbu
contextmenu.exportFlashDevelop = Exportovat FlashDevelop projekt
contextmenu.exportFlashDevelop = Exportovat do FlashDevelop
filter.as3proj=FlashDevelop AS3 projekty (*.as3proj)
work.exporting.flashDevelop = Exportov\u00e1n\u00ed FlashDevelop projektu
menu.file.export.flashDevelop = Exportovat FD projekt
menu.file.export.flashDevelop = Exportovat do FlashDevelop
contextmenu.exportIdea = Exportovat IDEA project
filter.iml = IntelliJ IDEA projekty (*.iml)
work.exporting.idea = Exportov\u00e1n\u00ed IntelliJ IDEA projektu
menu.file.export.idea = Exportovat IDEA projekt
menu.file.export.idea = Exportovat do IntelliJ IDEA
contextmenu.exportFla = Exportovat do FLA
export.project.select.directory = Vyberte um\u00edst\u011bn\u00ed nov\u00e9ho adres\u00e1\u0159e projektu
callStack.header.swf = SWF
@@ -972,4 +972,18 @@ message.confirm.addfunction = Tato akce vytvo\u0159\u00ed nov\u00fd objekt Metho
kter\u00fd m\u016f\u017eete pou\u017e\u00edt jako operand pro instrukci newfunction.\r\n\
Pro editaci t\u011bla a parametr\u016f takov\u00e9 funkce ji mus\u00edte pot\u00e9 vyhledat v ActionScript pohledu.
addfunction.result = Nov\u00e9 id method infa: %method_info_index%. Stiskn\u011bte OK pro zkop\u00edrov\u00e1n\u00ed do schr\u00e1nky.
addfunction.result.title = Nov\u00e9 method info
addfunction.result.title = Nov\u00e9 method info
#after 21.0.2
filter.air.as3proj = FlashDevelop AIR AS3 projekt (*.as3proj)
packer.key.title = Kl\u00ed\u010d pro: %packer%
packer.key = Zadejte kl\u00ed\u010d pro packer "%packer%":
#after 21.0.5
contextmenu.exportVsCode = Exportovat do VS Code
work.exporting.vsCode = Exportuji VS Code
menu.file.export.vsCode = Exportovat do VS Code
#after 21.1.0
contextmenu.convertShapeType = Konvertovat typ tvaru
@@ -42,6 +42,7 @@ import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.AsLinkageDialog;
import com.jpexs.decompiler.flash.gui.ClipboardType;
import com.jpexs.decompiler.flash.gui.CollectDepthAsSpritesDialog;
import com.jpexs.decompiler.flash.gui.ConvertShapeTypeDialog;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.decompiler.flash.gui.MainPanel;
import com.jpexs.decompiler.flash.gui.PathResolvingDialog;
@@ -103,6 +104,7 @@ import com.jpexs.decompiler.flash.tags.base.RemoveTag;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.tags.converters.ShapeTypeConverter;
import com.jpexs.decompiler.flash.tags.gfx.ExporterInfo;
import com.jpexs.decompiler.flash.timeline.AS2Package;
import com.jpexs.decompiler.flash.timeline.AS3Package;
@@ -335,7 +337,9 @@ public class TagTreeContextMenu extends JPopupMenu {
private JMenuItem replaceWithGifMenuItem;
private JMenuItem collectDepthAsSpritesItem;
private JMenuItem collectDepthAsSpritesMenuItem;
private JMenuItem convertShapeTypeMenuItem;
private List<TreeItem> items = new ArrayList<>();
@@ -534,6 +538,11 @@ public class TagTreeContextMenu extends JPopupMenu {
replaceRefsWithTagMenuItem.addActionListener(this::replaceRefsWithTagActionPerformed);
replaceRefsWithTagMenuItem.setIcon(View.getIcon("replacewithtag16"));
add(replaceRefsWithTagMenuItem);
convertShapeTypeMenuItem = new JMenuItem(mainPanel.translate("contextmenu.convertShapeType"));
convertShapeTypeMenuItem.addActionListener(this::convertShapeTypeActionPerformed);
convertShapeTypeMenuItem.setIcon(View.getIcon("shape16"));
add(convertShapeTypeMenuItem);
addSeparator();
@@ -761,10 +770,10 @@ public class TagTreeContextMenu extends JPopupMenu {
pasteInsideMenuItem.addActionListener(this::pasteInsideActionPerformed);
add(pasteInsideMenuItem);
collectDepthAsSpritesItem = new JMenuItem(mainPanel.translate("contextmenu.collectDepthAsSprites"));
collectDepthAsSpritesItem.setIcon(View.getIcon("sprite16"));
collectDepthAsSpritesItem.addActionListener(this::collectDepthAsSprites);
add(collectDepthAsSpritesItem);
collectDepthAsSpritesMenuItem = new JMenuItem(mainPanel.translate("contextmenu.collectDepthAsSprites"));
collectDepthAsSpritesMenuItem.setIcon(View.getIcon("sprite16"));
collectDepthAsSpritesMenuItem.addActionListener(this::collectDepthAsSprites);
add(collectDepthAsSpritesMenuItem);
addSeparator();
@@ -1064,7 +1073,19 @@ public class TagTreeContextMenu extends JPopupMenu {
}
tim = fr.timeline.timelined;
}
boolean allSelectedIsShape = true;
if (items.isEmpty()) {
allSelectedIsShape = false;
}
for (TreeItem item : items) {
if (!(item instanceof ShapeTag)) {
allSelectedIsShape = false;
}
if (item instanceof Tag) {
Tag tag = (Tag) item;
if (tag.isReadOnly()) {
@@ -1214,6 +1235,7 @@ public class TagTreeContextMenu extends JPopupMenu {
replaceWithGifMenuItem.setVisible(false);
replaceWithTagMenuItem.setVisible(false);
replaceRefsWithTagMenuItem.setVisible(false);
convertShapeTypeMenuItem.setVisible(false);
abcExplorerMenuItem.setVisible(false);
cleanAbcMenuItem.setVisible(false);
rawEditMenuItem.setVisible(false);
@@ -1256,7 +1278,7 @@ public class TagTreeContextMenu extends JPopupMenu {
pasteAfterMenuItem.setVisible(false);
pasteBeforeMenuItem.setVisible(false);
pasteInsideMenuItem.setVisible(false);
collectDepthAsSpritesItem.setVisible(allSelectedIsFrame && allSelectedSameParent);
collectDepthAsSpritesMenuItem.setVisible(allSelectedIsFrame && allSelectedSameParent);
applyUnpackerMenu.setVisible(false);
openSWFInsideTagMenuItem.setVisible(false);
addAs12ScriptMenuItem.setVisible(false);
@@ -1411,7 +1433,7 @@ public class TagTreeContextMenu extends JPopupMenu {
replaceRefsWithTagMenuItem.setVisible(true);
}
}
if (firstItem instanceof DefineSpriteTag) {
replaceWithGifMenuItem.setVisible(true);
}
@@ -1636,6 +1658,10 @@ public class TagTreeContextMenu extends JPopupMenu {
}
}
}
if (allSelectedIsShape) {
convertShapeTypeMenuItem.setVisible(true);
}
moveTagToMenu.removeAll();
moveTagToWithDependenciesMenu.removeAll();
@@ -2546,6 +2572,53 @@ public class TagTreeContextMenu extends JPopupMenu {
mainPanel.refreshTree(swf);
}
}
private void convertShapeTypeActionPerformed(ActionEvent evt) {
List<TreeItem> itemr = getSelectedItems();
if (itemr.isEmpty()) {
return;
}
int currentShapeNum = 0;
int min = 0;
int minForced = 0;
ShapeTypeConverter converter = new ShapeTypeConverter();
if (itemr.size() == 1) {
ShapeTag sh = (ShapeTag) itemr.get(0);
currentShapeNum = sh.getShapeNum();
min = converter.getMinShapeNum(sh);
minForced = converter.getForcedMinShapeNum(sh);
}
ConvertShapeTypeDialog dialog = new ConvertShapeTypeDialog(Main.getDefaultDialogsOwner(), currentShapeNum, minForced, min);
int shapeNum = dialog.showDialog();
if (shapeNum == 0) {
return;
}
for (TreeItem item : itemr) {
ShapeTag sh = (ShapeTag) item;
int newShapeNum = shapeNum;
int forcedMin = converter.getForcedMinShapeNum(sh);
if (newShapeNum < forcedMin) {
newShapeNum = forcedMin;
}
if (sh.getShapeNum() == newShapeNum) {
continue;
}
converter.convertCharacter(sh.getSwf(), sh.getCharacterId(), newShapeNum);
}
mainPanel.refreshTree();
if (itemr.size() == 1) {
ShapeTag sh = (ShapeTag) itemr.get(0);
mainPanel.setTagTreeSelectedNode(mainPanel.getCurrentTree(), sh.getSwf().getCharacter(sh.getCharacterId()));
}
}
private void replaceRefsWithTagActionPerformed(ActionEvent evt) {
TreeItem itemr = getCurrentItem();