Search in sources :

Example 1 with SpineDrawable

use of games.rednblack.editor.plugin.tiled.view.SpineDrawable in project HyperLap2D by rednblackgames.

the class TiledPanelMediator method handleNotification.

@Override
public void handleNotification(INotification notification) {
    super.handleNotification(notification);
    String tileName;
    switch(notification.getName()) {
        case MsgAPI.SCENE_LOADED:
            tiledPlugin.isSceneLoaded = true;
            tiledPlugin.initSaveData();
            viewComponent.initView();
            targetGrid = initTarget(targetGrid, viewComponent.getDropTable(), false);
            targetAutoGrid = initTarget(targetAutoGrid, viewComponent.getAutoGridDropTable(), true);
            com.artemis.World engine = tiledPlugin.getAPI().getEngine();
            viewComponent.setEngine(engine);
            viewComponent.setFixedPosition();
            break;
        case MsgAPI.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];
            boolean isAutoTilesTarget = (boolean) payload[2];
            if (isAutoTilesTarget) {
                // we only add tiles that have not been added previously
                if (tiledPlugin.dataToSave.containsAutoTile(tileName))
                    return;
                // retract the images for the auto-tiles
                retractAutoTiles(tileName);
                viewComponent.addAutoTile(tileName, type);
                tiledPlugin.dataToSave.addAutoTile(tileName, type);
            } else {
                // 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);
                facade.sendNotification(MsgAPI.UPDATE_RESOURCES_LIST);
            }
            tiledPlugin.saveDataManager.save();
            break;
        case TiledPlugin.TILE_SELECTED:
        case TiledPlugin.AUTO_TILE_SELECTED:
            if (viewComponent.isAutoGridTilesTabSelected()) {
                viewComponent.selectAutoTile(notification.getBody());
            } else {
                viewComponent.selectTile(notification.getBody());
            }
            break;
        case TiledPlugin.AUTO_FILL_TILES:
            autoGridTileManager.autoFill();
            break;
        case TiledPlugin.OPEN_DROP_DOWN:
            tileName = notification.getBody();
            HashMap<String, String> actionsSet = new HashMap<>();
            actionsSet.put(TiledPlugin.ACTION_SET_GRID_SIZE_FROM_LIST, "Set grid size");
            actionsSet.put(TiledPlugin.ACTION_DELETE_TILE, "Delete");
            actionsSet.put(TiledPlugin.ACTION_DELETE_TILE_ALL, "Delete all...");
            actionsSet.put(TiledPlugin.ACTION_OPEN_OFFSET_PANEL, "Set offset");
            tiledPlugin.facade.sendNotification(TiledPlugin.TILE_SELECTED, tiledPlugin.dataToSave.getTile(tileName));
            tiledPlugin.getAPI().showPopup(actionsSet, tileName);
            break;
        case TiledPlugin.AUTO_OPEN_DROP_DOWN:
            tileName = notification.getBody();
            HashMap<String, String> autoActionsSet = new HashMap<>();
            autoActionsSet.put(TiledPlugin.ACTION_SET_GRID_SIZE_FROM_LIST, "Set grid size");
            autoActionsSet.put(TiledPlugin.ACTION_DELETE_AUTO_TILE, "Delete");
            // autoActionsSet.put(TiledPlugin.ACTION_OPEN_OFFSET_PANEL, "Set offset");
            autoActionsSet.put(TiledPlugin.ACTION_SETUP_ALTERNATIVES_AUTO_TILE, "Setup alternatives");
            tiledPlugin.facade.sendNotification(TiledPlugin.AUTO_TILE_SELECTED, tiledPlugin.dataToSave.getAutoTile(tileName));
            tiledPlugin.getAPI().showPopup(autoActionsSet, tileName);
            break;
        case MsgAPI.ACTION_DELETE_IMAGE_RESOURCE:
            tileName = notification.getBody();
            tiledPlugin.facade.sendNotification(TiledPlugin.ACTION_DELETE_TILE, tileName);
            tiledPlugin.facade.sendNotification(TiledPlugin.ACTION_DELETE_AUTO_TILE, tileName);
            break;
        case TiledPlugin.ACTION_SET_GRID_SIZE_FROM_LIST:
            float width = 0;
            float height = 0;
            if (tiledPlugin.isAutoGridTilesTabSelected()) {
                AutoTileVO t = tiledPlugin.dataToSave.getAutoTile(notification.getBody());
                TextureRegion r = tiledPlugin.pluginRM.getTextureRegion(t.regionName, t.entityType);
                width = r.getRegionWidth() / TiledPlugin.AUTO_TILE_COLS;
                height = r.getRegionHeight() / TiledPlugin.AUTO_TILE_ROWS;
            } else {
                TileVO t = tiledPlugin.dataToSave.getTile(notification.getBody());
                if (t.entityType == SpineItemType.SPINE_TYPE) {
                    SpineDrawable spineDrawable = tiledPlugin.pluginRM.getSpineDrawable(t.regionName);
                    width = spineDrawable.width;
                    height = spineDrawable.height;
                } else {
                    TextureRegion r = tiledPlugin.pluginRM.getTextureRegion(t.regionName, t.entityType);
                    width = r.getRegionWidth();
                    height = r.getRegionHeight();
                }
            }
            tiledPlugin.dataToSave.setGrid(width / tiledPlugin.getPixelToWorld(), height / tiledPlugin.getPixelToWorld());
            tiledPlugin.facade.sendNotification(TiledPlugin.GRID_CHANGED);
            break;
        case TiledPlugin.ACTION_DELETE_TILE:
            String tn = notification.getBody();
            if (!tiledPlugin.dataToSave.containsTile(tn))
                return;
            tiledPlugin.dataToSave.removeTile(tn);
            tiledPlugin.saveDataManager.save();
            tiledPlugin.setSelectedTileVO(new TileVO());
            viewComponent.removeTile();
            facade.sendNotification(MsgAPI.UPDATE_RESOURCES_LIST);
            break;
        case TiledPlugin.ACTION_DELETE_AUTO_TILE:
            String tn2 = notification.getBody();
            if (!tiledPlugin.dataToSave.containsAutoTile(tn2))
                return;
            tiledPlugin.dataToSave.removeAutoTile(tn2);
            tiledPlugin.saveDataManager.save();
            tiledPlugin.setSelectedAutoTileVO(new AutoTileVO());
            for (AutoTileVO autoTile : tiledPlugin.dataToSave.getAutoTiles()) {
                Iterator<AlternativeAutoTileVO> iter = autoTile.alternativeAutoTileList.iterator();
                while (iter.hasNext()) {
                    AlternativeAutoTileVO alternativeAutoTileVO = iter.next();
                    if (alternativeAutoTileVO.region.equals(tn2)) {
                        iter.remove();
                    }
                }
            }
            viewComponent.removeAutoTile();
            tiledPlugin.facade.sendNotification(TiledPlugin.ACTION_RECALC_PERCENT_ALTERNATIVES_AUTO_TILE);
            facade.sendNotification(MsgAPI.UPDATE_RESOURCES_LIST);
            break;
        case TiledPlugin.ACTION_DELETE_TILE_ALL:
            Dialogs.showOptionDialog(tiledPlugin.getAPI().getUIStage(), "Delete all...", "Do you really want to delete all tiles?", Dialogs.OptionDialogType.YES_NO, new OptionDialogAdapter() {

                @Override
                public void yes() {
                    tiledPlugin.dataToSave.removeAllTiles();
                    tiledPlugin.saveDataManager.save();
                    tiledPlugin.setSelectedTileVO(new TileVO());
                    viewComponent.removeAllTiles();
                    facade.sendNotification(MsgAPI.UPDATE_RESOURCES_LIST);
                }

                @Override
                public void no() {
                }
            });
            break;
        case MsgAPI.TOOL_SELECTED:
            String body = notification.getBody();
            switch(body) {
                case DeleteTileTool.NAME:
                case DrawTileTool.NAME:
                    if (viewComponent.isOpen) {
                        break;
                    }
                    viewComponent.show(tiledPlugin.getAPI().getUIStage());
                    if (tiledPlugin.isSceneLoaded) {
                        viewComponent.setFixedPosition();
                    }
                    break;
                default:
                    viewComponent.hide();
                    break;
            }
            break;
        case SettingsTab.OK_BTN_CLICKED:
            tiledPlugin.dataToSave.setParameterVO(notification.getBody());
            tiledPlugin.saveDataManager.save();
            break;
        case TiledPlugin.GRID_CHANGED:
            viewComponent.reInitGridSettings();
            tiledPlugin.saveDataManager.save();
            break;
        case TiledPlugin.ACTION_SET_GRID_SIZE_FROM_ITEM:
            int observable = notification.getBody();
            DimensionsComponent dimensionsComponent = ComponentRetriever.get(observable, DimensionsComponent.class, tiledPlugin.getAPI().getEngine());
            tiledPlugin.dataToSave.setGrid(dimensionsComponent.width, dimensionsComponent.height);
            tiledPlugin.facade.sendNotification(TiledPlugin.GRID_CHANGED);
            break;
        case MsgAPI.ACTION_KEY_DOWN:
            int keyCode = notification.getBody();
            if (Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) || Gdx.input.isKeyPressed(Input.Keys.CONTROL_RIGHT)) {
                if (keyCode == Input.Keys.B) {
                    facade.sendNotification(MsgAPI.TOOL_CLICKED, DrawTileTool.NAME);
                }
            }
            break;
    }
}
Also used : HashMap(java.util.HashMap) SpineDrawable(games.rednblack.editor.plugin.tiled.view.SpineDrawable) OptionDialogAdapter(com.kotcrab.vis.ui.util.dialog.OptionDialogAdapter) AlternativeAutoTileVO(games.rednblack.editor.plugin.tiled.data.AlternativeAutoTileVO) AlternativeAutoTileVO(games.rednblack.editor.plugin.tiled.data.AlternativeAutoTileVO) AutoTileVO(games.rednblack.editor.plugin.tiled.data.AutoTileVO) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) TileVO(games.rednblack.editor.plugin.tiled.data.TileVO) AlternativeAutoTileVO(games.rednblack.editor.plugin.tiled.data.AlternativeAutoTileVO) AutoTileVO(games.rednblack.editor.plugin.tiled.data.AutoTileVO) DimensionsComponent(games.rednblack.editor.renderer.components.DimensionsComponent) ResourcePayloadObject(games.rednblack.h2d.common.ResourcePayloadObject)

