From 0b76255e07c6506ea0b9dc20075b2e470a5b6b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=8D=9A=7ENex?= <87421482+NexIsDumb@users.noreply.github.com> Date: Thu, 4 Jan 2024 02:42:29 +0100 Subject: [PATCH] Updater for the Note Types list in Chart Editor --- assets/data/noteTypes/Alt Anim Note.hx | 1 + source/funkin/editors/charter/Charter.hx | 65 +++++----- .../editors/charter/EditNoteTypesList.hx | 117 ++++++++++++++++++ 3 files changed, 146 insertions(+), 37 deletions(-) create mode 100644 assets/data/noteTypes/Alt Anim Note.hx create mode 100644 source/funkin/editors/charter/EditNoteTypesList.hx diff --git a/assets/data/noteTypes/Alt Anim Note.hx b/assets/data/noteTypes/Alt Anim Note.hx new file mode 100644 index 00000000..53cfc805 --- /dev/null +++ b/assets/data/noteTypes/Alt Anim Note.hx @@ -0,0 +1 @@ +// yo just for testing \ No newline at end of file diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index cb6e3668..14857520 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -205,10 +205,14 @@ class Charter extends UIState { null, { label: "Edit chart data", + color: 0xFF959829, icon: 4, + onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2;}, onSelect: chart_edit_data }, { label: "Edit metadata information", + color: 0xFF959829, icon: 4, + onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2;}, onSelect: chart_edit_metadata } ] @@ -270,19 +274,11 @@ class Charter extends UIState { }, null, { - label: "Add Note Type", + label: "Edit Note Types List", + color: 0xFF959829, icon: 4, + onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2;}, closeOnSelect: false, - onSelect: function (p) {trace(p);} - }, - { - label: "Edit Note Type", - closeOnSelect: false, - onSelect: function (p) {trace(p);} - }, - { - label: "Delete Note Type", - closeOnSelect: false, - onSelect: function (p) {trace(p);} + onSelect: editNoteTypesList }, null, { @@ -1239,6 +1235,9 @@ class Charter extends UIState { case CEditChartData(oldData, newData): PlayState.SONG.stage = oldData.stage; PlayState.SONG.scrollSpeed = oldData.speed; + case CEditNoteTypes(oldArray, newArray): + noteTypes = oldArray; + changeNoteType(); } } @@ -1279,6 +1278,9 @@ class Charter extends UIState { case CEditChartData(oldData, newData): PlayState.SONG.stage = newData.stage; PlayState.SONG.scrollSpeed = newData.speed; + case CEditNoteTypes(oldArray, newArray): + noteTypes = newArray; + changeNoteType(); } } @@ -1409,14 +1411,21 @@ class Charter extends UIState { undos.addToUndo(CEditSustains(undoChanges)); } - inline function changeNoteType(newID:Int) { - this.noteType = newID; buildNoteTypesUI(); - for(s in selection) + inline public function changeNoteType(?newID:Int) { + if(newID != null) noteType = newID; + if(noteType < 0) noteType = 0; + else if (noteType > noteTypes.length) noteType = noteTypes.length; + + buildNoteTypesUI(); + for(s in selection) if (s is CharterNote) { var n:CharterNote = cast s; n.updatePos(n.step, n.id, n.susLength, newID); } - } + } + + function editNoteTypesList(_) + FlxG.state.openSubState(new EditNoteTypesList()); function buildNoteTypesUI() { var noteTopButton:UITopMenuButton = cast topMenuSpr.members[noteIndex]; @@ -1444,30 +1453,11 @@ class Charter extends UIState { }, null, { - label: "Add Note Type", - color: 0xFF1E8020, icon: 2, - onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2;}, - closeOnSelect: false, - onSelect: function (_) { - var addButton:UIContextMenuOptionSpr = _.button; - addButton.label.text = ""; - var textBox:UITextBox = new UITextBox(addButton.x + 26, addButton.y+2, "TEST", 200, addButton.bHeight-4); - addButton.members.push(textBox); - }, - }, - { - label: "Edit Note Type", + label: "Edit Note Types List", color: 0xFF959829, icon: 4, onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2;}, closeOnSelect: false, - onSelect: function (p) {trace(p);}, - }, - { - label: "Delete Note Type", - color: 0xFF8F2222, icon: 3, - onCreate: function (button:UIContextMenuOptionSpr) {button.label.offset.x = button.icon.offset.x = -2; button.icon.offset.y = -1;}, - closeOnSelect: false, - onSelect: function (p) {trace(p);}, + onSelect: editNoteTypesList }, null, { @@ -1560,6 +1550,7 @@ enum CharterChange { CEditSustains(notes:Array); CEditEvent(event:CharterEvent, oldEvents:Array, newEvents:Array); CEditChartData(oldData:{stage:String, speed:Float}, newData:{stage:String, speed:Float}); + CEditNoteTypes(oldArray:Array, newArray:Array); } enum CharterCopyboardObject { diff --git a/source/funkin/editors/charter/EditNoteTypesList.hx b/source/funkin/editors/charter/EditNoteTypesList.hx new file mode 100644 index 00000000..4b8ea1b4 --- /dev/null +++ b/source/funkin/editors/charter/EditNoteTypesList.hx @@ -0,0 +1,117 @@ +package funkin.editors.charter; + +import flixel.math.FlxPoint; +import haxe.io.Path; + +class EditNoteTypesList extends UISubstateWindow { + public static var pathString:String = 'data/noteTypes/'; + + public var noteTypesList:UIButtonList; + public var saveButton:UIButton; + public var closeButton:UIButton; + + public override function create() { + FlxG.sound.music.pause(); + Charter.instance.vocals.pause(); + + winTitle = 'Note Types List Editor'; + winWidth = 380; winHeight = 390; + + super.create(); + + var title:UIText; + add(title = new UIText(windowSpr.x + 25, windowSpr.y + 15 + 16, 0, "Edit Note Types List", 28)); + + var noteTypesFileList = getNoteTypesList(true); + if (noteTypesFileList.length == 0) noteTypesFileList = getNoteTypesList(false); + var list:Array = Charter.instance.noteTypes; + + noteTypesList = new UIButtonList(15, title.y + title.height + 10, winWidth - 35, 260, "", FlxPoint.get(winWidth - 35, 60), null, 0); + noteTypesList.addButton.callback = () -> noteTypesList.add(new NoteTypeButton(0, 0, "New Note Type", noteTypesFileList, noteTypesList)); + noteTypesList.cameraSpacing = 0; + for (i in list) + noteTypesList.add(new NoteTypeButton(0, 0, i, noteTypesFileList, noteTypesList)); + add(noteTypesList); + noteTypesList.frames = Paths.getFrames('editors/ui/inputbox'); + + saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() { + saveList(); + close(); + }, 125); + add(saveButton); + + closeButton = new UIButton(saveButton.x - 20, saveButton.y, "Close", function() { + close(); + }, 125); + add(closeButton); + closeButton.color = 0xFFFF0000; + closeButton.x -= closeButton.bWidth; + } + + public function getNoteTypesList(?mods:Bool = false) { + var list:Array = []; + for (path in Paths.getFolderContent(pathString, true, mods ? MODS : BOTH)) if(Path.extension(path) == "hx") { + var file:String = Path.withoutDirectory(Path.withoutExtension(path)); + if (!list.contains(file)) list.push(file); + } + + return list; + } + + public function saveList() + { + var oldList:Array = Charter.instance.noteTypes; + var newList:Array = [for (note in noteTypesList.buttons.members) note.textBox.label.text]; + Charter.instance.noteTypes = newList; + Charter.instance.changeNoteType(); + Charter.instance.undos.addToUndo(CEditNoteTypes(oldList, newList)); + } +} + +class NoteTypeButton extends UIButton { + public var textBox:UIAutoCompleteTextBox; + public var deleteButton:UIButton; + public var deleteIcon:FlxSprite; + + public function new(x:Float, y:Float, name:String, list:Array, parent:UIButtonList) { + super(x, y, '', null, Std.int(parent.buttonSize.x), Std.int(parent.buttonSize.y)); + autoAlpha = false; + + members.push(textBox = new UIAutoCompleteTextBox(5, bHeight/2 - 40, name, 250)); + textBox.suggestItems = list; + textBox.antialiasing = true; + + field.alignment = LEFT; + field.x = textBox.x; + field.y = textBox.y + textBox.height + 30; + field.height = 9; + + deleteButton = new UIButton(textBox.x + textBox.label.width + 10, textBox.y - 8, "", function () { + parent.remove(this); + }, 32); + deleteButton.color = 0xFFFF0000; + deleteButton.autoAlpha = false; + members.push(deleteButton); + + deleteIcon = new FlxSprite(deleteButton.x + (15/2), deleteButton.y + 8).loadGraphic(Paths.image('editors/character/delete-button')); // Yeah yeah its for characters, but tbh goes fire here too + deleteIcon.antialiasing = false; + members.push(deleteIcon); + } + + private var lastName:String = null; + override function update(elapsed) { + deleteButton.y = y + bHeight / 2 - deleteButton.bHeight / 2 - 8; + textBox.y = y + bHeight/2 - 20; + deleteIcon.x = deleteButton.x + (15/2); deleteIcon.y = deleteButton.y + 8; + + deleteButton.selectable = selectable; + deleteButton.shouldPress = shouldPress; + + super.update(elapsed); + field.follow(this, textBox.x, textBox.x + textBox.height + 30); + if(lastName != textBox.label.text) { + lastName = textBox.label.text; + field.text = 'Path: ${EditNoteTypesList.pathString}$lastName.hx'; + } + } +} \ No newline at end of file