Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poi update working api ui merge #1024

Merged
merged 23 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a1ba840
POI section : Add Layer, Remove Selected, Enabled toggle all trigger …
greglemonmapbox Sep 19, 2018
f85286b
Added change checks to PointsOfInterestSubLayerPropertiesDrawer.
greglemonmapbox Sep 20, 2018
d5243ff
Further work on getting POI UI changes to trigger updates. Removed Ap…
greglemonmapbox Sep 20, 2018
3578a0b
Merge remote-tracking branch 'origin/api-ui-integration' into POI-upd…
greglemonmapbox Sep 21, 2018
5d63fdf
Change check for SpawnPrefabOptionsDrawer.
greglemonmapbox Sep 25, 2018
3145ef1
Removed unused change check.
greglemonmapbox Sep 25, 2018
e30c1a2
Refactored EditorHelper.CheckForModifiedProperties to allow HasChange…
greglemonmapbox Sep 25, 2018
bf66273
Refactored GeocodeAttributeSearchWindow to accept an object to update…
greglemonmapbox Sep 25, 2018
3c01e93
TEMP: Added comments to show what class is being modified on HasChang…
greglemonmapbox Sep 25, 2018
7224d2f
Merge remote-tracking branch 'origin/api-ui-integration' into POI-upd…
greglemonmapbox Sep 25, 2018
4f09adc
Removed unused variable and conditional check.
greglemonmapbox Sep 25, 2018
d9c84d4
Merge remote-tracking branch 'origin/api-ui-integration' into POI-upd…
greglemonmapbox Sep 25, 2018
23620ef
Merge remote-tracking branch 'origin/api-ui-integration' into POI-upd…
greglemonmapbox Sep 25, 2018
3d7af52
Changed change check code to call OnSunlayerPropertiesAdded and OnSub…
greglemonmapbox Sep 25, 2018
22c5cf1
Change default style for roads + layerName for custom.
abhishektrip Sep 26, 2018
929e76a
Removed true argument from CheckForModifiedProperty.
greglemonmapbox Sep 26, 2018
ba267fa
Merge remote-tracking branch 'origin/api-ui-integration' into POI-upd…
greglemonmapbox Sep 26, 2018
977606b
add default poi prefab and use it on new poi layers
brnkhy Sep 26, 2018
5b177c5
Fix bug which caused events to unbind when layer was added.
abhishektrip Sep 27, 2018
acff486
Merge branch 'POI-update-working-api-ui-merge' of github.com:mapbox/m…
abhishektrip Sep 27, 2018
6934461
Remove unused variable
abhishektrip Sep 27, 2018
ee82fd8
Removing prefab- comes in broken for older versions
abhishektrip Sep 27, 2018
d4d477b
Remove meta file
abhishektrip Sep 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdkproject/Assets/ApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public void ChangePoiCategory()
{
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
pois.categories = LocationPrefabCategories;
Debug.Log("ChangePoiCategory ---> " + pois.GetType().ToString()); //PrefabItemOptions
pois.HasChanged = true;
}

Expand All @@ -183,6 +184,7 @@ public void ChangePoiPrefab()
{
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
pois.spawnPrefabOptions.prefab = PoiPrefab;
Debug.Log("ChangePoiPrefab ---> " + pois.spawnPrefabOptions.GetType().ToString());//SpawnPrefabOptions
pois.spawnPrefabOptions.HasChanged = true;
}

Expand All @@ -192,6 +194,7 @@ public void ChangeToPoiByName()
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
pois.findByType = LocationPrefabFindBy.POIName;
pois.nameString = "yerba";
Debug.Log("ChangeToPoiByName ---> " + pois.GetType().ToString());//PrefabItemOptions
pois.HasChanged = true;
}

