mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 18:08:36 -07:00
feat: Chess v1.8
This commit is contained in:
30
applications/external/chess/scenes/flipchess_scene.c
vendored
Normal file
30
applications/external/chess/scenes/flipchess_scene.c
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "flipchess_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const flipchess_on_enter_handlers[])(void*) = {
|
||||
#include "flipchess_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const flipchess_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "flipchess_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const flipchess_on_exit_handlers[])(void* context) = {
|
||||
#include "flipchess_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers flipchess_scene_handlers = {
|
||||
.on_enter_handlers = flipchess_on_enter_handlers,
|
||||
.on_event_handlers = flipchess_on_event_handlers,
|
||||
.on_exit_handlers = flipchess_on_exit_handlers,
|
||||
.scene_num = FlipChessSceneNum,
|
||||
};
|
||||
29
applications/external/chess/scenes/flipchess_scene.h
vendored
Normal file
29
applications/external/chess/scenes/flipchess_scene.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) FlipChessScene##id,
|
||||
typedef enum {
|
||||
#include "flipchess_scene_config.h"
|
||||
FlipChessSceneNum,
|
||||
} FlipChessScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers flipchess_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "flipchess_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "flipchess_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "flipchess_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
4
applications/external/chess/scenes/flipchess_scene_config.h
vendored
Normal file
4
applications/external/chess/scenes/flipchess_scene_config.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
ADD_SCENE(flipchess, startscreen, Startscreen)
|
||||
ADD_SCENE(flipchess, menu, Menu)
|
||||
ADD_SCENE(flipchess, scene_1, Scene_1)
|
||||
ADD_SCENE(flipchess, settings, Settings)
|
||||
91
applications/external/chess/scenes/flipchess_scene_menu.c
vendored
Normal file
91
applications/external/chess/scenes/flipchess_scene_menu.c
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "../flipchess.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexScene1New = 10,
|
||||
SubmenuIndexScene1Resume,
|
||||
SubmenuIndexScene1Import,
|
||||
SubmenuIndexSettings,
|
||||
};
|
||||
|
||||
void flipchess_scene_menu_submenu_callback(void* context, uint32_t index) {
|
||||
FlipChess* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void flipchess_scene_menu_on_enter(void* context) {
|
||||
FlipChess* app = context;
|
||||
|
||||
submenu_add_item(
|
||||
app->submenu,
|
||||
"New Game",
|
||||
SubmenuIndexScene1New,
|
||||
flipchess_scene_menu_submenu_callback,
|
||||
app);
|
||||
|
||||
if(app->import_game == 1) {
|
||||
submenu_add_item(
|
||||
app->submenu,
|
||||
"Resume Game",
|
||||
SubmenuIndexScene1Resume,
|
||||
flipchess_scene_menu_submenu_callback,
|
||||
app);
|
||||
}
|
||||
|
||||
// submenu_add_item(
|
||||
// app->submenu,
|
||||
// "Import Game",
|
||||
// SubmenuIndexScene1Import,
|
||||
// flipchess_scene_menu_submenu_callback,
|
||||
// app);
|
||||
|
||||
submenu_add_item(
|
||||
app->submenu, "Settings", SubmenuIndexSettings, flipchess_scene_menu_submenu_callback, app);
|
||||
|
||||
submenu_set_selected_item(
|
||||
app->submenu, scene_manager_get_scene_state(app->scene_manager, FlipChessSceneMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FlipChessViewIdMenu);
|
||||
}
|
||||
|
||||
bool flipchess_scene_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
FlipChess* app = context;
|
||||
//UNUSED(app);
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
//exit app
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexScene1New) {
|
||||
app->import_game = 0;
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, FlipChessSceneMenu, SubmenuIndexScene1New);
|
||||
scene_manager_next_scene(app->scene_manager, FlipChessSceneScene_1);
|
||||
return true;
|
||||
}
|
||||
if(event.event == SubmenuIndexScene1Resume) {
|
||||
app->import_game = 1;
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, FlipChessSceneMenu, SubmenuIndexScene1Resume);
|
||||
scene_manager_next_scene(app->scene_manager, FlipChessSceneScene_1);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexScene1Import) {
|
||||
app->import_game = 1;
|
||||
app->input_state = FlipChessTextInputGame;
|
||||
text_input_set_header_text(app->text_input, "Enter board FEN");
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FlipChessViewIdTextInput);
|
||||
return true;
|
||||
} else if(event.event == SubmenuIndexSettings) {
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager, FlipChessSceneMenu, SubmenuIndexSettings);
|
||||
scene_manager_next_scene(app->scene_manager, FlipChessSceneSettings);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void flipchess_scene_menu_on_exit(void* context) {
|
||||
FlipChess* app = context;
|
||||
submenu_reset(app->submenu);
|
||||
}
|
||||
55
applications/external/chess/scenes/flipchess_scene_scene_1.c
vendored
Normal file
55
applications/external/chess/scenes/flipchess_scene_scene_1.c
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "../flipchess.h"
|
||||
#include "../helpers/flipchess_file.h"
|
||||
#include "../helpers/flipchess_custom_event.h"
|
||||
#include "../views/flipchess_scene_1.h"
|
||||
|
||||
void flipchess_scene_1_callback(FlipChessCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
FlipChess* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void flipchess_scene_scene_1_on_enter(void* context) {
|
||||
furi_assert(context);
|
||||
FlipChess* app = context;
|
||||
|
||||
flipchess_scene_1_set_callback(app->flipchess_scene_1, flipchess_scene_1_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FlipChessViewIdScene1);
|
||||
}
|
||||
|
||||
bool flipchess_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
|
||||
FlipChess* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case FlipChessCustomEventScene1Left:
|
||||
case FlipChessCustomEventScene1Right:
|
||||
break;
|
||||
case FlipChessCustomEventScene1Up:
|
||||
case FlipChessCustomEventScene1Down:
|
||||
break;
|
||||
case FlipChessCustomEventScene1Back:
|
||||
notification_message(app->notification, &sequence_reset_red);
|
||||
notification_message(app->notification, &sequence_reset_green);
|
||||
notification_message(app->notification, &sequence_reset_blue);
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
app->scene_manager, FlipChessSceneMenu)) {
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void flipchess_scene_scene_1_on_exit(void* context) {
|
||||
FlipChess* app = context;
|
||||
|
||||
if(app->import_game == 1 && strlen(app->import_game_text) > 0) {
|
||||
flipchess_save_file(app->import_game_text, FlipChessFileBoard, NULL, false, true);
|
||||
}
|
||||
}
|
||||
102
applications/external/chess/scenes/flipchess_scene_settings.c
vendored
Normal file
102
applications/external/chess/scenes/flipchess_scene_settings.c
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "../flipchess.h"
|
||||
#include "../helpers/flipchess_voice.h"
|
||||
#include <lib/toolbox/value_index.h>
|
||||
|
||||
#define TEXT_LABEL_ON "ON"
|
||||
#define TEXT_LABEL_OFF "OFF"
|
||||
|
||||
const char* const haptic_text[2] = {
|
||||
TEXT_LABEL_OFF,
|
||||
TEXT_LABEL_ON,
|
||||
};
|
||||
const uint32_t haptic_value[2] = {
|
||||
FlipChessHapticOff,
|
||||
FlipChessHapticOn,
|
||||
};
|
||||
|
||||
const char* const player_mode_text[4] = {
|
||||
"Human",
|
||||
"CPU 1",
|
||||
"CPU 2",
|
||||
"CPU 3",
|
||||
};
|
||||
const uint32_t player_mode_value[4] = {
|
||||
FlipChessPlayerHuman,
|
||||
FlipChessPlayerAI1,
|
||||
FlipChessPlayerAI2,
|
||||
FlipChessPlayerAI3,
|
||||
};
|
||||
|
||||
static void flipchess_scene_settings_set_haptic(VariableItem* item) {
|
||||
FlipChess* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, haptic_text[index]);
|
||||
app->haptic = haptic_value[index];
|
||||
}
|
||||
|
||||
static void flipchess_scene_settings_set_white_mode(VariableItem* item) {
|
||||
FlipChess* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, player_mode_text[index]);
|
||||
app->white_mode = player_mode_value[index];
|
||||
}
|
||||
|
||||
static void flipchess_scene_settings_set_black_mode(VariableItem* item) {
|
||||
FlipChess* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
variable_item_set_current_value_text(item, player_mode_text[index]);
|
||||
app->black_mode = player_mode_value[index];
|
||||
}
|
||||
|
||||
void flipchess_scene_settings_submenu_callback(void* context, uint32_t index) {
|
||||
FlipChess* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void flipchess_scene_settings_on_enter(void* context) {
|
||||
FlipChess* app = 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);
|
||||
value_index = value_index_uint32(app->white_mode, player_mode_value, 4);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, player_mode_text[value_index]);
|
||||
|
||||
// Black mode
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list, "Black:", 4, flipchess_scene_settings_set_black_mode, app);
|
||||
value_index = value_index_uint32(app->black_mode, player_mode_value, 4);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, player_mode_text[value_index]);
|
||||
|
||||
// Vibro on/off
|
||||
item = variable_item_list_add(
|
||||
app->variable_item_list, "Vibro/Haptic:", 2, flipchess_scene_settings_set_haptic, app);
|
||||
value_index = value_index_uint32(app->haptic, haptic_value, 2);
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, haptic_text[value_index]);
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FlipChessViewIdSettings);
|
||||
}
|
||||
|
||||
bool flipchess_scene_settings_on_event(void* context, SceneManagerEvent event) {
|
||||
FlipChess* app = context;
|
||||
UNUSED(app);
|
||||
bool consumed = false;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void flipchess_scene_settings_on_exit(void* context) {
|
||||
FlipChess* app = context;
|
||||
variable_item_list_set_selected_item(app->variable_item_list, 0);
|
||||
variable_item_list_reset(app->variable_item_list);
|
||||
}
|
||||
67
applications/external/chess/scenes/flipchess_scene_startscreen.c
vendored
Normal file
67
applications/external/chess/scenes/flipchess_scene_startscreen.c
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "../flipchess.h"
|
||||
#include "../helpers/flipchess_voice.h"
|
||||
#include "../helpers/flipchess_file.h"
|
||||
#include "../helpers/flipchess_custom_event.h"
|
||||
#include "../views/flipchess_startscreen.h"
|
||||
|
||||
void flipchess_scene_startscreen_callback(FlipChessCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
FlipChess* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void flipchess_scene_startscreen_on_enter(void* context) {
|
||||
furi_assert(context);
|
||||
FlipChess* app = context;
|
||||
|
||||
if(flipchess_has_file(FlipChessFileBoard, NULL, false)) {
|
||||
if(flipchess_load_file(app->import_game_text, FlipChessFileBoard, NULL)) {
|
||||
app->import_game = 1;
|
||||
}
|
||||
}
|
||||
|
||||
flipchess_startscreen_set_callback(
|
||||
app->flipchess_startscreen, flipchess_scene_startscreen_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, FlipChessViewIdStartscreen);
|
||||
}
|
||||
|
||||
bool flipchess_scene_startscreen_on_event(void* context, SceneManagerEvent event) {
|
||||
FlipChess* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case FlipChessCustomEventStartscreenLeft:
|
||||
case FlipChessCustomEventStartscreenRight:
|
||||
break;
|
||||
case FlipChessCustomEventStartscreenUp:
|
||||
case FlipChessCustomEventStartscreenDown:
|
||||
break;
|
||||
case FlipChessCustomEventStartscreenOk:
|
||||
scene_manager_next_scene(app->scene_manager, FlipChessSceneMenu);
|
||||
consumed = true;
|
||||
break;
|
||||
case FlipChessCustomEventStartscreenBack:
|
||||
notification_message(app->notification, &sequence_reset_red);
|
||||
notification_message(app->notification, &sequence_reset_green);
|
||||
notification_message(app->notification, &sequence_reset_blue);
|
||||
if(!scene_manager_search_and_switch_to_previous_scene(
|
||||
app->scene_manager, FlipChessSceneStartscreen)) {
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void flipchess_scene_startscreen_on_exit(void* context) {
|
||||
FlipChess* app = context;
|
||||
|
||||
if(app->sound == 1) {
|
||||
flipchess_voice_shall_we_play();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user