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