Pārlūkot izejas kodu

Made the readme and menu pretty

Cathy Nguyen 2 gadi atpakaļ
vecāks
revīzija
23f7cbdadc
6 mainītis faili ar 106 papildinājumiem un 108 dzēšanām
  1. 6 1
      README.md
  2. BIN
      Screenshot1.png
  3. BIN
      Screenshot2.png
  4. BIN
      Screenshot3.png
  5. BIN
      Screenshot4.png
  6. 100 107
      tama_p1.c

+ 6 - 1
README.md

@@ -18,6 +18,8 @@ Rename this to `rom.bin`.
 - Up button takes you to the emulator menu.
 - Hold the Back button to save and exit.
 
+![Alt Text](Screenshot1.png)
+![Alt Text](Screenshot2.png)
 
 Building
 --------
@@ -57,4 +59,7 @@ Implemented
 
 To-Do
 -----
-- display/hide runtime (reason: changing the in-game clock and aging up the Tamagotchi does not affect when it evolves.)
+- fix bug where the Flipper's button stop responding for a few seconds, usually after mashing buttons in quick succession.
+
+![Alt Text](Screenshot3.png)
+![Alt Text](Screenshot4.png)

BIN
Screenshot1.png


BIN
Screenshot2.png


BIN
Screenshot3.png


BIN
Screenshot4.png


+ 100 - 107
tama_p1.c

@@ -10,12 +10,8 @@
 
 TamaApp* g_ctx;
 FuriMutex* g_state_mutex;
-uint8_t layout_mode = 1;
-// 0: landscape (small);
-// 1: landscape (big);
-// 2: landscape (full);
-// 3: portrait =>
-// 4: portrait <=
+uint8_t layout_mode = 0; // 3: portrait => 4: portrait <=
+// 0: landscape (small) 1: landscape (big) 2: landscape (full)
 bool in_menu = false;
 
 uint8_t speed = 1;
@@ -238,6 +234,23 @@ static void draw_portrait_left(Canvas* const canvas) {
     }
 }
 
+static void draw_mini(Canvas* const canvas) {
+    // Calculate positioning
+    uint16_t y = 34;
+    for(uint8_t row = 0; row < 16; ++row) {
+        uint16_t x = 84;
+        uint32_t row_pixels = g_ctx->framebuffer[row];
+        for(uint8_t col = 0; col < 32; ++col) {
+            if(row_pixels & 1) {
+                canvas_draw_dot(canvas, x, y);
+            }
+            x += 1;
+            row_pixels >>= 1;
+        }
+        y += 1;
+    }
+}
+
 // static void draw_menu_portrait(Canvas* const canvas, void* cb_ctx) {}
 
 // static void draw_menu_landscape(Canvas* const canvas)
