From 9ffffe9c8afdde6ab256933ed1aa739b523e30e4 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Mon, 11 Dec 2023 02:40:58 -0500 Subject: [PATCH] player char select --- .../ui/debug/charting/ChartEditorState.hx | 130 ++++++++++-------- 1 file changed, 74 insertions(+), 56 deletions(-) diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index b6f687c75..d5f6fd9ae 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -2089,68 +2089,86 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState healthIconBF.zIndex = 30; FlxMouseEvent.add(healthIconDad, function(_) { - trace("clicked dad"); - - var toolbox:CollapsibleDialog = cast haxe.ui.RuntimeComponentBuilder.fromAsset(Paths.ui('chart-editor/toolbox/iconselector')); - toolbox.showDialog(false); - var scrollView = toolbox.findComponent('charSelectScroll'); - - var hbox = new Grid(); - hbox.columns = 5; - hbox.width = 100; - scrollView.addComponent(hbox); - - var charIds:Array = CharacterDataParser.listCharacterIds(); - - charIds.sort(function(a, b) { - var result:Int = 0; - - if (a < b) - { - result = -1; - } - else if (a > b) - { - result = 1; - } - - return result; - }); - - for (char in charIds) - { - var image = new haxe.ui.components.Button(); - image.width = 70; - image.height = 70; - - if (char == currentSongMetadata.playData.characters.opponent) image.selected = true; - - image.icon = CharacterDataParser.getCharPixelIconAsset(char); - image.onClick = _ -> { - healthIconsDirty = true; - currentSongMetadata.playData.characters.opponent = char; - toolbox.hideDialog(haxe.ui.containers.dialogs.Dialog.DialogButton.APPLY); - - // var label = toolbox.findComponent('charIconName'); - // label.text = char; - }; - - image.onMouseOver = _ -> { - var label = toolbox.findComponent('charIconName'); - label.text = char; - }; - hbox.addComponent(image); - } - - toolbox.x = FlxG.mouse.screenX; - toolbox.y = FlxG.mouse.screenY; + createAndOpenCharSelect(1); }); FlxMouseEvent.add(healthIconBF, function(_) { - trace("clicked bf"); + createAndOpenCharSelect(0); }); } + /** + * @param charType 0 == BF, 1 == Dad + */ + function createAndOpenCharSelect(charType:Int = 0):Void + { + var charData = currentSongMetadata.playData.characters; + var currentChar:String = switch (charType) + { + case 0: charData.player; + case 1: charData.opponent; + default: throw 'Invalid charType: ' + charType; + }; + var toolbox:CollapsibleDialog = cast haxe.ui.RuntimeComponentBuilder.fromAsset(Paths.ui('chart-editor/toolbox/iconselector')); + toolbox.showDialog(false); + var scrollView = toolbox.findComponent('charSelectScroll'); + + var hbox = new Grid(); + hbox.columns = 5; + hbox.width = 100; + scrollView.addComponent(hbox); + + var charIds:Array = CharacterDataParser.listCharacterIds(); + + charIds.sort(function(a, b) { + var result:Int = 0; + + if (a < b) + { + result = -1; + } + else if (a > b) + { + result = 1; + } + + return result; + }); + + for (char in charIds) + { + var image = new haxe.ui.components.Button(); + image.width = 70; + image.height = 70; + + if (char == currentChar) image.selected = true; + + image.icon = CharacterDataParser.getCharPixelIconAsset(char); + image.onClick = _ -> { + healthIconsDirty = true; + switch (charType) + { + case 0: currentSongMetadata.playData.characters.player = char; + case 1: currentSongMetadata.playData.characters.opponent = char; + default: throw 'Invalid charType: ' + charType; + }; + toolbox.hideDialog(haxe.ui.containers.dialogs.Dialog.DialogButton.APPLY); + + // var label = toolbox.findComponent('charIconName'); + // label.text = char; + }; + + image.onMouseOver = _ -> { + var label = toolbox.findComponent('charIconName'); + label.text = char; + }; + hbox.addComponent(image); + } + + toolbox.x = FlxG.mouse.screenX; + toolbox.y = FlxG.mouse.screenY; + } + function buildNotePreview():Void { var height:Int = FlxG.height - MENU_BAR_HEIGHT - GRID_TOP_PAD - PLAYBAR_HEIGHT - GRID_TOP_PAD - GRID_TOP_PAD;