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:
2025-12-05 15:10:52 +01:00
parent 53fa05e246
commit af7706bfac
21 changed files with 2352 additions and 3868 deletions

View File

@@ -5032,7 +5032,7 @@ MonoBehaviour:
icon: {fileID: 21300000, guid: 9e637b82da7408b45b28a9180b62ef60, type: 3}
secondaryIcon: {fileID: 0}
teriaryIcon: {fileID: 0}
iconPath:
iconPath: menu_Images/INVENTORY/Resources_17-05-2022/Amethyst
secondaryIconPath:
teriaryIconPath:
stackable: 0
@@ -5232,8 +5232,8 @@ MonoBehaviour:
iconPath:
secondaryIconPath:
teriaryIconPath:
stackable: 0
maxStack: 1
stackable: 1
maxStack: 3
amount: 0
originalObject: {fileID: 0}
dropObject: {fileID: 0}
@@ -5246,7 +5246,7 @@ MonoBehaviour:
checkColor: {r: 0.5372549, g: 0, b: 0, a: 1}
isEquiped: 0
destroyAfterUse: 0
canBeUsed: 1
canBeUsed: 0
canBeDroped: 0
canBeDestroyed: 0
EnableAnim: LowBack

View File

@@ -40,20 +40,24 @@ namespace Beyond
[vHelpBox("You can ignore display Attributes using this property")]
public List<bItemAttributes> ignoreAttributes;
public UnityEngine.Events.UnityEvent onInitPickUpItem, onFinishPickUpItem;
// --- FIX 1: Initialize Events inline to prevent NullReferenceException ---
public UnityEngine.Events.UnityEvent onInitPickUpItem = new UnityEngine.Events.UnityEvent();
public UnityEngine.Events.UnityEvent onFinishPickUpItem = new UnityEngine.Events.UnityEvent();
public InputField.OnChangeEvent onChangeName;
public InputField.OnChangeEvent onChangeType;
public InputField.OnChangeEvent onChangeAmount;
public InputField.OnChangeEvent onChangeDescription;
public InputField.OnChangeEvent onChangeAttributes;
public OnChangeEquipmentEvent onEquipItem;
public OnChangeEquipmentEvent onUnequipItem;
public OnSelectEquipArea onSelectEquipArea;
public OnChangeEquipmentEvent onEquipItem = new OnChangeEquipmentEvent();
public OnChangeEquipmentEvent onUnequipItem = new OnChangeEquipmentEvent();
public OnSelectEquipArea onSelectEquipArea = new OnSelectEquipArea();
// ------------------------------------------------------------------------
public event Action OnItemUsed;
public UnityEngine.UI.Toggle.ToggleEvent onSetLockToEquip;
public UnityEngine.UI.Toggle.ToggleEvent onSetLockToEquip = new UnityEngine.UI.Toggle.ToggleEvent();
[HideInInspector]
public bEquipSlot currentSelectedSlot;
@@ -79,10 +83,7 @@ namespace Beyond
public bool isLockedToEquip
{
get
{
return _isLockedToEquip;
}
get { return _isLockedToEquip; }
set
{
if (_isLockedToEquip != value) onSetLockToEquip.Invoke(value);
@@ -91,10 +92,6 @@ namespace Beyond
}
public bool ignoreEquipEvents;
/// <summary>
/// used to ignore <see cref="onEquipItem"/> event. if true, the inventory will just add the equipment to area but dont will send to Equip the item. you will nedd to call <see cref="EquipCurrentSlot"/> to equip the item in the area.
/// </summary>
internal bool isInit;
public void Init()
@@ -107,17 +104,24 @@ namespace Beyond
if (!isInit)
{
isInit = true;
//indexOfEquipedItem = -1;
inventory = GetComponentInParent<bInventory>();
itemManager = Player.Instance.GetComponent<bItemManager>();
//itemManager.onEquipItem
// Dependencies
if (inventory == null) inventory = GetComponentInParent<bInventory>();
if (inventory == null && Player.Instance != null && Player.Instance.ItemManager != null)
inventory = Player.Instance.ItemManager.inventory;
itemManager = Player.Instance != null ? Player.Instance.GetComponent<bItemManager>() : null;
if (equipSlots.Count == 0)
{
var equipSlotsArray = GetComponentsInChildren<bEquipSlot>(true);
equipSlots = equipSlotsArray.vToList();
}
foreach (bEquipSlot slot in equipSlots)
{
slot.SetInventory(this.inventory); // Explicitly set inventory
slot.onSubmitSlotCallBack = OnSubmitSlot;
slot.onSelectSlotCallBack = OnSelectSlot;
slot.onDeselectSlotCallBack = OnDeselect;
@@ -139,28 +143,17 @@ namespace Beyond
public void SetNewItemWindow(bItemWindow newItemPicker)
{
if (itemPicker)
{
DisableItemWindow();
}
if (itemPicker) DisableItemWindow();
itemPicker = newItemPicker;
EnableItemWindow();
}
public void DisableItemWindow()
{
itemPicker.gameObject.SetActive(false);
}
public void EnableItemWindow()
{
itemPicker.gameObject.SetActive(true);
}
public void DisableItemWindow() => itemPicker.gameObject.SetActive(false);
public void EnableItemWindow() => itemPicker.gameObject.SetActive(true);
public void SetEquipmentwindowWithFilter(List<bItemType> types)
{
itemPicker.CreateEquipmentWindow(inventory.items, types, null, OnPickItem);
//itemPicker.ReloadItems();
}
public void SetEquipmentWindowsUsableWithFilter(List<bItemType> types)
@@ -170,6 +163,7 @@ namespace Beyond
private void SetOccupiedIndexes()
{
usedIndexes.Clear();
for (int i = 0; i < equipSlots.Count; i++)
{
if (equipSlots[i].isOcupad())
@@ -179,155 +173,61 @@ namespace Beyond
public bool IsAnyItemEquipped()
{
for (int i = 0; i < equipSlots.Count; i++)
{
if (equipSlots[i].isOcupad())
{
return true;
}
}
for (int i = 0; i < equipSlots.Count; i++) if (equipSlots[i].isOcupad()) return true;
return false;
}
/// <summary>
/// Current Equipped Slot
/// </summary>
public bEquipSlot currentEquippedSlot
{
get
{
return equipSlots[indexOfEquippedItem];
}
}
public bEquipSlot currentEquippedSlot => equipSlots[indexOfEquippedItem];
/// <summary>
/// Item in Current Equipped Slot
/// </summary>
public bItem currentEquippedItem
{
get
{
var validEquipSlots = ValidSlots;
if (validEquipSlots.Count > 0 && indexOfEquippedItem >= 0 && indexOfEquippedItem < validEquipSlots.Count) return validEquipSlots[indexOfEquippedItem].item;
return null;
}
}
/// <summary>
/// All valid slot <seealso cref="vItemSlot.isValid"/>
/// </summary>
public List<bEquipSlot> ValidSlots
{
get { return equipSlots.FindAll(slot => slot.isValid && (!skipEmptySlots || slot.item != null)); }
}
public List<bEquipSlot> ValidSlots => equipSlots.FindAll(slot => slot.isValid && (!skipEmptySlots || slot.item != null));
/// <summary>
/// Check if Item is in Area
/// </summary>
/// <param name="item">item to check</param>
/// <returns></returns>
public bool ContainsItem(vItem item)
{
return ValidSlots.Find(slot => slot.item == item) != null;
}
public bool ContainsItem(vItem item) => ValidSlots.Find(slot => slot.item == item) != null;
private void UseItemInternal(bItem item)
{
if (item.type == bItemType.Gemstones)
if (item.type == bItemType.Gemstones)
{
if (gemableWeapons.Count < 1 || gemableWeapons[selectedGemableItemIndex] == null)
{
if (bItemCollectionDisplay.Instance && item.type == bItemType.Gemstones && item)
{
Player.Instance.PlayFullyChargedSound();
//in menu
if (PopupMenuController.Instance != null)
{
PopupMenuController.Instance.TryToShowPopupMesssage("No proper weapons available");
} //cant use gemstone with no proper weapons available
return;
}
}
else //if (item.type == bItemType.Gemstones)
else
{
bItemAttribute powerAttribute = gemableWeapons[selectedGemableItemIndex].attributes.First(attribute => attribute.name == bItemAttributes.Power);
if (powerAttribute.value >= powerChargesMaxValue)
{
Player.Instance.PlayFullyChargedSound();
//Player.Instance.MeleeManager.onEquipWeapon
if (PopupMenuController.Instance != null)
{
PopupMenuController.Instance.TryToShowPopupMesssage(gemableWeapons[selectedGemableItemIndex].name + " is already fully charged");
} //cant use gemstone with no proper weapons available
return;
}
powerAttribute.value += item.GetItemAttribute(bItemAttributes.Power).value;
if (powerAttribute.value > powerChargesMaxValue)
{
powerAttribute.value = powerChargesMaxValue;
}
if (powerAttribute.value > powerChargesMaxValue) powerAttribute.value = powerChargesMaxValue;
}
}
inventory.OnUseItem(item);
}
public void UseItem()
{
if (itemManager.UsingItem)
{
return;
}
//could move the logic to item manager
if (itemManager.UsingItem) return;
UseItemInternal(itemPicker.currentSelectedSlot.item);
/*
bItem itemBeingUsed = itemPicker.currentSelectedSlot.item;
//using here
if (itemBeingUsed.type == bItemType.Gemstones)
{
bItem item = itemBeingUsed;
if (gemableWeapons.Count < 1 || gemableWeapons[selectedGemableItemIndex] == null)
{
if (bItemCollectionDisplay.Instance && item.type == bItemType.Gemstones && item)
{
Player.Instance.PlayFullyChargedSound();
//in menu
if (PopupMenuController.Instance != null)
{
PopupMenuController.Instance.TryToShowPopupMesssage("No proper weapons available");
} //cant use gemstone with no proper weapons available
return;
}
}
else if (item.type == bItemType.Gemstones)
{
bItemAttribute powerAttribute = gemableWeapons[selectedGemableItemIndex].attributes.First(attribute => attribute.name == bItemAttributes.Power);
if (powerAttribute.value >= powerChargesMaxValue)
{
Player.Instance.PlayFullyChargedSound();
if (PopupMenuController.Instance != null)
{
PopupMenuController.Instance.TryToShowPopupMesssage(gemableWeapons[selectedGemableItemIndex].name + " is already fully charged");
} //cant use gemstone with no proper weapons available
return;
}
powerAttribute.value += item.GetItemAttribute(bItemAttributes.Power).value;
if (powerAttribute.value > powerChargesMaxValue)
{
powerAttribute.value = powerChargesMaxValue;
}
}
}
inventory.OnUseItem(itemBeingUsed);
*/
}
public void UseItem(bEquipSlot equipSlot)
@@ -335,8 +235,6 @@ namespace Beyond
bItem itemBeingUsed = equipSlot.item;
FindGemableWeapons();
UseItemInternal(itemBeingUsed);
//do some nice things here i think
//inventory.OnUseItem(itemBeingUsed);
}
public void UseEquippedItem()
@@ -344,10 +242,6 @@ namespace Beyond
inventory.OnUseItem(currentEquippedItem);
}
/// <summary>
/// Event called from Inventory slot UI on Submit
/// </summary>
/// <param name="slot"></param>
public void OnSubmitSlot(bItemSlot slot)
{
lastSelectedSlot = currentSelectedSlot;
@@ -366,39 +260,24 @@ namespace Beyond
}
}
/// <summary>
/// Event called to cancel Submit action
/// </summary>
public void CancelCurrentSlot()
{
if (currentSelectedSlot == null)
currentSelectedSlot = lastSelectedSlot;
if (currentSelectedSlot != null)
currentSelectedSlot.OnCancel();
if (currentSelectedSlot == null) currentSelectedSlot = lastSelectedSlot;
if (currentSelectedSlot != null) currentSelectedSlot.OnCancel();
onFinishPickUpItem.Invoke();
}
/// <summary>
/// Unequip Item of the Slot
/// </summary>
/// <param name="slot">target slot</param>
public void UnequipItem(bEquipSlot slot)
{
if (slot)
{
bItem item = slot.item;
if (ValidSlots[indexOfEquippedItem].item == item)
lastEquipedItem = item;
if (ValidSlots[indexOfEquippedItem].item == item) lastEquipedItem = item;
slot.RemoveItem();
onUnequipItem.Invoke(this, item);
}
}
/// <summary>
/// Unequip Item if is present in slots
/// </summary>
/// <param name="item"></param>
public void UnequipItem(bItem item)
{
var slot = ValidSlots.Find(_slot => _slot.item == item);
@@ -410,9 +289,6 @@ namespace Beyond
}
}
/// <summary>
/// Unequip <seealso cref="currentEquippedItem"/>
/// </summary>
public void UnequipCurrentItem()
{
if (currentSelectedSlot && currentSelectedSlot.item)
@@ -424,11 +300,6 @@ namespace Beyond
}
}
/// <summary>
/// Event called from inventory UI when select an slot
/// never fires apparently
/// </summary>
/// <param name="slot">target slot</param>
public void OnSelectSlot(bItemSlot slot)
{
if (equipSlots.Contains(slot as bEquipSlot))
@@ -439,22 +310,12 @@ namespace Beyond
CreateFullItemDescription(slot);
}
/// <summary>
/// Event called from inventory UI when unselect an slot
/// </summary>
/// <param name="slot">target slot</param>
public void OnDeselect(bItemSlot slot)
{
if (equipSlots.Contains(slot as bEquipSlot))
{
currentSelectedSlot = null;
}
}
/// <summary>
/// Create item description
/// </summary>
/// <param name="slot">target slot</param>
protected virtual void CreateFullItemDescription(bItemSlot slot)
{
var _name = slot.item ? slot.item.name : "";
@@ -477,43 +338,28 @@ namespace Beyond
if (displayAttributesText) displayAttributesText.text = _attributes;
onChangeAttributes.Invoke(_attributes);
Debug.LogError("happeingng?");
}
/// <summary>
/// Event called from inventory UI to open <see cref="vItemWindow"/> when submit slot
/// </summary>
/// <param name="slot">target slot</param>
// --- FIX 2: Safer OnPickItem implementation ---
public void OnPickItem(bItemSlot slot)
{
/*
//for gemstones it does something different, it switches internal idnex of currently selected sword
if (usedIndexes.Count == 0) SetOccupiedIndexes();
if (slot.item.type == bItemType.Gemstones)
{
SwitchPowerableWeapon();
return;
}
*/
//1 check if any slot has this item, if it does, unequip it
//2 if not fill the first free slot
//3 if no free slots available swap with the oldest one
if (usedIndexes.Count == 0)
{
SetOccupiedIndexes();
}
//1
// 1. Unequip if checked
if (slot.isChecked)
{
bEquipSlot occupiedSlot = equipSlots.Find(eSlot => eSlot.item == slot.item);
usedIndexes.Remove(equipSlots.IndexOf(occupiedSlot));
occupiedSlot.RemoveItem();
onUnequipItem.Invoke(this, slot.item);
onFinishPickUpItem.Invoke();
if (occupiedSlot != null) // Check if slot was actually found
{
usedIndexes.Remove(equipSlots.IndexOf(occupiedSlot));
occupiedSlot.RemoveItem();
onUnequipItem?.Invoke(this, slot.item); // Safe Invoke
}
onFinishPickUpItem?.Invoke(); // Safe Invoke
return;
}
//2
// 2. Fill first free slot
bEquipSlot freeSlot = equipSlots.Find(eslot => !eslot.isOcupad() && eslot.isValid && eslot.itemType.Contains(slot.item.type));
if (freeSlot)
{
@@ -521,76 +367,55 @@ namespace Beyond
freeSlot.AddItem(slot.item);
if (!ignoreEquipEvents)
{
onEquipItem.Invoke(this, slot.item);
onEquipItem?.Invoke(this, slot.item);
}
onFinishPickUpItem.Invoke();
onFinishPickUpItem?.Invoke();
usedIndexes.Add(equipSlots.IndexOf(freeSlot));
return;
}
//3
//get last used index that is of valid type
bEquipSlot slotToBeTaken = equipSlots[0];
for (int i = 0; i < usedIndexes.Count; i++)
// 3. Swap with oldest (FIFO) if full
if (usedIndexes.Count > 0)
{
int tempIndex = usedIndexes[i];
if (equipSlots[tempIndex].itemType.Contains(slot.item.type))
int slotIndexToTake = -1;
// Iterate through used indexes to find a compatible slot
for (int i = 0; i < usedIndexes.Count; i++)
{
slotToBeTaken = equipSlots[tempIndex];
usedIndexes.RemoveAt(i);
usedIndexes.Add(tempIndex);
i = usedIndexes.Count;
int idx = usedIndexes[i];
if (equipSlots[idx].itemType.Contains(slot.item.type))
{
slotIndexToTake = idx;
usedIndexes.RemoveAt(i);
usedIndexes.Add(idx);
break;
}
}
// If we found a compatible slot to swap
if (slotIndexToTake != -1)
{
bEquipSlot slotToBeTaken = equipSlots[slotIndexToTake];
if (slotToBeTaken.isOcupad())
{
onUnequipItem?.Invoke(this, slotToBeTaken.item);
slotToBeTaken.RemoveItem();
}
onPickUpItemCallBack?.Invoke(this, slot);
slotToBeTaken.AddItem(slot.item);
if (!ignoreEquipEvents)
{
onEquipItem?.Invoke(this, slot.item);
}
}
}
// bEquipSlot slotToBeTaken = equipSlots[usedIndexes[0]];
//remove old 1st
slotToBeTaken.RemoveItem();
onUnequipItem.Invoke(this, slot.item);
onFinishPickUpItem.Invoke();
//add new
onPickUpItemCallBack?.Invoke(this, slot);
slotToBeTaken.AddItem(slot.item);
if (!ignoreEquipEvents)
{
onEquipItem.Invoke(this, slot.item);
}
onFinishPickUpItem.Invoke();
return;
if (!currentSelectedSlot)
{
currentSelectedSlot = lastSelectedSlot;
}
if (!currentSelectedSlot)
{
return;
}
if (currentSelectedSlot.item != null && slot.item != currentSelectedSlot.item)
{
currentSelectedSlot.item.isInEquipArea = false;
var item = currentSelectedSlot.item;
if (item == slot.item) lastEquipedItem = item;
currentSelectedSlot.RemoveItem();
onUnequipItem.Invoke(this, item);
}
if (slot.item != currentSelectedSlot.item)
{
if (onPickUpItemCallBack != null)
onPickUpItemCallBack(this, slot);
currentSelectedSlot.AddItem(slot.item);
if (!ignoreEquipEvents) onEquipItem.Invoke(this, currentSelectedSlot.item);
}
currentSelectedSlot.OnCancel();
currentSelectedSlot = null;
lastSelectedSlot = null;
onFinishPickUpItem.Invoke();
onFinishPickUpItem?.Invoke();
}
// ----------------------------------------------
void FindGemableWeapons()
{
@@ -603,7 +428,6 @@ namespace Beyond
{
if (itemSelected.item.type == bItemType.Gemstones)
{
//for gemstones reset selection of gemable weapon, no saving per gem as of now
FindGemableWeapons();
if (gemableWeapons.Count > 0)
{
@@ -627,12 +451,8 @@ namespace Beyond
}
selectedPowerableItem = gemableWeapons[selectedGemableItemIndex];
itemPicker.SetPowerableSwitchSwordImage(selectedPowerableItem);
//updaing ui
}
/// <summary>
/// Equip next slot <seealso cref="currentEquippedItem"/>
/// </summary>
public void NextEquipSlot()
{
if (equipSlots == null || equipSlots.Count == 0) return;
@@ -645,13 +465,10 @@ namespace Beyond
indexOfEquippedItem = 0;
if (currentEquippedItem != null && !ignoreEquipEvents)
onEquipItem.Invoke(this, currentEquippedItem);
onUnequipItem.Invoke(this, lastEquipedItem);
onEquipItem?.Invoke(this, currentEquippedItem);
onUnequipItem?.Invoke(this, lastEquipedItem);
}
/// <summary>
/// Equip previous slot <seealso cref="currentEquippedItem"/>
/// </summary>
public void PreviousEquipSlot()
{
if (equipSlots == null || equipSlots.Count == 0) return;
@@ -665,15 +482,11 @@ namespace Beyond
indexOfEquippedItem = validEquipSlots.Count - 1;
if (currentEquippedItem != null && !ignoreEquipEvents)
onEquipItem.Invoke(this, currentEquippedItem);
onEquipItem?.Invoke(this, currentEquippedItem);
onUnequipItem.Invoke(this, lastEquipedItem);
onUnequipItem?.Invoke(this, lastEquipedItem);
}
/// <summary>
/// Equip slot <see cref="currentEquippedItem"/>
/// </summary>
/// <param name="indexOfSlot">index of target slot</param>
public void SetEquipSlot(int indexOfSlot)
{
if (equipSlots == null || equipSlots.Count == 0) return;
@@ -683,25 +496,20 @@ namespace Beyond
indexOfEquippedItem = indexOfSlot;
if (currentEquippedItem != null && !ignoreEquipEvents)
{
onEquipItem.Invoke(this, currentEquippedItem);
onEquipItem?.Invoke(this, currentEquippedItem);
}
if (currentEquippedItem != lastEquipedItem)
onUnequipItem.Invoke(this, lastEquipedItem);
onUnequipItem?.Invoke(this, lastEquipedItem);
}
}
public void EquipCurrentSlot()
{
if (!currentEquippedSlot || (currentEquippedSlot.item != null && currentEquippedSlot.item.isEquiped)) return;
if (currentEquippedItem) onEquipItem.Invoke(this, currentEquippedItem);
else if (lastEquipedItem) onUnequipItem.Invoke(this, lastEquipedItem);
if (currentEquippedItem) onEquipItem?.Invoke(this, currentEquippedItem);
else if (lastEquipedItem) onUnequipItem?.Invoke(this, lastEquipedItem);
}
/// <summary>
/// Add an item to an slot
/// </summary>
/// <param name="slot">target Slot</param>
/// <param name="item">target Item</param>
public void AddItemToEquipSlot(bItemSlot slot, bItem item, bool autoEquip = false)
{
if (slot is bEquipSlot && equipSlots.Contains(slot as bEquipSlot))
@@ -710,11 +518,6 @@ namespace Beyond
}
}
/// <summary>
/// Add an item to an slot
/// </summary>
/// <param name="indexOfSlot">index of target Slot</param>
/// <param name="item">target Item</param>
public void AddItemToEquipSlot(int indexOfSlot, bItem item, bool autoEquip = false)
{
if (indexOfSlot < equipSlots.Count && item != null && item.canBeUsed)
@@ -732,7 +535,7 @@ namespace Beyond
{
if (currentEquippedItem == slot.item) lastEquipedItem = slot.item;
slot.item.isInEquipArea = false;
onUnequipItem.Invoke(this, slot.item);
onUnequipItem?.Invoke(this, slot.item);
}
item.checkColor = slot.checkColor;
item.isInEquipArea = true;
@@ -740,15 +543,11 @@ namespace Beyond
if (autoEquip)
SetEquipSlot(indexOfSlot);
else if (!ignoreEquipEvents)
onEquipItem.Invoke(this, item);
onEquipItem?.Invoke(this, item);
}
}
}
/// <summary>
/// Remove item of an slot
/// </summary>
/// <param name="slot">target Slot</param>
public void RemoveItemOfEquipSlot(bItemSlot slot)
{
if (slot is bEquipSlot && equipSlots.Contains(slot as bEquipSlot))
@@ -757,10 +556,6 @@ namespace Beyond
}
}
/// <summary>
/// Remove item of an slot
/// </summary>
/// <param name="slot">index of target Slot</param>
public void RemoveItemOfEquipSlot(int indexOfSlot)
{
if (indexOfSlot < equipSlots.Count)
@@ -772,15 +567,11 @@ namespace Beyond
item.isInEquipArea = false;
if (currentEquippedItem == item) lastEquipedItem = currentEquippedItem;
slot.RemoveItem();
onUnequipItem.Invoke(this, item);
onUnequipItem?.Invoke(this, item);
}
}
}
/// <summary>
/// Add item to current equiped slot
/// </summary>
/// <param name="item">target item</param>
public void AddCurrentItem(bItem item)
{
if (indexOfEquippedItem < equipSlots.Count)
@@ -790,22 +581,19 @@ namespace Beyond
{
if (currentEquippedItem == slot.item) lastEquipedItem = slot.item;
slot.item.isInEquipArea = false;
onUnequipItem.Invoke(this, currentSelectedSlot.item);
onUnequipItem?.Invoke(this, currentSelectedSlot.item);
}
slot.AddItem(item);
if (!ignoreEquipEvents) onEquipItem.Invoke(this, item);
if (!ignoreEquipEvents) onEquipItem?.Invoke(this, item);
}
}
/// <summary>
/// Remove current equiped Item
/// </summary>
public void RemoveCurrentItem()
{
if (!currentEquippedItem) return;
lastEquipedItem = currentEquippedItem;
ValidSlots[indexOfEquippedItem].RemoveItem();
onUnequipItem.Invoke(this, lastEquipedItem);
onUnequipItem?.Invoke(this, lastEquipedItem);
}
}
}

