From 9959a8067fb841c47cacdf291e60efbfc6a4afcf Mon Sep 17 00:00:00 2001 From: citrusbolt Date: Tue, 20 Apr 2021 11:30:16 -0600 Subject: [PATCH] Add 12/24 hour option for clock --- include/global.h | 2 ++ include/strings.h | 5 ++++ src/option_menu.c | 51 ++++++++++++++++++++++++++++++---- src/start_menu.c | 70 +++++++++++++++++++++++++++++++++++++++++------ src/strings.c | 5 ++++ 5 files changed, 119 insertions(+), 14 deletions(-) diff --git a/include/global.h b/include/global.h index 6f4847c0ff..d66e4b81e6 100644 --- a/include/global.h +++ b/include/global.h @@ -477,6 +477,8 @@ struct SaveBlock2 u16 optionsBattleStyle:1; // OPTIONS_BATTLE_STYLE_[SHIFT/SET] u16 optionsBattleSceneOff:1; // whether battle animations are disabled u16 regionMapZoom:1; // whether the map is zoomed in + u16 options24HourClock:1; + u16 extraOptionsFiller:3; /*0x18*/ struct Pokedex pokedex; /*0x90*/ u8 filler_90[0x8]; /*0x98*/ struct Time localTimeOffset; diff --git a/include/strings.h b/include/strings.h index 38b0af39e1..d1d0f74b33 100644 --- a/include/strings.h +++ b/include/strings.h @@ -3159,5 +3159,10 @@ extern const u8 gText_EggFromJohto[]; extern const u8 gText_BadEggDesc[]; extern const u8 gText_CurrentTime[]; extern const u8 gText_CurrentTimeOff[]; +extern const u8 gText_CurrentTimeAM[]; +extern const u8 gText_CurrentTimeAMOff[]; +extern const u8 gText_CurrentTimePM[]; +extern const u8 gText_CurrentTimePMOff[]; +extern const u8 gText_ClockOption[]; #endif // GUARD_STRINGS_H diff --git a/src/option_menu.c b/src/option_menu.c index 936aff9233..2bcc36e3b3 100644 --- a/src/option_menu.c +++ b/src/option_menu.c @@ -26,6 +26,7 @@ enum TD_SOUND, TD_BUTTONMODE, TD_FRAMETYPE, + TD_CLOCK }; // Menu items @@ -37,7 +38,8 @@ enum MENUITEM_SOUND, MENUITEM_BUTTONMODE, MENUITEM_FRAMETYPE, - MENUITEM_CANCEL, + MENUITEM_CLOCK, + //MENUITEM_CANCEL, MENUITEM_COUNT, }; @@ -54,6 +56,7 @@ enum #define YPOS_SOUND (MENUITEM_SOUND * 16) #define YPOS_BUTTONMODE (MENUITEM_BUTTONMODE * 16) #define YPOS_FRAMETYPE (MENUITEM_FRAMETYPE * 16) +#define YPOS_CLOCK (MENUITEM_CLOCK * 16) // this file's functions static void Task_OptionMenuFadeIn(u8 taskId); @@ -73,6 +76,8 @@ static u8 FrameType_ProcessInput(u8 selection); static void FrameType_DrawChoices(u8 selection); static u8 ButtonMode_ProcessInput(u8 selection); static void ButtonMode_DrawChoices(u8 selection); +static u8 Clock_ProcessInput(u8 selection); +static void Clock_DrawChoices(u8 selection); static void DrawTextOption(void); static void DrawOptionMenuTexts(void); static void DrawBgWindowFrames(void); @@ -91,7 +96,8 @@ static const u8 *const sOptionMenuItemsNames[MENUITEM_COUNT] = [MENUITEM_SOUND] = gText_Sound, [MENUITEM_BUTTONMODE] = gText_ButtonMode, [MENUITEM_FRAMETYPE] = gText_Frame, - [MENUITEM_CANCEL] = gText_OptionMenuCancel, + [MENUITEM_CLOCK] = gText_ClockOption, + //[MENUITEM_CANCEL] = gText_OptionMenuCancel, }; static const struct WindowTemplate sOptionMenuWinTemplates[] = @@ -242,6 +248,7 @@ void CB2_InitOptionMenu(void) gTasks[taskId].data[TD_SOUND] = gSaveBlock2Ptr->optionsSound; gTasks[taskId].data[TD_BUTTONMODE] = gSaveBlock2Ptr->optionsButtonMode; gTasks[taskId].data[TD_FRAMETYPE] = gSaveBlock2Ptr->optionsWindowFrameType; + gTasks[taskId].data[TD_CLOCK] = gSaveBlock2Ptr->options24HourClock; TextSpeed_DrawChoices(gTasks[taskId].data[TD_TEXTSPEED]); BattleScene_DrawChoices(gTasks[taskId].data[TD_BATTLESCENE]); @@ -249,6 +256,7 @@ void CB2_InitOptionMenu(void) Sound_DrawChoices(gTasks[taskId].data[TD_SOUND]); ButtonMode_DrawChoices(gTasks[taskId].data[TD_BUTTONMODE]); FrameType_DrawChoices(gTasks[taskId].data[TD_FRAMETYPE]); + Clock_DrawChoices(gTasks[taskId].data[TD_CLOCK]); HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); CopyWindowToVram(WIN_OPTIONS, 3); @@ -273,7 +281,7 @@ static void Task_OptionMenuProcessInput(u8 taskId) { if (JOY_NEW(A_BUTTON)) { - if (gTasks[taskId].data[TD_MENUSELECTION] == MENUITEM_CANCEL) + //if (gTasks[taskId].data[TD_MENUSELECTION] == MENUITEM_CANCEL) gTasks[taskId].func = Task_OptionMenuSave; } else if (JOY_NEW(B_BUTTON)) @@ -285,12 +293,14 @@ static void Task_OptionMenuProcessInput(u8 taskId) if (gTasks[taskId].data[TD_MENUSELECTION] > 0) gTasks[taskId].data[TD_MENUSELECTION]--; else - gTasks[taskId].data[TD_MENUSELECTION] = MENUITEM_CANCEL; + gTasks[taskId].data[TD_MENUSELECTION] = MENUITEM_CLOCK; + // gTasks[taskId].data[TD_MENUSELECTION] = MENUITEM_CANCEL; HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); } else if (JOY_NEW(DPAD_DOWN)) { - if (gTasks[taskId].data[TD_MENUSELECTION] < MENUITEM_CANCEL) + //if (gTasks[taskId].data[TD_MENUSELECTION] < MENUITEM_CANCEL) + if (gTasks[taskId].data[TD_MENUSELECTION] < MENUITEM_CLOCK) gTasks[taskId].data[TD_MENUSELECTION]++; else gTasks[taskId].data[TD_MENUSELECTION] = 0; @@ -344,6 +354,13 @@ static void Task_OptionMenuProcessInput(u8 taskId) if (previousOption != gTasks[taskId].data[TD_FRAMETYPE]) FrameType_DrawChoices(gTasks[taskId].data[TD_FRAMETYPE]); break; + case MENUITEM_CLOCK: + previousOption = gTasks[taskId].data[TD_CLOCK]; + gTasks[taskId].data[TD_CLOCK] = Clock_ProcessInput(gTasks[taskId].data[TD_CLOCK]); + + if (previousOption != gTasks[taskId].data[TD_CLOCK]) + Clock_DrawChoices(gTasks[taskId].data[TD_CLOCK]); + break; default: return; } @@ -364,6 +381,7 @@ static void Task_OptionMenuSave(u8 taskId) gSaveBlock2Ptr->optionsSound = gTasks[taskId].data[TD_SOUND]; gSaveBlock2Ptr->optionsButtonMode = gTasks[taskId].data[TD_BUTTONMODE]; gSaveBlock2Ptr->optionsWindowFrameType = gTasks[taskId].data[TD_FRAMETYPE]; + gSaveBlock2Ptr->options24HourClock = gTasks[taskId].data[TD_CLOCK]; BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_OptionMenuFadeOut; @@ -623,6 +641,29 @@ static void ButtonMode_DrawChoices(u8 selection) DrawOptionMenuChoice(gText_ButtonTypeLEqualsA, GetStringRightAlignXOffset(1, gText_ButtonTypeLEqualsA, 198), YPOS_BUTTONMODE, styles[2]); } +static u8 Clock_ProcessInput(u8 selection) +{ + if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + { + selection ^= 1; + sArrowPressed = TRUE; + } + + return selection; +} + +static void Clock_DrawChoices(u8 selection) +{ + u8 styles[2]; + + styles[0] = 0; + styles[1] = 0; + styles[selection] = 1; + + DrawOptionMenuChoice(gText_BattleSceneOn, 104, YPOS_CLOCK, styles[0]); + DrawOptionMenuChoice(gText_BattleSceneOff, GetStringRightAlignXOffset(1, gText_BattleSceneOff, 198), YPOS_CLOCK, styles[1]); +} + static void DrawTextOption(void) { FillWindowPixelBuffer(WIN_TEXT_OPTION, PIXEL_FILL(1)); diff --git a/src/start_menu.c b/src/start_menu.c index b2be9ca42c..21bf9d1b7c 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -210,7 +210,8 @@ static const struct WindowTemplate sSaveInfoWindowTemplate = { .baseBlock = 8 }; -static const struct WindowTemplate sCurrentTimeWindowTemplate = {0, 1, 17, 4, 2, 0xF, 48}; +static const struct WindowTemplate sCurrentTime24WindowTemplate = {0, 1, 17, 4, 2, 0xF, 48}; +static const struct WindowTemplate sCurrentTimeWindowTemplate = {0, 1, 17, 7, 2, 0xF, 48}; // Local functions static void BuildStartMenuActions(void); @@ -1432,13 +1433,37 @@ void AppendToList(u8 *list, u8 *pos, u8 newEntry) static void ShowCurrentTimeWindow(void) { RtcCalcLocalTime(); - sCurrentTimeWindowId = AddWindow(&sCurrentTimeWindowTemplate); + if (gSaveBlock2Ptr->options24HourClock) + sCurrentTimeWindowId = AddWindow(&sCurrentTime24WindowTemplate); + else + sCurrentTimeWindowId = AddWindow(&sCurrentTimeWindowTemplate); PutWindowTilemap(sCurrentTimeWindowId); DrawStdWindowFrame(sCurrentTimeWindowId, FALSE); FlagSet(FLAG_TEMP_5); - ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours, STR_CONV_MODE_LEADING_ZEROS, 2); - ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); - StringExpandPlaceholders(gStringVar4, gText_CurrentTime); + if (gSaveBlock2Ptr->options24HourClock) + { + ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours, STR_CONV_MODE_LEADING_ZEROS, 2); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); + StringExpandPlaceholders(gStringVar4, gText_CurrentTime); + } + else + { + if (gLocalTime.hours >= 12) + { + ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours - 12, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); + StringExpandPlaceholders(gStringVar4, gText_CurrentTimePM); + } + else + { + if (gLocalTime.hours == 0) + ConvertIntToDecimalStringN(gStringVar1, 12, STR_CONV_MODE_LEADING_ZEROS, 2); + else + ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); + StringExpandPlaceholders(gStringVar4, gText_CurrentTimeAM); + } + } AddTextPrinterParameterized(sCurrentTimeWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL); CopyWindowToVram(sCurrentTimeWindowId, 2); } @@ -1448,12 +1473,39 @@ void UpdateClockDisplay(void) if (!FlagGet(FLAG_TEMP_5)) return; RtcCalcLocalTime(); - ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours, STR_CONV_MODE_LEADING_ZEROS, 2); - ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); - if (gLocalTime.seconds % 2) + if (gSaveBlock2Ptr->options24HourClock) + { + ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours, STR_CONV_MODE_LEADING_ZEROS, 2); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); StringExpandPlaceholders(gStringVar4, gText_CurrentTime); + } else - StringExpandPlaceholders(gStringVar4, gText_CurrentTimeOff); + { + if (gLocalTime.hours >= 12) + { + if (gLocalTime.hours == 12) + ConvertIntToDecimalStringN(gStringVar1, 12, STR_CONV_MODE_LEADING_ZEROS, 2); + else + ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours - 12, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); + if (gLocalTime.seconds % 2) + StringExpandPlaceholders(gStringVar4, gText_CurrentTimePM); + else + StringExpandPlaceholders(gStringVar4, gText_CurrentTimePMOff); + } + else + { + if (gLocalTime.hours == 0) + ConvertIntToDecimalStringN(gStringVar1, 12, STR_CONV_MODE_LEADING_ZEROS, 2); + else + ConvertIntToDecimalStringN(gStringVar1, gLocalTime.hours, STR_CONV_MODE_RIGHT_ALIGN, 2); + ConvertIntToDecimalStringN(gStringVar2, gLocalTime.minutes, STR_CONV_MODE_LEADING_ZEROS, 2); + if (gLocalTime.seconds % 2) + StringExpandPlaceholders(gStringVar4, gText_CurrentTimeAM); + else + StringExpandPlaceholders(gStringVar4, gText_CurrentTimeAMOff); + } + } AddTextPrinterParameterized(sCurrentTimeWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL); CopyWindowToVram(sCurrentTimeWindowId, 2); } diff --git a/src/strings.c b/src/strings.c index 36f6a49b08..0fc55321ce 100644 --- a/src/strings.c +++ b/src/strings.c @@ -1913,3 +1913,8 @@ const u8 gText_EggFromJohto[] = _("An odd POKéMON EGG found\nby the DAY CARE co const u8 gText_BadEggDesc[] = _("A peculiar POKéMON EGG."); const u8 gText_CurrentTime[] = _(" {STR_VAR_1}:{STR_VAR_2}"); const u8 gText_CurrentTimeOff[] = _(" {STR_VAR_1} {STR_VAR_2}"); +const u8 gText_CurrentTimeAM[] = _(" {STR_VAR_1}:{STR_VAR_2} a.m."); +const u8 gText_CurrentTimeAMOff[] = _(" {STR_VAR_1} {STR_VAR_2} a.m."); +const u8 gText_CurrentTimePM[] = _(" {STR_VAR_1}:{STR_VAR_2} p.m."); +const u8 gText_CurrentTimePMOff[] = _(" {STR_VAR_1} {STR_VAR_2} p.m."); +const u8 gText_ClockOption[] = _("12 HOUR CLOCK");