Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ORG] RU-MAKEAPP: Keep input file extensions option. #3

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[4.10.1]
- Fixed file path editing for FileChooser may result in a crash.
- Option to append input file extensions to region names.
- Window validates and fixes its dimensions on startup.
- Minor UI cleanup and improvements.

Expand Down
6 changes: 4 additions & 2 deletions assets/i18n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ dPbChangeBackground = Change background
dInputFileTitleFile = Input file properties
dInputFileTitleDir = Input directory properties
dInputFileTitleFileIgnore = Ignored file properties
dInputFileRegionsPrefix = Regions' prefix
dInputFileRegionsPrefix = Region prefix
dInputFileRegionName = Region name
dInputFileRecursive = Recursive
dInputFileFlattenPaths = Flatten paths
Expand Down Expand Up @@ -264,7 +264,7 @@ psWrapY = Wrap Y
psJpegQuality = Jpeg quality
psScaleFactors = Scale factors

psUseFastAlgorithm = Use fast algorithm
psUseFastAlgorithm = Fast algorithm
psEdgePadding = Edge padding
psStripWhitespaceX = Strip whitespace X
psStripWhitespaceY = Strip whitespace Y
Expand All @@ -285,6 +285,7 @@ psSquare = Force square
psLimitMemory = Limit memory
psLegacyOutput = Legacy format
psPrettyPrint = Pretty print
psKeepFileExtensions = Keep file extensions

psTtPot = If checked, output pages will have power of two dimensions.
psTtMof = If checked, output pages will have multiple of four dimensions.
Expand Down Expand Up @@ -322,6 +323,7 @@ psTtScaleSuffix = For each scale, the suffix to use for the output files. If omi
psTtLegacyOutput = Use the old LibGDX texture atlas data file format (for pre LibGDX 1.9.13 projects)
psTtPrettyPrint = Render more explicit and human-readable atlas data files. \
Has effect only for the new LibGDX texture atlas format. See "Legacy format" option.
psTtKeepFileExtensions = Append the image file extension to region names (if the region name is not set explicitelly).

canvasInfoNoPageToShow = N/A
canvasInfoTtZoom = Zoom
Expand Down
1 change: 1 addition & 0 deletions assets/lml/panePackSettings.lml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@

<vischeckbox id="cbLimitMemory" onchange="onSettingsCbChecked" tooltip="@psTtLimitMemory">@psLimitMemory</vischeckbox>

<vischeckbox id="cbKeepFileExtensions" onchange="onSettingsCbChecked" tooltip="@psTtKeepFileExtensions">@psKeepFileExtensions</vischeckbox>
</vistable>

