From 02e1a5008ae809a5c648a8c8a28cbecbd30c1d3d Mon Sep 17 00:00:00 2001 From: lemz1 Date: Mon, 18 Nov 2024 23:08:12 +0100 Subject: [PATCH] import already existing player animations --- .../components/dialogs/ResultsAnimDialog.hx | 146 +++++++++++++++++- 1 file changed, 138 insertions(+), 8 deletions(-) diff --git a/source/funkin/ui/debug/char/components/dialogs/ResultsAnimDialog.hx b/source/funkin/ui/debug/char/components/dialogs/ResultsAnimDialog.hx index 9552dfbef7..8f11243b79 100644 --- a/source/funkin/ui/debug/char/components/dialogs/ResultsAnimDialog.hx +++ b/source/funkin/ui/debug/char/components/dialogs/ResultsAnimDialog.hx @@ -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> = [ + 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(); @@ -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; @@ -57,6 +113,30 @@ private class AddRankAnimationDataBox extends HBox addComponent(addButton); addComponent(removeButton); } + + public function useAnimationData(playerAnimations:Array):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(' @@ -69,15 +149,24 @@ private class AddRankAnimationDataBox extends HBox + + + + - + @@ -94,7 +183,7 @@ private class AddRankAnimationDataBox extends HBox ') private class RankAnimationData extends VBox { - public function new() + public function new(?data:PlayerResultsAnimationData) { super(); @@ -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; + } + } } }