diff --git a/include/constants/map_types.h b/include/constants/map_types.h index 292274c558..27b39cd401 100755 --- a/include/constants/map_types.h +++ b/include/constants/map_types.h @@ -36,4 +36,6 @@ enum MapBattleScene #define MAP_BATTLE_SCENE_LANCE MAP_BATTLE_SCENE_NORMAL #define MAP_BATTLE_SCENE_LINK MAP_BATTLE_SCENE_NORMAL +#define FLOOR_ROOFTOP 127 + #endif // GUARD_CONSTANTS_MAP_TYPES_H diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 6ed5f37fc6..b50ef157d5 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -235,7 +235,8 @@ struct MapHeader /* 0x15 */ u8 cave; /* 0x16 */ u8 weather; /* 0x17 */ u8 mapType; - /* 0x18 */ u8 filler_18[2]; + /* 0x18 */ s8 floorNumber; + /* 0x19 */ u8 filler_19; // fields correspond to the arguments in the map_header_flags macro /* 0x1A */ bool8 allowCycling:1; bool8 allowEscaping:1; // Escape Rope and Dig diff --git a/include/map_name_popup.h b/include/map_name_popup.h index 85d2f0795f..773ce73575 100644 --- a/include/map_name_popup.h +++ b/include/map_name_popup.h @@ -8,4 +8,9 @@ // Exported ROM declarations void HideMapNamePopUpWindow(void); void ShowMapNamePopup(void); +u8 *GetPopUpMapName(u8 *dest, const struct MapHeader *mapHeader); + +#define MAP_POPUP_STRING_BUFFER_LENGTH 27 +#define MAP_POPUP_PREFIX_BUFFER_LENGTH 6 + #endif //GUARD_MAP_NAME_POPUP_H diff --git a/src/map_name_popup.c b/src/map_name_popup.c index 2a3828947e..ce6aa68a79 100644 --- a/src/map_name_popup.c +++ b/src/map_name_popup.c @@ -13,11 +13,13 @@ #include "region_map.h" #include "rtc.h" #include "start_menu.h" +#include "strings.h" #include "string_util.h" #include "task.h" #include "text.h" #include "constants/battle_frontier.h" #include "constants/layouts.h" +#include "constants/map_types.h" #include "constants/region_map_sections.h" #include "constants/weather.h" #include "config/general.h" @@ -518,9 +520,60 @@ static void UpdateSecondaryPopUpWindow(u8 secondaryPopUpWindowId) CopyWindowToVram(secondaryPopUpWindowId, COPYWIN_FULL); } +static void MapNamePopupAppendFloorNum(u8 *map_name, s8 floorNum) +{ + if (floorNum == 0) + return; + u8 *dest = map_name; + while (*dest != EOS) + dest++; + *dest++ = CHAR_SPACE; + if (floorNum == FLOOR_ROOFTOP) + { + StringCopy(dest, gText_Rooftop); + return; + } + if (floorNum < 0) + { + *dest++ = CHAR_B; + floorNum *= -1; + } + dest = ConvertIntToDecimalStringN(dest, floorNum, STR_CONV_MODE_LEFT_ALIGN, 2); + *dest++ = CHAR_F; + *dest = EOS; +} + +static bool32 IsCeladonDeptStore(const struct MapHeader *mapHeader) +{ + if (mapHeader->regionMapSectionId != MAPSEC_CELADON_CITY) + return FALSE; + if (mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_1F + && mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_2F + && mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_3F + && mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_4F + && mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_5F + && mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_ROOF + && mapHeader->mapLayoutId != LAYOUT_CELADON_CITY_DEPARTMENT_STORE_ELEVATOR) + return FALSE; + return TRUE; +} + +u8 *GetPopUpMapName(u8 *dest, const struct MapHeader *mapHeader) +{ + if (IsCeladonDeptStore(mapHeader)) + StringCopy(dest, COMPOUND_STRING("CELADON DEPT.")); + else + GetMapName(dest, mapHeader->regionMapSectionId, 0); + if (mapHeader->floorNumber != 0) + { + MapNamePopupAppendFloorNum(dest, mapHeader->floorNumber); + } + return dest; +} + static void ShowMapNamePopUpWindow(void) { - u8 mapDisplayHeader[27]; + u8 mapDisplayHeader[MAP_POPUP_STRING_BUFFER_LENGTH]; u8 *withoutPrefixPtr; u8 x; const u8 *mapDisplayHeaderSource; @@ -530,20 +583,20 @@ static void ShowMapNamePopUpWindow(void) { if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_TOP) { - withoutPrefixPtr = &(mapDisplayHeader[6]); + withoutPrefixPtr = &(mapDisplayHeader[MAP_POPUP_PREFIX_BUFFER_LENGTH]); mapDisplayHeaderSource = sBattlePyramid_MapHeaderStrings[FRONTIER_STAGES_PER_CHALLENGE]; } else { - withoutPrefixPtr = &(mapDisplayHeader[6]); + withoutPrefixPtr = &(mapDisplayHeader[MAP_POPUP_PREFIX_BUFFER_LENGTH]); mapDisplayHeaderSource = sBattlePyramid_MapHeaderStrings[gSaveBlock2Ptr->frontier.curChallengeBattleNum]; } StringCopy(withoutPrefixPtr, mapDisplayHeaderSource); } else { - withoutPrefixPtr = &(mapDisplayHeader[6]); - GetMapName(withoutPrefixPtr, gMapHeader.regionMapSectionId, 0); + withoutPrefixPtr = &(mapDisplayHeader[MAP_POPUP_PREFIX_BUFFER_LENGTH]); + GetPopUpMapName(withoutPrefixPtr, &gMapHeader); } if (OW_POPUP_GENERATION == GEN_5) @@ -576,8 +629,9 @@ static void ShowMapNamePopUpWindow(void) } else { - x = GetStringCenterAlignXOffset(FONT_NARROW, withoutPrefixPtr, 80); - AddTextPrinterParameterized(GetMapNamePopUpWindowId(), FONT_NARROW, mapDisplayHeader, x, 3, TEXT_SKIP_DRAW, NULL); + u32 fontId = GetFontIdToFit(withoutPrefixPtr, FONT_NORMAL, -1, 80); + x = GetStringCenterAlignXOffset(fontId, withoutPrefixPtr, 80); + AddTextPrinterParameterized(GetMapNamePopUpWindowId(), fontId, mapDisplayHeader, x, 3, TEXT_SKIP_DRAW, NULL); CopyWindowToVram(GetMapNamePopUpWindowId(), COPYWIN_FULL); } } diff --git a/test/text.c b/test/text.c index 3695d54d02..a0429a764e 100644 --- a/test/text.c +++ b/test/text.c @@ -5,9 +5,11 @@ #include "battle_message.h" #include "battle_setup.h" #include "item.h" -#include "malloc.h" -#include "party_menu.h" #include "main_menu.h" +#include "malloc.h" +#include "map_name_popup.h" +#include "overworld.h" +#include "party_menu.h" #include "string_util.h" #include "text.h" #include "constants/abilities.h" @@ -15,6 +17,7 @@ #include "constants/battle_string_ids.h" #include "constants/items.h" #include "constants/moves.h" +#include "../src/data/map_group_count.h" #include "test/overworld_script.h" TEST("Move names fit on Pokemon Summary Screen") @@ -557,6 +560,28 @@ TEST("Type names fit on Pokedex Search Screen") EXPECT_LE(GetStringWidth(fontId, gTypesInfo[type].name, 0), widthPx); } + +TEST("Map names fit in popup") +{ + ASSUME(OW_POPUP_GENERATION == GEN_3); + u32 i, j; + const u32 fontId = FONT_NARROWER; + u32 widthPx = 80; + s8 mapGroup = 0; + s8 mapNum = 0; + u8 mapName[MAP_POPUP_STRING_BUFFER_LENGTH - MAP_POPUP_PREFIX_BUFFER_LENGTH]; + for (i = 0; MAP_GROUP_COUNT[i] != 0; i++) + { + for (j = 0; j < MAP_GROUP_COUNT[i]; j++) + { + const struct MapHeader *mapHeader = Overworld_GetMapHeaderByGroupAndId(i, j); + if (mapHeader->showMapName) + PARAMETRIZE_LABEL("%S", GetPopUpMapName(mapName, mapHeader)) { mapGroup = i; mapNum = j;} + } + } + EXPECT_LE(GetStringWidth(fontId, GetPopUpMapName(mapName, Overworld_GetMapHeaderByGroupAndId(mapGroup, mapNum)), 0), widthPx); +} + extern u16 sBattlerAbilities[MAX_BATTLERS_COUNT]; //* #define BATTLE_STRING_BUFFER_SIZE 1000 diff --git a/tools/mapjson/mapjson.cpp b/tools/mapjson/mapjson.cpp index 57e7c1337d..b767cc8b9c 100644 --- a/tools/mapjson/mapjson.cpp +++ b/tools/mapjson/mapjson.cpp @@ -169,8 +169,13 @@ string generate_map_header_text(Json map_data, Json layouts_data) { << "\t.byte " << json_to_string(map_data, "weather") << "\n" << "\t.byte " << json_to_string(map_data, "map_type") << "\n"; - if (version != "firered") - text << "\t.2byte 0\n"; + string floor_number = json_to_string(map_data, "floor_number", true); + if (floor_number.empty()) + text << "\t.byte 0\n"; + else + text << "\t.byte " << floor_number << "\n"; + + text << "\t.byte 0\n"; if (version == "ruby") text << "\t.byte " << json_to_string(map_data, "show_map_name") << "\n"; @@ -181,9 +186,6 @@ string generate_map_header_text(Json map_data, Json layouts_data) { << "allow_running=" << json_to_string(map_data, "allow_running") << ", " << "show_map_name=" << json_to_string(map_data, "show_map_name") << "\n"; - if (version == "firered") - text << "\t.byte " << json_to_string(map_data, "floor_number") << "\n"; - text << "\t.byte " << json_to_string(map_data, "battle_scene") << "\n\n"; return text.str();