Skip to content

Commit

Permalink
useful utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
KoloInDaCrib committed Dec 10, 2024
1 parent ec5439e commit 649d895
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 48 deletions.
2 changes: 1 addition & 1 deletion assets
22 changes: 15 additions & 7 deletions source/funkin/ui/debug/char/CharCreatorCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class CharCreatorCharacter extends Bopper
public var atlasCharacter:CharSelectAtlasSprite = null;
public var currentAtlasAnimation:Null<String> = null;

public var ignoreLoop:Bool = false;

override public function new(wizardParams:WizardGenerateParams)
{
super(CharacterRegistry.DEFAULT_DANCEEVERY);
Expand Down Expand Up @@ -105,6 +107,8 @@ class CharCreatorCharacter extends Bopper

if (atlasCharacter != null) // easier than transform LOL
{
if (ignoreLoop) atlasCharacter.looping = false;

atlasCharacter.x = this.x;
atlasCharacter.y = this.y;
atlasCharacter.alpha = this.alpha;
Expand Down Expand Up @@ -206,26 +210,30 @@ class CharCreatorCharacter extends Bopper

public override function playAnimation(name:String, restart:Bool = false, ignoreOther:Bool = false, reverse:Bool = false):Void
{
if (atlasCharacter == null)
{
super.playAnimation(name, restart, ignoreOther, reverse);
return;
}
if (!active) active = true;

if ((!canPlayOtherAnims && !ignoreOther)) return;

var correctName = correctAnimationName(name);
if (correctName == null)
{
trace('Could not find Atlas animation: ' + name);
trace('Could not find Character animation: ' + name);
return;
}

var animData = getAnimationData(correctName);
var loop:Bool = ignoreLoop ? false : animData.looped;

if (atlasCharacter == null)
{
super.playAnimation(name, restart, ignoreOther, reverse);
animation.curAnim.looped = loop;
return;
}

currentAtlasAnimation = correctName;
var prefix:String = animData.prefix;
if (prefix == null) prefix = correctName;
var loop:Bool = animData.looped;

atlasCharacter.playAnimation(prefix, restart, ignoreOther, loop);
applyAnimationOffsets(correctName);
Expand Down
2 changes: 2 additions & 0 deletions source/funkin/ui/debug/char/CharCreatorState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class CharCreatorState extends UIState
menubarItemExport.onClick = _ -> this.exportAll();
menubarItemExit.onClick = _ -> exitEditor();
menubarItemAbout.onClick = _ -> new CharCreatorAboutDialog().showDialog();

menubarSliderAnimSpeed.onChange = function(_) menubarLabelAnimSpeed.text = 'Animation Speed: ${menubarSliderAnimSpeed.pos}%';
}

function handleShortcuts():Void
Expand Down
20 changes: 16 additions & 4 deletions source/funkin/ui/debug/char/animate/CharSelectAtlasSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ class CharSelectAtlasSprite extends FlxAnimate

var fr:FlxKeyFrame = null;

var looping:Bool = false;
public var curFrame(get, never):Int;
public var totalFrames(get, never):Int;

public var looping:Bool = false;
public var ignoreExclusionPref:Array<String> = [];

/**
Expand Down Expand Up @@ -232,6 +234,16 @@ class CharSelectAtlasSprite extends FlxAnimate
}
}

function get_curFrame()
{
return (frames != null ? (anim?.curFrame ?? 0) : 0) - (fr?.index ?? 0);
}

function get_totalFrames()
{
return fr?.duration ?? (frames != null ? anim?.length ?? 0 : 0);
}

override public function update(elapsed:Float)
{
super.update(elapsed);
Expand Down Expand Up @@ -402,8 +414,8 @@ class CharSelectAtlasSprite extends FlxAnimate
public function getBasePosition():Null<FlxPoint>
{
// var stagePos = new FlxPoint(anim.stageInstance.matrix.tx, anim.stageInstance.matrix.ty);
var instancePos = new FlxPoint(anim.curInstance.matrix.tx, anim.curInstance.matrix.ty);
var firstElement = anim.curSymbol.timeline?.get(0)?.get(0)?.get(0);
var instancePos = new FlxPoint(anim?.curInstance?.matrix?.tx ?? 0, anim?.curInstance?.matrix?.ty ?? 0);
var firstElement = anim?.curSymbol?.timeline?.get(0)?.get(0)?.get(0);
if (firstElement == null) return instancePos;
var firstElementPos = new FlxPoint(firstElement.matrix.tx, firstElement.matrix.ty);

Expand All @@ -413,7 +425,7 @@ class CharSelectAtlasSprite extends FlxAnimate
public function getPivotPosition():Null<FlxPoint>
{
if (!symbolsInitialized) return null;
return anim.curInstance.symbol.transformationPoint;
return anim?.curInstance?.symbol?.transformationPoint;
}

public override function destroy():Void
Expand Down
29 changes: 26 additions & 3 deletions source/funkin/ui/debug/char/pages/CharCreatorFreeplayPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CharCreatorFreeplayPage extends CharCreatorDefaultPage

var pivotPointer:FlxShapeCircle;
var basePointer:FlxShapeCircle;
var frameTxt:FlxText;

override public function new(state:CharCreatorState, data:WizardGenerateParams)
{
Expand Down Expand Up @@ -133,6 +134,11 @@ class CharCreatorFreeplayPage extends CharCreatorDefaultPage

add(pivotPointer);
add(basePointer);

frameTxt = new FlxText(0, 0, 0, "", 48);
frameTxt.setFormat(Paths.font("vcr.ttf"), 48, FlxColor.WHITE, LEFT);
frameTxt.setBorderStyle(OUTLINE, FlxColor.BLACK, 3);
add(frameTxt);
}

override public function update(elapsed:Float)
Expand All @@ -145,13 +151,29 @@ class CharCreatorFreeplayPage extends CharCreatorDefaultPage
if (pivotPos != null) pivotPointer.setPosition(pivotPos.x - pivotPointer.width / 2, pivotPos.y - pivotPointer.height / 2);
if (basePos != null) basePointer.setPosition(basePos.x - basePointer.width / 2, basePos.y - basePointer.height / 2);

pivotPointer.visible = (daState.menubarCheckViewPivot.selected && pivotPos != null);
basePointer.visible = (daState.menubarCheckViewBase.selected && basePos != null);
pivotPointer.visible = (daState.menubarCheckToolsPivot.selected && pivotPos != null);
basePointer.visible = (daState.menubarCheckToolsBase.selected && basePos != null);

frameTxt.visible = daState.menubarCheckToolsFrames.selected;
frameTxt.text = 'Frame: ${dj.curFrame}/${(dj.totalFrames) - 1}';
if (pivotPos != null) frameTxt.setPosition(pivotPos.x - frameTxt.width / 2, pivotPos.y - frameTxt.height / 2);

dj.anim.timeScale = daState.menubarSliderAnimSpeed.pos / 100;

// no need for handleKeybinds function since these are the only functions in update methinks
if (!CharCreatorUtil.isHaxeUIDialogOpen)
{
if (FlxG.keys.justPressed.SPACE) playDJAnimation();
if (FlxG.keys.justPressed.SPACE)
{
if (!FlxG.keys.pressed.SHIFT && daState.menubarCheckToolsPause.selected && !dj.isAnimationFinished())
{
dj.active = !dj.active;
}
else
{
playDJAnimation();
}
}

if (FlxG.keys.justPressed.W) changeDJAnimation(-1);
if (FlxG.keys.justPressed.S) changeDJAnimation(1);
Expand Down Expand Up @@ -189,6 +211,7 @@ class CharCreatorFreeplayPage extends CharCreatorDefaultPage
labelAnimOffsetX.text = "" + (djAnims[currentDJAnimation]?.offsets[0] ?? 0.0);
labelAnimOffsetY.text = "" + (djAnims[currentDJAnimation]?.offsets[1] ?? 0.0);

dj.active = true;
dj.playAnimation(djAnims[currentDJAnimation]?.prefix ?? "", true);
dj.offset.set(djAnims[currentDJAnimation]?.offsets[0] ?? 0.0, djAnims[currentDJAnimation]?.offsets[1] ?? 0.0);
}
Expand Down
40 changes: 34 additions & 6 deletions source/funkin/ui/debug/char/pages/CharCreatorGameplayPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import funkin.ui.debug.char.components.dialogs.DefaultPageDialog;
import flixel.util.FlxColor;
import flixel.addons.display.shapes.FlxShapeCircle;
import flixel.FlxSprite;
import flixel.text.FlxText;

using StringTools;

Expand All @@ -45,6 +46,7 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
var atlasCharBasePointer:FlxShapeCircle;
var midPointPointer:FlxShapeCircle;
var camMarker:FlxSprite;
var frameTxt:FlxText;

override public function new(daState:CharCreatorState, wizardParams:WizardGenerateParams)
{
Expand Down Expand Up @@ -84,7 +86,7 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
atlasCharBasePointer = new FlxShapeCircle(0, 0, 16, cast {thickness: 2, color: 0xff00ffff}, 0xff00ffff);
midPointPointer = new FlxShapeCircle(0, 0, 16, cast {thickness: 2, color: 0xffffff00}, 0xffffff00);

atlasCharPivotPointer.zIndex = atlasCharBasePointer.zIndex = midPointPointer.zIndex = flixel.math.FlxMath.MAX_VALUE_INT - 2;
atlasCharPivotPointer.zIndex = atlasCharBasePointer.zIndex = midPointPointer.zIndex = flixel.math.FlxMath.MAX_VALUE_INT - 1;
atlasCharPivotPointer.visible = atlasCharBasePointer.visible = midPointPointer.visible = false;
atlasCharPivotPointer.alpha = atlasCharBasePointer.alpha = midPointPointer.alpha = 0.5;

Expand All @@ -95,9 +97,15 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
camMarker = new FlxSprite().loadGraphic(Paths.image("cursor/cursor-crosshair"));
camMarker.setGraphicSize(80, 80);
camMarker.updateHitbox();
camMarker.zIndex = flixel.math.FlxMath.MAX_VALUE_INT;
camMarker.zIndex = flixel.math.FlxMath.MAX_VALUE_INT - 2;
add(camMarker);

frameTxt = new FlxText(0, 0, 0, "", 48);
frameTxt.setFormat(Paths.font("vcr.ttf"), 48, FlxColor.WHITE, LEFT);
frameTxt.setBorderStyle(OUTLINE, FlxColor.BLACK, 3);
frameTxt.zIndex = flixel.math.FlxMath.MAX_VALUE_INT;
add(frameTxt);

sortAssets();
}

Expand All @@ -107,6 +115,9 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
labelAnimOffsetX.text = "" + (currentCharacter.getAnimationData(currentCharacter.getCurrentAnimation())?.offsets[0] ?? 0);
labelAnimOffsetY.text = "" + (currentCharacter.getAnimationData(currentCharacter.getCurrentAnimation())?.offsets[1] ?? 0);

frameTxt.visible = daState.menubarCheckToolsFrames.selected;
currentCharacter.ignoreLoop = daState.menubarCheckToolsLoop.selected;

if (currentCharacter.atlasCharacter != null)
{
var pivotPos = currentCharacter.atlasCharacter.getPivotPosition();
Expand All @@ -115,13 +126,23 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
if (pivotPos != null) atlasCharPivotPointer.setPosition(pivotPos.x - atlasCharPivotPointer.width / 2, pivotPos.y - atlasCharPivotPointer.height / 2);
if (basePos != null) atlasCharBasePointer.setPosition(basePos.x - atlasCharBasePointer.width / 2, basePos.y - atlasCharBasePointer.height / 2);

atlasCharPivotPointer.visible = (daState.menubarCheckViewPivot.selected && pivotPos != null);
atlasCharBasePointer.visible = (daState.menubarCheckViewBase.selected && basePos != null);
atlasCharPivotPointer.visible = (daState.menubarCheckToolsPivot.selected && pivotPos != null);
atlasCharBasePointer.visible = (daState.menubarCheckToolsBase.selected && basePos != null);

frameTxt.text = 'Frame: ${currentCharacter.atlasCharacter.curFrame}/${(currentCharacter.atlasCharacter.totalFrames) - 1}';
if (pivotPos != null) frameTxt.setPosition(pivotPos.x - frameTxt.width / 2, pivotPos.y - frameTxt.height / 2);

currentCharacter.atlasCharacter.anim.timeScale = daState.menubarSliderAnimSpeed.pos / 100;
}
else
{
midPointPointer.setPosition(currentCharacter.getMidpoint().x - midPointPointer.width / 2, currentCharacter.getMidpoint().y - midPointPointer.height / 2);
midPointPointer.visible = daState.menubarCheckViewMidpoint.selected;
midPointPointer.visible = daState.menubarCheckToolsMidpoint.selected;

frameTxt.text = 'Frame: ${currentCharacter.animation.curAnim?.curFrame ?? 0}/${(currentCharacter.animation.curAnim?.numFrames ?? 0) - 1}';
frameTxt.setPosition(currentCharacter.getMidpoint().x - frameTxt.width / 2, currentCharacter.getMidpoint().y - frameTxt.height / 2);

currentCharacter.animation.timeScale = daState.menubarSliderAnimSpeed.pos / 100;
}

var type = currentCharacter.characterType;
Expand All @@ -132,7 +153,14 @@ class CharCreatorGameplayPage extends CharCreatorDefaultPage
{
if (FlxG.keys.justPressed.SPACE && currentCharacter.getCurrentAnimation() != null)
{
currentCharacter.playAnimation(currentCharacter.getCurrentAnimation(), true);
if (!FlxG.keys.pressed.SHIFT && daState.menubarCheckToolsPause.selected && !currentCharacter.isAnimationFinished())
{
currentCharacter.active = !currentCharacter.active;
}
else
{
currentCharacter.playAnimation(currentCharacter.getCurrentAnimation(), true);
}
}

if (FlxG.keys.justPressed.W) changeAnim(-1);
Expand Down
Loading

0 comments on commit 649d895

Please sign in to comment.