Many changes to Invector inventory system, added WIP UI system, added implementation for max stamina, moving speed, attack speed, attack power, thorns
This commit is contained in:
@@ -3,7 +3,6 @@ using Invector.vItemManager;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -13,24 +12,29 @@ using UnityEngine.UI;
|
||||
namespace Beyond
|
||||
{
|
||||
[System.Serializable]
|
||||
public class OnHandleSlot : UnityEngine.Events.UnityEvent<bItemSlot>
|
||||
{ }
|
||||
public class OnHandleSlot : UnityEngine.Events.UnityEvent<bItemSlot> { }
|
||||
|
||||
[System.Serializable]
|
||||
public class OnCompleteSlotList : UnityEngine.Events.UnityEvent<List<bItemSlot>>
|
||||
{ }
|
||||
public class OnCompleteSlotList : UnityEngine.Events.UnityEvent<List<bItemSlot>> { }
|
||||
|
||||
[vClassHeader("Item Window", openClose = false)]
|
||||
public class bItemWindow : vMonoBehaviour
|
||||
{
|
||||
public bInventory inventory;
|
||||
[vReadOnly] public bItem currentItem;
|
||||
private List<bItem> items;
|
||||
|
||||
[Header("Required References")]
|
||||
[Tooltip("The prefab used to instantiate items in the list.")]
|
||||
public bItemSlot slotPrefab;
|
||||
[Tooltip("The Content RectTransform inside your Scroll View.")]
|
||||
public RectTransform contentWindow;
|
||||
|
||||
public List<bItemSlot> slots;
|
||||
public List<bItemType> supportedItems;
|
||||
public bool updateSlotCount = true;
|
||||
|
||||
[Header("UI References")]
|
||||
public TMP_Text displayNameText;
|
||||
public Image rarityImage;
|
||||
public Text displayTypeText;
|
||||
@@ -42,104 +46,56 @@ namespace Beyond
|
||||
public Image displayItemImage, secondaryItemImage, teriaryItemImage;
|
||||
[SerializeField] private Sprite defaultSprite;
|
||||
|
||||
[Header("Additional things")]
|
||||
[Header("Selection & Buttons")]
|
||||
public bItemSlot currentSelectedSlot;
|
||||
|
||||
[SerializeField] private TMP_Text submitButtonText, consumeButtonText;
|
||||
[SerializeField] private RectTransform descriptionTransform;
|
||||
[SerializeField] public RectTransform descriptionTransform;
|
||||
[SerializeField] private Scrollbar descriptionScroolbar;
|
||||
[SerializeField] private string useButtonString = "";
|
||||
|
||||
[SerializeField]
|
||||
private GameObject button, consumeButton;
|
||||
|
||||
[SerializeField]
|
||||
private bool isTradeWindow = false;
|
||||
[SerializeField] private GameObject button, consumeButton;
|
||||
[SerializeField] private bool isTradeWindow = false;
|
||||
|
||||
[vHelpBox("You can ignore display Attributes using this property")]
|
||||
public List<bItemAttributes> ignoreAttributes;
|
||||
|
||||
[vEditorToolbar("Text Events")]
|
||||
public InputField.OnChangeEvent onChangeName;
|
||||
|
||||
public InputField.OnChangeEvent onChangeType;
|
||||
public InputField.OnChangeEvent onChangeAmount;
|
||||
public InputField.OnChangeEvent onChangeDescription;
|
||||
public InputField.OnChangeEvent onChangeAttributes;
|
||||
// public InputField.OnChangeEvent onChangeImage;
|
||||
public InputField.OnChangeEvent onChangeName, onChangeType, onChangeAmount, onChangeDescription, onChangeAttributes;
|
||||
|
||||
[vEditorToolbar("Events")]
|
||||
public OnCompleteSlotList onCompleteSlotListCallBack;
|
||||
|
||||
public OnHandleSlot onSubmitSlot;
|
||||
public OnHandleSlot onSelectSlot;
|
||||
public UnityEvent onCancelSlot;
|
||||
|
||||
[Tooltip("Called when item window has slots on enable")]
|
||||
public UnityEvent onAddSlots;
|
||||
|
||||
[Tooltip("Called when item window dont have slots on enable")]
|
||||
public UnityEvent onClearSlots;
|
||||
|
||||
private UnityAction<bItemSlot> onSubmitSlotCallback;
|
||||
private UnityAction<bItemSlot> onSelectCallback;
|
||||
private readonly WaitForEndOfFrame WaitForEndOfFrame = new WaitForEndOfFrame();
|
||||
|
||||
private List<bItemType> chroniclesTypes = new List<bItemType> { bItemType.ChronicleResources, bItemType.Locations, bItemType.Science, bItemType.Characters };
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (descriptionScroolbar)
|
||||
{
|
||||
StartCoroutine(RebuildLayoutCoroutine());
|
||||
}
|
||||
if (descriptionScroolbar && descriptionTransform)
|
||||
StartCoroutine(RebuildLayoutCoroutine(descriptionTransform));
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
//unload stuff
|
||||
UnloadCurrentImage();
|
||||
}
|
||||
private void OnDisable() => UnloadCurrentImage();
|
||||
|
||||
private void UnloadCurrentImage()
|
||||
{
|
||||
// Sprite spriteToUnload = displayItemImage.sprite;
|
||||
if (displayItemImage)
|
||||
{
|
||||
Resources.UnloadAsset(displayItemImage.sprite);
|
||||
}
|
||||
if (secondaryItemImage)
|
||||
{
|
||||
Resources.UnloadAsset(secondaryItemImage.sprite);
|
||||
}
|
||||
if (teriaryItemImage)
|
||||
{
|
||||
Resources.UnloadAsset(teriaryItemImage.sprite);
|
||||
}
|
||||
|
||||
if (powerSwordImage)
|
||||
{
|
||||
Resources.UnloadAsset(powerSwordImage.sprite);
|
||||
}
|
||||
// displayItemImage.sprite = null;
|
||||
// secondaryItemImage.sprite = null;
|
||||
// teriaryItemImage.sprite = null;
|
||||
// Resources.UnloadAsset(spriteToUnload);
|
||||
//Resources.UnloadUnusedAssets();
|
||||
if (displayItemImage && displayItemImage.sprite) Resources.UnloadAsset(displayItemImage.sprite);
|
||||
if (secondaryItemImage && secondaryItemImage.sprite) Resources.UnloadAsset(secondaryItemImage.sprite);
|
||||
if (teriaryItemImage && teriaryItemImage.sprite) Resources.UnloadAsset(teriaryItemImage.sprite);
|
||||
if (powerSwordImage && powerSwordImage.sprite) Resources.UnloadAsset(powerSwordImage.sprite);
|
||||
}
|
||||
|
||||
public void ReloadItems()
|
||||
{
|
||||
ReloadItems(items);
|
||||
}
|
||||
public void ReloadItems() => ReloadItems(items);
|
||||
|
||||
public void ClearSlots()
|
||||
{
|
||||
int slotsCount = slots.Count;
|
||||
for (int i = 0; i < slotsCount; i++)
|
||||
{
|
||||
Destroy(slots[i].gameObject);
|
||||
}
|
||||
if (slots == null) return;
|
||||
for (int i = 0; i < slots.Count; i++) if (slots[i]) Destroy(slots[i].gameObject);
|
||||
slots.Clear();
|
||||
currentSelectedSlot = null;
|
||||
}
|
||||
@@ -162,11 +118,7 @@ namespace Beyond
|
||||
}
|
||||
i--;
|
||||
}
|
||||
else if (slots[i] == null)
|
||||
{
|
||||
slots.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
else if (slots[i] == null) { slots.RemoveAt(i); i--; }
|
||||
}
|
||||
}
|
||||
if (currentSelectedSlot == null || currentSelectedSlot.item == null || slots.Count == 0)
|
||||
@@ -184,121 +136,111 @@ namespace Beyond
|
||||
|
||||
public virtual void CreateEquipmentWindow(List<bItem> items, List<bItemType> type, bItem currentItem = null, UnityAction<bItemSlot> onPickUpItemCallback = null, UnityAction<bItemSlot> onSelectSlotCallBack = null)
|
||||
{
|
||||
this.supportedItems = type;
|
||||
this.items = items.FindAll(item => type.Contains(item.type));
|
||||
List<bItem> list = new List<bItem>();
|
||||
foreach (var bItem in this.items.OrderBy(item => item.type)
|
||||
.ThenBy(item => item.name))
|
||||
list.Add(bItem);
|
||||
foreach (var bItem in this.items.OrderBy(item => item.type).ThenBy(item => item.name)) list.Add(bItem);
|
||||
this.items = list;
|
||||
|
||||
this.currentItem = currentItem;
|
||||
if (!this.currentItem && this.items.Count > 0)
|
||||
{
|
||||
this.currentItem = this.items[0];
|
||||
}
|
||||
CreateEquipmentWindowNormal(this.items, onPickUpItemCallback, destroyAdictionSlots: true);
|
||||
if (!this.currentItem && this.items.Count > 0) this.currentItem = this.items[0];
|
||||
CreateEquipmentWindowNormal(this.items, onPickUpItemCallback, onSelectSlotCallBack, destroyAdictionSlots: true);
|
||||
}
|
||||
|
||||
public virtual void CreateEquipmentWindowUsable(List<bItem> items, List<bItemType> type, bItem currentItem = null, UnityAction<bItemSlot> onPickUpItemCallback = null, UnityAction<bItemSlot> onSelectSlotCallBack = null)
|
||||
{
|
||||
this.supportedItems = type;
|
||||
this.currentItem = currentItem;
|
||||
var _items = items.FindAll(item => type.Contains(item.type));
|
||||
var _itemsUsable = _items.FindAll(item => item.canBeUsed);
|
||||
CreateEquipmentWindowNormal(_itemsUsable, onPickUpItemCallback, destroyAdictionSlots: true);
|
||||
CreateEquipmentWindowNormal(_itemsUsable, onPickUpItemCallback, onSelectSlotCallBack, destroyAdictionSlots: true);
|
||||
}
|
||||
|
||||
public void CreateEquipmentWindowNormal(List<bItem> items, UnityAction<bItemSlot> onPickUpItemCallBack = null, UnityAction<bItemSlot> onSelectSlotCallBack = null, bool destroyAdictionSlots = true)
|
||||
{
|
||||
var _items = supportedItems.Count == 0 ? items : items.FindAll(i => supportedItems.Contains(i.type));
|
||||
if (inventory == null && Player.Instance != null && Player.Instance.ItemManager != null)
|
||||
inventory = Player.Instance.ItemManager.inventory;
|
||||
|
||||
var _items = supportedItems == null || supportedItems.Count == 0 ? items : items.FindAll(i => supportedItems.Contains(i.type));
|
||||
|
||||
if (_items.Count == 0)
|
||||
{
|
||||
CreateFullItemDescription(null);
|
||||
onClearSlots.Invoke();
|
||||
if (slots.Count > 0 && destroyAdictionSlots && updateSlotCount)
|
||||
{
|
||||
for (int i = 0; i < slots.Count; i++)
|
||||
{
|
||||
// yield return null;
|
||||
Destroy(slots[i].gameObject);
|
||||
}
|
||||
slots.Clear();
|
||||
}
|
||||
|
||||
if (slots != null && slots.Count > 0 && destroyAdictionSlots && updateSlotCount) ClearSlots();
|
||||
currentSelectedSlot = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slots == null) slots = new List<bItemSlot>();
|
||||
|
||||
if (slots.Count > _items.Count && destroyAdictionSlots && updateSlotCount)
|
||||
{
|
||||
int difference = slots.Count - _items.Count;
|
||||
|
||||
for (int i = 0; i < difference; i++)
|
||||
{
|
||||
// yield return null;
|
||||
Destroy(slots[0].gameObject);
|
||||
slots.RemoveAt(0);
|
||||
}
|
||||
for (int i = 0; i < difference; i++) { if (slots[0]) Destroy(slots[0].gameObject); slots.RemoveAt(0); }
|
||||
}
|
||||
|
||||
bool selecItem = false;
|
||||
onSubmitSlotCallback = onPickUpItemCallBack;
|
||||
onSelectCallback = onSelectSlotCallBack;
|
||||
if (slots == null) slots = new List<bItemSlot>();
|
||||
var count = items.Count;
|
||||
|
||||
if (updateSlotCount)
|
||||
{
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
{
|
||||
bItemSlot slot = null;
|
||||
if (i < slots.Count)
|
||||
{
|
||||
slot = slots[i];
|
||||
}
|
||||
if (i < slots.Count) slot = slots[i];
|
||||
else
|
||||
{
|
||||
slot = Instantiate(slotPrefab) as bItemSlot;
|
||||
// --- SAFETY CHECK ---
|
||||
if (slotPrefab == null)
|
||||
{
|
||||
Debug.LogError("<b>[bItemWindow]</b> Error: 'Slot Prefab' is not assigned! Please drag a bItemSlot prefab into the 'Slot Prefab' field in the Inspector.", this);
|
||||
return;
|
||||
}
|
||||
if (contentWindow == null)
|
||||
{
|
||||
Debug.LogError("<b>[bItemWindow]</b> Error: 'Content Window' is not assigned! Please assign the Content RectTransform of your Scroll View.", this);
|
||||
return;
|
||||
}
|
||||
// --------------------
|
||||
|
||||
slot = Instantiate(slotPrefab) as bItemSlot;
|
||||
slots.Add(slot);
|
||||
var rectTranform = slot.GetComponent<RectTransform>();
|
||||
rectTranform.SetParent(contentWindow);
|
||||
rectTranform.localPosition = Vector3.zero;
|
||||
rectTranform.localScale = Vector3.one;
|
||||
rectTranform.localRotation = Quaternion.identity;
|
||||
// yield return null;
|
||||
|
||||
// Ensure the new slot is visible and active
|
||||
slot.gameObject.SetActive(true);
|
||||
}
|
||||
// slot = slots[i];
|
||||
|
||||
slot.SetInventory(this.inventory);
|
||||
slot.AddItem(_items[i]);
|
||||
if (slot.item.type == bItemType.PowerScroll && slot.item.canBeDroped)
|
||||
{
|
||||
slot.TryToMarkAsSpeciallEquipped();
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.CheckItem(_items[i].isInEquipArea);
|
||||
}
|
||||
|
||||
if (slot.item.type == bItemType.PowerScroll && slot.item.canBeDroped) slot.TryToMarkAsSpeciallEquipped();
|
||||
else slot.CheckItem(_items[i].isInEquipArea);
|
||||
|
||||
slot.onSubmitSlotCallBack = OnSubmit;
|
||||
slot.onSelectSlotCallBack = OnSelect;
|
||||
|
||||
if (currentItem != null && currentItem == _items[i])
|
||||
{
|
||||
if (currentSelectedSlot)
|
||||
{
|
||||
currentSelectedSlot.MarkSlotAsDeselected();
|
||||
}
|
||||
if (currentSelectedSlot) currentSelectedSlot.MarkSlotAsDeselected();
|
||||
selecItem = true;
|
||||
currentSelectedSlot = slot;
|
||||
|
||||
OnSelect(slot);
|
||||
}
|
||||
slot.UpdateDisplays();
|
||||
}
|
||||
}
|
||||
if (slots.Count > 0 && !selecItem)
|
||||
{
|
||||
currentSelectedSlot = slots[0];
|
||||
//StartCoroutine(SetSelectableHandle(slots[0].gameObject));
|
||||
}
|
||||
|
||||
if (slots.Count > 0 && !selecItem) currentSelectedSlot = slots[0];
|
||||
if (contentWindow) LayoutRebuilder.ForceRebuildLayoutImmediate(contentWindow);
|
||||
}
|
||||
|
||||
SetSubmitButton(currentSelectedSlot);
|
||||
|
||||
if (slots.Count > 0)
|
||||
@@ -307,124 +249,98 @@ namespace Beyond
|
||||
EnableDescriptionObjects();
|
||||
CreateFullItemDescription(currentSelectedSlot);
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableDescriptionObjects();
|
||||
}
|
||||
else DisableDescriptionObjects();
|
||||
|
||||
onCompleteSlotListCallBack.Invoke(slots);
|
||||
}
|
||||
|
||||
public void EnableDescriptionObjects()
|
||||
{
|
||||
displayNameText.enabled = true;
|
||||
descriptionTransform.gameObject.SetActive(true);
|
||||
if (displayNameText) displayNameText.enabled = true;
|
||||
if (descriptionTransform) descriptionTransform.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void DisableDescriptionObjects()
|
||||
{
|
||||
displayNameText.enabled = false;
|
||||
descriptionTransform.gameObject.SetActive(false);
|
||||
if (displayNameText) displayNameText.enabled = false;
|
||||
if (descriptionTransform) descriptionTransform.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void SetPowerableSwitchSwordImage(bItem selectedPowerableItem)
|
||||
{
|
||||
if (powerSwordImage == null) return;
|
||||
if (powerSwordImage.sprite) Resources.UnloadAsset(powerSwordImage.sprite);
|
||||
if (!selectedPowerableItem) powerSwordImage.enabled = false;
|
||||
else
|
||||
{
|
||||
powerSwordImage.enabled = true;
|
||||
powerSwordImage.sprite = Resources.Load<Sprite>(selectedPowerableItem.iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IEnumerator CreateEquipmentWindowRoutine(List<bItem> items, UnityAction<bItemSlot> onPickUpItemCallBack = null, UnityAction<bItemSlot> onSelectSlotCallBack = null, bool destroyAdictionSlots = true)
|
||||
{
|
||||
var _items = supportedItems.Count == 0 ? items : items.FindAll(i => supportedItems.Contains(i.type));
|
||||
if (inventory == null && Player.Instance != null && Player.Instance.ItemManager != null)
|
||||
inventory = Player.Instance.ItemManager.inventory;
|
||||
|
||||
var _items = supportedItems == null || supportedItems.Count == 0 ? items : items.FindAll(i => supportedItems.Contains(i.type));
|
||||
|
||||
if (_items.Count == 0)
|
||||
{
|
||||
CreateFullItemDescription(null);
|
||||
onClearSlots.Invoke();
|
||||
if (slots.Count > 0 && destroyAdictionSlots && updateSlotCount)
|
||||
{
|
||||
for (int i = 0; i < slots.Count; i++)
|
||||
{
|
||||
// yield return null;
|
||||
Destroy(slots[i].gameObject);
|
||||
}
|
||||
slots.Clear();
|
||||
currentSelectedSlot = null;
|
||||
}
|
||||
ClearSlots();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (slots.Count > _items.Count && destroyAdictionSlots && updateSlotCount)
|
||||
{
|
||||
int difference = slots.Count - _items.Count;
|
||||
|
||||
for (int i = 0; i < difference; i++)
|
||||
{
|
||||
yield return null;
|
||||
Destroy(slots[0].gameObject);
|
||||
slots.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
bool selecItem = false;
|
||||
onSubmitSlotCallback = onPickUpItemCallBack;
|
||||
onSelectCallback = onSelectSlotCallBack;
|
||||
if (slots == null) slots = new List<bItemSlot>();
|
||||
var count = items.Count;
|
||||
// if (updateSlotCount)
|
||||
ClearSlots();
|
||||
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
{
|
||||
for (int i = 0; i < _items.Count; i++)
|
||||
if (slotPrefab == null)
|
||||
{
|
||||
bItemSlot slot = null;
|
||||
if (i < slots.Count)
|
||||
{
|
||||
slot = slots[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
slot = Instantiate(slotPrefab) as bItemSlot;
|
||||
|
||||
slots.Add(slot);
|
||||
var rectTranform = slot.GetComponent<RectTransform>();
|
||||
rectTranform.SetParent(contentWindow);
|
||||
rectTranform.localPosition = Vector3.zero;
|
||||
rectTranform.localScale = Vector3.one;
|
||||
// yield return null;
|
||||
}
|
||||
// slot = slots[i];
|
||||
slot.AddItem(_items[i]);
|
||||
slot.CheckItem(_items[i].isInEquipArea);
|
||||
slot.onSubmitSlotCallBack = OnSubmit;
|
||||
slot.onSelectSlotCallBack = OnSelect;
|
||||
|
||||
if (currentItem != null && currentItem == _items[i])
|
||||
{
|
||||
selecItem = true;
|
||||
currentSelectedSlot = slot;
|
||||
SetSelectable(slot.gameObject);
|
||||
}
|
||||
slot.UpdateDisplays();
|
||||
Debug.LogError("<b>[bItemWindow]</b> Error: 'Slot Prefab' is missing!", this);
|
||||
yield break;
|
||||
}
|
||||
|
||||
bItemSlot slot = Instantiate(slotPrefab) as bItemSlot;
|
||||
slots.Add(slot);
|
||||
var rectTranform = slot.GetComponent<RectTransform>();
|
||||
rectTranform.SetParent(contentWindow);
|
||||
rectTranform.localPosition = Vector3.zero;
|
||||
rectTranform.localScale = Vector3.one;
|
||||
slot.gameObject.SetActive(true);
|
||||
|
||||
slot.inventory = this.inventory;
|
||||
slot.AddItem(_items[i]);
|
||||
slot.CheckItem(_items[i].isInEquipArea);
|
||||
slot.onSubmitSlotCallBack = OnSubmit;
|
||||
slot.onSelectSlotCallBack = OnSelect;
|
||||
slot.UpdateDisplays();
|
||||
|
||||
yield return null;
|
||||
}
|
||||
if (slots.Count > 0 && !selecItem)
|
||||
{
|
||||
currentSelectedSlot = slots[0];
|
||||
StartCoroutine(SetSelectableHandle(slots[0].gameObject));
|
||||
}
|
||||
|
||||
if (contentWindow) LayoutRebuilder.ForceRebuildLayoutImmediate(contentWindow);
|
||||
if (slots.Count > 0) { currentSelectedSlot = slots[0]; CreateFullItemDescription(currentSelectedSlot); }
|
||||
}
|
||||
|
||||
if (slots.Count > 0)
|
||||
{
|
||||
onAddSlots.Invoke();
|
||||
CreateFullItemDescription(currentSelectedSlot);
|
||||
}
|
||||
if (slots.Count > 0) onAddSlots.Invoke();
|
||||
onCompleteSlotListCallBack.Invoke(slots);
|
||||
}
|
||||
|
||||
public virtual IEnumerator SetSelectableHandle(GameObject target)
|
||||
{
|
||||
if (this.enabled)
|
||||
{
|
||||
yield return WaitForEndOfFrame;
|
||||
SetSelectable(target);
|
||||
}
|
||||
if (this.enabled) { yield return WaitForEndOfFrame; SetSelectable(target); }
|
||||
}
|
||||
|
||||
public virtual void SetSelectable(GameObject target)
|
||||
{
|
||||
if (!EventSystem.current) return;
|
||||
var pointer = new PointerEventData(EventSystem.current);
|
||||
ExecuteEvents.Execute(EventSystem.current.currentSelectedGameObject, pointer, ExecuteEvents.pointerExitHandler);
|
||||
if (EventSystem.current.currentSelectedGameObject)
|
||||
ExecuteEvents.Execute(EventSystem.current.currentSelectedGameObject, pointer, ExecuteEvents.pointerExitHandler);
|
||||
EventSystem.current.SetSelectedGameObject(target, new BaseEventData(EventSystem.current));
|
||||
ExecuteEvents.Execute(target, pointer, ExecuteEvents.selectHandler);
|
||||
}
|
||||
@@ -433,7 +349,8 @@ namespace Beyond
|
||||
{
|
||||
if (ShouldDissalowUseOfScrolls(slot))
|
||||
{
|
||||
PopupMenuController.Instance.TryToShowPopupMesssage("Skill Required: " + SkillsManager.instance.GetStringNameOf(Skills.MasterOfScrolls));
|
||||
if (PopupMenuController.Instance != null && SkillsManager.instance != null)
|
||||
PopupMenuController.Instance.TryToShowPopupMesssage("Skill Required: " + SkillsManager.instance.GetStringNameOf(Skills.MasterOfScrolls));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -446,118 +363,57 @@ namespace Beyond
|
||||
|
||||
private bool ShouldDissalowUseOfScrolls(bItemSlot slot)
|
||||
{
|
||||
if (slot == null || slot.item == null) return false;
|
||||
if (SkillsManager.instance == null) return false;
|
||||
return slot.item.type == bItemType.PowerScroll && SkillsManager.instance.GetSkillLevelOf(Skills.MasterOfScrolls) == 0 && PopupMenuController.Instance != null && !isTradeWindow;
|
||||
}
|
||||
|
||||
private void SetSubmitButton(bItemSlot slot)
|
||||
{
|
||||
if (!slot)
|
||||
if (!slot || !button)
|
||||
{
|
||||
button.SetActive(false);
|
||||
if (consumeButton)
|
||||
if (button) button.SetActive(false);
|
||||
if (consumeButton) consumeButton.SetActive(false);
|
||||
return;
|
||||
}
|
||||
button.SetActive(true);
|
||||
if (useButtonString != "") { if (submitButtonText) submitButtonText.text = useButtonString; return; }
|
||||
|
||||
if (submitButtonText)
|
||||
{
|
||||
bItemType itemType = slot.item.type;
|
||||
switch (itemType)
|
||||
{
|
||||
consumeButton.SetActive(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
button.SetActive(true);
|
||||
}
|
||||
|
||||
if (useButtonString != "")
|
||||
{
|
||||
submitButtonText.text = useButtonString;
|
||||
return;
|
||||
}
|
||||
|
||||
bItemType itemType = slot.item.type;
|
||||
|
||||
switch (itemType)
|
||||
{
|
||||
case bItemType.MeleeWeapon:
|
||||
case bItemType.Swords:
|
||||
case bItemType.Axes:
|
||||
case bItemType.QuantaPower:
|
||||
case bItemType.Gemstones:
|
||||
|
||||
submitButtonText.text = slot.isChecked ? "Unequip" : "Equip";
|
||||
break;
|
||||
|
||||
case bItemType.PowerScroll:
|
||||
if (!slot.item.canBeDroped)
|
||||
{
|
||||
case bItemType.MeleeWeapon:
|
||||
case bItemType.Swords:
|
||||
case bItemType.Axes:
|
||||
case bItemType.QuantaPower:
|
||||
case bItemType.Gemstones:
|
||||
case bItemType.Trinkets:
|
||||
submitButtonText.text = slot.isChecked ? "Unequip" : "Equip";
|
||||
}
|
||||
else
|
||||
{
|
||||
button.SetActive(false);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case bItemType.Builder:
|
||||
submitButtonText.text = "Create";
|
||||
break;
|
||||
|
||||
case bItemType.Consumable:
|
||||
case bItemType.ConsumablesFaith:
|
||||
submitButtonText.text = slot.isChecked ? "Unequip" : "Equip";
|
||||
consumeButton.SetActive(true);
|
||||
consumeButtonText.text = "Consume";
|
||||
break;
|
||||
/*
|
||||
case bItemType.Gemstones:
|
||||
submitButtonText.text = "Switch Weapon";
|
||||
consumeButton.SetActive(true);
|
||||
consumeButtonText.text = "Equip";
|
||||
break;
|
||||
*/
|
||||
case bItemType.Guilts:
|
||||
submitButtonText.text = "Agree";
|
||||
break;
|
||||
|
||||
default:
|
||||
button.SetActive(false);
|
||||
if (consumeButton)
|
||||
{
|
||||
consumeButton.SetActive(false);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case bItemType.PowerScroll:
|
||||
if (!slot.item.canBeDroped) submitButtonText.text = slot.isChecked ? "Unequip" : "Equip";
|
||||
else button.SetActive(false);
|
||||
break;
|
||||
case bItemType.Builder: submitButtonText.text = "Create"; break;
|
||||
case bItemType.Consumable:
|
||||
case bItemType.ConsumablesFaith:
|
||||
submitButtonText.text = slot.isChecked ? "Unequip" : "Equip";
|
||||
if (consumeButton) { consumeButton.SetActive(true); if (consumeButtonText) consumeButtonText.text = "Consume"; }
|
||||
break;
|
||||
case bItemType.Guilts: submitButtonText.text = "Agree"; break;
|
||||
default: submitButtonText.text = slot.isChecked ? "Unequip" : "Equip"; if (consumeButton) consumeButton.SetActive(false); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPowerableSwitchSwordImage(bItem selectedPowerableItem)
|
||||
{
|
||||
Resources.UnloadAsset(powerSwordImage.sprite);
|
||||
|
||||
if (!selectedPowerableItem)
|
||||
{
|
||||
powerSwordImage.enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
powerSwordImage.enabled = true;
|
||||
powerSwordImage.sprite = Resources.Load<Sprite>(selectedPowerableItem.iconPath);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSubmit()
|
||||
{
|
||||
OnSubmit(currentSelectedSlot);
|
||||
}
|
||||
public void OnSubmit() => OnSubmit(currentSelectedSlot);
|
||||
|
||||
public virtual void OnSelect(bItemSlot slot)
|
||||
{
|
||||
if (slot == null || slot.item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSelectedSlot)
|
||||
{
|
||||
currentSelectedSlot.MarkSlotAsDeselected();
|
||||
}
|
||||
if (slot == null || slot.item == null) return;
|
||||
if (currentSelectedSlot) currentSelectedSlot.MarkSlotAsDeselected();
|
||||
currentSelectedSlot = slot;
|
||||
slot.MarkSlotAsSelected();
|
||||
CreateFullItemDescription(slot);
|
||||
@@ -570,144 +426,124 @@ namespace Beyond
|
||||
{
|
||||
if (!slot)
|
||||
{
|
||||
if (displayNameText) displayNameText.text = "";
|
||||
if (displayDescriptionText) displayDescriptionText.text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
var _name = slot.item ? slot.item.name : "";
|
||||
var _rarity = -1;
|
||||
if (ItemIsRarityInterested(slot))
|
||||
{
|
||||
bItemAttribute rarityAttribute = slot.item.GetItemAttribute(bItemAttributes.Rarity);
|
||||
_rarity = rarityAttribute != null ? rarityAttribute.value : 0; // 0 means ordinary, 1 ancient, 2 mystical
|
||||
}
|
||||
var _description = slot.item ? slot.item.description : "";
|
||||
var _image = slot.item ? Resources.Load<Sprite>(slot.item.iconPath) /* slot.item.icon */: defaultSprite;
|
||||
var _secondaryImage = slot.item ? Resources.Load<Sprite>(slot.item.secondaryIconPath) : null;
|
||||
var _teriaryImage = slot.item ? Resources.Load<Sprite>(slot.item.teriaryIconPath) : null;
|
||||
var _type = slot.item ? slot.item.ItemTypeText() : "";
|
||||
var _amount = slot.item ? slot.item.amount.ToString() : "";
|
||||
var _attributes = slot.item ? slot.item.GetItemAttributesText(ignoreAttributes) : "";
|
||||
var _power = slot.item ? slot.item.GetItemAttribute(bItemAttributes.Power) : null;
|
||||
var _Damage = slot.item ? slot.item.GetItemAttribute(bItemAttributes.Damage) : null;
|
||||
|
||||
Sprite _image = defaultSprite;
|
||||
Sprite _secondaryImage = null;
|
||||
Sprite _teriaryImage = null;
|
||||
|
||||
if (slot.item)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(slot.item.iconPath)) _image = Resources.Load<Sprite>(slot.item.iconPath);
|
||||
if (!string.IsNullOrEmpty(slot.item.secondaryIconPath)) _secondaryImage = Resources.Load<Sprite>(slot.item.secondaryIconPath);
|
||||
if (!string.IsNullOrEmpty(slot.item.teriaryIconPath)) _teriaryImage = Resources.Load<Sprite>(slot.item.teriaryIconPath);
|
||||
}
|
||||
|
||||
int _rarity = -1;
|
||||
if (ItemIsRarityInterested(slot))
|
||||
{
|
||||
bItemAttribute rarityAttribute = slot.item.GetItemAttribute(bItemAttributes.Rarity);
|
||||
_rarity = rarityAttribute != null ? rarityAttribute.value : 0;
|
||||
}
|
||||
|
||||
if (displayNameText) displayNameText.text = _name;
|
||||
onChangeName.Invoke(_name);
|
||||
|
||||
if (rarityImage && _rarity >= 0)
|
||||
{
|
||||
rarityImage.gameObject.SetActive(true);
|
||||
rarityImage.sprite = slot.raritySprites[_rarity];
|
||||
}
|
||||
else
|
||||
{
|
||||
rarityImage.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (displayTypeText) displayTypeText.text = _type;
|
||||
onChangeType.Invoke(_type);
|
||||
|
||||
if (displayAmountText) displayAmountText.text = _amount;
|
||||
onChangeAmount.Invoke(_amount);
|
||||
|
||||
if (displayDescriptionText) displayDescriptionText.text = _description;
|
||||
onChangeDescription.Invoke(_description);
|
||||
|
||||
if (displayAttributesText) displayAttributesText.text = _attributes;
|
||||
onChangeAttributes.Invoke(_attributes);
|
||||
|
||||
if (chroniclesTypes.Contains(slot.item.type))
|
||||
if (rarityImage)
|
||||
{
|
||||
displayItemImage.sprite = (Sprite)_secondaryImage;
|
||||
}
|
||||
else if (displayItemImage)
|
||||
{
|
||||
displayItemImage.sprite = (Sprite)_image;
|
||||
if (_rarity >= 0 && slot.raritySprites != null && _rarity < slot.raritySprites.Count)
|
||||
{
|
||||
rarityImage.gameObject.SetActive(true);
|
||||
rarityImage.sprite = slot.raritySprites[_rarity];
|
||||
}
|
||||
else rarityImage.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
bItemAttribute yOffsetAttribute = slot.item.GetItemAttribute(bItemAttributes.ImageYDescOffset);
|
||||
bItemAttribute xOffsetAttribute = slot.item.GetItemAttribute(bItemAttributes.ImageXDescOffset);
|
||||
Vector3 imagePosition = displayItemImage.transform.localPosition;
|
||||
float yOffset = 0;
|
||||
float xOffset = 0;
|
||||
if (yOffsetAttribute != null)
|
||||
if (displayItemImage)
|
||||
{
|
||||
yOffset = yOffsetAttribute.value;
|
||||
if (slot.item != null && chroniclesTypes.Contains(slot.item.type)) displayItemImage.sprite = _secondaryImage;
|
||||
else displayItemImage.sprite = _image;
|
||||
|
||||
if (slot.item != null)
|
||||
{
|
||||
bItemAttribute xOffset = slot.item.GetItemAttribute(bItemAttributes.ImageXDescOffset);
|
||||
bItemAttribute yOffset = slot.item.GetItemAttribute(bItemAttributes.ImageYDescOffset);
|
||||
displayItemImage.transform.localPosition = new Vector3(xOffset != null ? xOffset.value : 0, yOffset != null ? yOffset.value : 0, 0);
|
||||
}
|
||||
}
|
||||
if (xOffsetAttribute != null)
|
||||
{
|
||||
xOffset = xOffsetAttribute.value;
|
||||
}
|
||||
displayItemImage.transform.localPosition = new Vector3(xOffset, yOffset, imagePosition.z);
|
||||
|
||||
if (secondaryItemImage) secondaryItemImage.sprite = _secondaryImage;
|
||||
|
||||
if (teriaryItemImage) teriaryItemImage.sprite = _teriaryImage;
|
||||
|
||||
if (slot.item.type == bItemType.Gemstones)
|
||||
if (changeableAttributesText) changeableAttributesText.gameObject.SetActive(false);
|
||||
if (powerSwordImage) powerSwordImage.gameObject.SetActive(false);
|
||||
|
||||
if (slot.item != null)
|
||||
{
|
||||
if (powerSwordImage && powerSwordImage.sprite)
|
||||
bItemAttribute _power = slot.item.GetItemAttribute(bItemAttributes.Power);
|
||||
bItemAttribute _Damage = slot.item.GetItemAttribute(bItemAttributes.Damage);
|
||||
|
||||
if (slot.item.type == bItemType.Gemstones)
|
||||
{
|
||||
powerSwordImage.gameObject.SetActive(true);
|
||||
if (powerSwordImage && powerSwordImage.sprite) powerSwordImage.gameObject.SetActive(true);
|
||||
if (changeableAttributesText && _power != null)
|
||||
{
|
||||
changeableAttributesText.gameObject.SetActive(true);
|
||||
changeableAttributesText.text = "<color=blue>+" + _power.value.ToString() + " Quantum Charge</color>";
|
||||
}
|
||||
}
|
||||
else //in case we have no valid weapons for gemstone
|
||||
else if (_power != null && changeableAttributesText)
|
||||
{
|
||||
powerSwordImage.gameObject.SetActive(false);
|
||||
}
|
||||
// //for gemstones power value is constant
|
||||
changeableAttributesText.gameObject.SetActive(true);
|
||||
changeableAttributesText.text = "<color=blue>+" + _power.value.ToString() + " Quantum Charge</color>";
|
||||
}
|
||||
else if (_power != null) //powerable weapons
|
||||
{
|
||||
// < color = blue > (+15) </ color > Damage </ color >
|
||||
//< color = purple > 0 < color = blue > (+30) </ color > Spectral Damage </ color ></ align >
|
||||
changeableAttributesText.gameObject.SetActive(true);
|
||||
changeableAttributesText.text = "<color=blue>" + _power.value.ToString() + "/100 Quantum Charge </color>";
|
||||
if (_power.value > 0)
|
||||
{
|
||||
changeableAttributesText.text += "<color=grey>\n" + (_Damage.value * 2).ToString() + " Damage</color>" +
|
||||
"<color=purple>\n" + (_Damage.value * 2).ToString() + " Spectral Damage</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
changeableAttributesText.text += "<color=grey>\n" + (_Damage.value).ToString() + " Damage</color>" +
|
||||
"<color=purple>\n" + "0" + " Spectral Damage</color>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (changeableAttributesText)
|
||||
{
|
||||
changeableAttributesText.gameObject.SetActive(false);
|
||||
}
|
||||
if (powerSwordImage)
|
||||
{
|
||||
powerSwordImage.gameObject.SetActive(false);
|
||||
changeableAttributesText.gameObject.SetActive(true);
|
||||
changeableAttributesText.text = "<color=blue>" + _power.value.ToString() + "/100 Quantum Charge </color>";
|
||||
if (_Damage != null)
|
||||
{
|
||||
if (_power.value > 0)
|
||||
{
|
||||
changeableAttributesText.text += "<color=grey>\n" + (_Damage.value * 2).ToString() + " Damage</color>" +
|
||||
"<color=purple>\n" + (_Damage.value * 2).ToString() + " Spectral Damage</color>";
|
||||
}
|
||||
else
|
||||
{
|
||||
changeableAttributesText.text += "<color=grey>\n" + (_Damage.value).ToString() + " Damage</color>" +
|
||||
"<color=purple>\n" + "0" + " Spectral Damage</color>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptionTransform)
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(descriptionTransform);
|
||||
}
|
||||
if (descriptionTransform) LayoutRebuilder.ForceRebuildLayoutImmediate(descriptionTransform);
|
||||
}
|
||||
|
||||
//need to handle equip
|
||||
|
||||
private static bool ItemIsRarityInterested(bItemSlot slot)
|
||||
{
|
||||
return slot.item && slot.rarityInterestedType.Contains(slot.item.type);
|
||||
}
|
||||
|
||||
private IEnumerator RebuildLayoutCoroutine()
|
||||
private IEnumerator RebuildLayoutCoroutine(RectTransform transform)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(Time.fixedDeltaTime);
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(descriptionTransform);
|
||||
if (transform) LayoutRebuilder.ForceRebuildLayoutImmediate(transform);
|
||||
}
|
||||
|
||||
public virtual void OnCancel()
|
||||
{
|
||||
onCancelSlot.Invoke();
|
||||
}
|
||||
public virtual void OnCancel() => onCancelSlot.Invoke();
|
||||
|
||||
public void BlockAllButGaze(bool b)
|
||||
{
|
||||
@@ -718,17 +554,8 @@ namespace Beyond
|
||||
{
|
||||
foreach (var s in slots)
|
||||
{
|
||||
if (block)
|
||||
{
|
||||
if (s.item.id != exceptionItem)
|
||||
{
|
||||
s.Clickable = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s.Clickable = true;
|
||||
}
|
||||
if (block) { if (s.item.id != exceptionItem) s.Clickable = false; }
|
||||
else s.Clickable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user