Example 2 with SpineDrawable

use of games.rednblack.editor.plugin.tiled.view.SpineDrawable in project HyperLap2D by rednblackgames.

the class AbstractGridTilesTab method setGridSizeToFirstTileSize.

protected void setGridSizeToFirstTileSize(String tileName, int type) {
    float width = 0;
    float height = 0;
    if (type == SpineItemType.SPINE_TYPE) {
        SpineDrawable spineDrawable = tiledPlugin.pluginRM.getSpineDrawable(tileName);
        width = spineDrawable.width;
        height = spineDrawable.height;
    } else {
        TextureRegion r = tiledPlugin.pluginRM.getTextureRegion(tileName, type);
        width = r.getRegionWidth();
        height = r.getRegionHeight();
    }
    float gridWidth = width / tiledPlugin.getPixelToWorld();
    float gridHeight = height / tiledPlugin.getPixelToWorld();
    tiledPlugin.dataToSave.setGrid(gridWidth, gridHeight);
    tiledPlugin.facade.sendNotification(TiledPlugin.GRID_CHANGED);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpineDrawable(games.rednblack.editor.plugin.tiled.view.SpineDrawable)

Example 3 with SpineDrawable

use of games.rednblack.editor.plugin.tiled.view.SpineDrawable in project HyperLap2D by rednblackgames.

the class ResourcesManager method getSpineDrawable.

public SpineDrawable getSpineDrawable(String name) {
    if (spineDrawableCache.get(name) == null) {
        SpineDataObject spineDataObject = (SpineDataObject) tiledPlugin.getAPI().getSceneLoader().getRm().getExternalItemType(SpineItemType.SPINE_TYPE, name);
        SkeletonData skeletonData = spineDataObject.skeletonData;
        Skeleton skeleton = new Skeleton(skeletonData);
        spineDrawableCache.put(name, new SpineDrawable(skeleton, skeletonRenderer));
    }
    return spineDrawableCache.get(name);
}
Also used : SpineDrawable(games.rednblack.editor.plugin.tiled.view.SpineDrawable) Skeleton(com.esotericsoftware.spine.Skeleton) SkeletonData(com.esotericsoftware.spine.SkeletonData) SpineDataObject(games.rednblack.h2d.extension.spine.SpineDataObject)

Aggregations

SpineDrawable (games.rednblack.editor.plugin.tiled.view.SpineDrawable)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 Skeleton (com.esotericsoftware.spine.Skeleton)1 SkeletonData (com.esotericsoftware.spine.SkeletonData)1 OptionDialogAdapter (com.kotcrab.vis.ui.util.dialog.OptionDialogAdapter)1 AlternativeAutoTileVO (games.rednblack.editor.plugin.tiled.data.AlternativeAutoTileVO)1 AutoTileVO (games.rednblack.editor.plugin.tiled.data.AutoTileVO)1 TileVO (games.rednblack.editor.plugin.tiled.data.TileVO)1 DimensionsComponent (games.rednblack.editor.renderer.components.DimensionsComponent)1 ResourcePayloadObject (games.rednblack.h2d.common.ResourcePayloadObject)1 SpineDataObject (games.rednblack.h2d.extension.spine.SpineDataObject)1 HashMap (java.util.HashMap)1