From d7cad6b0994c8f8f017b80ce77cf677d41c1b092 Mon Sep 17 00:00:00 2001 From: squee72564 Date: Mon, 1 Jan 2024 20:48:44 -0800 Subject: [PATCH] Added temporary scene management for testing --- scenes/confirmation_scene.c | 80 +++++++++++++++++++++++++++++++++++++ scenes/settings_scene.c | 12 +++--- 2 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 scenes/confirmation_scene.c diff --git a/scenes/confirmation_scene.c b/scenes/confirmation_scene.c new file mode 100644 index 0000000..3277e20 --- /dev/null +++ b/scenes/confirmation_scene.c @@ -0,0 +1,80 @@ +#include "../minesweeper.h" +#include "../views/minesweeper_game_screen.h" + +static void confirmation_scene_dialog_callback(DialogExResult result, void* context) { + furi_assert(context); + + MineSweeperApp* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, result); +} + +void minesweeper_scene_confirmation_screen_on_enter(void* context) { + furi_assert(context); + MineSweeperApp* app = (MineSweeperApp*)context; + + view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView); + + dialog_ex_set_context(app->confirmation_screen, app); + + dialog_ex_set_header(app->confirmation_screen, "Save Settings?", 128/2, 4, AlignCenter, AlignTop); + + dialog_ex_set_text(app->confirmation_screen, "Warning: Saving will reset\nthe game with the\nselected settings.", 128/2, 64/2, AlignCenter, AlignCenter); + + dialog_ex_set_left_button_text(app->confirmation_screen, "Back"); + + dialog_ex_set_right_button_text(app->confirmation_screen, "Save and Reset"); + + dialog_ex_set_result_callback(app->confirmation_screen, confirmation_scene_dialog_callback); + + view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperConfirmationView); +} + +bool minesweeper_scene_confirmation_screen_on_event(void* context, SceneManagerEvent event) { + furi_assert(context); + + MineSweeperApp* app = context; + bool consumed = false; + + if (event.type == SceneManagerEventTypeCustom) { + switch (event.event) { + + case DialogExResultLeft : + if (!scene_manager_search_and_switch_to_previous_scene( + app->scene_manager, MineSweeperSceneSettingsScreen)) { + + scene_manager_stop(app->scene_manager); + view_dispatcher_stop(app->view_dispatcher); + } + break; + + case DialogExResultRight : + + view_dispatcher_switch_to_view(app->view_dispatcher, MineSweeperLoadingView); + + // Commit changes to actual buffer for settings data + + // Reset the game board + mine_sweeper_game_screen_reset(app->game_screen); + + // Go to reset game view + scene_manager_search_and_switch_to_another_scene(app->scene_manager, MineSweeperSceneGameScreen); + break; + + case DialogExResultCenter : + break; + + default : + break; + } + consumed = true; + } + + return consumed; +} + +void minesweeper_scene_confirmation_screen_on_exit(void* context) { + furi_assert(context); + MineSweeperApp* app = (MineSweeperApp*)context; + + dialog_ex_reset(app->confirmation_screen); +} diff --git a/scenes/settings_scene.c b/scenes/settings_scene.c index 88aa9b0..dbc767d 100644 --- a/scenes/settings_scene.c +++ b/scenes/settings_scene.c @@ -249,13 +249,15 @@ bool minesweeper_scene_settings_screen_on_event(void* context, SceneManagerEvent } else if (event.type == SceneManagerEventTypeBack) { - if (!scene_manager_search_and_switch_to_previous_scene( - app->scene_manager, MineSweeperSceneMenuScreen)) { + scene_manager_next_scene(app->scene_manager, MineSweeperSceneConfirmationScreen); - scene_manager_stop(app->scene_manager); - view_dispatcher_stop(app->view_dispatcher); + //if (!scene_manager_search_and_switch_to_previous_scene( + // app->scene_manager, MineSweeperSceneMenuScreen)) { - } + // scene_manager_stop(app->scene_manager); + // view_dispatcher_stop(app->view_dispatcher); + + //} consumed = true; }