Revamp note kind handling in the chart editor.

This commit is contained in:
EliteMasterEric 2024-02-16 22:01:47 -05:00
parent 516c5e8596
commit 98e6d4091e
9 changed files with 222 additions and 79 deletions

View File

@ -898,20 +898,26 @@ class SongNoteDataRaw implements ICloneable<SongNoteDataRaw>
/**
* The kind of the note.
* This can allow the note to include information used for custom behavior.
* Defaults to blank or `Constants.DEFAULT_DIFFICULTY`.
* Defaults to `null` for no kind.
*/
@:alias("k")
@:default("normal")
@:optional
public var kind(get, default):String = '';
@:isVar
public var kind(get, set):Null<String> = null;
function get_kind():String
function get_kind():Null<String>
{
if (this.kind == null || this.kind == '') return 'normal';
if (this.kind == null || this.kind == '') return null;
return this.kind;
}
function set_kind(value:Null<String>):Null<String>
{
if (value == '') value = null;
return this.kind = value;
}
public function new(time:Float, data:Int, length:Float = 0, kind:String = '')
{
this.time = time;
@ -1061,13 +1067,13 @@ abstract SongNoteData(SongNoteDataRaw) from SongNoteDataRaw to SongNoteDataRaw
if (this == null) return other == null;
if (other == null) return false;
if (this.kind == '')
if (this.kind == null || this.kind == '')
{
if (other.kind != '' && other.kind != 'normal') return false;
if (other.kind != '' && this.kind != null) return false;
}
else
{
if (other.kind == '' || other.kind != this.kind) return false;
if (other.kind == '' || this.kind == null) return false;
}
return this.time == other.time && this.data == other.data && this.length == other.length;
@ -1082,11 +1088,11 @@ abstract SongNoteData(SongNoteDataRaw) from SongNoteDataRaw to SongNoteDataRaw
if (this.kind == '')
{
if (other.kind != '' && other.kind != 'normal') return true;
if (other.kind != '') return true;
}
else
{
if (other.kind == '' || other.kind != this.kind) return true;
if (other.kind == '') return true;
}
return this.time != other.time || this.data != other.data || this.length != other.length;

View File

@ -210,14 +210,13 @@ class SongDataUtils
*/
public static function writeItemsToClipboard(data:SongClipboardItems):Void
{
var writer = new json2object.JsonWriter<SongClipboardItems>();
var ignoreNullOptionals = true;
var writer = new json2object.JsonWriter<SongClipboardItems>(ignoreNullOptionals);
var dataString:String = writer.write(data, ' ');
ClipboardUtil.setClipboard(dataString);
trace('Wrote ' + data.notes.length + ' notes and ' + data.events.length + ' events to clipboard.');
trace(dataString);
}
/**

View File

@ -702,7 +702,7 @@ class PlayState extends MusicBeatSubState
function assertChartExists():Bool
{
// Returns null if the song failed to load or doesn't have the selected difficulty.
if (currentSong == null || currentChart == null)
if (currentSong == null || currentChart == null || currentChart.notes == null)
{
// We have encountered a critical error. Prevent Flixel from trying to run any gameplay logic.
criticalFailure = true;
@ -721,6 +721,10 @@ class PlayState extends MusicBeatSubState
{
message = 'The was a critical error retrieving data for this song on "$currentDifficulty" difficulty with variation "$currentVariation". Click OK to return to the main menu.';
}
else if (currentChart.notes == null)
{
message = 'The was a critical error retrieving note data for this song on "$currentDifficulty" difficulty with variation "$currentVariation". Click OK to return to the main menu.';
}
// Display a popup. This blocks the application until the user clicks OK.
lime.app.Application.current.window.alert(message, 'Error loading PlayState');

View File

@ -162,8 +162,8 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
public static final CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/opponent-preview');
public static final CHART_EDITOR_TOOLBOX_METADATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/metadata');
public static final CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:String = Paths.ui('chart-editor/toolbox/offsets');
public static final CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/notedata');
public static final CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/eventdata');
public static final CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/note-data');
public static final CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/event-data');
public static final CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT:String = Paths.ui('chart-editor/toolbox/freeplay');
public static final CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT:String = Paths.ui('chart-editor/toolbox/playtest-properties');
@ -538,9 +538,9 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// Tools Status
/**
* The note kind to use for notes being placed in the chart. Defaults to `''`.
* The note kind to use for notes being placed in the chart. Defaults to `null`.
*/
var noteKindToPlace:String = '';
var noteKindToPlace:Null<String> = null;
/**
* The event type to use for events being placed in the chart. Defaults to `''`.
@ -2458,11 +2458,6 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
*/
override public function draw():Void
{
if (selectionBoxStartPos != null)
{
trace('selectionBoxSprite: ${selectionBoxSprite.visible} ${selectionBoxSprite.exists} ${this.members.contains(selectionBoxSprite)}');
}
super.draw();
}
@ -2968,7 +2963,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
menubarItemToggleToolboxDifficulty.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_DIFFICULTY_LAYOUT, event.value);
menubarItemToggleToolboxMetadata.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_METADATA_LAYOUT, event.value);
menubarItemToggleToolboxOffsets.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT, event.value);
menubarItemToggleToolboxNotes.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT, event.value);
menubarItemToggleToolboxNoteData.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT, event.value);
menubarItemToggleToolboxEventData.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT, event.value);
menubarItemToggleToolboxFreeplay.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_FREEPLAY_LAYOUT, event.value);
menubarItemToggleToolboxPlaytestProperties.onChange = event -> this.setToolboxState(CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT, event.value);
@ -5286,6 +5281,9 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
{
FlxG.watch.addQuick('musicTime', audioInstTrack?.time ?? 0.0);
FlxG.watch.addQuick('noteKindToPlace', noteKindToPlace);
FlxG.watch.addQuick('eventKindToPlace', eventKindToPlace);
FlxG.watch.addQuick('scrollPosInPixels', scrollPositionInPixels);
FlxG.watch.addQuick('playheadPosInPixels', playheadPositionInPixels);

View File

@ -59,6 +59,17 @@ class SelectItemsCommand implements ChartEditorCommand
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT);
}
// If we just selected one or more notes (and no events), then we should make the note data toolbox display the note data for the selected note.
if (this.events.length == 0 && this.notes.length >= 1)
{
var noteSelected = this.notes[0];
state.noteKindToPlace = noteSelected.kind;
// This code is here to parse note data that's not built as a struct for some reason.
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT);
}
state.noteDisplayDirty = true;
state.notePreviewDirty = true;
}

