This commit is contained in:
FosterProgramming 2026-03-21 08:02:48 +01:00 committed by GitHub
commit e8b6abb989
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 104 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -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();