Explorar o código

Screen Fade Update

An update to the library item Screen Fade which supports swapping dialogs.
Peter Robinson hai 9 meses
pai
achega
751c7308f0

+ 1 - 1
library/ScreenFade/module.taml

@@ -1,7 +1,7 @@
 <ModuleDefinition
 	ModuleId="ScreenFade"
 	VersionId="1"
-	BuildID="5"
+	BuildID="6"
 	Synchronized="1"
 	Description="Switches the Canvas with a quick screen fade. Can be used for a temporary background for dialogs or windows."
 	Author="Torque2D"

+ 2 - 1
library/ScreenFade/screenFade.cs

@@ -49,7 +49,8 @@ function ScreenFade::swapCanvas(%this, %content, %color, %time)
 
 //Fades the screen to color and then puts the dialog on top of it.
 //Color and time are optional.
-//When your dialog closes, call %this.post("dialogClose"); to inform ScreenFade where %this is the same object passed to openDialog().
+//When your dialog closes, call %this.postEvent("dialogClose"); to inform ScreenFade where %this is the same object passed to openDialog().
+//Or call %this.postEvent("dialogSwap", %dialog); to swap the dialog for another. Then the new dialog will have to post "dialogClose" when it closes.
 //ScreenFade will post events: onOpenComplete() and onCloseComplete().
 function ScreenFade::openDialog(%this, %dialog, %color, %time)
 {

+ 19 - 0
library/ScreenFade/scripts/ScreenFadeBackground.cs

@@ -11,6 +11,7 @@ function ScreenFadeBackground::resetColor(%this)
 function ScreenFadeBackground::startSwap(%this)
 {
 	%this.resetColor();
+	%this.clear();
 	Canvas.pushDialog(%this);
 	%this.fadeTo(%this.solidColor, %this.swapTime, "EaseInOut");
 	%this.schedule(%this.swapTime, "doSwap");
@@ -58,11 +59,29 @@ function ScreenFadeBackground::onDialogClose(%this)
 		{
 			cancel(%this.hideSchedule);
 		}
+		%this.clear();
 		%this.fadeTo(%this.transparentColor, %this.dialogTime, "EaseIn");
 		%this.hideSchedule = %this.schedule(%this.dialogTime, "onCloseComplete");
 	}
 }
 
+function ScreenFadeBackground::onDialogSwap(%this, %dialog)
+{
+	if(%this.isAwake() && isObject(%this.dialog))
+	{
+		if(isEventPending(%this.hideSchedule))
+		{
+			cancel(%this.hideSchedule);
+		}
+		%this.setImageColor(%this.solidColor);
+		%this.stopListening(%this.dialog);
+		%this.removeIfMember(%this.dialog);
+		%this.dialog = %dialog;
+		%this.add(%this.dialog);
+		%this.startListening(%this.dialog);
+	}
+}
+
 function ScreenFadeBackground::onCloseComplete(%this)
 {
 	if(isObject(%this.dialog))