From 47f39b072a34b4f701c3d3ca17dd0c2aa4e06068 Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Fri, 24 Nov 2023 00:42:07 -0500 Subject: [PATCH] Convert chart editor to macro-based UIState --- Project.xml | 5 +- assets | 2 +- docs/style-guide.md | 4 + source/funkin/play/PauseSubState.hx | 1 + source/funkin/play/PlayState.hx | 3 +- .../ui/debug/charting/ChartEditorState.hx | 503 +++++++++--------- .../components/ChartEditorPlaybarHead.hx | 17 + .../handlers/ChartEditorShortcutHandler.hx | 36 +- .../handlers/ChartEditorToolboxHandler.hx | 25 +- source/funkin/util/FileUtil.hx | 173 +++--- source/haxe/ui/backend/flixel/UIStateBase.hx | 3 + .../haxe/ui/backend/flixel/UISubStateBase.hx | 3 + 12 files changed, 396 insertions(+), 379 deletions(-) create mode 100644 source/funkin/ui/debug/charting/components/ChartEditorPlaybarHead.hx create mode 100644 source/haxe/ui/backend/flixel/UIStateBase.hx create mode 100644 source/haxe/ui/backend/flixel/UISubStateBase.hx diff --git a/Project.xml b/Project.xml index 46ba7f155..4c0ffdce7 100644 --- a/Project.xml +++ b/Project.xml @@ -162,10 +162,13 @@ - + + + +
diff --git a/assets b/assets index 4ed2b3084..74847831d 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 4ed2b3084d54899e10d10a97eaafe210158768be +Subproject commit 74847831dec229fc1c639ca4ca963973022b8648 diff --git a/docs/style-guide.md b/docs/style-guide.md index 1131cca2b..4c4e01492 100644 --- a/docs/style-guide.md +++ b/docs/style-guide.md @@ -32,6 +32,10 @@ Example: public function checkSyncError(?targetTime:Float):Float ``` +## Commenting Unused Code + +Do not comment out sections of code that are unused. Keep these snippets elsewhere or remove them. Older chunks of code can be retrieved by referring to the older Git commits, and having large chunks of commented code makes files longer and more confusing to navigate. + ## License Headers Do not include headers specifying code license on individual files in the repo, since the main `LICENSE.md` file covers all of them. diff --git a/source/funkin/play/PauseSubState.hx b/source/funkin/play/PauseSubState.hx index f5555b66e..c9039ce40 100644 --- a/source/funkin/play/PauseSubState.hx +++ b/source/funkin/play/PauseSubState.hx @@ -233,6 +233,7 @@ class PauseSubState extends MusicBeatSubState if (PlayStatePlaylist.isStoryMode) { + PlayStatePlaylist.reset(); openSubState(new funkin.ui.transition.StickerSubState(null, STORY)); } else diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index c9512aa93..7d20f4697 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1354,8 +1354,7 @@ class PlayState extends MusicBeatSubState else { // lolol - lime.app.Application.current.window.alert('Nice job, you ignoramus. $id isn\'t a real stage.\nI\'m falling back to the default so the game doesn\'t shit itself.', - 'Stage Error'); + lime.app.Application.current.window.alert('Unable to load stage ${id}, is its data corrupted?.', 'Stage Error'); } } diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 4772fab7c..02f66e6d6 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -1,6 +1,5 @@ package funkin.ui.debug.charting; -import haxe.ui.containers.menus.MenuBar; import flixel.addons.display.FlxSliceSprite; import flixel.addons.display.FlxTiledSprite; import flixel.addons.transition.FlxTransitionableState; @@ -18,17 +17,18 @@ import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.tweens.misc.VarTween; import flixel.util.FlxColor; -import funkin.ui.mainmenu.MainMenuState; import flixel.util.FlxSort; import flixel.util.FlxTimer; import funkin.audio.visualize.PolygonSpectogram; import funkin.audio.VoicesGroup; import funkin.data.notestyle.NoteStyleRegistry; +import funkin.data.song.SongData.SongCharacterData; import funkin.data.song.SongData.SongChartData; import funkin.data.song.SongData.SongEventData; import funkin.data.song.SongData.SongMetadata; import funkin.data.song.SongData.SongNoteData; import funkin.data.song.SongDataUtils; +import funkin.data.song.SongRegistry; import funkin.input.Cursor; import funkin.input.TurboKeyHandler; import funkin.modding.events.ScriptEvent; @@ -39,20 +39,12 @@ import funkin.play.components.HealthIcon; import funkin.play.notes.NoteSprite; import funkin.play.PlayState; import funkin.play.song.Song; -import funkin.data.song.SongData.SongChartData; -import funkin.data.song.SongRegistry; -import funkin.data.song.SongData.SongEventData; -import funkin.data.song.SongData.SongMetadata; -import funkin.data.song.SongData.SongNoteData; -import funkin.data.song.SongData.SongCharacterData; -import funkin.data.song.SongDataUtils; -import funkin.ui.debug.charting.commands.ChartEditorCommand; -import funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler; import funkin.play.stage.StageData; import funkin.save.Save; import funkin.ui.debug.charting.commands.AddEventsCommand; import funkin.ui.debug.charting.commands.AddNotesCommand; import funkin.ui.debug.charting.commands.ChartEditorCommand; +import funkin.ui.debug.charting.commands.ChartEditorCommand; import funkin.ui.debug.charting.commands.CutItemsCommand; import funkin.ui.debug.charting.commands.DeselectAllItemsCommand; import funkin.ui.debug.charting.commands.DeselectItemsCommand; @@ -73,15 +65,21 @@ import funkin.ui.debug.charting.components.ChartEditorEventSprite; import funkin.ui.debug.charting.components.ChartEditorHoldNoteSprite; import funkin.ui.debug.charting.components.ChartEditorNotePreview; import funkin.ui.debug.charting.components.ChartEditorNoteSprite; +import funkin.ui.debug.charting.components.ChartEditorPlaybarHead; import funkin.ui.debug.charting.components.ChartEditorSelectionSquareSprite; +import funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler; import funkin.ui.haxeui.components.CharacterPlayer; import funkin.ui.haxeui.HaxeUIState; +import funkin.ui.mainmenu.MainMenuState; import funkin.util.Constants; +import funkin.util.FileUtil; import funkin.util.SortUtil; import funkin.util.WindowUtil; import haxe.DynamicAccess; import haxe.io.Bytes; import haxe.io.Path; +import haxe.ui.backend.flixel.UIRuntimeState; +import haxe.ui.backend.flixel.UIState; import haxe.ui.components.DropDown; import haxe.ui.components.Label; import haxe.ui.components.NumberStepper; @@ -90,18 +88,20 @@ import haxe.ui.components.TextField; import haxe.ui.containers.dialogs.CollapsibleDialog; import haxe.ui.containers.Frame; import haxe.ui.containers.menus.Menu; +import haxe.ui.containers.menus.MenuBar; import haxe.ui.containers.menus.MenuItem; import haxe.ui.containers.TreeView; import haxe.ui.containers.TreeViewNode; import haxe.ui.core.Component; import haxe.ui.core.Screen; import haxe.ui.events.DragEvent; +import haxe.ui.events.MouseEvent; +import haxe.ui.events.UIEvent; import haxe.ui.events.UIEvent; import haxe.ui.focus.FocusManager; import haxe.ui.notifications.NotificationManager; import haxe.ui.notifications.NotificationType; import openfl.display.BitmapData; -import funkin.util.FileUtil; using Lambda; @@ -109,24 +109,22 @@ using Lambda; * A state dedicated to allowing the user to create and edit song charts. * Built with HaxeUI for use by both developers and modders. * - * Some functionality is moved to other classes to help maintain my sanity. + * Some functionality is split into handler classes to help maintain my sanity. * * @author MasterEric */ -@:nullSafety -class ChartEditorState extends HaxeUIState +// @:nullSafety + +@:build(haxe.ui.ComponentBuilder.build("assets/exclude/data/ui/chart-editor/main-view.xml")) +class ChartEditorState extends UIState // UIState derives from MusicBeatState { /** * CONSTANTS */ // ============================== - // XML Layouts - public static final CHART_EDITOR_LAYOUT:String = Paths.ui('chart-editor/main-view'); - - public static final CHART_EDITOR_NOTIFBAR_LAYOUT:String = Paths.ui('chart-editor/components/notifbar'); - public static final CHART_EDITOR_PLAYBARHEAD_LAYOUT:String = Paths.ui('chart-editor/components/playbar-head'); - + // Layouts public static final CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/notedata'); + public static final CHART_EDITOR_TOOLBOX_EVENTDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/eventdata'); public static final CHART_EDITOR_TOOLBOX_METADATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/metadata'); public static final CHART_EDITOR_TOOLBOX_DIFFICULTY_LAYOUT:String = Paths.ui('chart-editor/toolbox/difficulty'); @@ -1199,6 +1197,110 @@ class ChartEditorState extends HaxeUIState return currentSongMetadata.playData.characters.instrumental = value; } + /** + * HAXEUI COMPONENTS + */ + // ============================== + + /** + * The layout containing the playbar. + * Constructed manually and added to the layout so we can control its position. + */ + var playbarHeadLayout:Null = null; + + // NOTE: All the components below are automatically assigned via HaxeUI macros. + /** + * The menubar at the top of the screen. + */ + // var menubar:MenuBar; + /** + * The `File -> New Chart` menu item. + */ + // var menubarItemNewChart:MenuItem; + /** + * The `File -> Open Chart` menu item. + */ + // var menubarItemOpenChart:MenuItem; + /** + * The `File -> Open Recent` menu. + */ + // var menubarOpenRecent:Menu; + /** + * The `File -> Save Chart` menu item. + */ + // var menubarItemSaveChart:MenuItem; + /** + * The `File -> Save Chart As` menu item. + */ + // var menubarItemSaveChartAs:MenuItem; + /** + * The `File -> Preferences` menu item. + */ + // var menubarItemPreferences:MenuItem; + /** + * The `File -> Exit` menu item. + */ + // var menubarItemExit:MenuItem; + /** + * The `Edit -> Undo` menu item. + */ + // var menubarItemUndo:MenuItem; + /** + * The `Edit -> Redo` menu item. + */ + // var menubarItemRedo:MenuItem; + /** + * The `Edit -> Cut` menu item. + */ + // var menubarItemCut:MenuItem; + /** + * The `Edit -> Copy` menu item. + */ + // var menubarItemCopy:MenuItem; + /** + * The `Edit -> Paste` menu item. + */ + // var menubarItemPaste:MenuItem; + /** + * The `Edit -> Paste Unsnapped` menu item. + */ + // var menubarItemPasteUnsnapped:MenuItem; + /** + * The `Edit -> Delete` menu item. + */ + // var menubarItemDelete:MenuItem; + /** + * The label by the playbar telling the song position. + */ + // var playbarSongPos:Label; + /** + * The label by the playbar telling the song time remaining. + */ + // var playbarSongRemaining:Label; + /** + * The label by the playbar telling the note snap. + */ + // var playbarNoteSnap:Label; + /** + * The button by the playbar to jump to the start of the song. + */ + // var playbarStart:Button; + /** + * The button by the playbar to jump backwards in the song. + */ + // var playbarBack:Button; + /** + * The button by the playbar to play or pause the song. + */ + // var playbarPlay:Button; + /** + * The button by the playbar to jump forwards in the song. + */ + // var playbarForward:Button; + /** + * The button by the playbar to jump to the end of the song. + */ + // var playbarEnd:Button; /** * RENDER OBJECTS */ @@ -1288,41 +1390,6 @@ class ChartEditorState extends HaxeUIState */ var menuBG:Null = null; - /** - * The layout containing the playbar head slider. - */ - var playbarHeadLayout:Null = null; - - /** - * The submenu in the menubar containing recently opened files. - */ - var menubarOpenRecent:Null = null; - - /** - * The item in the menubar to save the currently opened chart. - */ - var menubarItemSaveChart:Null = null; - - /** - * The playbar head slider. - */ - var playbarHead:Null = null; - - /** - * The label by the playbar telling the song position. - */ - var playbarSongPos:Null