Max images(for editor, clamp for client and warning for mapconvert) (fixes #2148)

This commit is contained in:
Jupeyy 2020-09-19 20:52:28 +02:00
parent e07b430700
commit a1eb5dc114
5 changed files with 21 additions and 4 deletions

View file

@ -43,6 +43,8 @@ void CMapImages::OnMapLoadImpl(class CLayers *pLayers, IMap *pMap)
int Start;
pMap->GetType(MAPITEMTYPE_IMAGE, &Start, &m_Count);
m_Count = clamp(m_Count, 0, 64);
for(int g = 0; g < pLayers->NumGroups(); g++)
{
CMapItemGroup *pGroup = pLayers->GetGroup(g);

View file

@ -3633,6 +3633,13 @@ void CEditor::AddImage(const char *pFileName, int StorageType, void *pUser)
return;
}
if(pEditor->m_Map.m_lImages.size() >= 64) // hard limit for teeworlds
{
pEditor->m_PopupEventType = pEditor->POPEVENT_IMAGE_MAX;
pEditor->m_PopupEventActivated = true;
return;
}
CEditorImage *pImg = new CEditorImage(pEditor);
*pImg = ImgInfo;
pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo.m_Width, ImgInfo.m_Height, ImgInfo.m_Format, ImgInfo.m_pData, CImageInfo::FORMAT_AUTO, 0);

View file

@ -803,14 +803,15 @@ public:
enum
{
POPEVENT_EXIT=0,
POPEVENT_EXIT = 0,
POPEVENT_LOAD,
POPEVENT_LOADCURRENT,
POPEVENT_NEW,
POPEVENT_SAVE,
POPEVENT_LARGELAYER,
POPEVENT_PREVENTUNUSEDTILES,
POPEVENT_IMAGEDIV16
POPEVENT_IMAGEDIV16,
POPEVENT_IMAGE_MAX,
};
int m_PopupEventType;

View file

@ -1098,6 +1098,8 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View, void *pContext)
pEditor->UI()->DoLabel(&Label, "Unused tiles disabled", 20.0f, 0);
else if(pEditor->m_PopupEventType == POPEVENT_IMAGEDIV16)
pEditor->UI()->DoLabel(&Label, "Image width/height", 20.0f, 0);
else if(pEditor->m_PopupEventType == POPEVENT_IMAGE_MAX)
pEditor->UI()->DoLabel(&Label, "Max images", 20.0f, 0);
View.HSplitBottom(10.0f, &View, 0);
View.HSplitBottom(20.0f, &View, &ButtonBar);
@ -1120,7 +1122,9 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View, void *pContext)
else if(pEditor->m_PopupEventType == POPEVENT_PREVENTUNUSEDTILES)
pEditor->UI()->DoLabel(&Label, "Unused tiles can't be placed by default because they could get a use later and then destroy your map.\nActivate the 'Unused' switch to be able to place every tile.", 10.0f, -1, Label.w-10.0f);
else if(pEditor->m_PopupEventType == POPEVENT_IMAGEDIV16)
pEditor->UI()->DoLabel(&Label, "The width or height of this image is not divisible by 16. This is required for images used in tile layers for Teeworlds 0.7 compatibility.", 10.0f, -1, Label.w-10.0f);
pEditor->UI()->DoLabel(&Label, "The width or height of this image is not divisible by 16. This is required for images used in tile layers for Teeworlds 0.7 compatibility.", 10.0f, -1, Label.w - 10.0f);
else if(pEditor->m_PopupEventType == POPEVENT_IMAGE_MAX)
pEditor->UI()->DoLabel(&Label, "The client only allows a maximum of 64 images.", 10.0f, -1, Label.w - 10.0f);
// button bar
ButtonBar.VSplitLeft(30.0f, 0, &ButtonBar);
@ -1146,7 +1150,7 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View, void *pContext)
}
ButtonBar.VSplitRight(30.0f, &ButtonBar, 0);
ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label);
if(pEditor->m_PopupEventType != POPEVENT_LARGELAYER && pEditor->m_PopupEventType != POPEVENT_PREVENTUNUSEDTILES && pEditor->m_PopupEventType != POPEVENT_IMAGEDIV16)
if(pEditor->m_PopupEventType != POPEVENT_LARGELAYER && pEditor->m_PopupEventType != POPEVENT_PREVENTUNUSEDTILES && pEditor->m_PopupEventType != POPEVENT_IMAGEDIV16 && pEditor->m_PopupEventType != POPEVENT_IMAGE_MAX)
{
static int s_AbortButton = 0;
if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, 0))

View file

@ -222,6 +222,9 @@ int main(int argc, const char **argv)
bool Success = true;
if(i > 64)
dbg_msg("map_convert_07", "%s: Uses more textures than the client maximum of 64.", pSourceFileName);
// add all items
for(int Index = 0; Index < g_DataReader.NumItems(); Index++)
{