menu.d 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. enum
  17. {
  18. MENU_ITEM_START = 0,
  19. MENU_ITEM_SOUND = 1,
  20. MENU_ITEM_SFX = 2,
  21. MENU_ITEM_FULLSCREEN = 3,
  22. MENU_ITEM_EXIT = 4,
  23. FADE_SPEED_IN = 0.02f,
  24. FADE_SPEED_OUT = 0.04f,
  25. INACTIVITY_TIMEOUT = 20.0f
  26. }
  27. void fadeEffect(float alpha, bool fadeIn, void delegate(float alpha) renderer)
  28. {
  29. const float FadeIncrement = 0.02f;
  30. while (fadeIn ? alpha < 2.0f : alpha > 0.0f)
  31. {
  32. alpha += fadeIn ? FadeIncrement : -FadeIncrement;
  33. BeginDrawing();
  34. ClearBackground(Colors.BLACK);
  35. renderer(alpha);
  36. EndDrawing();
  37. }
  38. }
  39. void renderText(float alpha, immutable(char)* text)
  40. {
  41. DrawTextEx(textFont, text,
  42. Vector2(GetScreenWidth() / 2 - MeasureText(text, 40) / 2,
  43. GetScreenHeight() / 2), 40, 0, Fade(Colors.WHITE, alpha)
  44. );
  45. }
  46. void renderLogo(float alpha, immutable(char)* name, bool fullscreen)
  47. {
  48. Texture2D companyLogo = LoadTexture(name);
  49. if (fullscreen) {
  50. DrawTexturePro(companyLogo,
  51. Rectangle(0, 0, cast(float) companyLogo.width, cast(float) companyLogo.height),
  52. Rectangle(0, 0, cast(float) GetScreenWidth(), cast(float) GetScreenHeight()),
  53. Vector2(0, 0), 0.0, Fade(Colors.WHITE, alpha));
  54. }
  55. else {
  56. DrawTexture(companyLogo, GetScreenWidth() / 2, GetScreenHeight() / 2, Colors.WHITE);
  57. }
  58. }
  59. void helloScreen()
  60. {
  61. debug
  62. {
  63. bool play = false;
  64. debugWriteln("hello screen showing");
  65. if (play == false) {
  66. videoFinished = true;
  67. goto debug_lab;
  68. }
  69. }
  70. else {
  71. fadeEffect(0.0f, true, (float alpha) {
  72. renderText(alpha, "powered by\n\nHimmel Engine");
  73. });
  74. fadeEffect(2.0f, false, (float alpha) {
  75. renderText(alpha, "powered by\n\nHimmel Engine");
  76. });
  77. /*
  78. fadeEffect(0.0f, true, (float alpha) {
  79. renderLogo(alpha, "atlus_logo.png".toStringz, true);
  80. });
  81. fadeEffect(fadeAlpha, false, (float alpha) {
  82. renderLogo(alpha, "atlus_logo.png".toStringz, true);
  83. });
  84. */
  85. // Play Opening Video
  86. BeginDrawing();
  87. debug debugWriteln("searching for video");
  88. if (std.file.exists(getcwd() ~ "/res/videos/soul_OP.moflex.mp4"))
  89. {
  90. debug debugWriteln("video found, playing");
  91. playVideo("/res/videos/soul_OP.moflex.mp4");
  92. }
  93. else {
  94. debug debugWriteln("video not found, skipping");
  95. videoFinished = true;
  96. }
  97. }
  98. debug_lab:
  99. }
  100. int showMainMenu() {
  101. int luaExecutionCode = luaInit("scripts/menu.lua");
  102. if (luaExecutionCode != EngineExitCodes.EXIT_OK) {
  103. debugWriteln("Engine stops execution according to error code: ",
  104. luaExecutionCode.to!EngineExitCodes);
  105. currentGameState = GameState.Exit;
  106. return luaExecutionCode;
  107. }
  108. luaReload = false;
  109. while (currentGameState == GameState.MainMenu)
  110. {
  111. UpdateMusicStream(music);
  112. luaEventLoop();
  113. BeginDrawing();
  114. BeginMode2D(camera);
  115. backgroundLogic();
  116. EndMode2D();
  117. EndDrawing();
  118. }
  119. StopMusicStream(music);
  120. UnloadMusicStream(music);
  121. luaReload = true;
  122. return 0;
  123. }