KrejwenBAN
Member
Hi,
I am not quite sure if it is a bug or using remove item over expected "boundaries"
I added an item remove operation with confirmation pop box in shop menu. When player click right mouse button on item in shop menu I show a confirmation pop window. When player confirmed the operation the item is remove. However, If I remove this item and mouse is over an empty item view slot then I get the following warning: "Cannot get the price of a NULL item" from method
The source of the problem is in method:
in line
ItemInfo is set to None.
What should I do to not destroy the flow of the code?
Regards
I am not quite sure if it is a bug or using remove item over expected "boundaries"
I added an item remove operation with confirmation pop box in shop menu. When player click right mouse button on item in shop menu I show a confirmation pop window. When player confirmed the operation the item is remove. However, If I remove this item and mouse is over an empty item view slot then I get the following warning: "Cannot get the price of a NULL item" from method
C#:
protected CurrencyCollection GetPrice(ItemInfo itemInfo)
{
if (itemInfo.Item == null) {
Debug.LogWarning("Cannot get the price of a NULL item");
return null;
}
var shop = (Shop)m_Shop;
if (m_IsBuying) {
if (shop.TryGetBuyValueForBuyer(m_Inventory, itemInfo, ref m_TempCurrencyCollection)) {
return m_TempCurrencyCollection;
}
} else {
if (shop.TryGetSellValueForSeller(m_Inventory, itemInfo, ref m_TempCurrencyCollection)) {
return m_TempCurrencyCollection;
}
}
var buySell = m_IsBuying ? "Buy" : "Sell";
Debug.LogWarning($"Was unable to find the {buySell} price for item: " + itemInfo);
return null;
}
The source of the problem is in method:
C#:
protected virtual void OnItemSelected(ItemViewSlotEventData slotEventData)
{
if (m_ShopperClientCurrencyOwner == null || m_Inventory == null) {
Debug.LogError("The client inventory is either null or it does not have a currencyOwner.", gameObject);
return;
}
var itemInfo = slotEventData.ItemViewSlot.ItemInfo;
if (m_QuantityPickerPanel.IsOpen == false) { return; }
if (m_SelectedItemInfo.Item == itemInfo.Item) { return; }
m_SelectedItemInfo = itemInfo;
m_QuantityPickerPanel.SetPreviousSelectable(slotEventData.ItemViewSlot);
m_QuantityPickerPanel.QuantityPicker.MinQuantity = 1;
if (m_IsBuying) {
var price = GetPrice((1, itemInfo));
var quotient = m_ShopperClientCurrencyOwner.PotentialQuotientFor(price);
var max = Mathf.Max(quotient, 1);
if (m_LimitBuyQuantityToAvailableItemAmount) {
max = Mathf.Min(max, itemInfo.Amount);
}
m_QuantityPickerPanel.QuantityPicker.MaxQuantity = max;
m_QuantityPickerPanel.ConfirmCancelPanel.EnableConfirm(quotient > 0);
} else {
m_QuantityPickerPanel.QuantityPicker.MaxQuantity = itemInfo.Amount;
}
m_QuantityPickerPanel.QuantityPicker.SetQuantity(1);
var quantity = m_QuantityPickerPanel.QuantityPicker.Quantity;
DrawPriceTo((quantity, m_SelectedItemInfo), m_TotalPrice);
}
in line
C#:
var itemInfo = slotEventData.ItemViewSlot.ItemInfo;
What should I do to not destroy the flow of the code?
Regards