xtruan 2 лет назад
Родитель
Сommit
07a18d860f

+ 2 - 0
flipchess.c

@@ -81,6 +81,8 @@ FlipChess* flipchess_app_alloc() {
     app->white_mode = FlipChessPlayerHuman;
     app->black_mode = FlipChessPlayerAI1;
 
+    // Startscreen
+    app->sound = 0;
     // Main menu
     app->import_game = 0;
 

+ 2 - 0
flipchess.h

@@ -35,6 +35,8 @@ typedef struct {
     int haptic;
     int white_mode;
     int black_mode;
+    // Startscreen options
+    uint8_t sound;
     // Main menu options
     uint8_t import_game;
     // Text input

+ 19 - 7
helpers/flipchess_voice.cpp

@@ -4,22 +4,34 @@
 #include "../sam/stm32_sam.h"
 STM32SAM voice;
 
-int32_t flipchess_voice_game(void* p) {
-    UNUSED(p);
+void flipchess_voice_shall_we_play() {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
         voice.begin();
         voice.say("SHAAL WE PLAY AY GAME?");
         furi_hal_speaker_release();
     }
-    return 0;
 }
 
-int32_t flipchess_voice_no(void* p) {
-    UNUSED(p);
+void flipchess_voice_which_side() {
     if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
         voice.begin();
-        voice.say("No");
+        voice.say("WHICH SIDE DO YOU WANT?");
+        furi_hal_speaker_release();
+    }
+}
+
+void flipchess_voice_how_about_chess() {
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+        voice.begin();
+        voice.say("HOW ABOUT A NICE GAME OF CHESS?");
+        furi_hal_speaker_release();
+    }
+}
+
+void flipchess_voice_a_strange_game() {
+    if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(1000)) {
+        voice.begin();
+        voice.say("A STRANGE GAME... THE ONLY WINNING MOVE IS NOT TO PLAY.");
         furi_hal_speaker_release();
     }
-    return 0;
 }

+ 4 - 4
helpers/flipchess_voice.h

@@ -1,12 +1,12 @@
-#include <stdint.h>
-
 #ifdef __cplusplus
 #define EXTERNC extern "C"
 #else
 #define EXTERNC
 #endif
 
-EXTERNC int32_t flipchess_voice_game(void* p);
-EXTERNC int32_t flipchess_voice_no(void* p);
+EXTERNC void flipchess_voice_shall_we_play();
+EXTERNC void flipchess_voice_which_side();
+EXTERNC void flipchess_voice_how_about_chess();
+EXTERNC void flipchess_voice_a_strange_game();
 
 #undef EXTERNC

+ 2 - 2
scenes/flipchess_scene_menu.c

@@ -16,8 +16,8 @@ void flipchess_scene_menu_submenu_callback(void* context, uint32_t index) {
 void flipchess_scene_menu_on_enter(void* context) {
     FlipChess* app = context;
 
-    if(app->haptic == 1) {
-        flipchess_voice_game(NULL);
+    if(app->sound == 1) {
+        flipchess_voice_shall_we_play();
     }
 
     submenu_add_item(

+ 6 - 0
scenes/flipchess_scene_scene_1.c

@@ -1,4 +1,5 @@
 #include "../flipchess.h"
+#include "../helpers/flipchess_voice.h"
 #include "../helpers/flipchess_custom_event.h"
 #include "../views/flipchess_scene_1.h"
 
@@ -11,6 +12,11 @@ void flipchess_scene_1_callback(FlipChessCustomEvent event, void* context) {
 void flipchess_scene_scene_1_on_enter(void* context) {
     furi_assert(context);
     FlipChess* app = context;
+
+    if(app->sound == 1) {
+        flipchess_voice_how_about_chess();
+    }
+
     flipchess_scene_1_set_callback(app->flipchess_scene_1, flipchess_scene_1_callback, app);
     view_dispatcher_switch_to_view(app->view_dispatcher, FlipChessViewIdScene1);
 }

+ 5 - 0
scenes/flipchess_scene_settings.c

@@ -1,4 +1,5 @@
 #include "../flipchess.h"
+#include "../helpers/flipchess_voice.h"
 #include <lib/toolbox/value_index.h>
 
 #define TEXT_LABEL_ON "ON"
@@ -57,6 +58,10 @@ void flipchess_scene_settings_on_enter(void* context) {
     VariableItem* item;
     uint8_t value_index;
 
+    if(app->sound == 1) {
+        flipchess_voice_which_side();
+    }
+
     // White mode
     item = variable_item_list_add(
         app->variable_item_list, "White:", 4, flipchess_scene_settings_set_white_mode, app);

+ 18 - 2
views/flipchess_startscreen.c

@@ -46,7 +46,8 @@ void flipchess_startscreen_draw(Canvas* canvas, FlipChessStartscreenModel* model
     //canvas_draw_icon(canvas, 0, 40, &I_Background_128x11);
     //canvas_draw_str(canvas, 10, 61, "FLIPR");
 
-    elements_button_center(canvas, "Start");
+    elements_button_center(canvas, "Sound");
+    elements_button_right(canvas, "Silent");
 }
 
 static void flipchess_startscreen_model_init(FlipChessStartscreenModel* const model) {
@@ -56,6 +57,8 @@ static void flipchess_startscreen_model_init(FlipChessStartscreenModel* const mo
 bool flipchess_startscreen_input(InputEvent* event, void* context) {
     furi_assert(context);
     FlipChessStartscreen* instance = context;
+    FlipChess* app = instance->context;
+
     if(event->type == InputTypeRelease) {
         switch(event->key) {
         case InputKeyBack:
@@ -69,10 +72,23 @@ bool flipchess_startscreen_input(InputEvent* event, void* context) {
                 true);
             break;
         case InputKeyLeft:
-        case InputKeyRight:
         case InputKeyUp:
         case InputKeyDown:
         case InputKeyOk:
+            // sound on
+            app->sound = 1;
+            with_view_model(
+                instance->view,
+                FlipChessStartscreenModel * model,
+                {
+                    UNUSED(model);
+                    instance->callback(FlipChessCustomEventStartscreenOk, instance->context);
+                },
+                true);
+            break;
+        case InputKeyRight:
+            // sound off
+            app->sound = 0;
             with_view_model(
                 instance->view,
                 FlipChessStartscreenModel * model,