Skip to content

Commit

Permalink
Add ability to not draw menu rings
Browse files Browse the repository at this point in the history
Recolor Soko menu

Turn off LEDs & Rings for soko instructions

Fix Soko out of bounds
  • Loading branch information
AEFeinstein committed Dec 3, 2024
1 parent 9f6c6b4 commit ff1f830
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 6 deletions.
27 changes: 21 additions & 6 deletions main/menu/menuManiaRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO
ringDir = (ringDir == 1) ? -1 : 1;
ring->color = ringColors[i];
}
renderer->drawRings = true;

// LEDs on by default
renderer->ledsOn = true;
Expand Down Expand Up @@ -476,13 +477,16 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
// Clear the background
fillDisplayArea(0, 0, TFT_WIDTH, TFT_HEIGHT, renderer->bgColor);

// Draw the rings
for (int16_t i = 0; i < ARRAY_SIZE(renderer->rings); i++)
if (renderer->drawRings)
{
maniaRing_t* ring = &renderer->rings[i];
int16_t ringRadius = (MIN_RING_RADIUS + MAX_RING_RADIUS) / 2
+ (((MAX_RING_RADIUS - MIN_RING_RADIUS) * getSin1024(ring->diameterAngle)) / 1024);
drawManiaRing(ringRadius, ring->orbitAngle, ring->color, renderer->bgColor);
// Draw the rings
for (int16_t i = 0; i < ARRAY_SIZE(renderer->rings); i++)
{
maniaRing_t* ring = &renderer->rings[i];
int16_t ringRadius = (MIN_RING_RADIUS + MAX_RING_RADIUS) / 2
+ (((MAX_RING_RADIUS - MIN_RING_RADIUS) * getSin1024(ring->diameterAngle)) / 1024);
drawManiaRing(ringRadius, ring->orbitAngle, ring->color, renderer->bgColor);
}
}

// Find the start of the 'page'
Expand Down Expand Up @@ -651,6 +655,17 @@ void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn)
}
}

/**
* @brief Set if the rings should be drawn
*
* @param renderer The renderer to set
* @param ringsOn true to draw rings, false to not
*/
void setManiaDrawRings(menuManiaRenderer_t* renderer, bool ringsOn)
{
renderer->drawRings = ringsOn;
}

