scene_credits.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "scene_credits.h"
  2. #include "app.h"
  3. #include "wave/calc.h"
  4. #include "wave/scene_management.h"
  5. #include "racso_sokoban_icons.h"
  6. #include "wave/graphics/icons.h"
  7. #include "wave/graphics/icon_drawing.h"
  8. #include "gui/canvas.h"
  9. typedef enum Screen
  10. {
  11. Screen_ControlsGuide,
  12. Screen_Credits,
  13. Screen_COUNT
  14. } Screen;
  15. static Screen currentScreen;
  16. void credits_transition_callback(int from, int to, void* context)
  17. {
  18. UNUSED(from);
  19. UNUSED(to);
  20. UNUSED(context);
  21. currentScreen = 0;
  22. }
  23. void render_boxed_text(Canvas* canvas, char* text, int x, int y)
  24. {
  25. int fontHeight = canvas_current_font_height(canvas);
  26. int textWidth = strlen(text) * fontHeight * 2 / 3;
  27. canvas_set_color(canvas, ColorWhite);
  28. canvas_draw_box(canvas, x, y - fontHeight / 2, textWidth, fontHeight - 1);
  29. canvas_set_color(canvas, ColorBlack);
  30. canvas_draw_frame(canvas, x - 1, y - fontHeight / 2 - 1, textWidth + 2, fontHeight + 1);
  31. canvas_draw_str_aligned(canvas, x + textWidth / 2, y, AlignCenter, AlignCenter, text);
  32. }
  33. void render_controls_guide(Canvas* canvas)
  34. {
  35. canvas_clear(canvas);
  36. canvas_set_color(canvas, ColorBlack);
  37. canvas_set_font(canvas, FontPrimary);
  38. canvas_draw_str_aligned(canvas, 64, 1, AlignCenter, AlignTop, "Controls");
  39. canvas_set_font(canvas, FontKeyboard);
  40. int x = 32, y = 32;
  41. draw_icon_aligned(canvas, x, y, AlignCenter, AlignCenter, &I_icon_button_ok);
  42. draw_icon_aligned(canvas, x, y - 10, AlignCenter, AlignBottom, &I_icon_button_up);
  43. draw_icon_aligned(canvas, x, y + 10, AlignCenter, AlignTop, &I_icon_button_down);
  44. draw_icon_aligned(canvas, x - 10, y, AlignRight, AlignCenter, &I_icon_button_left);
  45. draw_icon_aligned(canvas, x + 10, y, AlignLeft, AlignCenter, &I_icon_button_right);
  46. draw_icon_aligned(canvas, x + 40, y + 20, AlignLeft, AlignCenter, &I_icon_button_back);
  47. render_boxed_text(canvas, "Move", 36, 18);
  48. render_boxed_text(canvas, "Undo", 38, 34);
  49. render_boxed_text(canvas, "Exit", 90, 54);
  50. }
  51. void render_credits(Canvas* canvas)
  52. {
  53. canvas_clear(canvas);
  54. canvas_set_color(canvas, ColorBlack);
  55. canvas_set_font(canvas, FontPrimary);
  56. canvas_draw_str_aligned(canvas, 64 - 10, 1, AlignRight, AlignTop, "Made with");
  57. canvas_draw_icon(canvas, 64 - 4, 0, &I_ace_spades);
  58. canvas_draw_str_aligned(canvas, 65 + 10, 1, AlignLeft, AlignTop, "by Racso");
  59. int boxSize = 10;
  60. int x = 64 - boxSize * 3 / 2;
  61. int y = 32 - boxSize * 3 / 2;
  62. canvas_draw_box(canvas, x + boxSize, y, boxSize, boxSize);
  63. canvas_draw_box(canvas, x + 2 * boxSize, y, boxSize, boxSize);
  64. canvas_draw_box(canvas, x + boxSize, y + boxSize, boxSize, boxSize);
  65. canvas_draw_box(canvas, x + boxSize, y + 2 * boxSize, boxSize, boxSize);
  66. canvas_draw_box(canvas, x, y + boxSize, boxSize, boxSize);
  67. canvas_set_font(canvas, FontKeyboard);
  68. canvas_draw_str_aligned(canvas, 64, 62, AlignCenter, AlignBottom, "https://rac.so");
  69. }
  70. void credits_render_callback(Canvas* const canvas, void* context)
  71. {
  72. UNUSED(context);
  73. if (currentScreen == Screen_ControlsGuide)
  74. render_controls_guide(canvas);
  75. else if (currentScreen == Screen_Credits)
  76. render_credits(canvas);
  77. }
  78. void credits_input_callback(InputKey key, InputType type, void* context)
  79. {
  80. UNUSED(key);
  81. AppContext* app = (AppContext*)context;
  82. if (type != InputTypePress)
  83. return;
  84. currentScreen += 1;
  85. if (currentScreen >= Screen_COUNT)
  86. scene_manager_set_scene(app->sceneManager, SceneType_Menu);
  87. }