Skip to content

Commit 3d92704

Browse files
authored
Track all selected items separately for each editor map (ddnet#11483)
2 parents ee67c2f + 649177f commit 3d92704

17 files changed

+1188
-1185
lines changed

src/game/editor/editor.cpp

Lines changed: 277 additions & 660 deletions
Large diffs are not rendered by default.

src/game/editor/editor.h

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ class CEditor : public IEditor, public IEnvelopeEval
166166
const CMapView *MapView() const { return &m_MapView; }
167167
CLayerSelector *LayerSelector() { return &m_LayerSelector; }
168168

169-
void SelectNextLayer();
170-
void SelectPreviousLayer();
171-
172169
void FillGameTiles(EGameTileOp FillTile) const;
173170
bool CanFillGameTiles() const;
174171
void AddQuadOrSound();
@@ -237,14 +234,6 @@ class CEditor : public IEditor, public IEnvelopeEval
237234
m_AnimateSpeed = 1;
238235
m_AnimateUpdatePopup = false;
239236

240-
m_SelectedQuadEnvelope = -1;
241-
242-
m_vSelectedEnvelopePoints = {};
243-
m_UpdateEnvPointInfo = false;
244-
m_SelectedTangentInPoint = std::pair(-1, -1);
245-
m_SelectedTangentOutPoint = std::pair(-1, -1);
246-
m_CurrentQuadIndex = -1;
247-
248237
for(size_t i = 0; i < std::size(m_aSavedColors); ++i)
249238
{
250239
m_aSavedColors[i] = color_cast<ColorRGBA>(ColorHSLA(i / (float)std::size(m_aSavedColors), 1.0f, 0.5f));
@@ -357,41 +346,6 @@ class CEditor : public IEditor, public IEnvelopeEval
357346
void RenderGameEntities(const std::shared_ptr<CLayerTiles> &pTiles);
358347
void RenderSwitchEntities(const std::shared_ptr<CLayerTiles> &pTiles);
359348

360-
std::vector<CQuad *> GetSelectedQuads();
361-
std::shared_ptr<CLayer> GetSelectedLayerType(int Index, int Type) const;
362-
std::shared_ptr<CLayer> GetSelectedLayer(int Index) const;
363-
std::shared_ptr<CLayerGroup> GetSelectedGroup() const;
364-
CSoundSource *GetSelectedSource() const;
365-
void SelectLayer(int LayerIndex, int GroupIndex = -1);
366-
void AddSelectedLayer(int LayerIndex);
367-
void SelectQuad(int Index);
368-
void ToggleSelectQuad(int Index);
369-
void DeselectQuads();
370-
void DeselectQuadPoints();
371-
void SelectQuadPoint(int QuadIndex, int Index);
372-
void ToggleSelectQuadPoint(int QuadIndex, int Index);
373-
void DeleteSelectedQuads();
374-
bool IsQuadSelected(int Index) const;
375-
bool IsQuadCornerSelected(int Index) const;
376-
bool IsQuadPointSelected(int QuadIndex, int Index) const;
377-
int FindSelectedQuadIndex(int Index) const;
378-
379-
int FindEnvPointIndex(int Index, int Channel) const;
380-
void SelectEnvPoint(int Index);
381-
void SelectEnvPoint(int Index, int Channel);
382-
void ToggleEnvPoint(int Index, int Channel);
383-
bool IsEnvPointSelected(int Index, int Channel) const;
384-
bool IsEnvPointSelected(int Index) const;
385-
void DeselectEnvPoints();
386-
void SelectTangentOutPoint(int Index, int Channel);
387-
bool IsTangentOutPointSelected(int Index, int Channel) const;
388-
void SelectTangentInPoint(int Index, int Channel);
389-
bool IsTangentInPointSelected(int Index, int Channel) const;
390-
bool IsTangentInSelected() const;
391-
bool IsTangentOutSelected() const;
392-
bool IsTangentSelected() const;
393-
std::pair<CFixedTime, int> EnvGetSelectedTimeAndValue() const;
394-
395349
template<typename E>
396350
SEditResult<E> DoPropertiesWithState(CUIRect *pToolbox, CProperty *pProps, int *pIds, int *pNewVal, const std::vector<ColorRGBA> &vColors = {});
397351
int DoProperties(CUIRect *pToolbox, CProperty *pProps, int *pIds, int *pNewVal, const std::vector<ColorRGBA> &vColors = {});
@@ -525,19 +479,6 @@ class CEditor : public IEditor, public IEnvelopeEval
525479

526480
bool m_ShowPicker;
527481

528-
std::vector<int> m_vSelectedLayers;
529-
std::vector<int> m_vSelectedQuads;
530-
int m_SelectedGroup;
531-
int m_SelectedQuadPoints;
532-
int m_SelectedEnvelope;
533-
std::vector<std::pair<int, int>> m_vSelectedEnvelopePoints;
534-
int m_SelectedQuadEnvelope;
535-
int m_CurrentQuadIndex;
536-
int m_SelectedSource;
537-
std::pair<int, int> m_SelectedTangentInPoint;
538-
std::pair<int, int> m_SelectedTangentOutPoint;
539-
bool m_UpdateEnvPointInfo;
540-
541482
// Color palette and pipette
542483
ColorRGBA m_aSavedColors[8];
543484
ColorRGBA m_PipetteColor = ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f);
@@ -794,8 +735,6 @@ class CEditor : public IEditor, public IEnvelopeEval
794735

795736
void RenderMenubar(CUIRect Menubar);
796737

797-
void SelectGameLayer();
798-
799738
void DoAudioPreview(CUIRect View, const void *pPlayPauseButtonId, const void *pStopButtonId, const void *pSeekBarId, int SampleId);
800739

801740
// Zooming

src/game/editor/editor_actions.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ void CEditorActionAddLayer::Undo()
595595

596596
Map()->m_vpGroups[m_GroupIndex]->m_Collapse = false;
597597
if(m_LayerIndex >= (int)vLayers.size())
598-
Editor()->SelectLayer(vLayers.size() - 1, m_GroupIndex);
598+
Map()->SelectLayer(vLayers.size() - 1, m_GroupIndex);
599599

600600
Map()->OnModify();
601601
}
@@ -623,7 +623,7 @@ void CEditorActionAddLayer::Redo()
623623
vLayers.insert(vLayers.begin() + m_LayerIndex, m_pLayer);
624624

