effects.d 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. module ui.effects;
  2. import raylib;
  3. import std.stdio;
  4. import variables;
  5. import std.string;
  6. import system.abstraction;
  7. import std.file;
  8. int screenWidth;
  9. int screenHeight;
  10. Texture2D[] loadAnimationFramesUI(const string fileDir, const string animationFileName)
  11. {
  12. screenWidth = systemSettings.defaultScreenWidth;
  13. screenHeight = systemSettings.defaultScreenHeight;
  14. Texture2D[] frames;
  15. uint frameIndex = 1;
  16. while (true)
  17. {
  18. string frameFileName = format("%s-%03d.png", animationFileName, frameIndex);
  19. if (std.file.exists(fileDir~"/"~frameFileName) == false) break;
  20. debug debugWriteln(frameFileName);
  21. Texture2D texture = LoadTexture((fileDir~"/"~frameFileName).toStringz());
  22. frames ~= texture;
  23. debug debugWriteln("Loaded frame for UI ", frameIndex, " - ", frameFileName);
  24. frameIndex++;
  25. }
  26. debug debugWriteln("Frames for ui animations length: ", frames.length);
  27. return frames;
  28. }
  29. void playUIAnimation(Texture2D[] frames)
  30. {
  31. static float frameTime = 0.0f;
  32. if (playAnimation) {
  33. frameTime += GetFrameTime();
  34. while (frameTime >= frameDuration && frameDuration > 0) {
  35. frameTime -= frameDuration;
  36. currentFrame = cast(int)((currentFrame + 1) % frames.length);
  37. }
  38. int frameWidth = frames[currentFrame].width;
  39. int frameHeight = frames[currentFrame].height;
  40. DrawTexturePro(
  41. frames[currentFrame],
  42. Rectangle(0, 0, frameWidth, frameHeight),
  43. Rectangle(0, 0, screenWidth, screenHeight),
  44. Vector2(0, 0),
  45. 0,
  46. Color(255, 255, 255, 127)
  47. );
  48. } else {
  49. frameTime = 0.0f;
  50. currentFrame = 0;
  51. }
  52. }
  53. void fadeEffect(float alpha, bool fadeIn, void delegate(float alpha) renderer)
  54. {
  55. const float FadeIncrement = 0.02f;
  56. while (fadeIn ? alpha < 2.0f : alpha > 0.0f)
  57. {
  58. alpha += fadeIn ? FadeIncrement : -FadeIncrement;
  59. BeginDrawing();
  60. ClearBackground(Colors.BLACK);
  61. renderer(alpha);
  62. EndDrawing();
  63. }
  64. }
  65. void renderText(float alpha, immutable(char)* text)
  66. {
  67. DrawTextEx(textFont, text,
  68. Vector2(GetScreenWidth() / 2 - MeasureText(text, 40) / 2,
  69. GetScreenHeight() / 2), 40, 0, Fade(Colors.WHITE, alpha)
  70. );
  71. }
  72. void helloScreen()
  73. {
  74. debug
  75. {
  76. bool play = false;
  77. debugWriteln("hello screen showing");
  78. if (play == false) {
  79. videoFinished = true;
  80. }
  81. } else {
  82. fadeEffect(0.0f, true, (float alpha) {
  83. renderText(alpha, "powered by\n\nHimmel Engine");
  84. });
  85. fadeEffect(2.0f, false, (float alpha) {
  86. renderText(alpha, "powered by\n\nHimmel Engine");
  87. });
  88. /*
  89. fadeEffect(0.0f, true, (float alpha) {
  90. renderLogo(alpha, "atlus_logo.png".toStringz, true);
  91. });
  92. fadeEffect(fadeAlpha, false, (float alpha) {
  93. renderLogo(alpha, "atlus_logo.png".toStringz, true);
  94. });
  95. */
  96. // Play Opening Video
  97. }
  98. }