1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-27 07:27:12 +00:00
Funkin/source/funkin/ui/debug/charting/dialogs/ChartEditorBaseDialog.hx

116 lines
2.5 KiB
Haxe
Raw Normal View History

2023-11-24 05:41:38 +00:00
package funkin.ui.debug.charting.dialogs;
import haxe.ui.containers.dialogs.Dialog;
import haxe.ui.containers.dialogs.Dialog.DialogEvent;
import haxe.ui.animation.AnimationBuilder;
import haxe.ui.styles.EasingFunction;
2023-11-24 05:41:38 +00:00
import haxe.ui.core.Component;
// @:nullSafety // TODO: Fix null safety when used with HaxeUI build macros.
2023-11-24 05:41:38 +00:00
@:access(funkin.ui.debug.charting.ChartEditorState)
class ChartEditorBaseDialog extends Dialog
{
2023-12-16 02:09:01 +00:00
var chartEditorState:ChartEditorState;
2023-11-24 05:41:38 +00:00
var params:DialogParams;
var locked:Bool = false;
2023-12-16 02:09:01 +00:00
public function new(chartEditorState:ChartEditorState, params:DialogParams)
2023-11-24 05:41:38 +00:00
{
super();
2023-12-16 02:09:01 +00:00
this.chartEditorState = chartEditorState;
2023-11-24 05:41:38 +00:00
this.params = params;
this.destroyOnClose = true;
this.closable = params.closable ?? false;
this.onDialogClosed = event -> onClose(event);
}
2023-12-13 23:24:55 +00:00
public override function showDialog(modal:Bool = true):Void
{
super.showDialog(modal);
fadeInComponent(this, 1);
}
private override function onReady():Void
{
_overlay.opacity = 0;
fadeInDialogOverlay();
}
2023-11-24 05:41:38 +00:00
/**
* Called when the dialog is closed.
* Override this to add custom behavior.
*/
public function onClose(event:DialogEvent):Void
{
2023-12-16 02:09:01 +00:00
chartEditorState.isHaxeUIDialogOpen = false;
2023-11-24 05:41:38 +00:00
}
/**
* Locks this dialog from interaction.
* Use this when you want to prevent dialog interaction while another dialog is open.
*/
public function lock():Void
{
this.locked = true;
this.closable = false;
}
/**
* Unlocks the dialog for interaction.
*/
public function unlock():Void
{
this.locked = false;
this.closable = params.closable ?? false;
}
2023-12-13 23:24:55 +00:00
static final OVERLAY_EASE_DURATION:Float = 0.2;
static final OVERLAY_EASE_TYPE:String = "easeOut";
function fadeInDialogOverlay():Void
{
if (!modal)
{
trace('Dialog is not modal, skipping overlay fade...');
return;
}
if (_overlay == null)
{
trace('[WARN] Dialog overlay is null, skipping overlay fade...');
return;
}
2023-12-13 23:24:55 +00:00
fadeInComponent(_overlay, 0.5);
}
function fadeInComponent(component:Component, fadeTo:Float = 1):Void
{
var builder = new AnimationBuilder(component, OVERLAY_EASE_DURATION, OVERLAY_EASE_TYPE);
builder.setPosition(0, "opacity", 0, true); // 0% absolute
2023-12-13 23:24:55 +00:00
builder.setPosition(100, "opacity", fadeTo, true);
2023-12-13 23:24:55 +00:00
trace('Fading in dialog component...');
builder.play();
}
2023-11-24 05:41:38 +00:00
}
typedef DialogParams =
{
?closable:Bool,
?modal:Bool
};
typedef DialogDropTarget =
{
component:Component,
handler:String->Void
}