625625
Map()->m_vpGroups[m_GroupIndex]->m_Collapse = false;
626-
Editor()->SelectLayer(m_LayerIndex, m_GroupIndex);
626+
Map()->SelectLayer(m_LayerIndex, m_GroupIndex);
627627
Map()->OnModify();
628628
}
629629

@@ -657,7 +657,7 @@ void CEditorActionDeleteLayer::Redo()
657657

658658
Map()->m_vpGroups[m_GroupIndex]->m_Collapse = false;
659659
if(m_LayerIndex >= (int)vLayers.size())
660-
Editor()->SelectLayer(vLayers.size() - 1, m_GroupIndex);
660+
Map()->SelectLayer(vLayers.size() - 1, m_GroupIndex);
661661

662662
Map()->OnModify();
663663
}
@@ -685,7 +685,7 @@ void CEditorActionDeleteLayer::Undo()
685685
vLayers.insert(vLayers.begin() + m_LayerIndex, m_pLayer);
686686

687687
Map()->m_vpGroups[m_GroupIndex]->m_Collapse = false;
688-
Editor()->SelectLayer(m_LayerIndex, m_GroupIndex);
688+
Map()->SelectLayer(m_LayerIndex, m_GroupIndex);
689689
Map()->OnModify();
690690
}
691691

@@ -705,14 +705,14 @@ void CEditorActionGroup::Undo()
705705
{
706706
// Undo: add back the group
707707
Map()->m_vpGroups.insert(Map()->m_vpGroups.begin() + m_GroupIndex, m_pGroup);
708-
Editor()->m_SelectedGroup = m_GroupIndex;
708+
Map()->m_SelectedGroup = m_GroupIndex;
709709
Map()->OnModify();
710710
}
711711
else
712712
{
713713
// Undo: delete the group
714714
Map()->DeleteGroup(m_GroupIndex);
715-
Editor()->m_SelectedGroup = maximum(0, m_GroupIndex - 1);
715+
Map()->m_SelectedGroup = maximum(0, m_GroupIndex - 1);
716716
}
717717

718718
Map()->OnModify();
@@ -724,13 +724,13 @@ void CEditorActionGroup::Redo()
724724
{
725725
// Redo: add back the group
726726
Map()->m_vpGroups.insert(Map()->m_vpGroups.begin() + m_GroupIndex, m_pGroup);
727-
Editor()->m_SelectedGroup = m_GroupIndex;
727+
Map()->m_SelectedGroup = m_GroupIndex;
728728
}
729729
else
730730
{
731731
// Redo: delete the group
732732
Map()->DeleteGroup(m_GroupIndex);
733-
Editor()->m_SelectedGroup = maximum(0, m_GroupIndex - 1);
733+
Map()->m_SelectedGroup = maximum(0, m_GroupIndex - 1);
734734
}
735735

736736
Map()->OnModify();
@@ -761,7 +761,7 @@ void CEditorActionEditGroupProp::Undo()
761761

