Smart layers drag n drop

This commit is contained in:
fgnm
2023-05-09 11:06:34 +02:00
parent eccb55742a
commit 5ce48ffadf
5 changed files with 52 additions and 5 deletions
@@ -53,6 +53,7 @@ public class BootstrapCommand extends SimpleCommand {
facade.registerCommand(MsgAPI.ACTION_DELETE_LAYER, DeleteLayerCommand::new);
facade.registerCommand(MsgAPI.ACTION_NEW_LAYER, NewLayerCommand::new);
facade.registerCommand(MsgAPI.ACTION_SWAP_LAYERS, LayerSwapCommand::new);
facade.registerCommand(MsgAPI.ACTION_JUMP_LAYERS, LayerJumpCommand::new);
facade.registerCommand(MsgAPI.ACTION_RENAME_LAYER, RenameLayerCommand::new);
facade.registerCommand(MsgAPI.ACTION_ADD_COMPONENT, AddComponentToItemCommand::new);
@@ -0,0 +1,46 @@
package games.rednblack.editor.controller.commands;
import games.rednblack.editor.renderer.components.LayerMapComponent;
import games.rednblack.editor.utils.runtime.EntityUtils;
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
import games.rednblack.editor.view.stage.Sandbox;
public class LayerJumpCommand extends EntityModifyRevertibleCommand {
private static final String CLASS_NAME = "games.rednblack.editor.controller.commands.LayerJumpCommand";
public static final String DONE = CLASS_NAME + "DONE";
private Integer entityId;
private String sourceName;
private String targetName;
private void backup() {
if(entityId == null) {
Object[] payload = getNotification().getBody();
sourceName = (String) payload[0];
targetName = (String) payload[1];
entityId = EntityUtils.getEntityId(Sandbox.getInstance().getCurrentViewingEntity());
}
}
@Override
public void doAction() {
backup();
int viewingEntity = EntityUtils.getByUniqueId(entityId);
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
targetName = layerMapComponent.jump(sourceName, targetName);
facade.sendNotification(DONE);
}
@Override
public void undoAction() {
int viewingEntity = EntityUtils.getByUniqueId(entityId);
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
layerMapComponent.jump(sourceName, targetName);
facade.sendNotification(DONE);
}
}
@@ -74,7 +74,7 @@ public class UILayerBoxMediator extends PanelMediator<UILayerBox> {
DeleteLayerCommand.DONE,
DeleteLayerCommand.UNDONE,
NewLayerCommand.DONE,
LayerSwapCommand.DONE,
LayerJumpCommand.DONE,
RenameLayerCommand.DONE
@@ -136,9 +136,9 @@ public class UILayerBoxMediator extends PanelMediator<UILayerBox> {
});
break;
case UILayerBox.LAYER_DROPPED:
facade.sendNotification(MsgAPI.ACTION_SWAP_LAYERS, notification.getBody());
facade.sendNotification(MsgAPI.ACTION_JUMP_LAYERS, notification.getBody());
break;
case LayerSwapCommand.DONE:
case LayerJumpCommand.DONE:
int index = viewComponent.getCurrentSelectedLayerIndex();
initLayerData();
viewComponent.setCurrentSelectedLayer(index);