1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-04 13:54:22 +00:00

Editor: Added ability to set units for event properties. Fixed bug where event icon tooltip wouldn't show an enum text value correctly.

This commit is contained in:
Jenny Crowe 2024-01-24 20:31:25 -07:00
parent 583eb81de5
commit e111e91a9c
3 changed files with 39 additions and 8 deletions

View file

@ -6,7 +6,7 @@ import funkin.data.song.SongData.SongEventData;
import funkin.util.macro.ClassMacro;
import funkin.play.event.ScriptedSongEvent;
@:forward(name, tittlte, type, keys, min, max, step, defaultValue, iterator)
@:forward(name, title, type, keys, min, max, step, units, defaultValue, iterator)
abstract SongEventSchema(SongEventSchemaRaw)
{
public function new(?fields:Array<SongEventSchemaField>)
@ -42,7 +42,7 @@ abstract SongEventSchema(SongEventSchemaRaw)
return this[k] = v;
}
public function stringifyFieldValue(name:String, value:Dynamic):String
public function stringifyFieldValue(name:String, value:Dynamic, addUnits:Bool = true):String
{
var field:SongEventSchemaField = getByName(name);
if (field == null) return 'Unknown';
@ -52,21 +52,34 @@ abstract SongEventSchema(SongEventSchemaRaw)
case SongEventFieldType.STRING:
return Std.string(value);
case SongEventFieldType.INTEGER:
return Std.string(value);
var returnValue:String = Std.string(value);
if (addUnits) return addUnitsToString(returnValue, field);
return returnValue;
case SongEventFieldType.FLOAT:
return Std.string(value);
var returnValue:String = Std.string(value);
if (addUnits) return addUnitsToString(returnValue, field);
return returnValue;
case SongEventFieldType.BOOL:
return Std.string(value);
case SongEventFieldType.ENUM:
var valueString:String = Std.string(value);
for (key in field.keys.keys())
{
if (field.keys.get(key) == value) return key;
// Comparing these values as strings because comparing Dynamic variables is jank.
if (Std.string(field.keys.get(key)) == valueString) return key;
}
return Std.string(value);
return valueString;
default:
return 'Unknown';
}
}
function addUnitsToString(value:String, field:SongEventSchemaField)
{
if (field.units == null || field.units == '') return value;
return value + ' ${field.units}';
}
}
typedef SongEventSchemaRaw = Array<SongEventSchemaField>;
@ -115,6 +128,12 @@ typedef SongEventSchemaField =
*/
?step:Float,
/**
* Used for INTEGER and FLOAT values.
* The units that the value is expressed in (pixels, percent, etc).
*/
?units:String,
/**
* An optional default value for the field.
*/

View file

@ -135,10 +135,10 @@ class FocusCameraSongEvent extends SongEvent
return new SongEventSchema([
{
name: "char",
title: "Character",
title: "Target",
defaultValue: 0,
type: SongEventFieldType.ENUM,
keys: ["Position" => -1, "Boyfriend" => 0, "Dad" => 1, "Girlfriend" => 2]
keys: ["Position" => -1, "Player" => 0, "Opponent" => 1, "Girlfriend" => 2]
},
{
name: "x",
@ -146,6 +146,7 @@ class FocusCameraSongEvent extends SongEvent
defaultValue: 0,
step: 10.0,
type: SongEventFieldType.FLOAT,
units: "px",
},
{
name: "y",
@ -153,6 +154,7 @@ class FocusCameraSongEvent extends SongEvent
defaultValue: 0,
step: 10.0,
type: SongEventFieldType.FLOAT,
units: "px",
}
]);
}

View file

@ -216,6 +216,16 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox
target.addComponent(input);
if (field.units != null && field.units != "")
{
var units:Label = new Label();
units.text = field.units;
units.verticalAlign = "center";
units.left = 85;
units.top = 4;
input.addComponent(units);
}
// Update the value of the event data.
input.onChange = function(event:UIEvent) {
var value = event.target.value;