Improve tree view updates

This commit is contained in:
fgnm
2023-09-03 16:05:06 +02:00
parent 5efdf54923
commit 3535f40354
10 changed files with 49 additions and 35 deletions
@@ -101,8 +101,8 @@ public class ConvertToCompositeCommand extends EntityModifyRevertibleCommand {
//let everyone know
Facade.getInstance().sendNotification(DONE);
Facade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity);
sandbox.getSelector().setSelection(entity, true);
facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, entity);
}
@Override
@@ -57,6 +57,6 @@ public class CutItemsCommand extends EntityModifyRevertibleCommand {
Facade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity);
}
sandbox.getSelector().setSelections(newEntitiesList, true);
facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, newEntitiesList);
}
}
@@ -84,7 +84,7 @@ public class DeleteItemsCommand extends EntityModifyRevertibleCommand {
Facade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity);
}
sandbox.getSelector().setSelections(newEntitiesList, true);
facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, newEntitiesList);
}
public void setItemsToDelete(Set<Integer> entities) {
@@ -1,13 +1,14 @@
package games.rednblack.editor.controller.commands;
import games.rednblack.editor.renderer.components.LayerMapComponent;
import games.rednblack.editor.renderer.systems.LayerSystem;
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";
public static final String DONE = CLASS_NAME + ".DONE";
private Integer entityId;
@@ -31,8 +32,8 @@ public class LayerJumpCommand extends EntityModifyRevertibleCommand {
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
targetName = layerMapComponent.jump(sourceName, targetName);
Sandbox.getInstance().getEngine().getSystem(LayerSystem.class).process();
facade.sendNotification(DONE);
}
@Override
@@ -41,6 +42,7 @@ public class LayerJumpCommand extends EntityModifyRevertibleCommand {
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
layerMapComponent.jump(sourceName, targetName);
Sandbox.getInstance().getEngine().getSystem(LayerSystem.class).process();
facade.sendNotification(DONE);
}
}
@@ -19,6 +19,7 @@
package games.rednblack.editor.controller.commands;
import games.rednblack.editor.renderer.components.LayerMapComponent;
import games.rednblack.editor.renderer.systems.LayerSystem;
import games.rednblack.editor.utils.runtime.EntityUtils;
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
import games.rednblack.editor.view.stage.Sandbox;
@@ -52,8 +53,8 @@ public class LayerSwapCommand extends EntityModifyRevertibleCommand {
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
layerMapComponent.swap(sourceName, targetName);
Sandbox.getInstance().getEngine().getSystem(LayerSystem.class).process();
facade.sendNotification(DONE);
}
@Override
@@ -62,6 +63,7 @@ public class LayerSwapCommand extends EntityModifyRevertibleCommand {
LayerMapComponent layerMapComponent = SandboxComponentRetriever.get(viewingEntity, LayerMapComponent.class);
layerMapComponent.swap(targetName, sourceName);
Sandbox.getInstance().getEngine().getSystem(LayerSystem.class).process();
facade.sendNotification(DONE);
}
}
@@ -26,6 +26,7 @@ import games.rednblack.editor.renderer.components.ZIndexComponent;
import games.rednblack.editor.renderer.data.CompositeItemVO;
import games.rednblack.editor.renderer.data.MainItemVO;
import games.rednblack.editor.renderer.factory.EntityFactory;
import games.rednblack.editor.renderer.systems.LayerSystem;
import games.rednblack.editor.renderer.utils.HyperJson;
import games.rednblack.editor.utils.runtime.EntityUtils;
import games.rednblack.editor.utils.runtime.SandboxComponentRetriever;
@@ -71,12 +72,13 @@ public class PasteItemsCommand extends EntityModifyRevertibleCommand {
transformComponent.x += diff.x;
transformComponent.y += diff.y;
ZIndexComponent zIndexComponent = SandboxComponentRetriever.get(entity, ZIndexComponent.class);
// UILayerBoxMediator layerBoxMediator = facade.retrieveMediator(UILayerBoxMediator.NAME);
zIndexComponent.layerName = layerBoxMediator.getCurrentSelectedLayerName();
Sandbox.getInstance().getEngine().getSystem(LayerSystem.class).process();
Facade.getInstance().sendNotification(MsgAPI.NEW_ITEM_ADDED, entity);
pastedEntityIds.add(EntityUtils.getEntityId(entity));
}
sandbox.getSelector().setSelections(newEntitiesList, true);
facade.sendNotification(MsgAPI.ACTION_SET_SELECTION, newEntitiesList);
}
@Override
@@ -34,7 +34,7 @@ import java.util.Set;
public class SetSelectionCommand extends RevertibleCommand {
private static final String CLASS_NAME = "games.rednblack.editor.controller.commands.SetSelectionCommand";
public static final String DONE = CLASS_NAME + "DONE";
public static final String DONE = CLASS_NAME + ".DONE";
private Array<Integer> previousSelectionIds;
@@ -44,29 +44,35 @@ public class SetSelectionCommand extends RevertibleCommand {
HashSet<Integer> previousSelection = new HashSet<>(Sandbox.getInstance().getSelector().getSelectedItems());
previousSelectionIds = EntityUtils.getEntityId(previousSelection);
Set<Integer> items = getNotification().getBody();
if (getNotification().getBody() instanceof Integer) {
int entity = getNotification().getBody();
sandbox.getSelector().setSelection(entity, true);
} else {
Set<Integer> items = getNotification().getBody();
if(items == null) {
// deselect all
sandbox.getSelector().setSelections(items, true);
facade.sendNotification(DONE);
return;
}
if(items == null) {
// deselect all
sandbox.getSelector().setSelections(items, true);
facade.sendNotification(DONE);
return;
}
// check if items are in viewable element, if no - cancel
NodeComponent nodeComponent = SandboxComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class);
for (Iterator<Integer> iterator = items.iterator(); iterator.hasNext();) {
int item = iterator.next();
if(!nodeComponent.children.contains(item, false)) {
iterator.remove();
// check if items are in viewable element, if no - cancel
NodeComponent nodeComponent = SandboxComponentRetriever.get(sandbox.getCurrentViewingEntity(), NodeComponent.class);
for (Iterator<Integer> iterator = items.iterator(); iterator.hasNext();) {
int item = iterator.next();
if(!nodeComponent.children.contains(item, false)) {
iterator.remove();
}
}
if(items.size() == 0) {
cancel();
} else {
sandbox.getSelector().setSelections(items, true);
}
}
if(items.size() == 0) {
cancel();
} else {
sandbox.getSelector().setSelections(items, true);
}
facade.sendNotification(DONE);
}
@@ -69,10 +69,11 @@ public class UIItemsTreeBox extends UICollapsibleBox {
private final Vector2 tmp = new Vector2();
public UIItemsTreeBox() {
super("Items Tree", 180);
super("Items Tree", 190);
setMovable(false);
facade = Facade.getInstance();
treeTable = new VisTable();
treeTable.setFillParent(true);
treeTable.left();
zUp = StandardWidgetsFactory.createImageButton("arrow-button");
StandardWidgetsFactory.addTooltip(zUp, "Move Z-Index Up");
@@ -109,7 +110,7 @@ public class UIItemsTreeBox extends UICollapsibleBox {
tree = new VisTree<>();
scroller = StandardWidgetsFactory.createScrollPane(tree);
scroller.setFlickScroll(false);
treeTable.add(scroller).width(170).padTop(5).maxHeight(550).colspan(2);
treeTable.add(scroller).growX().padTop(5).maxHeight(550).colspan(2);
//
rootTreeNode = addTreeRoot(rootScene, null);
rootTreeNode.setExpanded(true);
@@ -2,10 +2,7 @@ package games.rednblack.editor.view.ui.box;
import com.badlogic.gdx.scenes.scene2d.utils.Selection;
import com.badlogic.gdx.utils.Array;
import games.rednblack.editor.controller.commands.AddSelectionCommand;
import games.rednblack.editor.controller.commands.ItemsMoveCommand;
import games.rednblack.editor.controller.commands.ReleaseSelectionCommand;
import games.rednblack.editor.controller.commands.SetSelectionCommand;
import games.rednblack.editor.controller.commands.*;
import games.rednblack.editor.controller.commands.resource.DeleteResourceCommand;
import games.rednblack.editor.renderer.data.LayerItemVO;
import games.rednblack.editor.utils.runtime.EntityUtils;
@@ -43,7 +40,9 @@ public class UIItemsTreeBoxMediator extends PanelMediator<UIItemsTreeBox> {
MsgAPI.DELETE_ITEMS_COMMAND_DONE);
interests.add(MsgAPI.ACTION_Z_INDEX_CHANGED,
MsgAPI.ACTION_CAMERA_CHANGE_COMPOSITE,
MsgAPI.ITEM_DATA_UPDATED);
MsgAPI.ITEM_DATA_UPDATED,
LayerJumpCommand.DONE);
interests.add(LayerSwapCommand.DONE);
}
@Override
@@ -64,6 +63,8 @@ public class UIItemsTreeBoxMediator extends PanelMediator<UIItemsTreeBox> {
case MsgAPI.NEW_ITEM_ADDED:
case MsgAPI.DELETE_ITEMS_COMMAND_DONE:
case DeleteResourceCommand.DONE:
case LayerJumpCommand.DONE:
case LayerSwapCommand.DONE:
rootEntity = sandbox.getCurrentViewingEntity();
if (notification.getType() == null || !notification.getType().equals(ItemsMoveCommand.TAG))
viewComponent.update(rootEntity);