@@ -246,6 +259,8 @@ static void draw_menu(Canvas* const canvas) {
     canvas_draw_frame(canvas, 0, 0, 128, 64);
     canvas_draw_str_aligned(canvas, 64, 6, AlignCenter, AlignCenter, "Menu");
     canvas_draw_line(canvas, 0, 10, 128, 10);
+    draw_mini(canvas);
+
     switch(menu_cursor) {
     case 0:
         canvas_draw_triangle(canvas, 4, 16, 6, 6, CanvasDirectionLeftToRight);
@@ -763,88 +778,23 @@ int32_t tama_p1_app(void* p) {
                 btn_state_t tama_btn_state = 0;
 
                 if(in_menu) {
-                    if(event.input.key == InputKeyBack && event.input.type == InputTypePress) {
+                    if(event.input.key == InputKeyBack) {
                         in_menu = false;
-                    }
-                    if(event.input.key == InputKeyOk) {
-                        switch(menu_cursor) {
-                        case 0:
-                            // mute tamagotchi
-                            if(input_type == InputTypePress)
-                                tama_btn_state = BTN_STATE_PRESSED;
-                            else if(input_type == InputTypeRelease)
-                                tama_btn_state = BTN_STATE_RELEASED;
-                            tamalib_set_button(BTN_LEFT, tama_btn_state);
-                            tamalib_set_button(BTN_RIGHT, tama_btn_state);
-                            break;
-                        case 1:
-                            if(event.input.type == InputTypePress) {
-                                switch(layout_mode) {
-                                case 0:
-                                case 1:
-                                case 2:
-                                    layout_mode += 1;
-                                    break;
-                                case 3:
-                                    layout_mode = 0;
-                                    break;
-                                }
-                            }
-                            break;
-                        case 2:
-                            if(event.input.type == InputTypePress) {
-                                speed_up();
-                            }
-                            break;
-                        case menu_items - 1:
-                        default:
-                            switch(sub_menu_default) {
-                            case 0:
-                                in_menu = false;
-                                break;
-                            case 1:
-                                if(speed != 1) {
-                                    uint8_t temp = speed;
-                                    speed = 1;
-                                    tamalib_set_speed(speed);
-                                    speed = temp;
-                                    tamalib_set_speed(speed);
-                                }
-                                tama_p1_save_state();
-                                in_menu = false;
-                                break;
-                            case 2:
-                                if(speed != 1) {
-                                    speed = 1;
-                                    tamalib_set_speed(speed);
-                                }
-                                furi_timer_stop(timer);
-                                running = false;
-                                tama_p1_save_state();
-                                break;
-                            default:
-                                break;
-                            }
-                            break;
-                        }
-                    }
-                    if(event.input.key == InputKeyUp && event.input.type == InputTypePress) {
+                    } else if(event.input.key == InputKeyUp && event.input.type == InputTypePress) {
                         if(menu_cursor > 0) {
                             menu_cursor -= 1;
                         } else {
                             sub_menu_default = 0;
                             menu_cursor = menu_items - 1;
                         }
-                    }
-                    if(event.input.key == InputKeyDown && event.input.type == InputTypePress) {
+                    } else if(event.input.key == InputKeyDown && event.input.type == InputTypePress) {
                         if(menu_cursor < menu_items - 1) {
                             sub_menu_default = 0;
                             menu_cursor += 1;
                         } else {
                             menu_cursor = 0;
                         }
-                    }
-                    if(event.input.key == InputKeyLeft && event.input.type == InputTypePress) {
+                    } else if(event.input.key == InputKeyLeft && event.input.type == InputTypePress) {
                         switch(menu_cursor) {
                         case 1:
                             switch(layout_mode) {
@@ -869,6 +819,7 @@ int32_t tama_p1_app(void* p) {
                                 break;
                             case 1:
                             case 2:
+                                // sub_menu_default = 0;
                                 sub_menu_default -= 1;
                                 break;
                             default:
@@ -878,8 +829,7 @@ int32_t tama_p1_app(void* p) {
                         default:
                             break;
                         }
-                    }
-                    if(event.input.key == InputKeyRight && event.input.type == InputTypePress) {
+                    } else if(event.input.key == InputKeyRight && event.input.type == InputTypePress) {
                         switch(menu_cursor) {
                         case 1:
                             switch(layout_mode) {
@@ -901,6 +851,7 @@ int32_t tama_p1_app(void* p) {
                             switch(sub_menu_default) {
                             case 0:
                             case 1:
+                                // sub_menu_default = 2;
                                 sub_menu_default += 1;
                                 break;
                             case 2:
@@ -913,6 +864,67 @@ int32_t tama_p1_app(void* p) {
                         default:
                             break;
                         }
+                    } else if(event.input.key == InputKeyOk) {
+                        switch(menu_cursor) {
+                        case 0:
+                            // mute tamagotchi
+                            if(input_type == InputTypePress)
+                                tama_btn_state = BTN_STATE_PRESSED;
+                            else if(input_type == InputTypeRelease)
+                                tama_btn_state = BTN_STATE_RELEASED;
+                            tamalib_set_button(BTN_LEFT, tama_btn_state);
+                            tamalib_set_button(BTN_RIGHT, tama_btn_state);
+                            break;
+                        case 1:
+                            if(event.input.type == InputTypePress) {
+                                switch(layout_mode) {
+                                case 0:
+                                case 1:
+                                case 2:
+                                    layout_mode += 1;
+                                    break;
+                                case 3:
+                                    layout_mode = 0;
+                                    break;
+                                }
+                            }
+                            break;
+                        case 2:
+                            if(event.input.type == InputTypePress) {
+                                speed_up();
+                            }
+                            break;
+                        case menu_items - 1:
+                        default:
+                            switch(sub_menu_default) {
+                            case 0:
+                                in_menu = false;
+                                break;
+                            case 1:
+                                if(speed != 1) {
+                                    uint8_t temp = speed;
+                                    speed = 1;
+                                    tamalib_set_speed(speed);
+                                    speed = temp;
+                                    tamalib_set_speed(speed);
+                                }
+                                tama_p1_save_state();
+                                in_menu = false;
+                                break;
+                            case 2:
+                                if(speed != 1) {
+                                    speed = 1;
+                                    tamalib_set_speed(speed);
+                                }
+                                furi_timer_stop(timer);
+                                tama_p1_save_state();
+                                running = false;
+                                break;
+                            default:
+                                break;
+                            }
+                            break;
+                        }
                     }
 
                 } else { // out of menu
@@ -920,28 +932,11 @@ int32_t tama_p1_app(void* p) {
                         tama_btn_state = BTN_STATE_PRESSED;
                     else if(input_type == InputTypeRelease)
                         tama_btn_state = BTN_STATE_RELEASED;
-                    if(event.input.key == InputKeyBack && event.input.type == InputTypeLong) {
-                        if(speed != 1) {
-                            speed = 1;
-                            tamalib_set_speed(speed);
-                        }
-                        furi_timer_stop(timer);
-                        running = false;
-                        tama_p1_save_state();
-                    }
+
                     if(input_type == InputTypePress || input_type == InputTypeRelease) {
                         if(event.input.key == InputKeyOk) {
                             tamalib_set_button(BTN_MIDDLE, tama_btn_state);
                         }
-                        // else if(
-                        //     event.input.key == InputKeyBack &&
-                        //     event.input.type == InputTypeShort) {
-                        //     if(speed != 1) {
-                        //         speed = 1;
-                        //         tamalib_set_speed(speed);
-                        //     }
-                        //     tama_p1_save_state();
-                        // }
                         switch(layout_mode) {
                         case 0:
                         case 1:
@@ -1002,21 +997,19 @@ int32_t tama_p1_app(void* p) {
                                 break;
                             }
                             break;
-                        default: // error handling
-                            switch(event.input.key) {
-                            case InputKeyUp:
-                            case InputKeyDown:
-                            case InputKeyLeft:
-                            case InputKeyRight:
-                                sub_menu_default = 0;
-                                in_menu = true;
-                                break;
-                            default:
-                                break;
-                            }
+                        default:
                             break;
                         }
                     }
+                    if(event.input.key == InputKeyBack && event.input.type == InputTypeLong) {
+                        if(speed != 1) {
+                            speed = 1;
+                            tamalib_set_speed(speed);
+                        }
+                        furi_timer_stop(timer);
+                        tama_p1_save_state();
+                        running = false;
+                    }
                 }
             }
             furi_mutex_release(g_state_mutex);