1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-10 08:44:47 +00:00
Funkin/source/funkin/ui/debug/charting/dialogs/ChartEditorBaseDialog.hx

105 lines
2.2 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
{
var state:ChartEditorState;
var params:DialogParams;
var locked:Bool = false;
public function new(state:ChartEditorState, params:DialogParams)
{
super();
this.state = state;
this.params = params;
this.destroyOnClose = true;
this.closable = params.closable ?? false;
this.onDialogClosed = event -> onClose(event);
}
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
{
state.isHaxeUIDialogOpen = false;
}
/**
* 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;
}
static final OVERLAY_EASE_DURATION:Float = 5.0;
static final OVERLAY_EASE_TYPE:String = "linear";
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;
}
var builder = new AnimationBuilder(_overlay, OVERLAY_EASE_DURATION, "linear");
builder.setPosition(0, "opacity", 0, true); // 0% absolute
builder.setPosition(100, "opacity", 0.80, true);
trace('Fading in dialog overlay...');
builder.play();
}
2023-11-24 05:41:38 +00:00
}
typedef DialogParams =
{
?closable:Bool,
?modal:Bool
};
typedef DialogDropTarget =
{
component:Component,
handler:String->Void
}