diff --git a/source/funkin/editors/character/CharacterPropertiesWindow.hx b/source/funkin/editors/character/CharacterPropertiesWindow.hx index 41e0b1a2..26ac7b2f 100644 --- a/source/funkin/editors/character/CharacterPropertiesWindow.hx +++ b/source/funkin/editors/character/CharacterPropertiesWindow.hx @@ -143,7 +143,7 @@ class CharacterPropertiesWindow extends UISliceSprite { } public function editCharacterSpriteUI() { - CharacterEditor.instance.openSubState(new CharacterSpriteScreen(character.sprite, (sprite:String) -> { + CharacterEditor.instance.openSubState(new CharacterSpriteScreen('characters/${character.sprite}', (sprite:String) -> { trace(sprite); })); } diff --git a/source/funkin/editors/character/CharacterSpriteScreen.hx b/source/funkin/editors/character/CharacterSpriteScreen.hx index f6ef2d39..5d110e2a 100644 --- a/source/funkin/editors/character/CharacterSpriteScreen.hx +++ b/source/funkin/editors/character/CharacterSpriteScreen.hx @@ -30,7 +30,7 @@ class CharacterSpriteScreen extends UISubstateWindow { super.create(); - imageExplorer = new UIImageExplorer(20, windowSpr.y + 30 + 16 + 20, 320, 58, (_, _) -> {refreshWindowSize();}); + imageExplorer = new UIImageExplorer(20, windowSpr.y + 30 + 16 + 20, imagePath, 320, 58, (_, _) -> {refreshWindowSize();}); add(imageExplorer); addLabelOn(imageExplorer, "Character Image File").applyMarkup( "Character Image File $* Required$", @@ -55,6 +55,7 @@ class CharacterSpriteScreen extends UISubstateWindow { } public function refreshWindowSize() { + if (imageExplorer == null) return; windowSpr.bWidth = 20 + imageExplorer.bWidth + 20; windowSpr.bHeight = 30 + 16 + 20 + imageExplorer.bHeight + 14 + saveButton.bHeight + 14; diff --git a/source/funkin/editors/ui/UIFileExplorer.hx b/source/funkin/editors/ui/UIFileExplorer.hx index 9a4b86ac..6e7c8f81 100644 --- a/source/funkin/editors/ui/UIFileExplorer.hx +++ b/source/funkin/editors/ui/UIFileExplorer.hx @@ -23,13 +23,7 @@ class UIFileExplorer extends UISliceSprite { uploadButton = new UIButton(x + 8, y+ 8, null, function () { var fileDialog = new FileDialog(); - fileDialog.onSelect.add(function(path) { - filePath = path; - file = cast sys.io.File.getBytes(path); - deleteButton.visible = deleteButton.selectable = deleteIcon.visible = !(uploadButton.visible = uploadButton.selectable = false); - - if (this.onFile != null) this.onFile(filePath, file); - }); + fileDialog.onSelect.add(loadFile); fileDialog.browse(OPEN, fileType); }, bWidth - 16, bHeight - 16); members.push(uploadButton); @@ -64,6 +58,13 @@ class UIFileExplorer extends UISliceSprite { } } + public function loadFile(path:String) { + file = cast sys.io.File.getBytes(filePath = path); + deleteButton.visible = deleteButton.selectable = deleteIcon.visible = !(uploadButton.visible = uploadButton.selectable = false); + + if (this.onFile != null) this.onFile(filePath, file); + } + public function removeFile() { if (uiElement != null) { members.remove(uiElement); diff --git a/source/funkin/editors/ui/UIImageExplorer.hx b/source/funkin/editors/ui/UIImageExplorer.hx index e6caa031..ecd8a2d6 100644 --- a/source/funkin/editors/ui/UIImageExplorer.hx +++ b/source/funkin/editors/ui/UIImageExplorer.hx @@ -15,7 +15,7 @@ using funkin.backend.utils.BitmapUtil; // TODO: make this limited if on web class UIImageExplorer extends UIFileExplorer { - public function new(x:Float, y:Float, ?w:Int, ?h:Int, ?onFile:(String, Bytes)->Void) { + public function new(x:Float, y:Float, image:String, ?w:Int, ?h:Int, ?onFile:(String, Bytes)->Void) { super(x, y, w, h, "png, jpg", function (filePath, file) { if (filePath != null && file != null) uploadImage(filePath, file); if (onFile != null) onFile(filePath, file); @@ -24,10 +24,16 @@ class UIImageExplorer extends UIFileExplorer { deleteButton.bWidth = 26; deleteButton.bHeight = 26; - this.allowAtlases = true; //allowAtlases; + var fullImagePath:String = '${Path.normalize(Sys.getCwd())}/${Paths.image(image)}'.replace('/', '\\'); + var noExt = Path.withoutExtension(fullImagePath); + if (FileSystem.exists('$noExt\\spritemap1.png')) + fullImagePath = '$noExt\\spritemap1.png'; + + if (FileSystem.exists(fullImagePath)) + loadFile(fullImagePath); } - private var allowAtlases:Bool; + private var allowAtlases:Bool = true; public var fileText:UIText; @@ -119,7 +125,8 @@ class UIImageExplorer extends UIFileExplorer { var image = null; if (isAtlas && spritemapImages.length > 0) { var spritemapPath:String = Path.join([directoryPath, spritemapImages[0]]); - trace("Loading spritemap: " + spritemapImages[0]); + trace("Loading spritemap: " + spritemapImages, spritemaps); + trace(directoryPath); imagePath = Path.normalize(spritemapPath); directoryPath = Path.directory(imagePath);