double inventory screen
This commit is contained in:
@@ -14,13 +14,13 @@ public class InfoBox : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
|
||||
private UIDocument uiDocument;
|
||||
private Camera mainCamera;
|
||||
private IInventoryHolder inventoryHolder;
|
||||
private InventoryHolder inventoryHolder;
|
||||
private Label infoBox;
|
||||
|
||||
void Start()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
inventoryHolder = GetComponent<IInventoryHolder>();
|
||||
inventoryHolder = GetComponent<InventoryHolder>();
|
||||
|
||||
uiDocument = gameObject.AddComponent<UIDocument>();
|
||||
uiDocument.panelSettings = uiPanelSettings;
|
||||
|
||||
@@ -1,39 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class InventoryScreen : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private VisualTreeAsset uiInventoryAsset;
|
||||
|
||||
[SerializeField]
|
||||
private VisualTreeAsset uiItemAsset;
|
||||
|
||||
private UIDocument uiDocument;
|
||||
|
||||
private VisualElement root;
|
||||
private VisualElement itemList;
|
||||
private Label headerLabel;
|
||||
private Label footerLabel;
|
||||
private VisualElement sourceInventory;
|
||||
private VisualElement targetInventory;
|
||||
|
||||
private IInventoryHolder inventoryHolder;
|
||||
private IInventoryHolder targetInventoryHolder;
|
||||
// private InventoryHolder inventoryHolder;
|
||||
// private InventoryHolder targetInventoryHolder;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
uiDocument = GetComponent<UIDocument>();
|
||||
|
||||
root = uiDocument.rootVisualElement;
|
||||
var inventory = root.Q("Inventory");
|
||||
sourceInventory = root.Q("SourceInventory");
|
||||
sourceInventory.style.display = DisplayStyle.None;
|
||||
targetInventory = root.Q("TargetInventory");
|
||||
targetInventory.style.display = DisplayStyle.None;
|
||||
|
||||
root.style.display = DisplayStyle.None;
|
||||
|
||||
itemList = inventory.Q("Inventory").Q("ContainerScroll");
|
||||
headerLabel = inventory.Q<Label>("Header");
|
||||
footerLabel = inventory.Q<Label>("Footer");
|
||||
Hide();
|
||||
|
||||
root.RegisterCallback<ClickEvent>(OnRootClicked);
|
||||
inventory.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
||||
sourceInventory.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
||||
targetInventory.RegisterCallback<ClickEvent>(evt => evt.StopPropagation());
|
||||
}
|
||||
|
||||
private void OnRootClicked(ClickEvent evt)
|
||||
@@ -52,14 +55,37 @@ public class InventoryScreen : MonoBehaviour
|
||||
root.style.display = DisplayStyle.None;
|
||||
}
|
||||
|
||||
public void Display(IInventoryHolder inventory, IInventoryHolder targetInventory = null)
|
||||
public void Display(InventoryHolder sourceInventory, InventoryHolder targetInventory = null)
|
||||
{
|
||||
this.inventoryHolder = inventory;
|
||||
this.targetInventoryHolder = inventory;
|
||||
ShowInventory(this.sourceInventory, sourceInventory);
|
||||
ShowInventory(this.targetInventory, targetInventory);
|
||||
|
||||
Show();
|
||||
}
|
||||
|
||||
public void ShowInventory(VisualElement inventory, InventoryHolder holder)
|
||||
{
|
||||
inventory.Clear();
|
||||
|
||||
if (holder == null)
|
||||
{
|
||||
inventory.style.display = DisplayStyle.None;
|
||||
return;
|
||||
}
|
||||
inventory.style.display = DisplayStyle.Flex;
|
||||
|
||||
uiInventoryAsset.CloneTree(inventory);
|
||||
|
||||
// TemplateContainer inventory = uiInventoryAsset.Instantiate();
|
||||
// container.Add(inventory);
|
||||
|
||||
var itemList = inventory.Q("Inventory").Q("ContainerScroll");
|
||||
var headerLabel = inventory.Q<Label>("Header");
|
||||
var footerLabel = inventory.Q<Label>("Footer");
|
||||
|
||||
itemList.Clear();
|
||||
|
||||
foreach (var item in inventory.Inventory.Items)
|
||||
foreach (var item in holder.Inventory.Items)
|
||||
{
|
||||
var child = uiItemAsset.Instantiate();
|
||||
// child.AddToClassList(".item");
|
||||
@@ -68,9 +94,7 @@ public class InventoryScreen : MonoBehaviour
|
||||
itemList.Add(child);
|
||||
}
|
||||
|
||||
headerLabel.text = inventory.Name;
|
||||
footerLabel.text = $"Свободно: {inventory.Inventory.Free}";
|
||||
|
||||
Show();
|
||||
headerLabel.text = holder.Name;
|
||||
footerLabel.text = $"Свободно: {holder.Inventory.Free}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ using UnityEngine.UIElements;
|
||||
|
||||
public class InventoryScreenInvoker : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
public InventoryHolder SourceInventory;
|
||||
public InventoryHolder TargetInventory;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
Show();
|
||||
@@ -19,13 +22,6 @@ public class InventoryScreenInvoker : MonoBehaviour, IPointerClickHandler
|
||||
return;
|
||||
}
|
||||
|
||||
var inventory = GetComponent<IInventoryHolder>();
|
||||
if (inventory == null)
|
||||
{
|
||||
Debug.Log("Cannot show inventory screen on an object without an inventory");
|
||||
return;
|
||||
}
|
||||
|
||||
inventoryScreen.Display(inventory);
|
||||
inventoryScreen.Display(SourceInventory, TargetInventory);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user