示例#1
0
 public void CancelSelection()
 {
     EquipBar.Get().CancelSelection();
     CraftBar.Get().CancelSelection();
     InventoryBar.Get().CancelSelection();
     PlayerCharacter.Get().CancelConstruction();
 }
示例#2
0
    //When the character interact with this selectable, check all the actions and see if any should be triggered.
    public void Use(PlayerCharacter character)
    {
        if (enabled)
        {
            ItemSlot islot   = InventoryBar.Get().GetSelectedSlot();
            ItemSlot eslot   = EquipBar.Get().GetSelectedSlot();
            ItemSlot slot    = eslot != null ? eslot : islot;
            MAction  maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(this) : null;

            AAction aaction = FindAutoAction();
            if (maction != null && maction.CanDoAction(character, this))
            {
                maction.DoAction(character, slot, this);
                TheUI.Get().CancelSelection();
            }
            else if (aaction != null && aaction.CanDoAction(character, this))
            {
                aaction.DoAction(character, this);
            }
            else if (actions.Length > 0)
            {
                ActionSelector.Get().Show(character, this);
            }

            if (onUse != null)
            {
                onUse.Invoke(character);
            }
        }
    }
 public int GetEquippedSelectedSlotIndex()
 {
     if (EquipBar.Get())
     {
         return(EquipBar.Get().GetSelectedSlotIndex());
     }
     return(-1);
 }
示例#4
0
    void Update()
    {
        transform.position = PlayerControlsMouse.Get().GetPointingPos();
        transform.rotation = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up);

        ItemSlot   islot   = InventoryBar.Get().GetSelectedSlot();
        ItemSlot   eslot   = EquipBar.Get().GetSelectedSlot();
        ItemSlot   slot    = eslot != null ? eslot : islot;
        Selectable select  = Selectable.GetNearestHover(transform.position);
        MAction    maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(select) : null;

        title.enabled = maction != null;
        title.text    = maction != null ? maction.title : "";

        if ((slot != null) != icon_group.activeSelf)
        {
            icon_group.SetActive(slot != null);
        }

        if (slot != null && slot.GetItem())
        {
            icon.sprite = slot.GetItem().icon;
        }
    }
示例#5
0
    private void OnClickSlot(int slot, CraftData item)
    {
        ActionSelectorUI.Get().Hide();
        selected_right_slot = -1;

        ItemSlot cslot = GetSlot(slot);
        ItemSlot eslot = EquipBar.Get().GetSelectedSlot();
        ItemSlot sslot = eslot != null ? eslot : GetSelectedSlot();

        //Merge items
        if (sslot != null && cslot != null)
        {
            ItemSlot slot1   = cslot;
            ItemSlot slot2   = sslot;
            ItemData item1   = slot1.GetItem();
            ItemData item2   = slot2.GetItem();
            MAction  action1 = item1 != null?item1.FindMergeAction(item2) : null;

            MAction action2 = item2 != null?item2.FindMergeAction(item1) : null;

            if (item1 != null && item2 != null)
            {
                //Same item, combine stacks
                if (item1 == item2)
                {
                    if (slot1.GetQuantity() + slot2.GetQuantity() <= item1.inventory_max)
                    {
                        int quantity = slot2.GetQuantity();
                        PlayerData.Get().RemoveItemAt(slot2.slot_index, quantity);
                        PlayerData.Get().AddItemAt(item1.id, slot1.slot_index, quantity);
                        CancelSelection();
                        return;
                    }
                }
                //Else, use merge action
                else if (action1 != null && action1.CanDoAction(PlayerCharacter.Get(), slot2))
                {
                    action1.DoAction(PlayerCharacter.Get(), slot1, slot2);
                    CancelSelection();
                    return;
                }

                else if (action2 != null && action2.CanDoAction(PlayerCharacter.Get(), slot1))
                {
                    action2.DoAction(PlayerCharacter.Get(), slot2, slot1);
                    CancelSelection();
                    return;
                }
            }
        }

        //Swap equipped with item
        if (eslot != null)
        {
            PlayerData.Get().UnequipItemTo(eslot.slot_index, slot);
            TheUI.Get().CancelSelection();
        }
        //Swap two items
        else if (HasSlotSelected())
        {
            if (slot != selected_slot)
            {
                PlayerData.Get().SwapItemSlots(slot, selected_slot);
            }

            CancelSelection();
        }
        else
        {
            if (item != null)
            {
                TheUI.Get().CancelSelection();
                selected_slot = slot;
            }
        }

        if (onClickSlot != null && cslot != null)
        {
            onClickSlot.Invoke(cslot);
        }
    }