Skip to content

Commit

Permalink
ownedCharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 14, 2024
1 parent 9704da5 commit 956fd23
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets
Original file line number Diff line number Diff line change
@@ -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<String>
{
return ownedCharBox.listOwnedCharacters();
}
}

private class AddOwnedCharBox extends HBox
{
var dropDowns:Array<DropDown> = [];

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<String>
{
return [
for (dropDown in dropDowns)
dropDown.selectedItem.id
];
}
}
2 changes: 1 addition & 1 deletion source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 956fd23

Please sign in to comment.