예제 #1
0
    public void UpdateUI()
    {
        foreach (InventorySlot ins in slots)
        {
            if (ins.GetQuantity() > 0)
            {
                if (ins.Equals(main_slot.item_reference))
                {
                    ins.DecreaseQuantity();
                    if (ins.GetQuantity() == 0)
                    {
                        ins.Clear();
                    }
                    break;
                }
            }
        }

        if (main_slot.GetQuantity() == 0 || main_slot.IsEmpty())
        {
            main_slot.Clear();
            int i;
            for (i = 0; i < 3; i++)
            {
                if (slots[i].GetQuantity() == 0)
                {
                    if (slots[i + 1].GetQuantity() > 0)
                    {
                        slots[i].Fill(slots[i + 1].item_reference);
                        slots[i + 1].Clear();
                        slots[i].SetSelected(true);
                    }
                    else if (i != 0 && slots[i - 1].GetQuantity() > 0)
                    {
                        slots[i - 1].SetSelected(true);
                        slots[i - 1].Fill(slots[i].item_reference);
                        slots[i].Clear();
                        slots[i].SetSelected(false);
                    }
                }
            }

            main_slot.Fill(System.Array.Find(slots, slot => slot.isSelected()).item_reference);
        }

        if (slots[0].GetQuantity() <= 0)
        {
            slots[0].SetSelected(false);
            main_slot.Clear();
        }

        foreach (InventorySlot s in slots)
        {
            if (s.GetQuantity() == 0 || s.IsEmpty())
            {
                s.Clear();
                s.SetSelected(false);
            }
        }
    }