From 1f46626c1d98f37b1fdb65abf6f4dea271494689 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Tue, 01 Apr 2025 15:53:40 +0000
Subject: [PATCH] fixed ruletileset
---
Assets/Scripts/Inventory/InventoryDisplay.cs | 94 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 82 insertions(+), 12 deletions(-)
diff --git a/Assets/Scripts/Inventory/InventoryDisplay.cs b/Assets/Scripts/Inventory/InventoryDisplay.cs
index a5ed7cf..8036296 100644
--- a/Assets/Scripts/Inventory/InventoryDisplay.cs
+++ b/Assets/Scripts/Inventory/InventoryDisplay.cs
@@ -1,4 +1,5 @@
using Assets.Scripts.Enums;
+using Assets.Scripts.Helpers;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -16,6 +17,8 @@
public GameObject itemUIPrefab;
public GameObject itemNameDescription;
public GameObject itemDescription;
+ public GameObject itemDeleteButton;
+ public GameObject inventoryMaxAmount;
public List<GameObject> itemUIs = new List<GameObject>();
@@ -57,15 +60,20 @@
//}
if (context.started)
{
- inventoryPanel.SetActive(!inventoryPanel.activeSelf);
- if (inventoryPanel.activeSelf)
- {
- UpdateItemContentList();
- }
- else
- {
- //ClearItemContentList();
- }
+ ToggleInventoryPanel();
+ }
+ }
+
+ public void ToggleInventoryPanel()
+ {
+ inventoryPanel.SetActive(!inventoryPanel.activeSelf);
+ if (inventoryPanel.activeSelf)
+ {
+ UpdateItemContentList();
+ }
+ else
+ {
+ //ClearItemContentList();
}
}
@@ -151,19 +159,79 @@
//}
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);
+ else
+ {
+ 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()
+ {
+ InventorySlot inventorySlot = itemNameDescription.GetComponent<ItemUIScript>()?.InventorySlot;
+ if (inventorySlot?.item?.itemName != null)
+ {
+ inventory.RemoveItem(inventorySlot.item, inventorySlot.quantity);
+ itemNameDescription.SetActive(false);
+ itemDeleteButton.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()
{
+ TextMeshProHelper.UpdateItemMaxCountText(inventoryMaxAmount.GetComponent<TextMeshProUGUI>(), inventory.items.Count, inventory.maxInventorySize);
+
// First, deactivate all existing itemUIs
itemUIs.ForEach(itemUI => itemUI.SetActive(false));
@@ -194,7 +262,9 @@
// Add click event listener only if the itemUI was just created
if (isCreated)
+ {
itemUI.GetComponent<Button>().onClick.AddListener(() => OnItemClick(itemUIScript.InventorySlot));
+ }
else
{
// Update the itemUIScript of the itemNameDescription panel if the item is already selected
--
Gitblit v1.10.0