@@ -76,10 +76,11 @@ static void roll(State* const state) {
76
76
77
77
if (state -> dice_index == 0 ) coin_set_end (state -> roll_result ); // change coin anim
78
78
79
+ add_to_history (state , state -> dice_index , state -> dice_count , state -> roll_result );
79
80
state -> app_state = AnimState ;
80
81
}
81
82
82
- static void draw_ui (const State * state , Canvas * canvas ) {
83
+ static void draw_main_menu (const State * state , Canvas * canvas ) {
83
84
canvas_set_font (canvas , FontSecondary );
84
85
85
86
FuriString * count = furi_string_alloc ();
@@ -92,7 +93,7 @@ static void draw_ui(const State* state, Canvas* canvas) {
92
93
}
93
94
// dice arrow buttons
94
95
if (isDiceButtonsVisible (state -> app_state )) {
95
- if (state -> dice_index > 0 ) canvas_draw_icon (canvas , 45 , 44 , & I_ui_button_left );
96
+ if (state -> dice_index > 0 ) canvas_draw_icon (canvas , 44 , 44 , & I_ui_button_left );
96
97
if (state -> dice_index < DICE_TYPES - 1 )
97
98
canvas_draw_icon (canvas , 78 , 44 , & I_ui_button_right );
98
99
}
@@ -105,17 +106,62 @@ static void draw_ui(const State* state, Canvas* canvas) {
105
106
canvas_draw_str_aligned (canvas , 58 , 61 , AlignCenter , AlignBottom , furi_string_get_cstr (count ));
106
107
107
108
// buttons
108
- if (isAnimState (state -> app_state ) == false) canvas_draw_icon (canvas , 92 , 54 , & I_ui_button_roll );
109
+ if (isAnimState (state -> app_state ) == false) {
110
+ canvas_draw_icon (canvas , 92 , 54 , & I_ui_button_roll );
111
+ canvas_draw_icon (canvas , 0 , 54 , & I_ui_button_history );
112
+ }
109
113
110
- if (state -> app_state != AnimResultState && state -> app_state != ResultState ) {
111
- canvas_draw_icon (canvas , 0 , 54 , & I_ui_button_exit );
112
- } else {
114
+ if (state -> app_state == AnimResultState || state -> app_state == ResultState ) {
113
115
canvas_draw_icon (canvas , 0 , 54 , & I_ui_button_back );
114
116
}
115
117
116
118
furi_string_free (count );
117
119
}
118
120
121
+ static void draw_history (const State * state , Canvas * canvas ) {
122
+ canvas_set_font (canvas , FontSecondary );
123
+ FuriString * hist = furi_string_alloc ();
124
+
125
+ uint8_t x = HISTORY_START_POST_X ;
126
+ uint8_t y = HISTORY_START_POST_Y ;
127
+ for (uint8_t i = 0 ; i < HISTORY_COL ; i ++ ) {
128
+ // left side
129
+ furi_string_printf (hist , "%01d." , i + 1 );
130
+ canvas_draw_str_aligned (canvas , x , y , AlignLeft , AlignBottom , furi_string_get_cstr (hist ));
131
+ if (state -> history [i ].index < 0 ) {
132
+ furi_string_printf (hist , "--------" );
133
+ } else {
134
+ if (state -> history [i ].index == 0 ){
135
+ furi_string_printf (hist , state -> history [i ].result == 1 ? "Heads" : "Tails" );
136
+ } else {
137
+ furi_string_printf (hist , "%01d%s: %01d" , state -> history [i ].count , dice_types [state -> history [i ].index ].name , state -> history [i ].result );
138
+ }
139
+ }
140
+ canvas_draw_str_aligned (canvas , x + HISTORY_X_GAP , y , AlignLeft , AlignBottom , furi_string_get_cstr (hist ));
141
+
142
+ // right side
143
+ uint8_t r_index = i + HISTORY_COL ;
144
+ furi_string_printf (hist , "%01d." , r_index + 1 );
145
+ canvas_draw_str_aligned (canvas , x + HISTORY_STEP_X , y , AlignLeft , AlignBottom , furi_string_get_cstr (hist ));
146
+ if (state -> history [r_index ].index < 0 ){
147
+ furi_string_printf (hist , "--------" );
148
+ } else {
149
+ if (state -> history [r_index ].index == 0 ){
150
+ furi_string_printf (hist , state -> history [r_index ].result == 1 ? "Heads" : "Tails" );
151
+ } else {
152
+ furi_string_printf (hist , "%01d%s: %01d" , state -> history [r_index ].count , dice_types [state -> history [r_index ].index ].name , state -> history [r_index ].result );
153
+ }
154
+ }
155
+ canvas_draw_str_aligned (canvas , x + HISTORY_STEP_X + HISTORY_X_GAP , y , AlignLeft , AlignBottom , furi_string_get_cstr (hist ));
156
+
157
+ y += HISTORY_STEP_Y ;
158
+ }
159
+
160
+ canvas_draw_icon (canvas , 0 , 54 , & I_ui_button_back );
161
+ canvas_draw_icon (canvas , 75 , 54 , & I_ui_button_exit );
162
+ furi_string_free (hist );
163
+ }
164
+
119
165
static void draw_dice (const State * state , Canvas * canvas ) {
120
166
if (isMenuState (state -> app_state ) == false) { // draw only selected dice
121
167
if (state -> dice_index == 0 ) { // coin
@@ -200,12 +246,16 @@ static void draw_callback(Canvas* canvas, void* ctx) {
200
246
201
247
canvas_clear (canvas );
202
248
203
- draw_ui (state , canvas );
204
-
205
- if (isResultVisible (state -> app_state , state -> dice_index )) {
206
- draw_results (state , canvas );
249
+ if (state -> app_state == HistoryState ) {
250
+ draw_history (state , canvas );
207
251
} else {
208
- draw_dice (state , canvas );
252
+ draw_main_menu (state , canvas );
253
+
254
+ if (isResultVisible (state -> app_state , state -> dice_index )) {
255
+ draw_results (state , canvas );
256
+ } else {
257
+ draw_dice (state , canvas );
258
+ }
209
259
}
210
260
211
261
furi_mutex_release (state -> mutex );
@@ -289,31 +339,42 @@ int32_t dice_dnd_app(void* p) {
289
339
if (state -> dice_index != 0 ) {
290
340
state -> dice_count += 1 ;
291
341
if (state -> dice_count > MAX_DICE_COUNT ) {
292
- state -> dice_count = MAX_DICE_COUNT ;
342
+ state -> dice_count = 1 ;
293
343
}
294
344
}
295
345
} else if (event .input .key == InputKeyDown ) {
296
346
state -> dice_count -= 1 ;
297
347
if (state -> dice_count < 1 ) {
298
- state -> dice_count = 1 ;
348
+ state -> dice_count = MAX_DICE_COUNT ;
299
349
}
300
350
}
301
351
}
302
352
// roll
303
353
if (event .input .key == InputKeyOk && isAnimState (state -> app_state ) == false) {
304
354
roll (state );
305
355
}
306
- // back to dice select state or quit from app
307
- if (event .input .key == InputKeyBack ) {
308
- if (state -> app_state == ResultState ||
309
- state -> app_state == AnimResultState ) {
356
+ }
357
+
358
+ // back button handlers
359
+ if (event .input .key == InputKeyBack ){
360
+ // switch states
361
+ if (event .input .type == InputTypeShort ) {
362
+ if (state -> app_state == SelectState ){
363
+ state -> app_state = HistoryState ;
364
+ }
365
+ else if (state -> app_state == HistoryState ) {
366
+ state -> app_state = SelectState ;
367
+ }
368
+ else if (state -> app_state == ResultState || state -> app_state == AnimResultState ) {
310
369
state -> anim_frame = 0 ;
311
370
state -> app_state = SelectState ;
312
- } else {
313
- processing = false;
314
371
}
315
372
}
316
- }
373
+ // exit
374
+ else if (event .input .type == InputTypeLong ) {
375
+ processing = false;
376
+ }
377
+ }
317
378
}
318
379
} else {
319
380
FURI_LOG_D (TAG , "osMessageQueue: event timeout" );
0 commit comments