From 68e2a805c3d3d145b09b00ad001124b6f4265117 Mon Sep 17 00:00:00 2001 From: Kolo <67389779+JustKolosaki@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:47:24 +0100 Subject: [PATCH] a lot of cosmetic things --- .../ui/debug/char/CharCreatorCharacter.hx | 2 +- .../funkin/ui/debug/char/CharCreatorState.hx | 13 ++-- .../CharCreatorImportExportHandler.hx | 48 ++++++++---- .../debug/char/pages/CharCreatorSelectPage.hx | 77 ++++++++++++++++++- 4 files changed, 115 insertions(+), 25 deletions(-) diff --git a/source/funkin/ui/debug/char/CharCreatorCharacter.hx b/source/funkin/ui/debug/char/CharCreatorCharacter.hx index c64e53d6f2..8228608604 100644 --- a/source/funkin/ui/debug/char/CharCreatorCharacter.hx +++ b/source/funkin/ui/debug/char/CharCreatorCharacter.hx @@ -78,7 +78,7 @@ class CharCreatorCharacter extends Bopper var data = generatedParams.files[1].bytes.toString(); this.frames = FlxAtlasFrames.fromSpriteSheetPacker(img, data); - case CharacterRenderType.AnimateAtlas: // todo + case CharacterRenderType.AnimateAtlas: if (generatedParams.files.length != 1) return; // zip file with all the data atlasCharacter = new CharSelectAtlasSprite(0, 0, generatedParams.files[0].bytes); diff --git a/source/funkin/ui/debug/char/CharCreatorState.hx b/source/funkin/ui/debug/char/CharCreatorState.hx index 03286710ab..2f738347c2 100644 --- a/source/funkin/ui/debug/char/CharCreatorState.hx +++ b/source/funkin/ui/debug/char/CharCreatorState.hx @@ -101,19 +101,22 @@ class CharCreatorState extends UIState { menubarOptionGameplay.onChange = function(_) switchToPage(Gameplay); menubarOptionCharSelect.onChange = function(_) switchToPage(CharacterSelect); - menubarItemExport.onClick = _ -> exportStuff(); + menubarItemExport.onClick = _ -> this.exportAll(); } function handleShortcuts():Void { - if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.S) exportStuff(); + if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.S) this.exportAll(); } + var params:WizardGenerateParams; + function wizardComplete(params:WizardGenerateParams):Void { // clear da pages sorry chat remove(selectedPage); selectedPage = null; + this.params = params; var allPages = [for (k => p in pages) p]; while (allPages.length > 0) @@ -162,12 +165,6 @@ class CharCreatorState extends UIState selectedPage.fillUpBottomBar(bottomBarLeftBox, bottomBarMiddleBox, bottomBarRightBox); selectedPage.fillUpPageSettings(menubarMenuSettings); } - - function exportStuff():Void - { - if (Std.isOfType(selectedPage, CharCreatorSelectPage)) this.exportPlayableCharacter(); - else if (Std.isOfType(selectedPage, CharCreatorGameplayPage)) this.exportCharacter(); - } } enum CharCreatorPage diff --git a/source/funkin/ui/debug/char/handlers/CharCreatorImportExportHandler.hx b/source/funkin/ui/debug/char/handlers/CharCreatorImportExportHandler.hx index 47aa3cc9d1..cec1c40b9a 100644 --- a/source/funkin/ui/debug/char/handlers/CharCreatorImportExportHandler.hx +++ b/source/funkin/ui/debug/char/handlers/CharCreatorImportExportHandler.hx @@ -28,21 +28,43 @@ class CharCreatorImportExportHandler gameplayPage.currentCharacter.fromCharacterData(CharacterRegistry.fetchCharacterData(charId)); } - public static function exportCharacter(state:CharCreatorState):Void + public static function exportAll(state:CharCreatorState) { - var gameplayPage:CharCreatorGameplayPage = cast state.pages[Gameplay]; - var zipEntries = []; + if (state.params.generateCharacter) exportCharacter(state, zipEntries); + if (state.params.generatePlayerData) exportPlayableCharacter(state, zipEntries); + + FileUtil.saveFilesAsZIP(zipEntries); + } - for (file in gameplayPage.currentCharacter.files) + public static function exportCharacter(state:CharCreatorState, zipEntries:Array):Void + { + var gameplayPage:CharCreatorGameplayPage = cast state.pages[Gameplay]; + + if (gameplayPage.currentCharacter.renderType != funkin.data.character.CharacterData.CharacterRenderType.AnimateAtlas) { - // skip if the file is in a character path - if (CharCreatorUtil.isPathProvided(file.name, "images/characters")) + for (file in gameplayPage.currentCharacter.files) { - continue; + // skip if the file is in a character path + if (CharCreatorUtil.isPathProvided(file.name, "images/characters")) + { + continue; + } + + zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(file.name)}', file.bytes)); } + } + else + { + // no check needed there's no zip files in assets folder - zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(file.name)}', file.bytes)); + for (file in FileUtil.readZIPFromBytes(gameplayPage.currentCharacter.files[0].bytes)) + { + var zipName = gameplayPage.currentCharacter.files[0].name.replace(".zip", ""); + + zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/characters/${Path.withoutDirectory(zipName)}/${Path.withoutDirectory(file.fileName)}', + file.data)); + } } // if the icon path isn't absolute, in the proper folder AND there already was an xml file (if we added one), then we don't save files and replace the typedef's id field @@ -67,14 +89,12 @@ class CharCreatorImportExportHandler // we push this later in case we use a pre-existing icon zipEntries.push(FileUtil.makeZIPEntry('${gameplayPage.currentCharacter.characterId}.json', gameplayPage.currentCharacter.toJSON())); - FileUtil.saveFilesAsZIP(zipEntries); } - public static function exportPlayableCharacter(state:CharCreatorState):Void + public static function exportPlayableCharacter(state:CharCreatorState, zipEntries:Array):Void { var selectPage:CharCreatorSelectPage = cast state.pages[CharacterSelect]; - - var zipEntries = []; + var charID = selectPage.data.importedCharacter ?? selectPage.data.characterID; // for (file in selectPage.iconFiles) // { @@ -87,7 +107,7 @@ class CharCreatorImportExportHandler // zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/freeplay/icons/${Path.withoutDirectory(file.name)}', file.bytes)); // } - zipEntries.push(FileUtil.makeZIPEntry('${selectPage.data.characterID}.json', selectPage.toJSON())); - FileUtil.saveFilesAsZIP(zipEntries); + zipEntries.push(FileUtil.makeZIPEntry('data/players/${charID}.json', selectPage.toJSON())); + if (selectPage.nametagFile != null) zipEntries.push(FileUtil.makeZIPEntryFromBytes('images/charSelect${charID}Nametag.png', selectPage.nametagFile.bytes)); } } diff --git a/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx b/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx index 0a4d90fdb5..9b80fef7ae 100644 --- a/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx +++ b/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx @@ -11,6 +11,7 @@ import funkin.data.freeplay.player.PlayerData; import funkin.data.freeplay.player.PlayerRegistry; import funkin.graphics.adobeanimate.FlxAtlasSprite; import funkin.graphics.FunkinSprite; +import funkin.graphics.shaders.MosaicEffect; import funkin.ui.debug.char.animate.CharSelectAtlasSprite; import funkin.ui.debug.char.pages.subpages.CharSelectIndexSubPage; import funkin.ui.debug.char.components.dialogs.*; @@ -36,6 +37,9 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage var data:WizardGenerateParams; var nametag:FlxSprite; + var nametagShader:MosaicEffect = new MosaicEffect(); + var nametagFile:WizardFile; + var gf:CharSelectAtlasSprite; var bf:CharSelectAtlasSprite; @@ -85,6 +89,21 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage initForeground(); nametag = new FlxSprite(); + if (data.importedPlayerData != null) nametag.loadGraphic(Paths.image('charSelect/' + + (data.importedPlayerData == "bf" ? "boyfriend" : data.importedPlayerData) + + "Nametag")); + nametag.updateHitbox(); + + nametag.scale.set(0.77, 0.77); + updateNametagPos(); + + nametag.shader = nametagShader; // truly a sight to behold + setNametagShaderBlockSize(0, 1, 1); + setNametagShaderBlockSize(1, nametag.width / 27, nametag.height / 26); + setNametagShaderBlockSize(2, nametag.width / 10, nametag.height / 10); + + setNametagShaderBlockSize(3, 1, 1); + add(nametag); dialogMap = new Map(); @@ -151,7 +170,8 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage if (idx >= array.length) idx = 0; else if (idx < 0) idx = array.length - 1; - (useGF ? gf : bf).playAnimation(array[idx]); + (useGF ? gf : bf).stopAnimation(); + (useGF ? gf : bf).playAnimation(array[idx]); (useGF ? gfAnimLabel : bfAnimLabel).text = (useGF ? "GF" : "Player") + " Anim: " + array[idx]; } @@ -166,11 +186,16 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage var openFile = new MenuItem(); openFile.text = "Load from File"; + var openNametag = new MenuItem(); + openNametag.text = "Load Nametag Image"; + // additions menu.addComponent(pixelStuff); pixelStuff.addComponent(openFile); pixelStuff.addComponent(openPos); + menu.addComponent(openNametag); + var settingsDialog = new MenuCheckBox(); settingsDialog.text = "Playable Character Settings"; menu.addComponent(settingsDialog); @@ -198,11 +223,48 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage }); } + openNametag.onClick = function(_) { + FileUtil.browseForBinaryFile("Load Nametag Image", [FileUtil.FILE_EXTENSION_INFO_PNG], function(_) { + if (_?.fullPath == null) return; + + nametagFile = {name: _.fullPath, bytes: FileUtil.readBytesFromPath(_.fullPath)} + + nametag.loadGraphic(openfl.display.BitmapData.fromBytes(nametagFile.bytes)); + nametag.updateHitbox(); + + updateNametagPos(); + + setNametagShaderBlockSize(0, 1, 1); + setNametagShaderBlockSize(1, nametag.width / 27, nametag.height / 26); + setNametagShaderBlockSize(2, nametag.width / 10, nametag.height / 10); + setNametagShaderBlockSize(3, 1, 1); + }); + } + settingsDialog.onClick = function(_) { dialogMap[SettingsDialog].hidden = !settingsDialog.selected; } } + function updateNametagPos() + { + nametag.x -= (nametag.getMidpoint().x - 1008); + nametag.y -= (nametag.getMidpoint().y - 100); + } + + function setNametagShaderBlockSize(frame:Int, ?forceX:Float, ?forceY:Float) + { + var daX:Float = 10 * FlxG.random.int(1, 4); + var daY:Float = 10 * FlxG.random.int(1, 4); + + if (forceX != null) daX = forceX; + if (forceY != null) daY = forceY; + + new flixel.util.FlxTimer().start(frame / 30, _ -> { + nametagShader.setBlockSize(daX, daY); + }); + } + function initBackground():Void { var bg:FlxSprite = new FlxSprite(-153, -140); @@ -304,7 +366,18 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage if (handleInput) { - if (FlxG.keys.justPressed.B) {} + if (FlxG.keys.justPressed.SPACE) + { + gf.stopAnimation(); + gf.playAnimation(gfAnimLabel.text.split(" Anim: ")[1], true, true); + + bf.stopAnimation(); + bf.playAnimation(bfAnimLabel.text.split(" Anim: ")[1], true, true); + } + + // perhaps gonan find a better keybind for this idk + if (FlxG.keys.justPressed.W) changeCharAnim(-1, FlxG.keys.pressed.SHIFT); + if (FlxG.keys.justPressed.S) changeCharAnim(1, FlxG.keys.pressed.SHIFT); } }