menu.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include <switch.h>
  4. #include "ui/menu.h"
  5. #include "ui/gc.h"
  6. #include "ui/settings.h"
  7. #include "gfx/SDL_easy.h"
  8. #include "gfx/image.h"
  9. #include "gfx/shape.h"
  10. #include "gfx/text.h"
  11. #include "gfx/button.h"
  12. #include "sound/sound.h"
  13. #include "nx/ns.h"
  14. #include "nx/ncm.h"
  15. #include "nx/input.h"
  16. #include "nx/lbl.h"
  17. #include "util/log.h"
  18. #ifdef DEBUG
  19. #define TITLE_NAME "GameCard Installer (DEBUG)"
  20. #else
  21. #define TITLE_NAME "GameCard Installer"
  22. #endif
  23. #define EMPTY_ICON_PATH "romfs:/no_icon.jpg"
  24. #define STORAGE_BAR_W 325
  25. #define STORAGE_BAR_H 15
  26. typedef enum
  27. {
  28. Option_Nand,
  29. Option_SD,
  30. Option_Exit,
  31. } Option;
  32. const char *g_option_list[] =
  33. {
  34. "Nand Install",
  35. "SD Card Install",
  36. "Exit",
  37. };
  38. const char *g_sound_list[] =
  39. {
  40. "romfs:/sound/error.wav",
  41. "romfs:/sound/insert.wav",
  42. "romfs:/sound/select.wav",
  43. "romfs:/sound/popup.wav",
  44. };
  45. // background shapes.
  46. typedef struct
  47. {
  48. shape_t background;
  49. shape_t side_background;
  50. shape_t upper_bar;
  51. shape_t lower_bar;
  52. shape_t selected_bar;
  53. text_t *title;
  54. text_t *a_text;
  55. text_t *b_text;
  56. text_t *x_text;
  57. text_t *y_text;
  58. text_t *l_text;
  59. text_t *r_text;
  60. button_t *a_button;
  61. button_t *b_button;
  62. button_t *x_button;
  63. button_t *y_button;
  64. button_t *l_button;
  65. button_t *r_button;
  66. button_t *app_icon;
  67. } Background_t;
  68. Background_t g_background = {0};
  69. typedef struct
  70. {
  71. text_t *text;
  72. bool selected;
  73. bool avaliable;
  74. } Options_t;
  75. Options_t g_options[3] = {0};
  76. // sound effects.
  77. typedef struct
  78. {
  79. sound_t *error;
  80. sound_t *insert;
  81. sound_t *move;
  82. sound_t *popup;
  83. } SoundEffects_t;
  84. SoundEffects_t g_sound_effects = {0};
  85. typedef struct
  86. {
  87. size_t free;
  88. size_t total;
  89. float size_gb;
  90. shape_t bar;
  91. shape_t filled;
  92. text_t *space_text;
  93. } Storage_t;
  94. Storage_t g_nand_storage = {0};
  95. Storage_t g_sd_storage = {0};
  96. // the gamecard struct that will contain info on the gc, as well as gfx data.
  97. GameInfo_t g_game_info = {0};
  98. // the default icon that is rendered if no gamecard is inserted.
  99. image_t *g_empty_icon = {0};
  100. // global cursor for the main menu.
  101. uint8_t g_cursor = 0;
  102. // tetris spinning piece.
  103. button_t *g_tetris_button[0x8] = {0};
  104. uint8_t g_tetris_spin_pos = 0;
  105. // global flag for when the gamecard is inserted, changes render options.
  106. bool g_gc_inserted = false;
  107. /*
  108. * Init and exit.
  109. */
  110. void setup_background(void)
  111. {
  112. // shapes.
  113. g_background.background = create_shape(Colour_Nintendo_Black, 0, 0, SCREEN_W, SCREEN_H, true);
  114. g_background.side_background = create_shape(Colour_Nintendo_LightBlack, 30, 90, 375, 555, true);
  115. g_background.upper_bar = create_shape(Colour_Nintendo_White, 30, (SCREEN_H / 8), SCREEN_W - (30 * 2), 2, true);
  116. g_background.lower_bar = create_shape(Colour_Nintendo_White, 30, 650, SCREEN_W - (30 * 2), 2, true);
  117. g_background.selected_bar = create_shape(Colour_Nintendo_Cyan, 90, 230, 4, 45, true);
  118. // title and icon.
  119. g_background.title = create_text(&FONT_TEXT[QFontSize_25], 130, 40, Colour_Nintendo_White, TITLE_NAME);
  120. g_background.app_icon = create_button(&FONT_BUTTON[QFontSize_45], 65, 30, Colour_Nintendo_White, Font_Button_SETTINGS);
  121. // buttons.
  122. g_background.a_button = create_button(&FONT_BUTTON[QFontSize_25], 1150, 675, Colour_Nintendo_White, Font_Button_A);
  123. g_background.b_button = create_button(&FONT_BUTTON[QFontSize_25], 1055 - 35, 675, Colour_Nintendo_White, Font_Button_B);
  124. g_background.x_button = create_button(&FONT_BUTTON[QFontSize_25], 870, 675, Colour_Nintendo_White, Font_Button_X);
  125. g_background.y_button = create_button(&FONT_BUTTON[QFontSize_25], 700, 675, Colour_Nintendo_White, Font_Button_Y);
  126. g_background.l_button = create_button(&FONT_BUTTON[QFontSize_25], 90 - 40, 130 + (255/2), Colour_Nintendo_White, Font_Button_L);
  127. g_background.r_button = create_button(&FONT_BUTTON[QFontSize_25], 90 + 255 + 15, 130 + (255/2), Colour_Nintendo_White, Font_Button_R);
  128. // button text.
  129. g_background.a_text = create_text(&FONT_TEXT[QFontSize_20], 1185, 675, Colour_Nintendo_White, "OK");
  130. g_background.b_text = create_text(&FONT_TEXT[QFontSize_20], 1055, 675, Colour_Nintendo_White, "Back");
  131. g_background.x_text = create_text(&FONT_TEXT[QFontSize_20], 905, 675, Colour_Nintendo_White, "Settings");
  132. g_background.y_text = create_text(&FONT_TEXT[QFontSize_20], 735, 675, Colour_Nintendo_White, "Game Info");
  133. }
  134. void setup_options(void)
  135. {
  136. for (uint16_t i = 0, y = 300; i < 3; i++, y += 125)
  137. {
  138. g_options[i].text = create_text(&FONT_TEXT[QFontSize_23], 500, y, Colour_Nintendo_White, g_option_list[i]);
  139. }
  140. }
  141. void setup_storage(void)
  142. {
  143. // setup the nand storage.
  144. g_nand_storage.free = ns_get_storage_free_space(NcmStorageId_BuiltInUser);
  145. g_nand_storage.total = ns_get_storage_total_size(NcmStorageId_BuiltInUser);
  146. g_nand_storage.bar = create_shape(Colour_Nintendo_White, 480, 170, STORAGE_BAR_W, 14, false);
  147. g_nand_storage.filled = create_shape(Colour_Nintendo_White, 480 + 2, 170 + 2, STORAGE_BAR_W - (((float)g_nand_storage.free / (float)g_nand_storage.total) * STORAGE_BAR_W) - 4, 14 - 4, true);
  148. g_nand_storage.size_gb = (float)g_nand_storage.free / 0x40000000;
  149. g_nand_storage.space_text = create_text(&FONT_TEXT[QFontSize_23], 490, 135, Colour_Nintendo_White, "System memory %.1fGB", g_nand_storage.size_gb);
  150. // setup the sd card storage.
  151. g_sd_storage.free = ns_get_storage_free_space(NcmStorageId_SdCard);
  152. g_sd_storage.total = ns_get_storage_total_size(NcmStorageId_SdCard);
  153. g_sd_storage.bar = create_shape(Colour_White, 860, 170, STORAGE_BAR_W, 14, false);
  154. g_sd_storage.filled = create_shape(Colour_Nintendo_White, 860 + 2, 170 + 2, STORAGE_BAR_W - (((float)g_sd_storage.free / (float)g_sd_storage.total) * STORAGE_BAR_W) - 4, 14 - 4, true);
  155. g_sd_storage.size_gb = (float)g_sd_storage.free / 0x40000000;
  156. g_sd_storage.space_text = create_text(&FONT_TEXT[QFontSize_23], 870, 135, Colour_Nintendo_White, "microSD card %.1fGB", g_sd_storage.size_gb);
  157. }
  158. void setup_sound_effects(void)
  159. {
  160. g_sound_effects.error = load_sound_from_file(g_sound_list[0]);
  161. g_sound_effects.insert = load_sound_from_file(g_sound_list[1]);
  162. g_sound_effects.move = load_sound_from_file(g_sound_list[2]);
  163. g_sound_effects.popup = load_sound_from_file(g_sound_list[3]);
  164. }
  165. void setup_teris(void)
  166. {
  167. for (uint16_t i = 0, button = Font_Tetris_TL; button <= Font_Tetris_L; i++, button++)
  168. {
  169. g_tetris_button[i] = create_button(&FONT_BUTTON[QFontSize_33], 50, SCREEN_H - 50, Colour_Nintendo_White, button);
  170. }
  171. }
  172. void free_background(void)
  173. {
  174. free_text(g_background.title);
  175. free_button(g_background.app_icon);
  176. free_button(g_background.a_button);
  177. free_button(g_background.b_button);
  178. free_button(g_background.x_button);
  179. free_button(g_background.y_button);
  180. free_button(g_background.l_button);
  181. free_button(g_background.r_button);
  182. free_text(g_background.a_text);
  183. free_text(g_background.b_text);
  184. free_text(g_background.x_text);
  185. free_text(g_background.y_text);
  186. }
  187. void free_options(void)
  188. {
  189. for (uint8_t i = 0; i < 3; i++)
  190. {
  191. free_text(g_options[i].text);
  192. }
  193. }
  194. void free_storage(void)
  195. {
  196. free_text(g_nand_storage.space_text);
  197. free_text(g_sd_storage.space_text);
  198. }
  199. void free_sound_effects(void)
  200. {
  201. free_sound(g_sound_effects.error);
  202. free_sound(g_sound_effects.insert);
  203. free_sound(g_sound_effects.move);
  204. free_sound(g_sound_effects.popup);
  205. }
  206. void free_tetris(void)
  207. {
  208. for (uint16_t i = 0, button = Font_Tetris_B; button <= Font_Tetris_L; i++, button++)
  209. {
  210. free_button(g_tetris_button[i]);
  211. }
  212. }
  213. void free_game_info(GameInfo_t *game_info)
  214. {
  215. if (!game_info)
  216. {
  217. write_log("missing params in %s\n", __func__);
  218. return;
  219. }
  220. free_image(game_info->icon);
  221. free_text(game_info->title);
  222. free_text(game_info->author);
  223. free_text(game_info->text_size);
  224. free_text(game_info->text_key_gen);
  225. free_text(game_info->text_app_id);
  226. free_text(game_info->text_entry_contents);
  227. memset(game_info, 0, sizeof(GameInfo_t));
  228. }
  229. void free_game_info_detailed(GameInfoDetailed_t *info)
  230. {
  231. if (!info)
  232. {
  233. write_log("missing params in %s\n", __func__);
  234. return;
  235. }
  236. free_text(info->text_type);
  237. free_text(info->text_id);
  238. free_text(info->text_keygen);
  239. free_text(info->text_version);
  240. free_text(info->text_content_count);
  241. free_text(info->text_content_meta_count);
  242. for (uint16_t i = 0; i < info->content_count; i++)
  243. {
  244. free_text(info->entry[i].name);
  245. free_text(info->entry[i].type);
  246. free_text(info->entry[i].size);
  247. }
  248. info->id = 0;
  249. info->type = 0;
  250. info->keygen = 0;
  251. info->version = 0;
  252. info->content_count = 0;
  253. info->content_meta_count = 0;
  254. memset(info, 0, sizeof(GameInfoDetailed_t));
  255. }
  256. bool init_menu(void)
  257. {
  258. //ncm_delete_all_placeholders_id();
  259. // romfs will contain the empty icon and sound effects.
  260. if (R_FAILED(romfsInit()))
  261. return false;
  262. // load background.
  263. setup_background();
  264. // setup menu options.
  265. setup_options();
  266. // load sounds.
  267. setup_sound_effects();
  268. // setup the storage.
  269. setup_storage();
  270. // create the spinning tetris.
  271. setup_teris();
  272. // load icon from romfs.
  273. g_empty_icon = create_image_from_file(EMPTY_ICON_PATH, 90, 130, 0, 0);
  274. // unmount romfs as we only needed the empty icon picture and sound effects.
  275. romfsExit();
  276. return true;
  277. }
  278. void exit_menu(void)
  279. {
  280. free_image(g_empty_icon);
  281. free_background();
  282. free_options();
  283. free_storage();
  284. free_sound_effects();
  285. free_tetris();
  286. }
  287. /*
  288. * Update stuff.
  289. */
  290. void update_button_spin(void)
  291. {
  292. g_tetris_spin_pos = g_tetris_spin_pos == 7 ? 0 : g_tetris_spin_pos + 1;
  293. }
  294. void update_options(void)
  295. {
  296. for (uint8_t i = 0; i < 3; i++)
  297. {
  298. if (i == g_cursor)
  299. {
  300. g_options[i].selected = true;
  301. SDL_SetTextureColour(g_options[i].text->tex, g_cursor == Option_Exit || g_gc_inserted ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver);
  302. }
  303. else
  304. {
  305. g_options[i].selected = false;
  306. SDL_SetTextureColour(g_options[i].text->tex, i == Option_Exit || g_gc_inserted ? Colour_Nintendo_White : Colour_Nintendo_Silver);
  307. }
  308. g_options[i].avaliable = g_gc_inserted;
  309. }
  310. }
  311. void update_storage_size(void)
  312. {
  313. // get new free space.
  314. g_nand_storage.free = ns_get_storage_free_space(NcmStorageId_BuiltInUser);
  315. g_nand_storage.total = ns_get_storage_total_size(NcmStorageId_BuiltInUser);
  316. g_sd_storage.free = ns_get_storage_free_space(NcmStorageId_SdCard);
  317. g_sd_storage.total = ns_get_storage_total_size(NcmStorageId_SdCard);
  318. // update shapes.
  319. set_shape(&g_nand_storage.filled, Colour_Nintendo_White, 480 + 2, 170 + 2, STORAGE_BAR_W - (((float)g_nand_storage.free / (float)g_nand_storage.total) * STORAGE_BAR_W) - 4, 14 - 4, true);
  320. set_shape(&g_sd_storage.filled, Colour_Nintendo_White, 860 + 2, 170 + 2, STORAGE_BAR_W - (((float)g_sd_storage.free / (float)g_sd_storage.total) * STORAGE_BAR_W) - 4, 14 - 4, true);
  321. // calculate new sizes / 1GiB.
  322. g_nand_storage.size_gb = (float)g_nand_storage.free / 0x40000000;
  323. g_sd_storage.size_gb = (float)g_sd_storage.free / 0x40000000;
  324. // update text.
  325. update_text(g_nand_storage.space_text, "System memory %.1fGB", g_nand_storage.size_gb);
  326. update_text(g_sd_storage.space_text, "microSD card %.1fGB", g_sd_storage.size_gb);
  327. }
  328. void update_gamecard(void)
  329. {
  330. if (gc_poll() != g_gc_inserted)
  331. {
  332. update_button_spin();
  333. play_sound(g_sound_effects.insert, -1, 0);
  334. if (g_gc_inserted)
  335. {
  336. g_gc_inserted = false;
  337. gc_unmount();
  338. free_game_info(&g_game_info);
  339. }
  340. else
  341. {
  342. if (gc_mount())
  343. {
  344. gc_setup_game_info(&g_game_info, 0);
  345. g_gc_inserted = true;
  346. }
  347. }
  348. }
  349. }
  350. void update_pulse_colour(PulseColour_t *pulse)
  351. {
  352. if (pulse->col.g == 255) pulse->increase_blue = true;
  353. else if (pulse->col.b == 255 && pulse->delay == 10)
  354. {
  355. pulse->increase_blue = false;
  356. pulse->delay = 0;
  357. }
  358. if (pulse->col.b == 255 && pulse->increase_blue == true)
  359. {
  360. pulse->delay++;
  361. }
  362. else
  363. {
  364. pulse->col.b = pulse->increase_blue ? pulse->col.b + 2 : pulse->col.b - 2;
  365. pulse->col.g = pulse->increase_blue ? pulse->col.g - 2 : pulse->col.g + 2;
  366. }
  367. }
  368. /*
  369. * Ui Display stuff.
  370. */
  371. void ui_display_background(void)
  372. {
  373. // background colour.
  374. draw_shape(&g_background.background);
  375. draw_shape(&g_background.side_background);
  376. draw_shape(&g_background.upper_bar);
  377. draw_shape(&g_background.lower_bar);
  378. // title and icon.
  379. draw_text(g_background.title);
  380. draw_button(g_background.app_icon);
  381. // buttons
  382. draw_button(g_background.a_button);
  383. draw_button(g_background.b_button);
  384. draw_button(g_background.x_button);
  385. draw_button(g_background.y_button);
  386. draw_text(g_background.a_text);
  387. draw_text(g_background.b_text);
  388. draw_text(g_background.x_text);
  389. draw_text(g_background.y_text);
  390. }
  391. void ui_display_storage_size(void)
  392. {
  393. draw_shape(&g_nand_storage.bar);
  394. draw_shape(&g_nand_storage.filled);
  395. draw_text(g_nand_storage.space_text);
  396. draw_shape(&g_sd_storage.bar);
  397. draw_shape(&g_sd_storage.filled);
  398. draw_text(g_sd_storage.space_text);
  399. }
  400. PulseShape_t g_options_pulse_bar = { { {0, 255, 187, 255} , false, 0 }, { 0 } };
  401. void ui_display_option_list(void)
  402. {
  403. for (uint8_t i = 0; i < 3; i++)
  404. {
  405. if (g_options[i].selected)
  406. {
  407. draw_shape_position(&g_background.selected_bar, 485, g_options[i].text->rect.y - 10);
  408. SDL_DrawShapeOutlineEX(g_options_pulse_bar.pulse.col.r, g_options_pulse_bar.pulse.col.g, g_options_pulse_bar.pulse.col.b, g_options_pulse_bar.pulse.col.a, 475, g_options[i].text->rect.y - 25, 720, 70, 5);
  409. }
  410. draw_text(g_options[i].text);
  411. }
  412. }
  413. void ui_display_gamecard(void)
  414. {
  415. if (!g_gc_inserted)
  416. {
  417. draw_image2(g_empty_icon);
  418. }
  419. else
  420. {
  421. // if theres more than one game on the gamecard, show the user how to swap.
  422. if (gc_get_game_count() > 1)
  423. {
  424. draw_button(g_background.l_button);
  425. draw_button(g_background.r_button);
  426. }
  427. if (g_game_info.icon)
  428. {
  429. draw_image2(g_game_info.icon);
  430. }
  431. else
  432. {
  433. draw_image2(g_empty_icon);
  434. }
  435. draw_text(g_game_info.title);
  436. draw_text(g_game_info.author);
  437. draw_text(g_game_info.text_size);
  438. draw_text(g_game_info.text_key_gen);
  439. draw_text(g_game_info.text_app_id);
  440. draw_text(g_game_info.text_entry_contents);
  441. }
  442. }
  443. void ui_display_detailed_gamecard(void)
  444. {
  445. // initial info setup.
  446. uint16_t cursor = 0;
  447. GameInfoDetailed_t info = {0};
  448. if (!gc_setup_detailed_game_info(&info, cursor))
  449. {
  450. return;
  451. }
  452. // the size of the pop-up box.
  453. const SDL_Rect box = { 255 / 1.5, 145 / 1.5, SCREEN_W - (box.x * 2), SCREEN_H - (box.y * 2)};
  454. button_t *l_button = create_button(&FONT_BUTTON[QFontSize_23], 845, box.y + 480, Colour_Nintendo_White, Font_Button_L);
  455. button_t *r_button = create_button(&FONT_BUTTON[QFontSize_23], 875, box.y + 480, Colour_Nintendo_White, Font_Button_R);
  456. text_t *swap_text = create_text(&FONT_TEXT[QFontSize_23], 910, box.y + 480, Colour_Nintendo_White, "Swap Entry");
  457. text_t *title = create_text(&FONT_TEXT[QFontSize_28], box.x + 60, box.y + 30, Colour_Nintendo_White, "Game-Info");
  458. while (appletMainLoop())
  459. {
  460. input_t input = get_input();
  461. if (input.down)
  462. {
  463. play_sound(g_sound_effects.move, -1, 0);
  464. }
  465. if (input.down & HidNpadButton_B)
  466. {
  467. break;
  468. }
  469. if (input.down & HidNpadButton_L)
  470. {
  471. // ensure that we have at least one entry (we always should) then check if we have more than one.
  472. if (g_game_info.total_count && g_game_info.total_count -1)
  473. {
  474. cursor = move_cursor_up(cursor, g_game_info.total_count);
  475. free_game_info_detailed(&info);
  476. if (!gc_setup_detailed_game_info(&info, cursor))
  477. {
  478. break;
  479. }
  480. }
  481. }
  482. if (input.down & HidNpadButton_R)
  483. {
  484. // same as above.
  485. if (g_game_info.total_count && g_game_info.total_count -1)
  486. {
  487. cursor = move_cursor_down(cursor, g_game_info.total_count);
  488. free_game_info_detailed(&info);
  489. if (!gc_setup_detailed_game_info(&info, cursor))
  490. {
  491. break;
  492. }
  493. }
  494. }
  495. ui_display_dim_background();
  496. SDL_DrawShape(Colour_Nintendo_DarkGrey, box.x, box.y, box.w, box.h, true);
  497. SDL_DrawShape(Colour_Nintendo_LightBlack, box.x + 375, box.y + 72, box.w - 375, box.h - 72 - 75, true);
  498. // title / boarder / bottom.
  499. draw_text(title);
  500. SDL_DrawShape(Colour_Nintendo_White, box.x + 25, box.y + 75, box.w - 50, 2, true);
  501. SDL_DrawShape(Colour_Nintendo_White, box.x + 25, box.y + box.h - 75, box.w - 50, 2, true);
  502. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 60, box.y + 480, Colour_Nintendo_White, "Page: %u / %u", cursor + 1, g_game_info.total_count);
  503. draw_button(l_button);
  504. draw_button(r_button);
  505. draw_text(swap_text);
  506. if (g_game_info.icon)
  507. {
  508. draw_image_set(g_game_info.icon, 290, 200, g_game_info.icon->rect.w / 2, g_game_info.icon->rect.h / 2);
  509. }
  510. else
  511. {
  512. draw_image_set(g_empty_icon, 290, 200, g_empty_icon->rect.w / 2, g_empty_icon->rect.h / 2);
  513. }
  514. draw_text(info.text_type);
  515. draw_text(info.text_id);
  516. draw_text(info.text_keygen);
  517. draw_text(info.text_version);
  518. draw_text(info.text_content_count);
  519. draw_text(info.text_content_meta_count);
  520. for (uint16_t i = 0; i < info.content_count; i++)
  521. {
  522. draw_text(info.entry[i].name);
  523. draw_text(info.entry[i].type);
  524. draw_text(info.entry[i].size);
  525. }
  526. SDL_UpdateRenderer();
  527. }
  528. free_button(l_button);
  529. free_button(r_button);
  530. free_text(swap_text);
  531. free_text(title);
  532. free_game_info_detailed(&info);
  533. }
  534. void ui_display_button_spin(void)
  535. {
  536. draw_button(g_tetris_button[g_tetris_spin_pos]);
  537. }
  538. void ui_display_dim_background(void)
  539. {
  540. // clear the renderer.
  541. SDL_ClearRenderer();
  542. // re draw the main menu.
  543. render_menu();
  544. // draw an opaque shape over the entire screen.
  545. SDL_SetRenderDrawColor(SDL_GetRenderer(SDL_GetWindow()), 20, 20, 20, 225);
  546. SDL_Rect rect = { 0, 0, SCREEN_W, SCREEN_H };
  547. SDL_RenderFillRect(SDL_GetRenderer(SDL_GetWindow()), &rect);
  548. }
  549. void ui_display_popup_box(void)
  550. {
  551. ui_display_dim_background();
  552. // The pop up shape.
  553. SDL_Rect box = { 255, 145, 770, 430 };
  554. SDL_DrawShape(Colour_Nintendo_DarkGrey, box.x, box.y, box.w, box.h, true);
  555. }
  556. void ui_draw_spacers(int x, int y, int txt_size)
  557. {
  558. SDL_DrawShape(Colour_Nintendo_Silver, x - 25, y-18, 500 + 50, 1, true);
  559. SDL_DrawShape(Colour_Nintendo_Silver, x - 25, y+txt_size+18, 500 + 50, 1, true);
  560. }
  561. void ui_draw_highlight_box(PulseShape_t *pulse_shape, int x, int y, int w, int h)
  562. {
  563. SDL_DrawShapeOutlineEX(pulse_shape->pulse.col.r, pulse_shape->pulse.col.g, pulse_shape->pulse.col.b, pulse_shape->pulse.col.a, x - 20, y - 20, w, h + 20, 5);
  564. update_pulse_colour(&pulse_shape->pulse);
  565. }
  566. // this code should be made illegal.
  567. // this is what happens when you want to bang out a ui menu in 1 hour.
  568. // TODO: burn the code.
  569. // ACTUAL TODO: write a usable ui framework.
  570. // - one that doesn't leak mem and that actually caches stuff.
  571. void ui_display_options(void)
  572. {
  573. PulseShape_t pulse_shape = { { {0, 255, 187, 255} , false, 0 }, { 0 } };
  574. const char *title_base = "Install Base";
  575. const char *title_update = "Install Update";
  576. const char *title_dlc = "Install DLC";
  577. const char *title_music = "Enable Music";
  578. const char *title_sound = "Sound Effects";
  579. const char *hdr[] =
  580. {
  581. "Installation",
  582. "Sounds",
  583. "Exit",
  584. };
  585. const char *expl_keygen[] =
  586. {
  587. "This will re-encrypt the key area of all the nca's with keygen 0.",
  588. "Allows some games to be launched on lower firmware versions.",
  589. };
  590. const char *expl_mus[] =
  591. {
  592. "Enable / disable the music playback.",
  593. };
  594. const char *expl_snd[] =
  595. {
  596. "Enable / disable the sound effects.",
  597. };
  598. SDL_Rect box = { 255 / 1.5, 145 / 1.5, SCREEN_W - (box.x * 2), SCREEN_H - (box.y * 2)};
  599. SettingFlag install_base = setting_get_install_base();
  600. SettingFlag install_upp = setting_get_install_upp();
  601. SettingFlag install_dlc = setting_get_install_dlc();
  602. SettingFlag install_lower_key_gen = setting_get_install_lower_key_gen();
  603. SettingFlag sound_sound = setting_get_sound();
  604. SettingFlag sound_music = setting_get_music();
  605. uint8_t cursor = 0;
  606. uint8_t r_cursor = 0;
  607. bool left_column = true;
  608. uint8_t cursor_max[] = { 4, 2, 0 };
  609. while (appletMainLoop())
  610. {
  611. input_t input = get_input();
  612. if (input.down)
  613. {
  614. play_sound(g_sound_effects.move, -1, 0);
  615. }
  616. if (input.down & HidNpadButton_B)
  617. {
  618. if (left_column)
  619. break;
  620. left_column = true;
  621. }
  622. else if (input.down & HidNpadButton_AnyLeft)
  623. {
  624. left_column = true;
  625. }
  626. else if (input.down & HidNpadButton_AnyRight)
  627. {
  628. left_column = false;
  629. }
  630. else if (input.down & HidNpadButton_AnyDown)
  631. {
  632. if (left_column)
  633. {
  634. r_cursor = 0;
  635. cursor = move_cursor_down(cursor, 3);
  636. }
  637. else
  638. {
  639. r_cursor = move_cursor_down(r_cursor, cursor_max[cursor]);
  640. }
  641. }
  642. else if (input.down & HidNpadButton_AnyUp)
  643. {
  644. if (left_column)
  645. {
  646. r_cursor = 0;
  647. cursor = move_cursor_up(cursor, 3);
  648. }
  649. else
  650. {
  651. r_cursor = move_cursor_up(r_cursor, cursor_max[cursor]);
  652. }
  653. }
  654. else if (input.down & HidNpadButton_A)
  655. {
  656. if (cursor == 2 && left_column) break;
  657. if (left_column) left_column = !left_column;
  658. else
  659. {
  660. switch (cursor)
  661. {
  662. case 0:
  663. {
  664. switch (r_cursor)
  665. {
  666. case 0:
  667. {
  668. install_base = !install_base;
  669. setting_set_install_base(install_base);
  670. break;
  671. }
  672. case 1:
  673. {
  674. install_upp = !install_upp;
  675. setting_set_install_upp(install_upp);
  676. break;
  677. }
  678. case 2:
  679. {
  680. install_dlc = !install_dlc;
  681. setting_set_install_dlc(install_dlc);
  682. break;
  683. }
  684. case 3:
  685. {
  686. install_lower_key_gen = !install_lower_key_gen;
  687. setting_set_install_lower_key_gen(install_lower_key_gen);
  688. break;
  689. }
  690. }
  691. break;
  692. }
  693. case 1:
  694. {
  695. switch (r_cursor)
  696. {
  697. case 0:
  698. {
  699. sound_music = !sound_music;
  700. setting_set_music(sound_music);
  701. break;
  702. }
  703. case 1:
  704. {
  705. sound_sound = !sound_sound;
  706. setting_set_sound(sound_sound);
  707. break;
  708. }
  709. }
  710. break;
  711. }
  712. default:
  713. {
  714. return;
  715. }
  716. }
  717. }
  718. }
  719. ui_display_dim_background();
  720. SDL_DrawShape(Colour_Nintendo_DarkGrey, box.x, box.y, box.w, box.h, true);
  721. SDL_DrawShape(Colour_Nintendo_LightBlack, box.x + 275, box.y + 72, box.w - 275, box.h - 72 - 75, true);
  722. // title
  723. SDL_DrawShape(Colour_Nintendo_White, box.x + 25, box.y + 75, box.w - 50, 2, true);
  724. SDL_DrawShape(Colour_Nintendo_White, box.x + 25, box.y + box.h - 75, box.w - 50, 2, true);
  725. SDL_DrawText(FONT_TEXT[QFontSize_28].fnt, box.x + 60, box.y + 30, Colour_Nintendo_White, "Settings");
  726. for (int i = 0, y = box.y + 155; i < 3; i++, y += 100)
  727. {
  728. SDL_DrawText(FONT_TEXT[QFontSize_25].fnt, box.x + 50, y, cursor == i ? Colour_Nintendo_Cyan : Colour_Nintendo_White, "%s", hdr[i]);
  729. if (cursor == i)
  730. {
  731. SDL_DrawShape(Colour_Nintendo_Cyan, box.x + 40, y - 4, 4, 25 + 8, true);
  732. if (left_column)
  733. {
  734. ui_draw_highlight_box(&pulse_shape, box.x + 50, y, 200, 40);
  735. }
  736. }
  737. }
  738. switch (cursor)
  739. {
  740. case 0:
  741. {
  742. //base
  743. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 135, Colour_Nintendo_White, title_base);
  744. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 800, box.y + 135, install_base ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver, "%s", install_base ? "On" : "Off");
  745. ui_draw_spacers(box.x + 350, box.y + 135, 23);
  746. if (!left_column && r_cursor == 0)
  747. ui_draw_highlight_box(&pulse_shape, box.x + 350, box.y + 135, 550, 40);
  748. //upp
  749. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 195, Colour_Nintendo_White, title_update);
  750. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 800, box.y + 195, install_upp ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver, "%s", install_upp ? "On" : "Off");
  751. ui_draw_spacers(box.x + 350, box.y + 195, 23);
  752. if (!left_column && r_cursor == 1)
  753. ui_draw_highlight_box(&pulse_shape, box.x + 350, box.y + 195, 550, 40);
  754. //dlc
  755. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 255, Colour_Nintendo_White, title_dlc);
  756. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 800, box.y + 255, install_dlc ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver, "%s", install_dlc ? "On" : "Off");
  757. ui_draw_spacers(box.x + 350, box.y + 255, 23);
  758. if (!left_column && r_cursor == 2)
  759. ui_draw_highlight_box(&pulse_shape, box.x + 350, box.y + 255, 550, 40);
  760. //keygen
  761. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 335, Colour_Nintendo_White, "Lower Keygen Version");
  762. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 800, box.y + 335, install_lower_key_gen ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver, "%s", install_lower_key_gen ? "On" : "Off");
  763. ui_draw_spacers(box.x + 350, box.y + 335, 23);
  764. if (!left_column && r_cursor == 3)
  765. ui_draw_highlight_box(&pulse_shape, box.x + 350, box.y + 335, 550, 40);
  766. for (int i = 0, y = box.y + 390; i < 2; i++, y+= 25)
  767. {
  768. SDL_DrawText(FONT_TEXT[QFontSize_15].fnt, box.x + 350, y, Colour_Nintendo_BrightSilver, "%s", expl_keygen[i]);
  769. }
  770. break;
  771. }
  772. case 1:
  773. {
  774. //music
  775. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 135, Colour_Nintendo_White, title_music);
  776. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 800, box.y + 135, sound_music ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver, "%s", sound_music ? "On" : "Off");
  777. ui_draw_spacers(box.x + 350, box.y + 135, 23);
  778. if (!left_column && r_cursor == 0)
  779. ui_draw_highlight_box(&pulse_shape, box.x + 350, box.y + 135, 550, 40);
  780. for (int i = 0, y = box.y + 185; i < 1; i++, y+= 25)
  781. {
  782. SDL_DrawText(FONT_TEXT[QFontSize_15].fnt, box.x + 350, y, Colour_Nintendo_BrightSilver, "%s", expl_mus[i]);
  783. }
  784. //sound
  785. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 265, Colour_Nintendo_White, title_sound);
  786. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 800, box.y + 265, sound_sound ? Colour_Nintendo_Cyan : Colour_Nintendo_Silver, "%s", sound_sound ? "On" : "Off");
  787. ui_draw_spacers(box.x + 350, box.y + 265, 23);
  788. if (!left_column && r_cursor == 1)
  789. ui_draw_highlight_box(&pulse_shape, box.x + 350, box.y + 265, 550, 40);
  790. for (int i = 0, y = box.y + 315; i < 1; i++, y+= 25)
  791. {
  792. SDL_DrawText(FONT_TEXT[QFontSize_15].fnt, box.x + 350, y, Colour_Nintendo_BrightSilver, "%s", expl_snd[i]);
  793. }
  794. break;
  795. }
  796. case 2:
  797. {
  798. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, box.x + 350, box.y + 135, Colour_Nintendo_BrightSilver, "Exit the settings menu.");
  799. }
  800. default:
  801. {
  802. break;
  803. }
  804. }
  805. SDL_UpdateRenderer();
  806. }
  807. }
  808. bool ui_display_yes_no_box(const char *message)
  809. {
  810. uint8_t cursor = 1;
  811. bool flag = false;
  812. PulseShape_t pulse_shape = { { {0, 255, 187, 255} , false, 0 }, { 0 } };
  813. while (appletMainLoop())
  814. {
  815. input_t input = get_input();
  816. if (input.down & HidNpadButton_AnyRight)
  817. cursor = 1;
  818. if (input.down & HidNpadButton_AnyLeft)
  819. cursor = 0;
  820. int ret = check_if_touch_yesno(&input);
  821. if (ret != -1)
  822. {
  823. cursor = ret;
  824. input.down |= HidNpadButton_A;
  825. }
  826. if (input.down & HidNpadButton_A)
  827. {
  828. flag = cursor;
  829. break;
  830. }
  831. if (input.down & HidNpadButton_B)
  832. {
  833. flag = false;
  834. break;
  835. }
  836. ui_display_dim_background();
  837. // The pop up shape.
  838. SDL_Rect box = { 255, 210, 770, 295 };
  839. SDL_DrawShape(Colour_Nintendo_DarkGrey, box.x, box.y, box.w, box.h, true);
  840. // display the message.
  841. SDL_DrawTextCenterX(FONT_TEXT[QFontSize_25].fnt, box.y + 110, box.x, box.w, Colour_Nintendo_White, message);
  842. //
  843. SDL_DrawShape(Colour_Nintendo_LightSilver, box.x, (box.y + box.h) - 72, 770, 2, true);
  844. SDL_DrawShapeOutlineEX(pulse_shape.pulse.col.r, pulse_shape.pulse.col.g, pulse_shape.pulse.col.b, pulse_shape.pulse.col.a, cursor ? box.x + 380 : 250, box.y + 220, 390, 75, 5);
  845. SDL_DrawTextCenterX(FONT_TEXT[QFontSize_25].fnt, (box.y + box.h) - 50, box.x + (box.w / 2), box.w / 2, Colour_Nintendo_Cyan, "OK");
  846. SDL_DrawTextCenterX(FONT_TEXT[QFontSize_25].fnt, (box.y + box.h) - 50, box.x, box.w / 2, Colour_Nintendo_Cyan, "Back");
  847. update_pulse_colour(&pulse_shape.pulse);
  848. SDL_UpdateRenderer();
  849. }
  850. return flag;
  851. }
  852. void ui_display_error_box(ErrorCodes err, const char *func)
  853. {
  854. if (!is_backlight_enabled())
  855. {
  856. enable_backlight(BacklightFade_Instant);
  857. }
  858. // play the error sound effect.
  859. play_sound(g_sound_effects.error, -1, 0);
  860. // display the popup box.
  861. ui_display_popup_box();
  862. SDL_Rect box = { 455, 470, 365, 65 };
  863. SDL_DrawButton(FONT_BUTTON[QFontSize_63].fnt, 0xE140, 608, 180, Colour_Nintendo_Red);
  864. SDL_DrawText(FONT_TEXT[QFontSize_25].fnt, 520, 270, Colour_Nintendo_White, "Error code: 0x%04X", err);
  865. SDL_DrawTextCenterX(FONT_TEXT[QFontSize_23].fnt, 325, box.x, box.w, Colour_Nintendo_White, "%s in %s()", error_get_description(err), func);
  866. SDL_DrawText(FONT_TEXT[QFontSize_20].fnt, 340, 380, Colour_Nintendo_BrightSilver, "If this message appears repeatedly, please open an issue.");
  867. SDL_DrawText(FONT_TEXT[QFontSize_20].fnt, 320, 415, Colour_Nintendo_BrightSilver, "https://github.com/ITotalJustice/Gamecard-Installer-NX/issues");
  868. SDL_DrawShapeOutline(Colour_Nintendo_Cyan, box.x, box.y, box.w, box.h, 5);
  869. SDL_DrawText(FONT_TEXT[QFontSize_23].fnt, 620, box.y + 25, Colour_Nintendo_White, "OK");
  870. // update the screen.
  871. SDL_UpdateRenderer();
  872. // delay for 1 second so that users will see the error, even if they're mashing buttons.
  873. SDL_Delay(1000);
  874. // loop until the user selects okay!
  875. while (appletMainLoop())
  876. {
  877. if (check_if_touch_error())
  878. break;
  879. }
  880. }
  881. progress_bar_t *ui_init_progress_bar(const char *name, uint64_t speed, uint16_t eta_min, uint8_t eta_sec, size_t done, size_t remaining)
  882. {
  883. progress_bar_t *p_bar = calloc(1, sizeof(progress_bar_t));
  884. if (!p_bar) return NULL;
  885. // shapes.
  886. SDL_Rect prog_bar = { 400, 470, 480, 12 };
  887. p_bar->empty_bar = create_shape(Colour_Nintendo_LightSilver, prog_bar.x, prog_bar.y, prog_bar.w, prog_bar.h, true);
  888. p_bar->filled_bar = create_shape(Colour_Nintendo_Cyan, prog_bar.x, prog_bar.y, ((float)done / (float)remaining) * prog_bar.w, prog_bar.h, true);
  889. // text.
  890. p_bar->text_header = create_text(&FONT_TEXT[QFontSize_25], 575, 200, Colour_Nintendo_White, "Installing...");
  891. p_bar->text_warning1 = create_text(&FONT_TEXT[QFontSize_20], 500, 260, Colour_Nintendo_BrightSilver, "Please do not remove the gamecard or");
  892. p_bar->text_warning2 = create_text(&FONT_TEXT[QFontSize_20], 500, 295, Colour_Nintendo_BrightSilver, "power off the system whilst installing.");
  893. p_bar->text_speed = create_text(&FONT_TEXT[QFontSize_20], 325, 360, Colour_Nintendo_White, "%.2f MiB/s", speed);
  894. p_bar->text_name = create_text(&FONT_TEXT[QFontSize_20], 410, 420, Colour_Nintendo_White, "%s", name);
  895. p_bar->text_time = create_text(&FONT_TEXT[QFontSize_20], prog_bar.x + 85, prog_bar.y + 40, Colour_Nintendo_White, "%d %s %d seconds remaining", eta_min, eta_min != 1 ? "minutes" : "minute", eta_sec);
  896. // vars.
  897. p_bar->speed = speed;
  898. p_bar->eta_min = eta_min;
  899. p_bar->eta_sec = eta_sec;
  900. return p_bar;
  901. }
  902. void ui_free_progress_bar(progress_bar_t *p_bar)
  903. {
  904. if (!p_bar) return;
  905. free_text(p_bar->text_header);
  906. free_text(p_bar->text_warning1);
  907. free_text(p_bar->text_warning2);
  908. free_text(p_bar->text_name);
  909. free_text(p_bar->text_speed);
  910. free_text(p_bar->text_time);
  911. free(p_bar);
  912. p_bar = NULL;
  913. }
  914. void ui_update_progress_bar(progress_bar_t *p_bar, uint64_t speed, uint16_t eta_min, uint8_t eta_sec, size_t done, size_t remaining)
  915. {
  916. if (!p_bar) return;
  917. // shapes.
  918. p_bar->filled_bar.info.rect.w = ((float)done / (float)remaining) * p_bar->empty_bar.info.rect.w;
  919. // text.
  920. if (p_bar->speed != speed)
  921. update_text(p_bar->text_speed, "%.2f MiB/s", (float)speed / 0x100000);
  922. if (p_bar->eta_sec != eta_sec || p_bar->eta_min != eta_min)
  923. update_text(p_bar->text_time, "%d %s %d seconds remaining", eta_min, eta_min != 1 ? "minutes" : "minute", eta_sec);
  924. // vars.
  925. p_bar->speed = speed;
  926. p_bar->eta_min = eta_min;
  927. p_bar->eta_sec = eta_sec;
  928. }
  929. void ui_display_progress_bar(progress_bar_t *p_bar)
  930. {
  931. // display the popup box.
  932. ui_display_popup_box();
  933. // Title and warning text.
  934. draw_text(p_bar->text_header);
  935. draw_text(p_bar->text_warning1);
  936. draw_text(p_bar->text_warning2);
  937. // game icon and speed.
  938. if (g_game_info.icon)
  939. {
  940. draw_image_set(g_game_info.icon, 320, 200, g_game_info.icon->rect.w / 2, g_game_info.icon->rect.h / 2);
  941. }
  942. else
  943. {
  944. draw_image_set(g_empty_icon, 320, 200, g_empty_icon->rect.w / 2, g_empty_icon->rect.h / 2);
  945. }
  946. draw_text(p_bar->text_speed);
  947. draw_text(p_bar->text_name);
  948. draw_text(p_bar->text_time);
  949. // nca name and progress bar.
  950. draw_shape(&p_bar->empty_bar);
  951. draw_shape(&p_bar->filled_bar);
  952. // now update the renderer with the progress bar.
  953. SDL_UpdateRenderer();
  954. }
  955. void render_menu(void)
  956. {
  957. ui_display_background();
  958. ui_display_storage_size();
  959. ui_display_option_list();
  960. ui_display_gamecard();
  961. ui_display_button_spin();
  962. }
  963. /*
  964. * Basic input handling.
  965. */
  966. uint8_t handle_input(void)
  967. {
  968. input_t input = get_input();
  969. if (input.down)
  970. {
  971. update_button_spin();
  972. }
  973. int ret = check_if_option(&input);
  974. if (ret != -1)
  975. {
  976. g_cursor = ret;
  977. update_options();
  978. input.down |= HidNpadButton_A;
  979. }
  980. if (input.down & HidNpadButton_AnyDown)
  981. {
  982. g_cursor = move_cursor_down(g_cursor, 3);
  983. play_sound(g_sound_effects.move, -1, 0);
  984. }
  985. else if (input.down & HidNpadButton_AnyUp)
  986. {
  987. g_cursor = move_cursor_up(g_cursor, 3);
  988. play_sound(g_sound_effects.move, -1, 0);
  989. }
  990. else if (input.down & HidNpadButton_L)
  991. {
  992. gc_prev_game(&g_game_info);
  993. }
  994. else if (input.down & HidNpadButton_R)
  995. {
  996. gc_next_game(&g_game_info);
  997. }
  998. else if (input.down & HidNpadButton_B)
  999. {
  1000. if (ui_display_yes_no_box("Would you like to exit?"))
  1001. return Option_Exit;
  1002. }
  1003. else if (input.down & HidNpadButton_X)
  1004. {
  1005. play_sound(g_sound_effects.move, -1, 0);
  1006. ui_display_options();
  1007. }
  1008. else if (input.down & HidNpadButton_Y)
  1009. {
  1010. if (g_gc_inserted)
  1011. {
  1012. play_sound(g_sound_effects.move, -1, 0);
  1013. ui_display_detailed_gamecard();
  1014. }
  1015. }
  1016. else if (input.down & HidNpadButton_A)
  1017. {
  1018. play_sound(g_sound_effects.popup, -1, 0);
  1019. switch (g_cursor)
  1020. {
  1021. case Option_Nand:
  1022. if (g_gc_inserted)
  1023. {
  1024. if (ui_display_yes_no_box("Install to the Nand?"))
  1025. {
  1026. gc_install(NcmStorageId_BuiltInUser);
  1027. update_storage_size();
  1028. }
  1029. }
  1030. break;
  1031. case Option_SD:
  1032. if (g_gc_inserted)
  1033. {
  1034. if (ui_display_yes_no_box("Install to the SD Card?"))
  1035. {
  1036. gc_install(NcmStorageId_SdCard);
  1037. update_storage_size();
  1038. }
  1039. }
  1040. break;
  1041. case Option_Exit:
  1042. if (ui_display_yes_no_box("Would you like to exit?"))
  1043. return Option_Exit;
  1044. }
  1045. }
  1046. return 0;
  1047. }
  1048. /*
  1049. * Main.
  1050. */
  1051. void start_menu(void)
  1052. {
  1053. while (appletMainLoop())
  1054. {
  1055. // get input.
  1056. if (handle_input() == Option_Exit)
  1057. {
  1058. break;
  1059. }
  1060. // update stuff.
  1061. update_gamecard();
  1062. update_pulse_colour(&g_options_pulse_bar.pulse);
  1063. update_options();
  1064. // now render the menu.
  1065. SDL_ClearRenderer();
  1066. render_menu();
  1067. SDL_UpdateRenderer();
  1068. }
  1069. }