From b606d2683795d0303e2a352eed690a2a0a3b4c1a Mon Sep 17 00:00:00 2001 From: hyperion51 Date: Tue, 14 Apr 2020 04:08:33 +0100 Subject: [PATCH] Database Tools Update Added validation for Database Links Added Database List Scroll View --- Assets/Scripts/Editor/DatabaseInspector.cs | 10 ++- Assets/Scripts/Editor/DatabaseView.cs | 93 ++++------------------ Assets/Scripts/TechTreeTestMsagl.cs | 3 +- 3 files changed, 22 insertions(+), 84 deletions(-) diff --git a/Assets/Scripts/Editor/DatabaseInspector.cs b/Assets/Scripts/Editor/DatabaseInspector.cs index e6435c66f..dd32ccf91 100644 --- a/Assets/Scripts/Editor/DatabaseInspector.cs +++ b/Assets/Scripts/Editor/DatabaseInspector.cs @@ -605,11 +605,12 @@ public class DatabaseInspector : EditorWindow { var guid = (Guid) DragAndDrop.GetGenericData("Item"); var dragEntry = DatabaseCache.Get(guid); + var dragValid = dragEntry != null && entryType.IsInstanceOfType(dragEntry) && dragEntry != entry; if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = dragEntry != null && entryType.IsInstanceOfType(dragEntry) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; else if(Event.current.type == EventType.DragPerform) { - if (guid != Guid.Empty && entryType.IsInstanceOfType(dragEntry)) + if (dragValid) { DragAndDrop.AcceptDrag(); GUI.changed = true; @@ -763,11 +764,12 @@ public class DatabaseInspector : EditorWindow { var guid = DragAndDrop.GetGenericData("Item"); var dragObj = DragAndDrop.GetGenericData("Item") is Guid ? DatabaseCache.Get((Guid) guid) : null; + var dragValid = entryType.IsInstanceOfType(dragObj) && dragObj != entry; if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = entryType.IsInstanceOfType(dragObj) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; else if(Event.current.type == EventType.DragPerform) { - if (entryType.IsInstanceOfType(dragObj)) + if (dragValid) { DragAndDrop.AcceptDrag(); value.Add((Guid) guid); diff --git a/Assets/Scripts/Editor/DatabaseView.cs b/Assets/Scripts/Editor/DatabaseView.cs index 74143bca5..abc07e201 100644 --- a/Assets/Scripts/Editor/DatabaseView.cs +++ b/Assets/Scripts/Editor/DatabaseView.cs @@ -16,6 +16,7 @@ using UnityEngine.Serialization; // TODO: USE THIS EVERYWHERE using static Unity.Mathematics.math; using Object = UnityEngine.Object; +using static UnityEditor.EditorGUILayout; public class DatabaseListView : EditorWindow { @@ -43,6 +44,7 @@ public class DatabaseListView : EditorWindow private bool[] _entryFoldouts; private string _connectionString; private const float LineHeight = 20; + private Vector2 _view; public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black; @@ -143,6 +145,16 @@ public class DatabaseListView : EditorWindow { Event currentEvent = Event.current; EventType currentEventType = currentEvent.type; + + _view = BeginScrollView( + _view, + false, + false, + GUIStyle.none, + GUI.skin.verticalScrollbar, + GUI.skin.scrollView, + GUILayout.Width(EditorGUIUtility.currentViewWidth), + GUILayout.ExpandHeight(true)); if (currentEventType == EventType.DragUpdated) // Indicate that we don't accept drags ourselves @@ -362,85 +374,8 @@ public class DatabaseListView : EditorWindow } } } - -// EditorGUILayout.BeginHorizontal(ListItemStyle); -// _commoditiesFoldout = EditorGUILayout.Foldout(_commoditiesFoldout, "Commodities", true); -// EditorGUILayout.EndHorizontal(); -// if (_commoditiesFoldout) -// { -// using (var h = new EditorGUILayout.HorizontalScope(ListItemStyle)) -// { -// GUILayout.Space(10); -// _simpleFoldout = EditorGUILayout.Foldout(_simpleFoldout, "Simple", true); -// } -// if (_simpleFoldout) -// { -// foreach (var item in Database.Items.Values.Where(e=>e.GetType()==typeof(ItemData)).Cast()) -// { -// var style = ListItemStyle; -// var selected = SelectedItem == item.ID; -// using (var h = new EditorGUILayout.HorizontalScope(selected?_selectedStyle:style)) -// { -// if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) -// select(item); -// GUILayout.Space(20); -// GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); -// } -// } -// -// using (var h = new EditorGUILayout.HorizontalScope(ListItemStyle)) -// { -// if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) -// CreateItem(typeof(ItemData)); -// GUILayout.Space(20); -// var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); -// GUI.DrawTexture(rect, GlobalData.Instance.plus, ScaleMode.StretchToFill, true, 1, Color.black, 0, 0); -// GUILayout.Label("New Simple Commodity"); -// } -// } -// -// using (var h = new EditorGUILayout.HorizontalScope(ListItemStyle)) -// { -// GUILayout.Space(10); -// _compoundFoldout = EditorGUILayout.Foldout(_compoundFoldout, "Compound", true); -// } -// if (_compoundFoldout) -// { -// foreach (var item in Database.Items.Values.Where(e=>e.GetType()==typeof(CraftedItem)).Cast()) -// { -// var style = ListItemStyle; -// var selected = SelectedItem == item.GetId(); -// using (var h = new EditorGUILayout.HorizontalScope(selected?_selectedStyle:style)) -// { -// if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) -// select(item); -// GUILayout.Space(20); -// GUILayout.Label(item.Item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); -// } -// } -// -// using (var h = new EditorGUILayout.HorizontalScope(ListItemStyle)) -// { -// if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) -// CreateItem(typeof(CraftedItem)); -// GUILayout.Space(20); -// var rect = EditorGUILayout.GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); -// GUI.DrawTexture(rect, GlobalData.Instance.plus, ScaleMode.StretchToFill, true, 1, Color.black, 0, 0); -// GUILayout.Label("New Compound Commodity"); -// } -// } -// } -// EditorGUILayout.BeginHorizontal(ListItemStyle); -// _consumablesFoldout = EditorGUILayout.Foldout(_consumablesFoldout, "Consumables", true); -// EditorGUILayout.EndHorizontal(); -// if (_consumablesFoldout) -// { -// -// } - - // HACK: This ensures none of the controls in this window can be focused (usually from clicking foldouts) - //GUI.SetNextControlName(""); - //GUI.FocusControl(""); + + EndScrollView(); } private string FormatTypeName(string typeName) diff --git a/Assets/Scripts/TechTreeTestMsagl.cs b/Assets/Scripts/TechTreeTestMsagl.cs index 46f0432bf..322f5ace7 100644 --- a/Assets/Scripts/TechTreeTestMsagl.cs +++ b/Assets/Scripts/TechTreeTestMsagl.cs @@ -20,8 +20,9 @@ public class TechTreeTestMsagl : MonoBehaviour public Prototype Tech; public Prototype RadialLink; public Prototype Arrow; - + [Section("Graph Generation")] + public bool TestMode = false; public int TechCount = 50; public int SeedTechs = 5; public int RollingWindowSize = 50;