You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
566 lines
24 KiB
C#
566 lines
24 KiB
C#
|
4 years ago
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
using SiegeSong;
|
||
|
|
|
||
|
|
|
||
|
|
namespace SiegeSong
|
||
|
|
{
|
||
|
|
public class InventoryManager : MonoBehaviour
|
||
|
|
{
|
||
|
|
public EquipmentManager EquipmentManager;
|
||
|
|
public ApparrelManager ApparrelManager;
|
||
|
|
|
||
|
|
public AudioClip[] OpenMenuSounds;
|
||
|
|
public AudioClip[] MenuClickSounds;
|
||
|
|
public AudioClip[] MenuActivateSounds;
|
||
|
|
|
||
|
|
public GameObject MenuWrapper;
|
||
|
|
public GameObject WorldHudWrapper;
|
||
|
|
public bool InventoryScreenOpen;
|
||
|
|
|
||
|
|
public GameObject CameraObject;
|
||
|
|
|
||
|
|
public GameObject TransferScreen;
|
||
|
|
public GameObject InventoryScreen;
|
||
|
|
|
||
|
|
|
||
|
|
public Text DescriptionLabel;
|
||
|
|
public Text EffectsLabel;
|
||
|
|
//public SkinnedMesh PreviewMesh;
|
||
|
|
|
||
|
|
public Text CurrentHealthLabel;
|
||
|
|
public Text MaxHealthLabel;
|
||
|
|
public Slider HealthSlider;
|
||
|
|
public Text CurrentStaminaLabel;
|
||
|
|
public Text MaxStaminaLabel;
|
||
|
|
public Slider StaminaSlider;
|
||
|
|
public Text CurrentMagicLabel;
|
||
|
|
public Text MaxMagicLabel;
|
||
|
|
public Slider MagicSlider;
|
||
|
|
public Text CurrentCarryWeightLabel;
|
||
|
|
public Text MaxCarryWeightLabel;
|
||
|
|
public Text CurrentGoldLabel;
|
||
|
|
|
||
|
4 years ago
|
public StatisticsManager Actor;
|
||
|
4 years ago
|
|
||
|
|
public Container Inventory;
|
||
|
|
|
||
|
|
public bool TransferScreenOpen;
|
||
|
|
public bool TransferTargetSelf;
|
||
|
|
public Text TransferSelfLabel;
|
||
|
|
public Text TransferOtherLabel;
|
||
|
|
public GameObject TransferOtherPointer;
|
||
|
|
public GameObject TransferSelfPointer;
|
||
|
|
public Container TransferOther;
|
||
|
|
private List<GameObject> TransferRows;
|
||
|
|
public GameObject TransferRowArea;
|
||
|
|
public GameObject TransferRowPrefab;
|
||
|
|
|
||
|
|
public GameObject ItemDictionary;
|
||
|
|
public int SelectedItemID;
|
||
|
|
public int SelectedAmount;
|
||
|
|
|
||
|
|
private List<GameObject> InventoryRows;
|
||
|
|
private Dictionary<int, GameObject> rows;
|
||
|
|
public GameObject InventoryRowArea;
|
||
|
|
public GameObject InventoryRowPrefab;
|
||
|
4 years ago
|
|
||
|
|
public bool OpenInputNewState;
|
||
|
|
public bool UpArrowInputNewState;
|
||
|
|
public bool DownArrowInputNewState;
|
||
|
|
public bool ActivateInputNewState;
|
||
|
|
public bool DropInputNewState;
|
||
|
4 years ago
|
|
||
|
|
public int SelectedItemIndex;
|
||
|
|
|
||
|
|
|
||
|
|
private bool downArrowInputOldState;
|
||
|
|
private bool upArrowInputOldState;
|
||
|
|
|
||
|
|
private bool openInputOldState;
|
||
|
|
private bool activateInputOldState;
|
||
|
|
private bool dropInputOldState;
|
||
|
|
|
||
|
4 years ago
|
public Transform DroppedItemStartPosition;
|
||
|
4 years ago
|
|
||
|
4 years ago
|
private Color enabledTextColor;
|
||
|
|
private Color disabledTextColor;
|
||
|
4 years ago
|
|
||
|
4 years ago
|
private float transferRowHeight = 24.0f;
|
||
|
|
private float inventoryRowHeight = 24.0f;
|
||
|
|
private float inputAxisThreshhold = 0.1f;
|
||
|
|
|
||
|
|
private float rowsXOffset = 0f;
|
||
|
|
private float rowsYOffset = 0f;
|
||
|
4 years ago
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
rows = new Dictionary<int, GameObject>();
|
||
|
|
InventoryRows = new List<GameObject>();
|
||
|
|
Inventory.InventoryManager = this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerClick(PointerEventData eventData)
|
||
|
|
{
|
||
|
|
Debug.Log("Clicked: " + eventData.pointerCurrentRaycast.gameObject.name);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
if (InventoryRows == null)
|
||
|
|
InventoryRows = new List<GameObject>();
|
||
|
|
|
||
|
|
if (TransferScreenOpen || InventoryScreenOpen)
|
||
|
|
{
|
||
|
|
if (!upArrowInputOldState && UpArrowInputNewState)
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, MenuClickSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = MenuClickSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
|
||
|
|
if (SelectedItemIndex > 0)
|
||
|
|
SelectedItemIndex--;
|
||
|
|
else
|
||
|
|
SelectedItemIndex = TransferScreenOpen && !TransferTargetSelf ? TransferOther.Contents.Count - 1 : Inventory.Contents.Count - 1;
|
||
|
|
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!downArrowInputOldState && DownArrowInputNewState)
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, MenuClickSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = MenuClickSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
|
||
|
|
if (SelectedItemIndex >= (TransferScreenOpen && !TransferTargetSelf ? TransferOther.Contents.Count - 1 : Inventory.Contents.Count - 1))
|
||
|
|
SelectedItemIndex = 0;
|
||
|
|
else
|
||
|
|
SelectedItemIndex++;
|
||
|
|
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
|
||
|
|
if (UpArrowInputNewState)
|
||
|
|
upArrowInputOldState = true;
|
||
|
|
if (DownArrowInputNewState)
|
||
|
|
downArrowInputOldState = true;
|
||
|
|
|
||
|
|
if (!DownArrowInputNewState && !UpArrowInputNewState)
|
||
|
|
{
|
||
|
|
upArrowInputOldState = false;
|
||
|
|
downArrowInputOldState = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!OpenInputNewState)
|
||
|
|
{
|
||
|
|
if (ActivateInputNewState || DropInputNewState)
|
||
|
|
{
|
||
|
|
if (InventoryScreenOpen || (TransferScreenOpen && TransferTargetSelf))
|
||
|
|
SelectedItemID = Inventory.GetIDByOwnedIndex(SelectedItemIndex);
|
||
|
|
if (TransferScreenOpen && !TransferTargetSelf)
|
||
|
|
SelectedItemID = TransferOther.GetIDByOwnedIndex(SelectedItemIndex);
|
||
|
|
SelectedAmount = 1;
|
||
|
|
if (DropInputNewState)
|
||
|
|
dropInputOldState = true;
|
||
|
|
if (ActivateInputNewState)
|
||
|
|
activateInputOldState = true;
|
||
|
|
}
|
||
|
|
if (activateInputOldState && !ActivateInputNewState)
|
||
|
|
{
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
{
|
||
|
|
if (SelectedItemID != 0)
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, MenuActivateSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = MenuActivateSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
if (TransferTargetSelf)
|
||
|
|
{
|
||
|
|
TransferOther.AddItem(SelectedItemID, SelectedAmount);
|
||
|
|
RemoveItem();
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
TransferOther.RemoveItem(SelectedItemID, SelectedAmount);
|
||
|
|
AddItem();
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (InventoryScreenOpen)
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, MenuActivateSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = MenuActivateSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
ActivateItem();
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (dropInputOldState && !DropInputNewState)
|
||
|
|
{
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
{
|
||
|
|
SelectedItemIndex = 0;
|
||
|
|
TransferTargetSelf = !TransferTargetSelf;
|
||
|
|
}
|
||
|
|
else if (InventoryScreenOpen)
|
||
|
|
{
|
||
|
|
DropItem();
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!ActivateInputNewState)
|
||
|
|
activateInputOldState = false;
|
||
|
|
if (!DropInputNewState)
|
||
|
|
dropInputOldState = false;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextIndex()
|
||
|
|
{
|
||
|
|
|
||
|
|
if (SelectedItemIndex < Inventory.Contents.Count)
|
||
|
|
SelectedItemIndex++;
|
||
|
|
else
|
||
|
|
SelectedItemIndex = 0;
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void PreviousIndex()
|
||
|
|
{
|
||
|
|
|
||
|
|
if (SelectedItemIndex > 0)
|
||
|
|
SelectedItemIndex--;
|
||
|
|
else
|
||
|
|
SelectedItemIndex = Inventory.Contents.Count;
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UpdateTransferScreen()
|
||
|
|
{
|
||
|
|
TransferSelfLabel.color = TransferTargetSelf ? enabledTextColor : disabledTextColor;
|
||
|
4 years ago
|
TransferSelfLabel.text = Actor.Stats.FirstName;
|
||
|
4 years ago
|
TransferOtherLabel.color = TransferTargetSelf ? disabledTextColor : enabledTextColor;
|
||
|
|
TransferOtherLabel.text = TransferOther.Name;
|
||
|
|
TransferOtherPointer.active = TransferTargetSelf;
|
||
|
|
TransferSelfPointer.active = !TransferTargetSelf;
|
||
|
|
|
||
|
|
if (TransferRows != null)
|
||
|
|
{
|
||
|
|
foreach (var uiRow in TransferRows)
|
||
|
|
{
|
||
|
|
uiRow.active = false;
|
||
|
|
GameObject.Destroy(uiRow);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
for (var i = 0; i < TransferRowArea.transform.childCount; i++)
|
||
|
|
{
|
||
|
|
var row = TransferRowArea.transform.GetChild(i);
|
||
|
|
row.gameObject.active = false;
|
||
|
|
GameObject.Destroy(row);
|
||
|
|
}
|
||
|
|
|
||
|
|
TransferRows = new List<GameObject>();
|
||
|
|
|
||
|
|
var itemCount = TransferTargetSelf || TransferOther == null ? Inventory.Contents.Count : (TransferOther.Contents != null ? TransferOther.Contents.Count : 0);
|
||
|
|
|
||
|
|
for (var i = 0; i < itemCount; i++)
|
||
|
|
{
|
||
|
|
var uiRow = Instantiate(TransferRowPrefab);
|
||
|
|
var uiRowProperties = uiRow.GetComponent<InventoryRow>();
|
||
|
|
uiRowProperties.InventoryManager = this;
|
||
|
|
var targetItemId = TransferTargetSelf ? Inventory.GetIDByOwnedIndex(i) : TransferOther.GetIDByOwnedIndex(i);
|
||
|
|
var targetItem = GetItemByID(targetItemId);
|
||
|
|
if (targetItem != null && targetItem.GetComponent<InventoryItem>() != null)
|
||
|
|
{
|
||
|
|
uiRowProperties.ItemID = targetItem.GetComponent<InventoryItem>().ID;
|
||
|
|
var uiRowRect = uiRow.GetComponent<RectTransform>();
|
||
|
|
uiRow.transform.parent = TransferRowArea.transform;
|
||
|
|
uiRow.transform.localScale = Vector3.one;
|
||
|
|
|
||
|
4 years ago
|
uiRowRect.position = new Vector2(0, transferRowHeight * -(i + 1));
|
||
|
|
uiRowRect.offsetMin = new Vector2(0, transferRowHeight * -(i + 1));
|
||
|
|
uiRowRect.offsetMax = new Vector2(0, transferRowHeight * -(i));
|
||
|
|
uiRowRect.sizeDelta = new Vector2(0, transferRowHeight);
|
||
|
4 years ago
|
|
||
|
|
foreach (Transform childTransform in uiRow.transform)
|
||
|
|
{
|
||
|
|
var child = childTransform.gameObject;
|
||
|
|
if (child.name == "icon")
|
||
|
4 years ago
|
{
|
||
|
|
if (TransferTargetSelf)
|
||
|
|
{
|
||
|
|
var activeIdsList = new List<int>(ApparrelManager.CurrentlyActiveIDs);
|
||
|
|
child.GetComponent<Image>().enabled = activeIdsList.Contains(Inventory.GetIDByOwnedIndex(i));
|
||
|
|
}
|
||
|
|
else if (TransferOther.gameObject.GetComponentInChildren<ApparrelManager>() != null)
|
||
|
|
{
|
||
|
|
var activeIdsList = new List<int>(TransferOther.gameObject.GetComponentInChildren<ApparrelManager>().CurrentlyActiveIDs);
|
||
|
|
child.GetComponent<Image>().enabled = activeIdsList.Contains(Inventory.GetIDByOwnedIndex(i));
|
||
|
|
}
|
||
|
|
}
|
||
|
4 years ago
|
|
||
|
|
if (child.name == "highlight")
|
||
|
|
child.active = SelectedItemIndex == i;
|
||
|
|
|
||
|
|
//foreach (Transform hlChildTransform in childTransform)
|
||
|
|
//hlChildTransform.gameObject.GetComponent<Image>().enabled = SelectedItemIndex == i;
|
||
|
|
|
||
|
|
if (child.name == "name")
|
||
|
|
child.GetComponent<Text>().text = GetItemByID(TransferTargetSelf ? Inventory.GetIDByOwnedIndex(i) : TransferOther.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().FriendlyName;
|
||
|
|
|
||
|
|
if (child.name == "weight")
|
||
|
|
child.GetComponent<Text>().text = GetItemByID(TransferTargetSelf ? Inventory.GetIDByOwnedIndex(i) : TransferOther.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().PhysicalWeight.ToString();
|
||
|
|
|
||
|
|
if (child.name == "value")
|
||
|
|
child.GetComponent<Text>().text = GetItemByID(TransferTargetSelf ? Inventory.GetIDByOwnedIndex(i) : TransferOther.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().MonetaryValue.ToString();
|
||
|
|
|
||
|
|
}
|
||
|
|
TransferRows.Add(uiRow);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OpenInventoryScreen()
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, OpenMenuSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = OpenMenuSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
|
||
|
|
WorldHudWrapper.active = false;
|
||
|
|
MenuWrapper.active = true;
|
||
|
|
InventoryScreenOpen = true;
|
||
|
|
InventoryScreen.active = true;
|
||
|
4 years ago
|
TransferTargetSelf = true;
|
||
|
4 years ago
|
UpdateInventoryScreen();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OpenTransferMenu(Container transferOther)
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, OpenMenuSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = OpenMenuSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
|
||
|
|
WorldHudWrapper.active = false;
|
||
|
|
MenuWrapper.active = true;
|
||
|
|
SelectedItemIndex = 0;
|
||
|
|
TransferOther = transferOther;
|
||
|
|
TransferScreenOpen = true;
|
||
|
4 years ago
|
TransferTargetSelf = false;
|
||
|
4 years ago
|
TransferScreen.active = true;
|
||
|
|
activateInputOldState = ActivateInputNewState;
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void CloseInventoryScreen()
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, OpenMenuSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = OpenMenuSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
|
||
|
|
WorldHudWrapper.active = true;
|
||
|
|
MenuWrapper.active = false;
|
||
|
|
InventoryScreenOpen = false;
|
||
|
|
InventoryScreen.active = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void CloseTransferScreen()
|
||
|
|
{
|
||
|
|
var soundIndex = Random.Range(0, OpenMenuSounds.Length);
|
||
|
4 years ago
|
Actor.AudioSource.clip = OpenMenuSounds[soundIndex];
|
||
|
|
Actor.AudioSource.Play();
|
||
|
4 years ago
|
|
||
|
|
WorldHudWrapper.active = true;
|
||
|
|
MenuWrapper.active = false;
|
||
|
4 years ago
|
TransferTargetSelf = true;
|
||
|
4 years ago
|
TransferScreenOpen = false;
|
||
|
|
TransferScreen.active = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void UpdateInventoryScreen()
|
||
|
|
{
|
||
|
4 years ago
|
CurrentHealthLabel.text = Actor.Stats.Health.ToString();
|
||
|
|
MaxHealthLabel.text = Actor.Stats.MaxHealth.ToString();
|
||
|
|
HealthSlider.value = Actor.Stats.Health;
|
||
|
|
CurrentStaminaLabel.text = Actor.Stats.Stamina.ToString();
|
||
|
|
MaxStaminaLabel.text = Actor.Stats.MaxStamina.ToString();
|
||
|
|
StaminaSlider.value = Actor.Stats.Stamina;
|
||
|
|
CurrentMagicLabel.text = Actor.Stats.Magic.ToString();
|
||
|
|
MaxMagicLabel.text = Actor.Stats.MaxMagic.ToString();
|
||
|
|
MagicSlider.value = Actor.Stats.Magic;
|
||
|
|
CurrentCarryWeightLabel.text = Actor.Stats.CarryWeight.ToString();
|
||
|
|
MaxCarryWeightLabel.text = Actor.Stats.MaxCarryWeight.ToString();
|
||
|
|
CurrentGoldLabel.text = Actor.Stats.Gold.ToString();
|
||
|
4 years ago
|
|
||
|
|
for (var i = 0; i < Inventory.Contents.Count; i++)
|
||
|
|
{
|
||
|
|
var uiRow = rows != null && rows.ContainsKey(Inventory.GetIDByOwnedIndex(i)) ? rows[Inventory.GetIDByOwnedIndex(i)] : Instantiate(InventoryRowPrefab);
|
||
|
|
var uiRowProperties = uiRow.GetComponent<InventoryRow>();
|
||
|
|
uiRowProperties.InventoryManager = this;
|
||
|
|
uiRowProperties.ItemID = Inventory.GetIDByOwnedIndex(i);
|
||
|
|
var rowExists = false;
|
||
|
|
|
||
|
|
var uiRowRect = uiRow.GetComponent<RectTransform>();
|
||
|
|
uiRow.transform.parent = InventoryRowArea.transform;
|
||
|
|
uiRow.transform.localScale = Vector3.one;
|
||
|
4 years ago
|
uiRowRect.position = new Vector2(0, inventoryRowHeight * -(i + 1));
|
||
|
|
uiRowRect.offsetMin = new Vector2(0, inventoryRowHeight * -(i + 1));
|
||
|
|
uiRowRect.offsetMax = new Vector2(0, inventoryRowHeight * -(i));
|
||
|
|
uiRowRect.sizeDelta = new Vector2(0, inventoryRowHeight);
|
||
|
4 years ago
|
|
||
|
|
if (SelectedItemIndex == i)
|
||
|
|
{
|
||
|
|
DescriptionLabel.text = GetItemByID(Inventory.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().Description;
|
||
|
|
EffectsLabel.text = string.Join("\n", GetItemByID(Inventory.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().Effects);
|
||
|
|
}
|
||
|
|
|
||
|
|
var targetItem = GetItemByID(uiRowProperties.ItemID);
|
||
|
|
if (Inventory != null && Inventory.Contents != null && Inventory.Contents.Count > 0 && InventoryRows != null && targetItem != null && targetItem.GetComponent<InventoryItem>() != null)
|
||
|
|
{
|
||
|
|
foreach (Transform childTransform in uiRow.transform)
|
||
|
|
{
|
||
|
|
var child = childTransform.gameObject;
|
||
|
|
if (child.name == "icon")
|
||
|
4 years ago
|
{
|
||
|
|
if (TransferTargetSelf)
|
||
|
|
{
|
||
|
|
var activeIdsList = new List<int>(ApparrelManager.CurrentlyActiveIDs);
|
||
|
|
child.GetComponent<Image>().enabled = activeIdsList.Contains(Inventory.GetIDByOwnedIndex(i));
|
||
|
|
}
|
||
|
|
else if (TransferOther != null && TransferOther.gameObject.GetComponentInChildren<ApparrelManager>() != null)
|
||
|
|
{
|
||
|
|
var activeIdsList = new List<int>(TransferOther.gameObject.GetComponentInChildren<ApparrelManager>().CurrentlyActiveIDs);
|
||
|
|
child.GetComponent<Image>().enabled = activeIdsList.Contains(Inventory.GetIDByOwnedIndex(i));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
child.GetComponent<Image>().enabled = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
4 years ago
|
|
||
|
|
if (child.name == "highlight")
|
||
|
|
foreach (Transform hlChildTransform in childTransform)
|
||
|
|
hlChildTransform.gameObject.GetComponent<Image>().enabled = SelectedItemIndex == i;
|
||
|
|
|
||
|
|
if (child.name == "name")
|
||
|
|
child.GetComponent<Text>().text = GetItemByID(Inventory.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().FriendlyName;
|
||
|
|
|
||
|
|
if (child.name == "quantity")
|
||
|
|
child.GetComponent<Text>().text = Inventory.Contents.ContainsKey(i) ? Inventory.Contents[i].ToString() : "1";
|
||
|
|
|
||
|
|
if (child.name == "weight")
|
||
|
|
child.GetComponent<Text>().text = GetItemByID(Inventory.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().PhysicalWeight.ToString();
|
||
|
|
|
||
|
|
if (child.name == "value")
|
||
|
|
child.GetComponent<Text>().text = GetItemByID(Inventory.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>().MonetaryValue.ToString();
|
||
|
|
|
||
|
|
if (child.name == "condition")
|
||
|
|
{
|
||
|
|
var item = GetItemByID(Inventory.GetIDByOwnedIndex(i)).GetComponent<InventoryItem>();
|
||
|
|
child.GetComponent<Text>().text = item.PhysicalCondition + "/" + item.MaxPhysicalCondition;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!rows.ContainsKey(Inventory.GetIDByOwnedIndex(i)))
|
||
|
|
{
|
||
|
|
InventoryRows.Add(uiRow);
|
||
|
|
rows.Add(Inventory.GetIDByOwnedIndex(i), uiRow);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public GameObject GetItemByID(int ID)
|
||
|
|
{
|
||
|
|
for (var i = 0; i < ItemDictionary.transform.childCount; i++)
|
||
|
|
{
|
||
|
|
if (ItemDictionary.transform.GetChild(i).GetComponent<InventoryItem>().ID == ID)
|
||
|
|
{
|
||
|
|
return ItemDictionary.transform.GetChild(i).gameObject;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void DropItem()
|
||
|
|
{
|
||
|
|
RemoveItem();
|
||
|
|
for (var i = 0; i < SelectedAmount; i++)
|
||
|
|
{
|
||
|
|
GetItemByID(SelectedItemID).GetComponent<InventoryItem>().DroppedStartPosition = DroppedItemStartPosition;
|
||
|
|
GetItemByID(SelectedItemID).GetComponent<InventoryItem>().Drop();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void AddItem()
|
||
|
|
{
|
||
|
|
if (Inventory.Contents.ContainsKey(SelectedItemID))
|
||
|
|
Inventory.Contents[SelectedItemID] += SelectedAmount;
|
||
|
|
else
|
||
|
|
Inventory.Contents.Add(SelectedItemID, SelectedAmount);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void RemoveItem()
|
||
|
|
{
|
||
|
|
var currentlyOwnedCount = Inventory.Contents.ContainsKey(SelectedItemID) ? Inventory.Contents[SelectedItemID] : 0;
|
||
|
|
if (currentlyOwnedCount - SelectedAmount > 0)
|
||
|
|
{
|
||
|
|
Inventory.Contents[SelectedItemID] = currentlyOwnedCount - SelectedAmount;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Inventory.Contents.Remove(SelectedItemID);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ActivateItem()
|
||
|
|
{
|
||
|
|
for (var i = 0; i < SelectedAmount; i++)
|
||
|
|
{
|
||
|
|
var gameObject = GetItemByID(SelectedItemID);
|
||
|
|
if (gameObject)
|
||
|
|
{
|
||
|
|
var item = gameObject.GetComponent<InventoryItem>();
|
||
|
|
if (item != null)
|
||
|
|
item.Activate(ApparrelManager);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (InventoryScreenOpen)
|
||
|
|
UpdateInventoryScreen();
|
||
|
|
if (TransferScreenOpen)
|
||
|
|
UpdateTransferScreen();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|