Просмотр исходного кода

add game submenu (pvp, pve, story)

jblanked 11 месяцев назад
Родитель
Сommit
195321e2dc
3 измененных файлов с 69 добавлено и 40 удалено
  1. 17 3
      alloc/alloc.c
  2. 46 36
      callback/callback.c
  3. 6 1
      flip_world.h

+ 17 - 3
alloc/alloc.c

@@ -16,7 +16,8 @@ void *global_app;
 void flip_world_show_submenu()
 {
     FlipWorldApp *app = (FlipWorldApp *)global_app;
-    if (app->submenu) {
+    if (app->submenu)
+    {
         view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
     }
 }
@@ -51,10 +52,17 @@ FlipWorldApp *flip_world_app_alloc()
     {
         return NULL;
     }
-    submenu_add_item(app->submenu, "Play", FlipWorldSubmenuIndexRun, callback_submenu_choices, app);
+    if (!easy_flipper_set_submenu(&app->submenu_game, FlipWorldViewGameSubmenu, "Play", callback_to_submenu, &app->view_dispatcher))
+    {
+        return NULL;
+    }
+    submenu_add_item(app->submenu, "Play", FlipWorldSubmenuIndexGameSubmenu, callback_submenu_choices, app);
     submenu_add_item(app->submenu, "About", FlipWorldSubmenuIndexMessage, callback_submenu_choices, app);
     submenu_add_item(app->submenu, "Settings", FlipWorldSubmenuIndexSettings, callback_submenu_choices, app);
     //
+    submenu_add_item(app->submenu_game, "Story", FlipWorldSubmenuIndexStory, callback_submenu_choices, app);
+    submenu_add_item(app->submenu_game, "PvP", FlipWorldSubmenuIndexPvP, callback_submenu_choices, app);
+    submenu_add_item(app->submenu_game, "PvE", FlipWorldSubmenuIndexPvE, callback_submenu_choices, app);
 
     // Switch to the main view
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewSubmenu);
@@ -77,6 +85,11 @@ void flip_world_app_free(FlipWorldApp *app)
         view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewSubmenu);
         submenu_free(app->submenu);
     }
+    if (app->submenu_game)
+    {
+        view_dispatcher_remove_view(app->view_dispatcher, FlipWorldViewGameSubmenu);
+        submenu_free(app->submenu_game);
+    }
     // Free Widget(s)
     if (app->widget_result)
     {
@@ -101,5 +114,6 @@ void flip_world_app_free(FlipWorldApp *app)
     furi_record_close(RECORD_GUI);
 
     // free the app
-    if (app) free(app);
+    if (app)
+        free(app);
 }

+ 46 - 36
callback/callback.c

@@ -11,7 +11,7 @@
 // FURI_LOG_DEV will log only during app development. Be sure that Settings/System/Log Device is "LPUART"; so we dont use serial port.
 #ifdef DEVELOPMENT
 #define FURI_LOG_DEV(tag, format, ...) furi_log_print_format(FuriLogLevelInfo, tag, format, ##__VA_ARGS__)
-#define DEV_CRASH()                    furi_crash()
+#define DEV_CRASH() furi_crash()
 #else
 #define FURI_LOG_DEV(tag, format, ...)
 #define DEV_CRASH()
