Skip to content

Commit

Permalink
Merge branch 'char-creator-thing' into feature/multisparrow-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 authored Nov 1, 2024
2 parents e0ab779 + c113333 commit d8f3e6a
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 101 deletions.
16 changes: 16 additions & 0 deletions source/funkin/ui/debug/char/CharCreatorCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,25 @@ class CharCreatorCharacter extends Bopper
offsets: offsets
});

super.setAnimationOffsets(name, offsets[0], offsets[1]);

return true;
}

override public function setAnimationOffsets(name:String, xOffset:Float, yOffset:Float)
{
super.setAnimationOffsets(name, xOffset, yOffset);

for (anim in animations)
{
if (anim.name == name)
{
anim.offsets = [xOffset, yOffset];
break;
}
}
}

public override function playAnimation(name:String, restart:Bool = false, ignoreOther:Bool = false, reverse:Bool = false):Void
{
if (atlasCharacter == null)
Expand Down
1 change: 1 addition & 0 deletions source/funkin/ui/debug/char/CharCreatorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import flixel.FlxG;

/**
* also made by kolo
* in collaboration with lemz!
* my second slightly more disappointing son
*/
@:build(haxe.ui.ComponentBuilder.build("assets/exclude/data/ui/char-creator/main-view.xml"))
Expand Down
10 changes: 8 additions & 2 deletions source/funkin/ui/debug/char/components/dialogs/AddAnimDialog.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.ui.debug.char.components.dialogs;

import funkin.ui.debug.char.pages.CharCreatorGameplayPage.CharDialogType;
import haxe.ui.containers.dialogs.CollapsibleDialog;
import haxe.ui.data.ArrayDataSource;

Expand Down Expand Up @@ -75,10 +76,12 @@ class AddAnimDialog extends DefaultPageDialog
charAnimFlipY.selected);

if (!animAdded) return;

char.setAnimationOffsets(charAnimName.text, charAnimOffsetX.pos, charAnimOffsetY.pos);
char.playAnimation(charAnimName.text);

cast(page, CharCreatorGameplayPage).ghostCharacter.addAnimation(charAnimName.text, charAnimPrefix.text, [charAnimOffsetX.pos, charAnimOffsetY.pos],
(shouldDoIndices ? indices : []), charAnimPath.text, Std.int(charAnimFramerate.pos), charAnimLooped.selected, charAnimFlipX.selected,
charAnimFlipY.selected);

updateDropdown();
charAnimDropdown.selectedIndex = charAnimDropdown.dataSource.size - 1;
}
Expand All @@ -90,5 +93,8 @@ class AddAnimDialog extends DefaultPageDialog

for (anim in linkedChar.animations)
charAnimDropdown.dataSource.add({text: anim.name});