View File

@@ -135,7 +135,7 @@ namespace Beyond
maturity = Player.Instance.GetAttribute("Maturity");
brightness.OnValueChanged.AddListener(PlayBrightnessEffectOnValueChanged);
Player.Instance.onStatsUpdated += SetSlidersScales;
Player.Instance.UodatePlayerStatistics();
Player.Instance.UpdatePlayerStatistics();
// Player.Instance.brig
}
@@ -348,11 +348,12 @@ namespace Beyond
yield return StartCoroutine(FlashBrightnesOnce(finalColorGained, brighntessAnimTime));
}
public void SetSlidersScales(float value)
public void SetSlidersScales(float healthScale, float faithScale, float staminaScale)
{
staminaSlider.SetScale(value);
healthSlider.SetScale(value);
faithSlider.SetScale(value);
// Apply specific scales to specific sliders
staminaSlider.SetScale(staminaScale);
healthSlider.SetScale(healthScale);
faithSlider.SetScale(faithScale);
}
private void SetTextureOffset(Material material, float value)

View File

@@ -60,7 +60,8 @@ namespace Beyond
[Description("Move Speed Bonus")] MoveSpeedBonusPercent = 25,
[Description("Attack Speed Bonus")] AttackSpeedBonusPercent = 26,
[Description("Faith Regen Bonus")] FaithRegenBonusPercent = 27,
[Description("Thorn Damage Bonus")] ThornDamageBonusPercent = 28
[Description("Thorn Damage Bonus")] ThornDamageBonusPercent = 28,
[Description("Stamina Bonus")] StaminaBonusPercent = 29
}
public enum TrinketColor

