screenFade.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.post("dialogClose"); to inform ScreenFade where %this is the same object passed to openDialog().
  47. //ScreenFade will post events: onOpenComplete() and onCloseComplete().
  48. function ScreenFade::openDialog(%this, %dialog, %color, %time)
  49. {
  50. if(%color $= "")
  51. {
  52. %color = "0 0 0 230";
  53. }
  54. if(%time $= "")
  55. {
  56. %time = 300;
  57. }
  58. %this.background.solidColor = %color;
  59. %this.background.transparentColor = getWord(%color, 0) SPC getWord(%color, 1) SPC getWord(%color, 2) SPC "0";
  60. %this.background.dialog = %dialog;
  61. %this.background.dialogTime = %time;
  62. %this.background.openDialog();
  63. }