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.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.*;
|
||||
import com.kotcrab.vis.ui.widget.file.FileChooser;
|
||||
import games.rednblack.h2d.common.H2DDialog;
|
||||
import games.rednblack.h2d.common.view.ui.StandardWidgetsFactory;
|
||||
@@ -21,6 +18,7 @@ public class ImportTileSetDialog extends H2DDialog {
|
||||
private final InputFileWidget imagePathField;
|
||||
private final VisTextButton importButton;
|
||||
private final Facade facade;
|
||||
private final VisCheckBox removeBlankTileCheck;
|
||||
|
||||
public ImportTileSetDialog(Facade facade) {
|
||||
super("Import TileSet");
|
||||
@@ -40,6 +38,8 @@ public class ImportTileSetDialog extends H2DDialog {
|
||||
getContentTable().row().padTop(10);
|
||||
//
|
||||
|
||||
|
||||
|
||||
Validators.IntegerValidator validator = new Validators.IntegerValidator();
|
||||
|
||||
width = StandardWidgetsFactory.createValidableTextField(validator);
|
||||
@@ -55,6 +55,13 @@ public class ImportTileSetDialog extends H2DDialog {
|
||||
sizeTable.add("px");
|
||||
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");
|
||||
getButtonsTable().add(importButton);
|
||||
pack();
|
||||
@@ -70,6 +77,8 @@ public class ImportTileSetDialog extends H2DDialog {
|
||||
return Integer.parseInt(height.getText());
|
||||
}
|
||||
|
||||
public Boolean getBlankTileOption(){ return removeBlankTileCheck.isChecked(); }
|
||||
|
||||
private void setListeners() {
|
||||
importButton.addListener(new ClickListener() {
|
||||
@Override
|
||||
|
||||
+34
-10
@@ -65,16 +65,15 @@ public class ImportTileSetDialogMediator extends Mediator<ImportTileSetDialog> {
|
||||
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();
|
||||
texturePackVO.regions.add(name + i);
|
||||
i++;
|
||||
if( getViewComponent().getBlankTileOption()){
|
||||
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);
|
||||
i++;
|
||||
}
|
||||
}else{
|
||||
createTilePixmap(pixmap,x,y,w,h,i,name,texturePackVO);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +85,32 @@ public class ImportTileSetDialogMediator extends Mediator<ImportTileSetDialog> {
|
||||
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() {
|
||||
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