[editor only] Tileset auto splitter
This commit is contained in:
Binary file not shown.
+1
-1
@@ -2,7 +2,7 @@ gdxVersion = 1.10.0
|
||||
gdxVersionBeta = 1.10.0
|
||||
ashleyVersion = 1.7.4
|
||||
spineVersion = 3.8.55.1
|
||||
visuiVersion = 1.5.0-SNAPSHOT
|
||||
visuiVersion = 1.5.0
|
||||
typingLabelVersion = 1.2.0
|
||||
shapedrawerVersion = 2.4.0
|
||||
talosVersion = 1.3.1
|
||||
@@ -34,12 +34,14 @@ import games.rednblack.editor.plugin.tiled.save.DataToSave;
|
||||
import games.rednblack.editor.plugin.tiled.save.SaveDataManager;
|
||||
import games.rednblack.editor.plugin.tiled.tools.DeleteTileTool;
|
||||
import games.rednblack.editor.plugin.tiled.tools.DrawTileTool;
|
||||
import games.rednblack.editor.plugin.tiled.view.dialog.ImportTileSetDialogMediator;
|
||||
import games.rednblack.editor.renderer.components.MainItemComponent;
|
||||
import games.rednblack.editor.renderer.components.TextureRegionComponent;
|
||||
import games.rednblack.editor.renderer.components.TransformComponent;
|
||||
import games.rednblack.editor.renderer.components.ZIndexComponent;
|
||||
import games.rednblack.editor.renderer.utils.ComponentRetriever;
|
||||
import games.rednblack.editor.renderer.utils.CustomVariables;
|
||||
import games.rednblack.h2d.common.MenuAPI;
|
||||
import games.rednblack.h2d.common.plugins.H2DPluginAdapter;
|
||||
import net.mountainblade.modular.annotations.Implementation;
|
||||
|
||||
@@ -57,6 +59,7 @@ public class TiledPlugin extends H2DPluginAdapter {
|
||||
public static final String TILE_SELECTED = CLASS_NAME + ".TILE_SELECTED";
|
||||
public static final String OPEN_DROP_DOWN = CLASS_NAME + ".OPEN_DROP_DOWN";
|
||||
public static final String GRID_CHANGED = CLASS_NAME + ".GRID_CHANGED";
|
||||
public static final String IMPORT_TILESET_PANEL_OPEN = CLASS_NAME + ".IMPORT_TILESET_PANEL_OPEN";
|
||||
public static final String ACTION_DELETE_TILE = CLASS_NAME + ".ACTION_DELETE_TILE";
|
||||
public static final String ACTION_SET_OFFSET = CLASS_NAME + ".ACTION_SET_OFFSET";
|
||||
public static final String ACTION_OPEN_OFFSET_PANEL = CLASS_NAME + ".ACTION_OPEN_OFFSET_PANEL";
|
||||
@@ -91,6 +94,7 @@ public class TiledPlugin extends H2DPluginAdapter {
|
||||
@Override
|
||||
public void initPlugin() {
|
||||
facade.registerMediator(new TiledPanelMediator(this));
|
||||
facade.registerMediator(new ImportTileSetDialogMediator(pluginAPI, facade));
|
||||
|
||||
pluginRM = new ResourcesManager(this);
|
||||
offsetPanel = new OffsetPanel(this);
|
||||
@@ -117,6 +121,8 @@ public class TiledPlugin extends H2DPluginAdapter {
|
||||
pluginAPI.addTool(DeleteTileTool.NAME, tileDeleteButtonStyle, false, deleteTileTool);
|
||||
|
||||
pluginAPI.setDropDownItemName(ACTION_SET_GRID_SIZE_FROM_ITEM, "Set tile grid size");
|
||||
|
||||
pluginAPI.addMenuItem(MenuAPI.RESOURCE_MENU, "Import Tile Set...", IMPORT_TILESET_PANEL_OPEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package games.rednblack.editor.plugin.tiled.view.dialog;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import com.kotcrab.vis.ui.util.Validators;
|
||||
import com.kotcrab.vis.ui.widget.VisLabel;
|
||||
import com.kotcrab.vis.ui.widget.VisTable;
|
||||
import com.kotcrab.vis.ui.widget.VisTextButton;
|
||||
import com.kotcrab.vis.ui.widget.VisValidatableTextField;
|
||||
import com.kotcrab.vis.ui.widget.file.FileChooser;
|
||||
import games.rednblack.h2d.common.H2DDialog;
|
||||
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
|
||||
import games.rednblack.h2d.common.view.ui.widget.InputFileWidget;
|
||||
import org.puremvc.java.interfaces.IFacade;
|
||||
|
||||
public class ImportTileSetDialog extends H2DDialog {
|
||||
private static final String prefix = "games.rednblack.editor.plugin.tiled.view.dialog.ImportTileSetDialog";
|
||||
public static final String IMPORT_TILESET = prefix + ".IMPORT_TILESET";
|
||||
|
||||
private final VisValidatableTextField width, height;
|
||||
private final InputFileWidget imagePathField;
|
||||
private final VisTextButton importButton;
|
||||
private final IFacade facade;
|
||||
|
||||
public ImportTileSetDialog(IFacade facade) {
|
||||
super("Import TileSet");
|
||||
this.facade = facade;
|
||||
|
||||
setModal(true);
|
||||
addCloseButton();
|
||||
VisTable fileTable = new VisTable();
|
||||
fileTable.pad(6);
|
||||
//
|
||||
fileTable.add(new VisLabel("Tile Set:")).right().padRight(5);
|
||||
imagePathField = new InputFileWidget(FileChooser.Mode.OPEN, FileChooser.SelectionMode.FILES, false);
|
||||
imagePathField.setTextFieldWidth(156);
|
||||
fileTable.add(imagePathField);
|
||||
getContentTable().add(fileTable);
|
||||
//
|
||||
getContentTable().row().padTop(10);
|
||||
//
|
||||
|
||||
Validators.IntegerValidator validator = new Validators.IntegerValidator();
|
||||
|
||||
width = StandardWidgetsFactory.createValidableTextField(validator);
|
||||
height = StandardWidgetsFactory.createValidableTextField(validator);
|
||||
|
||||
VisTable sizeTable = new VisTable();
|
||||
sizeTable.add("Width:").padRight(3);
|
||||
sizeTable.add(width).width(60);
|
||||
sizeTable.add("px");
|
||||
sizeTable.row().padTop(5);
|
||||
sizeTable.add("Height:").padRight(3);
|
||||
sizeTable.add(height).width(60);
|
||||
sizeTable.add("px");
|
||||
getContentTable().add(sizeTable);
|
||||
|
||||
importButton = StandardWidgetsFactory.createTextButton("Import");
|
||||
getButtonsTable().add(importButton);
|
||||
pack();
|
||||
|
||||
setListeners();
|
||||
}
|
||||
|
||||
public int getTileWidth() {
|
||||
return Integer.parseInt(width.getText());
|
||||
}
|
||||
|
||||
public int getTileHeight() {
|
||||
return Integer.parseInt(height.getText());
|
||||
}
|
||||
|
||||
private void setListeners() {
|
||||
importButton.addListener(new ClickListener() {
|
||||
@Override
|
||||
public void clicked(InputEvent event, float x, float y) {
|
||||
if (width.isInputValid() && height.isInputValid() && imagePathField.getValue() != null) {
|
||||
facade.sendNotification(IMPORT_TILESET, imagePathField.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package games.rednblack.editor.plugin.tiled.view.dialog;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.PixmapIO;
|
||||
import games.rednblack.editor.plugin.tiled.TiledPlugin;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.plugins.PluginAPI;
|
||||
import org.puremvc.java.interfaces.IFacade;
|
||||
import org.puremvc.java.interfaces.INotification;
|
||||
import org.puremvc.java.patterns.mediator.Mediator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ImportTileSetDialogMediator extends Mediator<ImportTileSetDialog> {
|
||||
private static final String TAG = ImportTileSetDialogMediator.class.getCanonicalName();
|
||||
public static final String NAME = TAG;
|
||||
|
||||
private final PluginAPI pluginAPI;
|
||||
|
||||
public ImportTileSetDialogMediator(PluginAPI pluginAPI, IFacade facade) {
|
||||
super(NAME, new ImportTileSetDialog(facade));
|
||||
this.pluginAPI = pluginAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] listNotificationInterests() {
|
||||
return new String[] {
|
||||
TiledPlugin.IMPORT_TILESET_PANEL_OPEN,
|
||||
ImportTileSetDialog.IMPORT_TILESET
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleNotification(INotification notification) {
|
||||
switch (notification.getName()) {
|
||||
case TiledPlugin.IMPORT_TILESET_PANEL_OPEN:
|
||||
viewComponent.show(pluginAPI.getUIStage());
|
||||
break;
|
||||
case ImportTileSetDialog.IMPORT_TILESET:
|
||||
FileHandle tileset = notification.getBody();
|
||||
importTileset(tileset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void importTileset(FileHandle tileset) {
|
||||
byte[] image = tileset.readBytes();
|
||||
Pixmap pixmap = new Pixmap(image, 0, image.length);
|
||||
String name = tileset.nameWithoutExtension();
|
||||
|
||||
int tileW = viewComponent.getTileWidth();
|
||||
int tileH = viewComponent.getTileHeight();
|
||||
|
||||
int i = 0;
|
||||
for (int x = 0; x < pixmap.getWidth(); x += tileW) {
|
||||
for (int y = 0; y < pixmap.getHeight(); y += tileH) {
|
||||
int w = x + tileW <= pixmap.getWidth() ? tileW : pixmap.getWidth() - x;
|
||||
int h = y + tileH <= pixmap.getHeight() ? tileH : pixmap.getHeight() - y;
|
||||
Pixmap tilePixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
|
||||
tilePixmap.drawPixmap(pixmap, 0, 0, x, y, w, h);
|
||||
|
||||
String imagesPath = getCurrentRawImagesPath() + File.separator + name + i + ".png";
|
||||
FileHandle path = new FileHandle(imagesPath);
|
||||
PixmapIO.writePNG(path, tilePixmap);
|
||||
|
||||
tilePixmap.dispose();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
pixmap.dispose();
|
||||
|
||||
viewComponent.close();
|
||||
facade.sendNotification(MsgAPI.ACTION_REPACK);
|
||||
}
|
||||
|
||||
public String getCurrentRawImagesPath() {
|
||||
return pluginAPI.getProjectPath() + File.separator + "assets" + File.separator + "orig" + File.separator + "images";
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,6 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
packer.setTransparentColor(Color.WHITE);
|
||||
packer.getTransparentColor().a = 0;
|
||||
|
||||
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("freetypefonts/DejaVuSans.ttf"));
|
||||
FreeTypeFontGenerator monoGenerator = new FreeTypeFontGenerator(Gdx.files.internal("freetypefonts/FiraCode-Regular.ttf"));
|
||||
|
||||
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
|
||||
@@ -98,27 +97,19 @@ public class ResourceManager extends Proxy implements IResourceRetriever {
|
||||
parameter.minFilter = Texture.TextureFilter.Linear;
|
||||
parameter.magFilter = Texture.TextureFilter.Linear;
|
||||
|
||||
parameter.size = 10;
|
||||
BitmapFont smallFont = generator.generateFont(parameter);
|
||||
|
||||
parameter.size = 12;
|
||||
BitmapFont defaultFont = generator.generateFont(parameter);
|
||||
|
||||
parameter.size = 14;
|
||||
BitmapFont bigFont = generator.generateFont(parameter);
|
||||
BitmapFont defaultMono = monoGenerator.generateFont(parameter);
|
||||
defaultMono.setFixedWidthGlyphs(parameter.characters);
|
||||
|
||||
generator.dispose();
|
||||
monoGenerator.dispose();
|
||||
|
||||
ShadedDistanceFieldFont smallDistanceField = new ShadedDistanceFieldFont(Gdx.files.internal("style/default-font-32.fnt"));
|
||||
TextureRegion dejavuRegion = new TextureRegion(new Texture(Gdx.files.internal("style/default-font-32.png")));
|
||||
ShadedDistanceFieldFont smallDistanceField = new ShadedDistanceFieldFont(Gdx.files.internal("style/default-font-32.fnt"), dejavuRegion);
|
||||
smallDistanceField.setDistanceFieldSmoothing(6);
|
||||
smallDistanceField.getData().setScale(0.35f);
|
||||
ShadedDistanceFieldFont defaultDistanceField = new ShadedDistanceFieldFont(Gdx.files.internal("style/default-font-32.fnt"));
|
||||
ShadedDistanceFieldFont defaultDistanceField = new ShadedDistanceFieldFont(Gdx.files.internal("style/default-font-32.fnt"), dejavuRegion);
|
||||
defaultDistanceField.setDistanceFieldSmoothing(6);
|
||||
defaultDistanceField.getData().setScale(0.4f);
|
||||
ShadedDistanceFieldFont bigDistanceField = new ShadedDistanceFieldFont(Gdx.files.internal("style/default-font-32.fnt"));
|
||||
ShadedDistanceFieldFont bigDistanceField = new ShadedDistanceFieldFont(Gdx.files.internal("style/default-font-32.fnt"), dejavuRegion);
|
||||
bigDistanceField.setDistanceFieldSmoothing(6);
|
||||
bigDistanceField.getData().setScale(0.5f);
|
||||
/* Create the ObjectMap and add the fonts to it */
|
||||
|
||||
@@ -68,18 +68,23 @@ public class HyperLap2DMenuBar extends CustomMenuBar {
|
||||
|
||||
public void addMenuItem(String menu, String subMenuName, String notificationName) {
|
||||
if(menu.equals(MenuAPI.FILE_MENU)) {
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.addItem(new MenuItem(subMenuName, new MenuItemListener(notificationName, null, menu)));
|
||||
}
|
||||
if(menu.equals(MenuAPI.EDIT_MENU)) {
|
||||
editMenu.addSeparator();
|
||||
editMenu.addItem(new MenuItem(subMenuName, new MenuItemListener(notificationName, null, menu)));
|
||||
}
|
||||
if(menu.equals(MenuAPI.RESOURCE_MENU)) {
|
||||
resourcesMenu.addSeparator();
|
||||
resourcesMenu.addItem(new MenuItem(subMenuName, new MenuItemListener(notificationName, null, menu)));
|
||||
}
|
||||
if(menu.equals(MenuAPI.WINDOW_MENU)) {
|
||||
windowMenu.addSeparator();
|
||||
windowMenu.addItem(new MenuItem(subMenuName, new MenuItemListener(notificationName, null, menu)));
|
||||
}
|
||||
if(menu.equals(MenuAPI.HELP_MENU)) {
|
||||
helpMenu.addSeparator();
|
||||
helpMenu.addItem(new MenuItem(subMenuName, new MenuItemListener(notificationName, null, menu)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user