Add tutorial when opening setter

This commit is contained in:
RandyTheSilly committed 2026-11-01 16:56:32 -05:00
1 parent 7113201f23
commit 4439f929a1
2 files changed
+60 -21

No files matched your search

+60 -14
View File
@@ -1,4 +1,3 @@
#include "main.h"
#include "scheduler.h" #include "scheduler.h"
#include "settings.h" #include "settings.h"
#include "triangles.h" #include "triangles.h"
@@ -15,6 +14,8 @@ static Window *s_status_window;
static Window *s_drop_window; static Window *s_drop_window;
static Layer *s_top_bar_layer; static Layer *s_top_bar_layer;
static Layer *s_bottom_bar_layer; static Layer *s_bottom_bar_layer;
//// status
static ScrollLayer *s_status_scroll_layer;
static TextLayer *s_status_txt_layer; static TextLayer *s_status_txt_layer;
//// setter //// setter
static BitmapLayer *s_clock_bmp_layer; static BitmapLayer *s_clock_bmp_layer;
@@ -83,7 +84,7 @@ static const GRect s_top_bar_grect = GRect(0, 0, PBL_DISPLAY_WIDTH, s_edge_bar_h
static const GRect s_bottom_bar_grect = GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar_height, PBL_DISPLAY_WIDTH, s_edge_bar_height); static const GRect s_bottom_bar_grect = GRect(0, PBL_DISPLAY_HEIGHT - s_edge_bar_height, PBL_DISPLAY_WIDTH, s_edge_bar_height);
static const GColor s_primary_color = GColorJaegerGreen; static const GColor s_primary_color = GColorJaegerGreen;
//// status //// status
#define STATUS_TEXT_INSET 3 #define STATUS_TEXT_INSET 4
//// alarm //// alarm
#define MAX_SECS_WITHOUT_INPUT 10 #define MAX_SECS_WITHOUT_INPUT 10
#define SHAKE_COOLDOWN_SECS 2 #define SHAKE_COOLDOWN_SECS 2
@@ -111,21 +112,42 @@ static char *s_options_under[2];
////////////////////// STATUS ////////////////////// ////////////////////// STATUS //////////////////////
typedef enum {
STATUS_TUTORIAL = 1,
STATUS_CONFIRMATION = 2,
STATUS_FAILURE = 3
} StatusWindowPurpose;
static void push_setter_window(); static void push_setter_window();
static void click_handler_push_setter(void *recognizer, void *ctx) { static void click_handler_push_setter(void *recognizer, void *ctx) {
s_highlight_pos = 0; s_highlight_pos = 0;
s_skip_current_day = true; // setting the next alarm should assume the user meant tomorrow
window_stack_pop_all(true); window_stack_pop_all(true);
push_setter_window(); push_setter_window();
} }
static void click_handler_disable_tutorial_and_push_setter(void *recognizer, void *ctx) {
settings.TutorialEnabled = false;
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
click_handler_push_setter(recognizer, ctx);
}
static void click_handler_push_setter_skip_current_day(void *recognizer, void *ctx) {
s_skip_current_day = true; // setting the next alarm should assume the user meant tomorrow
click_handler_push_setter(recognizer, ctx);
}
static void click_handler_exit(void *recognizer, void *ctx) { static void click_handler_exit(void *recognizer, void *ctx) {
window_stack_pop_all(true); window_stack_pop_all(true);
} }
static void status_tutorial_click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_SELECT, click_handler_push_setter);
window_single_click_subscribe(BUTTON_ID_BACK, click_handler_disable_tutorial_and_push_setter);
}
static void status_confirmation_click_config_provider(void *ctx) { static void status_confirmation_click_config_provider(void *ctx) {
window_single_click_subscribe(BUTTON_ID_BACK, click_handler_push_setter); window_single_click_subscribe(BUTTON_ID_BACK, click_handler_push_setter_skip_current_day);
window_single_click_subscribe(BUTTON_ID_SELECT, click_handler_exit); window_single_click_subscribe(BUTTON_ID_SELECT, click_handler_exit);
} }
@@ -138,31 +160,51 @@ static void status_set_failure_click_config_provider(void *ctx) {
static void status_window_load(StatusWindowPurpose purpose) { static void status_window_load(StatusWindowPurpose purpose) {
Layer *window_layer = window_get_root_layer(s_status_window); 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)); GRect bounds = layer_get_bounds(window_layer);
s_status_txt_layer = text_layer_create(GRect(0, 0, bounds.size.w, 750));
text_layer_set_font(s_status_txt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24)); text_layer_set_font(s_status_txt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
text_layer_set_background_color(s_status_txt_layer, GColorClear);
text_layer_set_text_alignment(s_status_txt_layer, GTextAlignmentCenter);
switch (purpose) { switch (purpose) {
case STATUS_TUTORIAL:
text_layer_set_text(s_status_txt_layer, "\nWelcome to Trigalarm!\n\nIn Trigalarm, you set one alarm that reoccurs every day and cannot be disabled. You can, however, change the time whenever you please.\n\nWhen your alarm goes off, you are presented with a (configurable) set of triangles. Each triangle has its own time limit it must be solved within in order to progress. Shake the watch to submit each answer.\n\nIf a triangle's time limit expires, your progress will be set back by one. Solve every triangle to disarm the alarm!\n\nSELECT: \"Okay!\"\nBACK: \"Shut up!\"\n\n\n");
s_status_scroll_layer = scroll_layer_create(layer_get_frame(window_layer));
#ifdef PBL_ROUND
scroll_layer_set_paging(s_status_scroll_layer, true);
#endif
scroll_layer_set_callbacks(s_status_scroll_layer, (ScrollLayerCallbacks){.click_config_provider = status_tutorial_click_config_provider});
scroll_layer_set_click_config_onto_window(s_status_scroll_layer, s_status_window);
scroll_layer_add_child(s_status_scroll_layer, text_layer_get_layer(s_status_txt_layer));
layer_add_child(window_layer, scroll_layer_get_layer(s_status_scroll_layer));
text_layer_enable_screen_text_flow_and_paging(s_status_txt_layer, STATUS_TEXT_INSET);
GSize max_size = text_layer_get_content_size(s_status_txt_layer);
text_layer_set_size(s_status_txt_layer, max_size);
scroll_layer_set_content_size(s_status_scroll_layer, GSize(bounds.size.w, max_size.h));
return;
case STATUS_CONFIRMATION: { case STATUS_CONFIRMATION: {
static char s_status_confirmed_buffer[106]; static char s_status_confirmed_buffer[86];
snprintf(s_status_confirmed_buffer, sizeof(s_status_confirmed_buffer), "Alarm disarmed and re-set (%02u:%02u) successfully.\n\nPress SELECT to exit or BACK to change the alarm time.", the_time.HourSet, the_time.MinuteSet); snprintf(s_status_confirmed_buffer, sizeof(s_status_confirmed_buffer), "Alarm disarmed and re-set (%02u:%02u) successfully.\n\nSELECT: Exit\nBACK: Change alarm time", the_time.HourSet, the_time.MinuteSet);
text_layer_set_text(s_status_txt_layer, s_status_confirmed_buffer); text_layer_set_text(s_status_txt_layer, s_status_confirmed_buffer);
window_set_click_config_provider(s_status_window, status_confirmation_click_config_provider); window_set_click_config_provider(s_status_window, status_confirmation_click_config_provider);
layer_add_child(window_layer, text_layer_get_layer(s_status_txt_layer));
break; break;
} }
case STATUS_SET_FAILURE: case STATUS_FAILURE:
text_layer_set_text(s_status_txt_layer, "Failed to set an alarm.\nPress any button to return to alarm setter."); 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); window_set_click_config_provider(s_status_window, status_set_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));
text_layer_set_text_alignment(s_status_txt_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(s_status_txt_layer)); layer_add_child(window_layer, text_layer_get_layer(s_status_txt_layer));
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));
text_layer_enable_screen_text_flow_and_paging(s_status_txt_layer, STATUS_TEXT_INSET); text_layer_enable_screen_text_flow_and_paging(s_status_txt_layer, STATUS_TEXT_INSET);
} }
static void status_window_unload() { static void status_window_unload() {
text_layer_destroy(s_status_txt_layer); text_layer_destroy(s_status_txt_layer);
if (s_status_scroll_layer != NULL) {
scroll_layer_destroy(s_status_scroll_layer);
s_status_scroll_layer = NULL;
}
window_destroy(s_status_window); window_destroy(s_status_window);
} }
@@ -213,7 +255,7 @@ static bool schedule_alarm(WakeupReason schedule_reason) {
status = wakeup_schedule_simple_robust(target, 15, schedule_reason); status = wakeup_schedule_simple_robust(target, 15, schedule_reason);
} }
if (status < 0) { if (status < 0) {
push_status_window(STATUS_SET_FAILURE); push_status_window(STATUS_FAILURE);
persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_ALARM); persist_write_int(STORAGE_KEY_ALARM_REASON, WAKE_ALARM);
s_alarm_reason = WAKE_ALARM; s_alarm_reason = WAKE_ALARM;
return false; return false;
@@ -1116,7 +1158,11 @@ static void init() {
if (s_alarm_reason == WAKE_RECOVERY_ALARM) { if (s_alarm_reason == WAKE_RECOVERY_ALARM) {
push_alarm_window(); push_alarm_window();
} else { } else {
push_setter_window(); if (settings.TutorialEnabled) {
push_status_window(STATUS_TUTORIAL);
} else {
push_setter_window();
}
} }
}; };
} }
-7
View File
@@ -1,7 +0,0 @@
#pragma once
typedef enum
{
STATUS_CONFIRMATION = 1,
STATUS_SET_FAILURE = 2
} StatusWindowPurpose;