/**
* @brief Recolor a menu renderer
*
Expand Down
2 changes: 2 additions & 0 deletions main/menu/menuManiaRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct
wsg_t batt[4]; ///< Images for the battery levels

maniaRing_t rings[2];
bool drawRings;

int32_t ledDecayTimer; ///< Timer to decay LEDs
int32_t ledExciteTimer; ///< Timer to excite LEDs
Expand Down Expand Up @@ -101,6 +102,7 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO
void deinitMenuManiaRenderer(menuManiaRenderer_t* renderer);
void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedUs);
void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn);
void setManiaDrawRings(menuManiaRenderer_t* renderer, bool ringsOn);
void recolorMenuManiaRenderer(menuManiaRenderer_t* renderer, paletteColor_t titleBgColor, paletteColor_t titleTextColor,
paletteColor_t textOutlineColor, paletteColor_t bgColor, paletteColor_t outerRingColor,
paletteColor_t innerRingColor, paletteColor_t rowColor, paletteColor_t rowTextColor,
Expand Down
30 changes: 30 additions & 0 deletions main/modes/games/soko/soko.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ static void sokoEnterMode(void)
soko->menuManiaRenderer
= initMenuManiaRenderer(&soko->font_righteous, &soko->font_righteous_outline, &soko->font_rodin);

// Color the menu
led_t menuColor = {
.r = 0xFF,
.g = 0xCC,
.b = 0x00,
};
static const paletteColor_t shadowColors[] = {c103, c213, c224, c334, c445, c555, c445, c334, c224, c213};
recolorMenuManiaRenderer(soko->menuManiaRenderer, //
c401, c554, c522, // titleBgColor, titleTextColor, textOutlineColor
c444, // bgColor
c433, c334, // outerRingColor, innerRingColor
c111, c555, // rowColor, rowTextColor
shadowColors, ARRAY_SIZE(shadowColors), menuColor);

// addSingleItemToMenu(soko->menu, sokoResumeGameLabel);
addSingleItemToMenu(soko->menu, sokoPlayGameLabel);
addSingleItemToMenu(soko->menu, sokoHelpLabel);
Expand All @@ -130,6 +144,8 @@ static void sokoEnterMode(void)
// Set the mode to menu mode
soko->screen = SOKO_MENU;
soko->state = SKS_INIT;
setManiaLedsOn(soko->menuManiaRenderer, true);
setManiaDrawRings(soko->menuManiaRenderer, true);

// load up the level list.
soko->levelFileText = loadTxt("SK_LEVEL_LIST.txt", true);
Expand Down Expand Up @@ -217,6 +233,8 @@ static void sokoMenuCb(const char* label, bool selected, uint32_t settingVal)
{
soko->helpIdx = 0;
soko->screen = SOKO_HELP;
setManiaLedsOn(soko->menuManiaRenderer, false);
setManiaDrawRings(soko->menuManiaRenderer, false);
}
else if (sokoExitLabel == label)
{
Expand Down Expand Up @@ -246,6 +264,10 @@ static void sokoMainLoop(int64_t elapsedUs)
}
case SOKO_LEVELPLAY:
{
// Turn LEDs off
led_t offLeds[CONFIG_NUM_LEDS] = {0};
setLeds(offLeds, CONFIG_NUM_LEDS);

// pass along to other gameplay, in other file
// Always process button events, regardless of control scheme, so the main menu button can be captured
buttonEvt_t evt = {0};
Expand All @@ -265,6 +287,10 @@ static void sokoMainLoop(int64_t elapsedUs)
}
case SOKO_LOADNEWLEVEL:
{
// Turn LEDs off
led_t offLeds[CONFIG_NUM_LEDS] = {0};
setLeds(offLeds, CONFIG_NUM_LEDS);

sokoLoadGameplay(soko, soko->loadNewLevelIndex, soko->loadNewLevelFlag);
sokoInitNewLevel(soko, soko->currentLevel.gameMode);
ESP_LOGD(SOKO_TAG, "Go to gameplay");
Expand All @@ -274,6 +300,10 @@ static void sokoMainLoop(int64_t elapsedUs)
}
case SOKO_HELP:
{
// Turn LEDs off
led_t offLeds[CONFIG_NUM_LEDS] = {0};
setLeds(offLeds, CONFIG_NUM_LEDS);

buttonEvt_t evt = {0};
while (checkButtonQueueWrapper(&evt))
{
Expand Down
4 changes: 4 additions & 0 deletions main/modes/games/soko/sokoHelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void buttonSokoHelp(soko_abs_t* soko, buttonEvt_t* evt)
else
{
soko->screen = SOKO_MENU;
setManiaLedsOn(soko->menuManiaRenderer, true);
setManiaDrawRings(soko->menuManiaRenderer, true);
}
break;
}
Expand All @@ -171,6 +173,8 @@ void buttonSokoHelp(soko_abs_t* soko, buttonEvt_t* evt)
else
{
soko->screen = SOKO_MENU;
setManiaLedsOn(soko->menuManiaRenderer, true);
setManiaDrawRings(soko->menuManiaRenderer, true);
}
break;
}
Expand Down
2 changes: 2 additions & 0 deletions main/modes/games/soko/soko_gamerules.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ void overworldSokoGameLoop(soko_abs_t* self, int64_t elapsedUs)
{
self->input.exitToOverworld = false;
self->screen = SOKO_MENU;
setManiaLedsOn(self->menuManiaRenderer, true);
setManiaDrawRings(self->menuManiaRenderer, true);
}
}

Expand Down
4 changes: 4 additions & 0 deletions main/modes/games/soko/soko_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ void sokoLoadEulerTiles(soko_abs_t* soko)
// Level loading
void sokoLoadBinLevel(soko_abs_t* soko, uint16_t levelIndex)
{
if (levelIndex >= SOKO_LEVEL_COUNT)
{
return;
}
ESP_LOGD(SOKO_TAG, "load bin level %" PRIu16 ", %s", levelIndex, soko->levelNames[levelIndex]);
soko->state = SKS_INIT;
size_t fileSize;
Expand Down

0 comments on commit ff1f830

Please sign in to comment.