Skip to content

Commit

Permalink
buncha new stuff
Browse files Browse the repository at this point in the history
- CharSelectIndexSubPage now has a dedicated haxeui button (also exit with BACK keybind lol)
- Pixel icons are able to be uploaded from files now yuh
- Some cosmetic stuff in CharSelectIndexSubPage
  • Loading branch information
KoloInDaCrib committed Nov 12, 2024
1 parent 097a507 commit 459992c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 5 deletions.
49 changes: 45 additions & 4 deletions source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package funkin.ui.debug.char.pages;

import haxe.ui.containers.menus.Menu;
import haxe.ui.containers.menus.MenuItem;
import funkin.audio.FunkinSound;
import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.ui.debug.char.pages.subpages.CharSelectIndexSubPage;
import funkin.util.FileUtil;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.group.FlxSpriteGroup;
import flixel.tweens.FlxEase;
Expand All @@ -19,6 +22,8 @@ import flixel.math.FlxPoint;
import flixel.math.FlxMath;
import flixel.FlxG;

using StringTools;

@:allow(funkin.ui.debug.char.pages.subpages.CharSelectIndexSubPage)
class CharCreatorSelectPage extends CharCreatorDefaultPage
{
Expand All @@ -32,6 +37,7 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage

// used for `PlayableCharacter` generation
var selectedIndexData:Int = 0;
var pixelIconFiles:Array<WizardFile> = [];

var subPages:Map<CharCreatorSelectSubPage, FlxSpriteGroup>;

Expand Down Expand Up @@ -67,6 +73,44 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
add(subPages[IndexSubPage]);
}

override public function fillUpPageSettings(menu:Menu)
{
var pixelStuff = new Menu();
pixelStuff.text = "Pixel Icon";

var openPos = new MenuItem();
openPos.text = "Set Position";

var openFile = new MenuItem();
openFile.text = "Load from File";

// additions
menu.addComponent(pixelStuff);
pixelStuff.addComponent(openFile);
pixelStuff.addComponent(openPos);

// callbacks
openPos.onClick = function(_) {
cast(subPages[IndexSubPage], CharSelectIndexSubPage).open();
}

openFile.onClick = function(_) {
FileUtil.browseForBinaryFile("Load Pixel Icon File", [FileUtil.FILE_EXTENSION_INFO_PNG], function(_) {
if (_?.fullPath == null) return;

var daImgPath = _.fullPath;
var daXmlPath = daImgPath.replace(".png", ".xml");

pixelIconFiles = [
{name: daImgPath, bytes: FileUtil.readBytesFromPath(daImgPath)}];

if (FileUtil.doesFileExist(daXmlPath)) pixelIconFiles.push({name: daXmlPath, bytes: FileUtil.readBytesFromPath(daXmlPath)});

openFile.tooltip = "File Path: " + daImgPath;
});
}
}

function initBackground():Void
{
var bg:FlxSprite = new FlxSprite(-153, -140);
Expand Down Expand Up @@ -168,10 +212,7 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage

if (handleInput)
{
if (FlxG.keys.justPressed.B)
{
cast(subPages[IndexSubPage], CharSelectIndexSubPage).open();
}
if (FlxG.keys.justPressed.B) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CharSelectIndexSubPage extends FlxSpriteGroup
updateIconAnims();
handleMousePress();

if (FlxG.keys.justPressed.X)
if (PlayerSettings.player1.controls.BACK)
{
close();
}
Expand Down Expand Up @@ -294,6 +294,7 @@ class CharSelectIndexSubPage extends FlxSpriteGroup
iconTint.y = selectedIcon.y;
iconTint.scale.set(selectedIcon.scale.x, selectedIcon.scale.y);

var ogIcon = grpIcons.members[parentPage.selectedIndexData];
parentPage.selectedIndexData = cursorIndex;
FlxG.sound.play(Paths.sound('CS_confirm'));

Expand All @@ -306,6 +307,69 @@ class CharSelectIndexSubPage extends FlxSpriteGroup
cursorDarkBlue.visible = true;
isSelecting = false;
});

if (Std.isOfType(ogIcon, PixelatedIcon))
{
var icon:PixelatedIcon = cast ogIcon;
icon.shader = new funkin.graphics.shaders.Grayscale();

icon.setCharacter("bf");
icon.setGraphicSize(128, 128);
icon.updateHitbox();
}

if (Std.isOfType(selectedIcon, PixelatedIcon))
{
var icon:PixelatedIcon = cast selectedIcon;
icon.shader = null;

// also do we even need icontint anymore?
if (parentPage.pixelIconFiles.length > 0) // custom icons should have the priority over preset ones i think
{
var pngBytes = parentPage.pixelIconFiles[0].bytes;
var xmlBytes = parentPage.pixelIconFiles[1]?.bytes ?? null;
var graphic = openfl.display.BitmapData.fromBytes(pngBytes);

if (xmlBytes == null)
{
icon.loadGraphic(graphic);
iconTint.loadGraphic(graphic);
}
else
{
icon.frames = iconTint.frames = flixel.graphics.frames.FlxAtlasFrames.fromSparrow(graphic, xmlBytes.toString());
icon.animation.addByPrefix('idle', 'idle0', 10, true);
icon.animation.addByPrefix('confirm', 'confirm0', 10, false);
icon.animation.addByPrefix('confirm-hold', 'confirm-hold0', 10, true);

iconTint.animation.addByPrefix('idle', 'idle0', 10, true);
iconTint.animation.addByPrefix('confirm', 'confirm0', 10, false);
iconTint.animation.addByPrefix('confirm-hold', 'confirm-hold0', 10, true);

icon.animation.finishCallback = function(name:String):Void {
if (name == 'confirm') icon.animation.play('confirm-hold');
};
iconTint.animation.finishCallback = function(name:String):Void {
if (name == 'confirm') icon.animation.play('confirm-hold');
};

icon.animation.play('idle');
iconTint.animation.play('idle');
}
}
else if (parentPage.data.importedPlayerData != null)
{
icon.setCharacter(parentPage.data.importedPlayerData);
iconTint.setCharacter(parentPage.data.importedPlayerData);
}

icon.setGraphicSize(128, 128);
iconTint.setGraphicSize(128, 128);
icon.updateHitbox();
iconTint.updateHitbox();
}

updateIconPositions();
}

function handleCursorPosition(elapsed:Float):Void
Expand Down

0 comments on commit 459992c

Please sign in to comment.