Option to get previous matrix for first instance of PlaceObjectTypeTag per depth

This commit is contained in:
Exund
2023-06-27 11:21:52 +02:00
committed by Jindra Petřík
parent a2f585ba5c
commit cb83c5a97e
4 changed files with 57 additions and 3 deletions

View File

@@ -483,6 +483,11 @@ public class PlaceObject2Tag extends PlaceObjectTypeTag implements ASMSourceCont
this.placeFlagMove = placeFlagMove;
}
@Override
public void setPlaceFlagMove(boolean placeFlagMove) {
this.placeFlagMove = placeFlagMove;
}
@Override
public boolean hasImage() {
return false;

View File

@@ -50,6 +50,8 @@ public class CollectDepthAsSpritesDialogue extends AppDialog {
private final JCheckBox replaceCheckBox;
private final JCheckBox offsetCheckBox;
private final JCheckBox firstMatrixCheckBox;
private int result = ERROR_OPTION;
@@ -74,6 +76,9 @@ public class CollectDepthAsSpritesDialogue extends AppDialog {
offsetCheckBox = new JCheckBox(translate("collect.offset"));
cnt.add(offsetCheckBox);
firstMatrixCheckBox = new JCheckBox(translate("collect.matrix"));
cnt.add(firstMatrixCheckBox);
JPanel panButtons = new JPanel(new FlowLayout());
okButton.addActionListener(this::okButtonActionPerformed);
@@ -116,6 +121,10 @@ public class CollectDepthAsSpritesDialogue extends AppDialog {
public boolean getOffset() {
return offsetCheckBox.isSelected();
}
public boolean getEnsureFirstMatrix() {
return firstMatrixCheckBox.isSelected();
}
public int showDialog(Collection<Integer> depths) {
depthsList.setListData(depths.toArray(new Integer[depths.size()]));

View File

@@ -17,6 +17,7 @@ dialog.title = Collect options
collect.depths = Depths to collect:
collect.replace = Replace original tags with sprite
collect.offset = Offset top left corner to (0,0)
collect.matrix = Use the previous frames matrix as the first PlaceObject matrix
button.ok = OK
button.cancel = Cancel

View File

@@ -643,6 +643,7 @@ public class TagTreeContextMenu extends JPopupMenu {
add(pasteInsideMenuItem);
collectDepthAsSpritesItem = new JMenuItem(mainPanel.translate("contextmenu.collectDepthAsSprites"));
collectDepthAsSpritesItem.setIcon(View.getIcon("sprite16"));
collectDepthAsSpritesItem.addActionListener(this::collectDepthAsSprites);
add(collectDepthAsSpritesItem);
@@ -4130,6 +4131,7 @@ public class TagTreeContextMenu extends JPopupMenu {
List<Integer> depths = dialog.getDepths();
boolean replace = dialog.getReplace();
boolean offset = dialog.getOffset();
boolean firstMatrix = dialog.getEnsureFirstMatrix();
Map<Integer, DefineSpriteTag> sprites = new HashMap<>();
for (int d : depths) {
@@ -4149,19 +4151,56 @@ public class TagTreeContextMenu extends JPopupMenu {
try {
for (int i = frames.size() - 1; i > -1; i--) {
Frame f = (Frame) frames.get(i);
Map<Integer, PlaceObjectTypeTag> prevMatrixAtDepth = new HashMap<>();
int pf = f.frame - 1;
for (int j = 0; j < f.innerTags.size(); j++) {
Tag t = f.innerTags.get(j);
int depth = -1;
if (t instanceof RemoveTag) {
depth = ((RemoveTag) t).getDepth();
} else if (t instanceof PlaceObjectTypeTag) {
depth = ((PlaceObjectTypeTag) t).getDepth();
PlaceObjectTypeTag place = (PlaceObjectTypeTag) t;
depth = place.getDepth();
if (firstMatrix && i == 0) {
if (place.getMatrix() == null) {
for (; pf > -1; pf--) {
if (prevMatrixAtDepth.containsKey(depth)) {
break;
}
Frame prev = f.timeline.getFrame(pf);
for (Tag pt : prev.innerTags) {
if (pt instanceof PlaceObjectTypeTag) {
PlaceObjectTypeTag pplace = (PlaceObjectTypeTag) pt;
prevMatrixAtDepth.putIfAbsent(pplace.getDepth(), pplace);
}
}
}
}
}
}
if (depth != -1) {
DefineSpriteTag sprite = sprites.get(depth);
Tag clone = t.cloneTag();
if (firstMatrix && i == 0 && clone instanceof PlaceObjectTypeTag) {
PlaceObjectTypeTag place = (PlaceObjectTypeTag) clone;
if (place.getMatrix() == null) {
PlaceObjectTypeTag previous = prevMatrixAtDepth.get(place.getDepth());
if (previous != null) {
MATRIX m = previous.getMatrix();
if (m != null) {
place.setPlaceFlagHasMatrix(true);
place.setPlaceFlagMove(true);
place.setMatrix(new MATRIX(m));
}
}
}
}
clone.setTimelined(sprite);
sprite.addTag(i, clone);
@@ -4235,7 +4274,7 @@ public class TagTreeContextMenu extends JPopupMenu {
}
swf.updateCharacters();
if(replace) {
if (replace) {
swf.computeDependentCharacters();
swf.computeDependentFrames();
}