Enabled selection of multiple images in the image resource pannel. Added drag and drop with multiple images to the tiles plugin.

This commit is contained in:
Jan-Thierry Wegener
2021-06-03 22:07:17 +02:00
parent 21ef61ffcd
commit e8a1bd8b70
14 changed files with 615 additions and 76 deletions
@@ -18,28 +18,28 @@
package games.rednblack.editor.plugin.tiled;
import java.util.HashMap;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop;
import games.rednblack.editor.plugin.tiled.view.SpineDrawable;
import games.rednblack.editor.renderer.factory.EntityFactory;
import games.rednblack.h2d.common.vo.CursorData;
import games.rednblack.editor.plugin.tiled.data.TileVO;
import games.rednblack.editor.plugin.tiled.tools.DeleteTileTool;
import games.rednblack.editor.plugin.tiled.tools.DrawTileTool;
import games.rednblack.editor.plugin.tiled.view.SpineDrawable;
import games.rednblack.editor.plugin.tiled.view.tabs.SettingsTab;
import games.rednblack.editor.renderer.components.DimensionsComponent;
import games.rednblack.editor.renderer.factory.EntityFactory;
import games.rednblack.editor.renderer.utils.ComponentRetriever;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.ResourcePayloadObject;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import java.util.HashMap;
/**
* Created by mariam on 2/2/2016.
@@ -63,6 +63,7 @@ public class TiledPanelMediator extends Mediator<TiledPanel> {
return new String[]{
MsgAPI.SCENE_LOADED,
TiledPlugin.TILE_ADDED,
TiledPlugin.IMAGE_BUNDLE_DROP_SINGLE,
TiledPlugin.TILE_SELECTED,
TiledPlugin.ACTION_DELETE_TILE,
TiledPlugin.ACTION_SET_GRID_SIZE_FROM_LIST,
@@ -105,10 +106,13 @@ public class TiledPanelMediator extends Mediator<TiledPanel> {
if (type == EntityFactory.UNKNOWN_TYPE) return; //only some resources can become a tile!
String tileName = resourcePayloadObject.name;
if (tiledPlugin.dataToSave.containsTile(tileName)) return;
// we send a notifier even in the case when the tile is not already added
tiledPlugin.facade.sendNotification(TiledPlugin.TILE_ADDED, new Object[]{tileName, type});
if (type == EntityFactory.IMAGE_TYPE) {
// ensure that all selected images are dropped
// the respective listener is responsible for dropping one-by-one, since he tracks the selected ones
tiledPlugin.facade.sendNotification(TiledPlugin.IMAGE_BUNDLE_DROP, new Object[]{tileName, type});
}
}
};
tiledPlugin.facade.sendNotification(MsgAPI.ADD_TARGET, target);
@@ -116,10 +120,15 @@ public class TiledPanelMediator extends Mediator<TiledPanel> {
viewComponent.setEngine(engine);
viewComponent.setFixedPosition();
break;
case TiledPlugin.IMAGE_BUNDLE_DROP_SINGLE:
// aliasing the drop from the main project
case TiledPlugin.TILE_ADDED:
Object[] payload = notification.getBody();
tileName = (String) payload[0];
int type = (int) payload[1];
// we only add tiles that have not been added previously
if (tiledPlugin.dataToSave.containsTile(tileName)) return;
viewComponent.addTile(tileName, type);
tiledPlugin.dataToSave.addTile(tileName, type);
@@ -18,6 +18,8 @@
package games.rednblack.editor.plugin.tiled;
import java.util.Set;
import com.badlogic.ashley.core.Entity;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
@@ -26,6 +28,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array;
import com.kotcrab.vis.ui.VisUI;
import com.kotcrab.vis.ui.widget.VisImageButton;
import games.rednblack.editor.plugin.tiled.data.TileVO;
import games.rednblack.editor.plugin.tiled.manager.ResourcesManager;
import games.rednblack.editor.plugin.tiled.offset.OffsetPanel;
@@ -45,8 +48,6 @@ import games.rednblack.h2d.common.MenuAPI;
import games.rednblack.h2d.common.plugins.H2DPluginAdapter;
import net.mountainblade.modular.annotations.Implementation;
import java.util.Set;
/**
* Created by mariam on 2/2/2016.
*/
@@ -66,6 +67,9 @@ public class TiledPlugin extends H2DPluginAdapter {
public static final String TILE_GRID_OFFSET_ADDED = CLASS_NAME + ".TILE_GRID_OFFSET_ADDED";
public static final String ACTION_SET_GRID_SIZE_FROM_ITEM = CLASS_NAME + ".ACTION_SET_GRID_SIZE_FROM_ITEM";
public static final String ACTION_SET_GRID_SIZE_FROM_LIST = CLASS_NAME + ".ACTION_SET_GRID_SIZE_FROM_LIST";
// notification from the main project
public static final String IMAGE_BUNDLE_DROP_SINGLE = "games.rednblack.editor.view.ui.box.UIResourcesBoxMediator.IMAGE_BUNDLE_DROP_SINGLE";
public static final String IMAGE_BUNDLE_DROP = "games.rednblack.editor.view.ui.box.UIResourcesBoxMediator.IMAGE_BUNDLE_DROP";
//-------end--------//
public static final String TILE_TAG = "TILE";
@@ -18,20 +18,52 @@
package games.rednblack.editor.controller;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.editor.view.ui.*;
import games.rednblack.editor.view.menu.HyperLap2DMenuBarMediator;
import games.rednblack.editor.view.HyperLap2DScreenMediator;
import games.rednblack.editor.view.stage.SandboxMediator;
import games.rednblack.editor.view.stage.UIStageMediator;
import games.rednblack.editor.view.ui.box.*;
import games.rednblack.editor.view.ui.box.bottom.*;
import games.rednblack.editor.view.ui.dialog.*;
import games.rednblack.editor.view.ui.panel.*;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.command.SimpleCommand;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.splash.SplashScreenAdapter;
import games.rednblack.editor.view.HyperLap2DScreenMediator;
import games.rednblack.editor.view.menu.HyperLap2DMenuBarMediator;
import games.rednblack.editor.view.stage.SandboxMediator;
import games.rednblack.editor.view.stage.UIStageMediator;
import games.rednblack.editor.view.ui.FollowersUIMediator;
import games.rednblack.editor.view.ui.ImageResourceSelectionUIMediator;
import games.rednblack.editor.view.ui.RulersUIMediator;
import games.rednblack.editor.view.ui.StickyNotesUIMediator;
import games.rednblack.editor.view.ui.UIDropDownMenuMediator;
import games.rednblack.editor.view.ui.UIWindowActionMediator;
import games.rednblack.editor.view.ui.UIWindowTitleMediator;
import games.rednblack.editor.view.ui.box.UIAlignBoxMediator;
import games.rednblack.editor.view.ui.box.UICompositeHierarchyMediator;
import games.rednblack.editor.view.ui.box.UIItemsTreeBoxMediator;
import games.rednblack.editor.view.ui.box.UILayerBoxMediator;
import games.rednblack.editor.view.ui.box.UIMultiPropertyBoxMediator;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.editor.view.ui.box.UIToolBoxMediator;
import games.rednblack.editor.view.ui.box.bottom.UIGridBoxMediator;
import games.rednblack.editor.view.ui.box.bottom.UILivePreviewBoxMediator;
import games.rednblack.editor.view.ui.box.bottom.UIResolutionBoxMediator;
import games.rednblack.editor.view.ui.box.bottom.UISceneBoxMediator;
import games.rednblack.editor.view.ui.box.bottom.UIZoomBoxMediator;
import games.rednblack.editor.view.ui.dialog.AboutDialogMediator;
import games.rednblack.editor.view.ui.dialog.AutoTraceDialogMediator;
import games.rednblack.editor.view.ui.dialog.CodeEditorDialogMediator;
import games.rednblack.editor.view.ui.dialog.ConsoleDialogMediator;
import games.rednblack.editor.view.ui.dialog.CreateNewResolutionDialogMediator;
import games.rednblack.editor.view.ui.dialog.CreateNoiseDialogMediator;
import games.rednblack.editor.view.ui.dialog.CreatePlaceholderDialogMediator;
import games.rednblack.editor.view.ui.dialog.LoadingBarDialogMediator;
import games.rednblack.editor.view.ui.dialog.NewProjectDialogMediator;
import games.rednblack.editor.view.ui.dialog.NodeEditorDialogMediator;
import games.rednblack.editor.view.ui.dialog.SaveProjectDialogMediator;
import games.rednblack.editor.view.ui.dialog.SettingsDialogMediator;
import games.rednblack.editor.view.ui.panel.CustomVariablesPanelMediator;
import games.rednblack.editor.view.ui.panel.EditSpriteAnimationPanelMediator;
import games.rednblack.editor.view.ui.panel.ImportPanelMediator;
import games.rednblack.editor.view.ui.panel.ShaderUniformsPanelMediator;
import games.rednblack.editor.view.ui.panel.TagsPanelMediator;
/**
* Created by sargis on 4/1/15.
*/
@@ -67,6 +99,9 @@ public class BootstrapViewCommand extends SimpleCommand {
facade.registerMediator(new UIStageMediator());
facade.registerMediator(new SandboxMediator());
facade.registerMediator(new UIDropDownMenuMediator());
// improved selection behavior for the image panel
facade.registerMediator(new ImageResourceSelectionUIMediator());
//Panels
facade.registerMediator(new ImportPanelMediator());
@@ -19,7 +19,11 @@
package games.rednblack.editor.view;
import com.badlogic.ashley.core.Engine;
import com.badlogic.gdx.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
@@ -29,20 +33,22 @@ import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.Align;
import games.rednblack.editor.HyperLap2DApp;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.proxy.SettingsManager;
import games.rednblack.editor.utils.KeyBindingsLayout;
import games.rednblack.editor.view.menu.FileMenu;
import games.rednblack.editor.view.menu.ResourcesMenu;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.view.stage.UIStage;
import games.rednblack.editor.view.stage.input.MetaKeyInputProcessor;
import games.rednblack.editor.view.stage.input.SandboxInputAdapter;
import games.rednblack.editor.view.ui.widget.actors.basic.SandboxBackUI;
import games.rednblack.editor.view.ui.widget.actors.basic.WhitePixel;
import games.rednblack.h2d.common.MenuAPI;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.editor.view.ui.widget.actors.basic.SandboxBackUI;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.view.stage.UIStage;
import games.rednblack.editor.view.stage.input.SandboxInputAdapter;
import games.rednblack.h2d.common.vo.SceneConfigVO;
public class HyperLap2DScreen implements Screen, InputProcessor {
@@ -141,6 +147,7 @@ public class HyperLap2DScreen implements Screen, InputProcessor {
multiplexer.addProcessor(this);
multiplexer.addProcessor(uiStage);
multiplexer.addProcessor(new SandboxInputAdapter());
multiplexer.addProcessor(MetaKeyInputProcessor.getInstance());
Gdx.input.setInputProcessor(multiplexer);
}
@@ -0,0 +1,132 @@
package games.rednblack.editor.view.stage.input;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
/**
* This processor serves other {@link InputListener} as a helper to know if the shift/alt/ctrl keys are pressed.
*
* This class is implemented as a singleton.
*
* @author Jan-Thierry Wegener
*
*/
public final class MetaKeyInputProcessor implements InputProcessor {
private static MetaKeyInputProcessor INSTANCE;
private boolean isShiftDown = false;
private boolean isCtrlDown = false;
private boolean isAltDown = false;
private MetaKeyInputProcessor() {
}
/**
* Facade Singleton Factory method
*
* @return The Singleton instance of the processor.
*/
public synchronized static MetaKeyInputProcessor getInstance() {
if (INSTANCE == null) {
INSTANCE = new MetaKeyInputProcessor();
}
return INSTANCE;
}
/**
* Returns whether a shift key is currently pressed or not.
*
* @return <code>true</code> if one of the shift keys is pressed, <code>false</code> otherwise.
*/
public boolean isShiftDown() {
return isShiftDown;
}
/**
* Returns whether a control key is currently pressed or not.
*
* @return <code>true</code> if one of the ctrl keys is pressed, <code>false</code> otherwise.
*/
public boolean isCtrlDown() {
return isCtrlDown;
}
/**
* Returns whether a alt key is currently pressed or not.
*
* @return <code>true</code> if one of the alt keys is pressed, <code>false</code> otherwise.
*/
public boolean isAltDown() {
return isAltDown;
}
@Override
public boolean keyDown(int keycode) {
switch (keycode) {
case Input.Keys.SHIFT_LEFT:
case Input.Keys.SHIFT_RIGHT:
isShiftDown = true;
break;
case Input.Keys.ALT_LEFT:
case Input.Keys.ALT_RIGHT:
isAltDown = true;
break;
case Input.Keys.CONTROL_LEFT:
case Input.Keys.CONTROL_RIGHT:
isCtrlDown = true;
break;
}
return false;
}
@Override
public boolean keyUp(int keycode) {
switch (keycode) {
case Input.Keys.SHIFT_LEFT:
case Input.Keys.SHIFT_RIGHT:
isShiftDown = false;
break;
case Input.Keys.ALT_LEFT:
case Input.Keys.ALT_RIGHT:
isAltDown = false;
break;
case Input.Keys.CONTROL_LEFT:
case Input.Keys.CONTROL_RIGHT:
isCtrlDown = false;
break;
}
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(float amountX, float amountY) {
return false;
}
}
@@ -0,0 +1,155 @@
package games.rednblack.editor.view.ui;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.puremvc.java.interfaces.INotification;
import org.puremvc.java.patterns.mediator.Mediator;
import com.badlogic.gdx.scenes.scene2d.ui.Cell;
import com.kotcrab.vis.ui.widget.VisTable;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.UIImagesTab;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.box.ImageResource;
/**
* This mediator is part of the behavior that allows multiple images to be selected and dropped to other panels (like the GridTilesTab from the tiles plugin).
*
* @author Jan-Thierry Wegener
*/
public class ImageResourceSelectionUIMediator extends Mediator<ImageResource> {
public static final String NAME = ImageResourceSelectionUIMediator.class.getCanonicalName();
private final SortedSet<String> imageResourceSelectedSet = new TreeSet<>();
/**
* The image table from {@link UIImagesTab}. This is the table we add our selection behavior to.
*/
private VisTable imagesTable;
private ImageResource imageResourcePreviousClick;
public ImageResourceSelectionUIMediator() {
super(NAME);
}
@Override
public void onRegister() {
super.onRegister();
}
@Override
public String[] listNotificationInterests() {
return new String[]{
UIResourcesBoxMediator.IMAGE_LEFT_CLICK,
UIResourcesBoxMediator.IMAGE_BUNDLE_DROP,
UIResourcesBoxMediator.IMAGE_TABLE_UPDATED
};
}
@Override
public void handleNotification(INotification notification) {
super.handleNotification(notification);
switch (notification.getName()) {
case UIResourcesBoxMediator.IMAGE_LEFT_CLICK:
ImageResource imageResource = notification.getBody();
if (imageResourceSelectedSet.remove(imageResource.getPayloadData().name)) {
setSelected(imageResource, false);
if (UIResourcesBoxMediator.SHIFT_EVENT_TYPE.equals(notification.getType())) {
removeBetween(imageResourcePreviousClick, imageResource);
}
} else {
setSelected(imageResource, true);
if (UIResourcesBoxMediator.SHIFT_EVENT_TYPE.equals(notification.getType())) {
addSelectionBetween(imageResourcePreviousClick, imageResource);
}
}
imageResourcePreviousClick = imageResource;
break;
case UIResourcesBoxMediator.IMAGE_BUNDLE_DROP:
Set<String> nameSet = new HashSet<>(imageResourceSelectedSet);
// remove the dropped one, so that it is not added twice
Object[] payloadBody = notification.getBody();
nameSet.remove(payloadBody[0]);
for (String name : nameSet) {
HyperLap2DFacade.getInstance().sendNotification(UIResourcesBoxMediator.IMAGE_BUNDLE_DROP_SINGLE, new Object[] {name, payloadBody[1]});
}
break;
case UIResourcesBoxMediator.IMAGE_TABLE_UPDATED:
imagesTable = notification.getBody();
break;
default:
System.err.println("Unknown notification: " + notification);
}
}
private void setSelected(ImageResource imageResource, boolean isSelected) {
if (isSelected) {
imageResource.switchToMouseOverColor();
imageResource.setHighlightWhenMouseOver(false);
imageResourceSelectedSet.add(imageResource.getPayloadData().name);
} else {
imageResource.switchToStandardColor();
imageResource.setHighlightWhenMouseOver(true);
imageResourceSelectedSet.remove(imageResource.getPayloadData().name);
}
}
private int getCellIndex(ImageResource imageResource, int defaultIndex) {
Cell<ImageResource> cell = imagesTable.getCell(imageResource);
int index = defaultIndex;
if (cell != null) {
// compute the indixes, should be faster than iterating over the array of cells
index = cell.getRow() * imagesTable.getColumns() + cell.getColumn();
}
return index;
}
private void addSelectionBetween(ImageResource imageResourceStart, ImageResource imageResourceEnd) {
int startIndex = getCellIndex(imageResourceStart, 0);
int endIndex = getCellIndex(imageResourceEnd, imagesTable.getCells().size - 1);
// we want to start with start :)
if (endIndex < startIndex) {
int tmp = startIndex;
startIndex = endIndex;
// add one to include the previously clicked image
endIndex = tmp;
}
for (int i = startIndex; i <= endIndex; i++) {
Cell<ImageResource> cell = imagesTable.getCells().get(i);
ImageResource imageResource = cell.getActor();
setSelected(imageResource, true);
}
}
private void removeBetween(ImageResource imageResourceStart, ImageResource imageResourceEnd) {
int startIndex = getCellIndex(imageResourceStart, 0);
int endIndex = getCellIndex(imageResourceEnd, imagesTable.getCells().size - 1);
// we want to start with start :)
if (endIndex < startIndex) {
int tmp = startIndex;
startIndex = endIndex;
// add one to include the previously clicked image
endIndex = tmp;
}
for (int i = startIndex; i <= endIndex; i++) {
Cell<ImageResource> cell = imagesTable.getCells().get(i);
ImageResource imageResource = cell.getActor();
setSelected(imageResource, false);
}
}
}
@@ -18,16 +18,22 @@
package games.rednblack.editor.view.ui.box;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop;
import com.badlogic.gdx.utils.Array;
import games.rednblack.editor.view.ui.box.resourcespanel.*;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.h2d.common.view.ui.widget.imagetabbedpane.ImageTab;
import java.util.stream.Stream;
import org.puremvc.java.interfaces.INotification;
import java.util.stream.Stream;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop;
import com.badlogic.gdx.utils.Array;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.proxy.ProjectManager;
import games.rednblack.editor.view.ui.box.resourcespanel.UIActionsTabMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.UIAnimationsTabMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.UIImagesTabMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.UILibraryItemsTabMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.UIParticleEffectsTabMediator;
import games.rednblack.h2d.common.MsgAPI;
import games.rednblack.h2d.common.view.ui.widget.imagetabbedpane.ImageTab;
/**
* Created by azakhary on 4/17/2015.
@@ -39,6 +45,15 @@ public class UIResourcesBoxMediator extends PanelMediator<UIResourcesBox> {
private static final String PREFIX = "games.rednblack.editor.view.ui.box.UIResourcesBoxMediator";
public static final String IMAGE_LEFT_CLICK = PREFIX + ".IMAGE_LEFT_CLICK";
public static final String IMAGE_BUNDLE_DROP = PREFIX + ".IMAGE_BUNDLE_DROP";
public static final String IMAGE_BUNDLE_DROP_SINGLE = PREFIX + ".IMAGE_BUNDLE_DROP_SINGLE";
public static final String SHIFT_EVENT_TYPE = PREFIX + ".SHIFT_EVENT_TYPE";
public static final String IMAGE_TABLE_UPDATED = PREFIX + ".IMAGE_TABLE_UPDATED";
public static final String IMAGE_RIGHT_CLICK = PREFIX + ".IMAGE_RIGHT_CLICK";
public static final String SPINE_ANIMATION_RIGHT_CLICK = PREFIX + ".SPINE_ANIMATION_RIGHT_CLICK";
public static final String SPRITE_ANIMATION_RIGHT_CLICK = PREFIX + ".SPRITE_ANIMATION_RIGHT_CLICK";
@@ -18,26 +18,28 @@
package games.rednblack.editor.view.ui.box.resourcespanel;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import java.util.function.BiFunction;
import org.apache.commons.lang3.ArrayUtils;
import org.puremvc.java.interfaces.INotification;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import games.rednblack.h2d.extention.spine.SpineItemType;
import games.rednblack.editor.controller.commands.resource.DeleteSpineAnimation;
import games.rednblack.editor.controller.commands.resource.DeleteSpriteAnimation;
import games.rednblack.editor.factory.ItemFactory;
import games.rednblack.editor.proxy.ResourceManager;
import games.rednblack.editor.renderer.factory.EntityFactory;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.DraggableResource;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.DraggableResourceView;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.box.BoxItemResource;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.box.SpineResource;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.box.SpriteResource;
import org.apache.commons.lang3.ArrayUtils;
import org.puremvc.java.interfaces.INotification;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import java.util.function.BiFunction;
import games.rednblack.h2d.extention.spine.SpineItemType;
/**
* Created by azakhary on 4/17/2015.
@@ -87,12 +89,13 @@ public class UIAnimationsTabMediator extends UIResourcesTabMediator<UIAnimations
viewComponent.setThumbnailBoxes(animationBoxes);
}
private void createAnimationResources(Set<String> strings, Class resourceClass, BiFunction<String, Vector2, Boolean> factoryFunction, String searchText) {
private void createAnimationResources(Set<String> strings, Class<? extends BoxItemResource> resourceClass, BiFunction<String, Vector2, Boolean> factoryFunction, String searchText) {
for (String animationName : strings) {
if (!animationName.contains(searchText)) continue;
try {
Constructor constructor = resourceClass.getConstructor(String.class);
DraggableResource draggableResource = new DraggableResource((DraggableResourceView) constructor.newInstance(animationName));
Constructor<? extends BoxItemResource> constructor = resourceClass.getConstructor(String.class, Color.class, Color.class, Color.class, Color.class, boolean.class);
DraggableResource draggableResource = new DraggableResource(constructor.newInstance(animationName, new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 0.4f),
new Color(200f / 255f, 200f / 255f, 200f / 255f, 0.2f), new Color(255f / 255f, 94f / 255f, 0f / 255f, 1f), true));
draggableResource.initDragDrop();
draggableResource.setFactoryFunction(factoryFunction);
animationBoxes.add(draggableResource);
@@ -19,13 +19,14 @@
package games.rednblack.editor.view.ui.box.resourcespanel;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.Array;
import com.kotcrab.vis.ui.VisUI;
import com.kotcrab.vis.ui.widget.VisScrollPane;
import com.kotcrab.vis.ui.widget.VisTable;
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.DraggableResource;
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
/**
* Created by azakhary on 4/17/2015.
@@ -64,5 +65,6 @@ public class UIImagesTab extends UIResourcesTab {
imagesTable.row();
}
}
HyperLap2DFacade.getInstance().sendNotification(UIResourcesBoxMediator.IMAGE_TABLE_UPDATED, imagesTable);
}
}
@@ -18,16 +18,18 @@
package games.rednblack.editor.view.ui.box.resourcespanel;
import org.apache.commons.lang3.ArrayUtils;
import org.puremvc.java.interfaces.INotification;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.utils.Array;
import games.rednblack.editor.controller.commands.resource.DeleteImageResource;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.factory.ItemFactory;
import games.rednblack.editor.proxy.ResourceManager;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.DraggableResource;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.box.ImageResource;
import org.apache.commons.lang3.ArrayUtils;
import org.puremvc.java.interfaces.INotification;
/**
* Created by azakhary on 4/17/2015.
@@ -74,7 +76,9 @@ public class UIImagesTabMediator extends UIResourcesTabMediator<UIImagesTab> {
for (TextureAtlas.AtlasRegion region : new Array.ArrayIterator<>(atlasRegions)) {
if(!region.name.contains(searchText))continue;
boolean is9patch = region.findValue("split") != null;
DraggableResource draggableResource = new DraggableResource(new ImageResource(region));
ImageResource imageResource = new ImageResource(region, new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 0.4f),
new Color(200f / 255f, 200f / 255f, 200f / 255f, 0.2f), new Color(255f / 255f, 94f / 255f, 0f / 255f, 1f), true);
DraggableResource draggableResource = new DraggableResource(imageResource);
if (is9patch) {
draggableResource.setFactoryFunction(ItemFactory.get()::create9Patch);
} else {
@@ -20,13 +20,18 @@ package games.rednblack.editor.view.ui.box.resourcespanel.draggable.box;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.utils.Null;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.view.ui.widget.actors.basic.PixelRect;
import games.rednblack.editor.view.stage.Sandbox;
import games.rednblack.editor.view.stage.input.MetaKeyInputProcessor;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.editor.view.ui.box.resourcespanel.draggable.DraggableResourceView;
import games.rednblack.editor.view.ui.widget.actors.basic.PixelRect;
/**
* Created by sargis on 5/6/15.
@@ -36,27 +41,134 @@ public abstract class BoxItemResource extends Group implements DraggableResource
protected float thumbnailSize = 50;
protected PixelRect rc;
/**
* The color to fill the background of the image. Also the color of the background when the mouse is not over the image.
*/
private final Color fillColor;
/**
* The standard color of the border. Also the color of the border when the mouse is not over the image.
*/
private final Color borderColor;
/**
* The color of the border when the mouse hovers over the image.
*/
private final Color borderMouseOverColor;
/**
* The color to fill the background of the image when the mouse hovers over the image.
*/
private final Color fillMouseOverColor;
/**
* Whether to change the border color when the mouse hovers over the image.
*/
private boolean highlightWhenMouseOver;
public BoxItemResource() {
this(new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 0.4f), Color.BLACK, Color.BLACK, false);
}
/**
* Creates a new box item resource with the given colors.
*
* @param region The atlas region for the image resource.
* @param fillColor The color to fill the background of the image.
* @param borderColor The standard color of the border. Also used when the mouse is not hovering over the image.
* @param fillMouseOverColor The color to fill the background of the image when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param borderMouseOverColor The color of the border when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param highlightWhenMouseOver Whether to change the border color when the mouse hovers over the image.
*/
public BoxItemResource(Color fillColor, Color borderColor, Color fillMouseOverColor, Color borderMouseOverColor, boolean highlightWhenMouseOver) {
sandbox = Sandbox.getInstance();
rc = new PixelRect(thumbnailSize, thumbnailSize);
rc.setFillColor(new Color(1, 1, 1, 0.2f));
rc.setBorderColor(new Color(1, 1, 1, 0.4f));
rc.setFillColor(fillColor);
rc.setBorderColor(borderColor);
addActor(rc);
setWidth(thumbnailSize);
setHeight(thumbnailSize);
this.fillColor = fillColor;
this.borderColor = borderColor;
this.fillMouseOverColor = fillMouseOverColor;
this.borderMouseOverColor = borderMouseOverColor;
this.highlightWhenMouseOver = highlightWhenMouseOver;
}
/**
* Sets the right-click event. Should not be used with {@link #setClickEvent(String, String, String)}.
*
* @param eventName The event name in case of a right-click.
* @param payload The payload for the right-click.
*/
public void setRightClickEvent(String eventName, String payload) {
setClickEvent(null, eventName, null, payload);
}
/**
* Sets the left/right-click event. Should not be used with {@link #setRightClickEvent(String, String)}.
*
* @param leftClickEventName The event name in case of a left-click.
* @param leftClickPayload The payload for the left-click.
* @param rightClickEventName The event name in case of a right-click.
* @param rightClickPayload The payload for the right-click.
*/
public void setClickEvent(String leftClickEventName, String rightClickEventName, Object leftClickPayload, Object rightClickPayload) {
addListener(new InputListener() {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
private boolean isOver;
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
super.touchDown(event, x, y, pointer, button);
return true;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
if(button == Input.Buttons.RIGHT) {
HyperLap2DFacade.getInstance().sendNotification(eventName, payload);
}
@Override
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
// we only care for the event if the mouse is still in this resource
if (isOver && !event.isTouchFocusCancel()) {
if(button == Input.Buttons.LEFT && leftClickEventName != null) {
String shiftEventType = MetaKeyInputProcessor.getInstance().isShiftDown() ? UIResourcesBoxMediator.SHIFT_EVENT_TYPE : null;
HyperLap2DFacade.getInstance().sendNotification(leftClickEventName, leftClickPayload, shiftEventType);
}
if(button == Input.Buttons.RIGHT && rightClickEventName != null) {
HyperLap2DFacade.getInstance().sendNotification(rightClickEventName, rightClickPayload);
}
}
}
@Override
public void enter (InputEvent event, float x, float y, int pointer, @Null Actor fromActor) {
// mouse is in the resource
isOver = true;
// check if we have to change the color
if (highlightWhenMouseOver) {
switchToMouseOverColor();
}
}
@Override
public void exit (InputEvent event, float x, float y, int pointer, @Null Actor fromActor) {
// mouse no longer in the resource
isOver = false;
// check if we have to revert the color
if (highlightWhenMouseOver) {
rc.setFillColor(fillColor);
rc.setBorderColor(borderColor);
}
}
});
}
public void setHighlightWhenMouseOver(boolean highlightWhenMouseOver) {
this.highlightWhenMouseOver = highlightWhenMouseOver;
}
public void switchToMouseOverColor() {
if (fillMouseOverColor != null && borderMouseOverColor != null) {
rc.setFillColor(fillMouseOverColor);
rc.setBorderColor(borderMouseOverColor);
}
}
public void switchToStandardColor() {
if (fillColor != null && borderColor != null) {
rc.setFillColor(fillColor);
rc.setBorderColor(borderColor);
}
}
}
@@ -18,19 +18,39 @@
package games.rednblack.editor.view.ui.box.resourcespanel.draggable.box;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import games.rednblack.h2d.common.ResourcePayloadObject;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.h2d.common.ResourcePayloadObject;
public class ImageResource extends BoxItemResource {
private final Image payloadImg;
private final ResourcePayloadObject payload;
public ImageResource(AtlasRegion region) {
// this is not changing the behavior of the former constructor
// as long as the colors of the super class are not changed
this(region, new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 0.4f), Color.BLACK, Color.BLACK, false);
}
/**
* Creates a new image resource from the given {@link AtlasRegion}.
*
* @param region The atlas region for the image resource.
* @param fillColor The color to fill the background of the image.
* @param borderColor The standard color of the border. Also used when the mouse is not hovering over the image.
* @param fillMouseOverColor The color to fill the background of the image when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param borderMouseOverColor The color of the border when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param highlightWhenMouseOver Whether to change the border color when the mouse hovers over the image.
*/
public ImageResource(AtlasRegion region, Color fillColor, Color borderColor, Color fillMouseOverColor, Color borderMouseOverColor, boolean highlightWhenMouseOver) {
super(fillColor, borderColor, fillMouseOverColor, borderMouseOverColor, highlightWhenMouseOver);
Image img = new Image(region);
if (img.getWidth() > thumbnailSize || img.getHeight() > thumbnailSize) {
// resizing is needed
@@ -52,8 +72,8 @@ public class ImageResource extends BoxItemResource {
}
addActor(img);
setRightClickEvent(UIResourcesBoxMediator.IMAGE_RIGHT_CLICK, region.name);
setClickEvent(UIResourcesBoxMediator.IMAGE_LEFT_CLICK, UIResourcesBoxMediator.IMAGE_RIGHT_CLICK, this, region.name);
payloadImg = new Image(region);
payload = new ResourcePayloadObject();
@@ -70,4 +90,5 @@ public class ImageResource extends BoxItemResource {
public ResourcePayloadObject getPayloadData() {
return payload;
}
}
@@ -19,14 +19,16 @@
package games.rednblack.editor.view.ui.box.resourcespanel.draggable.box;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import games.rednblack.h2d.common.ResourcePayloadObject;
import games.rednblack.editor.HyperLap2DFacade;
import games.rednblack.editor.renderer.data.SpineVO;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.editor.view.ui.widget.actors.SpineActor;
import games.rednblack.h2d.common.ResourcePayloadObject;
/**
* Created by azakhary on 7/3/2014.
@@ -40,7 +42,23 @@ public class SpineResource extends BoxItemResource {
private boolean isMouseInside = false;
public SpineResource(String animationName) {
super();
// this is not changing the behavior of the former constructor
// as long as the colors of the super class are not changed
this(animationName, new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 0.4f), Color.BLACK, Color.BLACK, false);
}
/**
* Creates a new spine resource from the given animation name.
*
* @param animationName The of the animation for the spine resource.
* @param fillColor The color to fill the background of the image.
* @param borderColor The standard color of the border. Also used when the mouse is not hovering over the image.
* @param fillMouseOverColor The color to fill the background of the image when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param borderMouseOverColor The color of the border when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param highlightWhenMouseOver Whether to change the border color when the mouse hovers over the image.
*/
public SpineResource(String animationName, Color fillColor, Color borderColor, Color fillMouseOverColor, Color borderMouseOverColor, boolean highlightWhenMouseOver) {
super(fillColor, borderColor, fillMouseOverColor, borderMouseOverColor, highlightWhenMouseOver);
facade = HyperLap2DFacade.getInstance();
SpineVO vo = new SpineVO();
vo.animationName = animationName;
@@ -69,12 +87,14 @@ public class SpineResource extends BoxItemResource {
animThumb.setAnimation(animThumb.skeletonData.getAnimations().get(0).getName());
addListener(new ClickListener() {
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
isMouseInside = true;
super.enter(event, x, y, pointer, fromActor);
}
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
isMouseInside = false;
super.enter(event, x, y, pointer, toActor);
}
@@ -18,14 +18,16 @@
package games.rednblack.editor.view.ui.box.resourcespanel.draggable.box;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import games.rednblack.h2d.common.ResourcePayloadObject;
import games.rednblack.editor.renderer.data.SpriteAnimationVO;
import games.rednblack.editor.renderer.resources.IResourceRetriever;
import games.rednblack.editor.view.ui.box.UIResourcesBoxMediator;
import games.rednblack.editor.view.ui.widget.actors.SpriteAnimationActor;
import games.rednblack.h2d.common.ResourcePayloadObject;
/**
* Created by azakhary on 7/3/2014.
@@ -40,7 +42,23 @@ public class SpriteResource extends BoxItemResource {
private boolean isMouseInside = false;
public SpriteResource(String animationName) {
super();
// this is not changing the behavior of the former constructor
// as long as the colors of the super class are not changed
this(animationName, new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 0.4f), Color.BLACK, Color.BLACK, false);
}
/**
* Creates a new sprite resource from the given animation name.
*
* @param animationName The of the animation for the sprite resource.
* @param fillColor The color to fill the background of the image.
* @param borderColor The standard color of the border. Also used when the mouse is not hovering over the image.
* @param fillMouseOverColor The color to fill the background of the image when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param borderMouseOverColor The color of the border when the mouse hovers over the image. Only used if the the parameter <code>highlightWhenMouseOver</code> is set to <code>true</code>.
* @param highlightWhenMouseOver Whether to change the border color when the mouse hovers over the image.
*/
public SpriteResource(String animationName, Color fillColor, Color borderColor, Color fillMouseOverColor, Color borderMouseOverColor, boolean highlightWhenMouseOver) {
super(fillColor, borderColor, fillMouseOverColor, borderMouseOverColor, highlightWhenMouseOver);
SpriteAnimationVO vo = new SpriteAnimationVO();
vo.animationName = animationName;
@@ -68,11 +86,13 @@ public class SpriteResource extends BoxItemResource {
addListener(new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
isMouseInside = true;
super.enter(event, x, y, pointer, fromActor);
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
isMouseInside = false;
super.enter(event, x, y, pointer, toActor);