@@ -430,7 +430,7 @@ static bool alloc_variable_item_list(void *context, uint32_t view_id)
             char _game_fps[8];
             if (load_char("Game-FPS", _game_fps, sizeof(_game_fps)))
             {
-                                int index = is_str(_game_fps, "30") ? 0 : is_str(_game_fps, "60") ? 1
+                int index = is_str(_game_fps, "30") ? 0 : is_str(_game_fps, "60") ? 1
                                                       : is_str(_game_fps, "120")  ? 2
                                                       : is_str(_game_fps, "240")  ? 3
                                                                                   : 0;
@@ -441,20 +441,19 @@ static bool alloc_variable_item_list(void *context, uint32_t view_id)
             if (load_char("Game-VGM-X", _game_vgm_x, sizeof(_game_vgm_x)))
             {
                 int vgm_x = atoi(_game_vgm_x);
-                int index = vgm_x == -2 ? 0 :
-                            vgm_x == -1 ? 1 :
-                            vgm_x == 0  ? 2 :
-                            vgm_x == 1  ? 3 :
-                            vgm_x == 2  ? 4 :
-                            vgm_x == 3  ? 5 :
-                            vgm_x == 4  ? 6 :
-                            vgm_x == 5  ? 7 :
-                            vgm_x == 6  ? 8 :
-                            vgm_x == 7  ? 9 :
-                            vgm_x == 8  ? 10 :
-                            vgm_x == 9  ? 11 :
-                            vgm_x == 10 ? 12 :
-                                          2;
+                int index = vgm_x == -2 ? 0 : vgm_x == -1 ? 1
+                                          : vgm_x == 0    ? 2
+                                          : vgm_x == 1    ? 3
+                                          : vgm_x == 2    ? 4
+                                          : vgm_x == 3    ? 5
+                                          : vgm_x == 4    ? 6
+                                          : vgm_x == 5    ? 7
+                                          : vgm_x == 6    ? 8
+                                          : vgm_x == 7    ? 9
+                                          : vgm_x == 8    ? 10
+                                          : vgm_x == 9    ? 11
+                                          : vgm_x == 10   ? 12
+                                                          : 2;
                 variable_item_set_current_value_index(app->variable_item_game_vgm_x, index);
                 variable_item_set_current_value_text(app->variable_item_game_vgm_x, vgm_levels[index]);
             }
@@ -462,41 +461,43 @@ static bool alloc_variable_item_list(void *context, uint32_t view_id)
             if (load_char("Game-VGM-Y", _game_vgm_y, sizeof(_game_vgm_y)))
             {
                 int vgm_y = atoi(_game_vgm_y);
-                int index = vgm_y == -2 ? 0 :
-                            vgm_y == -1 ? 1 :
-                            vgm_y == 0  ? 2 :
-                            vgm_y == 1  ? 3 :
-                            vgm_y == 2  ? 4 :
-                            vgm_y == 3  ? 5 :
-                            vgm_y == 4  ? 6 :
-                            vgm_y == 5  ? 7 :
-                            vgm_y == 6  ? 8 :
-                            vgm_y == 7  ? 9 :
-                            vgm_y == 8  ? 10 :
-                            vgm_y == 9  ? 11 :
-                            vgm_y == 10 ? 12 :
-                                          2;
+                int index = vgm_y == -2 ? 0 : vgm_y == -1 ? 1
+                                          : vgm_y == 0    ? 2
+                                          : vgm_y == 1    ? 3
+                                          : vgm_y == 2    ? 4
+                                          : vgm_y == 3    ? 5
+                                          : vgm_y == 4    ? 6
+                                          : vgm_y == 5    ? 7
+                                          : vgm_y == 6    ? 8
+                                          : vgm_y == 7    ? 9
+                                          : vgm_y == 8    ? 10
+                                          : vgm_y == 9    ? 11
+                                          : vgm_y == 10   ? 12
+                                                          : 2;
                 variable_item_set_current_value_index(app->variable_item_game_vgm_y, index);
                 variable_item_set_current_value_text(app->variable_item_game_vgm_y, vgm_levels[index]);
             }
             char _game_screen_always_on[8];
             if (load_char("Game-Screen-Always-On", _game_screen_always_on, sizeof(_game_screen_always_on)))
             {
-                int index = is_str(_game_screen_always_on, "No") ? 0 : is_str(_game_screen_always_on, "Yes") ? 1 : 0;
+                int index = is_str(_game_screen_always_on, "No") ? 0 : is_str(_game_screen_always_on, "Yes") ? 1
+                                                                                                             : 0;
                 variable_item_set_current_value_text(app->variable_item_game_screen_always_on, yes_or_no_choices[index]);
                 variable_item_set_current_value_index(app->variable_item_game_screen_always_on, index);
             }
             char _game_sound_on[8];
             if (load_char("Game-Sound-On", _game_sound_on, sizeof(_game_sound_on)))
             {
-                int index = is_str(_game_sound_on, "No") ? 0 : is_str(_game_sound_on, "Yes") ? 1 : 0;
+                int index = is_str(_game_sound_on, "No") ? 0 : is_str(_game_sound_on, "Yes") ? 1
+                                                                                             : 0;
                 variable_item_set_current_value_text(app->variable_item_game_sound_on, yes_or_no_choices[index]);
                 variable_item_set_current_value_index(app->variable_item_game_sound_on, index);
             }
             char _game_vibration_on[8];
             if (load_char("Game-Vibration-On", _game_vibration_on, sizeof(_game_vibration_on)))
             {
-                int index = is_str(_game_vibration_on, "No") ? 0 : is_str(_game_vibration_on, "Yes") ? 1 : 0;
+                int index = is_str(_game_vibration_on, "No") ? 0 : is_str(_game_vibration_on, "Yes") ? 1
+                                                                                                     : 0;
                 variable_item_set_current_value_text(app->variable_item_game_vibration_on, yes_or_no_choices[index]);
                 variable_item_set_current_value_index(app->variable_item_game_vibration_on, index);
             }
@@ -737,7 +738,8 @@ void free_all_views(void *context, bool should_free_variable_item_list, bool sho
         }
     }
 
