mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
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:
parent
f000fcea29
commit
077b0eeaab
|
@ -4902,6 +4902,21 @@ bool CEditor::IsEnvelopeUsed(int EnvelopeIndex) const
|
||||||
return false;
|
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)
|
void CEditor::RenderEnvelopeEditor(CUIRect View)
|
||||||
{
|
{
|
||||||
if(m_SelectedEnvelope < 0)
|
if(m_SelectedEnvelope < 0)
|
||||||
|
@ -5586,7 +5601,6 @@ int CEditor::PopupMenuFile(CEditor *pEditor, CUIRect View, void *pContext)
|
||||||
static int s_ExitButton = 0;
|
static int s_ExitButton = 0;
|
||||||
|
|
||||||
CUIRect Slot;
|
CUIRect Slot;
|
||||||
View.HSplitTop(2.0f, &Slot, &View);
|
|
||||||
View.HSplitTop(12.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)"))
|
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;
|
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)
|
void CEditor::RenderMenubar(CUIRect MenuBar)
|
||||||
{
|
{
|
||||||
CUIRect FileButton;
|
CUIRect FileButton;
|
||||||
static int s_FileButton = 0;
|
static int s_FileButton = 0;
|
||||||
MenuBar.VSplitLeft(60.0f, &FileButton, &MenuBar);
|
MenuBar.VSplitLeft(60.0f, &FileButton, &MenuBar);
|
||||||
if(DoButton_Menu(&s_FileButton, "File", 0, &FileButton, 0, nullptr))
|
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;
|
CUIRect Info, Close;
|
||||||
MenuBar.VSplitLeft(40.0f, nullptr, &MenuBar);
|
MenuBar.VSplitLeft(5.0f, nullptr, &MenuBar);
|
||||||
MenuBar.VSplitRight(20.0f, &MenuBar, &Close);
|
MenuBar.VSplitRight(20.0f, &MenuBar, &Close);
|
||||||
Close.VSplitLeft(5.0f, nullptr, &Close);
|
Close.VSplitLeft(5.0f, nullptr, &Close);
|
||||||
MenuBar.VSplitLeft(MenuBar.w * 0.75f, &MenuBar, &Info);
|
MenuBar.VSplitLeft(MenuBar.w * 0.75f, &MenuBar, &Info);
|
||||||
|
|
|
@ -1118,6 +1118,7 @@ public:
|
||||||
static int PopupSelectGametileOp(CEditor *pEditor, CUIRect View, void *pContext);
|
static int PopupSelectGametileOp(CEditor *pEditor, CUIRect View, void *pContext);
|
||||||
static int PopupImage(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 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 PopupSelectConfigAutoMap(CEditor *pEditor, CUIRect View, void *pContext);
|
||||||
static int PopupSound(CEditor *pEditor, CUIRect View, void *pContext);
|
static int PopupSound(CEditor *pEditor, CUIRect View, void *pContext);
|
||||||
static int PopupSource(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);
|
static void AddSound(const char *pFileName, int StorageType, void *pUser);
|
||||||
|
|
||||||
bool IsEnvelopeUsed(int EnvelopeIndex) const;
|
bool IsEnvelopeUsed(int EnvelopeIndex) const;
|
||||||
|
void RemoveUnusedEnvelopes();
|
||||||
|
|
||||||
void RenderLayers(CUIRect LayersBox);
|
void RenderLayers(CUIRect LayersBox);
|
||||||
void RenderImagesList(CUIRect Toolbox);
|
void RenderImagesList(CUIRect Toolbox);
|
||||||
|
|
Loading…
Reference in a new issue