Skip to content

Commit 8525f1b

Browse files
authored
Merge pull request #50 from tangrams/gui-plugin-matchers
Filter matchers editor
2 parents 3ec5509 + 81c2926 commit 8525f1b

19 files changed

+685
-140
lines changed

Assets/Editor/FeatureStyleEditor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void OnEnable()
2020
styleEditor = new StyleEditor(featureStyle);
2121
featureStyle.Editor = styleEditor;
2222
}
23-
2423
}
2524

2625
public override void OnInspectorGUI()

Assets/Editor/FilterStyleEditor.cs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using Mapzen;
55
using Mapzen.Unity;
6+
using Mapzen.VectorData.Filters;
67
using UnityEditor;
78
using UnityEngine;
89

@@ -19,7 +20,7 @@ public class FilterStyleEditor : EditorBase
1920
"pois",
2021
"roads",
2122
"transit",
22-
"water"
23+
"water",
2324
});
2425

2526
[SerializeField]
@@ -28,9 +29,15 @@ public class FilterStyleEditor : EditorBase
2829
[SerializeField]
2930
private int selectedLayer;
3031

32+
[SerializeField]
33+
private FeatureStyle.Matcher.Type selectedMatcherType;
34+
3135
[SerializeField]
3236
private List<LayerStyleEditor> layerStyleEditors;
3337

38+
[SerializeField]
39+
private MatcherEditor matcherEditor;
40+
3441
[SerializeField]
3542
private FeatureStyle.FilterStyle filterStyle;
3643

@@ -49,6 +56,12 @@ public FilterStyleEditor(FeatureStyle.FilterStyle filterStyle)
4956
{
5057
layerStyleEditors.Add(new LayerStyleEditor(layerStyle));
5158
}
59+
60+
if (filterStyle.Matcher != null)
61+
{
62+
selectedMatcherType = filterStyle.Matcher.MatcherType;
63+
this.matcherEditor = new MatcherEditor(filterStyle.Matcher);
64+
}
5265
}
5366

5467
private void AddLayerStyleLayout(FeatureStyle.FilterStyle filterStyle, string name)
@@ -76,7 +89,7 @@ private void AddLayerStyleLayout(FeatureStyle.FilterStyle filterStyle, string na
7689
layerStyle.PolylineBuilderOptions = PolylineBuilderEditor.DefaultOptions();
7790
layerStyle.Material = new Material(Shader.Find("Diffuse"));
7891

79-
filterStyle.AddLayerStyle(layerStyle);
92+
filterStyle.LayerStyles.Add(layerStyle);
8093

8194
// Create the associated layer editor
8295
layerStyleEditors.Add(new LayerStyleEditor(layerStyle));
@@ -120,7 +133,7 @@ public void OnInspectorGUI()
120133
if (state.markedForDeletion)
121134
{
122135
// Remove the layer from the filter styles
123-
filterStyle.RemoveLayerStyle(layerStyling);
136+
filterStyle.LayerStyles.Remove(layerStyling);
124137

125138
// Remove the associated layer editor
126139
layerStyleEditors.RemoveAt(i);
@@ -129,6 +142,30 @@ public void OnInspectorGUI()
129142

130143
EditorGUI.indentLevel--;
131144

132-
// TODO: Matchers
145+
var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast<FeatureStyle.Matcher.Type>();
146+
var matcherTypeStringList = matcherTypeList.Select(type => type.ToString());
147+
var oldType = selectedMatcherType;
148+
149+
selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:",
150+
(int)selectedMatcherType, matcherTypeStringList.ToArray());
151+
152+
if (selectedMatcherType != oldType)
153+
{
154+
matcherEditor = new MatcherEditor(new FeatureStyle.Matcher(selectedMatcherType));
155+
}
156+
else
157+
{
158+
if (selectedMatcherType == FeatureStyle.Matcher.Type.None)
159+
{
160+
matcherEditor = null;
161+
}
162+
}
163+
164+
if (matcherEditor != null)
165+
{
166+
matcherEditor.OnInspectorGUI();
167+
168+
filterStyle.Matcher = matcherEditor.Matcher;
169+
}
133170
}
134171
}

Assets/Editor/MapzenMapEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private void LogWarnings()
111111

