Skip to content

Commit 5eb1dc8

Browse files
committed
Added UI import/export buttons in editor.
1 parent 98b51ea commit 5eb1dc8

File tree

2 files changed

+106
-9
lines changed

2 files changed

+106
-9
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/ImageUtils.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,22 @@ public boolean accept(File dir, String name) {
125125
}
126126

127127
public static void scaleAtlas(File orgAtlas, File destDir, float scale) throws IOException {
128-
CustomTextureUnpacker unpacker = new CustomTextureUnpacker();
129-
File outputDir = DesktopUtils.createTempDirectory();
130-
131-
String atlasParentPath = orgAtlas.getParentFile().getAbsolutePath();
132-
133-
TextureAtlasData atlas = new TextureAtlasData(new FileHandle(orgAtlas), new FileHandle(atlasParentPath), false);
128+
File tmpDir = DesktopUtils.createTempDirectory();
129+
134130
EditorLogger.debug("SCALING: " + orgAtlas.getName());
135-
unpacker.splitAtlas(atlas, outputDir.getAbsolutePath());
131+
unpackAtlas(orgAtlas, tmpDir);
136132

137-
createAtlas(outputDir.getAbsolutePath(), destDir.getAbsolutePath(), orgAtlas.getName(), scale,
133+
createAtlas(tmpDir.getAbsolutePath(), destDir.getAbsolutePath(), orgAtlas.getName(), scale,
138134
TextureFilter.Linear, TextureFilter.Linear);
139135

140-
DesktopUtils.removeDir(outputDir.getAbsolutePath());
136+
DesktopUtils.removeDir(tmpDir.getAbsolutePath());
137+
}
138+
139+
public static void unpackAtlas(File orgAtlas, File destDir) {
140+
CustomTextureUnpacker unpacker = new CustomTextureUnpacker();
141+
String atlasParentPath = orgAtlas.getParentFile().getAbsolutePath();
142+
TextureAtlasData atlas = new TextureAtlasData(new FileHandle(orgAtlas), new FileHandle(atlasParentPath), false);
143+
unpacker.splitAtlas(atlas, destDir.getAbsolutePath());
141144
}
142145

143146
public static void scaleDirAtlases(File orgDir, File destDir, float scale) throws IOException {

adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ToolsWindow.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
******************************************************************************/
1616
package com.bladecoder.engineeditor.scneditor;
1717

18+
import java.io.File;
1819
import java.io.IOException;
1920

2021
import com.badlogic.gdx.Gdx;
2122
import com.badlogic.gdx.files.FileHandle;
23+
import com.badlogic.gdx.graphics.Texture.TextureFilter;
2224
import com.badlogic.gdx.scenes.scene2d.Actor;
2325
import com.badlogic.gdx.scenes.scene2d.Stage;
2426
import com.badlogic.gdx.scenes.scene2d.ui.Container;
@@ -34,9 +36,11 @@
3436
import com.bladecoder.engineeditor.Ctx;
3537
import com.bladecoder.engineeditor.common.EditorLogger;
3638
import com.bladecoder.engineeditor.common.I18NUtils;
39+
import com.bladecoder.engineeditor.common.ImageUtils;
3740
import com.bladecoder.engineeditor.common.Message;
3841
import com.bladecoder.engineeditor.common.ModelTools;
3942
import com.bladecoder.engineeditor.common.RunProccess;
43+
import com.bladecoder.engineeditor.model.Project;
4044
import com.kotcrab.vis.ui.widget.file.FileChooser;
4145
import com.kotcrab.vis.ui.widget.file.FileChooser.Mode;
4246
import com.kotcrab.vis.ui.widget.file.FileChooser.SelectionMode;
@@ -60,6 +64,9 @@ public ToolsWindow(Skin skin, ScnWidget sw) {
6064
TextButton testOnIOSDeviceButton = new TextButton("Test on IOS device", skin, "no-toggled");
6165
TextButton exportTSVButton = new TextButton("I18N - Export texts as .tsv", skin, "no-toggled");
6266
TextButton importTSVButton = new TextButton("I18N - Import.tsv file", skin, "no-toggled");
67+
68+
TextButton exportUIImages = new TextButton("Export UI Images", skin, "no-toggled");
69+
TextButton createUIAtlas = new TextButton("Create UI Atlas", skin, "no-toggled");
6370

6471
table.defaults().left().expandX();
6572
table.top().pad(DPIUtils.getSpacing() / 2);
@@ -92,6 +99,12 @@ public ToolsWindow(Skin skin, ScnWidget sw) {
9299

93100
table.row();
94101
table.add(importTSVButton).expandX().fill();
102+
103+
table.row();
104+
table.add(exportUIImages).expandX().fill();
105+
106+
table.row();
107+
table.add(createUIAtlas).expandX().fill();
95108

96109
// table.row();
97110
// table.add(tmpButton).expandX().fill();
@@ -153,13 +166,94 @@ public void changed(ChangeEvent event, Actor actor) {
153166
importTSV();
154167
}
155168
});
169+
170+
exportUIImages.addListener(new ChangeListener() {
171+
@Override
172+
public void changed(ChangeEvent event, Actor actor) {
173+
exportUIImages();
174+
}
175+
});
176+
177+
createUIAtlas.addListener(new ChangeListener() {
178+
@Override
179+
public void changed(ChangeEvent event, Actor actor) {
180+
createUIAtlas();
181+
}
182+
});
156183

157184
table.pack();
158185
setActor(table);
159186
prefSize(table.getWidth(), Math.max(200, table.getHeight()));
160187
setSize(table.getWidth(), Math.max(200, table.getHeight()));
161188
}
162189

190+
protected void createUIAtlas() {
191+
FileChooser fileChooser = new FileChooser(Mode.OPEN);
192+
fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
193+
fileChooser.setViewMode(ViewMode.LIST);
194+
195+
fileChooser.setSelectionMode(SelectionMode.DIRECTORIES);
196+
getStage().addActor(fileChooser);
197+
198+
fileChooser.setListener(new FileChooserListener() {
199+
200+
@Override
201+
public void selected(Array<FileHandle> files) {
202+
try {
203+
// fileChooser.setTitle("Select the file to export the project texts");
204+
205+
ImageUtils.createAtlas(files.get(0).file().getAbsolutePath(),
206+
Ctx.project.getProjectPath() + "/" + Project.UI_PATH + "/1/", "ui", 1, TextureFilter.Linear,
207+
TextureFilter.Nearest);
208+
209+
Message.showMsg(getStage(), "UI Atlas created sucessfully.", 4);
210+
} catch (IOException e) {
211+
Message.showMsg(getStage(), "There was a problem creating the UI Atlas.", 4);
212+
EditorLogger.printStackTrace(e);
213+
}
214+
}
215+
216+
@Override
217+
public void canceled() {
218+
219+
}
220+
});
221+
222+
}
223+
224+
protected void exportUIImages() {
225+
FileChooser fileChooser = new FileChooser(Mode.OPEN);
226+
fileChooser.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.7f);
227+
fileChooser.setViewMode(ViewMode.LIST);
228+
229+
fileChooser.setSelectionMode(SelectionMode.DIRECTORIES);
230+
getStage().addActor(fileChooser);
231+
232+
fileChooser.setListener(new FileChooserListener() {
233+
234+
@Override
235+
public void selected(Array<FileHandle> files) {
236+
try {
237+
// fileChooser.setTitle("Select the file to export the project texts");
238+
239+
ImageUtils.unpackAtlas(new File(Ctx.project.getProjectPath() + "/" + Project.UI_PATH + "/1/ui.atlas"),
240+
files.get(0).file());
241+
242+
Message.showMsg(getStage(), "UI Atlas images exported sucessfully.", 4);
243+
} catch (Exception e) {
244+
Message.showMsg(getStage(), "There was a problem exporting images from UI Atlas.", 4);
245+
EditorLogger.printStackTrace(e);
246+
}
247+
}
248+
249+
@Override
250+
public void canceled() {
251+
252+
}
253+
});
254+
255+
}
256+
163257
private void exportTSV() {
164258

165259
FileChooser fileChooser = new FileChooser(Mode.SAVE);

0 commit comments

Comments
 (0)