menu.d 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. module ui.menu;
  2. import raylib;
  3. import variables;
  4. import std.stdio;
  5. import system.abstraction;
  6. import system.config;
  7. import core.time;
  8. import core.thread;
  9. import std.string;
  10. import graphics.engine;
  11. import graphics.playback;
  12. import std.file;
  13. import scripts.lua;
  14. import std.conv;
  15. import graphics.gamelogic;
  16. import system.cleanup;
  17. void fadeEffect(float alpha, bool fadeIn, void delegate(float alpha) renderer)
  18. {
  19. const float FadeIncrement = 0.02f;
  20. while (fadeIn ? alpha < 2.0f : alpha > 0.0f)
  21. {
  22. alpha += fadeIn ? FadeIncrement : -FadeIncrement;
  23. BeginDrawing();
  24. ClearBackground(Colors.BLACK);
  25. renderer(alpha);
  26. EndDrawing();
  27. }
  28. }
  29. void renderText(float alpha, immutable(char)* text)
  30. {
  31. DrawTextEx(textFont, text,
  32. Vector2(GetScreenWidth() / 2 - MeasureText(text, 40) / 2,
  33. GetScreenHeight() / 2), 40, 0, Fade(Colors.WHITE, alpha)
  34. );
  35. }
  36. void helloScreen()
  37. {
  38. debug
  39. {
  40. bool play = false;
  41. debugWriteln("hello screen showing");
  42. if (play == false) {
  43. videoFinished = true;
  44. }
  45. } else {
  46. fadeEffect(0.0f, true, (float alpha) {
  47. renderText(alpha, "powered by\n\nHimmel Engine");
  48. });
  49. fadeEffect(2.0f, false, (float alpha) {
  50. renderText(alpha, "powered by\n\nHimmel Engine");
  51. });
  52. /*
  53. fadeEffect(0.0f, true, (float alpha) {
  54. renderLogo(alpha, "atlus_logo.png".toStringz, true);
  55. });
  56. fadeEffect(fadeAlpha, false, (float alpha) {
  57. renderLogo(alpha, "atlus_logo.png".toStringz, true);
  58. });
  59. */
  60. // Play Opening Video
  61. }
  62. }
  63. int showMainMenu() {
  64. int luaExecutionCode = luaInit("scripts/menu.lua");
  65. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  66. writeln("[ERROR] Engine stops execution according to error code: ",
  67. luaExecutionCode.to!EngineExitCodes);
  68. currentGameState = GameState.Exit;
  69. return luaExecutionCode;
  70. }
  71. luaReload = false;
  72. while (currentGameState == GameState.MainMenu)
  73. {
  74. ClearBackground(Colors.WHITE);
  75. if (IsKeyPressed(KeyboardKey.KEY_F11)) {
  76. ToggleFullscreen();
  77. }
  78. UpdateMusicStream(music);
  79. BeginDrawing();
  80. BeginMode2D(camera);
  81. backgroundLogic();
  82. effectsLogic();
  83. luaEventLoop();
  84. EndMode2D();
  85. EndDrawing();
  86. }
  87. debugWriteln("menu assets unloading");
  88. UnloadFont(textFont);
  89. StopMusicStream(music);
  90. UnloadMusicStream(music);
  91. luaReload = true;
  92. return EngineExitCodes.EXIT_OK;
  93. }