112112
foreach (var filterStyle in style.FilterStyles)
113113
{
114-
if (filterStyle.Filter.CollectionNameSet.Count == 0)
114+
if (filterStyle.GetFilter().CollectionNameSet.Count == 0)
115115
{
116116
Debug.LogWarning("The style " + style.name + " has a filter selecting no layer");
117117
}

Assets/Editor/MatcherEditor.cs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
4+
using Mapzen;
5+
using Mapzen.Unity;
6+
using Mapzen.VectorData.Filters;
7+
using UnityEditor;
8+
using UnityEngine;
9+
10+
[Serializable]
11+
public class MatcherEditor : EditorBase
12+
{
13+
[SerializeField]
14+
private FeatureStyle.Matcher.Type selectedMatcherType;
15+
16+
[SerializeField]
17+
private FeatureStyle.Matcher matcher;
18+
19+
[SerializeField]
20+
private List<MatcherEditor> matcherEditors;
21+
22+
public FeatureStyle.Matcher Matcher
23+
{
24+
get { return matcher; }
25+
}
26+
27+
public MatcherEditor(FeatureStyle.Matcher matcher)
28+
: base()
29+
{
30+
this.matcher = matcher;
31+
this.matcherEditors = new List<MatcherEditor>();
32+
33+
foreach (var matcherChild in matcher.Matchers)
34+
{
35+
this.matcherEditors.Add(new MatcherEditor(matcherChild));
36+
}
37+
}
38+
39+
private MatcherEditor AddMatcherLayout()
40+
{
41+
MatcherEditor editor = null;
42+
43+
EditorGUILayout.BeginHorizontal();
44+
{
45+
var matcherTypeList = Enum.GetValues(typeof(FeatureStyle.Matcher.Type)).Cast<FeatureStyle.Matcher.Type>();
46+
var matcherTypeStringList = matcherTypeList.Select(type => type.ToString());
47+
48+
selectedMatcherType = (FeatureStyle.Matcher.Type)EditorGUILayout.Popup("Matcher:",
49+
(int)selectedMatcherType, matcherTypeStringList.ToArray());
50+
51+
EditorConfig.SetColor(EditorConfig.AddButtonColor);
52+
if (GUILayout.Button(EditorConfig.AddButtonContent, EditorConfig.SmallButtonWidth)
53+
&& selectedMatcherType != FeatureStyle.Matcher.Type.None)
54+
{
55+
var matcherType = (FeatureStyle.Matcher.Type)selectedMatcherType;
56+
var newMatcher = new FeatureStyle.Matcher(matcherType);
57+
58+
editor = new MatcherEditor(newMatcher);
59+
matcher.Matchers.Add(newMatcher);
60+
}
61+
EditorConfig.ResetColor();
62+
}
63+
EditorGUILayout.EndHorizontal();
64+
65+
return editor;
66+
}
67+
68+
public void OnInspectorGUI()
69+
{
70+
EditorGUI.indentLevel++;
71+
72+
if (matcher.IsCompound())
73+
{
74+
var editor = AddMatcherLayout();
75+
if (editor != null)
76+
{
77+
matcherEditors.Add(editor);
78+
}
79+
}
80+
else
81+
{
82+
switch (matcher.MatcherType)
83+
{
84+
case FeatureStyle.Matcher.Type.Property:
85+
matcher.HasProperty = EditorGUILayout.TextField("Has property:", matcher.HasProperty);
86+
break;
87+
88+
case FeatureStyle.Matcher.Type.PropertyRange:
89+
matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty);
90+
EditorGUILayout.BeginHorizontal();
91+
matcher.MinRange = EditorGUILayout.FloatField("min:", matcher.MinRange);
92+
matcher.MinRangeEnabled = EditorGUILayout.Toggle(matcher.MinRangeEnabled);
93+
EditorGUILayout.EndHorizontal();
94+
EditorGUILayout.BeginHorizontal();
95+
matcher.MaxRange = EditorGUILayout.FloatField("max:", matcher.MaxRange);
96+
matcher.MaxRangeEnabled = EditorGUILayout.Toggle(matcher.MaxRangeEnabled);
97+
EditorGUILayout.EndHorizontal();
98+
break;
99+
100+
case FeatureStyle.Matcher.Type.PropertyValue:
101+
matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty);
102+
matcher.PropertyValue = EditorGUILayout.TextField("Property value:", matcher.PropertyValue);
103+
break;
104+
105+
case FeatureStyle.Matcher.Type.PropertyRegex:
106+
matcher.HasProperty = EditorGUILayout.TextField("Property:", matcher.HasProperty);
107+
matcher.RegexPattern = EditorGUILayout.TextField("Regex:", matcher.RegexPattern);
108+
break;
109+
}
110+
}
111+
112+
for (int i = matcherEditors.Count - 1; i >= 0; i--)
113+
{
114+
var editor = matcherEditors[i];
115+
116+
var state = FoldoutEditor.OnInspectorGUI(editor.GUID.ToString(), editor.Matcher.MatcherType.ToString());
117+
118+
if (state.show)
119+
{
120+
editor.OnInspectorGUI();
121+
}
122+
123+
if (state.markedForDeletion)
124+
{
125+
matcher.Matchers.Remove(editor.Matcher);
126+
matcherEditors.RemoveAt(i);
127+
}
128+
}
129+
130+
EditorGUI.indentLevel--;
131+
}
132+
}
133+
134+

Assets/Editor/MatcherEditor.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)