1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2025-05-24 16:11:12 +00:00

[ENHANCEMENT] Add Script Events for losing/gaining focus (#3721)

* add events for focus gain/lost

* add callbacks

* move the events to a new interface

* Ok NOW it works

* the event can now longer be canceled
This commit is contained in:
Abnormal 2025-01-17 01:25:19 +00:00 committed by GitHub
parent 2b7f62edd3
commit 4b127b6413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 71 additions and 0 deletions

View file

@ -37,6 +37,9 @@ interface IStateChangingScriptedClass extends IScriptedClass
public function onSubStateOpenEnd(event:SubStateScriptEvent):Void;
public function onSubStateCloseBegin(event:SubStateScriptEvent):Void;
public function onSubStateCloseEnd(event:SubStateScriptEvent):Void;
public function onFocusLost(event:FocusScriptEvent):Void;
public function onFocusGained(event:FocusScriptEvent):Void;
}
/**

View file

@ -436,6 +436,22 @@ class StateChangeScriptEvent extends ScriptEvent
}
}
/**
* An event that is fired when the game loses or gains focus.
*/
class FocusScriptEvent extends ScriptEvent
{
public function new(type:ScriptEventType):Void
{
super(type, false);
}
public override function toString():String
{
return 'FocusScriptEvent(type=' + type + ')';
}
}
/**
* An event that is fired when moving out of or into an FlxSubState.
*/

View file

@ -177,6 +177,12 @@ class ScriptEventDispatcher
case SUBSTATE_CLOSE_END:
t.onSubStateCloseEnd(cast event);
return;
case FOCUS_LOST:
t.onFocusLost(cast event);
return;
case FOCUS_GAINED:
t.onFocusGained(cast event);
return;
default: // Continue;
}
}

View file

@ -223,6 +223,20 @@ enum abstract ScriptEventType(String) from String to String
*/
var SUBSTATE_CLOSE_END = 'SUBSTATE_CLOSE_END';
/**
* Called when the game regains focus.
*
* This event is not cancelable.
*/
var FOCUS_GAINED = 'FOCUS_GAINED';
/**
* Called when the game loses focus.
*
* This event is not cancelable.
*/
var FOCUS_LOST = 'FOCUS_LOST';
/**
* Called when the game starts a conversation.
*

View file

@ -109,6 +109,10 @@ class Module implements IPlayStateScriptedClass implements IStateChangingScripte
public function onStateChangeEnd(event:StateChangeScriptEvent) {}
public function onFocusGained(event:FocusScriptEvent) {}
public function onFocusLost(event:FocusScriptEvent) {}
public function onSubStateOpenBegin(event:SubStateScriptEvent) {}
public function onSubStateOpenEnd(event:SubStateScriptEvent) {}

View file

@ -87,6 +87,20 @@ class MusicBeatState extends FlxTransitionableState implements IEventHandler
dispatchEvent(new UpdateScriptEvent(elapsed));
}
override function onFocus():Void
{
super.onFocus();
dispatchEvent(new FocusScriptEvent(FOCUS_GAINED));
}
override function onFocusLost():Void
{
super.onFocusLost();
dispatchEvent(new FocusScriptEvent(FOCUS_LOST));
}
function createWatermarkText()
{
// Both have an xPos of 0, but a width equal to the full screen.

View file

@ -89,6 +89,20 @@ class MusicBeatSubState extends FlxSubState implements IEventHandler
dispatchEvent(new UpdateScriptEvent(elapsed));
}
override function onFocus():Void
{
super.onFocus();
dispatchEvent(new FocusScriptEvent(FOCUS_GAINED));
}
override function onFocusLost():Void
{
super.onFocusLost();
dispatchEvent(new FocusScriptEvent(FOCUS_LOST));
}
public function initConsoleHelpers():Void {}
function reloadAssets()