From b55bc192f403826120d4721630934f27e028edba Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Mon, 31 Mar 2025 18:21:39 +0000
Subject: [PATCH] #28 added inventory description UI scrollbar

---
 Assets/Scripts/Inventory/InventoryDisplay.cs |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/Assets/Scripts/Inventory/InventoryDisplay.cs b/Assets/Scripts/Inventory/InventoryDisplay.cs
index a7d3fad..dfd4f32 100644
--- a/Assets/Scripts/Inventory/InventoryDisplay.cs
+++ b/Assets/Scripts/Inventory/InventoryDisplay.cs
@@ -152,18 +152,19 @@
         //}
         if (itemNameDescription.GetComponent<ItemUIScript>()?.InventorySlot?.item?.itemName == inventorySlot.item.itemName)
         {
-            itemDescription.SetActive(!itemNameDescription.activeSelf);
+            itemDescription.transform.parent.parent.parent.gameObject.SetActive(!itemNameDescription.activeSelf);
             itemDeleteButton.SetActive(!itemNameDescription.activeSelf);
             itemNameDescription.SetActive(!itemNameDescription.activeSelf);
         }
         else
         {
-            itemDescription.SetActive(true);
+            itemDescription.transform.parent.parent.parent.gameObject.SetActive(true);
             itemDeleteButton.SetActive(true);
             itemNameDescription.SetActive(true);
         }
         itemNameDescription.GetComponent<ItemUIScript>().InventorySlot = inventorySlot;
         itemDescription.GetComponent<ItemUIScript>().InventorySlot = inventorySlot;
+        ResetScrollbarForDescription();
     }
     public void OnItemDeleteClick()
     {
@@ -173,10 +174,53 @@
             inventory.RemoveItem(inventorySlot.item, inventorySlot.quantity);
             itemNameDescription.SetActive(false);
             itemDeleteButton.SetActive(false);
-            itemDescription.SetActive(false);
+            ResetScrollbarForDescription();
+            itemDescription.transform.parent.parent.parent.gameObject.SetActive(false);
         }
     }
 
+    private void ResetScrollbarForDescription()
+    {
+        //var scrollRect = itemDescription.transform.parent.parent.GetComponent<ScrollRect>();
+        //if (scrollRect != null)
+        //{
+        //    // Reset the scroll position
+        //    scrollRect.normalizedPosition = Vector2.one; // (1,1) = top, (0,0) = bottom
+
+        //    // Force the scroll view to refresh its layout
+        //    LayoutRebuilder.ForceRebuildLayoutImmediate(scrollRect.content);
+
+        //    // Reset the content's position
+        //    var content = itemDescription.transform.Find("ItemTextDescription");
+        //    if (content != null)
+        //    {
+        //        RectTransform rectTransform = content.GetComponent<RectTransform>();
+        //        if (rectTransform != null)
+        //        {
+        //            rectTransform.anchoredPosition = Vector2.zero;
+        //        }
+        //    }
+        //}
+        // Reset the scroll position
+        var scrollrect = itemDescription.transform.parent.parent.GetComponent<ScrollRect>();
+        if (scrollrect != null)
+        {
+            Debug.Log("Resetting scroll position");
+            scrollrect.verticalNormalizedPosition = 1; // 0 = top, 1 = bottom
+        }
+        // Reset the content's position
+        // transform.Find("ItemTextDescription")
+        //var content = itemDescription.transform.Find("ItemTextDescription");
+        //if (content != null)
+        //{
+        //    RectTransform rectTransform = content.GetComponent<RectTransform>();
+        //    if (rectTransform != null)
+        //    {
+        //        rectTransform.anchoredPosition = Vector2.zero;
+        //    }
+        //}
+    }
+
     private void UpdateItemContentList()
     {
         // First, deactivate all existing itemUIs

--
Gitblit v1.9.3