View File

@@ -1,8 +1,5 @@
using Invector;
using Invector.vCharacterController;
using Invector.vItemManager;
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
@@ -17,33 +14,24 @@ namespace Beyond
[vClassHeader("Item Slot", openClose = false)]
public class bItemSlot : vMonoBehaviour, IPointerClickHandler, ISelectHandler, IDeselectHandler, ISubmitHandler, IPointerEnterHandler, IPointerExitHandler
{
[Header("Dependencies")]
public bInventory inventory;
[vEditorToolbar("Default")]
[SerializeField]
private CanvasGroup m_canvasGroup;
[SerializeField] private CanvasGroup m_canvasGroup;
public bItem item;
public bool isValid = true;
[HideInInspector]
public bool isChecked;
[HideInInspector] public bool isChecked;
public List<bItemType> rarityInterestedType = new List<bItemType> { bItemType.Swords, bItemType.Axes, bItemType.Resources, bItemType.Consumable, bItemType.ConsumablesFaith, bItemType.Gemstones };
public Color checkColor = Color.cyan;
[vEditorToolbar("Optional")]
public Image icon, secondaryIcon, teriaryIcon, rarityImage;
public Image blockIcon;
public Image checkIconBG;
public Image checkIcon;
public Image isSelectedIcon;
public Image blockIcon, checkIconBG, checkIcon, isSelectedIcon;
public TMP_Text displayNameText;
public Text displayTypeText;
public TMP_Text displayAmountText;
public Text displayDescriptionText;
public Text displayAttributesText;
public Text displayDescriptionText, displayAttributesText;
public GameObject notSeenMark;
public bool IsClickable = true;
@@ -53,74 +41,72 @@ namespace Beyond
{
set {
m_isClickable = value;
m_canvasGroup.alpha = m_isClickable ? 1f : 0.5f;
m_canvasGroup.blocksRaycasts = m_isClickable;
if(m_canvasGroup) {
m_canvasGroup.alpha = m_isClickable ? 1f : 0.5f;
m_canvasGroup.blocksRaycasts = m_isClickable;
}
}
get => m_isClickable;
}
[SerializeField]
public List<Sprite> raritySprites;
[SerializeField] public List<Sprite> raritySprites;
[vHelpBox("You can ignore display Attributes using this property")]
public List<bItemAttributes> ignoreAttributes;
[vEditorToolbar("Events")]
public InputField.OnChangeEvent onChangeName;
public InputField.OnChangeEvent onChangeType;
public InputField.OnChangeEvent onChangeAmount;
public InputField.OnChangeEvent onChangeDescription;
public InputField.OnChangeEvent onChangeAttributes;
public InputField.OnChangeEvent onChangeName, onChangeType, onChangeAmount, onChangeDescription, onChangeAttributes;
public List<AttributeDisplay> customAttributeDisplay;
[System.Serializable]
public class AttributeDisplay
{
public Invector.vItemManager.vItemAttributes name;
[Tooltip("Special Tags\n(NAME) = Display name of the Attribute\n(VALUE) = Display the value of the Attribute\n ***Keep Empty to use default attribute display***")]
public string displayFormat = "(VALUE)";
public Text text;
public InputField.OnChangeEvent onChangeDisplay;
}
[vEditorToolbar("Events")]
public ItemSlotEvent onSubmitSlotCallBack, onSelectSlotCallBack, onDeselectSlotCallBack;
public OnHandleItemEvent onAddItem, onRemoveItem;
public UnityEvent onEnable;
public UnityEvent onDisable;
public UnityEvent onClick;
public UnityEvent onEnable, onDisable, onClick;
protected Selectable selectable;
protected Color color = Color.white;
// --- Static Colors (Restored) ---
private static Color deselectedImageColor = new Color(1, 1, 1, 0.7f);
private static Color selectedImageColor = new Color(1, 1, 1, 1);
private static Color selectedTextColor = new Color(0, 0, 0, 1);
private static Color defaultTextColor = new Color(0.3f, 0.3f, 0.3f, 1);
public static Color GetDefaultButtonTextColor()
public static Color GetDefaultButtonTextColor() => defaultTextColor;
public static Color GetSelectedButtonTextColor() => selectedTextColor;
public static Color GetDeselectedImageColor() => deselectedImageColor;
public static Color GetSelectedImageColor() => selectedImageColor;
// --- Explicit Inventory Setter ---
public void SetInventory(bInventory newInventory)
{
return defaultTextColor;
if (this.inventory != null) this.inventory.OnUpdateInventory -= UpdateDisplays;
this.inventory = newInventory;
if (this.inventory != null) this.inventory.OnUpdateInventory += UpdateDisplays;
UpdateDisplays();
}
public static Color GetSelectedButtonTextColor()
protected virtual void Start()
{
return selectedTextColor;
}
if (inventory == null)
{
var equipArea = GetComponentInParent<bEquipArea>();
if (equipArea != null) inventory = equipArea.inventory;
if (inventory == null && Player.Instance != null && Player.Instance.ItemManager != null)
inventory = Player.Instance.ItemManager.inventory;
}
public static Color GetDeselectedImageColor()
{
return deselectedImageColor;
}
if (inventory) inventory.OnUpdateInventory += UpdateDisplays;
public static Color GetSelectedImageColor()
{
return selectedImageColor;
selectable = GetComponent<Selectable>();
if (!m_canvasGroup) m_canvasGroup = GetComponent<CanvasGroup>();
SetValid(isValid);
}
private void OnEnable()
@@ -132,77 +118,28 @@ namespace Beyond
private void OnDisable()
{
onDisable.Invoke();
UnloadCurrentImage();
//unload
}
private void UnloadCurrentImage()
{
if (icon)
{
Resources.UnloadAsset(icon.sprite);
}
if (secondaryIcon)
{
Resources.UnloadAsset(secondaryIcon.sprite);
}
if (teriaryIcon)
{
Resources.UnloadAsset(teriaryIcon.sprite);
}
// icon.sprite = null;
// secondaryIcon.sprite = null;
// teriaryIcon.sprite = null;
//Resources.UnloadUnusedAssets();
if (icon && icon.sprite) Resources.UnloadAsset(icon.sprite);
if (secondaryIcon && secondaryIcon.sprite) Resources.UnloadAsset(secondaryIcon.sprite);
if (teriaryIcon && teriaryIcon.sprite) Resources.UnloadAsset(teriaryIcon.sprite);
}
protected virtual void Start()
{
var inventory = GetComponentInParent<bInventory>();
if (inventory)
inventory.OnUpdateInventory += UpdateDisplays;
selectable = GetComponent<Selectable>();
if (!m_canvasGroup)
m_canvasGroup = GetComponent<CanvasGroup>();
SetValid(isValid);
}
/// <summary>
/// Update all slot display texts
/// </summary>
public virtual void UpdateDisplays()
{
UpdateDisplays(item);
}
public virtual void UpdateDisplays() => UpdateDisplays(item);
private void OnDestroy()
{
var inventory = GetComponentInParent<bInventory>();
if (inventory)
inventory.OnUpdateInventory -= UpdateDisplays;
if (inventory) inventory.OnUpdateInventory -= UpdateDisplays;
}
/// <summary>
/// Enable or disable checkIcon
/// </summary>
/// <param name="value">Enable or disable value</param>
// ... Existing Methods ...
public virtual void CheckItem(bool value)
{
/*
if (item && item.type == bItemType.Gemstones && checkIcon)
{
//checkIconBG.gameObject.SetActive(false);
// checkIcon.gameObject.SetActive(false);
return;
}
*/
if (item && item.type == bItemType.PowerScroll && item.canBeDroped) //there are power scrolls which are not equippable
{
isChecked = true;
}
if (item && item.type == bItemType.PowerScroll && item.canBeDroped) isChecked = true;
else if (checkIcon && item)
{
isChecked = value;
@@ -213,40 +150,25 @@ namespace Beyond
public void TryToMarkAsSpeciallEquipped()
{
if (!checkIcon)
{
return;
}
checkIcon.gameObject.SetActive(true);
checkIcon.color = Color.gray;
if (checkIcon) { checkIcon.gameObject.SetActive(true); checkIcon.color = Color.gray; }
}
/// <summary>
/// Set if the slot is Selectable or not
/// </summary>
/// <param name="value">Enable or disable value</param>
public virtual void SetValid(bool value)
{
isValid = value;
if (selectable) selectable.interactable = value;
if (blockIcon == null) return;
blockIcon.color = value ? Color.clear : Color.white;
blockIcon.SetAllDirty();
isValid = value;
if (blockIcon) { blockIcon.color = value ? Color.clear : Color.white; blockIcon.SetAllDirty(); }
}
/// <summary>
/// Add item to slot
/// </summary>
/// <param name="item">target item</param>
public virtual void AddItem(bItem item)
{
if (item != null)
{
this.item = item;
onAddItem.Invoke(item);
// UpdateDisplays(item);
// --- FIX: Force display update immediately ---
UpdateDisplays(item);
// ---------------------------------------------
}
else RemoveItem();
}
@@ -262,26 +184,12 @@ namespace Beyond
ChangeDisplayAttributes(item);
CheckItem(item != null && item.isInEquipArea);
TryToSetRarityIcon(item);
if (item)
{
SetNotSeenIcon(item.id);
}
if (item) SetNotSeenIcon(item.id);
}
private void SetNotSeenIcon(int itemId)
{
if (notSeenMark == null)
{
return;
}
if (NewItemPopupSaver.itemsSeen.Contains(itemId))
{
notSeenMark.SetActive(false);
}
else
{
notSeenMark.SetActive(true);
}
if (notSeenMark) notSeenMark.SetActive(!NewItemPopupSaver.itemsSeen.Contains(itemId));
}
private void TryToSetRarityIcon(bItem item)
@@ -290,314 +198,127 @@ namespace Beyond
{
rarityImage.gameObject.SetActive(true);
bItemAttribute rarityAttribute = item.GetItemAttribute(bItemAttributes.Rarity);
if (rarityAttribute != null)
{
rarityImage.sprite = raritySprites[rarityAttribute.value];
}
else
{
rarityImage.sprite = raritySprites[0];
}
rarityImage.sprite = (rarityAttribute != null && rarityAttribute.value < raritySprites.Count) ? raritySprites[rarityAttribute.value] : raritySprites[0];
}
}
/// <summary>
/// Update the Display type text
/// </summary>
/// <param name="item">target item</param>
protected virtual void ChangeDisplayType(bItem item)
{
if (item)
{
onChangeType.Invoke(item.ItemTypeText());
if (displayTypeText) displayTypeText.text = item.ItemTypeText();
}
else
{
onChangeType.Invoke("");
if (displayTypeText) displayTypeText.text = "";
}
string txt = item ? item.ItemTypeText() : "";
onChangeType.Invoke(txt);
if (displayTypeText) displayTypeText.text = txt;
}
/// <summary>
/// Update the Display attribute text
/// </summary>
/// <param name="item"></param>
protected virtual void ChangeDisplayAttributes(bItem item)
{
if (item)
{
if (displayAttributesText) displayAttributesText.text = item.GetItemAttributesText(ignoreAttributes);
onChangeAttributes.Invoke(item.GetItemAttributesText(ignoreAttributes));
for (int i = 0; i < item.attributes.Count; i++)
{
AttributeDisplay attributeDisplay = customAttributeDisplay.Find(att => att.name.Equals(item.attributes[i].name));
if (attributeDisplay != null)
{
string displayText = item.attributes[i].GetDisplayText();
if (attributeDisplay.text) attributeDisplay.text.text = displayText;
attributeDisplay.onChangeDisplay.Invoke(displayText);
string txt = item ? item.GetItemAttributesText(ignoreAttributes) : "";
if (displayAttributesText) displayAttributesText.text = txt;
onChangeAttributes.Invoke(txt);
if(item && customAttributeDisplay != null) {
foreach(var attr in item.attributes) {
var display = customAttributeDisplay.Find(a => a.name.Equals(attr.name));
if(display != null) {
string val = attr.GetDisplayText();
if(display.text) display.text.text = val;
display.onChangeDisplay.Invoke(val);
}
}
}
else
{
if (displayAttributesText) displayAttributesText.text = "";
onChangeAttributes.Invoke("");
for (int i = 0; i < customAttributeDisplay.Count; i++)
{
if (customAttributeDisplay[i].text) customAttributeDisplay[i].text.text = "";
customAttributeDisplay[i].onChangeDisplay.Invoke("");
}
}
}
/// <summary>
/// Update the Display item Icon image
/// </summary>
/// <param name="item"></param>
protected virtual void ChangeDisplayIcon(bItem item)
{
if (!item) return;
if (icon)
{
icon.sprite = Resources.Load<Sprite>(item.iconPath);
// color.a = 1;
// icon.color = color;
}
if (!item || !icon) return;
if (item.icon != null) icon.sprite = item.icon;
else if (!string.IsNullOrEmpty(item.iconPath)) icon.sprite = Resources.Load<Sprite>(item.iconPath);
}
public void ChangeAdditionalDisplayIcons(bItem item)
{
if (!item) return;
if (secondaryIcon && item.secondaryIconPath.Length > 1)
{
secondaryIcon.sprite = Resources.Load<Sprite>(item.secondaryIconPath);
}
if (teriaryIcon && item.teriaryIconPath.Length > 1)
{
teriaryIcon.sprite = Resources.Load<Sprite>(item.teriaryIconPath);
}
if (secondaryIcon && item.secondaryIconPath.Length > 1) secondaryIcon.sprite = Resources.Load<Sprite>(item.secondaryIconPath);
if (teriaryIcon && item.teriaryIconPath.Length > 1) teriaryIcon.sprite = Resources.Load<Sprite>(item.teriaryIconPath);
}
/// <summary>
/// Update the Display Description text
/// </summary>
/// <param name="item"></param>
protected virtual void ChangeDisplayDescription(bItem item)
{
if (item)
{
onChangeDescription.Invoke(item.description);
if (displayDescriptionText) displayDescriptionText.text = item.description;
}
else
{
onChangeDescription.Invoke("");
if (displayDescriptionText) displayDescriptionText.text = "";
}
string txt = item ? item.description : "";
onChangeDescription.Invoke(txt);
if (displayDescriptionText) displayDescriptionText.text = txt;
}
/// <summary>
/// Update the Display Amount text
/// </summary>
/// <param name="item"></param>
protected virtual void ChangeDisplayAmount(bItem item)
{
string amountText = "";
if (item != null && this.gameObject.activeSelf)
{
if (item.stackable && item.amount > 1)
amountText = " " + item.amount.ToString();
else
amountText = "";
}
else if (item == null) amountText = "";
if (displayAmountText) displayNameText.text += amountText;
onChangeAmount.Invoke(amountText);
string txt = (item != null && item.stackable && item.amount > 1) ? " " + item.amount.ToString() : "";
if (displayAmountText) displayAmountText.text = txt;
onChangeAmount.Invoke(txt);
}
/// <summary>
/// Update the Display item Name text
/// </summary>
/// <param name="item"></param>
protected virtual void ChangeDisplayName(bItem item)
{
if (item)
{
onChangeName.Invoke(item.name);
if (displayNameText)
{
displayNameText.text = item.name;
}
}
else
{
onChangeName.Invoke("");
if (displayNameText) displayNameText.text = "";
}
string txt = item ? item.name : "";
onChangeName.Invoke(txt);
if (displayNameText) displayNameText.text = txt;
}
/// <summary>
/// Remove current item from the slot
/// </summary>
public virtual void RemoveItem()
{
this.item = null;
onRemoveItem.Invoke(item);
if (icon)
{
// color.a = 0;
//icon.color = color;
icon.sprite = null;
icon.SetAllDirty();
}
if (icon) { icon.sprite = null; icon.SetAllDirty(); }
UpdateDisplays(null);
}
/// <summary>
/// Check if slot has an item
/// </summary>
/// <returns></returns>
public virtual bool isOcupad()
{
return item != null;
}
public virtual bool isOcupad() => item != null;
#region UnityEngine.EventSystems Implementation
public virtual void OnSelect(BaseEventData eventData)
{
// isSelectedIcon.enabled = true;
if (onSelectSlotCallBack != null)
onSelectSlotCallBack(this);
}
public virtual void OnSelect(BaseEventData eventData) => onSelectSlotCallBack?.Invoke(this);
public virtual void OnDeselect(BaseEventData eventData) => onDeselectSlotCallBack?.Invoke(this);
public void MarkSlotAsSelected()
{
displayNameText.color = GetSelectedButtonTextColor();
if (!NewItemPopupSaver.itemsSeen.Contains(item.id))
{
NewItemPopupSaver.itemsSeen.Add(item.id);
SetNotSeenIcon(item.id);
}
if (isSelectedIcon)
{
isSelectedIcon.enabled = true;
}
else
{
icon.color = GetSelectedImageColor();
if (secondaryIcon)
{
secondaryIcon.color = icon.color;
}
if (teriaryIcon)
{
teriaryIcon.color = icon.color;
}
if (rarityImage)
{
rarityImage.color = icon.color;
}
}
if (displayNameText) displayNameText.color = GetSelectedButtonTextColor();
if (item && !NewItemPopupSaver.itemsSeen.Contains(item.id)) { NewItemPopupSaver.itemsSeen.Add(item.id); SetNotSeenIcon(item.id); }
if (isSelectedIcon) isSelectedIcon.enabled = true;
else SetIconColor(GetSelectedImageColor());
}
public void MarkSlotAsDeselected()
{
displayNameText.color = GetDefaultButtonTextColor();
if (isSelectedIcon)
{
isSelectedIcon.enabled = false;
}
else
{
icon.color = GetDeselectedImageColor();
if (secondaryIcon)
{
secondaryIcon.color = icon.color;
}
if (teriaryIcon)
{
teriaryIcon.color = icon.color;
}
if (rarityImage)
{
rarityImage.color = icon.color;
}
}
if (displayNameText) displayNameText.color = GetDefaultButtonTextColor();
if (isSelectedIcon) isSelectedIcon.enabled = false;
else SetIconColor(GetDeselectedImageColor());
}
public virtual void OnDeselect(BaseEventData eventData)
private void SetIconColor(Color c)
{
// isSelectedIcon.enabled = false;
if (onDeselectSlotCallBack != null)
onDeselectSlotCallBack(this);
if (icon) icon.color = c;
if (secondaryIcon) secondaryIcon.color = c;
if (teriaryIcon) teriaryIcon.color = c;
if (rarityImage) rarityImage.color = c;
}
public virtual void OnSubmit(BaseEventData eventData)
{
if (isValid)
{
onClick.Invoke();
if (onSubmitSlotCallBack != null)
onSubmitSlotCallBack(this);
}
if (isValid) { onClick.Invoke(); onSubmitSlotCallBack?.Invoke(this); }
CheckItem(item != null && item.isInEquipArea);
}
public virtual void OnPointerEnter(PointerEventData eventData)
{
//if(vInput.instance.inputDevice == InputDevice.MouseKeyboard)
{
EventSystem.current.SetSelectedGameObject(this.gameObject);
if (onSelectSlotCallBack != null)
onSelectSlotCallBack(this);
}
///DEBUG
if (IsClickable != Clickable)
{
Clickable = IsClickable;
}
EventSystem.current.SetSelectedGameObject(gameObject);
onSelectSlotCallBack?.Invoke(this);
if (IsClickable != Clickable) Clickable = IsClickable;
}
public virtual void OnPointerExit(PointerEventData eventData)
{
//if (vInput.instance.inputDevice == InputDevice.MouseKeyboard)
{
if (onDeselectSlotCallBack != null)
onDeselectSlotCallBack(this);
}
}
public virtual void OnPointerExit(PointerEventData eventData) => onDeselectSlotCallBack?.Invoke(this);
public virtual void OnPointerClick(PointerEventData eventData)
{
return;
#if UNITY_ANDROID || UNITY_IOS
if (vInput.instance.inputDevice == InputDevice.Mobile)
#else
//if (vInput.instance.inputDevice == InputDevice.MouseKeyboard)
#endif
if (eventData.button == PointerEventData.InputButton.Left && isValid)
{
if (eventData.button == PointerEventData.InputButton.Left)
{
if (isValid)
{
onClick.Invoke();
if (onSubmitSlotCallBack != null)
onSubmitSlotCallBack(this);
}
}
onClick.Invoke();
onSubmitSlotCallBack?.Invoke(this);
}
}
#endregion UnityEngine.EventSystems Implementation
}
}

View File

@@ -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;
}
}
}

View File

@@ -48,17 +48,15 @@ namespace Beyond
{
if (m != this)
{
Members = new List<vBodyMember>();
for (int i = 0; i < m.Members.Count; i++)
{
Members.Add(m.Members[i]);
}
this.hitProperties = m.hitProperties;
this.defaultDamage = m.defaultDamage;
this.defaultDefenseRate = m.defaultDefenseRate;
this.defaultAttackDistance = m.defaultAttackDistance;
this.defaultStaminaCost = m.defaultStaminaCost;
// This copies EVERY Serialized field from 'm' to 'this'
// It works perfectly because bMeleeManager inherits vMeleeManager
JsonUtility.FromJsonOverwrite(JsonUtility.ToJson(m), this);
// Re-run init to apply the copied data
this.Init();
// Stop after finding the first match so we don't copy ourselves if checking later
break;
}
}
}