mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add buttons to move envelopes left and right, use unicode icons
Closes #4129.
This commit is contained in:
parent
b997fe97bc
commit
9054eb15aa
|
@ -4850,20 +4850,43 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
pNewEnv = m_Map.NewEnvelope(3);
|
||||
}
|
||||
|
||||
// Delete button
|
||||
if(m_SelectedEnvelope >= 0)
|
||||
{
|
||||
// Delete button
|
||||
ToolBar.VSplitRight(10.0f, &ToolBar, nullptr);
|
||||
ToolBar.VSplitRight(50.0f, &ToolBar, &Button);
|
||||
static int s_DelButton = 0;
|
||||
if(DoButton_Editor(&s_DelButton, "Delete", 0, &Button, 0, "Delete this envelope"))
|
||||
ToolBar.VSplitRight(25.0f, &ToolBar, &Button);
|
||||
static int s_DeleteButton = 0;
|
||||
if(DoButton_Editor(&s_DeleteButton, "✗", 0, &Button, 0, "Delete this envelope"))
|
||||
{
|
||||
m_Map.m_Modified = true;
|
||||
m_Map.DeleteEnvelope(m_SelectedEnvelope);
|
||||
if(m_SelectedEnvelope >= (int)m_Map.m_vpEnvelopes.size())
|
||||
m_SelectedEnvelope = m_Map.m_vpEnvelopes.size() - 1;
|
||||
pEnvelope = m_SelectedEnvelope >= 0 ? m_Map.m_vpEnvelopes[m_SelectedEnvelope] : nullptr;
|
||||
}
|
||||
|
||||
// Move right button
|
||||
ToolBar.VSplitRight(5.0f, &ToolBar, nullptr);
|
||||
ToolBar.VSplitRight(25.0f, &ToolBar, &Button);
|
||||
static int s_MoveRightButton = 0;
|
||||
if(DoButton_Ex(&s_MoveRightButton, "→", 0, &Button, 0, "Move this envelope to the right", IGraphics::CORNER_R))
|
||||
{
|
||||
m_Map.SwapEnvelopes(m_SelectedEnvelope, m_SelectedEnvelope + 1);
|
||||
m_SelectedEnvelope = clamp<int>(m_SelectedEnvelope + 1, 0, m_Map.m_vpEnvelopes.size() - 1);
|
||||
pEnvelope = m_Map.m_vpEnvelopes[m_SelectedEnvelope];
|
||||
}
|
||||
|
||||
// Move left button
|
||||
ToolBar.VSplitRight(25.0f, &ToolBar, &Button);
|
||||
static int s_MoveLeftButton = 0;
|
||||
if(DoButton_Ex(&s_MoveLeftButton, "←", 0, &Button, 0, "Move this envelope to the left", IGraphics::CORNER_L))
|
||||
{
|
||||
m_Map.SwapEnvelopes(m_SelectedEnvelope - 1, m_SelectedEnvelope);
|
||||
m_SelectedEnvelope = clamp<int>(m_SelectedEnvelope - 1, 0, m_Map.m_vpEnvelopes.size() - 1);
|
||||
pEnvelope = m_Map.m_vpEnvelopes[m_SelectedEnvelope];
|
||||
}
|
||||
|
||||
// Margin on the right side
|
||||
ToolBar.VSplitRight(7.0f, &ToolBar, nullptr);
|
||||
}
|
||||
|
||||
if(pNewEnv) // add the default points
|
||||
|
@ -6148,49 +6171,69 @@ void CEditorMap::DeleteEnvelope(int Index)
|
|||
|
||||
m_Modified = true;
|
||||
|
||||
// fix links between envelopes and quads
|
||||
VisitEnvelopeReferences([Index](int &ElementIndex) {
|
||||
if(ElementIndex == Index)
|
||||
ElementIndex = -1;
|
||||
else if(ElementIndex > Index)
|
||||
ElementIndex--;
|
||||
});
|
||||
|
||||
m_vpEnvelopes.erase(m_vpEnvelopes.begin() + Index);
|
||||
}
|
||||
|
||||
void CEditorMap::SwapEnvelopes(int Index0, int Index1)
|
||||
{
|
||||
if(Index0 < 0 || Index0 >= (int)m_vpEnvelopes.size())
|
||||
return;
|
||||
if(Index1 < 0 || Index1 >= (int)m_vpEnvelopes.size())
|
||||
return;
|
||||
if(Index0 == Index1)
|
||||
return;
|
||||
|
||||
m_Modified = true;
|
||||
|
||||
VisitEnvelopeReferences([Index0, Index1](int &ElementIndex) {
|
||||
if(ElementIndex == Index0)
|
||||
ElementIndex = Index1;
|
||||
else if(ElementIndex == Index1)
|
||||
ElementIndex = Index0;
|
||||
});
|
||||
|
||||
std::swap(m_vpEnvelopes[Index0], m_vpEnvelopes[Index1]);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void CEditorMap::VisitEnvelopeReferences(F &&Visitor)
|
||||
{
|
||||
for(auto &pGroup : m_vpGroups)
|
||||
{
|
||||
for(auto &pLayer : pGroup->m_vpLayers)
|
||||
{
|
||||
if(pLayer->m_Type == LAYERTYPE_QUADS)
|
||||
{
|
||||
CLayerQuads *pLayerQuads = static_cast<CLayerQuads *>(pLayer);
|
||||
for(auto &Quad : pLayerQuads->m_vQuads)
|
||||
{
|
||||
if(Quad.m_PosEnv == Index)
|
||||
Quad.m_PosEnv = -1;
|
||||
else if(Quad.m_PosEnv > Index)
|
||||
Quad.m_PosEnv--;
|
||||
if(Quad.m_ColorEnv == Index)
|
||||
Quad.m_ColorEnv = -1;
|
||||
else if(Quad.m_ColorEnv > Index)
|
||||
Quad.m_ColorEnv--;
|
||||
Visitor(Quad.m_PosEnv);
|
||||
Visitor(Quad.m_ColorEnv);
|
||||
}
|
||||
}
|
||||
else if(pLayer->m_Type == LAYERTYPE_TILES)
|
||||
{
|
||||
CLayerTiles *pLayerTiles = static_cast<CLayerTiles *>(pLayer);
|
||||
if(pLayerTiles->m_ColorEnv == Index)
|
||||
pLayerTiles->m_ColorEnv = -1;
|
||||
if(pLayerTiles->m_ColorEnv > Index)
|
||||
pLayerTiles->m_ColorEnv--;
|
||||
Visitor(pLayerTiles->m_ColorEnv);
|
||||
}
|
||||
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
|
||||
{
|
||||
CLayerSounds *pLayerSounds = static_cast<CLayerSounds *>(pLayer);
|
||||
for(auto &Source : pLayerSounds->m_vSources)
|
||||
{
|
||||
if(Source.m_PosEnv == Index)
|
||||
Source.m_PosEnv = -1;
|
||||
else if(Source.m_PosEnv > Index)
|
||||
Source.m_PosEnv--;
|
||||
if(Source.m_SoundEnv == Index)
|
||||
Source.m_SoundEnv = -1;
|
||||
else if(Source.m_SoundEnv > Index)
|
||||
Source.m_SoundEnv--;
|
||||
Visitor(Source.m_PosEnv);
|
||||
Visitor(Source.m_SoundEnv);
|
||||
}
|
||||
}
|
||||
|
||||
m_vpEnvelopes.erase(m_vpEnvelopes.begin() + Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CEditorMap::MakeGameLayer(CLayer *pLayer)
|
||||
|
|
|
@ -413,6 +413,9 @@ public:
|
|||
}
|
||||
|
||||
void DeleteEnvelope(int Index);
|
||||
void SwapEnvelopes(int Index0, int Index1);
|
||||
template<typename F>
|
||||
void VisitEnvelopeReferences(F &&Visitor);
|
||||
|
||||
CLayerGroup *NewGroup()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue