Implemented ignoring blank tile (#95)
* Implemented ignoring blank tile Implemented ognoring bloank tile in ImportTileSetDialogMediator & ImportTileSetDialog * Remove log, update jar plugin --------- Co-authored-by: fgnm <fgnm.dev@gmail.com>
This commit is contained in:
Binary file not shown.
+13
-4
@@ -3,10 +3,7 @@ package games.rednblack.editor.plugin.tiled.view.dialog;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||||
import com.kotcrab.vis.ui.util.Validators;
|
import com.kotcrab.vis.ui.util.Validators;
|
||||||
import com.kotcrab.vis.ui.widget.VisLabel;
|
import com.kotcrab.vis.ui.widget.*;
|
||||||
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 com.kotcrab.vis.ui.widget.file.FileChooser;
|
||||||
import games.rednblack.h2d.common.H2DDialog;
|
import games.rednblack.h2d.common.H2DDialog;
|
||||||
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
|
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
|
||||||
@@ -21,6 +18,7 @@ public class ImportTileSetDialog extends H2DDialog {
|
|||||||
private final InputFileWidget imagePathField;
|
private final InputFileWidget imagePathField;
|
||||||
private final VisTextButton importButton;
|
private final VisTextButton importButton;
|
||||||
private final Facade facade;
|
private final Facade facade;
|
||||||
|
private final VisCheckBox removeBlankTileCheck;
|
||||||
|
|
||||||
public ImportTileSetDialog(Facade facade) {
|
public ImportTileSetDialog(Facade facade) {
|
||||||
super("Import TileSet");
|
super("Import TileSet");
|
||||||
@@ -40,6 +38,8 @@ public class ImportTileSetDialog extends H2DDialog {
|
|||||||
getContentTable().row().padTop(10);
|
getContentTable().row().padTop(10);
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Validators.IntegerValidator validator = new Validators.IntegerValidator();
|
Validators.IntegerValidator validator = new Validators.IntegerValidator();
|
||||||
|
|
||||||
width = StandardWidgetsFactory.createValidableTextField(validator);
|
width = StandardWidgetsFactory.createValidableTextField(validator);
|
||||||
@@ -55,6 +55,13 @@ public class ImportTileSetDialog extends H2DDialog {
|
|||||||
sizeTable.add("px");
|
sizeTable.add("px");
|
||||||
getContentTable().add(sizeTable);
|
getContentTable().add(sizeTable);
|
||||||
|
|
||||||
|
//test
|
||||||
|
getContentTable().row().padTop(10);
|
||||||
|
removeBlankTileCheck = StandardWidgetsFactory.createCheckBox("Remove blank tile");
|
||||||
|
getContentTable().add(removeBlankTileCheck);
|
||||||
|
getContentTable().row().padTop(10);
|
||||||
|
|
||||||
|
|
||||||
importButton = StandardWidgetsFactory.createTextButton("Import");
|
importButton = StandardWidgetsFactory.createTextButton("Import");
|
||||||
getButtonsTable().add(importButton);
|
getButtonsTable().add(importButton);
|
||||||
pack();
|
pack();
|
||||||
@@ -70,6 +77,8 @@ public class ImportTileSetDialog extends H2DDialog {
|
|||||||
return Integer.parseInt(height.getText());
|
return Integer.parseInt(height.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getBlankTileOption(){ return removeBlankTileCheck.isChecked(); }
|
||||||
|
|
||||||
private void setListeners() {
|
private void setListeners() {
|
||||||
importButton.addListener(new ClickListener() {
|
importButton.addListener(new ClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+34
-10
@@ -65,16 +65,15 @@ public class ImportTileSetDialogMediator extends Mediator<ImportTileSetDialog> {
|
|||||||
for (int y = 0; y < pixmap.getHeight(); y += tileH) {
|
for (int y = 0; y < pixmap.getHeight(); y += tileH) {
|
||||||
int w = x + tileW <= pixmap.getWidth() ? tileW : pixmap.getWidth() - x;
|
int w = x + tileW <= pixmap.getWidth() ? tileW : pixmap.getWidth() - x;
|
||||||
int h = y + tileH <= pixmap.getHeight() ? tileH : pixmap.getHeight() - y;
|
int h = y + tileH <= pixmap.getHeight() ? tileH : pixmap.getHeight() - y;
|
||||||
Pixmap tilePixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
|
if( getViewComponent().getBlankTileOption()){
|
||||||
tilePixmap.drawPixmap(pixmap, 0, 0, x, y, w, h);
|
if(!isBlankTile(pixmap, x, y, w, h)) { //check if the tile is blank (empty, if not it can be added)
|
||||||
|
createTilePixmap(pixmap,x,y,w,h,i,name,texturePackVO);
|
||||||
String imagesPath = getCurrentRawImagesPath() + File.separator + name + i + ".png";
|
i++;
|
||||||
FileHandle path = new FileHandle(imagesPath);
|
}
|
||||||
PixmapIO.writePNG(path, tilePixmap);
|
}else{
|
||||||
|
createTilePixmap(pixmap,x,y,w,h,i,name,texturePackVO);
|
||||||
tilePixmap.dispose();
|
i++;
|
||||||
texturePackVO.regions.add(name + i);
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +85,32 @@ public class ImportTileSetDialogMediator extends Mediator<ImportTileSetDialog> {
|
|||||||
facade.sendNotification(MsgAPI.ACTION_REPACK);
|
facade.sendNotification(MsgAPI.ACTION_REPACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createTilePixmap(Pixmap pixmap, int x, int y, int w, int h, int i, String name, TexturePackVO texturePackVO){
|
||||||
|
Pixmap tilePixmap = new Pixmap(w, h, Pixmap.Format.RGBA8888);
|
||||||
|
|
||||||
|
//insert control
|
||||||
|
|
||||||
|
tilePixmap.drawPixmap(pixmap, 0, 0, x, y, w, h);
|
||||||
|
|
||||||
|
int pix = pixmap.getPixel(x,y);
|
||||||
|
String imagesPath = getCurrentRawImagesPath() + File.separator + name + i + ".png";
|
||||||
|
FileHandle path = new FileHandle(imagesPath);
|
||||||
|
PixmapIO.writePNG(path, tilePixmap);
|
||||||
|
|
||||||
|
tilePixmap.dispose();
|
||||||
|
texturePackVO.regions.add(name + i);
|
||||||
|
}
|
||||||
|
|
||||||
public String getCurrentRawImagesPath() {
|
public String getCurrentRawImagesPath() {
|
||||||
return pluginAPI.getProjectPath() + File.separator + "assets" + File.separator + "orig" + File.separator + "images";
|
return pluginAPI.getProjectPath() + File.separator + "assets" + File.separator + "orig" + File.separator + "images";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isBlankTile(Pixmap pixmap ,int x, int y, int w, int h){
|
||||||
|
for(int cx = x; cx < x + w; cx += 1) {
|
||||||
|
for(int cy = y; cy < y + h; cy += 1 ){
|
||||||
|
if(pixmap.getPixel(cx, cy)!= 0) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user