| 1 | #include "layer_selector.h" |
|---|---|
| 2 | |
| 3 | #include "editor.h" |
| 4 | |
| 5 | #include <engine/shared/config.h> |
| 6 | |
| 7 | void CLayerSelector::OnInit(CEditor *pEditor) |
| 8 | { |
| 9 | CEditorComponent::OnInit(pEditor); |
| 10 | |
| 11 | m_SelectionOffset = 0; |
| 12 | } |
| 13 | |
| 14 | bool CLayerSelector::SelectByTile() |
| 15 | { |
| 16 | // ctrl+right click a map index to select the layer that has a tile there |
| 17 | if(Ui()->HotItem() != &Editor()->m_MapEditorId) |
| 18 | return false; |
| 19 | if(!Input()->ModifierIsPressed() || !Ui()->MouseButtonClicked(Index: 1)) |
| 20 | return false; |
| 21 | if(!g_Config.m_EdLayerSelector) |
| 22 | return false; |
| 23 | |
| 24 | int MatchedGroup = -1; |
| 25 | int MatchedLayer = -1; |
| 26 | int Matches = 0; |
| 27 | bool IsFound = false; |
| 28 | for(const auto &HoverTile : Editor()->HoverTiles()) |
| 29 | { |
| 30 | if(!Editor()->m_Map.m_vpGroups[HoverTile.m_Group]->m_Visible || |
| 31 | !Editor()->m_Map.m_vpGroups[HoverTile.m_Group]->m_vpLayers[HoverTile.m_Layer]->m_Visible) |
| 32 | continue; |
| 33 | |
| 34 | if(MatchedGroup == -1) |
| 35 | { |
| 36 | MatchedGroup = HoverTile.m_Group; |
| 37 | MatchedLayer = HoverTile.m_Layer; |
| 38 | } |
| 39 | if(++Matches > m_SelectionOffset) |
| 40 | { |
| 41 | m_SelectionOffset++; |
| 42 | MatchedGroup = HoverTile.m_Group; |
| 43 | MatchedLayer = HoverTile.m_Layer; |
| 44 | IsFound = true; |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | if(MatchedGroup != -1 && MatchedLayer != -1) |
| 49 | { |
| 50 | if(!IsFound) |
| 51 | m_SelectionOffset = 1; |
| 52 | Editor()->SelectLayer(LayerIndex: MatchedLayer, GroupIndex: MatchedGroup); |
| 53 | return true; |
| 54 | } |
| 55 | return false; |
| 56 | } |
| 57 |