192 lines
6.7 KiB
C#
192 lines
6.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Invector.vShooter;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class InventoryMenuController : MonoBehaviour
|
|
{
|
|
[SerializeField] private MenuScroll menuScroll;
|
|
|
|
[SerializeField] private bEquipArea weaponsArea;
|
|
[SerializeField] private bItemWindow weaponsItemPicker;
|
|
|
|
[SerializeField] private bEquipArea othersArea;
|
|
[SerializeField] private bItemWindow othersItemPicker;
|
|
|
|
[SerializeField] private bItemSlot consumablesSlotPrefab, othersSlotPrefab;
|
|
|
|
[SerializeField] private bItemManager itemManager;
|
|
[SerializeField] private TMP_Text categoryText;
|
|
|
|
[SerializeField] private Image weaponImage, blueprintsImage, consumablesImage, resourcesImage;
|
|
|
|
private List<bItemType> weaponTypes = new List<bItemType> { bItemType.Swords, bItemType.Axes };
|
|
private List<bItemType> blueprintTypes = new List<bItemType> { bItemType.Builder };
|
|
private List<bItemType> consumableTypes = new List<bItemType> { bItemType.Consumable, bItemType.ConsumablesFaith };
|
|
private List<bItemType> resourcesTypes = new List<bItemType> { bItemType.Resources, bItemType.Gemstones };
|
|
|
|
public List<bItemType> currentTypes = new List<bItemType>();
|
|
|
|
private bEquipArea currentlySelectedArea;
|
|
|
|
public void OpenInventory()
|
|
{
|
|
OpenWeaponArea();
|
|
menuScroll.OnOpened += RefreshEquipmentWindow;
|
|
itemManager.onFinishItemDestroy += RefreshEquipmentWindow;
|
|
/// inventory.OnUpdateInventory += RefreshEquipmentWindow;
|
|
}
|
|
|
|
public void CloseInventory()
|
|
{
|
|
itemManager.onFinishItemDestroy -= RefreshEquipmentWindow;
|
|
|
|
menuScroll.OnOpened -= RefreshEquipmentWindow;
|
|
}
|
|
|
|
public void OpenWeaponArea()
|
|
{
|
|
currentTypes = weaponTypes;
|
|
SetEquipmentAreaIfNotCorrect(weaponsArea, weaponsItemPicker);
|
|
categoryText.text = "Weapons";
|
|
Player.Instance.PlayCategoryChangeSound();
|
|
currentlySelectedArea.SetEquipmentwindowWithFilter(currentTypes);
|
|
weaponImage.enabled = true;
|
|
blueprintsImage.enabled = false;
|
|
consumablesImage.enabled = false;
|
|
resourcesImage.enabled = false;
|
|
}
|
|
|
|
public void OpenBlueprintsArea()
|
|
{
|
|
currentTypes = blueprintTypes;
|
|
if (othersItemPicker.slotPrefab != othersSlotPrefab)
|
|
{
|
|
othersItemPicker.ClearSlots();
|
|
othersItemPicker.slotPrefab = othersSlotPrefab;
|
|
}
|
|
SetEquipmentAreaIfNotCorrect(othersArea, othersItemPicker);
|
|
categoryText.text = "Blueprints";
|
|
Player.Instance.PlayCategoryChangeSound();
|
|
currentlySelectedArea.SetEquipmentwindowWithFilter(currentTypes);
|
|
weaponImage.enabled = false;
|
|
blueprintsImage.enabled = true;
|
|
consumablesImage.enabled = false;
|
|
resourcesImage.enabled = false;
|
|
}
|
|
|
|
private void SetEquipmentAreaIfNotCorrect(bEquipArea area, bItemWindow itemPicker)
|
|
{
|
|
if (currentlySelectedArea != area && currentlySelectedArea != null)
|
|
{
|
|
currentlySelectedArea.DisableItemWindow();
|
|
}
|
|
currentlySelectedArea = area;
|
|
//currentlySelectedArea.EnableItemWindow();
|
|
currentlySelectedArea.SetNewItemWindow(itemPicker);
|
|
}
|
|
|
|
public void OpenConsumablesArea()
|
|
{
|
|
currentTypes = consumableTypes;
|
|
othersItemPicker.ClearSlots();
|
|
othersItemPicker.slotPrefab = consumablesSlotPrefab;
|
|
SetEquipmentAreaIfNotCorrect(othersArea, othersItemPicker);
|
|
categoryText.text = "Consumables";
|
|
Player.Instance.PlayCategoryChangeSound();
|
|
currentlySelectedArea.SetEquipmentwindowWithFilter(currentTypes);
|
|
weaponImage.enabled = false;
|
|
blueprintsImage.enabled = false;
|
|
consumablesImage.enabled = true;
|
|
resourcesImage.enabled = false;
|
|
}
|
|
|
|
public void TryToSelectGemstoneInResources()
|
|
{
|
|
OpenResourcesArea();
|
|
TryToSelectGemstone();
|
|
//menuScroll.OnOpened += TryToSelectGemstone;
|
|
}
|
|
|
|
public void TryToSelectShadowSlayerInWeaponsArea()
|
|
{
|
|
// OpenResourcesArea();
|
|
menuScroll.OnOpened += TryToSelectShadowSlayer;
|
|
}
|
|
|
|
public void OpenResourcesArea()
|
|
{
|
|
currentTypes = resourcesTypes;
|
|
if (othersItemPicker.slotPrefab != othersSlotPrefab)
|
|
{
|
|
othersItemPicker.ClearSlots();
|
|
othersItemPicker.slotPrefab = othersSlotPrefab;
|
|
}
|
|
SetEquipmentAreaIfNotCorrect(othersArea, othersItemPicker);
|
|
categoryText.text = "Resources";
|
|
Player.Instance.PlayCategoryChangeSound();
|
|
currentlySelectedArea.SetEquipmentwindowWithFilter(currentTypes);
|
|
weaponImage.enabled = false;
|
|
blueprintsImage.enabled = false;
|
|
consumablesImage.enabled = false;
|
|
resourcesImage.enabled = true;
|
|
}
|
|
|
|
private void TryToSelectGemstone()
|
|
{
|
|
bItemSlot gemstoneSlot = othersItemPicker.slots.Find(slot => slot.item && slot.item.type == bItemType.Gemstones);
|
|
if (gemstoneSlot)
|
|
{
|
|
gemstoneSlot.OnSelect(null);
|
|
}
|
|
// menuScroll.OnOpened -= TryToSelectGemstone;
|
|
}
|
|
|
|
private void TryToSelectShadowSlayer()
|
|
{
|
|
bItemSlot swordSlot = weaponsItemPicker.slots.Find(slot => slot.item && slot.item.name == "Shadow Slayer");
|
|
if (swordSlot)
|
|
{
|
|
swordSlot.OnSelect(null);
|
|
}
|
|
menuScroll.OnOpened -= TryToSelectShadowSlayer;
|
|
}
|
|
|
|
public void RefreshEquipmentWindow(int index)
|
|
{
|
|
RefreshEquipmentWindow();
|
|
}
|
|
|
|
public void RefreshEquipmentWindow()
|
|
{
|
|
if (currentlySelectedArea != null)
|
|
{
|
|
currentlySelectedArea.SetEquipmentwindowWithFilter(currentTypes);
|
|
}
|
|
else
|
|
{
|
|
currentlySelectedArea = weaponsArea;
|
|
currentTypes = weaponTypes;
|
|
currentlySelectedArea.SetEquipmentwindowWithFilter(weaponTypes);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (menuScroll)
|
|
{
|
|
menuScroll.OnOpened -= RefreshEquipmentWindow;
|
|
}
|
|
|
|
if (itemManager)
|
|
{
|
|
itemManager.onFinishItemDestroy -= RefreshEquipmentWindow;
|
|
}
|
|
}
|
|
}
|
|
} |