From 36bf22f1c4fe2b03fe82941ffd4fbfa12b8758e5 Mon Sep 17 00:00:00 2001 From: furo Date: Wed, 8 Nov 2023 15:29:14 +0100 Subject: [PATCH] Add button to rename images and sounds in editor. --- src/game/editor/editor.cpp | 6 ++-- src/game/editor/popups.cpp | 62 +++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 811b0b6b5..f1d7d329f 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -4309,9 +4309,9 @@ void CEditor::RenderImagesList(CUIRect ToolBox) if(Result == 2) { const std::shared_ptr 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; - 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) { 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); } } } diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 2a3d28440..14ce6e499 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1552,16 +1552,37 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View, { CEditor *pEditor = static_cast(pContext); + static int s_ExternalButton = 0; static int s_ReaddButton = 0; static int s_ReplaceButton = 0; static int s_RemoveButton = 0; static int s_ExportButton = 0; + const float RowHeight = 12.0f; + CUIRect Slot; - View.HSplitTop(12.0f, &Slot, &View); + View.HSplitTop(RowHeight, &Slot, &View); std::shared_ptr 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(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; } View.HSplitTop(5.0f, nullptr, &View); - View.HSplitTop(12.0f, &Slot, &View); + View.HSplitTop(RowHeight, &Slot, &View); } else if(CEditor::IsVanillaImage(pImg->m_aName)) { @@ -1580,7 +1601,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupImage(void *pContext, CUIRect View, return CUI::POPUP_CLOSE_CURRENT; } View.HSplitTop(5.0f, nullptr, &View); - View.HSplitTop(12.0f, &Slot, &View); + View.HSplitTop(RowHeight, &Slot, &View); } 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(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")) { 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(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")) { 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) { 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")) { 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_ExportButton = 0; + const float RowHeight = 12.0f; + CUIRect Slot; - View.HSplitTop(12.0f, &Slot, &View); + View.HSplitTop(RowHeight, &Slot, &View); std::shared_ptr pSound = pEditor->m_Map.m_vpSounds[pEditor->m_SelectedSound]; static CUI::SSelectionPopupContext s_SelectionPopupContext; static CScrollRegion 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")) { 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(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")) { 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(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")) { 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(12.0f, &Slot, &View); + View.HSplitTop(RowHeight, &Slot, &View); 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);