Added: #2463 Export subsprites animation context menu on frames

This commit is contained in:
Jindra Petřík
2025-06-02 22:11:52 +02:00
parent b5ba12ef8c
commit a0bfa7c8c0
12 changed files with 476 additions and 37 deletions
@@ -189,7 +189,11 @@ public class ExportDialog extends AppDialog {
}
public double getZoom() {
return Double.parseDouble(zoomTextField.getText()) / 100;
try {
return Double.parseDouble(zoomTextField.getText()) / 100;
} catch (NumberFormatException nfe) {
return 1;
}
}
private void saveConfig() {
@@ -0,0 +1,282 @@
/*
* Copyright (C) 2025 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.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.FrameExportMode;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
*
* @author JPEXS
*/
public class ExportSubspriteAnimationDialog extends AppDialog {
private int result = ERROR_OPTION;
private JTextField lengthTextField = new JTextField("1", 3);
private JComboBox<String> formatComboBox;
private final MainPanel mainPanel;
private JButton okButton;
private JTextField zoomTextField = new JTextField(4);
private JCheckBox transparentFrameBackgroundCheckBox;
private List<FrameExportMode> modes = new ArrayList<>();
public ExportSubspriteAnimationDialog(MainPanel mainPanel, Window owner) {
super(owner);
setTitle(translate("dialog.title"));
Container cnt = getContentPane();
setSize(800, 600);
cnt.setLayout(new BorderLayout());
JPanel centralPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2, 2, 2, 2);
gbc.anchor = GridBagConstraints.FIRST_LINE_START;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
centralPanel.add(new JLabel(translate("format")), gbc);
Vector<String> optionNames = new Vector<>();
String exportFormatsStr = Configuration.lastSelectedExportFormats.get();
if ("".equals(exportFormatsStr)) {
exportFormatsStr = null;
}
String[] exportFormatsArr = new String[0];
if (exportFormatsStr != null) {
if (exportFormatsStr.contains(",")) {
exportFormatsArr = exportFormatsStr.split(",");
} else {
exportFormatsArr = new String[]{exportFormatsStr};
}
}
List<String> exportFormats = Arrays.asList(exportFormatsArr);
int selectedFormat = -1;
for (FrameExportMode mode : FrameExportMode.values()) {
if (mode == FrameExportMode.SWF
|| mode == FrameExportMode.CANVAS) {
continue;
}
String key = "frames." + mode.toString().toLowerCase(Locale.ENGLISH);
optionNames.add(AppStrings.translate(ExportDialog.class, key));
if (exportFormats.contains(key)) {
selectedFormat = modes.size();
}
modes.add(mode);
}
gbc.gridx++;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.NONE;
formatComboBox = new JComboBox<>(optionNames);
if (selectedFormat != -1) {
formatComboBox.setSelectedIndex(selectedFormat);
}
centralPanel.add(formatComboBox, gbc);
gbc.gridy++;
gbc.gridwidth = 2;
transparentFrameBackgroundCheckBox = new JCheckBox(AppStrings.translate(ExportDialog.class, "transparentFrameBackground"));
transparentFrameBackgroundCheckBox.setVisible(true);
centralPanel.add(transparentFrameBackgroundCheckBox, gbc);
if (Configuration.lastExportTransparentBackground.get()) {
transparentFrameBackgroundCheckBox.setSelected(true);
}
JLabel zlab = new JLabel(translateTitle("zoom"));
JLabel pctLabel = new JLabel(AppStrings.translate(ExportDialog.class, "zoom.percent"));
zlab.setLabelFor(zoomTextField);
String pct = "" + Configuration.lastSelectedExportZoom.get() * 100;
if (pct.endsWith(".0")) {
pct = pct.substring(0, pct.length() - 2);
}
zoomTextField.setText(pct);
gbc.gridy++;
gbc.gridx = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.LINE_END;
centralPanel.add(zlab, gbc);
gbc.gridx++;
gbc.anchor = GridBagConstraints.LINE_START;
centralPanel.add(zoomTextField, gbc);
gbc.gridx++;
gbc.anchor = GridBagConstraints.LINE_START;
centralPanel.add(pctLabel, gbc);
gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
centralPanel.add(new JLabel(translate("length")), gbc);
gbc.gridx++;
gbc.fill = GridBagConstraints.NONE;
lengthTextField.setMinimumSize(lengthTextField.getPreferredSize());
lengthTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
check();
}
@Override
public void removeUpdate(DocumentEvent e) {
check();
}
@Override
public void changedUpdate(DocumentEvent e) {
check();
}
});
centralPanel.add(lengthTextField, gbc);
gbc.gridx++;
centralPanel.add(new JLabel(translate("frames")), gbc);
JPanel buttonsPanel = new JPanel(new FlowLayout());
okButton = new JButton(translate("button.ok"));
okButton.addActionListener(this::okButtonActionPerformed);
JButton cancelButton = new JButton(translate("button.cancel"));
cancelButton.addActionListener(this::cancelButtonActionPerformed);
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
cnt.add(centralPanel, BorderLayout.CENTER);
cnt.add(buttonsPanel, BorderLayout.SOUTH);
cnt.setMinimumSize(cnt.getPreferredSize());
setSize(350, 200);
View.centerScreen(this);
View.setWindowIcon(this, "export");
getRootPane().setDefaultButton(okButton);
setModal(true);
this.mainPanel = mainPanel;
}
private void check() {
try {
int len = Integer.parseInt(lengthTextField.getText());
okButton.setEnabled(len > 0);
} catch (NumberFormatException nfe) {
okButton.setEnabled(false);
}
}
private void okButtonActionPerformed(ActionEvent evt) {
result = OK_OPTION;
try {
saveConfig();
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(ExportSubspriteAnimationDialog.this, AppStrings.translate(ExportDialog.class, "zoom.invalid"), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
zoomTextField.requestFocusInWindow();
return;
}
setVisible(false);
}
private void saveConfig() {
String format = getFormat().toString().toLowerCase(Locale.ENGLISH);
String formats = Configuration.lastSelectedExportFormats.get();
String[] parts = formats.split(",", -1);
List<String> newFormats = new ArrayList<>();
for (String part : parts) {
if (part.startsWith("frames.")) {
newFormats.add("frames." + format);
} else {
newFormats.add(part);
}
}
String cfg = String.join(",", newFormats);
Configuration.lastSelectedExportZoom.set(Double.parseDouble(zoomTextField.getText()) / 100);
Configuration.lastSelectedExportFormats.set(cfg);
Configuration.lastExportTransparentBackground.set(transparentFrameBackgroundCheckBox.isSelected());
}
private void cancelButtonActionPerformed(ActionEvent evt) {
result = CANCEL_OPTION;
setVisible(false);
}
public int showDialog() {
setVisible(true);
return result;
}
public int getLength() {
try {
return Integer.parseInt(lengthTextField.getText());
} catch (NumberFormatException nfe) {
return 0;
}
}
public FrameExportMode getFormat() {
return modes.get(formatComboBox.getSelectedIndex());
}
private String translateTitle(String title) {
return AppStrings.translate(ExportDialog.class, "titleFormat").replace("%title%", AppStrings.translate(ExportDialog.class, title));
}
public boolean isTransparentFrameBackgroundEnabled() {
return transparentFrameBackgroundCheckBox.isSelected();
}
public double getZoom() {
return Double.parseDouble(zoomTextField.getText()) / 100;
}
}
@@ -2296,7 +2296,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom(), export.isTransparentFrameBackgroundEnabled());
if (frames.containsKey(0)) {
String subFolder = FrameExportSettings.EXPORT_FOLDER_NAME;
ret.addAll(frameExporter.exportFrames(handler, selFile2 + File.separator + subFolder, swf, 0, frames.get(0), fes, evl));
ret.addAll(frameExporter.exportFrames(handler, selFile2 + File.separator + subFolder, swf, 0, frames.get(0), 1, fes, evl));
}
}
@@ -2306,7 +2306,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
int containerId = entry.getKey();
if (containerId != 0) {
String subFolder = SpriteExportSettings.EXPORT_FOLDER_NAME;
ret.addAll(frameExporter.exportSpriteFrames(handler, selFile2 + File.separator + subFolder, swf, containerId, entry.getValue(), ses, evl));
ret.addAll(frameExporter.exportSpriteFrames(handler, selFile2 + File.separator + subFolder, swf, containerId, entry.getValue(), 1, ses, evl));
}
}
}
@@ -2407,14 +2407,14 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (export.isOptionEnabled(FrameExportMode.class)) {
FrameExportSettings fes = new FrameExportSettings(export.getValue(FrameExportMode.class), export.getZoom(), export.isTransparentFrameBackgroundEnabled());
frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME), swf, 0, null, fes, evl);
frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME), swf, 0, null, 1, fes, evl);
}
if (export.isOptionEnabled(SpriteExportMode.class)) {
SpriteExportSettings ses = new SpriteExportSettings(export.getValue(SpriteExportMode.class), export.getZoom());
for (CharacterTag c : swf.getCharacters(false).values()) {
if (c instanceof DefineSpriteTag) {
frameExporter.exportSpriteFrames(handler, Path.combine(selFile, SpriteExportSettings.EXPORT_FOLDER_NAME), swf, c.getCharacterId(), null, ses, evl);
frameExporter.exportSpriteFrames(handler, Path.combine(selFile, SpriteExportSettings.EXPORT_FOLDER_NAME), swf, c.getCharacterId(), null, 1, ses, evl);
}
}
}
@@ -2518,7 +2518,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (export.isOptionEnabled(FrameExportMode.class)) {
for (FrameExportMode exportMode : FrameExportMode.values()) {
FrameExportSettings fes = new FrameExportSettings(exportMode, export.getZoom(), export.isTransparentFrameBackgroundEnabled());
frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, 0, null, fes, evl);
frameExporter.exportFrames(handler, Path.combine(selFile, FrameExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, 0, null, 1, fes, evl);
}
}
@@ -2527,7 +2527,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
SpriteExportSettings ses = new SpriteExportSettings(exportMode, export.getZoom());
for (CharacterTag c : swf.getCharacters(false).values()) {
if (c instanceof DefineSpriteTag) {
frameExporter.exportSpriteFrames(handler, Path.combine(selFile, SpriteExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, c.getCharacterId(), null, ses, evl);
frameExporter.exportSpriteFrames(handler, Path.combine(selFile, SpriteExportSettings.EXPORT_FOLDER_NAME, exportMode.name()), swf, c.getCharacterId(), null, 1, ses, evl);
}
}
}
@@ -5392,6 +5392,67 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
export(true, selected);
}
public void exportSubspriteAnimationActionPerformed(TreeItem frame) {
if (Main.isWorking()) {
return;
}
int frameNum = ((Frame) frame).frame;
TreeItem parent = getCurrentTree().getFullModel().getParent(frame);
int containerId = 0;
if (parent instanceof DefineSpriteTag) {
containerId = ((DefineSpriteTag) parent).getCharacterId();
}
final int fContainerId = containerId;
ExportSubspriteAnimationDialog dialog = new ExportSubspriteAnimationDialog(this, Main.getDefaultDialogsOwner());
if (dialog.showDialog() != JOptionPane.OK_OPTION) {
return;
}
FrameExportMode mode = dialog.getFormat();
int length = dialog.getLength();
final String selFile = selectExportDir("export");
if (selFile != null) {
final long timeBefore = System.currentTimeMillis();
new CancellableWorker<Void>("export") {
@Override
public Void doInBackground() throws Exception {
try {
AbortRetryIgnoreHandler errorHandler = new GuiAbortRetryIgnoreHandler();
FrameExporter frameExporter = new FrameExporter();
FrameExportSettings fes = new FrameExportSettings(mode, dialog.getZoom(), dialog.isTransparentFrameBackgroundEnabled());
String subFolder = FrameExportSettings.EXPORT_FOLDER_NAME;
frameExporter.exportFrames(errorHandler, selFile + File.separator + subFolder, (SWF) frame.getOpenable(), fContainerId, Arrays.asList(frameNum), length, fes, null);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error during export", ex);
ViewMessages.showMessageDialog(null, translate("error.export") + ": " + ex.getClass().getName() + " " + ex.getLocalizedMessage());
}
return null;
}
@Override
protected void onStart() {
Main.startWork(translate("work.exporting") + "...", this);
}
@Override
protected void done() {
Main.stopWork();
long timeAfter = System.currentTimeMillis();
final long timeMs = timeAfter - timeBefore;
View.execInEventDispatch(() -> {
setStatus(translate("export.finishedin").replace("%time%", Helper.formatTimeSec(timeMs)));
});
}
}.execute();
}
}
public File showImportFileChooser(String filter, boolean imagePreview, String icon) {
return showImportFileChooser(filter, imagePreview, null, icon);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

@@ -0,0 +1,21 @@
# Copyright (C) 2025 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 = Export subsprite animation
format = Format:
length = Length:
frames = frames
button.ok = OK
button.cancel = Cancel
@@ -0,0 +1,21 @@
# Copyright (C) 2025 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 = Export animace podsprit\u016f
format = Form\u00e1t:
length = D\u00e9lka:
frames = sn\u00edmk\u016f
button.ok = OK
button.cancel = Storno
@@ -1071,4 +1071,6 @@ message.link.type.otherScript = Link to other script in this SWF
message.link.type.otherScript.sample = OtherClass
message.link.type.otherFile = Link to other SWF file (usually playerglobal.swc)
message.link.type.otherFile.sample = String
message.link.reallyGo = Do you really want to go to another SWF?
message.link.reallyGo = Do you really want to go to another SWF?
contextmenu.exportSubspriteAnimation = Export subsprite animation
@@ -1070,4 +1070,6 @@ message.link.type.otherScript = Odkaz na jin\u00fd skript v tomto SWF
message.link.type.otherScript.sample = JinaTrida
message.link.type.otherFile = Odkaz do jin\u00e9ho SWF souboru (obvykle playerglobal.swc)
message.link.type.otherFile.sample = String
message.link.reallyGo = Opravdu chcete p\u0159ej\u00edt do jin\u00e9ho SWF?
message.link.reallyGo = Opravdu chcete p\u0159ej\u00edt do jin\u00e9ho SWF?
contextmenu.exportSubspriteAnimation = Export animace podsprit\u016f
@@ -202,6 +202,8 @@ public class TagTreeContextMenu extends JPopupMenu {
private JMenuItem undoTagMenuItem;
private JMenuItem exportSelectionMenuItem;
private JMenuItem exportSubspriteAnimationMenuItem;
private JMenuItem exportABCMenuItem;
@@ -482,6 +484,17 @@ public class TagTreeContextMenu extends JPopupMenu {
});
exportSelectionMenuItem.setIcon(View.getIcon("exportsel16"));
add(exportSelectionMenuItem);
exportSubspriteAnimationMenuItem = new JMenuItem(mainPanel.translate("contextmenu.exportSubspriteAnimation"));
exportSubspriteAnimationMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainPanel.exportSubspriteAnimationActionPerformed(getCurrentItem());
}
});
exportSubspriteAnimationMenuItem.setIcon(View.getIcon("exportsubsprites16"));
add(exportSubspriteAnimationMenuItem);
exportABCMenuItem = new JMenuItem(mainPanel.translate("contextmenu.exportAbc"));
exportABCMenuItem.addActionListener(this::exportABCActionPerformed);
@@ -1304,6 +1317,7 @@ public class TagTreeContextMenu extends JPopupMenu {
cloneMenuItem.setVisible(allSelectedIsTagOrFrame && allSelectedSameParent);
undoTagMenuItem.setVisible(allSelectedIsTag);
exportSelectionMenuItem.setEnabled(hasExportableNodes); //?
exportSubspriteAnimationMenuItem.setVisible(false);
exportABCMenuItem.setVisible(false);
replaceMenuItem.setVisible(false);
replaceNoFillMenuItem.setVisible(false);
@@ -1775,6 +1789,10 @@ public class TagTreeContextMenu extends JPopupMenu {
changeCharsetMenu.setVisible(true);
}
}
if (firstItem instanceof Frame) {
exportSubspriteAnimationMenuItem.setVisible(true);
}
}
if (allSelectedIsShape) {