Example #1
0
 protected override bool OnClose(params object[] args)
 {
     if (!IsOpen)
     {
         return(true);
     }
     foreach (var kvp in copySlots)
     {
         caches.Put(kvp.Value);
     }
     copySlots.Clear();
     selectedItems.Clear();
     SourceContainer.DarkIf(null);
     SourceContainer.MarkIf(null);
     SourceContainer = null;
     SourceHandler   = null;
     ZetanUtility.SetActive(tips, true);
     dialog        = string.Empty;
     SelectionType = ItemSelectionType.SelectNum;
     canSelect     = null;
     onConfirm     = null;
     if (!confirm)
     {
         onCancel?.Invoke();
     }
     onCancel = null;
     WindowsManager.CloseWindow <ItemWindow>();
     return(true);
 }
Example #2
0
 public void Clear()
 {
     foreach (var kvp in copySlots)
     {
         caches.Put(kvp.Value);
     }
     if (SourceContainer != null)
     {
         SourceContainer.MarkIf(null);
     }
     copySlots.Clear();
     selectedItems.Clear();
     ZetanUtility.SetActive(tips, true);
     WindowsManager.CloseWindow <ItemWindow>();
 }
Example #3
0
    private void TakeOut(ItemSlot copy, bool all = false)
    {
        if (!copy.IsEmpty)
        {
            if (all || copy.Data.amount < 2)
            {
                RemoveSlot(copy);
            }
            else
            {
                AmountWindow.StartInput((amount) =>
                {
                    if (copy.Data.amount < amount)
                    {
                        MessageManager.Instance.New("物品数量已改变,请重试");
                    }
                    else
                    {
                        copy.Data.amount -= (int)amount;
                        if (copy.Data.amount < 1)
                        {
                            RemoveSlot(copy);
                        }
                        else
                        {
                            copy.Refresh();
                        }
                    }
                }, copy.Data.amount, "取出数量");
            }
        }

        void RemoveSlot(ItemSlot copy)
        {
            copySlots.Remove(copy.Item.ID);
            caches.Put(copy);
            selectedItems.Remove(copy.Item);
            SourceContainer.MarkIf(s => selectedItems.Contains(s.Item));
            if (copySlots.Count < 1)
            {
                ZetanUtility.SetActive(tips, true);
            }
        }
    }
Example #4
0
    public void Place(ItemSlot source)
    {
        if (!source || source.IsEmpty || source.Data.IsEmpty)
        {
            return;
        }
        var slot = source.Data;
        int have = SourceHandler.GetAmount(slot.item);

        if (slot == null || slot.Model == null || have < 0)
        {
            return;
        }
        if (slot.Model.StackAble && SelectionType == ItemSelectionType.SelectNum)
        {
            if (!canSelect(source))
            {
                return;
            }
            if (typeLimit > 0 && copySlots.Count >= typeLimit)
            {
                MessageManager.Instance.New($"每次最多只能选择{typeLimit}样物品");
                return;
            }
            if (have < 2)
            {
                if (SourceHandler.CanLose(slot.item, 1))
                {
                    MakeSlot(slot.item, 1);
                }
            }
            else if (amountLimit == 1)
            {
                if (SourceHandler.CanLose(slot.item, 1))
                {
                    MakeSlot(slot.item, 1);
                }
            }
            else
            {
                AmountWindow.StartInput(delegate(long amount)
                {
                    if (SourceHandler.CanLose(slot.item, (int)amount))
                    {
                        if (copySlots.TryGetValue(slot.item.ID, out var copy))
                        {
                            copy.Data.amount = (int)amount;
                            copy.Refresh();
                        }
                        else
                        {
                            MakeSlot(slot.item, (int)amount);
                        }
                        if (copySlots.Count > 0)
                        {
                            ZetanUtility.SetActive(tips, false);
                        }
                    }
                }, amountLimit > 0 ? amountLimit : have);
            }
        }
        else if ((!slot.Model.StackAble && SelectionType == ItemSelectionType.SelectNum || SelectionType == ItemSelectionType.SelectAll) &&
                 canSelect(source) && SourceHandler.CanLose(slot.item, have))
        {
            if (copySlots.ContainsKey(slot.item.ID))
            {
                MessageManager.Instance.New("已选择该物品");
                return;
            }
            if (typeLimit > 0 && copySlots.Count >= typeLimit)
            {
                MessageManager.Instance.New($"每次最多只能选择{typeLimit}样物品");
            }
            else
            {
                MakeSlot(slot.item, have);
            }
        }

        void MakeSlot(ItemData data, int amount)
        {
            ItemSlot copy = caches.Get(itemCellsParent);

            copy.SetScrollRect(gridScrollRect);
            copy.SetCallbacks(GetHandleButtons, (s) => TakeOut(s, true), OnSlotEndDrag);
            copySlots.Add(data.ID, copy);
            selectedItems.Add(data);
            copy.Refresh(new ItemSlotData(data, amount));
            SourceContainer.MarkIf(s => selectedItems.Contains(s.Item));
            if (copySlots.Count > 0)
            {
                ZetanUtility.SetActive(tips, false);
            }
        }
    }