mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Merge pull request #7422 from furo321/editor-rename-asset
Add button to rename images and sounds in editor.
This commit is contained in:
commit
755f0778b9
|
@ -4309,9 +4309,9 @@ void CEditor::RenderImagesList(CUIRect ToolBox)
|
||||||
if(Result == 2)
|
if(Result == 2)
|
||||||
{
|
{
|
||||||
const std::shared_ptr<CEditorImage> pImg = m_Map.m_vpImages[m_SelectedImage];
|
const std::shared_ptr<CEditorImage> pImg = m_Map.m_vpImages[m_SelectedImage];
|
||||||
const int Height = !pImg->m_External && IsVanillaImage(pImg->m_aName) ? 90 : 73;
|
const int Height = !pImg->m_External && IsVanillaImage(pImg->m_aName) ? 107 : pImg->m_External ? 73 : 90;
|
||||||
static SPopupMenuId s_PopupImageId;
|
static SPopupMenuId s_PopupImageId;
|
||||||
UI()->DoPopupMenu(&s_PopupImageId, UI()->MouseX(), UI()->MouseY(), 120, Height, this, PopupImage);
|
UI()->DoPopupMenu(&s_PopupImageId, UI()->MouseX(), UI()->MouseY(), 140, Height, this, PopupImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4425,7 +4425,7 @@ void CEditor::RenderSounds(CUIRect ToolBox)
|
||||||
if(Result == 2)
|
if(Result == 2)
|
||||||
{
|
{
|
||||||
static SPopupMenuId s_PopupSoundId;
|
static SPopupMenuId s_PopupSoundId;
|
||||||
UI()->DoPopupMenu(&s_PopupSoundId, UI()->MouseX(), UI()->MouseY(), 120, 73, this, PopupSound);
|
UI()->DoPopupMenu(&s_PopupSoundId, UI()->MouseX(), UI()->MouseY(), 140, 90, this, PopupSound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1552,16 +1552,37 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View,
|
||||||
{
|
{
|
||||||
CEditor *pEditor = static_cast<CEditor *>(pContext);
|
CEditor *pEditor = static_cast<CEditor *>(pContext);
|
||||||
|
|
||||||
|
static int s_ExternalButton = 0;
|
||||||
static int s_ReaddButton = 0;
|
static int s_ReaddButton = 0;
|
||||||
static int s_ReplaceButton = 0;
|
static int s_ReplaceButton = 0;
|
||||||
static int s_RemoveButton = 0;
|
static int s_RemoveButton = 0;
|
||||||
static int s_ExportButton = 0;
|
static int s_ExportButton = 0;
|
||||||
|
|
||||||
|
const float RowHeight = 12.0f;
|
||||||
|
|
||||||
CUIRect Slot;
|
CUIRect Slot;
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
std::shared_ptr<CEditorImage> pImg = pEditor->m_Map.m_vpImages[pEditor->m_SelectedImage];
|
std::shared_ptr<CEditorImage> pImg = pEditor->m_Map.m_vpImages[pEditor->m_SelectedImage];
|
||||||
|
|
||||||
static int s_ExternalButton = 0;
|
if(!pImg->m_External)
|
||||||
|
{
|
||||||
|
CUIRect Label, EditBox;
|
||||||
|
|
||||||
|
static CLineInput s_RenameInput;
|
||||||
|
|
||||||
|
Slot.VMargin(5.0f, &Slot);
|
||||||
|
Slot.VSplitLeft(35.0f, &Label, &Slot);
|
||||||
|
Slot.VSplitLeft(RowHeight - 2.0f, nullptr, &EditBox);
|
||||||
|
pEditor->UI()->DoLabel(&Label, "Name:", RowHeight - 2.0f, TEXTALIGN_ML);
|
||||||
|
|
||||||
|
s_RenameInput.SetBuffer(pImg->m_aName, sizeof(pImg->m_aName));
|
||||||
|
if(pEditor->DoEditBox(&s_RenameInput, &EditBox, RowHeight - 2.0f))
|
||||||
|
pEditor->m_Map.OnModify();
|
||||||
|
|
||||||
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
|
}
|
||||||
|
|
||||||
if(pImg->m_External)
|
if(pImg->m_External)
|
||||||
{
|
{
|
||||||
if(pEditor->DoButton_MenuItem(&s_ExternalButton, "Embed", 0, &Slot, 0, "Embeds the image into the map file."))
|
if(pEditor->DoButton_MenuItem(&s_ExternalButton, "Embed", 0, &Slot, 0, "Embeds the image into the map file."))
|
||||||
|
@ -1570,7 +1591,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View,
|
||||||
return CUI::POPUP_CLOSE_CURRENT;
|
return CUI::POPUP_CLOSE_CURRENT;
|
||||||
}
|
}
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
}
|
}
|
||||||
else if(CEditor::IsVanillaImage(pImg->m_aName))
|
else if(CEditor::IsVanillaImage(pImg->m_aName))
|
||||||
{
|
{
|
||||||
|
@ -1580,7 +1601,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View,
|
||||||
return CUI::POPUP_CLOSE_CURRENT;
|
return CUI::POPUP_CLOSE_CURRENT;
|
||||||
}
|
}
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CUI::SSelectionPopupContext s_SelectionPopupContext;
|
static CUI::SSelectionPopupContext s_SelectionPopupContext;
|
||||||
|
@ -1619,7 +1640,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View,
|
||||||
}
|
}
|
||||||
|
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
if(pEditor->DoButton_MenuItem(&s_ReplaceButton, "Replace", 0, &Slot, 0, "Replaces the image with a new one"))
|
if(pEditor->DoButton_MenuItem(&s_ReplaceButton, "Replace", 0, &Slot, 0, "Replaces the image with a new one"))
|
||||||
{
|
{
|
||||||
pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_IMG, "Replace Image", "Replace", "mapres", false, ReplaceImageCallback, pEditor);
|
pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_IMG, "Replace Image", "Replace", "mapres", false, ReplaceImageCallback, pEditor);
|
||||||
|
@ -1627,7 +1648,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View,
|
||||||
}
|
}
|
||||||
|
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the image from the map"))
|
if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the image from the map"))
|
||||||
{
|
{
|
||||||
pEditor->m_Map.m_vpImages.erase(pEditor->m_Map.m_vpImages.begin() + pEditor->m_SelectedImage);
|
pEditor->m_Map.m_vpImages.erase(pEditor->m_Map.m_vpImages.begin() + pEditor->m_SelectedImage);
|
||||||
|
@ -1638,7 +1659,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View,
|
||||||
if(!pImg->m_External)
|
if(!pImg->m_External)
|
||||||
{
|
{
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
if(pEditor->DoButton_MenuItem(&s_ExportButton, "Export", 0, &Slot, 0, "Export the image"))
|
if(pEditor->DoButton_MenuItem(&s_ExportButton, "Export", 0, &Slot, 0, "Export the image"))
|
||||||
{
|
{
|
||||||
pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_IMG, "Save image", "Save", "mapres", false, CallbackSaveImage, pEditor);
|
pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_IMG, "Save image", "Save", "mapres", false, CallbackSaveImage, pEditor);
|
||||||
|
@ -1659,13 +1680,32 @@ CUI::EPopupMenuFunctionResult CEditor::PopupSound(void *pContext, CUIRect View,
|
||||||
static int s_RemoveButton = 0;
|
static int s_RemoveButton = 0;
|
||||||
static int s_ExportButton = 0;
|
static int s_ExportButton = 0;
|
||||||
|
|
||||||
|
const float RowHeight = 12.0f;
|
||||||
|
|
||||||
CUIRect Slot;
|
CUIRect Slot;
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
std::shared_ptr<CEditorSound> pSound = pEditor->m_Map.m_vpSounds[pEditor->m_SelectedSound];
|
std::shared_ptr<CEditorSound> pSound = pEditor->m_Map.m_vpSounds[pEditor->m_SelectedSound];
|
||||||
|
|
||||||
static CUI::SSelectionPopupContext s_SelectionPopupContext;
|
static CUI::SSelectionPopupContext s_SelectionPopupContext;
|
||||||
static CScrollRegion s_SelectionPopupScrollRegion;
|
static CScrollRegion s_SelectionPopupScrollRegion;
|
||||||
s_SelectionPopupContext.m_pScrollRegion = &s_SelectionPopupScrollRegion;
|
s_SelectionPopupContext.m_pScrollRegion = &s_SelectionPopupScrollRegion;
|
||||||
|
|
||||||
|
CUIRect Label, EditBox;
|
||||||
|
|
||||||
|
static CLineInput s_RenameInput;
|
||||||
|
|
||||||
|
Slot.VMargin(5.0f, &Slot);
|
||||||
|
Slot.VSplitLeft(35.0f, &Label, &Slot);
|
||||||
|
Slot.VSplitLeft(RowHeight - 2.0f, nullptr, &EditBox);
|
||||||
|
pEditor->UI()->DoLabel(&Label, "Name:", RowHeight - 2.0f, TEXTALIGN_ML);
|
||||||
|
|
||||||
|
s_RenameInput.SetBuffer(pSound->m_aName, sizeof(pSound->m_aName));
|
||||||
|
if(pEditor->DoEditBox(&s_RenameInput, &EditBox, RowHeight - 2.0f))
|
||||||
|
pEditor->m_Map.OnModify();
|
||||||
|
|
||||||
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
|
|
||||||
if(pEditor->DoButton_MenuItem(&s_ReaddButton, "Readd", 0, &Slot, 0, "Reloads the sound from the mapres folder"))
|
if(pEditor->DoButton_MenuItem(&s_ReaddButton, "Readd", 0, &Slot, 0, "Reloads the sound from the mapres folder"))
|
||||||
{
|
{
|
||||||
char aFilename[IO_MAX_PATH_LENGTH];
|
char aFilename[IO_MAX_PATH_LENGTH];
|
||||||
|
@ -1697,7 +1737,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupSound(void *pContext, CUIRect View,
|
||||||
}
|
}
|
||||||
|
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
if(pEditor->DoButton_MenuItem(&s_ReplaceButton, "Replace", 0, &Slot, 0, "Replaces the sound with a new one"))
|
if(pEditor->DoButton_MenuItem(&s_ReplaceButton, "Replace", 0, &Slot, 0, "Replaces the sound with a new one"))
|
||||||
{
|
{
|
||||||
pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_SOUND, "Replace sound", "Replace", "mapres", false, ReplaceSoundCallback, pEditor);
|
pEditor->InvokeFileDialog(IStorage::TYPE_ALL, FILETYPE_SOUND, "Replace sound", "Replace", "mapres", false, ReplaceSoundCallback, pEditor);
|
||||||
|
@ -1705,7 +1745,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupSound(void *pContext, CUIRect View,
|
||||||
}
|
}
|
||||||
|
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the sound from the map"))
|
if(pEditor->DoButton_MenuItem(&s_RemoveButton, "Remove", 0, &Slot, 0, "Removes the sound from the map"))
|
||||||
{
|
{
|
||||||
pEditor->m_Map.m_vpSounds.erase(pEditor->m_Map.m_vpSounds.begin() + pEditor->m_SelectedSound);
|
pEditor->m_Map.m_vpSounds.erase(pEditor->m_Map.m_vpSounds.begin() + pEditor->m_SelectedSound);
|
||||||
|
@ -1714,7 +1754,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupSound(void *pContext, CUIRect View,
|
||||||
}
|
}
|
||||||
|
|
||||||
View.HSplitTop(5.0f, nullptr, &View);
|
View.HSplitTop(5.0f, nullptr, &View);
|
||||||
View.HSplitTop(12.0f, &Slot, &View);
|
View.HSplitTop(RowHeight, &Slot, &View);
|
||||||
if(pEditor->DoButton_MenuItem(&s_ExportButton, "Export", 0, &Slot, 0, "Export sound"))
|
if(pEditor->DoButton_MenuItem(&s_ExportButton, "Export", 0, &Slot, 0, "Export sound"))
|
||||||
{
|
{
|
||||||
pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_SOUND, "Save sound", "Save", "mapres", false, CallbackSaveSound, pEditor);
|
pEditor->InvokeFileDialog(IStorage::TYPE_SAVE, FILETYPE_SOUND, "Save sound", "Save", "mapres", false, CallbackSaveSound, pEditor);
|
||||||
|
|
Loading…
Reference in a new issue