confirmation_scene.c 3.8 KB

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