</vistable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import com.crashinvaders.texturepackergui.controllers.*;
import com.crashinvaders.texturepackergui.controllers.main.filetype.*;
import com.crashinvaders.texturepackergui.controllers.main.inputfiles.PackInputFilesController;
import com.crashinvaders.texturepackergui.controllers.model.ModelService;
import com.crashinvaders.texturepackergui.controllers.model.PackModel;
import com.crashinvaders.texturepackergui.controllers.model.ProjectModel;
import com.crashinvaders.texturepackergui.controllers.model.ScaleFactorModel;
import com.crashinvaders.texturepackergui.controllers.model.*;
import com.crashinvaders.texturepackergui.controllers.model.filetype.*;
import com.crashinvaders.texturepackergui.controllers.projectserializer.ProjectSerializer;
import com.crashinvaders.texturepackergui.events.*;
Expand Down Expand Up @@ -241,6 +238,7 @@ public void resize(Stage stage, int width, int height) {
switch (event.getProperty()) {
case NAME:
case SCALE_FACTORS:
case KEEP_FILE_EXTENSIONS:
case SETTINGS:
if (event.getPack() == getSelectedPack()) {
updateViewsFromPack(event.getPack());
Expand Down Expand Up @@ -447,6 +445,7 @@ public void clicked(InputEvent e, float x, float y) {
break;
}
case "cbPrettyPrint": settings.prettyPrint = checkBox.isChecked(); break;
case "cbKeepFileExtensions": pack.setKeepInputFileExtensions(checkBox.isChecked()); break;
}
}

Expand Down Expand Up @@ -584,6 +583,7 @@ private void updateViewsFromPack(PackModel pack) {
actorsPackSettings.cbLimitMemory.setChecked(settings.limitMemory);
actorsPackSettings.cbLegacyOutput.setChecked(settings.legacyOutput);
actorsPackSettings.cbPrettyPrint.setChecked(settings.prettyPrint);
actorsPackSettings.cbKeepFileExtensions.setChecked(pack.isKeepInputFileExtensions());

((IntSeekBarModel) actorsPackSettings.skbMinPageWidth.getModel()).setValue(settings.minWidth, false);
((IntSeekBarModel) actorsPackSettings.skbMinPageHeight.getModel()).setValue(settings.minHeight, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ public class PackSettingsActors {
@LmlActor("cbLimitMemory") VisCheckBox cbLimitMemory;
@LmlActor("cbLegacyOutput") VisCheckBox cbLegacyOutput;
@LmlActor("cbPrettyPrint") VisCheckBox cbPrettyPrint;
@LmlActor("cbKeepFileExtensions") VisCheckBox cbKeepFileExtensions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Colors;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.PixmapIO;
import com.badlogic.gdx.scenes.scene2d.Group;
Expand All @@ -15,12 +14,11 @@
import com.crashinvaders.common.scene2d.Scene2dUtils;
import com.crashinvaders.common.scene2d.ShrinkContainer;
import com.crashinvaders.texturepackergui.controllers.ErrorDialogController;
import com.crashinvaders.texturepackergui.controllers.model.InputFile;
import com.crashinvaders.texturepackergui.controllers.model.ModelService;
import com.crashinvaders.texturepackergui.controllers.model.ModelUtils;
import com.crashinvaders.texturepackergui.controllers.model.*;
import com.crashinvaders.texturepackergui.controllers.ninepatcheditor.NinePatchEditorDialog;
import com.crashinvaders.texturepackergui.controllers.ninepatcheditor.NinePatchEditorModel;
import com.crashinvaders.texturepackergui.events.InputFilePropertyChangedEvent;
import com.crashinvaders.texturepackergui.events.PackPropertyChangedEvent;
import com.crashinvaders.texturepackergui.events.ShowToastEvent;
import com.crashinvaders.texturepackergui.utils.AppIconProvider;
import com.crashinvaders.texturepackergui.utils.FileUtils;
Expand Down Expand Up @@ -89,11 +87,21 @@ public class InputFilePropertiesDialogController implements ActionContainer {
}

@OnEvent(InputFilePropertyChangedEvent.class) void onEvent(InputFilePropertyChangedEvent event) {
if (event.getInputFile() != inputFile || ignoreInputFileUpdateEvents) return;
if (!isShown() || event.getInputFile() != inputFile || ignoreInputFileUpdateEvents) return;

mapDataFromModel();
}

@OnEvent(PackPropertyChangedEvent.class) void onEvent(PackPropertyChangedEvent event) {
if (!isShown() || inputFile == null) return;

switch (event.getProperty()) {
case KEEP_FILE_EXTENSIONS:
mapDataFromModel();
break;
}
}

@LmlAction("showFilePicker") void showFilePicker() {
final FileChooser fileChooser = new FileChooser(inputFile.getFileHandle().parent(), FileChooser.Mode.OPEN);
fileChooser.setIconProvider(new AppIconProvider(fileChooser));
Expand Down Expand Up @@ -128,8 +136,7 @@ public void selected (Array<FileHandle> files) {
dialog.hide();
}

@LmlAction("onFilePrefixTextChanged")
void onFilePrefixFocusChanged() {
@LmlAction("onFilePrefixTextChanged") void onFilePrefixFocusChanged() {
inputFile.setDirFilePrefix(edtFilePrefix.getText().trim());
}

Expand All @@ -144,8 +151,7 @@ void onFilePrefixFocusChanged() {
inputFile.setFlattenPaths(checked);
}

@LmlAction("onRegionNameTextChanged")
void onRegionNameTextChanged() {
@LmlAction("onRegionNameTextChanged") void onRegionNameTextChanged() {
inputFile.setRegionName(edtRegionName.getText().trim());
}

Expand Down Expand Up @@ -215,6 +221,8 @@ public void setInputFile(InputFile inputFile) {
}

private void mapDataFromModel() {
final PackModel packModel = modelService.getProject().getSelectedPack();

dialog.pack();

boolean fileShortened = false;
Expand Down Expand Up @@ -250,10 +258,11 @@ private void mapDataFromModel() {
if (!inputFile.isDirectory() && inputFile.getType() == InputFile.Type.Input) {
dialog.getTitleLabel().setText(localeService.getI18nBundle().get("dInputFileTitleFile"));
shrinkInputFile.setVisible(true);
String defaultRegionName = inputFile.getFileHandle().nameWithoutExtension();
if (defaultRegionName.endsWith(".9")) {
defaultRegionName = defaultRegionName.substring(0, defaultRegionName.length() - 2);
}

String defaultRegionName = InputFile.evalDefaultRegionName(
inputFile.getFileHandle(),
packModel.isKeepInputFileExtensions());

edtRegionName.setMessageText(defaultRegionName);
edtRegionName.setText(inputFile.getRegionName());

Expand Down Expand Up @@ -284,4 +293,8 @@ private boolean checkFileExists(InputFile inputFile, boolean showErrorToast) {
}
return exists;
}

private boolean isShown() {
return stage != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ public boolean isNinePatch() {
return isProgrammaticNinePatch() || isFileBasedNinePatch();
}

public static String evalDefaultRegionName(FileHandle fileHandle, boolean keepExtension) {
String result = fileHandle.nameWithoutExtension();
if (result.endsWith(".9")) {
result = result.substring(0, result.length() - 2);
}
if (keepExtension) {
result += "." + fileHandle.extension();
}
return result;
}

@Override
public String toString() {
return fileHandle.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class PackModel implements StateHashable {
private String name = "";
private String filename = "";
private String outputDir = "";
private boolean keepInputFileExtensions = false;

private EventDispatcher eventDispatcher;

Expand All @@ -39,6 +40,7 @@ public PackModel(PackModel pack) {
this.name = pack.name;
this.filename = pack.filename;
this.outputDir = pack.outputDir;
this.keepInputFileExtensions = pack.keepInputFileExtensions;

scaleFactors.addAll(pack.scaleFactors);

Expand Down Expand Up @@ -80,6 +82,15 @@ public void setOutputDir(String outputDir) {
}
}

public void setKeepInputFileExtensions(boolean value) {
if (this.keepInputFileExtensions == value) return;

this.keepInputFileExtensions = value;
if (eventDispatcher != null) {
eventDispatcher.postEvent(new PackPropertyChangedEvent(this, Property.KEEP_FILE_EXTENSIONS));
}
}

public String getName() {
return name;
}
Expand All @@ -96,6 +107,10 @@ public Array<InputFile> getInputFiles() {
return inputFiles;
}

public boolean isKeepInputFileExtensions() {
return keepInputFileExtensions;
}

public Settings getSettings() {
return settings;
}
Expand Down Expand Up @@ -208,7 +223,7 @@ public String toString() {
@Override
public int computeStateHash() {
int settingsHash = computeSettingsStateHash(settings);
return StateHashUtils.computeHash(scaleFactors, inputFiles, settingsHash, name, filename, outputDir);
return StateHashUtils.computeHash(scaleFactors, inputFiles, settingsHash, name, filename, outputDir, keepInputFileExtensions);
}

private static int computeSettingsStateHash(Settings s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ProjectModel implements StateHashable {

private final Array<PackModel> packs = new Array<>(true, 16);
private final Color previewBackgroundColor = new Color(Color.WHITE);
private final ProjectSettingsModel settings = new ProjectSettingsModel();
private FileHandle projectFile;
private FileTypeModel fileType = new PngFileTypeModel(); // PNG file type by default

Expand All @@ -32,6 +33,10 @@ public void setEventDispatcher(EventDispatcher eventDispatcher) {
}
}

public ProjectSettingsModel getSettings() {
return settings;
}

public FileHandle getProjectFile() {
return projectFile;
}
Expand Down Expand Up @@ -114,6 +119,6 @@ public void setPreviewBackgroundColor(Color color) {

@Override
public int computeStateHash() {
return StateHashUtils.computeHash(packs, previewBackgroundColor, projectFile, fileType);
return StateHashUtils.computeHash(packs, previewBackgroundColor, projectFile, fileType, settings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.crashinvaders.texturepackergui.controllers.model;

import com.badlogic.gdx.utils.*;
import com.crashinvaders.common.statehash.StateHashUtils;
import com.crashinvaders.common.statehash.StateHashable;
import com.github.czyzby.autumn.processor.event.EventDispatcher;

import java.io.StringWriter;

public class ProjectSettingsModel implements StateHashable {

protected EventDispatcher eventDispatcher;

private final InputFileSettingsModel inputFiles = new InputFileSettingsModel();

public InputFileSettingsModel getInputFiles() {
return inputFiles;
}

public void setEventDispatcher(EventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
}

public String serializeState() {
StringWriter buffer = new StringWriter();
try {
Json json = new Json();
json.setWriter(new JsonWriter(buffer));
json.writeObjectStart();
json.writeValue("inputFiles", inputFiles);
json.writeObjectEnd();
return buffer.toString();
} finally {
StreamUtils.closeQuietly(buffer);
}
}

public void deserializeState(String data) {
if (data == null) return;

JsonValue jsonValue = new JsonReader().parse(data);
this.inputFiles.read(null, jsonValue.get("inputFiles"));
}

@Override
public int computeStateHash() {
return StateHashUtils.computeHash(inputFiles);
}

public class InputFileSettingsModel implements StateHashable, Json.Serializable {

// private boolean keepInputFileExtensions = false;

// public boolean isKeepInputFileExtensions() {
// return keepInputFileExtensions;
// }

// public void setKeepInputFileExtensions(boolean value) {
// if (this.keepInputFileExtensions == value) return;
//
// this.keepInputFileExtensions = value;
//
// if (eventDispatcher != null) {
// eventDispatcher.postEvent(new ChangedEvent(
// ProjectSettingsModel.this,
// ChangedEvent.Property.INPUT_FILES));
// }
// }

@Override
public void write(Json json) {
// json.writeValue("keepInputFileExtensions", keepInputFileExtensions);
}

@Override
public void read(Json json, JsonValue jsonData) {
// this.keepInputFileExtensions = jsonData.getBoolean("keepInputFileExtensions", this.keepInputFileExtensions);
}

@Override
public int computeStateHash() {
// return StateHashUtils.computeHash(keepInputFileExtensions);
return 0;
}
}

public static class ChangedEvent {

private final ProjectSettingsModel settings;
private final Property property;

public ChangedEvent(ProjectSettingsModel settings, Property property) {
this.settings = settings;
this.property = property;
}

public ProjectSettingsModel getSettings() {
return settings;
}

public Property getProperty() {
return property;
}

public enum Property {
// INPUT_FILES,
}
}

}
Loading