Skip to content

Commit

Permalink
Preparations for game progression menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Dakkaron committed Jan 4, 2025
1 parent 9371e6b commit 9a00d81
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 59 deletions.
2 changes: 2 additions & 0 deletions T-HMI-PEPmonitor/src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define SENSOR_MODE_PEPS 1
#define SENSOR_MODE_TRAMPOLINE 2

#define PROGRESS_MENU_SELECTION_ID 32767

#define PROFILE_TASK_TYPE_SHORTBLOWS 1
#define PROFILE_TASK_TYPE_LONGBLOWS 2
#define PROFILE_TASK_TYPE_EQUALBLOWS 3
Expand Down
14 changes: 13 additions & 1 deletion T-HMI-PEPmonitor/src/games/gameLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ static int lua_wrapper_prefsGetNumber(lua_State* luaState) {
return 1;
}

static bool progressionMenuStillRunning = false;
static int lua_wrapper_closeProgressionMenu(lua_State* luaState) {
progressionMenuStillRunning = false;
return 0;
}

void initGames_lua(String gamePath, GameConfig* gameConfig, String* errorMessage) {
luaGamePath = gamePath;
Expand Down Expand Up @@ -291,6 +296,7 @@ void initGames_lua(String gamePath, GameConfig* gameConfig, String* errorMessage
lua.Lua_register("prefsGetInt", (const lua_CFunction) &lua_wrapper_prefsGetInt);
lua.Lua_register("prefsSetNumber", (const lua_CFunction) &lua_wrapper_prefsSetNumber);
lua.Lua_register("prefsGetNumber", (const lua_CFunction) &lua_wrapper_prefsGetNumber);
lua.Lua_register("closeProgressionMenu", (const lua_CFunction) &lua_wrapper_closeProgressionMenu);

setGamePrefsNamespace(gameConfig->prefsNamespace.c_str());

Expand Down Expand Up @@ -363,8 +369,14 @@ void drawInhalationGame_lua(DISPLAY_T* display, BlowData* blowData, String* erro
lua.Lua_dostring(&inhalationScript);
}

void displayProgressionMenu_lua(DISPLAY_T *display, String *errorMessage) {
bool displayProgressionMenu_lua(DISPLAY_T *display, String *errorMessage) {
progressionMenuStillRunning = true;
String progressionMenuScript = readFileToString((luaGamePath + "progressionMenu.lua").c_str());
if (progressionMenuScript.isEmpty()) {
errorMessage->concat("Failed to load progression menu script");
return false;
}
currentDisplay = display;
lua.Lua_dostring(&progressionMenuScript);
return progressionMenuStillRunning;
}
2 changes: 1 addition & 1 deletion T-HMI-PEPmonitor/src/games/gameLua.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ void drawEqualBlowGame_lua(DISPLAY_T* display, BlowData* blowData, String* error
void drawLongBlowGame_lua(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void drawTrampolineGame_lua(DISPLAY_T* display, JumpData* jumpData, String* errorMessage);
void drawInhalationGame_lua(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void displayProgressionMenu_lua(DISPLAY_T *display, String *errorMessage);
bool displayProgressionMenu_lua(DISPLAY_T *display, String *errorMessage);

#endif /* __GAME_LUA_H__ */
3 changes: 2 additions & 1 deletion T-HMI-PEPmonitor/src/games/gameMonsterCatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ void initGames_monsterCatcher(String gamePath, GameConfig* gameConfig, String* e
loadBmp(&ballCaughtIndicator, monsterCatcherGamePath + "gfx/interface/ball_caught_indicator.bmp");
}

void displayProgressionMenu_monsterCatcher(DISPLAY_T* display, String* errorMessage) {
bool displayProgressionMenu_monsterCatcher(DISPLAY_T* display, String* errorMessage) {
// TODO: display a paginized view of pokemon
return false;
}
2 changes: 1 addition & 1 deletion T-HMI-PEPmonitor/src/games/gameMonsterCatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void drawEqualBlowGame_monsterCatcher(DISPLAY_T* display, BlowData* blowData, St
void drawLongBlowGame_monsterCatcher(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void drawTrampolineGame_monsterCatcher(DISPLAY_T* display, JumpData* jumpData, String* errorMessage);
void drawInhalationGame_monsterCatcher(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void displayProgressionMenu_monsterCatcher(DISPLAY_T *display, String *errorMessage);
bool displayProgressionMenu_monsterCatcher(DISPLAY_T *display, String *errorMessage);

#define TRAINER_ANIM_PATH "gfx/trainer/brendan.bmp"

Expand Down
4 changes: 2 additions & 2 deletions T-HMI-PEPmonitor/src/games/gameRacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,6 @@ void drawInhalationGame_racing(DISPLAY_T* display, BlowData* blowData, String* e

}

void displayProgressionMenu_racing(DISPLAY_T* display, String* errorMessage) {

bool displayProgressionMenu_racing(DISPLAY_T* display, String* errorMessage) {
return false;
}
2 changes: 1 addition & 1 deletion T-HMI-PEPmonitor/src/games/gameRacing.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void drawEqualBlowGame_racing(DISPLAY_T* display, BlowData* blowData, String* er
void drawLongBlowGame_racing(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void drawTrampolineGame_racing(DISPLAY_T* display, JumpData* jumpData, String* errorMessage);
void drawInhalationGame_racing(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void displayProgressionMenu_racing(DISPLAY_T *display, String *errorMessage);
bool displayProgressionMenu_racing(DISPLAY_T *display, String *errorMessage);

#define TRAINER_ANIM_PATH "gfx/trainer/brendan.bmp"

Expand Down
9 changes: 5 additions & 4 deletions T-HMI-PEPmonitor/src/games/games.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ void drawInhalationGame(DISPLAY_T* display, BlowData* blowData, String* errorMes
}
}

void displayProgressionMenu(DISPLAY_T *display, String *errorMessage) {
bool displayProgressionMenu(DISPLAY_T *display, String *errorMessage) {
if (gameConfig.templateName == "monster") {
displayProgressionMenu_monsterCatcher(display, errorMessage);
return displayProgressionMenu_monsterCatcher(display, errorMessage);
} else if (gameConfig.templateName == "race") {
displayProgressionMenu_racing(display, errorMessage);
return displayProgressionMenu_racing(display, errorMessage);
} else if (gameConfig.templateName == "lua") {
displayProgressionMenu_lua(display, errorMessage);
return displayProgressionMenu_lua(display, errorMessage);
} else {
errorMessage->concat("No game loaded!");
return false;
}
}
2 changes: 1 addition & 1 deletion T-HMI-PEPmonitor/src/games/games.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void drawEqualBlowGame(DISPLAY_T* display, BlowData* blowData, String* errorMess
void drawLongBlowGame(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void drawTrampolineGame(DISPLAY_T* display, JumpData* jumpData, String* errorMessage);
void drawInhalationGame(DISPLAY_T* display, BlowData* blowData, String* errorMessage);
void displayProgressionMenu(DISPLAY_T* display, String* errorMessage);
bool displayProgressionMenu(DISPLAY_T* display, String* errorMessage);
String getRandomWinScreenPathForCurrentGame(String* errorMessage);

#endif /* __GAMES_H__ */
30 changes: 17 additions & 13 deletions T-HMI-PEPmonitor/src/hardware/gfxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,50 +480,54 @@ static void drawProfileSelectionPage(DISPLAY_T* display, uint16_t startNr, uint1
int32_t columns = _min(4, nr);
int32_t rows = nr>4 ? 2 : 1;
int32_t cWidth = (290 - 10*columns) / columns;
int32_t cHeight = rows==1 ? 220 : 105;
int32_t cHeight = rows==1 ? 200 : 95;
for (int32_t c = 0; c<columns; c++) {
for (int32_t r = 0; r<rows; r++) {
int32_t profileId = c + r*columns;
if (profileId < nr) {
ProfileData profileData;
readProfileData(profileId, &profileData, errorMessage);
display->fillRect(20 + c*(cWidth + 10), 10+(r*(cHeight+10)), cWidth, cHeight, TFT_BLUE);
display->fillRect(20 + c*(cWidth + 10), 30+r*(cHeight+10), cWidth, cHeight, TFT_BLUE);
int16_t imgW, imgH;
getBmpDimensions(profileData.imagePath, &imgW, &imgH);
drawBmp(profileData.imagePath, 20 + c*(cWidth + 10) + cWidth/2 - imgW/2, 10+(r*cHeight+10) + cHeight/2 - imgH/2, false);
drawBmp(profileData.imagePath, 20 + c*(cWidth + 10) + cWidth/2 - imgW/2, 30+r*(cHeight+10) + cHeight/2 - imgH/2, false);
uint8_t textDatumBackup = display->getTextDatum();
display->setTextDatum(BC_DATUM);
display->setTextSize(1);
display->drawString(profileData.name, 20 + c*(cWidth + 10) + cWidth/2, 10+(r*cHeight+10) + cHeight - 12);
display->drawString(profileData.name, 20 + c*(cWidth + 10) + cWidth/2, 30+r*(cHeight+10) + cHeight - 3);
display->setTextDatum(textDatumBackup);
}
}
}
drawBmp("/gfx/progressionmenu.bmp", SCREEN_WIDTH - 32, 0, false);
}

static void drawGameSelectionPage(DISPLAY_T* display, uint16_t startNr, uint16_t nr, bool drawArrows, String* errorMessage) {
int32_t columns = _min(4, nr);
int32_t rows = nr>4 ? 2 : 1;
int32_t cWidth = (290 - 10*columns) / columns;
int32_t cHeight = rows==1 ? 220 : 105;
int32_t cHeight = rows==1 ? 200 : 95;
for (int32_t c = 0; c<columns; c++) {
for (int32_t r = 0; r<rows; r++) {
if (c + r*columns < nr) {
String gamePath = getGamePath(c + r*columns, errorMessage);
display->fillRect(20 + c*(cWidth + 10), 10+(r*(cHeight+10)), cWidth, cHeight, TFT_BLUE);
display->fillRect(20 + c*(cWidth + 10), 30+r*(cHeight+10), cWidth, cHeight, TFT_BLUE);
int16_t imgW, imgH;
getBmpDimensions(gamePath + "logo.bmp", &imgW, &imgH);
drawBmp(gamePath + "logo.bmp", 20 + c*(cWidth + 10) + cWidth/2 - imgW/2, 10+(r*cHeight+10) + cHeight/2 - imgH/2, false);
drawBmp(gamePath + "logo.bmp", 20 + c*(cWidth + 10) + cWidth/2 - imgW/2, 30+r*(cHeight+10) + cHeight/2 - imgH/2, false);
}
}
}
}

static int16_t checkSelectionPageSelection(uint16_t startNr, uint16_t nr, bool drawArrows) {
static int16_t checkSelectionPageSelection(uint16_t startNr, uint16_t nr, bool drawArrows, bool progressMenuIcon) {
int32_t columns = _min(4, nr);
int32_t rows = nr>4 ? 2 : 1;
int32_t cWidth = (290 - 10*columns) / columns;
int32_t cHeight = rows==1 ? 220 : 105;
if (progressMenuIcon && isTouchInZone(SCREEN_WIDTH - 32, 0, 32, 32)) {
return PROGRESS_MENU_SELECTION_ID;
}
for (uint32_t c = 0; c<columns; c++) {
for (uint32_t r = 0; r<rows; r++) {
if (isTouchInZone(20 + c*(cWidth + 10), 10+(r*(cHeight+10)), cWidth, cHeight)) {
Expand All @@ -534,7 +538,7 @@ static int16_t checkSelectionPageSelection(uint16_t startNr, uint16_t nr, bool d
return -1;
}

uint16_t displayGameSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage) {
int16_t displayGameSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage) {
uint16_t startNr = 0;
uint32_t ms = millis();
uint32_t lastMs = millis();
Expand All @@ -551,7 +555,7 @@ uint16_t displayGameSelection(DISPLAY_T* display, uint16_t nr, String* errorMess
lastMs = ms;
ms = millis();
handleSerial();
int16_t selection = checkSelectionPageSelection(startNr, _min(nr, 8), nr>8);
int16_t selection = checkSelectionPageSelection(startNr, _min(nr, 8), nr>8, false);
if (selection != -1 && selection<nr) {
return selection;
}
Expand All @@ -564,7 +568,7 @@ uint16_t displayGameSelection(DISPLAY_T* display, uint16_t nr, String* errorMess
}
}

uint16_t displayProfileSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage) {
int16_t displayProfileSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage) {
uint16_t startNr = 0;
uint32_t ms = millis();
uint32_t lastMs = millis();
Expand All @@ -581,8 +585,8 @@ uint16_t displayProfileSelection(DISPLAY_T* display, uint16_t nr, String* errorM
lastMs = ms;
ms = millis();
handleSerial();
int16_t selection = checkSelectionPageSelection(startNr, _min(nr, 8), nr>8);
if (selection != -1 && selection<nr) {
int16_t selection = checkSelectionPageSelection(startNr, _min(nr, 8), nr>8, true);
if (selection != -1 && (selection<nr || selection == PROGRESS_MENU_SELECTION_ID)) {
return selection;
}
display->fillRect(0,0,70,20,TFT_BLACK);
Expand Down
4 changes: 2 additions & 2 deletions T-HMI-PEPmonitor/src/hardware/gfxHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void drawButton(DISPLAY_T* display, String text, int16_t x, int16_t y, int16_t w
bool checkButton(int16_t x, int16_t y, int16_t w, int16_t h);
bool drawAndCheckImageButton(DISPLAY_T* display, String path, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
bool drawAndCheckButton(DISPLAY_T* display, String text, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
uint16_t displayProfileSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage);
uint16_t displayGameSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage);
int16_t displayProfileSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage);
int16_t displayGameSelection(DISPLAY_T* display, uint16_t nr, String* errorMessage);
void drawKeyboard(DISPLAY_T* display, uint16_t keyColor, uint16_t textColor);
void checkKeyboard(DISPLAY_T* display, String* output, uint32_t maxCharacters, uint16_t keyColor, uint16_t textColor);
void checkFailWithMessage(String message);
Expand Down
27 changes: 3 additions & 24 deletions T-HMI-PEPmonitor/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,6 @@ void setBrightness(uint8_t value) {
_brightness = value;
}

void runGameSelection() {
String errorMessage;
uint16_t numberOfGames = getNumberOfGames(&errorMessage);
checkFailWithMessage(errorMessage);
Serial.print("Number of games: ");
Serial.println(numberOfGames);
String gamePath;
if (numberOfGames == 1) {
gamePath = getGamePath(0, &errorMessage);
} else {
gamePath = getGamePath(displayGameSelection(&spr, numberOfGames, &errorMessage), &errorMessage);
}
checkFailWithMessage(errorMessage);
Serial.print("Game path: ");
Serial.println(gamePath);
initGames(gamePath, &errorMessage);
checkFailWithMessage(errorMessage);
}

void setup() {
pinMode(PWR_ON_PIN, OUTPUT);
digitalWrite(PWR_ON_PIN, HIGH);
Expand Down Expand Up @@ -123,14 +104,12 @@ void setup() {
checkFailWithMessage(errorMessage);
initSystemConfig(&errorMessage);
checkFailWithMessage(errorMessage);

Serial.print("PEPit Version '");
Serial.print(VERSION);
Serial.println("' initialized");
runProfileSelection(&errorMessage);
spr.fillSprite(TFT_BLACK);
spr.pushSpriteFast(0,0);
spr.fillSprite(TFT_BLACK);
checkFailWithMessage(errorMessage);

runProfileSelection();
runGameSelection();
displayPhysioRotateScreen();
}
Expand Down
51 changes: 44 additions & 7 deletions T-HMI-PEPmonitor/src/physioProtocolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,53 @@ JumpData jumpData;

uint32_t lastMs = 0;

void runProfileSelection(String* errorMessage) {
void runGameSelection() {
spr.fillSprite(TFT_BLACK);
spr.pushSpriteFast(0,0);
spr.fillSprite(TFT_BLACK);
tft.fillScreen(TFT_BLACK);
String errorMessage;
uint16_t numberOfGames = getNumberOfGames(&errorMessage);
checkFailWithMessage(errorMessage);
Serial.print("Number of games: ");
Serial.println(numberOfGames);
String gamePath;
if (numberOfGames == 1) {
gamePath = getGamePath(0, &errorMessage);
} else {
gamePath = getGamePath(displayGameSelection(&spr, numberOfGames, &errorMessage), &errorMessage);
}
checkFailWithMessage(errorMessage);
Serial.print("Game path: ");
Serial.println(gamePath);
initGames(gamePath, &errorMessage);
checkFailWithMessage(errorMessage);
}

void runProfileSelection() {
String errorMessage;
bool profileSuccessfullyLoaded = false;
while (!profileSuccessfullyLoaded) {
uint32_t totalNumberOfProfiles = getNumberOfProfiles(errorMessage);
checkFailWithMessage(*errorMessage);
uint32_t selectedProfileId = displayProfileSelection(&spr, totalNumberOfProfiles, errorMessage);
checkFailWithMessage(*errorMessage);
readProfileData(selectedProfileId, &profileData, errorMessage);
checkFailWithMessage(*errorMessage);
spr.fillSprite(TFT_BLACK);
spr.pushSpriteFast(0,0);
spr.fillSprite(TFT_BLACK);
tft.fillScreen(TFT_BLACK);
uint32_t totalNumberOfProfiles = getNumberOfProfiles(&errorMessage);
checkFailWithMessage(errorMessage);
int32_t selectedProfileId = displayProfileSelection(&spr, totalNumberOfProfiles, &errorMessage);
profileSuccessfullyLoaded = true;
if (selectedProfileId == PROGRESS_MENU_SELECTION_ID) {
runGameSelection();
while (displayProgressionMenu(&spr, &errorMessage)) {
checkFailWithMessage(errorMessage);
}

profileSuccessfullyLoaded = false;
continue;
}
checkFailWithMessage(errorMessage);
readProfileData(selectedProfileId, &profileData, &errorMessage);
checkFailWithMessage(errorMessage);
for (uint32_t i=0;i<profileData.tasks;i++) {
if (profileData.taskType[i] == PROFILE_TASK_TYPE_TRAMPOLINE) {
spr.fillSprite(TFT_BLACK);
Expand Down
3 changes: 2 additions & 1 deletion T-HMI-PEPmonitor/src/physioProtocolHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define __PHYSIO_PROTOCOL_HANDLER_H__
#include <Arduino.h>

void runProfileSelection(String* errorMessage);
void runProfileSelection();
void runGameSelection();
void handlePhysioTask();
void displayPhysioRotateScreen();

Expand Down

0 comments on commit 9a00d81

Please sign in to comment.