From 7fb8572b3b4a0b35619036b6e77d8bd578cddda6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tobias=20Sch=C3=B6ner?= <tobias.stonehead@gmail.com>
Date: Fri, 17 Jun 2022 01:50:40 +0200
Subject: [PATCH] Made fact display scrollable

Fact display now also does not cover up the scroll area anymore (mask)
Dragged facts get moved to bottom of canvas hierachy while being dragged, so they are visible above all other ui
---
 Assets/Resources/Prefabs/Stage_Default.prefab | 39 +++++++-
 Assets/Resources/Prefabs/UI/FrameITUI.prefab  | 99 ++++++++++++++++++-
 Assets/Scripts/InventoryStuff/DisplayFacts.cs | 21 +++-
 Assets/Scripts/InventoryStuff/DragHandling.cs | 18 ++--
 Assets/Scripts/InventoryStuff/DropHandling.cs |  4 +
 5 files changed, 162 insertions(+), 19 deletions(-)

diff --git a/Assets/Resources/Prefabs/Stage_Default.prefab b/Assets/Resources/Prefabs/Stage_Default.prefab
index ae345171..82ae4a15 100644
--- a/Assets/Resources/Prefabs/Stage_Default.prefab
+++ b/Assets/Resources/Prefabs/Stage_Default.prefab
@@ -324,6 +324,16 @@ PrefabInstance:
       propertyPath: FieldActions.Array.data[1].m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName
       value: UnityEngine.Object, UnityEngine
       objectReference: {fileID: 0}
+    - target: {fileID: 1063267680909148023, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_SizeDelta.y
+      value: 630
+      objectReference: {fileID: 0}
+    - target: {fileID: 1063267680909148023, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_AnchoredPosition.y
+      value: 315
+      objectReference: {fileID: 0}
     - target: {fileID: 1063267681001813619, guid: b996060e27da25c498842defc1996d84,
         type: 3}
       propertyPath: m_AnchorMax.y
@@ -342,18 +352,23 @@ PrefabInstance:
     - target: {fileID: 1063267681950920702, guid: b996060e27da25c498842defc1996d84,
         type: 3}
       propertyPath: m_AnchorMax.x
-      value: 0
+      value: 1
       objectReference: {fileID: 0}
     - target: {fileID: 1063267681950920702, guid: b996060e27da25c498842defc1996d84,
         type: 3}
       propertyPath: m_AnchorMax.y
-      value: 0
+      value: 1
       objectReference: {fileID: 0}
     - target: {fileID: 1063267681950920702, guid: b996060e27da25c498842defc1996d84,
         type: 3}
       propertyPath: m_AnchorMin.x
       value: 0
       objectReference: {fileID: 0}
+    - target: {fileID: 1063267681976544645, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_IsActive
+      value: 0
+      objectReference: {fileID: 0}
     - target: {fileID: 1063267681976544647, guid: b996060e27da25c498842defc1996d84,
         type: 3}
       propertyPath: m_Size
@@ -559,6 +574,26 @@ PrefabInstance:
       propertyPath: m_AnchoredPosition.y
       value: 0
       objectReference: {fileID: 0}
+    - target: {fileID: 2283035808027014546, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_Enabled
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 2283035808027014546, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_VerticalFit
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 2283035808027014546, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_HorizontalFit
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 5427039714963774146, guid: b996060e27da25c498842defc1996d84,
+        type: 3}
+      propertyPath: m_AnchoredPosition.x
+      value: 0
+      objectReference: {fileID: 0}
     m_RemovedComponents: []
   m_SourcePrefab: {fileID: 100100000, guid: b996060e27da25c498842defc1996d84, type: 3}
 --- !u!224 &3020720018354060037 stripped
diff --git a/Assets/Resources/Prefabs/UI/FrameITUI.prefab b/Assets/Resources/Prefabs/UI/FrameITUI.prefab
index 5c1c58af..1096aa5b 100644
--- a/Assets/Resources/Prefabs/UI/FrameITUI.prefab
+++ b/Assets/Resources/Prefabs/UI/FrameITUI.prefab
@@ -448,6 +448,8 @@ GameObject:
   - component: {fileID: 1063267681290197932}
   - component: {fileID: 1063267681290197933}
   - component: {fileID: 1063267681290197930}
+  - component: {fileID: 8812037993037732299}
+  - component: {fileID: 504851055797469322}
   m_Layer: 5
   m_Name: Factscreen
   m_TagString: Untagged
@@ -465,7 +467,8 @@ RectTransform:
   m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
   m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
-  m_Children: []
+  m_Children:
+  - {fileID: 5427039714963774146}
   m_Father: {fileID: 1063267681848407549}
   m_RootOrder: 6
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -524,6 +527,7 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: d982f30612e9c5c4eb26c1ad0bb859e1, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
+  factscreenContent: {fileID: 5427039714963774146}
   prefab_Point: {fileID: 858001163752551619, guid: f019e9f67e8dab947bc60028223b6cec,
     type: 3}
   prefab_Distance: {fileID: 4221381813544557775, guid: 8106c748f1aeb084d87fdc71dd009b67,
@@ -538,11 +542,65 @@ MonoBehaviour:
     type: 3}
   prefab_ParallelLineFact: {fileID: 7510387096843212865, guid: 9f086cfbfeb0dfd46af67395aa17aafa,
     type: 3}
+  prefab_RectangleFact: {fileID: 0}
+  prefab_RadiusFact: {fileID: 0}
+  prefab_AreaCircle: {fileID: 0}
+  prefab_ConeVolume: {fileID: 0}
+  prefab_OrthogonalCircleLine: {fileID: 0}
+  prefab_TruncatedConeVolume: {fileID: 0}
+  prefab_RightAngle: {fileID: 0}
+  prefab_CylinderVolume: {fileID: 0}
+  prefab_CircleFact: {fileID: 0}
+  prefab_OnCircleFact: {fileID: 0}
+  prefab_AngleCircleLineFact: {fileID: 0}
   x_Start: -125
-  y_Start: 475
+  y_Start: -55
   X_Pacece_Between_Items: 110
   y_Pacece_Between_Items: 110
   number_of_Column: 3
+--- !u!114 &8812037993037732299
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1063267681290197928}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 1aa08ab6e0800fa44ae55d278d1423e3, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Content: {fileID: 5427039714963774146}
+  m_Horizontal: 1
+  m_Vertical: 1
+  m_MovementType: 2
+  m_Elasticity: 0.1
+  m_Inertia: 1
+  m_DecelerationRate: 0.135
+  m_ScrollSensitivity: 10
+  m_Viewport: {fileID: 1063267681290197931}
+  m_HorizontalScrollbar: {fileID: 0}
+  m_VerticalScrollbar: {fileID: 0}
+  m_HorizontalScrollbarVisibility: 0
+  m_VerticalScrollbarVisibility: 0
+  m_HorizontalScrollbarSpacing: 0
+  m_VerticalScrollbarSpacing: 0
+  m_OnValueChanged:
+    m_PersistentCalls:
+      m_Calls: []
+--- !u!114 &504851055797469322
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1063267681290197928}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 31a19414c41e5ae4aae2af33fee712f6, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_ShowMaskGraphic: 1
 --- !u!1 &1063267681476893320
 GameObject:
   m_ObjectHideFlags: 0
@@ -1778,7 +1836,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 1}
   m_AnchorMax: {x: 0.5, y: 1}
