mirror of
https://github.com/nacabaro/nacapet.git
synced 2026-09-30 23:21:37 +00:00
Add a way to switch backgrounds
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern int currentBackground;
|
||||
|
||||
struct BackgroundData {
|
||||
uint8_t backgroundWidth;
|
||||
uint8_t backgroundHeight;
|
||||
|
||||
+4
-1
@@ -61,6 +61,9 @@ uint32_t dayUnixTime = 0;
|
||||
Egg_t* eggSelection = NULL;
|
||||
uint8_t eggNumber = 0;
|
||||
|
||||
// Background stuff
|
||||
int currentBackground = 0;
|
||||
|
||||
// Tasks
|
||||
TaskHandle_t secondLoop = NULL;
|
||||
|
||||
@@ -92,7 +95,7 @@ void setup() {
|
||||
storage_readFile("/menu.bin", &menuElementsData);
|
||||
storage_readFile("/ui.bin", &uiElementsData);
|
||||
|
||||
storage_initBackground("/bg2.bin", bg);
|
||||
storage_initBackground(currentBackground, bg);
|
||||
|
||||
pinMode(K1_PIN, BUTTON_MODE);
|
||||
pinMode(K2_PIN, BUTTON_MODE);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "menu.h"
|
||||
#include "defs/sprite_data.h"
|
||||
#include "buttons/buttons.h"
|
||||
#include "draw/draw.h"
|
||||
#include "storage/storage.h"
|
||||
#include "display/display.h"
|
||||
#include "defs/screen_defs.h"
|
||||
|
||||
void menu_changeBackgroundScreen(
|
||||
TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* uiSpriteData
|
||||
) {
|
||||
int8_t selectedBackground = currentBackground;
|
||||
|
||||
fs::File bgFolder = SPIFFS.open("/bg");
|
||||
fs::File background = bgFolder.openNextFile();
|
||||
|
||||
uint8_t backgrounds = 0;
|
||||
|
||||
uint64_t currentTime = esp_timer_get_time();
|
||||
|
||||
int8_t selectedPreviousBackground = 0;
|
||||
|
||||
while (background) {
|
||||
if (!background.isDirectory()) {
|
||||
backgrounds++;
|
||||
}
|
||||
|
||||
background = background.openNextFile();
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
uint8_t buttonsPressed = buttons_getPressedButtons();
|
||||
currentTime = esp_timer_get_time();
|
||||
|
||||
switch (buttonsPressed) {
|
||||
case K1_PRESSED:
|
||||
selectedBackground++;
|
||||
if (selectedBackground > backgrounds) {
|
||||
selectedBackground = 0;
|
||||
}
|
||||
storage_initBackground(selectedBackground, bg);
|
||||
lastUpdateTime = currentTime;
|
||||
break;
|
||||
|
||||
case K2_PRESSED:
|
||||
selectedBackground--;
|
||||
if (selectedBackground < 0) {
|
||||
selectedBackground = backgrounds - 1;
|
||||
}
|
||||
storage_initBackground(selectedBackground, bg);
|
||||
lastUpdateTime = currentTime;
|
||||
break;
|
||||
|
||||
case K3_PRESSED:
|
||||
currentBackground = selectedBackground;
|
||||
lastUpdateTime = currentTime;
|
||||
return;
|
||||
|
||||
case K4_PRESSED:
|
||||
storage_initBackground(currentBackground, bg);
|
||||
lastUpdateTime = currentTime;
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedPreviousBackground != selectedBackground) {
|
||||
draw_drawBackground(bg, 90, 90, 3);
|
||||
draw_drawSprite(sprite, 174, 96, uiSpriteData, ARROW_ICON);
|
||||
tft_drawBuffer();
|
||||
}
|
||||
|
||||
if (currentTime - lastUpdateTime > INACTIVITY_THRESHOLD_TIME_US) {
|
||||
storage_initBackground(currentBackground, bg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-1
@@ -53,11 +53,13 @@ void menu_drawAngryScreen(
|
||||
struct SpriteData* spriteData, struct SpriteData* smallUiElements
|
||||
);
|
||||
void menu_drawFridgeScreen(TFT_eSprite &bg, TFT_eSprite& sprite, struct SpriteData* smallUiElements, struct SpriteData* bigUiElements);
|
||||
|
||||
void training_screenTraining2(
|
||||
TFT_eSprite &bg, TFT_eSprite &sprite,
|
||||
struct SpriteData* mainCharaData, struct SpriteData* attackSprites
|
||||
);
|
||||
void menu_changeBackgroundScreen(
|
||||
TFT_eSprite &bg, TFT_eSprite &sprite, struct SpriteData* uiSpriteData
|
||||
);
|
||||
|
||||
void menu_sleepScreen_sleepAction();
|
||||
void menu_sleepScreen_recalculateSleep();
|
||||
|
||||
@@ -17,7 +17,11 @@ void storage_init() {
|
||||
}
|
||||
|
||||
|
||||
void storage_initBackground(const char* path, TFT_eSprite& bg) {
|
||||
void storage_initBackground(const int id, TFT_eSprite& bg) {
|
||||
char path[15];
|
||||
|
||||
snprintf(path, 15, "/bg/%i.bin", id);
|
||||
|
||||
File file = SPIFFS.open(path, "r");
|
||||
if (!file) {
|
||||
printf("%s Failed to open file for reading\n", TAG_S);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
void storage_init();
|
||||
void storage_readFile(const char* path, struct SpriteData* spriteData);
|
||||
void storage_initBackground(const char* path, TFT_eSprite &bg);
|
||||
void storage_initBackground(const int id, TFT_eSprite &bg);
|
||||
|
||||
void storage_saveState();
|
||||
void storage_loadState();
|
||||
|
||||
Reference in New Issue
Block a user