screenFade.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. function ScreenFade::create(%this)
  2. {
  3. exec("./scripts/ScreenFadeBackground.cs");
  4. %this.background = new GuiSpriteCtrl() {
  5. class = "ScreenFadeBackground";
  6. profile = "GuiDefaultProfile";
  7. HorizSizing = "relative";
  8. VertSizing = "relative";
  9. Position = "0 0";
  10. Image = "ScreenFade:background";
  11. FullSize = 1;
  12. ConstrainProportions = 0;
  13. ImageColor = "255 255 255 0";
  14. Owner = %this;
  15. };
  16. }
  17. function ScreenFade::destroy(%this)
  18. {
  19. if(isObject(%this.background))
  20. {
  21. %this.background.delete();
  22. }
  23. }
  24. //Switches the canvas by fading in to color and back out to the new content. The process takes the given time in milliseconds.
  25. //Color and time are optional.
  26. //ScreenFade will post event: onSwapComplete().
  27. function ScreenFade::swapCanvas(%this, %content, %color, %time)
  28. {
  29. if(%color $= "")
  30. {
  31. %color = "0 0 0 0";
  32. }
  33. if(%time $= "")
  34. {
  35. %time = 1400;
  36. }
  37. %base = getWord(%color, 0) SPC getWord(%color, 1) SPC getWord(%color, 2);
  38. %this.background.solidColor = %base SPC "255";
  39. %this.background.transparentColor = %base SPC "0";
  40. %this.background.swapContent = %content;
  41. %this.background.swapTime = mRound((%time / 5) * 2);
  42. %this.background.startSwap();
  43. }
  44. //Fades the screen to color and then puts the dialog on top of it.
  45. //Color and time are optional.
  46. //When your dialog closes, call %this.postEvent("dialogClose"); to inform ScreenFade where %this is the same object passed to openDialog().
  47. //Or call %this.postEvent("dialogSwap", %dialog); to swap the dialog for another. Then the new dialog will have to post "dialogClose" when it closes.
  48. //ScreenFade will post events: onOpenComplete() and onCloseComplete().
  49. function ScreenFade::openDialog(%this, %dialog, %color, %time)
  50. {
  51. if(%color $= "")
  52. {
  53. %color = "0 0 0 230";
  54. }
  55. if(%time $= "")
  56. {
  57. %time = 300;
  58. }
  59. %this.background.solidColor = %color;
  60. %this.background.transparentColor = getWord(%color, 0) SPC getWord(%color, 1) SPC getWord(%color, 2) SPC "0";
  61. %this.background.dialog = %dialog;
  62. %this.background.dialogTime = %time;
  63. %this.background.openDialog();
  64. }