762762
if(m_Prop == EGroupProp::PROP_ORDER)
763763
{
764-
Editor()->m_SelectedGroup = Map()->MoveGroup(m_Current, m_Previous);
764+
Map()->m_SelectedGroup = Map()->MoveGroup(m_Current, m_Previous);
765765
}
766766
else
767767
Apply(m_Previous);
@@ -773,7 +773,7 @@ void CEditorActionEditGroupProp::Redo()
773773

774774
if(m_Prop == EGroupProp::PROP_ORDER)
775775
{
776-
Editor()->m_SelectedGroup = Map()->MoveGroup(m_Previous, m_Current);
776+
Map()->m_SelectedGroup = Map()->MoveGroup(m_Previous, m_Current);
777777
}
778778
else
779779
Apply(m_Current);
@@ -829,7 +829,7 @@ void CEditorActionEditLayerProp::Undo()
829829

830830
if(m_Prop == ELayerProp::PROP_ORDER)
831831
{
832-
Editor()->SelectLayer(pCurrentGroup->MoveLayer(m_Current, m_Previous));
832+
Map()->SelectLayer(pCurrentGroup->MoveLayer(m_Current, m_Previous));
833833
}
834834
else
835835
Apply(m_Previous);
@@ -841,7 +841,7 @@ void CEditorActionEditLayerProp::Redo()
841841

842842
if(m_Prop == ELayerProp::PROP_ORDER)
843843
{
844-
Editor()->SelectLayer(pCurrentGroup->MoveLayer(m_Previous, m_Current));
844+
Map()->SelectLayer(pCurrentGroup->MoveLayer(m_Previous, m_Current));
845845
}
846846
else
847847
Apply(m_Current);
@@ -858,8 +858,8 @@ void CEditorActionEditLayerProp::Apply(int Value)
858858
pPreviousGroup->m_vpLayers.insert(pPreviousGroup->m_vpLayers.begin() + m_LayerIndex, m_pLayer);
859859
else
860860
pPreviousGroup->m_vpLayers.push_back(m_pLayer);
861-
Editor()->m_SelectedGroup = Value;
862-
Editor()->SelectLayer(m_LayerIndex);
861+
Map()->m_SelectedGroup = Value;
862+
Map()->SelectLayer(m_LayerIndex);
863863
}
864864
else if(m_Prop == ELayerProp::PROP_HQ)
865865
{
@@ -1160,8 +1160,8 @@ void CEditorActionEditLayersGroupAndOrder::Undo()
11601160
pPreviousGroup->m_vpLayers.insert(pPreviousGroup->m_vpLayers.begin() + m_LayerIndices[k++], pLayer);
11611161
}
11621162

1163-
Editor()->m_vSelectedLayers = m_LayerIndices;
1164-
Editor()->m_SelectedGroup = m_GroupIndex;
1163+
Map()->m_vSelectedLayers = m_LayerIndices;
1164+
Map()->m_SelectedGroup = m_GroupIndex;
11651165
}
11661166

11671167
void CEditorActionEditLayersGroupAndOrder::Redo()
@@ -1181,8 +1181,8 @@ void CEditorActionEditLayersGroupAndOrder::Redo()
11811181
pPreviousGroup->m_vpLayers.insert(pPreviousGroup->m_vpLayers.begin() + m_NewLayerIndices[k++], pLayer);
11821182
}
11831183

1184-
Editor()->m_vSelectedLayers = m_NewLayerIndices;
1185-
Editor()->m_SelectedGroup = m_NewGroupIndex;
1184+
Map()->m_vSelectedLayers = m_NewLayerIndices;
1185+
Map()->m_SelectedGroup = m_NewGroupIndex;
11861186
}
11871187

