ui.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include <math.h>
  2. #include <notification/notification_messages.h>
  3. #include "ui.h"
  4. #define LINE_HEIGHT 16
  5. #define ITEM_PADDING 4
  6. const char MoneyMul[4] = {'K', 'B', 'T', 'S'};
  7. void draw_player_scene(Canvas* const canvas, const GameState* game_state) {
  8. int max_card = game_state->player_card_count;
  9. if(max_card > 0) draw_deck((game_state->player_cards), max_card, canvas);
  10. if(game_state->dealer_card_count > 0) draw_card_back_at(13, 5, canvas);
  11. max_card = game_state->dealer_card_count;
  12. if(max_card > 1) {
  13. draw_card_at(
  14. 2, 2, game_state->dealer_cards[1].pip, game_state->dealer_cards[1].character, canvas);
  15. }
  16. }
  17. void draw_dealer_scene(Canvas* const canvas, const GameState* game_state) {
  18. uint8_t max_card = game_state->dealer_card_count;
  19. draw_deck((game_state->dealer_cards), max_card, canvas);
  20. }
  21. void popup_frame(Canvas* const canvas) {
  22. canvas_set_color(canvas, ColorWhite);
  23. canvas_draw_box(canvas, 32, 15, 66, 13);
  24. canvas_set_color(canvas, ColorBlack);
  25. canvas_draw_frame(canvas, 32, 15, 66, 13);
  26. canvas_set_font(canvas, FontSecondary);
  27. }
  28. void draw_play_menu(Canvas* const canvas, const GameState* game_state) {
  29. const char* menus[3] = {"Double", "Hit", "Stay"};
  30. for(uint8_t m = 0; m < 3; m++) {
  31. if(m == 0 &&
  32. (game_state->doubled || game_state->player_score < game_state->settings.round_price))
  33. continue;
  34. int y = m * 13 + 25;
  35. canvas_set_color(canvas, ColorBlack);
  36. if(game_state->selectedMenu == m) {
  37. canvas_set_color(canvas, ColorBlack);
  38. canvas_draw_box(canvas, 1, y, 31, 12);
  39. } else {
  40. canvas_set_color(canvas, ColorWhite);
  41. canvas_draw_box(canvas, 1, y, 31, 12);
  42. canvas_set_color(canvas, ColorBlack);
  43. canvas_draw_frame(canvas, 1, y, 31, 12);
  44. }
  45. if(game_state->selectedMenu == m)
  46. canvas_set_color(canvas, ColorWhite);
  47. else
  48. canvas_set_color(canvas, ColorBlack);
  49. canvas_draw_str_aligned(canvas, 16, y + 6, AlignCenter, AlignCenter, menus[m]);
  50. }
  51. }
  52. void draw_screen(Canvas* const canvas, const bool* points) {
  53. for(uint8_t x = 0; x < 128; x++) {
  54. for(uint8_t y = 0; y < 64; y++) {
  55. if(points[y * 128 + x]) canvas_draw_dot(canvas, x, y);
  56. }
  57. }
  58. }
  59. void draw_score(Canvas* const canvas, bool top, uint8_t amount) {
  60. char drawChar[20];
  61. snprintf(drawChar, sizeof(drawChar), "Player score: %i", amount);
  62. if(top)
  63. canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, drawChar);
  64. else
  65. canvas_draw_str_aligned(canvas, 64, 62, AlignCenter, AlignBottom, drawChar);
  66. }
  67. void draw_money(Canvas* const canvas, uint32_t score) {
  68. canvas_set_font(canvas, FontSecondary);
  69. char drawChar[11];
  70. uint32_t currAmount = score;
  71. if(currAmount < 1000) {
  72. snprintf(drawChar, sizeof(drawChar), "$%lu", currAmount);
  73. } else {
  74. char c = 'K';
  75. for(uint8_t i = 0; i < 4; i++) {
  76. currAmount = currAmount / 1000;
  77. if(currAmount < 1000) {
  78. c = MoneyMul[i];
  79. break;
  80. }
  81. }
  82. snprintf(drawChar, sizeof(drawChar), "$%lu %c", currAmount, c);
  83. }
  84. canvas_draw_str_aligned(canvas, 126, 2, AlignRight, AlignTop, drawChar);
  85. }
  86. void draw_menu(
  87. Canvas* const canvas,
  88. const char* text,
  89. const char* value,
  90. int8_t y,
  91. bool left_caret,
  92. bool right_caret,
  93. bool selected) {
  94. UNUSED(selected);
  95. if(y < 0 || y >= 64) return;
  96. if(selected) {
  97. canvas_set_color(canvas, ColorBlack);
  98. canvas_draw_box(canvas, 0, y, 122, LINE_HEIGHT);
  99. canvas_set_color(canvas, ColorWhite);
  100. }
  101. canvas_draw_str_aligned(canvas, 4, y + ITEM_PADDING, AlignLeft, AlignTop, text);
  102. if(left_caret) canvas_draw_str_aligned(canvas, 80, y + ITEM_PADDING, AlignLeft, AlignTop, "<");
  103. canvas_draw_str_aligned(canvas, 100, y + ITEM_PADDING, AlignCenter, AlignTop, value);
  104. if(right_caret)
  105. canvas_draw_str_aligned(canvas, 120, y + ITEM_PADDING, AlignRight, AlignTop, ">");
  106. canvas_set_color(canvas, ColorBlack);
  107. }
  108. void settings_page(Canvas* const canvas, const GameState* gameState) {
  109. char drawChar[10];
  110. int startY = 0;
  111. if(LINE_HEIGHT * (gameState->selectedMenu + 1) >= 64) {
  112. startY -= (LINE_HEIGHT * (gameState->selectedMenu + 1)) - 64;
  113. }
  114. int scrollHeight = round(64 / 6.0) + ITEM_PADDING * 2;
  115. int scrollPos = 64 / (6.0 / (gameState->selectedMenu + 1)) - ITEM_PADDING * 2;
  116. canvas_set_color(canvas, ColorBlack);
  117. canvas_draw_box(canvas, 123, scrollPos, 4, scrollHeight);
  118. canvas_draw_box(canvas, 125, 0, 1, 64);
  119. snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.starting_money);
  120. draw_menu(
  121. canvas,
  122. "Start money",
  123. drawChar,
  124. 0 * LINE_HEIGHT + startY,
  125. gameState->settings.starting_money > gameState->settings.round_price,
  126. gameState->settings.starting_money < 400,
  127. gameState->selectedMenu == 0);
  128. snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.round_price);
  129. draw_menu(
  130. canvas,
  131. "Round price",
  132. drawChar,
  133. 1 * LINE_HEIGHT + startY,
  134. gameState->settings.round_price > 10,
  135. gameState->settings.round_price < gameState->settings.starting_money,
  136. gameState->selectedMenu == 1);
  137. snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.animation_duration);
  138. draw_menu(
  139. canvas,
  140. "Anim. length",
  141. drawChar,
  142. 2 * LINE_HEIGHT + startY,
  143. gameState->settings.animation_duration > 0,
  144. gameState->settings.animation_duration < 2000,
  145. gameState->selectedMenu == 2);
  146. snprintf(drawChar, sizeof(drawChar), "%li", gameState->settings.message_duration);
  147. draw_menu(
  148. canvas,
  149. "Popup time",
  150. drawChar,
  151. 3 * LINE_HEIGHT + startY,
  152. gameState->settings.message_duration > 0,
  153. gameState->settings.message_duration < 2000,
  154. gameState->selectedMenu == 3);
  155. // draw_menu(canvas, "Sound", gameState->settings.sound_effects ? "Yes" : "No",
  156. // 5 * LINE_HEIGHT + startY,
  157. // true,
  158. // true,
  159. // gameState->selectedMenu == 5
  160. // );
  161. }