From 956fd23c91f13b5dd53b1e1e4f00e66a2c4b952a Mon Sep 17 00:00:00 2001 From: lemz1 Date: Fri, 15 Nov 2024 00:42:25 +0100 Subject: [PATCH] ownedCharacters --- assets | 2 +- .../PlayableCharacterSettingsDialog.hx | 87 +++++++++++++++++++ .../debug/char/pages/CharCreatorSelectPage.hx | 2 +- 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/assets b/assets index c062e03cfd..c5672733fb 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit c062e03cfddd88daf674e6dfae9658228cfd32b9 +Subproject commit c5672733fb862b908a362d0094e65bdf5b59cd74 diff --git a/source/funkin/ui/debug/char/components/dialogs/PlayableCharacterSettingsDialog.hx b/source/funkin/ui/debug/char/components/dialogs/PlayableCharacterSettingsDialog.hx index 4387646ff5..645bcadd9b 100644 --- a/source/funkin/ui/debug/char/components/dialogs/PlayableCharacterSettingsDialog.hx +++ b/source/funkin/ui/debug/char/components/dialogs/PlayableCharacterSettingsDialog.hx @@ -1,10 +1,97 @@ package funkin.ui.debug.char.components.dialogs; +import haxe.ui.containers.HBox; +import haxe.ui.components.Button; +import haxe.ui.components.DropDown; +import haxe.ui.components.VerticalScroll; +import haxe.ui.data.ArrayDataSource; +import funkin.data.character.CharacterRegistry; +import funkin.util.SortUtil; + @:build(haxe.ui.macros.ComponentMacros.build("assets/exclude/data/ui/char-creator/dialogs/playable-character-settings-dialog.xml")) class PlayableCharacterSettingsDialog extends DefaultPageDialog { + var ownedCharBox:AddOwnedCharBox; + override public function new(daPage:CharCreatorDefaultPage) { super(daPage); + + ownedCharBox = new AddOwnedCharBox(); + + ownedCharsView.addComponent(ownedCharBox); + } + + public function listOwnedCharacters():Array + { + return ownedCharBox.listOwnedCharacters(); + } +} + +private class AddOwnedCharBox extends HBox +{ + var dropDowns:Array = []; + + override public function new() + { + super(); + + styleString = "border:1px solid $normal-border-color"; + percentWidth = 100; + height = 25; + verticalAlign = "center"; + + var addButton = new Button(); + addButton.text = "Add New Box"; + var removeButton = new Button(); + removeButton.text = "Remove Last Box"; + + addButton.percentWidth = removeButton.percentWidth = 50; + addButton.percentHeight = removeButton.percentHeight = 100; + + addButton.onClick = function(_) { + var parentList = this.parentComponent; + if (parentList == null) return; + + var newDropDown = new DropDown(); + newDropDown.dataSource = new ArrayDataSource(); + newDropDown.height = 25; + newDropDown.dropdownHeight = 100; + newDropDown.percentWidth = 100; + newDropDown.verticalAlign = "center"; + newDropDown.searchable = true; + var ids = CharacterRegistry.listCharacterIds(); + ids.sort(SortUtil.alphabetically); + for (id in ids) + { + newDropDown.dataSource.add({text: id, id: id}); + } + dropDowns.push(newDropDown); + + parentList.addComponentAt(newDropDown, parentList.childComponents.length - 1); // considering this box is last + removeButton.disabled = false; + } + + removeButton.disabled = true; + removeButton.onClick = function(_) { + var parentList = this.parentComponent; + if (parentList == null) return; + + dropDowns.pop(); + + parentList.removeComponentAt(parentList.childComponents.length - 2); + if (parentList.childComponents.length <= 2) removeButton.disabled = true; + } + + addComponent(addButton); + addComponent(removeButton); + } + + public function listOwnedCharacters():Array + { + return [ + for (dropDown in dropDowns) + dropDown.selectedItem.id + ]; } } diff --git a/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx b/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx index 3f828eaca1..450549958d 100644 --- a/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx +++ b/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx @@ -250,7 +250,7 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage { var playerData:PlayerData = new PlayerData(); playerData.name = "Unknown"; - playerData.ownedChars = []; + playerData.ownedChars = cast(dialogMap[SettingsDialog], PlayableCharacterSettingsDialog).listOwnedCharacters(); playerData.showUnownedChars = false; playerData.freeplayStyle = "bf"; playerData.freeplayDJ = null;