void HandleUIState(InputUI inputHandler) { switch (currentState) { case UIState.equipment: if (!isSwitching) { HandleSlotMovement(inputHandler); } else { HandleInventoryMovement(inputHandler); } HandleSlotInput(inputHandler); break; case UIState.inventory: HandleInventoryMovement(inputHandler); break; case UIState.attributes: break; case UIState.messages: break; case UIState.options: break; default: break; } }
private void Awake() { Instance = this; }
public void Init(InventoryManager inventoryManager) { invManager = inventoryManager; inputUI = InputUI.Instance; }
void HandleInventoryMovement(InputUI inputHandler) { bool up = (inputUI.vertical > 0); bool down = (inputUI.vertical < 0); bool left = (inputUI.horizontal < 0); bool right = (inputUI.horizontal > 0); if (!up && !down && !left && !right) { inputTimer = 0; } else { inputTimer -= Time.deltaTime; } if (inputTimer < 0) { inputTimer = 0; } if (inputTimer > 0) { return; } if (up) { //Inventory has fixed column count 5 currentInv_Index -= 5; inputTimer = inputDelay; } if (down) { //Inventory has fixed column count 5 currentInv_Index += 5; inputTimer = inputDelay; } if (left) { currentInv_Index -= 1; inputTimer = inputDelay; } if (right) { currentInv_Index += 1; inputTimer = inputDelay; } //Clamp //If you reach at the end, go to start, first element if (currentInv_Index > maxInv_Index - 1) { currentInv_Index = 0; } if (currentInv_Index < 0) { currentInv_Index = 0; } }
void HandleSlotMovement(InputUI inputUI) { int x = Mathf.RoundToInt(currentSlotPos.x); int y = Mathf.RoundToInt(currentSlotPos.y); bool up = (inputUI.vertical > 0); bool down = (inputUI.vertical < 0); bool left = (inputUI.horizontal < 0); bool right = (inputUI.horizontal > 0); if (!up && !down && !left && !right) { inputTimer = 0; } else { inputTimer -= Time.deltaTime; } if (inputTimer < 0) { inputTimer = 0; } if (inputTimer > 0) { return; } if (up) { y--; inputTimer = inputDelay; } if (down) { y++; inputTimer = inputDelay; } if (left) { x--; inputTimer = inputDelay; } if (right) { x++; inputTimer = inputDelay; } if (x > 4) { x = 0; } if (x < 0) { x = 0; } if (y > 5) { y = 0; } if (y < 0) { y = 5; } if (currentEqSlot != null) { currentEqSlot.iconBase.background.color = slotUnSelectedColor; } if (x == 4 && y == 3) { x = 4; y = 2; } currentEqSlot = equipmentSlots[x, y]; currentSlotPos.x = x; currentSlotPos.y = y; if (currentEqSlot != null) { currentEqSlot.iconBase.background.color = slotSelectedColor; } }
void HandleSlotInput(InputUI inputUI) { if (currentEqSlot == null) { return; } #region X Input --> Switching if (inputUI.x_input) { isSwitching = !isSwitching; Debug.Log("Changed is switching to : " + isSwitching); if (isSwitching) { Itemtype type = ItemTypeFromSlotType(currentEqSlot.eqSlotType); LoadCurrentItems(type); } else { Itemtype type = ItemTypeFromSlotType(currentEqSlot.eqSlotType); if (type == Itemtype.Weapon) { int targetIndex = currentEqSlot.itemPosition; //If slot index is greater than 2, it is left hand weapon, //since first 3 slots belong to right hand weapons bool isLeft = (currentEqSlot.itemPosition > 2) ? true : false; if (isLeft) { targetIndex -= 3; invManager.leftHandWeapons[targetIndex] = currentInvIcon.id; ItemInventoryInstance invInstance = session.GetWeaponItem(invManager.leftHandWeapons[targetIndex]); if (invInstance.slot != null) { equipmentSlotsUI.ClearEquipmentSlot(invInstance.slot, Itemtype.Weapon); ClearOnIndex(invInstance.equip_Index); } } else { invManager.rightHandWeapons[targetIndex] = currentInvIcon.id; ItemInventoryInstance invInstance = session.GetWeaponItem(invManager.rightHandWeapons[targetIndex]); if (invInstance.slot != null) { equipmentSlotsUI.ClearEquipmentSlot(invInstance.slot, Itemtype.Weapon); ClearOnIndex(invInstance.equip_Index); } } } else { ItemInventoryInstance invInstance = session.GetConsumableItem(invManager.consumableItems[currentEqSlot.itemPosition]); if (invInstance.slot != null) { equipmentSlotsUI.ClearEquipmentSlot(invInstance.slot, Itemtype.Consumable); //Set as empty item invManager.consumableItems[invInstance.equip_Index] = -1; } invManager.consumableItems[currentEqSlot.itemPosition] = currentInvIcon.id; } LoadEquipment(invManager, true); } ChangeToSwitching(); } #endregion //b --> back button if (inputUI.b_input) { if (isSwitching) { isSwitching = false; ChangeToSwitching(); } else { isMenu = false; CloseUI(); } } #region Y Input if (inputUI.y_input) { if (isSwitching) { centerOverlayIsOpen = !centerOverlayIsOpen; centerOverlay.SetActive(centerOverlayIsOpen); } else { Itemtype type = ItemTypeFromSlotType(currentEqSlot.eqSlotType); if (type == Itemtype.Weapon) { int targetIndex = currentEqSlot.itemPosition; bool isLeft = (currentEqSlot.itemPosition > 2) ? true : false; if (isLeft) { targetIndex -= 3; invManager.leftHandWeapons[targetIndex] = -1; ItemInventoryInstance invInstance = session.GetWeaponItem(invManager.leftHandWeapons[targetIndex]); if (invInstance.slot != null) { equipmentSlotsUI.ClearEquipmentSlot(invInstance.slot, Itemtype.Weapon); } } else { invManager.rightHandWeapons[targetIndex] = -1; ItemInventoryInstance invInstance = session.GetWeaponItem(invManager.rightHandWeapons[targetIndex]); if (invInstance.slot != null) { equipmentSlotsUI.ClearEquipmentSlot(invInstance.slot, Itemtype.Weapon); } } } else if (type == Itemtype.Consumable) { int targetIndex = currentEqSlot.itemPosition; if (targetIndex < invManager.consumableItems.Count) { invManager.consumableItems[currentEqSlot.itemPosition] = -1; ItemInventoryInstance invInstance = session.GetConsumableItem(invManager.consumableItems[targetIndex]); if (invInstance.slot != null) { equipmentSlotsUI.ClearEquipmentSlot(invInstance.slot, Itemtype.Consumable); } } } LoadEquipment(invManager, true); } } #endregion }