-  m_AnchoredPosition: {x: 3633.298, y: 0.000030517578}
+  m_AnchoredPosition: {x: 6860.9316, y: 0.000030517578}
   m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 0.5, y: 1}
 --- !u!114 &1063267682090589447
@@ -3162,6 +3220,41 @@ MonoBehaviour:
   m_FillOrigin: 0
   m_UseSpriteMesh: 0
   m_PixelsPerUnitMultiplier: 1
+--- !u!1 &5894918260326328225
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 5427039714963774146}
+  m_Layer: 5
+  m_Name: Facts
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &5427039714963774146
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5894918260326328225}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 1063267681290197931}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0, y: 1}
+  m_AnchorMax: {x: 1, y: 1}
+  m_AnchoredPosition: {x: 7200, y: 0}
+  m_SizeDelta: {x: 0, y: 100}
+  m_Pivot: {x: 0.5, y: 1}
 --- !u!1001 &1695473884174914986
 PrefabInstance:
   m_ObjectHideFlags: 0
diff --git a/Assets/Scripts/InventoryStuff/DisplayFacts.cs b/Assets/Scripts/InventoryStuff/DisplayFacts.cs
index 12d5402e..7b2ec793 100644
--- a/Assets/Scripts/InventoryStuff/DisplayFacts.cs
+++ b/Assets/Scripts/InventoryStuff/DisplayFacts.cs
@@ -10,6 +10,9 @@ public class DisplayFacts : MonoBehaviour
 
     public Dictionary<string, GameObject> displayedFacts = new Dictionary<string, GameObject>();
 
+    public Transform factscreenContent;
+
+    [Header("FactPrefabs")]
     public GameObject prefab_Point;
     public GameObject prefab_Distance;
     public GameObject prefab_Angle;
@@ -32,6 +35,7 @@ public class DisplayFacts : MonoBehaviour
     public GameObject prefab_OnCircleFact;
     public GameObject prefab_AngleCircleLineFact;
 
+    [Header("Visualisation")]
     public int x_Start;
     public int y_Start;
     public int X_Pacece_Between_Items;