View File

@ -56,6 +56,16 @@ class SetItemSelectionCommand implements ChartEditorCommand
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT);
}
// IF we just selected one or more notes (and no events), then we should make the note data toolbox display the note data for the selected note.
if (this.events.length == 0 && this.notes.length >= 1)
{
var noteSelected = this.notes[0];
state.noteKindToPlace = noteSelected.kind;
state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT);
}
state.noteDisplayDirty = true;
}

View File

@ -38,6 +38,7 @@ import funkin.ui.debug.charting.toolboxes.ChartEditorMetadataToolbox;
import funkin.ui.debug.charting.toolboxes.ChartEditorOffsetsToolbox;
import funkin.ui.debug.charting.toolboxes.ChartEditorFreeplayToolbox;
import funkin.ui.debug.charting.toolboxes.ChartEditorEventDataToolbox;
import funkin.ui.debug.charting.toolboxes.ChartEditorNoteDataToolbox;
import funkin.ui.debug.charting.toolboxes.ChartEditorDifficultyToolbox;
import haxe.ui.containers.Frame;
import haxe.ui.containers.Grid;
@ -79,17 +80,16 @@ class ChartEditorToolboxHandler
switch (id)
{
case ChartEditorState.CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:
onShowToolboxNoteData(state, toolbox);
case ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT:
cast(toolbox, ChartEditorBaseToolbox).refresh();
case ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:
// TODO: Fix this.
// TODO: Make these better.
cast(toolbox, ChartEditorBaseToolbox).refresh();
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT:
onShowToolboxPlaytestProperties(state, toolbox);
case ChartEditorState.CHART_EDITOR_TOOLBOX_DIFFICULTY_LAYOUT:
cast(toolbox, ChartEditorBaseToolbox).refresh();
case ChartEditorState.CHART_EDITOR_TOOLBOX_METADATA_LAYOUT:
// TODO: Fix this.
cast(toolbox, ChartEditorBaseToolbox).refresh();
case ChartEditorState.CHART_EDITOR_TOOLBOX_OFFSETS_LAYOUT:
cast(toolbox, ChartEditorBaseToolbox).refresh();
@ -124,10 +124,6 @@ class ChartEditorToolboxHandler
switch (id)
{
case ChartEditorState.CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:
onHideToolboxNoteData(state, toolbox);
case ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:
onHideToolboxEventData(state, toolbox);
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYTEST_PROPERTIES_LAYOUT:
onHideToolboxPlaytestProperties(state, toolbox);
case ChartEditorState.CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:
@ -196,7 +192,7 @@ class ChartEditorToolboxHandler
var toolbox:Null<CollapsibleDialog> = null;
switch (id)
{
case ChartEditorState.CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:
case ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT:
toolbox = buildToolboxNoteDataLayout(state);
case ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT:
toolbox = buildToolboxEventDataLayout(state);
@ -262,58 +258,13 @@ class ChartEditorToolboxHandler
static function buildToolboxNoteDataLayout(state:ChartEditorState):Null<CollapsibleDialog>
{
var toolbox:CollapsibleDialog = cast RuntimeComponentBuilder.fromAsset(ChartEditorState.CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT);
var toolbox:ChartEditorBaseToolbox = ChartEditorNoteDataToolbox.build(state);
if (toolbox == null) return null;
// Starting position.
toolbox.x = 75;
toolbox.y = 100;
toolbox.onDialogClosed = function(event:DialogEvent) {
state.menubarItemToggleToolboxNotes.selected = false;
}
var toolboxNotesNoteKind:Null<DropDown> = toolbox.findComponent('toolboxNotesNoteKind', DropDown);
if (toolboxNotesNoteKind == null) throw 'ChartEditorToolboxHandler.buildToolboxNoteDataLayout() - Could not find toolboxNotesNoteKind component.';
var toolboxNotesCustomKindLabel:Null<Label> = toolbox.findComponent('toolboxNotesCustomKindLabel', Label);
if (toolboxNotesCustomKindLabel == null)
throw 'ChartEditorToolboxHandler.buildToolboxNoteDataLayout() - Could not find toolboxNotesCustomKindLabel component.';
var toolboxNotesCustomKind:Null<TextField> = toolbox.findComponent('toolboxNotesCustomKind', TextField);
if (toolboxNotesCustomKind == null) throw 'ChartEditorToolboxHandler.buildToolboxNoteDataLayout() - Could not find toolboxNotesCustomKind component.';
toolboxNotesNoteKind.onChange = function(event:UIEvent) {
var isCustom:Bool = (event.data.id == '~CUSTOM~');
if (isCustom)
{
toolboxNotesCustomKindLabel.hidden = false;
toolboxNotesCustomKind.hidden = false;
state.noteKindToPlace = toolboxNotesCustomKind.text;
}
else
{
toolboxNotesCustomKindLabel.hidden = true;
toolboxNotesCustomKind.hidden = true;
state.noteKindToPlace = event.data.id;
}
}
toolboxNotesCustomKind.onChange = function(event:UIEvent) {
state.noteKindToPlace = toolboxNotesCustomKind.text;
}
return toolbox;
}
static function onShowToolboxNoteData(state:ChartEditorState, toolbox:CollapsibleDialog):Void {}
static function onHideToolboxNoteData(state:ChartEditorState, toolbox:CollapsibleDialog):Void {}
static function onHideToolboxEventData(state:ChartEditorState, toolbox:CollapsibleDialog):Void {}
static function onShowToolboxPlaytestProperties(state:ChartEditorState, toolbox:CollapsibleDialog):Void {}
static function onHideToolboxPlaytestProperties(state:ChartEditorState, toolbox:CollapsibleDialog):Void {}

View File

@ -0,0 +1,115 @@
package funkin.ui.debug.charting.toolboxes;
import haxe.ui.components.DropDown;
import haxe.ui.components.TextField;
import haxe.ui.events.UIEvent;
import funkin.ui.debug.charting.util.ChartEditorDropdowns;
/**
* The toolbox which allows modifying information like Note Kind.
*/
@:access(funkin.ui.debug.charting.ChartEditorState)
@:build(haxe.ui.ComponentBuilder.build("assets/exclude/data/ui/chart-editor/toolboxes/note-data.xml"))
class ChartEditorNoteDataToolbox extends ChartEditorBaseToolbox
{
var toolboxNotesNoteKind:DropDown;
var toolboxNotesCustomKind:TextField;
var _initializing:Bool = true;
public function new(chartEditorState2:ChartEditorState)
{
super(chartEditorState2);
initialize();
this.onDialogClosed = onClose;
this._initializing = false;
}
function onClose(event:UIEvent)
{
chartEditorState.menubarItemToggleToolboxNoteData.selected = false;
}
function initialize():Void
{
toolboxNotesNoteKind.onChange = function(event:UIEvent) {
var noteKind:Null<String> = event?.data?.id ?? null;
if (noteKind == '') noteKind = null;
trace('ChartEditorToolboxHandler.buildToolboxNoteDataLayout() - Note kind changed: $noteKind');
// Edit the note data to place.
if (noteKind == '~CUSTOM~')
{
showCustom();
toolboxNotesCustomKind.value = chartEditorState.noteKindToPlace;
}
else
{
hideCustom();
chartEditorState.noteKindToPlace = noteKind;
toolboxNotesCustomKind.value = chartEditorState.noteKindToPlace;
}
if (!_initializing && chartEditorState.currentNoteSelection.length > 0)
{
// Edit the note data of any selected notes.
for (note in chartEditorState.currentNoteSelection)
{
note.kind = chartEditorState.noteKindToPlace;
}
chartEditorState.saveDataDirty = true;
chartEditorState.noteDisplayDirty = true;
chartEditorState.notePreviewDirty = true;
}
};
var startingValueNoteKind = ChartEditorDropdowns.populateDropdownWithNoteKinds(toolboxNotesNoteKind, '');
toolboxNotesNoteKind.value = startingValueNoteKind;
toolboxNotesCustomKind.onChange = function(event:UIEvent) {
var customKind:Null<String> = event?.target?.text;
chartEditorState.noteKindToPlace = customKind;
if (chartEditorState.currentEventSelection.length > 0)
{
// Edit the note data of any selected notes.
for (note in chartEditorState.currentNoteSelection)
{
note.kind = chartEditorState.noteKindToPlace;
}
chartEditorState.saveDataDirty = true;
chartEditorState.noteDisplayDirty = true;
chartEditorState.notePreviewDirty = true;
}
};
toolboxNotesCustomKind.value = chartEditorState.noteKindToPlace;
}
public override function refresh():Void
{
super.refresh();
toolboxNotesNoteKind.value = ChartEditorDropdowns.lookupNoteKind(chartEditorState.noteKindToPlace);
toolboxNotesCustomKind.value = chartEditorState.noteKindToPlace;
}
function showCustom():Void
{
toolboxNotesCustomKindLabel.hidden = false;
toolboxNotesCustomKind.hidden = false;
}
function hideCustom():Void
{
toolboxNotesCustomKindLabel.hidden = true;
toolboxNotesCustomKind.hidden = true;
}
public static function build(chartEditorState:ChartEditorState):ChartEditorNoteDataToolbox
{
return new ChartEditorNoteDataToolbox(chartEditorState);
}
}

View File

@ -108,6 +108,55 @@ class ChartEditorDropdowns
return returnValue;
}
static final NOTE_KINDS:Map<String, String> = [
// Base
"" => "Default",
"~CUSTOM~" => "Custom",
// Weeks 1-7
"mom" => "Mom Sings (Week 5)",
"ugh" => "Ugh (Week 7)",
"hehPrettyGood" => "Heh, Pretty Good (Week 7)",
// Weekend 1
"weekend-1-lightcan" => "Light Can (2hot)",
"weekend-1-kickcan" => "Kick Can (2hot)",
"weekend-1-kneecan" => "Knee Can (2hot)",
"weekend-1-cockgun" => "Cock Gun (2hot)",
"weekend-1-firegun" => "Fire Gun (2hot)",
"weekend-1-punchlow" => "Punch Low (Blazin)",
"weekend-1-punchhigh" => "Punch High (Blazin)",
"weekend-1-punchlowblocked" => "Punch Low Blocked (Blazin)",
"weekend-1-punchhighblocked" => "Punch High Blocked (Blazin)",
"weekend-1-dodgelow" => "Dodge Low (Blazin)",
"weekend-1-blockhigh" => "Block High (Blazin)",
"weekend-1-fakeout" => "Fakeout (Blazin)",
];
public static function populateDropdownWithNoteKinds(dropDown:DropDown, startingKindId:String):DropDownEntry
{
dropDown.dataSource.clear();
var returnValue:DropDownEntry = lookupNoteKind('~CUSTOM');
for (noteKindId in NOTE_KINDS.keys())
{
var noteKind:String = NOTE_KINDS.get(noteKindId) ?? 'Default';
var value:DropDownEntry = {id: noteKindId, text: noteKind};
if (startingKindId == noteKindId) returnValue = value;
dropDown.dataSource.add(value);
}
return returnValue;
}
public static function lookupNoteKind(noteKindId:Null<String>):DropDownEntry
{
if (noteKindId == null) return lookupNoteKind('');
if (!NOTE_KINDS.exists(noteKindId)) return {id: '~CUSTOM~', text: 'Custom'};
return {id: noteKindId ?? '', text: NOTE_KINDS.get(noteKindId) ?? 'Default'};
}
/**
* Populate a dropdown with a list of song variations.
*/