Skip to content

Commit

Permalink
Swadge Hero (#300)
Browse files Browse the repository at this point in the history
Lots of Swadge Hero Progress

Added recolorMenuManiaRenderer()
  • Loading branch information
AEFeinstein authored Oct 5, 2024
1 parent 2778516 commit 69da2a1
Show file tree
Hide file tree
Showing 19 changed files with 1,088 additions and 238 deletions.
Binary file added assets/swadgeHero/sh_a.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/swadgeHero/sh_b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/swadgeHero/sh_down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/swadgeHero/sh_left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/swadgeHero/sh_right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/swadgeHero/sh_up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ idf_component_register(SRCS "asset_loaders/common/heatshrink_encoder.c"
"modes/games/soko/soko_undo.c"
"modes/games/swadgeHero/mode_swadgeHero.c"
"modes/games/swadgeHero/swadgeHero_game.c"
"modes/games/swadgeHero/swadgeHero_gameEnd.c"
"modes/games/swadgeHero/swadgeHero_menu.c"
"modes/games/ultimateTTT/ultimateTTT.c"
"modes/games/ultimateTTT/ultimateTTTcpuPlayer.c"
Expand Down
104 changes: 71 additions & 33 deletions main/menu/menuManiaRenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@
#define UP_ARROW_HEIGHT 10
#define UP_ARROW_MARGIN 2

#define TITLE_BG_COLOR c115
#define TITLE_TEXT_COLOR c542
#define TEXT_OUTLINE_COLOR c000
#define BG_COLOR c540
#define OUTER_RING_COLOR c243
#define INNER_RING_COLOR c531
#define ROW_COLOR c000
#define ROW_TEXT_COLOR c555
// #define ROW_TEXT_SELECTED_COLOR c533

#define ORBIT_RING_RADIUS_1 26
#define ORBIT_RING_RADIUS_2 18
#define RING_STROKE_THICKNESS 8
Expand All @@ -55,7 +45,7 @@
//==============================================================================

/// @brief Colors to cycle through for the selected drop shadow
static const paletteColor_t selectedShadowColors[] = {
static const paletteColor_t defaultShadowColors[] = {
c500, c511, c522, c533, c544, c555, c544, c533, c522, c511,
};

Expand Down Expand Up @@ -91,6 +81,18 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO
{
menuManiaRenderer_t* renderer = heap_caps_calloc(1, sizeof(menuManiaRenderer_t), MALLOC_CAP_SPIRAM);

// Default colors
renderer->titleBgColor = c115;
renderer->titleTextColor = c542;
renderer->textOutlineColor = c000;
renderer->bgColor = c540;
renderer->outerRingColor = c243;
renderer->innerRingColor = c531;
renderer->rowColor = c000;
renderer->rowTextColor = c555;
renderer->shadowColors = defaultShadowColors;
renderer->shadowColorsLen = ARRAY_SIZE(defaultShadowColors);

// Save or allocate title font
if (NULL == titleFont)
{
Expand Down Expand Up @@ -141,8 +143,8 @@ menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontO

// Initialize Rings
const paletteColor_t ringColors[] = {
INNER_RING_COLOR,
OUTER_RING_COLOR,
renderer->innerRingColor,
renderer->outerRingColor,
};
int32_t ringMinSpeed = 15000;
int32_t ringMaxSpeed = 20000;
Expand Down Expand Up @@ -215,7 +217,7 @@ static void drawMenuText(menuManiaRenderer_t* renderer, const char* text, int16_
bool leftArrow, bool rightArrow, bool doubleArrows)
{
// Pick colors based on selection
paletteColor_t textColor = ROW_TEXT_COLOR;
paletteColor_t textColor = renderer->rowTextColor;
if (isSelected)
{
// Draw drop shadow for selected item
Expand All @@ -225,7 +227,7 @@ static void drawMenuText(menuManiaRenderer_t* renderer, const char* text, int16_
y + rows + DROP_SHADOW_OFFSET, //
x + PARALLELOGRAM_HEIGHT - rows - 1 + PARALLELOGRAM_WIDTH + DROP_SHADOW_OFFSET, //
y + rows + DROP_SHADOW_OFFSET, //
selectedShadowColors[renderer->selectedShadowIdx]);
renderer->shadowColors[renderer->selectedShadowIdx]);
}

// Bounce the item
Expand All @@ -239,7 +241,7 @@ static void drawMenuText(menuManiaRenderer_t* renderer, const char* text, int16_
y + rows, //
x + PARALLELOGRAM_HEIGHT - rows - 1 + PARALLELOGRAM_WIDTH, //
y + rows, //
ROW_COLOR);
renderer->rowColor);
}

// Draw the text
Expand Down Expand Up @@ -328,27 +330,28 @@ static void drawMenuText(menuManiaRenderer_t* renderer, const char* text, int16_
*
* @param radius The radius of the ring
* @param angle The angle of the ring for orbiting circles
* @param color The color of the ring
* @param ringColor The color of the ring
* @param bgColor The color of the background
*/
static void drawManiaRing(int16_t radius, int16_t angle, paletteColor_t color)
static void drawManiaRing(int16_t radius, int16_t angle, paletteColor_t ringColor, paletteColor_t bgColor)
{
// Draw the ring
drawCircleOutline(TFT_WIDTH / 2, TFT_HEIGHT / 2, radius, RING_STROKE_THICKNESS, color);
drawCircleOutline(TFT_WIDTH / 2, TFT_HEIGHT / 2, radius, RING_STROKE_THICKNESS, ringColor);

// Draw the the smaller ring on the orbit (two filled circles)
vec_t circlePos = {
.x = 0,
.y = -radius + (RING_STROKE_THICKNESS / 2),
};
circlePos = rotateVec2d(circlePos, angle);
drawCircleFilled((TFT_WIDTH / 2) + circlePos.x, (TFT_HEIGHT / 2) + circlePos.y, ORBIT_RING_RADIUS_1, color);
drawCircleFilled((TFT_WIDTH / 2) + circlePos.x, (TFT_HEIGHT / 2) + circlePos.y, ORBIT_RING_RADIUS_1, ringColor);
drawCircleFilled((TFT_WIDTH / 2) + circlePos.x, (TFT_HEIGHT / 2) + circlePos.y,
ORBIT_RING_RADIUS_1 - RING_STROKE_THICKNESS, BG_COLOR);
ORBIT_RING_RADIUS_1 - RING_STROKE_THICKNESS, bgColor);

// Draw an opposite filled circle
circlePos.x = -circlePos.x;
circlePos.y = -circlePos.y;
drawCircleFilled((TFT_WIDTH / 2) + circlePos.x, (TFT_HEIGHT / 2) + circlePos.y, ORBIT_RING_RADIUS_2, color);
drawCircleFilled((TFT_WIDTH / 2) + circlePos.x, (TFT_HEIGHT / 2) + circlePos.y, ORBIT_RING_RADIUS_2, ringColor);
}

/**
Expand Down Expand Up @@ -379,7 +382,7 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
while (renderer->ledExciteTimer >= 40000 * 8)
{
renderer->ledExciteTimer -= 40000 * 8;
uint32_t ledColor = paletteToRGB(BG_COLOR);
uint32_t ledColor = paletteToRGB(renderer->bgColor);
renderer->leds[renderer->currentLed].r = ((ledColor >> 16) & 0xFF) / 2;
renderer->leds[renderer->currentLed].g = ((ledColor >> 8) & 0xFF) / 2;
renderer->leds[renderer->currentLed].b = ((ledColor >> 0) & 0xFF) / 2;
Expand Down Expand Up @@ -443,7 +446,7 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
while (renderer->selectedShadowTimer > (100000))
{
renderer->selectedShadowTimer -= (100000);
renderer->selectedShadowIdx = (renderer->selectedShadowIdx + 1) % ARRAY_SIZE(selectedShadowColors);
renderer->selectedShadowIdx = (renderer->selectedShadowIdx + 1) % renderer->shadowColorsLen;
}

// Run a timer to bounce the selected item, when transitioned to
Expand All @@ -468,15 +471,15 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
renderer->selectedMarqueeTimer += elapsedUs;

// Clear the background
fillDisplayArea(0, 0, TFT_WIDTH, TFT_HEIGHT, BG_COLOR);
fillDisplayArea(0, 0, TFT_WIDTH, TFT_HEIGHT, 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);
drawManiaRing(ringRadius, ring->orbitAngle, ring->color, renderer->bgColor);
}

// Find the start of the 'page'
Expand Down Expand Up @@ -513,18 +516,18 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
int16_t titleBgX1 = (TFT_WIDTH + tWidth) / 2 + 6;
int16_t titleBgY0 = y;
int16_t titleBgY1 = y + TITLE_BG_HEIGHT;
fillDisplayArea(titleBgX0, titleBgY0, titleBgX1, titleBgY1, TITLE_BG_COLOR);
fillDisplayArea(titleBgX0, titleBgY0, titleBgX1, titleBgY1, renderer->titleBgColor);
drawTriangleOutlined(titleBgX0, titleBgY0, titleBgX0, titleBgY1, titleBgX0 - (TITLE_BG_HEIGHT / 2),
(titleBgY0 + titleBgY1) / 2, TITLE_BG_COLOR, TITLE_BG_COLOR);
(titleBgY0 + titleBgY1) / 2, renderer->titleBgColor, renderer->titleBgColor);
drawTriangleOutlined(titleBgX1, titleBgY0, titleBgX1, titleBgY1, titleBgX1 + (TITLE_BG_HEIGHT / 2),
(titleBgY0 + titleBgY1) / 2, TITLE_BG_COLOR, TITLE_BG_COLOR);
(titleBgY0 + titleBgY1) / 2, renderer->titleBgColor, renderer->titleBgColor);

// Draw a title
y += (TITLE_BG_HEIGHT - renderer->titleFont->height) / 2;
// Draw the menu text
drawText(renderer->titleFont, TITLE_TEXT_COLOR, menu->title, (TFT_WIDTH - tWidth) / 2, y);
drawText(renderer->titleFont, renderer->titleTextColor, menu->title, (TFT_WIDTH - tWidth) / 2, y);
// Outline the menu text
drawText(renderer->titleFontOutline, TEXT_OUTLINE_COLOR, menu->title, (TFT_WIDTH - tWidth) / 2, y);
drawText(renderer->titleFontOutline, renderer->textOutlineColor, menu->title, (TFT_WIDTH - tWidth) / 2, y);

// Move to drawing the rows
y = titleBgY1 + Y_SECTION_MARGIN;
Expand All @@ -537,7 +540,7 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
{
drawLineFast(PARALLELOGRAM_X_OFFSET + PARALLELOGRAM_HEIGHT - t + (UP_ARROW_HEIGHT * 2 - 1) / 2, y + t,
PARALLELOGRAM_X_OFFSET + PARALLELOGRAM_HEIGHT + t + (UP_ARROW_HEIGHT * 2 - 1) / 2, y + t,
ROW_COLOR);
renderer->rowColor);
}
y += (UP_ARROW_HEIGHT);
}
Expand Down Expand Up @@ -598,7 +601,7 @@ void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedU
{
drawLineFast(PARALLELOGRAM_X_OFFSET + PARALLELOGRAM_WIDTH - t - (UP_ARROW_HEIGHT * 2) / 2, y - t,
PARALLELOGRAM_X_OFFSET + PARALLELOGRAM_WIDTH + t - (UP_ARROW_HEIGHT * 2) / 2, y - t,
ROW_COLOR);
renderer->rowColor);
}
}

Expand Down Expand Up @@ -644,3 +647,38 @@ void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn)
setLeds(renderer->leds, CONFIG_NUM_LEDS);
}
}

/**
* @brief Recolor a menu renderer
*
* @param renderer The menu renderer to recolor
* @param titleBgColor The color of the title background
* @param titleTextColor The color of the title text
* @param textOutlineColor The color of the title text outline
* @param bgColor The color of the screen background
* @param outerRingColor The color of the outer rotating ring
* @param innerRingColor The color of the inner rotating ring
* @param rowColor The color of the row background
* @param rowTextColor The color of the row text
* @param shadowColors The colors cycled through as the selected shadow
* @param shadowColorsLen The number of selected shadow colors to cycle through
*/
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,
const paletteColor_t* shadowColors, int32_t shadowColorsLen)
{
renderer->titleBgColor = titleBgColor;
renderer->titleTextColor = titleTextColor;
renderer->textOutlineColor = textOutlineColor;
renderer->bgColor = bgColor;
renderer->outerRingColor = outerRingColor;
renderer->innerRingColor = innerRingColor;
renderer->rings[0].color = outerRingColor;
renderer->rings[1].color = innerRingColor;
renderer->rowColor = rowColor;
renderer->rowTextColor = rowTextColor;
renderer->shadowColors = shadowColors;
renderer->shadowColorsLen = shadowColorsLen;
renderer->selectedShadowIdx = 0;
}
15 changes: 15 additions & 0 deletions main/menu/menuManiaRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,26 @@ typedef struct
int32_t selectedBounceTimer; ///< The timer to bounce the offset for the selected item
int32_t selectedValue; ///< The option index or setting value to tell when it changes
int32_t selectedMarqueeTimer; ///< The timer for marquee-ing the selected item text, if too long to fit

paletteColor_t titleBgColor; ///< The color of the title background
paletteColor_t titleTextColor; ///< The color of the title text
paletteColor_t textOutlineColor; ///< The color of the title text outline
paletteColor_t bgColor; ///< The color of the screen background
paletteColor_t outerRingColor; ///< The color of the outer rotating ring
paletteColor_t innerRingColor; ///< The color of the inner rotating ring
paletteColor_t rowColor; ///< The color of the row background
paletteColor_t rowTextColor; ///< The color of the row text
const paletteColor_t* shadowColors; ///< The colors cycled through as the selected shadow
int32_t shadowColorsLen; ///< The number of selected shadow colors to cycle through
} menuManiaRenderer_t;

menuManiaRenderer_t* initMenuManiaRenderer(font_t* titleFont, font_t* titleFontOutline, font_t* menuFont);
void deinitMenuManiaRenderer(menuManiaRenderer_t* renderer);
void drawMenuMania(menu_t* menu, menuManiaRenderer_t* renderer, int64_t elapsedUs);
void setManiaLedsOn(menuManiaRenderer_t* renderer, bool ledsOn);
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,
const paletteColor_t* shadowColors, int32_t shadowColorsLen);

