From 7231b3f6450fff10509c51fdaa5d7228582cbf6b Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Thu, 6 Mar 2025 23:57:05 -0500 Subject: [PATCH] New chart event: Set the character's health icon. --- source/funkin/play/PlayState.hx | 4 + .../play/event/SetCharacterSongEvent.hx | 3 + .../play/event/SetHealthIconSongEvent.hx | 117 ++++++++++++++++++ source/funkin/play/event/SetStageSongEvent.hx | 3 + .../toolboxes/ChartEditorEventDataToolbox.hx | 23 ++-- 5 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 source/funkin/play/event/SetCharacterSongEvent.hx create mode 100644 source/funkin/play/event/SetHealthIconSongEvent.hx create mode 100644 source/funkin/play/event/SetStageSongEvent.hx diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 7090bdc67..9a07487cb 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -889,6 +889,10 @@ class PlayState extends MusicBeatSubState Highscore.tallies.combo = 0; Countdown.performCountdown(); + // Reset the health icons. + currentStage.getBoyfriend().initHealthIcon(false); + currentStage.getDad().initHealthIcon(true); + needsReset = false; } diff --git a/source/funkin/play/event/SetCharacterSongEvent.hx b/source/funkin/play/event/SetCharacterSongEvent.hx new file mode 100644 index 000000000..ec7ae7fe2 --- /dev/null +++ b/source/funkin/play/event/SetCharacterSongEvent.hx @@ -0,0 +1,3 @@ +package funkin.play.event; + +// TODO: Add a song event which switches characters. diff --git a/source/funkin/play/event/SetHealthIconSongEvent.hx b/source/funkin/play/event/SetHealthIconSongEvent.hx new file mode 100644 index 000000000..bce0253dd --- /dev/null +++ b/source/funkin/play/event/SetHealthIconSongEvent.hx @@ -0,0 +1,117 @@ +package funkin.play.event; + +import funkin.data.event.SongEventSchema; +import funkin.play.character.CharacterData.HealthIconData; +import funkin.data.song.SongData; +import funkin.data.song.SongData.SongEventData; + +/** + * This class represents a handler for scroll speed events. + * + * Example: Set the health icon of Boyfriend to "bf-pixel": + * ``` + * { + * 'e': 'SetHealthIcon', + * "v": { + * "char": 0, + * "id": "bf-pixel", + * "scale": 1.0, + * "flipX": false, + * "isPixel": false, + * "offsetX": 0.0, + * "offsetY": 0.0 + * } + * } + * ``` + */ +class SetHealthIconSongEvent extends SongEvent +{ + public function new() + { + super('SetHealthIcon'); + } + + public override function handleEvent(data:SongEventData):Void + { + // Does nothing if there is no PlayState. + if (PlayState.instance == null) return; + + // Works even if we are minimal mode. + // if (PlayState.instance.isMinimalMode) return; + + var offsets:Array = [data.value.offsetX ?? 0.0, data.value.offsetY ?? 0.0]; + + var healthIconData:HealthIconData = + { + id: data.value.id ?? "bf", + scale: data.value.scale ?? 1.0, + flipX: data.value.flipX ?? false, + isPixel: data.value.isPixel ?? false, + offsets: offsets, + }; + + switch (data?.value?.char ?? 0) + { + case 0: + PlayState.instance.iconP1.configure(healthIconData); + case 1: + PlayState.instance.iconP2.configure(healthIconData); + default: + trace('[WARN] Unknown character index: ' + data.value.char); + } + } + + public override function getTitle():String + { + return 'Set Health Icon'; + } + + public override function getEventSchema():SongEventSchema + { + return new SongEventSchema([ + { + name: 'char', + title: 'Character', + defaultValue: 0, + type: SongEventFieldType.ENUM, + keys: ['Player' => 0, 'Opponent' => 1], + }, + { + name: 'id', + title: 'Health Icon ID', + defaultValue: 'bf', + type: SongEventFieldType.STRING, + }, + { + name: 'scale', + title: 'Scale', + defaultValue: 1.0, + type: SongEventFieldType.FLOAT, + }, + { + name: 'flipX', + title: 'Flip X?', + defaultValue: false, + type: SongEventFieldType.BOOL, + }, + { + name: 'isPixel', + title: 'Is Pixel?', + defaultValue: false, + type: SongEventFieldType.BOOL, + }, + { + name: 'offsetX', + title: 'X Offset', + defaultValue: 0, + type: SongEventFieldType.FLOAT, + }, + { + name: 'offsetY', + title: 'Y Offset', + defaultValue: 0, + type: SongEventFieldType.FLOAT, + } + ]); + } +} diff --git a/source/funkin/play/event/SetStageSongEvent.hx b/source/funkin/play/event/SetStageSongEvent.hx new file mode 100644 index 000000000..9536c5416 --- /dev/null +++ b/source/funkin/play/event/SetStageSongEvent.hx @@ -0,0 +1,3 @@ +package funkin.play.event; + +// TODO: Add a song event which switches stages. diff --git a/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx b/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx index 852b78dc7..c2cfa92c9 100644 --- a/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx +++ b/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx @@ -49,9 +49,14 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox function initialize():Void { toolboxEventsEventKind.onChange = function(event:UIEvent) { + if (event.data == null) + { + trace('ChartEditorEventDataToolbox: Event data is null'); + } + var eventType:String = event.data.id; - trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event type changed: $eventType'); + trace('ChartEditorEventDataToolbox - Event type changed: $eventType'); // Edit the event data to place. chartEditorState.eventKindToPlace = eventType; @@ -60,7 +65,7 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox if (schema == null) { - trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Unknown event kind: $eventType'); + trace('ChartEditorEventDataToolbox - Unknown event kind: $eventType'); return; } @@ -80,7 +85,7 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox } } var startingEventValue = ChartEditorDropdowns.populateDropdownWithSongEvents(toolboxEventsEventKind, chartEditorState.eventKindToPlace); - trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Starting event kind: ${startingEventValue}'); + trace('ChartEditorEventDataToolbox - Starting event kind: ${startingEventValue}'); toolboxEventsEventKind.value = startingEventValue; } @@ -92,7 +97,7 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox if (newDropdownElement == null) { - throw 'ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event kind not in dropdown: ${chartEditorState.eventKindToPlace}'; + throw 'ChartEditorEventDataToolbox - Event kind not in dropdown: ${chartEditorState.eventKindToPlace}'; } else if (toolboxEventsEventKind.value != newDropdownElement || lastEventKind != toolboxEventsEventKind.value.id) { @@ -101,17 +106,17 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox var schema:SongEventSchema = SongEventRegistry.getEventSchema(chartEditorState.eventKindToPlace); if (schema == null) { - trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Unknown event kind: ${chartEditorState.eventKindToPlace}'); + trace('ChartEditorEventDataToolbox - Unknown event kind: ${chartEditorState.eventKindToPlace}'); } else { - trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event kind changed: ${toolboxEventsEventKind.value.id} != ${newDropdownElement.id} != ${lastEventKind}, rebuilding form'); + trace('ChartEditorEventDataToolbox - Event kind changed: ${toolboxEventsEventKind.value.id} != ${newDropdownElement.id} != ${lastEventKind}, rebuilding form'); buildEventDataFormFromSchema(toolboxEventsDataGrid, schema, chartEditorState.eventKindToPlace); } } else { - trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event kind not changed: ${toolboxEventsEventKind.value} == ${newDropdownElement} == ${lastEventKind}'); + trace('ChartEditorEventDataToolbox - Event kind not changed: ${toolboxEventsEventKind.value} == ${newDropdownElement} == ${lastEventKind}'); } for (pair in chartEditorState.eventDataToPlace.keyValueIterator()) @@ -123,7 +128,7 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox if (field == null) { - throw 'ChartEditorToolboxHandler.refresh() - Field "${fieldId}" does not exist in the event data form for kind ${lastEventKind}.'; + throw 'ChartEditorEventDataToolbox - Field "${fieldId}" does not exist in the event data form for kind ${lastEventKind}.'; } else { @@ -142,7 +147,7 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox var textField:TextField = cast field; textField.text = value; default: - throw 'ChartEditorToolboxHandler.refresh() - Field "${fieldId}" is of unknown type "${Type.getClassName(Type.getClass(field))}".'; + throw 'ChartEditorEventDataToolbox - Field "${fieldId}" is of unknown type "${Type.getClassName(Type.getClass(field))}".'; } } }