-    if (should_free_submenu_settings) free_submenu_settings(app);
+    if (should_free_submenu_settings)
+        free_submenu_settings(app);
 }
 static bool fetch_world_list(FlipperHTTP *fhttp)
 {
@@ -1187,7 +1189,16 @@ void callback_submenu_choices(void *context, uint32_t index)
     }
     switch (index)
     {
-    case FlipWorldSubmenuIndexRun:
+    case FlipWorldSubmenuIndexGameSubmenu:
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipWorldViewGameSubmenu);
+        break;
+    case FlipWorldSubmenuIndexStory:
+        easy_flipper_dialog("Unavailable", "\nStory mode is not ready yet.\nPress BACK to return.");
+        break;
+    case FlipWorldSubmenuIndexPvP:
+        easy_flipper_dialog("Unavailable", "\nPvP mode is not ready yet.\nPress BACK to return.");
+        break;
+    case FlipWorldSubmenuIndexPvE:
         free_all_views(app, true, true);
         if (!is_enough_heap(60000))
         {
@@ -1248,7 +1259,6 @@ void callback_submenu_choices(void *context, uint32_t index)
                 easy_flipper_dialog("Error", "Failed to start game thread. Press BACK to return.");
                 return;
             }
-            
         }
         else
         {

+ 6 - 1
flip_world.h

@@ -21,7 +21,10 @@
 // Define the submenu items for our FlipWorld application
 typedef enum
 {
-    FlipWorldSubmenuIndexRun, // Click to run the FlipWorld application
+    FlipWorldSubmenuIndexPvE,
+    FlipWorldSubmenuIndexStory,
+    FlipWorldSubmenuIndexPvP,
+    FlipWorldSubmenuIndexGameSubmenu,
     FlipWorldSubmenuIndexMessage,
     FlipWorldSubmenuIndexSettings,
     FlipWorldSubmenuIndexWiFiSettings,
@@ -33,6 +36,7 @@ typedef enum
 typedef enum
 {
     FlipWorldViewSubmenu,          // The submenu
+    FlipWorldViewGameSubmenu,      // The game submenu
     FlipWorldViewMessage,          // The about, loading screen
     FlipWorldViewSettings,         // The settings screen
     FlipWorldViewVariableItemList, // The variable item list screen
@@ -58,6 +62,7 @@ typedef struct
     ViewDispatcher *view_dispatcher;       // Switches between our views
     View *view_message;                    // The about, loading screen
     Submenu *submenu;                      // The submenu
+    Submenu *submenu_game;                 // The game submenu
     Submenu *submenu_settings;             // The settings submenu
     VariableItemList *variable_item_list;  // The variable item list (settngs)
     VariableItem *variable_item_wifi_ssid; // The variable item for WiFi SSID