11881188
// -----------------------------------
@@ -1459,22 +1459,22 @@ CEditorActionEnvelopeAdd::CEditorActionEnvelopeAdd(CEditorMap *pMap, CEnvelope::
14591459
m_EnvelopeType(EnvelopeType)
14601460
{
14611461
str_format(m_aDisplayText, sizeof(m_aDisplayText), "Add new %s envelope", EnvelopeType == CEnvelope::EType::COLOR ? "color" : (EnvelopeType == CEnvelope::EType::POSITION ? "position" : "sound"));
1462-
m_PreviousSelectedEnvelope = Editor()->m_SelectedEnvelope;
1462+
m_PreviousSelectedEnvelope = Map()->m_SelectedEnvelope;
14631463
}
14641464

14651465
void CEditorActionEnvelopeAdd::Undo()
14661466
{
14671467
// Undo is removing the envelope, which was added at the back of the list
14681468
Map()->m_vpEnvelopes.pop_back();
14691469
Map()->OnModify();
1470-
Editor()->m_SelectedEnvelope = m_PreviousSelectedEnvelope;
1470+
Map()->m_SelectedEnvelope = m_PreviousSelectedEnvelope;
14711471
}
14721472

14731473
void CEditorActionEnvelopeAdd::Redo()
14741474
{
14751475
// Redo is adding a new envelope at the back of the list
14761476
Map()->NewEnvelope(m_EnvelopeType);
1477-
Editor()->m_SelectedEnvelope = Map()->m_vpEnvelopes.size() - 1;
1477+
Map()->m_SelectedEnvelope = Map()->m_vpEnvelopes.size() - 1;
14781478
}
14791479

14801480
CEditorActionEnvelopeDelete::CEditorActionEnvelopeDelete(CEditorMap *pMap, int EnvelopeIndex, std::vector<std::shared_ptr<IEditorEnvelopeReference>> &vpObjectReferences, std::shared_ptr<CEnvelope> &pEnvelope) :
@@ -1521,7 +1521,7 @@ void CEditorActionEnvelopeEdit::Undo()
15211521
}
15221522
}
15231523
Map()->OnModify();
1524-
Editor()->m_SelectedEnvelope = m_EnvelopeIndex;
1524+
Map()->m_SelectedEnvelope = m_EnvelopeIndex;
15251525
}
15261526

15271527
void CEditorActionEnvelopeEdit::Redo()
@@ -1540,7 +1540,7 @@ void CEditorActionEnvelopeEdit::Redo()
15401540
}
15411541
}
15421542
Map()->OnModify();
1543-
Editor()->m_SelectedEnvelope = m_EnvelopeIndex;
1543+
Map()->m_SelectedEnvelope = m_EnvelopeIndex;
15441544
}
15451545

15461546
CEditorActionEnvelopeEditPointTime::CEditorActionEnvelopeEditPointTime(CEditorMap *pMap, int EnvelopeIndex, int PointIndex, CFixedTime Previous, CFixedTime Current) :
@@ -1661,7 +1661,7 @@ void CEditorActionEditEnvelopePointValue::Apply(bool Undo)
16611661
}
16621662

16631663
Map()->OnModify();
1664-
Editor()->m_UpdateEnvPointInfo = true;
1664+
Map()->m_UpdateEnvPointInfo = true;
16651665
}
16661666

16671667
// ---------------------
@@ -1722,12 +1722,12 @@ void CEditorActionDeleteEnvelopePoint::Redo()
17221722
std::shared_ptr<CEnvelope> pEnvelope = Map()->m_vpEnvelopes[m_EnvelopeIndex];
17231723
pEnvelope->m_vPoints.erase(pEnvelope->m_vPoints.begin() + m_PointIndex);
17241724

1725-
auto pSelectedPointIt = std::find_if(Editor()->m_vSelectedEnvelopePoints.begin(), Editor()->m_vSelectedEnvelopePoints.end(), [this](const std::pair<int, int> Pair) {
1725+
auto pSelectedPointIt = std::find_if(Map()->m_vSelectedEnvelopePoints.begin(), Map()->m_vSelectedEnvelopePoints.end(), [this](const std::pair<int, int> Pair) {
17261726
return Pair.first == m_PointIndex;
17271727
});
17281728

1729-
if(pSelectedPointIt != Editor()->m_vSelectedEnvelopePoints.end())
1730-
Editor()->m_vSelectedEnvelopePoints.erase(pSelectedPointIt);
1729+
if(pSelectedPointIt != Map()->m_vSelectedEnvelopePoints.end())
1730+
Map()->m_vSelectedEnvelopePoints.erase(pSelectedPointIt);
17311731

17321732
Map()->OnModify();
17331733
}
@@ -1782,15 +1782,15 @@ void CEditorActionDeleteSoundSource::Undo()
17821782
{
17831783
std::shared_ptr<CLayerSounds> pLayerSounds = std::static_pointer_cast<CLayerSounds>(m_pLayer);
17841784
pLayerSounds->m_vSources.insert(pLayerSounds->m_vSources.begin() + m_SourceIndex, m_Source);
1785-
Editor()->m_SelectedSource = m_SourceIndex;
1785+
Map()->m_SelectedSoundSource = m_SourceIndex;
17861786
Map()->OnModify();
17871787
}
17881788

17891789
void CEditorActionDeleteSoundSource::Redo()
17901790
{
17911791
std::shared_ptr<CLayerSounds> pLayerSounds = std::static_pointer_cast<CLayerSounds>(m_pLayer);
17921792
pLayerSounds->m_vSources.erase(pLayerSounds->m_vSources.begin() + m_SourceIndex);
1793-
Editor()->m_SelectedSource--;
1793+
Map()->m_SelectedSoundSource--;
17941794
Map()->OnModify();
17951795
}
17961796

0 commit comments

Comments
 (0)