void Awake() { _instance = this; animator = GetComponent <Animator>(); gameObject.SetActive(false); foreach (ActionSelectorButton button in buttons) { button.onClick += OnClickAction; } }
private void OnClickSlotRight(int slot, CraftData item) { selected_slot = -1; selected_right_slot = -1; ActionSelectorUI.Get().Hide(); if (item != null && item.GetItem() != null && item.GetItem().actions.Length > 0) { selected_right_slot = slot; ActionSelectorUI.Get().Show(PlayerCharacter.Get(), slots[slot]); } ItemSlot cslot = GetSlot(slot); if (onRightClickSlot != null && cslot != null) { onRightClickSlot.Invoke(cslot); } }
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); } }
private void Awake() { instance = this; }