#endif
11 changes: 9 additions & 2 deletions main/midi/midiPlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,14 @@ void midiSeek(midiPlayer_t* player, uint32_t ticks)
if (!player->eventAvailable || player->pendingEvent.absTime > ticks)
{
ESP_LOGD("MIDI", "No more events between start and end time\n");
curTick = ticks;
if ((META_EVENT == player->pendingEvent.type) && (END_OF_TRACK == player->pendingEvent.meta.type))
{
curTick = player->pendingEvent.absTime;
}
else
{
curTick = ticks;
}
break;
}

Expand All @@ -2353,7 +2360,7 @@ void midiSeek(midiPlayer_t* player, uint32_t ticks)

stopped = !player->eventAvailable
&& !(player->eventAvailable = midiNextEvent(&player->reader, &player->pendingEvent));
if (stopped)
if (stopped && (uint32_t)-1 != ticks)
{
midiSongEnd(player);

Expand Down
3 changes: 2 additions & 1 deletion main/midi/midiPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,8 @@ void midiPause(midiPlayer_t* player, bool pause);
* large MIDI files.
*
* @param player The MIDI player to seek on
* @param ticks The absolute number of MIDI ticks to seek to.
* @param ticks The absolute number of MIDI ticks to seek to. If this is -1, it
* will seek to the end of the song
*/
void midiSeek(midiPlayer_t* player, uint32_t ticks);

Expand Down
Loading

0 comments on commit 69da2a1

Please sign in to comment.