Add "Tools > Remove unused envelopes" to editor

Add a new menu "Tools" next to the "File" menu, with a button to "Remove unused envelopes".

Clicking the button opens a confirmation popup to confirm the operation.

Closes #2576.
This commit is contained in:
Robert Müller 2022-11-26 13:20:12 +01:00
parent f000fcea29
commit 077b0eeaab
2 changed files with 50 additions and 3 deletions

View file

@ -4902,6 +4902,21 @@ bool CEditor::IsEnvelopeUsed(int EnvelopeIndex) const
return false;
}
void CEditor::RemoveUnusedEnvelopes()
{
for(size_t Envelope = 0; Envelope < m_Map.m_vpEnvelopes.size();)
{
if(IsEnvelopeUsed(Envelope))
{
++Envelope;
}
else
{
m_Map.DeleteEnvelope(Envelope);
}
}
}
void CEditor::RenderEnvelopeEditor(CUIRect View)
{
if(m_SelectedEnvelope < 0)
@ -5586,7 +5601,6 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View, void *pContext)
static int s_ExitButton = 0;
CUIRect Slot;
View.HSplitTop(2.0f, &Slot, &View);
View.HSplitTop(12.0f, &Slot, &View);
if(pEditor->DoButton_MenuItem(&s_NewMapButton, "New", 0, &Slot, 0, "Creates a new map (ctrl+n)"))
{
@ -5689,16 +5703,47 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View, void *pContext)
return 0;
}
int CEditor::PopupMenuTools(CEditor *pEditor, CUIRect View, void *pContext)
{
CUIRect Slot;
View.HSplitTop(12.0f, &Slot, &View);
static int s_RemoveUnusedEnvelopesButton = 0;
static SConfirmPopupContext s_ConfirmPopupContext;
if(pEditor->DoButton_MenuItem(&s_RemoveUnusedEnvelopesButton, "Remove unused envelopes", 0, &Slot, 0, "Removes all unused envelopes from the map"))
{
s_ConfirmPopupContext.Reset();
str_copy(s_ConfirmPopupContext.m_aMessage, "Are you sure that you want to remove all unused envelopes from this map?");
pEditor->ShowPopupConfirm(Slot.x + Slot.w, Slot.y, &s_ConfirmPopupContext);
}
if(s_ConfirmPopupContext.m_Result == SConfirmPopupContext::CONFIRMED)
pEditor->RemoveUnusedEnvelopes();
if(s_ConfirmPopupContext.m_Result != SConfirmPopupContext::UNSET)
{
s_ConfirmPopupContext.Reset();
return 1;
}
return 0;
}
void CEditor::RenderMenubar(CUIRect MenuBar)
{
CUIRect FileButton;
static int s_FileButton = 0;
MenuBar.VSplitLeft(60.0f, &FileButton, &MenuBar);
if(DoButton_Menu(&s_FileButton, "File", 0, &FileButton, 0, nullptr))
UiInvokePopupMenu(&s_FileButton, 1, FileButton.x, FileButton.y + FileButton.h - 1.0f, 120, 160, PopupMenuFile, this);
UiInvokePopupMenu(&s_FileButton, 1, FileButton.x, FileButton.y + FileButton.h - 1.0f, 120.0f, 152.0f, PopupMenuFile, this);
MenuBar.VSplitLeft(5.0f, nullptr, &MenuBar);
CUIRect ToolsButton;
static int s_ToolsButton = 0;
MenuBar.VSplitLeft(60.0f, &ToolsButton, &MenuBar);
if(DoButton_Menu(&s_ToolsButton, "Tools", 0, &ToolsButton, 0, nullptr))
UiInvokePopupMenu(&s_ToolsButton, 1, ToolsButton.x, ToolsButton.y + ToolsButton.h - 1.0f, 200.0f, 22.0f, PopupMenuTools, this);
CUIRect Info, Close;
MenuBar.VSplitLeft(40.0f, nullptr, &MenuBar);
MenuBar.VSplitLeft(5.0f, nullptr, &MenuBar);
MenuBar.VSplitRight(20.0f, &MenuBar, &Close);
Close.VSplitLeft(5.0f, nullptr, &Close);
MenuBar.VSplitLeft(MenuBar.w * 0.75f, &MenuBar, &Info);

View file

@ -1118,6 +1118,7 @@ public:
static int PopupSelectGametileOp(CEditor *pEditor, CUIRect View, void *pContext);
static int PopupImage(CEditor *pEditor, CUIRect View, void *pContext);
static int PopupMenuFile(CEditor *pEditor, CUIRect View, void *pContext);
static int PopupMenuTools(CEditor *pEditor, CUIRect View, void *pContext);
static int PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View, void *pContext);
static int PopupSound(CEditor *pEditor, CUIRect View, void *pContext);
static int PopupSource(CEditor *pEditor, CUIRect View, void *pContext);
@ -1212,6 +1213,7 @@ public:
static void AddSound(const char *pFileName, int StorageType, void *pUser);
bool IsEnvelopeUsed(int EnvelopeIndex) const;
void RemoveUnusedEnvelopes();
void RenderLayers(CUIRect LayersBox);
void RenderImagesList(CUIRect Toolbox);