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

Add base classes and initial expression for new styling system #287

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Assets/Scripts/Editor/Layers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/GeoJsonLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJsonLayerGameObject))]
public class GeoJsonLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJsonLayerGameObject)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/GeoJsonLineLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJSONLineLayer))]
public class GeoJsonLineLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJSONLineLayer)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/GeoJsonPointLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJSONPointLayer))]
public class GeoJsonPointLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJSONPointLayer)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(GeoJSONPolygonLayer))]
public class GeoJsonPolygonLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (GeoJSONPolygonLayer)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(HierarchicalObjectLayerGameObject))]
public class HierarchicalObjectLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
VisualElement root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (HierarchicalObjectLayerGameObject)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 154 additions & 0 deletions Assets/Scripts/Editor/Layers/LayerDataVisualElements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using Netherlands3D.LayerStyles;
using Netherlands3D.Twin.Layers;
using UnityEngine;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
public static class LayerDataVisualElements
{
public static void LayerData(LayerData layerData, VisualElement root)
{
// Add a divider first
root.Add(Divider(2, 8));
root.Add(Heading("Layer Data"));
root.Add(Divider());

if (layerData == null)
{
root.Add(FieldContent("This layer doesn't have any data associated with it (yet)."));
return;
}

root.Add(FieldWithCaption("Name", layerData.Name));
root.Add(FieldWithCaption("Color", ColorUtility.ToHtmlStringRGBA(layerData.Color)));

root.Add(FieldCaption("Styles"));
if (layerData.Styles.Count == 0)
{
root.Add(FieldContent("This layer doesn't have any styles associated with it (yet)."));
}

bool first = true;
foreach (var (_, style) in layerData.Styles)
{
var foldout = StyleFoldout(style);
// first should be folded out, rest collapsed by default
foldout.value = first;
if (first) first = false;

root.Add(foldout);
}
}

private static Foldout StyleFoldout(LayerStyle layerStyle)
{
var foldout = new Foldout { text = layerStyle.Metadata.Name };
var group = GroupWithBorder();
group.Add(FieldWithCaption("Name", layerStyle.Metadata.Name));
group.Add(FieldCaption("Rules"));
if (layerStyle.StylingRules.Count == 0)
{
group.Add(FieldContent("This style doesn't have any styling rules associated with it (yet)."));
}
foreach (var (_, stylingRule) in layerStyle.StylingRules)
{
group.Add(StyleRuleFoldout(stylingRule));
}
foldout.Add(group);

return foldout;
}

private static Foldout StyleRuleFoldout(StylingRule stylingRule)
{
var ruleFoldout = new Foldout { text = stylingRule.Name };
ruleFoldout.Add(FieldWithCaption("Name", stylingRule.Name));
ruleFoldout.Add(FieldWithCaption("Selector", "If " + stylingRule.Selector));
var styles = stylingRule.Symbolizer.ToString();
ruleFoldout.Add(FieldWithCaption("Styles", string.IsNullOrEmpty(styles) ? "[None]" : styles ));

return ruleFoldout;
}

private static VisualElement FieldWithCaption(string caption, string content)
{
var group = new VisualElement()
{
style =
{
marginBottom = 4
}
};
group.Add(FieldCaption(caption));
group.Add(FieldContent(content));

return group;
}

private static Label FieldCaption(string caption)
{
return new Label(caption) { style = { unityFontStyleAndWeight = FontStyle.Bold}};
}

private static Label FieldContent(string content)
{
if (string.IsNullOrEmpty(content))
{
content = "[None]";
}
return new Label(content);
}

private static VisualElement GroupWithBorder()
{
return new VisualElement
{
style =
{
borderTopWidth = 1,
borderRightWidth = 1,
borderBottomWidth = 1,
borderLeftWidth = 1,
borderBottomColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
borderTopColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
borderLeftColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
borderRightColor = new Color(0.7f, 0.7f, 0.7f), // Light gray color
paddingLeft = 8,
paddingRight = 8,
paddingTop = 4,
paddingBottom = 4,
marginTop = 4,
marginBottom = 4
}
};
}

private static VisualElement Divider(int thickness = 1, int marginTop = 4, int marginBottom = 4)
{
return new VisualElement
{
style =
{
height = thickness,
marginTop = marginTop,
marginBottom = marginBottom,
backgroundColor = new Color(0.7f, 0.7f, 0.7f)
}
};
}

private static VisualElement Heading(string caption)
{
return new Label(caption)
{
style =
{
unityFontStyleAndWeight = FontStyle.Bold,
fontSize = 14,
marginBottom = 4
}
};
}
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/Editor/Layers/LayerDataVisualElements.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/Scripts/Editor/Layers/WfsGeoJsonLayerGameObjectEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Netherlands3D.Twin.Layers;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace Netherlands3D.Twin.Editor.Layers
{
[CustomEditor(typeof(WFSGeoJsonLayerGameObject))]
public class WfsGeoJsonLayerGameObjectEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();

InspectorElement.FillDefaultInspector(root, serializedObject, this);

var layerGameObject = (WFSGeoJsonLayerGameObject)target;
LayerDataVisualElements.LayerData(layerGameObject.LayerData, root);

return root;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Netherlands3D.Twin.Layers.Properties;
using Netherlands3D.Twin.Projects;
using System;
using System.Linq;
using Netherlands3D.LayerStyles;
using Netherlands3D.Twin.Projects.ExtensionMethods;

namespace Netherlands3D.Twin
Expand Down Expand Up @@ -63,21 +65,26 @@ private void CreateGeoJSONLayer(LocalFile localFile, UnityEvent<string> onErrorC
if(localFile.SourceUrl.Length > 0)
geoJsonLayerName = localFile.SourceUrl;

//Create a new geojson layer with random color (untill UI provides ways to choose colors)
GeoJsonLayerGameObject newLayer = Instantiate(layerPrefab);
newLayer.Name = geoJsonLayerName;
newLayer.gameObject.name = geoJsonLayerName;
if (onErrorCallback != null)
newLayer.OnParseError.AddListener(onErrorCallback.Invoke);

//GeoJSON layer+visual colors are set to random colors until user can pick colors in UI
var randomLayerColor = Color.HSVToRGB(UnityEngine.Random.value, UnityEngine.Random.Range(0.5f, 1f), 1);
randomLayerColor.a = 0.5f;
newLayer.LayerData.Color = randomLayerColor;

var symbolizer = newLayer.LayerData.DefaultSymbolizer;
symbolizer?.SetFillColor(randomLayerColor);
symbolizer?.SetStrokeColor(randomLayerColor);

var localPath = localFile.LocalFilePath;
var fileName = Path.GetFileName(localPath);
var propertyData = newLayer.PropertyData as LayerURLPropertyData;

if (localFile.SourceUrl.StartsWith("http"))
propertyData.Data = AssetUriFactory.CreateRemoteAssetUri(localFile.SourceUrl);
else
propertyData.Data = AssetUriFactory.CreateProjectAssetUri(localPath);
propertyData.Data = localFile.SourceUrl.StartsWith("http")
? AssetUriFactory.CreateRemoteAssetUri(localFile.SourceUrl)
: AssetUriFactory.CreateProjectAssetUri(localPath);
}
}
}
Loading
Loading