Expand All @@ -200,6 +203,7 @@ public void ChangeToCategory()
{
var pois = _abstractMap.VectorData.LayerProperty.FindPoiLayerWithName("loc");
pois.findByType = LocationPrefabFindBy.MapboxCategory;
Debug.Log("ChangeToCategory ---> " + pois.GetType().ToString());//PrefabItemOptions
pois.HasChanged = true;
}
}
19 changes: 13 additions & 6 deletions sdkproject/Assets/Mapbox/Unity/Editor/EditorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@
/// </summary>
public static class EditorHelper
{
public static void CheckForModifiedProperty<T>(SerializedProperty property, T targetObject)
public static void CheckForModifiedProperty<T>(SerializedProperty property, T targetObject, bool forceHasChanged = false)
{
MapboxDataProperty targetObjectAsDataProperty = targetObject as MapboxDataProperty;
if (property.serializedObject.ApplyModifiedProperties() && targetObjectAsDataProperty != null)
MapboxDataProperty targetObjectAsDataProperty = GetMapboxDataPropertyObject(targetObject);
if (targetObjectAsDataProperty != null)
{
targetObjectAsDataProperty.HasChanged = true;
targetObjectAsDataProperty.HasChanged = forceHasChanged || property.serializedObject.ApplyModifiedProperties();
//REMOVE ME....
Debug.Log("<color=cyan>CheckForModifiedProperty is TRUE!! ---> </color>" + targetObject.GetType().ToString());
}
}

public static void CheckForModifiedProperty(SerializedProperty property)
public static void CheckForModifiedProperty(SerializedProperty property, bool forceHasChanged = false)
{
CheckForModifiedProperty(property, GetTargetObjectOfProperty(property), forceHasChanged);
}

public static MapboxDataProperty GetMapboxDataPropertyObject<T>(T targetObject)
{
CheckForModifiedProperty(property, GetTargetObjectOfProperty(property));
return targetObject as MapboxDataProperty;
}

public static bool DidModifyProperty<T>(SerializedProperty property, T targetObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

if (GUI.Button(buttonRect, searchButtonContent))
{
GeocodeAttributeSearchWindow.Open(property, true);
object objectToUpdate = EditorHelper.GetTargetObjectWithProperty(property);
GeocodeAttributeSearchWindow.Open(property, objectToUpdate);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
using Mapbox.Unity;
using System.Globalization;
using Mapbox.Unity.Map;
using Mapbox.Editor;

public class GeocodeAttributeSearchWindow : EditorWindow
{
SerializedProperty _coordinateProperty;
object _objectToUpdate;

private bool _updateAbstractMap;

Expand Down Expand Up @@ -42,12 +44,19 @@ void OnDisable()

bool hasSetFocus = false;

public static void Open(SerializedProperty property, bool updateAbstractMap = false)
public static void Open(SerializedProperty property, object objectToUpdate = null)
{
GeocodeAttributeSearchWindow window = EditorWindow.GetWindow<GeocodeAttributeSearchWindow>(true, "Search for location");

window._coordinateProperty = property;
window._updateAbstractMap = updateAbstractMap;
if (objectToUpdate != null)
{
window._objectToUpdate = objectToUpdate;

//REMOVE ME!!!
string propertyType = objectToUpdate.GetType().ToString();
Debug.Log("<color=red>" + propertyType + "</color>");
}

Event e = Event.current;
Vector2 mousePos = GUIUtility.GUIToScreenPoint(e.mousePosition);
Expand Down Expand Up @@ -125,13 +134,9 @@ void OnGUI()
_coordinateProperty.serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(_coordinateProperty.serializedObject.targetObject);

if (_updateAbstractMap)
if(_objectToUpdate != null)
{
AbstractMap map = (AbstractMap)_coordinateProperty.serializedObject.targetObject;
if(map != null)
{
map.Options.locationOptions.HasChanged = true;
}
EditorHelper.CheckForModifiedProperty(_coordinateProperty, _objectToUpdate, true);
}
Close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class PointsOfInterestSubLayerTreeView : TreeView
private float kToggleWidth = 18f;
private const int uniqueId = 0;//100000;

public bool hasChanged = false;

public PointsOfInterestSubLayerTreeView(TreeViewState state)
: base(state)
{
Expand Down Expand Up @@ -67,7 +69,12 @@ protected override void RowGUI(RowGUIArgs args)
Rect toggleRect = args.rowRect;
toggleRect.width = kToggleWidth;
var item = Layers.GetArrayElementAtIndex(args.item.id - uniqueId);
EditorGUI.BeginChangeCheck();
item.FindPropertyRelative("coreOptions.isActive").boolValue = EditorGUI.Toggle(toggleRect, item.FindPropertyRelative("coreOptions.isActive").boolValue);
if(EditorGUI.EndChangeCheck())
{
hasChanged = true;
}
args.item.displayName = item.FindPropertyRelative("coreOptions.sublayerName").stringValue;
base.RowGUI(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static VectorSubLayerProperties GetSubLayerProperties(PresetFeatureType t
layerName = "road";
geometryType = VectorPrimitiveType.Line;
lineWidth = 1.0f;
style = StyleTypes.Custom;
style = StyleTypes.Dark;
break;
case PresetFeatureType.Points:
layerName = "poi_label";
Expand All @@ -69,6 +69,8 @@ public static VectorSubLayerProperties GetSubLayerProperties(PresetFeatureType t
geometryType = VectorPrimitiveType.Polygon;
break;
case PresetFeatureType.Custom:
layerName = "";
geometryType = VectorPrimitiveType.Custom;
break;
default:
break;
Expand All @@ -92,7 +94,7 @@ public static VectorSubLayerProperties GetSubLayerProperties(PresetFeatureType t
{
Width = lineWidth
};

_properties.extrusionOptions = new GeometryExtrusionOptions
{
extrusionType = extrusionType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public void DrawUI(SerializedProperty property)
layerTreeView.Reload();
layerTreeView.OnGUI(layersRect);

if (layerTreeView.hasChanged)
{
EditorHelper.CheckForModifiedProperty(property);
layerTreeView.hasChanged = false;
}

selectedLayers = layerTreeView.GetSelection();
//if there are selected elements, set the selection index at the first element.
//if not, use the Selection index to persist the selection at the right index.
Expand Down Expand Up @@ -90,6 +96,12 @@ public void DrawUI(SerializedProperty property)

selectedLayers = new int[1] { prefabItemArray.arraySize - 1 };
layerTreeView.SetSelection(selectedLayers);

if (EditorHelper.DidModifyProperty(property))
{
PrefabItemOptions prefabItemOptionToAdd= (PrefabItemOptions)EditorHelper.GetTargetObjectOfProperty(prefabItem) as PrefabItemOptions;
((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyAdded(new VectorLayerUpdateArgs { property = prefabItemOptionToAdd });
}
}

if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
Expand All @@ -99,12 +111,25 @@ public void DrawUI(SerializedProperty property)
return;
}

List<PrefabItemOptions> LayersToRemove = new List<PrefabItemOptions>();
foreach (var index in selectedLayers.OrderByDescending(i => i))
{
PrefabItemOptions prefabItemOptionsToRemove = (PrefabItemOptions)EditorHelper.GetTargetObjectOfProperty(prefabItemArray.GetArrayElementAtIndex(index)) as PrefabItemOptions;
if(prefabItemOptionsToRemove != null)
{
LayersToRemove.Add(prefabItemOptionsToRemove);
}
prefabItemArray.DeleteArrayElementAtIndex(index);
}
selectedLayers = new int[0];
layerTreeView.SetSelection(selectedLayers);
if (EditorHelper.DidModifyProperty(property))
{
for (int i = 0; i < LayersToRemove.Count; i++)
{
((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs { property = LayersToRemove[i]});
}
}
}

EditorGUILayout.EndHorizontal();
Expand All @@ -127,8 +152,7 @@ public void DrawUI(SerializedProperty property)
{
GUI.enabled = false;
}

DrawLayerLocationPrefabProperties(layerProperty);
DrawLayerLocationPrefabProperties(layerProperty, property);
if (!isLayerActive)
{
GUI.enabled = true;
Expand All @@ -141,7 +165,7 @@ public void DrawUI(SerializedProperty property)
}
}

void DrawLayerLocationPrefabProperties(SerializedProperty layerProperty)
void DrawLayerLocationPrefabProperties(SerializedProperty layerProperty, SerializedProperty property)
{
EditorGUILayout.PropertyField(layerProperty);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PrefabItemOptionsDrawer : PropertyDrawer

static float _lineHeight = EditorGUIUtility.singleLineHeight;
const string searchButtonContent = "Search";

private GUIContent prefabLocationsTitle = new GUIContent
{
text = "Prefab Locations",
Expand Down Expand Up @@ -56,7 +57,9 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
//Prefab Game Object
EditorGUI.indentLevel++;
var spawnPrefabOptions = property.FindPropertyRelative("spawnPrefabOptions");

EditorGUILayout.PropertyField(spawnPrefabOptions);

GUILayout.Space(1);
EditorGUI.indentLevel--;

Expand Down Expand Up @@ -86,7 +89,12 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

EditorGUI.indentLevel++;

EditorGUI.BeginChangeCheck();
findByProp.enumValueIndex = EditorGUILayout.Popup(findByDropDown, findByProp.enumValueIndex, findByPropContent);
if (EditorGUI.EndChangeCheck())
{
EditorHelper.CheckForModifiedProperty(property);
}

EditorGUILayout.EndHorizontal();

Expand All @@ -110,8 +118,13 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
private void ShowCategoryOptions(SerializedProperty property)
{
//Category drop down
EditorGUI.BeginChangeCheck();
var categoryProp = property.FindPropertyRelative("categories");
categoryProp.intValue = (int)(LocationPrefabCategories)(EditorGUILayout.EnumFlagsField(categoriesDropDown, (LocationPrefabCategories)categoryProp.intValue));
if (EditorGUI.EndChangeCheck())
{
EditorHelper.CheckForModifiedProperty(property);
}
ShowDensitySlider(property);
}

Expand All @@ -130,18 +143,25 @@ private void ShowAddressOrLatLonUI(SerializedProperty property)
var coordinateLabel = String.Format("Location {0}", i);

// draw coordinate string.
EditorGUI.BeginChangeCheck();
coordinate.stringValue = EditorGUILayout.TextField(coordinateLabel, coordinate.stringValue);

if(EditorGUI.EndChangeCheck())
{
EditorHelper.CheckForModifiedProperty(property, true);
}
// draw search button.
if (GUILayout.Button(new GUIContent(searchButtonContent), (GUIStyle)"minibuttonleft", GUILayout.MaxWidth(100)))
{
GeocodeAttributeSearchWindow.Open(coordinate);
object propertyObject = EditorHelper.GetTargetObjectOfProperty(property);
GeocodeAttributeSearchWindow.Open(coordinate, propertyObject);
}

//include a remove button in the row
if (GUILayout.Button(new GUIContent(" X "), (GUIStyle)"minibuttonright", GUILayout.MaxWidth(30)))
{
coordinateProperties.DeleteArrayElementAtIndex(i);
EditorHelper.CheckForModifiedProperty(property);
}
EditorGUILayout.EndHorizontal();
}
Expand All @@ -154,6 +174,7 @@ private void ShowAddressOrLatLonUI(SerializedProperty property)
coordinateProperties.arraySize++;
var newElement = coordinateProperties.GetArrayElementAtIndex(coordinateProperties.arraySize - 1);
newElement.stringValue = "";
EditorHelper.CheckForModifiedProperty(property);
}
EditorGUILayout.EndHorizontal();
}
Expand All @@ -164,7 +185,12 @@ private void ShowPOINames(SerializedProperty property)
//Name field
var categoryProp = property.FindPropertyRelative("nameString");

EditorGUI.BeginChangeCheck();
categoryProp.stringValue = EditorGUILayout.TextField(nameField, categoryProp.stringValue);
if (EditorGUI.EndChangeCheck())
{
EditorHelper.CheckForModifiedProperty(property);
}

ShowDensitySlider(property);
}
Expand All @@ -173,12 +199,13 @@ private void ShowDensitySlider(SerializedProperty property)
{
//Density slider
var densityProp = property.FindPropertyRelative("density");
if (Application.isPlaying)
{
GUI.enabled = false;
}

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(densityProp, densitySlider);
if (EditorGUI.EndChangeCheck())
{
EditorHelper.CheckForModifiedProperty(property);
}
GUI.enabled = true;
densityProp.serializedObject.ApplyModifiedProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Mapbox.Unity.Map
using UnityEngine;
using Mapbox.Unity.MeshGeneration.Modifiers;
using UnityEditor;
using Mapbox.Editor;

[CustomPropertyDrawer(typeof(SpawnPrefabOptions))]
public class SpawnPrefabOptionsDrawer : PropertyDrawer
Expand All @@ -27,9 +28,14 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
{
EditorGUI.BeginProperty(position, label, property);
position.height = 2.5f * lineHeight;
EditorGUI.BeginChangeCheck();
property.FindPropertyRelative("prefab").objectReferenceValue = EditorGUI.ObjectField(new Rect(position.x, position.y, position.width, lineHeight), prefabContent, property.FindPropertyRelative("prefab").objectReferenceValue, typeof(UnityEngine.GameObject), false);
position.y += lineHeight;
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("scaleDownWithWorld"), scalePrefabContent);
if(EditorGUI.EndChangeCheck())
{
EditorHelper.CheckForModifiedProperty(property);
}
EditorGUI.EndProperty();
}

Expand Down
9 changes: 3 additions & 6 deletions sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,9 @@ protected virtual void InitializeMap(MapOptions options)
};
_vectorData.SubLayerAdded += (object sender, EventArgs eventArgs) =>
{
VectorLayerUpdateArgs layerUpdateArgs = eventArgs as VectorLayerUpdateArgs;

if (layerUpdateArgs.visualizer != null)
{
_mapVisualizer.UpdateTileForProperty(layerUpdateArgs.factory, layerUpdateArgs);
}
_mapVisualizer.UnregisterTilesFrom(VectorData.Factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);

Debug.Log("<color=blue>Vector</color>");
OnMapRedrawn();
Expand Down
Loading