updated tamagotchi (added muted button)

thanks Smileycathy1128!
This commit is contained in:
jbohack
2023-01-23 14:27:39 -05:00
parent 364943b1aa
commit 3cc4681cbc
3 changed files with 49 additions and 17 deletions

View File

@@ -38,9 +38,20 @@ static void tama_p1_draw_callback(Canvas* const canvas, void* cb_ctx) {
// FURI_LOG_D(TAG, "Drawing frame");
// Calculate positioning
uint16_t canv_width = canvas_width(canvas);
uint16_t canv_height = canvas_height(canvas);
uint16_t lcd_matrix_scaled_width = 32 * TAMA_SCREEN_SCALE_FACTOR;
uint16_t lcd_matrix_top = 0;
uint16_t lcd_matrix_scaled_height = 16 * TAMA_SCREEN_SCALE_FACTOR;
// uint16_t lcd_matrix_top = 0;
uint16_t lcd_matrix_top = (canv_height - lcd_matrix_scaled_height) / 2;
uint16_t lcd_matrix_left = (canv_width - lcd_matrix_scaled_width) / 2;
uint16_t lcd_icon_upper_top = lcd_matrix_top - TAMA_LCD_ICON_SIZE - TAMA_LCD_ICON_MARGIN;
uint16_t lcd_icon_upper_left = lcd_matrix_left;
uint16_t lcd_icon_lower_top =
lcd_matrix_top + lcd_matrix_scaled_height + TAMA_LCD_ICON_MARGIN;
uint16_t lcd_icon_lower_left = lcd_matrix_left;
uint16_t lcd_icon_spacing_horiz =
(lcd_matrix_scaled_width - (4 * TAMA_LCD_ICON_SIZE)) / 3 + TAMA_LCD_ICON_SIZE;
uint16_t y = lcd_matrix_top;
@@ -58,20 +69,32 @@ static void tama_p1_draw_callback(Canvas* const canvas, void* cb_ctx) {
y += TAMA_SCREEN_SCALE_FACTOR;
}
// Draw Icons on bottom
// Start drawing icons
uint8_t lcd_icons = g_ctx->icons;
uint16_t x_ic = 0;
y = 64 - TAMA_LCD_ICON_SIZE;
for(uint8_t i = 0; i < 7; ++i) {
// Draw top icons
y = lcd_icon_upper_top;
// y = 64 - TAMA_LCD_ICON_SIZE;
uint16_t x_ic = lcd_icon_upper_left;
for(uint8_t i = 0; i < 4; ++i) {
if(lcd_icons & 1) {
canvas_draw_icon(canvas, x_ic, y, icons_list[i]);
}
x_ic += TAMA_LCD_ICON_SIZE + 4;
// x_ic += TAMA_LCD_ICON_SIZE + 4;
x_ic += lcd_icon_spacing_horiz;
lcd_icons >>= 1;
}
if (lcd_icons & 7) {
canvas_draw_icon(canvas, 128 - TAMA_LCD_ICON_SIZE, 0, icons_list[7]);
// Draw bottom icons
y = lcd_icon_lower_top;
x_ic = lcd_icon_lower_left;
for(uint8_t i = 4; i < 8; ++i) {
// canvas_draw_frame(canvas, x_ic, y, TAMA_LCD_ICON_SIZE, TAMA_LCD_ICON_SIZE);
if(lcd_icons & 1) {
canvas_draw_icon(canvas, x_ic, y, icons_list[i]);
}
x_ic += lcd_icon_spacing_horiz;
lcd_icons >>= 1;
}
}
@@ -91,8 +114,6 @@ static void tama_p1_update_timer_callback(FuriMessageQueue* event_queue) {
TamaEvent event = {.type = EventTypeTick};
furi_message_queue_put(event_queue, &event, 0);
}
static void tama_p1_load_state() {
state_t *state;
@@ -204,7 +225,6 @@ static void tama_p1_save_state() {
// Saving state
FURI_LOG_D(TAG, "Saving Gamestate");
uint8_t buf[4];
state_t *state;
uint32_t offset = 0;
@@ -465,6 +485,14 @@ int32_t tama_p1_app(void* p) {
tamalib_set_button(BTN_MIDDLE, tama_btn_state);
} else if(event.input.key == InputKeyRight) {
tamalib_set_button(BTN_RIGHT, tama_btn_state);
} else if(event.input.key == InputKeyDown && event.input.type == InputTypeShort) {
// TODO: pause or fast-forward tamagotchi
tama_p1_save_state();
} else if(event.input.key == InputKeyUp) { // mute tamagotchi
tamalib_set_button(BTN_LEFT, tama_btn_state);
tamalib_set_button(BTN_RIGHT, tama_btn_state);
} else if(event.input.key == InputKeyBack && event.input.type == InputTypeShort) {
tama_p1_save_state();
}
}