var gameplayPage = cast(page, CharCreatorGameplayPage);
if (gameplayPage.ghostId == "") gameplayPage.refreshGhoulAnims();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,43 @@ import flixel.tweens.FlxTween;
@:build(haxe.ui.macros.ComponentMacros.build("assets/exclude/data/ui/char-creator/dialogs/ghost-dialog.xml"))
class GhostSettingsDialog extends DefaultPageDialog
{
var attachedMenu:GhostCharacterMenu;
public var attachedMenu:GhostCharacterMenu;
public var charId:String = Constants.DEFAULT_CHARACTER;

override public function new(daPage:CharCreatorDefaultPage)
{
super(daPage);

var regularChar = cast(daPage, CharCreatorGameplayPage).currentCharacter;
var ghostChar = cast(daPage, CharCreatorGameplayPage).ghostCharacter;
var charData = CharacterRegistry.fetchCharacterData(Constants.DEFAULT_CHARACTER);

ghostTypeButton.icon = (charData == null ? null : CharacterRegistry.getCharPixelIconAsset(Constants.DEFAULT_CHARACTER));
ghostTypeButton.text = (charData == null ? "None" : charData.name.length > 6 ? '${charData.name.substr(0, 6)}.' : '${charData.name}');

// callbacks
ghostEnable.onChange = function(_) {
ghostDataBox.disabled = !ghostEnable.selected;
ghostChar.visible = ghostEnable.selected;

if (ghostChar.visible) // i love saving on data
{
cast(daPage, CharCreatorGameplayPage).ghostId = (ghostCustomChar.selected ? charId : "");
}
}

ghostCurChar.onChange = function(_) {
ghostTypeButton.disabled = ghostCurChar.selected; // no need to check for the other one thankfully
ghostTypeButton.disabled = ghostCurChar.selected;
if (ghostCurChar.selected) Screen.instance.removeComponent(attachedMenu);

if (ghostChar.visible && ghostCurChar.selected) cast(daPage, CharCreatorGameplayPage).ghostId = "";
}

ghostCustomChar.onChange = function(_) {
ghostTypeButton.disabled = !ghostCustomChar.selected;
if (!ghostCustomChar.selected) Screen.instance.removeComponent(attachedMenu);

if (ghostChar.visible && ghostCustomChar.selected) cast(daPage, CharCreatorGameplayPage).ghostId = charId;
}

ghostTypeButton.onClick = function(_) {
Expand All @@ -38,11 +58,9 @@ class GhostSettingsDialog extends DefaultPageDialog

ghostAnimDropdown.onChange = function(_) {
if (ghostAnimDropdown.selectedIndex == -1) return;
cast(daPage, CharCreatorGameplayPage).ghostCharacter.playAnimation(ghostAnimDropdown.selectedItem.text);
ghostChar.playAnimation(ghostAnimDropdown.selectedItem.text);
}
}

function releaseTheGhouls() {}
}

/**
Expand Down Expand Up @@ -85,23 +103,28 @@ class GhostCharacterMenu extends Menu
charButton.padding = 8;
charButton.iconPosition = "top";

/*if (charId == state.selectedChar.characterId)
{
// Scroll to the character if it is already selected.
ghostSelectScroll.hscrollPos = Math.floor(charIndex / 5) * 80;
charButton.selected = true;
if (charId == parent.charId)
{
// Scroll to the character if it is already selected.
ghostSelectScroll.hscrollPos = Math.floor(charIndex / 5) * 80;
charButton.selected = true;

defaultText = '${charData.name} [${charId}]';
}*/
defaultText = '${charData.name} [${charId}]';
}

var LIMIT = 6;
charButton.icon = CharacterRegistry.getCharPixelIconAsset(charId);
charButton.text = charData.name.length > LIMIT ? '${charData.name.substr(0, LIMIT)}.' : '${charData.name}';

charButton.onClick = _ ->
{
// kill and replace
};
charButton.onClick = _ -> {
parent.charId = charId;

var gameplayPage = cast(page, CharCreatorGameplayPage);
if (gameplayPage.ghostCharacter.visible) gameplayPage.ghostId = charId;

parent.ghostTypeButton.text = charButton.text;
parent.ghostTypeButton.icon = charButton.icon;
};

charButton.onMouseOver = _ -> {
ghostIconName.text = '${charData.name} [${charId}]';
Expand Down
75 changes: 23 additions & 52 deletions source/funkin/ui/debug/char/components/wizard/AddCharFilesDialog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class AddCharFilesDialog extends DefaultWizardDialog
switch (params.renderType)
{
case "sparrow" | "multisparrow":
if (params.renderType == "multisparrow") recursiveAssetsBox();
else
addAssetsBox.addComponent(new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG));
addAssetsBox.addComponent(new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG));

case "packer":
addAssetsBox.addComponent(new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG));
Expand All @@ -59,12 +57,8 @@ class AddCharFilesDialog extends DefaultWizardDialog
if (addAssetsBox.disabled) return true;