@@ -67,7 +71,7 @@ void Start()
 
         var rect = GetComponent<RectTransform>();
         x_Start = (int)(rect.rect.x + X_Pacece_Between_Items * .5f);
-        y_Start = (int)(-rect.rect.y - y_Pacece_Between_Items * .5f);//);
+        y_Start = (int)(-y_Pacece_Between_Items * .5f);
         number_of_Column = Mathf.Max(1, (int)(rect.rect.width / prefab_Point.GetComponent<RectTransform>().rect.width) - 1);
 
         AddFactEvent.AddListener(AddFact);
@@ -78,8 +82,12 @@ void Start()
     public void AddFact(Fact fact) {
         var fid = fact.Id;
         var obj = CreateDisplay(transform, fact);
-        obj.GetComponent<RectTransform>().localPosition = GetPosition(displayedFacts.Count);
+        var rect = obj.GetComponent<RectTransform>();
+        rect.anchorMin = new Vector2(0.5f, 1);
+        rect.anchorMax = new Vector2(0.5f, 1);
+        rect.localPosition = GetPosition(displayedFacts.Count);
         displayedFacts.Add(fact.Id, obj);
+        AdjustFactscreenContentHeight();
     }
 
     public void RemoveFact(Fact fact)
@@ -87,6 +95,7 @@ public void RemoveFact(Fact fact)
         GameObject.Destroy(displayedFacts[fact.Id]);
         displayedFacts.Remove(fact.Id);
         UpdatePositions();
+        AdjustFactscreenContentHeight();
     }
 
     public void UpdatePositions()
@@ -103,7 +112,7 @@ public void AnimateFact(Fact fact) {
 
     private GameObject CreateDisplay(Transform transform, Fact fact)
     {
-        return fact.instantiateDisplay(prefabDictionary[fact.GetType()], transform);
+        return fact.instantiateDisplay(prefabDictionary[fact.GetType()], factscreenContent);
     }
 
     public Vector3 GetPosition(int i)
@@ -111,4 +120,10 @@ public Vector3 GetPosition(int i)
         return new Vector3(x_Start + (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
     }
 
+    private void AdjustFactscreenContentHeight()
+    {
+        var rect = factscreenContent.GetComponent<RectTransform>();
+        var height = (float)(y_Pacece_Between_Items * Math.Ceiling(((float)displayedFacts.Count / number_of_Column)));
+        rect.sizeDelta = new Vector2(rect.sizeDelta.x, height);
+    }
 }
diff --git a/Assets/Scripts/InventoryStuff/DragHandling.cs b/Assets/Scripts/InventoryStuff/DragHandling.cs
index 878cc591..90c26980 100644
--- a/Assets/Scripts/InventoryStuff/DragHandling.cs
+++ b/Assets/Scripts/InventoryStuff/DragHandling.cs
@@ -4,34 +4,30 @@
 public class DragHandling : MonoBehaviour, IDragHandler, IEndDragHandler
 {
     private Vector3 StartingPosition;
+    private Transform StartingParent;
     private bool dragged = false;
     public void OnDrag(PointerEventData eventData)
     {
         if (!dragged)
         {
             StartingPosition = transform.localPosition;
+            StartingParent = transform.parent;
             GetComponent<CanvasGroup>().blocksRaycasts = false;
             dragged = true;
         }
         transform.position = Input.mousePosition;
+
+        // display dragged object in front of all other ui
+        transform.parent = GetComponentInParent<Canvas>().transform;
+        transform.SetAsLastSibling();
     }
 
     public void OnEndDrag(PointerEventData eventData)
     {
+        transform.parent = StartingParent;
         transform.localPosition = StartingPosition;
         GetComponent<CanvasGroup>().blocksRaycasts = true;
         dragged = false;
 
-    }
-    // Start is called before the first frame update
-    void Start()
-    {
-
-    }
-
-    // Update is called once per frame
-    void Update()
-    {
-
     }
 }
diff --git a/Assets/Scripts/InventoryStuff/DropHandling.cs b/Assets/Scripts/InventoryStuff/DropHandling.cs
index edb94f9a..e912243a 100644
--- a/Assets/Scripts/InventoryStuff/DropHandling.cs
+++ b/Assets/Scripts/InventoryStuff/DropHandling.cs
@@ -24,6 +24,10 @@ public void OnDrop(PointerEventData eventData)
 
         current.transform.SetParent(gameObject.transform, false);
 
+        var rect = current.GetComponent<RectTransform>();
+        rect.anchorMin = new Vector2(0.5f, 0.5f);
+        rect.anchorMax = new Vector2(0.5f, 0.5f);
+
         currentFact = eventData.pointerDrag.GetComponent<FactWrapper>().fact;
         Debug.Log("recieved Fact: " + currentFact.Id);
 
-- 
GitLab