mirror of
https://github.com/ddnet/ddnet.git
synced 2024-10-20 15:58:18 +00:00
49 lines
1,016 B
C++
49 lines
1,016 B
C++
#include "editor.h"
|
|
|
|
#include "layer_selector.h"
|
|
|
|
void CLayerSelector::Init(CEditor *pEditor)
|
|
{
|
|
CEditorComponent::Init(pEditor);
|
|
|
|
m_SelectionOffset = 0;
|
|
}
|
|
|
|
bool CLayerSelector::SelectByTile()
|
|
{
|
|
// ctrl+rightclick a map index to select the layer that has a tile there
|
|
if(UI()->HotItem() != &Editor()->m_MapEditorId)
|
|
return false;
|
|
if(!Input()->ModifierIsPressed() || !UI()->MouseButtonClicked(1))
|
|
return false;
|
|
|
|
int MatchedGroup = -1;
|
|
int MatchedLayer = -1;
|
|
int Matches = 0;
|
|
bool IsFound = false;
|
|
for(auto HoverTile : Editor()->HoverTiles())
|
|
{
|
|
if(MatchedGroup == -1)
|
|
{
|
|
MatchedGroup = HoverTile.m_Group;
|
|
MatchedLayer = HoverTile.m_Layer;
|
|
}
|
|
if(++Matches > m_SelectionOffset)
|
|
{
|
|
m_SelectionOffset++;
|
|
MatchedGroup = HoverTile.m_Group;
|
|
MatchedLayer = HoverTile.m_Layer;
|
|
IsFound = true;
|
|
break;
|
|
}
|
|
}
|
|
if(MatchedGroup != -1 && MatchedLayer != -1)
|
|
{
|
|
if(!IsFound)
|
|
m_SelectionOffset = 1;
|
|
Editor()->SelectLayer(MatchedLayer, MatchedGroup);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|