var uploadBoxes:Array<UploadAssetsBox> = [];
for (i => box in addAssetsBox.childComponents)
for (box in addAssetsBox.childComponents)
{
if (stupidFuckingRenderCheck == "multisparrow" && i == addAssetsBox.childComponents.length - 1)
{
continue;
}
if (Std.isOfType(box, UploadAssetsBox)) uploadBoxes.push(cast box);
}

Expand All @@ -83,44 +77,31 @@ class AddCharFilesDialog extends DefaultWizardDialog
switch (params.renderType)
{
case "sparrow" | "multisparrow":
var files = [];
for (uploadBox in uploadBoxes)
{
var imgPath = uploadBox.daField.text;
var xmlPath = uploadBox.daField.text.replace(".png", ".xml");

// checking if we even have the correct file types in the correct places
if (Path.extension(imgPath) != "png" || Path.extension(xmlPath) != "xml") return false;
var imgPath = uploadBoxes[0].daField.text;
var xmlPath = uploadBoxes[0].daField.text.replace(".png", ".xml");

// testing if we could actually use these
var imgBytes = CharCreatorUtil.gimmeTheBytes(imgPath);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(xmlPath);
// checking if we even have the correct file types in the correct places
if (Path.extension(imgPath) != "png" || Path.extension(xmlPath) != "xml") return false;

var tempSprite = new FlxSprite();
try
{
var bitmap = BitmapData.fromBytes(imgBytes);
tempSprite.frames = FlxAtlasFrames.fromSparrow(bitmap, xmlBytes.toString());
}
catch (e)
{
tempSprite.destroy();
return false;
}
// testing if we could actually use these
var imgBytes = CharCreatorUtil.gimmeTheBytes(imgPath);
var xmlBytes = CharCreatorUtil.gimmeTheBytes(xmlPath);

tempSprite.destroy(); // fuck this guy i hate him
files = files.concat([
{
name: imgPath,
bytes: imgBytes
},
{
name: xmlPath,
bytes: xmlBytes
}
]);
var tempSprite = new FlxSprite();
try
{
var bitmap = BitmapData.fromBytes(imgBytes);
tempSprite.frames = FlxAtlasFrames.fromSparrow(bitmap, xmlBytes.toString());
}
catch (e)
{
tempSprite.destroy();
return false;
}
params.files = files;

tempSprite.destroy(); // fuck this guy i hate him
params.files = [
{name: imgPath, bytes: imgBytes}, {name: xmlPath, bytes: xmlBytes}];

return true;

Expand Down Expand Up @@ -205,16 +186,6 @@ class AddCharFilesDialog extends DefaultWizardDialog

return false;
}

function recursiveAssetsBox():Void
{
var uploadAssetsBox:UploadAssetsBox = new UploadAssetsBox("Put the path to the Spritesheet Image here.", FileUtil.FILE_EXTENSION_INFO_PNG);
uploadAssetsBox.daField.onChange = (_) -> {
uploadAssetsBox.daField.onChange = null;
recursiveAssetsBox();
};
addAssetsBox.addComponent(uploadAssetsBox);
}
}

class UploadAssetsBox extends HBox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DefaultWizardDialog extends Dialog
var id:Int = step;
if (_.button == DialogButton.CANCEL)
{
CharCreatorStartupWizard.wizardProcessRunning = false;
if (onQuit != null) onQuit();
}
else if (_.button == PREVIOUS_STEP_BUTTON)
Expand All @@ -43,6 +44,7 @@ class DefaultWizardDialog extends Dialog
id++;
if (id >= dialogArray.length)
{
CharCreatorStartupWizard.wizardProcessRunning = false;
if (onComplete != null) onComplete(params);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion source/funkin/ui/debug/char/import.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package funkin.ui.debug.char;

import funkin.ui.debug.char.util.*;
import funkin.ui.debug.char.util.CharCreatorUtil;
import funkin.ui.debug.char.util.GhostUtil;

#if !macro
using funkin.ui.debug.char.handlers.CharCreatorStartupWizard;
Expand Down
Loading

0 comments on commit d8f3e6a

Please sign in to comment.