Skip to content

Commit

Permalink
import already existing player animations
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 18, 2024
1 parent 9db319b commit 02e1a50
Showing 1 changed file with 138 additions and 8 deletions.
146 changes: 138 additions & 8 deletions source/funkin/ui/debug/char/components/dialogs/ResultsAnimDialog.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,79 @@ package funkin.ui.debug.char.components.dialogs;
import haxe.ui.containers.VBox;
import haxe.ui.containers.HBox;
import haxe.ui.components.Button;
import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.play.scoring.Scoring.ScoringRank;

@:build(haxe.ui.macros.ComponentMacros.build("assets/exclude/data/ui/char-creator/dialogs/results-anim-dialog.xml"))
@:access(funkin.ui.debug.char.pages.CharCreatorResultsPage)
class ResultsAnimDialog extends DefaultPageDialog
{
var rankAnimationDataMap:Map<ScoringRank, Array<PlayerResultsAnimationData>> = [
PERFECT_GOLD => [],
PERFECT => [],
EXCELLENT => [],
GREAT => [],
GOOD => [],
SHIT => [],
];

var rankAnimationBox:AddRankAnimationDataBox;

var currentRank(get, never):ScoringRank;

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

rankDropdown.onChange = function(_) {
if (daPage.data.importedPlayerData != null)
{
var currentChar = PlayerRegistry.instance.fetchEntry(daPage.data.importedPlayerData);
for (rank in rankAnimationDataMap.keys())
{
var playerAnimations = currentChar?.getResultsAnimationDatas(rank) ?? [];
rankAnimationDataMap.set(rank, playerAnimations);
}
}

rankAnimationView.addComponent(new AddRankAnimationDataBox());
rankAnimationBox = new AddRankAnimationDataBox();
rankAnimationView.addComponent(rankAnimationBox);

rankDropdown.selectedIndex = 0;
rankDropdown.onChange = _ -> rankAnimationBox.useAnimationData(rankAnimationDataMap[currentRank]);

rankAnimationBox.useAnimationData(rankAnimationDataMap[currentRank]);
}

function get_currentRank():ScoringRank
{
if (rankDropdown.selectedItem == null) return PERFECT_GOLD;

switch (rankDropdown.selectedItem.text)
{
case "Perfect Gold":
return PERFECT_GOLD;
case "Perfect":
return PERFECT;
case "Excellent":
return EXCELLENT;
case "Great":
return GREAT;
case "Good":
return GOOD;
case "Shit":
return SHIT;
}

return PERFECT_GOLD;
}
}

private class AddRankAnimationDataBox extends HBox
{
var addButton:Button;
var removeButton:Button;

public function new()
{
super();
Expand All @@ -29,9 +85,9 @@ private class AddRankAnimationDataBox extends HBox
height = 25;
verticalAlign = "center";

var addButton = new Button();
addButton = new Button();
addButton.text = "Add New Box";
var removeButton = new Button();
removeButton = new Button();
removeButton.text = "Remove Last Box";

addButton.percentWidth = removeButton.percentWidth = 50;
Expand All @@ -57,6 +113,30 @@ private class AddRankAnimationDataBox extends HBox
addComponent(addButton);
addComponent(removeButton);
}

public function useAnimationData(playerAnimations:Array<PlayerResultsAnimationData>):Void
{
var parentList = this.parentComponent;
if (parentList == null) return;

clearAnimationData();

for (animData in playerAnimations)
{
parentList.addComponentAt(new RankAnimationData(animData), parentList.childComponents.length - 1);
}

removeButton.disabled = parentList.childComponents.length <= 2;
}

function clearAnimationData():Void
{
var parentList = this.parentComponent;
if (parentList == null) return;

while (parentList.childComponents.length > 1)
parentList.removeComponentAt(parentList.childComponents.length - 2);
}
}

@:xml('
Expand All @@ -69,15 +149,24 @@ private class AddRankAnimationDataBox extends HBox
</data>
</dropdown>
<textfield id="animAssetPath" placeholder="Asset Path" width="100%"/>
<hbox width="100%" verticalAlign="center">
<label text="Offsets" verticalAlign="center"/>
<number-stepper id="animOffsetX" step="1" pos="0" verticalAlign="center"/>
<number-stepper id="animOffsetY" step="1" pos="0" verticalAlign="center"/>
</hbox>
<hbox width="100%" verticalAlign="center">
<label text="Z Index" verticalAlign="center"/>
<number-stepper id="animZIndex" min="0" step="1" pos="500" verticalAlign="center"/>
</hbox>
<hbox width="100%" verticalAlign="center">
<label text="Delay" verticalAlign="center"/>
<number-stepper id="animDelay" min="0" step="0.1" verticalAlign="center"/>
<number-stepper id="animDelay" min="0" step="0.01" verticalAlign="center"/>
</hbox>
<hbox width="100%" verticalAlign="center">
<label text="Scale" verticalAlign="center"/>
<number-stepper id="animScale" min="0" step="0.1" pos="1" verticalAlign="center"/>
<number-stepper id="animScale" min="0" step="0.01" pos="1" verticalAlign="center"/>
</hbox>
<checkbox id="animLooped" text="Looped"/>
<checkbox id="animLooped" text="Looped" selected="true"/>
<hbox width="100%" verticalAlign="center">
<checkbox id="animStartFrameLabelCheck" text="Start Frame Label" verticalAlign="center"/>
<textfield id="animStartFrameLabel" placeholder="Frame Label" disabled="true" verticalAlign="center"/>
Expand All @@ -94,7 +183,7 @@ private class AddRankAnimationDataBox extends HBox
')
private class RankAnimationData extends VBox
{
public function new()
public function new(?data:PlayerResultsAnimationData)
{
super();

Expand All @@ -109,5 +198,46 @@ private class RankAnimationData extends VBox
animLoopFrameLabelCheck.onClick = function(_) {
animLoopFrameLabel.disabled = !animLoopFrameLabelCheck.selected;
}

if (data != null)
{
animRenderType.selectedIndex = data.renderType == "sparrow" ? 1 : 0;
animAssetPath.value = data.assetPath;

if (data.offsets != null)
{
animOffsetX.value = data.offsets[0];
animOffsetY.value = data.offsets[1];
}

if (data.zIndex != null) animZIndex.value = data.zIndex;

if (data.delay != null) animDelay.value = data.delay;

if (data.scale != null) animScale.value = data.scale;

if (data.looped != null) animLooped.selected = data.looped;

if (data.startFrameLabel != null && data.startFrameLabel != "")
{
animStartFrameLabelCheck.selected = true;
animStartFrameLabel.disabled = false;
animStartFrameLabel.text = data.startFrameLabel;
}

if (data.loopFrame != null)
{
animLoopFrameCheck.selected = true;
animLoopFrame.disabled = false;
animLoopFrame.value = data.loopFrame;
}

if (data.loopFrameLabel != null)
{
animLoopFrameLabelCheck.selected = true;
animLoopFrameLabel.disabled = false;
animLoopFrameLabel.text = data.loopFrameLabel;
}
}
}
}

0 comments on commit 02e1a50

Please sign in to comment.