confirmation_scene.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "../minesweeper.h"
  2. static void confirmation_scene_dialog_callback(DialogExResult result, void* context) {
  3. furi_assert(context);
  4. MineSweeperApp* app = context;
  5. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  6. }
  7. void minesweeper_scene_confirmation_screen_on_enter(void* context) {
  8. furi_assert(context);
  9. MineSweeperApp* app = (MineSweeperApp*)context;
  10. view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView);
  11. dialog_ex_set_context(app->confirmation_screen, app);
  12. dialog_ex_set_header(
  13. app->confirmation_screen, "Save Settings?", 128 / 2, 4, AlignCenter, AlignTop);
  14. dialog_ex_set_text(
  15. app->confirmation_screen,
  16. "Warning: Saving will reset\nthe game with the\nselected settings.",
  17. 128 / 2,
  18. 64 / 2,
  19. AlignCenter,
  20. AlignCenter);
  21. dialog_ex_set_left_button_text(app->confirmation_screen, "Back");
  22. dialog_ex_set_center_button_text(app->confirmation_screen, "Cancel");
  23. dialog_ex_set_right_button_text(app->confirmation_screen, "Save");
  24. dialog_ex_set_result_callback(app->confirmation_screen, confirmation_scene_dialog_callback);
  25. view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperConfirmationView);
  26. }
  27. bool minesweeper_scene_confirmation_screen_on_event(void* context, SceneManagerEvent event) {
  28. furi_assert(context);
  29. MineSweeperApp* app = context;
  30. bool consumed = false;
  31. if(event.type == SceneManagerEventTypeCustom) {
  32. switch(event.event) {
  33. case DialogExResultLeft:
  34. if(!scene_manager_search_and_switch_to_previous_scene(
  35. app->scene_manager, MineSweeperSceneSettingsScreen)) {
  36. scene_manager_stop(app->scene_manager);
  37. view_dispatcher_stop(app->view_dispatcher);
  38. }
  39. break;
  40. case DialogExResultRight:
  41. view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView);
  42. // Commit changes to actual buffer for settings data
  43. app->settings_info.board_width = app->t_settings_info.board_width;
  44. app->settings_info.board_height = app->t_settings_info.board_height;
  45. app->settings_info.difficulty = app->t_settings_info.difficulty;
  46. app->settings_info.ensure_solvable_board = app->t_settings_info.ensure_solvable_board;
  47. mine_sweeper_save_settings(app);
  48. // This is used to let the settings view know it can save the main settings_info
  49. // to the temp one on the next on enter
  50. app->is_settings_changed = false;
  51. // Reset the game board
  52. mine_sweeper_game_screen_reset(
  53. app->game_screen,
  54. app->settings_info.board_width,
  55. app->settings_info.board_height,
  56. app->settings_info.difficulty,
  57. app->settings_info.ensure_solvable_board);
  58. // Go to reset game view
  59. scene_manager_search_and_switch_to_another_scene(
  60. app->scene_manager, MineSweeperSceneGameScreen);
  61. break;
  62. case DialogExResultCenter:
  63. // Do not commit changes to actual buffer on cancel
  64. app->is_settings_changed = false;
  65. // we want to just switch back to the game screen without resetting
  66. scene_manager_search_and_switch_to_another_scene(
  67. app->scene_manager, MineSweeperSceneGameScreen);
  68. break;
  69. default:
  70. break;
  71. }
  72. consumed = true;
  73. }
  74. return consumed;
  75. }
  76. void minesweeper_scene_confirmation_screen_on_exit(void* context) {
  77. furi_assert(context);
  78. MineSweeperApp* app = (MineSweeperApp*)context;
  79. dialog_ex_reset(app->confirmation_screen);
  80. }