//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 void CancelSelection() { EquipBar.Get().CancelSelection(); CraftBar.Get().CancelSelection(); InventoryBar.Get().CancelSelection(); PlayerCharacter.Get().CancelConstruction(); }
private void OnUpdate(object obj) { num.text = DataManager.Instance.equipModel._dataList.Count + "/" + DataManager.Instance.roleVo.maxEquipNum; for (int i = 0; i < equipCell.Length; i++) { equipCell[i].Create(null, ChangeSelectCell); for (int j = 0; j < DataManager.Instance.equipModel.nowEquip.Count; j++) { StaticEquipVo staticEquipVo = StaticDataPool.Instance.staticEquipPool.GetStaticDataVo(DataManager.Instance.equipModel.nowEquip[j].equipId); if (staticEquipVo.part == equipCell[i].pos) { equipCell[i].Create(DataManager.Instance.equipModel.nowEquip[j], ChangeSelectCell); } } equipCell[i].ChangeSelect(-1); } int count = 0; Tools.ClearChildFromParent(scrollRect.content); barList.Clear(); for (int i = 0; i < DataManager.Instance.equipModel._dataList.Count; i++) { StaticEquipLevelVo staticEquipLevelVo = StaticDataPool.Instance.staticEquipLevelPool.GetStaticDataVo(DataManager.Instance.equipModel._dataList[i].equipId, DataManager.Instance.equipModel._dataList[i].level); if (nowTab == staticEquipLevelVo.part) { GameObject barObj = Tools.CreateGameObject("UI/EquipPanel/EquipBar", scrollRect.content); EquipBar bar = barObj.GetComponent <EquipBar>(); barList.Add(bar); bar.Create(DataManager.Instance.equipModel._dataList[i], ChangeSelect); count++; } } scrollRect.content.sizeDelta = new Vector2(scrollRect.content.sizeDelta.x, 150 * count); ShowTip(nowVo); }
public int GetEquippedSelectedSlotIndex() { if (EquipBar.Get()) { return(EquipBar.Get().GetSelectedSlotIndex()); } return(-1); }
void Awake() { _instance = this; for (int i = 0; i < slots.Length; i++) { int index = i; //Important to copy so not overwritten in loop slots[i].slot_index = index; slots[i].is_equip = true; slots[i].onClick += (CraftData item) => { OnClickSlot(index, item); }; slots[i].onClickRight += (CraftData item) => { OnClickSlotRight(index, item); }; slots[i].onClickLong += (CraftData item) => { OnClickSlotRight(index, item); }; } }
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; } }
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); } }