Flash an X instead of a status window when the user inputs the wrong answer

This commit is contained in:
RandyTheSilly committed 2026-10-31 00:40:04 -04:00
1 parent 8820df1a85
commit f6a10475ca
6 files changed
+83 -11

No files matched your search

+33 -9
View File
@@ -25,6 +25,8 @@ static BitmapLayer *s_check_bmp_layer;
static TextLayer *s_setter_txt_layer;
static Layer *s_setter_highlight_layer;
//// alarm
static BitmapLayer *s_x_bmp_layer;
static Animation *s_x_anim_master;
static Layer *s_graph_layer;
static TextLayer *s_theta_txt_layer;
static TextLayer *s_parenthesis_txt_layer;
@@ -54,6 +56,8 @@ GFont s_font_mansalva_small;
//// setter
static GBitmap *s_clock_bmp;
static GBitmap *s_check_bmp;
//// alarm
static GBitmap *s_x_bmp;
// global vars
static WakeupReason s_alarm_reason;
@@ -129,10 +133,6 @@ static void status_set_failure_click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_DOWN, click_handler_push_setter);
}
static void status_math_failure_click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_SELECT, click_handler_retry);
}
static void status_window_load(StatusWindowPurpose purpose) {
Layer *window_layer = window_get_root_layer(s_status_window);
s_status_txt_layer = text_layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
@@ -149,10 +149,6 @@ static void status_window_load(StatusWindowPurpose purpose) {
case STATUS_SET_FAILURE:
text_layer_set_text(s_status_txt_layer, "Failed to set an alarm.\nPress any button to return to alarm setter.");
window_set_click_config_provider(s_status_window, status_set_failure_click_config_provider);
break;
case STATUS_MATH_FAILURE:
text_layer_set_text(s_status_txt_layer, "Incorrect equation.\nTry again!");
window_set_click_config_provider(s_status_window, status_math_failure_click_config_provider);
}
text_layer_set_background_color(s_status_txt_layer, GColorClear);
layer_set_frame(text_layer_get_layer(s_status_txt_layer), GRect(0, (PBL_DISPLAY_HEIGHT / 2) - (text_layer_get_content_size(s_status_txt_layer).h / 2), PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
@@ -542,7 +538,7 @@ static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
// check solution
for (int i = 0; i < 3; ++i) {
if (s_selected_indices[i] != s_solution_indices[i]) {
push_status_window(STATUS_MATH_FAILURE);
animation_schedule(animation_clone(s_x_anim_master));
return;
}
}
@@ -634,6 +630,16 @@ static void live_wakeup_handler_for_alarm(WakeupId id, int32_t wakeup_reason) {
}
}
static void anim_handler_flash_x_start(Animation *animation, void *context) {
layer_set_hidden(bitmap_layer_get_layer(s_x_bmp_layer), false);
}
static void anim_handler_flash_x_end(Animation *animation, bool finished, void *context) {
layer_set_hidden(bitmap_layer_get_layer(s_x_bmp_layer), true);
animation_destroy(animation);
}
static void anim_update_flash_x(Animation *animation, const AnimationProgress progress) {} // dummy
static const AnimationImplementation s_x_anim_impl = {.update = anim_update_flash_x};
static void alarm_window_load() {
wakeup_service_subscribe(live_wakeup_handler_for_alarm);
@@ -761,6 +767,20 @@ static void alarm_window_load() {
text_layer_set_font(s_progress_txt_layer, s_font_lecoish_small);
layer_add_child(window_layer, text_layer_get_layer(s_progress_txt_layer));
// x (incorrect equation icon)
s_x_bmp = gbitmap_create_with_resource(RESOURCE_ID_X);
s_x_bmp_layer = bitmap_layer_create(GRect(20, 24, 160, 179));
bitmap_layer_set_bitmap(s_x_bmp_layer, s_x_bmp);
bitmap_layer_set_compositing_mode(s_x_bmp_layer, GCompOpSet);
layer_set_hidden(bitmap_layer_get_layer(s_x_bmp_layer), true); // hide until needed
layer_add_child(window_layer, bitmap_layer_get_layer(s_x_bmp_layer));
// x flash animation init
s_x_anim_master = animation_create();
animation_set_implementation(s_x_anim_master, &s_x_anim_impl);
animation_set_duration(s_x_anim_master, 1500);
animation_set_handlers(s_x_anim_master, (AnimationHandlers){.started = anim_handler_flash_x_start, .stopped = anim_handler_flash_x_end}, NULL);
// configure UI around current triangle in s_triangle_layer
s_current_triangle_num = 1;
s_secs_since_last_input = MAX_SECS_WITHOUT_INPUT;
@@ -775,6 +795,10 @@ static void alarm_window_load() {
static void alarm_window_unload() {
tick_timer_service_unsubscribe();
accel_tap_service_unsubscribe();
animation_destroy(s_x_anim_master);
gbitmap_destroy(s_x_bmp);
bitmap_layer_destroy(s_x_bmp_layer);
text_layer_destroy(s_progress_txt_layer);
text_layer_destroy(s_countdown_txt_layer);
window_destroy(s_drop_window);
text_layer_destroy(s_side_a_txt_layer);
+1 -2
View File
@@ -3,8 +3,7 @@
typedef enum
{
STATUS_CONFIRMATION = 1,
STATUS_SET_FAILURE = 2,
STATUS_MATH_FAILURE = 3
STATUS_SET_FAILURE = 2
} StatusWindowPurpose;
static void push_setter_window();