mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Sorting images somewhat working, save is bugged
This commit is contained in:
parent
4d35f63174
commit
b066bb07e1
|
@ -1818,35 +1818,29 @@ static int CompareImageName(const void *Object1, const void *Object2)
|
|||
return str_comp(Image1->m_aName, Image2->m_aName);
|
||||
}
|
||||
|
||||
void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
||||
void CEditor::SortImages()
|
||||
{
|
||||
array<CEditorImage*> lImages = array<CEditorImage*>(m_Map.m_lImages);
|
||||
int aIndexes[lImages.size()];
|
||||
//array<CEditorImage*> lImages = array<CEditorImage*>(m_Map.m_lImages);
|
||||
//int aIndexes[lImages.size()];
|
||||
|
||||
if( m_Map.m_lSortedImages.size() != m_Map.m_lImages.size() )
|
||||
m_Map.m_lSortedImages = array<CEditorImage*>(m_Map.m_lImages);
|
||||
|
||||
bool Sorted = true;
|
||||
for(int i = 1; i < lImages.size(); i++)
|
||||
if( str_comp(lImages[i]->m_aName, lImages[i-1]->m_aName) < 0 )
|
||||
for(int i = 1; i < m_Map.m_lSortedImages.size(); i++)
|
||||
if( str_comp(m_Map.m_lSortedImages[i]->m_aName, m_Map.m_lSortedImages[i-1]->m_aName) < 0 )
|
||||
{
|
||||
Sorted = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!Sorted)
|
||||
{
|
||||
qsort(lImages.base_ptr(), lImages.size(), sizeof(CEditorImage*), CompareImageName);
|
||||
qsort(m_Map.m_lSortedImages.base_ptr(), m_Map.m_lSortedImages.size(), sizeof(CEditorImage*), CompareImageName);
|
||||
}
|
||||
|
||||
// lImages now contains a sorted version of m_Map.m_lImages
|
||||
// Now updating aIndex such that
|
||||
// aIndex[SortedIndexOf_lImages] = UnsortedIndexOf_m_Map.m_lImages
|
||||
|
||||
for(int NewRef = 0; NewRef < lImages.size(); NewRef++)
|
||||
for(int OldRef = 0; OldRef < m_Map.m_lImages.size(); OldRef++)
|
||||
if( m_Map.m_lImages[OldRef] == lImages[NewRef] )
|
||||
{
|
||||
aIndexes[NewRef] = OldRef;
|
||||
break;
|
||||
}
|
||||
}
|
||||
void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
||||
{
|
||||
SortImages();
|
||||
|
||||
for(int e = 0; e < 2; e++) // two passes, first embedded, then external
|
||||
{
|
||||
|
@ -1857,19 +1851,19 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
|||
else
|
||||
UI()->DoLabel(&Slot, "External", 12.0f, 0);
|
||||
|
||||
for(int i = 0; i < lImages.size(); i++)
|
||||
for(int i = 0; i < m_Map.m_lSortedImages.size(); i++)
|
||||
{
|
||||
if((e && !lImages[i]->m_External) ||
|
||||
(!e && lImages[i]->m_External))
|
||||
if((e && !m_Map.m_lSortedImages[i]->m_External) ||
|
||||
(!e && m_Map.m_lSortedImages[i]->m_External))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
char aBuf[128];
|
||||
str_copy(aBuf, lImages[i]->m_aName, sizeof(aBuf));
|
||||
str_copy(aBuf, m_Map.m_lSortedImages[i]->m_aName, sizeof(aBuf));
|
||||
ToolBox.HSplitTop(12.0f, &Slot, &ToolBox);
|
||||
|
||||
if(int Result = DoButton_Editor(&m_Map.m_lImages[aIndexes[i]], aBuf, m_SelectedImage == i, &Slot,
|
||||
if(int Result = DoButton_Editor(&m_Map.m_lSortedImages[i], aBuf, m_SelectedImage == i, &Slot,
|
||||
BUTTON_CONTEXT, "Select image"))
|
||||
{
|
||||
m_SelectedImage = i;
|
||||
|
@ -1890,7 +1884,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
|
|||
r.w = r.h;
|
||||
else
|
||||
r.h = r.w;
|
||||
Graphics()->TextureSet(m_Map.m_lImages[aIndexes[i]]->m_TexId);
|
||||
Graphics()->TextureSet(m_Map.m_lSortedImages[i]->m_TexId);
|
||||
Graphics()->BlendNormal();
|
||||
Graphics()->QuadsBegin();
|
||||
IGraphics::CQuadItem QuadItem(r.x, r.y, r.w, r.h);
|
||||
|
|
|
@ -261,6 +261,7 @@ public:
|
|||
|
||||
array<CLayerGroup*> m_lGroups;
|
||||
array<CEditorImage*> m_lImages;
|
||||
array<CEditorImage*> m_lSortedImages;
|
||||
array<CEnvelope*> m_lEnvelopes;
|
||||
|
||||
class CLayerGame *m_pGameLayer;
|
||||
|
@ -597,7 +598,8 @@ public:
|
|||
|
||||
static void ReplaceImage(const char *pFilename, void *pUser);
|
||||
static void AddImage(const char *pFilename, void *pUser);
|
||||
|
||||
void SortImages();
|
||||
|
||||
void RenderImages(CUIRect Toolbox, CUIRect Toolbar, CUIRect View);
|
||||
void RenderLayers(CUIRect Toolbox, CUIRect Toolbar, CUIRect View);
|
||||
void RenderModebar(CUIRect View);
|
||||
|
|
|
@ -375,10 +375,10 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View)
|
|||
CUIRect ButtonBar, ImageView;
|
||||
View.VSplitLeft(80.0f, &ButtonBar, &View);
|
||||
View.Margin(10.0f, &ImageView);
|
||||
|
||||
|
||||
int ShowImage = g_SelectImageCurrent;
|
||||
|
||||
for(int i = -1; i < pEditor->m_Map.m_lImages.size(); i++)
|
||||
for(int i = -1; i < pEditor->m_Map.m_lSortedImages.size(); i++)
|
||||
{
|
||||
CUIRect Button;
|
||||
ButtonBar.HSplitTop(12.0f, &Button, &ButtonBar);
|
||||
|
@ -389,18 +389,18 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View)
|
|||
|
||||
if(i == -1)
|
||||
{
|
||||
if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_lImages[i], "None", i==g_SelectImageCurrent, &Button))
|
||||
if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_lSortedImages[i], "None", i==g_SelectImageCurrent, &Button))
|
||||
g_SelectImageSelected = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_lImages[i], pEditor->m_Map.m_lImages[i]->m_aName, i==g_SelectImageCurrent, &Button))
|
||||
if(pEditor->DoButton_MenuItem(&pEditor->m_Map.m_lSortedImages[i], pEditor->m_Map.m_lSortedImages[i]->m_aName, i==g_SelectImageCurrent, &Button))
|
||||
g_SelectImageSelected = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(ShowImage >= 0 && ShowImage < pEditor->m_Map.m_lImages.size())
|
||||
pEditor->Graphics()->TextureSet(pEditor->m_Map.m_lImages[ShowImage]->m_TexId);
|
||||
if(ShowImage >= 0 && ShowImage < pEditor->m_Map.m_lSortedImages.size())
|
||||
pEditor->Graphics()->TextureSet(pEditor->m_Map.m_lSortedImages[ShowImage]->m_TexId);
|
||||
else
|
||||
pEditor->Graphics()->TextureSet(-1);
|
||||
pEditor->Graphics()->QuadsBegin();
|
||||
|
@ -413,6 +413,16 @@ int CEditor::PopupSelectImage(CEditor *pEditor, CUIRect View)
|
|||
|
||||
void CEditor::PopupSelectImageInvoke(int Current, float x, float y)
|
||||
{
|
||||
SortImages();
|
||||
|
||||
// Current = index of non sorted image, we want image of sorted image
|
||||
for(int i = 0; i < m_Map.m_lSortedImages.size(); i++)
|
||||
if( m_Map.m_lImages[Current] == m_Map.m_lSortedImages[i] )
|
||||
{
|
||||
Current = i;
|
||||
break;
|
||||
}
|
||||
|
||||
static int s_SelectImagePopupId = 0;
|
||||
g_SelectImageSelected = -100;
|
||||
g_SelectImageCurrent = Current;
|
||||
|
@ -423,10 +433,16 @@ int CEditor::PopupSelectImageResult()
|
|||
{
|
||||
if(g_SelectImageSelected == -100)
|
||||
return -100;
|
||||
|
||||
g_SelectImageCurrent = g_SelectImageSelected;
|
||||
g_SelectImageSelected = -100;
|
||||
return g_SelectImageCurrent;
|
||||
|
||||
// The user selected the sorted image, but we must return the index of the non sorted image
|
||||
for(int i = 0; i < m_Map.m_lImages.size(); i++)
|
||||
if(m_Map.m_lImages[i] == m_Map.m_lSortedImages[g_SelectImageCurrent])
|
||||
return i;
|
||||
|
||||
// Shouldn't ever reach here
|
||||
return -100;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue