Skip to content

Commit

Permalink
Debug menu (#311)
Browse files Browse the repository at this point in the history
Fix up debug menu options, persistence, fanfare
  • Loading branch information
AEFeinstein authored Nov 10, 2024
1 parent 1a426c8 commit 5785224
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 59 deletions.
Binary file removed assets/menu/item.mid
Binary file not shown.
Binary file removed assets/menu/jingle.mid
Binary file not shown.
Binary file added assets/menu/secret.mid
Binary file not shown.
6 changes: 3 additions & 3 deletions main/modes/games/cGrove/mode_cGrove.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static const char cGroveTitle[] = "Chowa Grove"; // Game title
static const char* cGroveMenuNames[] = {"Play with Chowa", "Spar", "Race", "Perform", "Player Profiles", "Settings"};
static const char* cGroveSettingOpts[] = {"Grove Touch Scroll: ", "Online: "};
static const char* const cGroveEnabledOptions[] = {"Enabled", "Disabled"};
static const uint32_t cGroveEnabledVals[] = {true, false};
static const int32_t cGroveEnabledVals[] = {true, false};

static const char* cGroveTitleSprites[] = {"cg_cloud.wsg", "cg_sky.wsg",
"cg_title_1.wsg", "cg_title_2.wsg",
Expand Down Expand Up @@ -144,10 +144,10 @@ static void cGroveEnterMode(void)
cg->menu = startSubMenu(cg->menu, cGroveMenuNames[5]); // Settings
// FIXME: Load values from NVM
// TODO: Add more settings
addSettingsOptionsItemToMenu(cg->menu, cGroveSettingOpts[0], cGroveEnabledOptions, &cGroveEnabledVals,
addSettingsOptionsItemToMenu(cg->menu, cGroveSettingOpts[0], cGroveEnabledOptions, cGroveEnabledVals,
ARRAY_SIZE(cGroveEnabledOptions), getScreensaverTimeSettingBounds(),
0); // Enable/disable touch controls
addSettingsOptionsItemToMenu(cg->menu, cGroveSettingOpts[1], cGroveEnabledOptions, &cGroveEnabledVals,
addSettingsOptionsItemToMenu(cg->menu, cGroveSettingOpts[1], cGroveEnabledOptions, cGroveEnabledVals,
ARRAY_SIZE(cGroveEnabledOptions), getScreensaverTimeSettingBounds(),
0); // Enable/disable online functions
cg->menu = endSubMenu(cg->menu);
Expand Down
18 changes: 13 additions & 5 deletions main/modes/music/jukebox/jukebox.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ const char* JK_TAG = "JK";
*============================================================================*/

// Text
static const char str_bgm_muted[] = "Swadge music is muted!";
static const char str_sfx_muted[] = "Swadge SFX are muted!";
static const char str_bgm[] = "Music";
#ifdef SW_VOL_CONTROL
static const char str_bgm_muted[] = "Swadge music is muted!";
static const char str_sfx_muted[] = "Swadge SFX are muted!";
#endif
const char str_bgm[] = "Music";
static const char str_sfx[] = "SFX";
static const char str_leds[] = "B: LEDs:";
static const char str_music_sfx[] = "Pause: Music/SFX:";
Expand Down Expand Up @@ -221,13 +223,15 @@ const jukeboxCategory_t musicCategories[] = {

jukeboxSong_t sfx_mainMenu[] = {
{
.filename = "item.mid",
.name = "Item",
.filename = "secret.mid",
.name = "Secret",
},
#ifdef SW_VOL_CONTROL
{
.filename = "jingle.mid",
.name = "Jingle",
},
#endif
};

jukeboxSong_t sfx_factoryTest[] = {
Expand Down Expand Up @@ -582,13 +586,15 @@ void jukeboxMainLoop(int64_t elapsedUs)
bool drawNames = false;
if (jukebox->inMusicSubmode)
{
#ifdef SW_VOL_CONTROL
// Warn the user that the swadge is muted, if that's the case
if (getBgmVolumeSetting() == getBgmVolumeSettingBounds()->min)
{
drawText(&jukebox->radiostars, c551, str_bgm_muted,
(TFT_WIDTH - textWidth(&jukebox->radiostars, str_bgm_muted)) / 2, TFT_HEIGHT / 2);
}
else
#endif
{
categoryName = musicCategories[jukebox->categoryIdx].categoryName;
songName = musicCategories[jukebox->categoryIdx].songs[jukebox->songIdx].name;
Expand All @@ -599,13 +605,15 @@ void jukeboxMainLoop(int64_t elapsedUs)
}
else
{
#ifdef SW_VOL_CONTROL
// Warn the user that the swadge is muted, if that's the case
if (getSfxVolumeSetting() == getSfxVolumeSettingBounds()->min)
{
drawText(&jukebox->radiostars, c551, str_sfx_muted,
(TFT_WIDTH - textWidth(&jukebox->radiostars, str_sfx_muted)) / 2, TFT_HEIGHT / 2);
}
else
#endif
{
categoryName = sfxCategories[jukebox->categoryIdx].categoryName;
songName = sfxCategories[jukebox->categoryIdx].songs[jukebox->songIdx].name;
Expand Down
84 changes: 53 additions & 31 deletions main/modes/system/mainMenu/mainMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@
typedef struct
{
menu_t* menu;
menu_t* secretsMenu;
menuManiaRenderer_t* renderer;
font_t font_righteous;
font_t font_rodin;
midiFile_t jingle;
midiFile_t fanfare;
#ifdef SW_VOL_CONTROL
midiFile_t jingle;
int32_t lastBgmVol;
int32_t lastSfxVol;
#endif
int32_t cheatCodeIdx;
bool debugMode;
#ifdef SW_VOL_CONTROL
bool fanfarePlaying;
bool resetConfirmShown;
#endif
int32_t autoLightDanceTimer;
} mainMenu_t;

Expand All @@ -70,16 +72,16 @@ void addSecretsMenu(void);
// It's good practice to declare immutable strings as const so they get placed in ROM, not RAM
const char mainMenuName[] = "Main Menu";
const char mainMenuTitle[] = "Swadge";
static const char mainMenuShowSecretsMenuName[] = "ShowOnMenu: ";
static const char mainMenuShowSecretsMenuName[] = "Secrets In Menu: ";
static const char factoryResetName[] = "Factory Reset";
static const char confirmResetName[] = "! Confirm Reset !";

swadgeMode_t mainMenuMode = {
.modeName = mainMenuName,
.wifiMode = NO_WIFI,
.overrideUsb = false,
.usesAccelerometer = true,
.usesThermometer = true,
.usesAccelerometer = false,
.usesThermometer = false,
.overrideSelectBtn = true,
.fnEnterMode = mainMenuEnterMode,
.fnExitMode = mainMenuExitMode,
Expand All @@ -95,11 +97,13 @@ mainMenu_t* mainMenu;

static const char settingsLabel[] = "Settings";

static const char tftSettingLabel[] = "TFT";
static const char ledSettingLabel[] = "LED";
static const char bgmVolSettingLabel[] = "BGM";
static const char sfxVolSettingLabel[] = "SFX";
static const char micSettingLabel[] = "MIC";
static const char tftSettingLabel[] = "TFT";
static const char ledSettingLabel[] = "LED";
#ifdef SW_VOL_CONTROL
static const char bgmVolSettingLabel[] = "BGM";
static const char sfxVolSettingLabel[] = "SFX";
#endif
const char micSettingLabel[] = "MIC";
static const char screenSaverSettingsLabel[] = "Screensaver: ";

static const int32_t screenSaverSettingsValues[] = {
Expand Down Expand Up @@ -147,8 +151,12 @@ static void mainMenuEnterMode(void)
loadFont("righteous_150.font", &mainMenu->font_righteous, false);

// Load a song for when the volume changes
#ifdef SW_VOL_CONTROL
loadMidiFile("jingle.mid", &mainMenu->jingle, false);
loadMidiFile("item.mid", &mainMenu->fanfare, false);
#endif
loadMidiFile("secret.mid", &mainMenu->fanfare, true);
initGlobalMidiPlayer();
midiGmOn(globalMidiPlayerGet(MIDI_BGM));

// Allocate the menu
mainMenu->menu = initMenu(mainMenuTitle, mainMenuCb);
Expand Down Expand Up @@ -186,13 +194,17 @@ static void mainMenuEnterMode(void)
// Get the bounds and current settings to build this menu
addSettingsItemToMenu(mainMenu->menu, tftSettingLabel, getTftBrightnessSettingBounds(), getTftBrightnessSetting());
addSettingsItemToMenu(mainMenu->menu, ledSettingLabel, getLedBrightnessSettingBounds(), getLedBrightnessSetting());
#ifdef SW_VOL_CONTROL
addSettingsItemToMenu(mainMenu->menu, bgmVolSettingLabel, getBgmVolumeSettingBounds(), getBgmVolumeSetting());
addSettingsItemToMenu(mainMenu->menu, sfxVolSettingLabel, getSfxVolumeSettingBounds(), getSfxVolumeSetting());
#endif
addSettingsItemToMenu(mainMenu->menu, micSettingLabel, getMicGainSettingBounds(), getMicGainSetting());

#ifdef SW_VOL_CONTROL
// These are just used for playing the sound only when the setting changes
mainMenu->lastBgmVol = getBgmVolumeSetting();
mainMenu->lastSfxVol = getSfxVolumeSetting();
#endif

addSettingsOptionsItemToMenu(mainMenu->menu, screenSaverSettingsLabel, screenSaverSettingsOptions,
screenSaverSettingsValues, ARRAY_SIZE(screenSaverSettingsValues),
Expand All @@ -210,9 +222,6 @@ static void mainMenuEnterMode(void)

// Initialize menu renderer
mainMenu->renderer = initMenuManiaRenderer(NULL, NULL, NULL);

// Make it smooth
setFrameRateUs(1000000 / 60);
}

/**
Expand All @@ -231,7 +240,9 @@ static void mainMenuExitMode(void)
freeFont(&mainMenu->font_righteous);

// Free the song
#ifdef SW_VOL_CONTROL
unloadMidiFile(&mainMenu->jingle);
#endif
unloadMidiFile(&mainMenu->fanfare);

// Free mode memory
Expand Down Expand Up @@ -271,9 +282,10 @@ static void mainMenuMainLoop(int64_t elapsedUs)
if (mainMenu->cheatCodeIdx >= ARRAY_SIZE(cheatCode))
{
mainMenu->cheatCodeIdx = 0;
soundPlayBgm(&mainMenu->fanfare, BZR_STEREO);
globalMidiPlayerPlaySong(&mainMenu->fanfare, MIDI_BGM);
#ifdef SW_VOL_CONTROL
mainMenu->fanfarePlaying = true;

#endif
// Return to the top level menu
while (mainMenu->menu->parentMenu)
{
Expand Down Expand Up @@ -315,11 +327,13 @@ static void mainMenuCb(const char* label, bool selected, uint32_t settingVal)
// Stop the buzzer first no matter what, so that it turns off
// if we scroll away from the BGM or SFX settings.

#ifdef SW_VOL_CONTROL
// Stop the buzzer when changing volume, not for fanfare
if (false == mainMenu->fanfarePlaying)
{
soundStop(true);
}
#endif

if (selected)
{
Expand Down Expand Up @@ -412,16 +426,6 @@ static void mainMenuCb(const char* label, bool selected, uint32_t settingVal)
{
switchToSwadgeMode(&t48Mode);
}
else if (label == factoryResetName)
{
if (!mainMenu->resetConfirmShown)
{
mainMenu->resetConfirmShown = true;
removeSingleItemFromMenu(mainMenu->menu, mnuBackStr);
addSingleItemToMenu(mainMenu->secretsMenu, confirmResetName);
addSingleItemToMenu(mainMenu->menu, mnuBackStr);
}
}
else if (label == confirmResetName)
{
if (eraseNvs())
Expand All @@ -445,6 +449,7 @@ static void mainMenuCb(const char* label, bool selected, uint32_t settingVal)
{
setLedBrightnessSetting(settingVal);
}
#ifdef SW_VOL_CONTROL
else if (bgmVolSettingLabel == label)
{
if (settingVal != mainMenu->lastBgmVol)
Expand All @@ -465,6 +470,7 @@ static void mainMenuCb(const char* label, bool selected, uint32_t settingVal)
mainMenu->fanfarePlaying = false;
}
}
#endif
else if (micSettingLabel == label)
{
setMicGainSetting(settingVal);
Expand All @@ -473,25 +479,41 @@ static void mainMenuCb(const char* label, bool selected, uint32_t settingVal)
{
setScreensaverTimeSetting(settingVal);
}
else if (mainMenuShowSecretsMenuName == label)
{
setShowSecretsMenuSetting(settingVal);
}
}
}

void addSecretsMenu(void)
{
mainMenu->debugMode = true;

// Return to the root
while (mainMenu->menu->parentMenu)
{
mainMenu->menu = mainMenu->menu->parentMenu;
}

// Add the secrets menu
mainMenu->menu = startSubMenu(mainMenu->menu, "Secrets");
mainMenu->secretsMenu = mainMenu->menu;
mainMenu->menu = startSubMenu(mainMenu->menu, "Secrets");

addSingleItemToMenu(mainMenu->menu, "Git Hash: " GIT_SHA1);
addSettingsOptionsItemToMenu(mainMenu->menu, mainMenuShowSecretsMenuName, showSecretsMenuSettingOptions,
showSecretsMenuSettingValues, ARRAY_SIZE(showSecretsMenuSettingOptions),
getShowSecretsMenuSettingBounds(), getShowSecretsMenuSetting());
// addSingleItemToMenu(mainMenu->menu, demoMode.modeName);

addSingleItemToMenu(mainMenu->menu, keebTestMode.modeName);
addSingleItemToMenu(mainMenu->menu, accelTestMode.modeName);
addSingleItemToMenu(mainMenu->menu, touchTestMode.modeName);
addSingleItemToMenu(mainMenu->menu, factoryTestMode.modeName);
addSingleItemToMenu(mainMenu->menu, factoryResetName);

mainMenu->menu = startSubMenu(mainMenu->menu, factoryResetName);
addSingleItemToMenu(mainMenu->menu, confirmResetName);
// Back is automatically added
mainMenu->menu = endSubMenu(mainMenu->menu);

// End the secrets menu
mainMenu->menu = endSubMenu(mainMenu->menu);
}
Loading

0 comments on commit 5785224

Please sign in to comment.