private void OnSlotValueChanged(UiSlot uiSlot) { if (OnSlotsValueChanged != null) { OnSlotsValueChanged(Slots); } }
public void Hide() { IsActive = false; Audio.Stop(); _torchSlot = null; Animation.Play("HideTorch"); }
public void ChangeItemAmount(UiSlot slot, int amount) { switch (slot.SlotType) { case SlotType.Inventory: Inventory.Slots[slot.SlotId].ChangeAmount(amount); break; case SlotType.Quick: Inventory.QuickSlots[slot.SlotId].ChangeAmount(amount); break; case SlotType.EquipBoots: case SlotType.EquipCap: case SlotType.EquipPants: case SlotType.EquipShirt: Inventory.EquipSlots[slot.SlotId].ChangeAmount(amount); break; case SlotType.Interactive: if (_gameManager.DisplayManager.CurrentInteractPanel != null && _gameManager.DisplayManager.CurrentInteractPanel is InteractView) { var panel = _gameManager.DisplayManager.CurrentInteractPanel as InteractView; panel.ChageAmount(slot, amount); } break; } }
public void OnInventorySlotClick(UiSlot uiSlot) { RefreshPrevSelectedSlot(); if (_prevSelectedSlot == uiSlot) { if (uiSlot.ItemModel.Item is ConsumableItem) { if (uiSlot.ItemModel.Amount == 1) { uiSlot.SetActiveSlot(false); } UseItem(uiSlot.ItemModel); } else { uiSlot.SetActiveSlot(false); } } else if (_prevSelectedSlot == null) { if (uiSlot.ItemModel != null) { uiSlot.SetActiveSlot(true); } } else { if (uiSlot.ItemModel == null || uiSlot.ItemModel.Item == null) { if (_prevSelectedSlot.ItemModel.Amount == 1) { _prevSelectedSlot.SetActiveSlot(false); } uiSlot.SetData(_gameManager, HolderObjectFactory.GetItem(_prevSelectedSlot.ItemModel.Item.GetType(), 1)); _prevSelectedSlot.ChangeAmount(1); } else if (uiSlot.ItemModel.Item.GetType() == _prevSelectedSlot.ItemModel.Item.GetType() && (uiSlot.ItemModel.Item.Durability == null || !uiSlot.ItemModel.Item.ShowDurability)) { if (_prevSelectedSlot.ItemModel.Amount == 1) { _prevSelectedSlot.SetActiveSlot(false); } _gameManager.PlayerModel.ChangeItemAmount(uiSlot, -1); _gameManager.PlayerModel.ChangeItemAmount(_prevSelectedSlot, 1); } else { var curModel = uiSlot.ItemModel; uiSlot.SetData(_gameManager, _prevSelectedSlot.ItemModel); _prevSelectedSlot.SetData(_gameManager, curModel); _prevSelectedSlot.SetActiveSlot(false); } } }
public override void ChageAmount(UiSlot slot, int amount) { Slots[slot.SlotId].ChangeAmount(amount); if (OnSlotsValueChanged != null) { OnSlotsValueChanged(Slots); } }
public void Show(UiSlot slot) { IsActive = true; TorchObject.SetActive(true); _torchSlot = slot; Animation.Play("ShowTorch"); Audio.Play(); FireParticles.Play(); }
private void OnEquipSlotClick(UiSlot uiSlot) { RefreshPrevSelectedSlot(); if (_prevSelectedSlot != null && !uiSlot.CanSetEquip(_prevSelectedSlot)) { _prevSelectedSlot.SetActiveSlot(false); } else { OnInventorySlotClick(uiSlot); } }
public void Init(GameManager gameManager, UiSlot slot) { CanPlace = true; _cachedTransform = transform; Slot = slot; AdditionalHeigth = 0.0f; GameManager = gameManager; if (CheckCanPlace) { foreach (var material in Materials) { material.SetColor("_Color", CanPlaceColor); } } _isInitialized = true; }
private void RefreshPrevSelectedSlot() { _prevSelectedSlot = null; foreach (var slot in MainHud.InventoryPanel.Slots) { if (slot.IsSelected) { _prevSelectedSlot = slot; break; } } foreach (var slot in MainHud.InventoryPanel.QuickSlotsPanel.Slots) { if (slot.IsSelected) { _prevSelectedSlot = slot; break; } } foreach (var slot in MainHud.InventoryPanel.EquipPanel.Slots) { if (slot.IsSelected) { _prevSelectedSlot = slot; break; } } if (_gameManager.DisplayManager.CurrentInteractPanel != null && _gameManager.DisplayManager.CurrentInteractPanel is InteractView) { var panel = _gameManager.DisplayManager.CurrentInteractPanel as InteractView; foreach (var slot in panel.Slots) { if (slot.IsSelected) { _prevSelectedSlot = slot; break; } } } }
public void SetItem(UiSlot slot, HolderObject itemModel) { if (slot.SlotType == SlotType.Inventory) { Inventory.Slots[slot.SlotId] = itemModel; } else if (slot.SlotType == SlotType.Quick) { Inventory.QuickSlots[slot.SlotId] = itemModel; } else if (slot.SlotType == SlotType.EquipBoots || slot.SlotType == SlotType.EquipCap || slot.SlotType == SlotType.EquipPants || slot.SlotType == SlotType.EquipShirt) { Inventory.EquipSlots[slot.SlotId] = itemModel; } else if (slot.SlotType == SlotType.Interactive) { if (_gameManager.DisplayManager.CurrentInteractPanel != null && _gameManager.DisplayManager.CurrentInteractPanel is InteractView) { var panel = _gameManager.DisplayManager.CurrentInteractPanel as InteractView; panel.SetItem(slot, itemModel); } if (slot.OnValueChanged != null) { slot.OnValueChanged(slot); } } else { if (slot.OnValueChanged != null) { slot.OnValueChanged(slot); } } }
private void OnInventorySlotClick(UiSlot uiSlot) { GameManager.Player.OnInventorySlotClick(uiSlot); }
public override void SetItem(UiSlot slot, HolderObject itemModel) { OnSlotValueChanged(slot); }
public override void ChageAmount(UiSlot slot, int amount) { Slots[slot.SlotId].ChangeAmount(amount); OnSlotValueChanged(slot); }
private void OnQuicklSlotClick(UiSlot uiSlot) { if (_changingWeapon) { return; } if (MainHud.InventoryPanel.IsShowing) { OnInventorySlotClick(uiSlot); } else { bool useItem = true; if (uiSlot.ItemModel != null) { if (_fishrodController != null && !(uiSlot.ItemModel.Item is Fishrod)) { _fishrodController.CurrentState = FishrodStates.Available; FishrodBobberParent.gameObject.SetActive(false); } if (uiSlot.ItemModel.Item is Torch) { if (_torchActive) { Torch.Hide(); } else { if (MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot != null && (MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot.ItemModel.Item is Bow || MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot.ItemModel.Item is Crossbow)) { foreach (var slot in MainHud.InventoryPanel.QuickSlotsPanel.Slots) { slot.SetActiveSlot(false); } MainHud.InventoryPanel.QuickSlotsPanel.UpdateView(); WeaponHandler.SetWeaponSmooth(); } Torch.Show(uiSlot); } _torchActive = !_torchActive; } else if (uiSlot.ItemModel.Item is ConsumableItem) { foreach (var slot in MainHud.InventoryPanel.QuickSlotsPanel.Slots) { if (slot != uiSlot) { slot.SetActiveSlot(false); } } } else if (uiSlot.ItemModel.Item is UsableItem) { foreach (var slot in MainHud.InventoryPanel.QuickSlotsPanel.Slots) { if (slot.ItemModel != null && slot.ItemModel.Item is UsableItem) { if (slot == uiSlot) { if (MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot != null && MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot == slot) { useItem = false; MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot = null; slot.SelectUsable(false); SetEmptyHand(); } else { slot.SelectUsable(true); MainHud.InventoryPanel.QuickSlotsPanel.CurrentSlot = uiSlot; } } else { slot.SelectUsable(false); } } } } else if (uiSlot.ItemModel.Item is IPlacement) { if (_currentWeapon != null) { SetEmptyHand(); } if (_currentGroundPlacementObject != null && _currentGroundPlacementObject.GetComponent <GroundPlacementItemController>().Slot == uiSlot) { useItem = false; } else { MainHud.InventoryPanel.QuickSlotsPanel.CurrentPlacementSlot = uiSlot; uiSlot.SelectUsable(true); var placementItem = uiSlot.ItemModel.Item as IPlacement; _currentGroundPlacementObject = Instantiate(Resources.Load <GameObject>(placementItem.PrefabTemplatePath)); var initScale = _currentGroundPlacementObject.transform.localScale; _currentGroundPlacementObject.transform.parent = DropObjectSpawnPlace.transform; _currentGroundPlacementObject.transform.localPosition = Vector3.zero; _currentGroundPlacementObject.transform.localRotation = Quaternion.identity; _currentGroundPlacementObject.transform.localScale = initScale; _currentGroundPlacementObject.GetComponent <GroundPlacementItemController>().Init(_gameManager, uiSlot); MainHud.InventoryPanel.QuickSlotsPanel.Hide(); MainHud.RemovePlaceItemButton.SetActive(true); _gameManager.PlacementItemsController.SetActiveConstructionColliders(true); if (uiSlot.ItemModel.Item is Construction) { var constItem = uiSlot.ItemModel.Item as Construction; if (constItem.ConstructionType == ConstructionType.Foundation) { MainHud.UpFoundationButton.SetActive(true); MainHud.DownFoundationButton.SetActive(true); } } MainHud.AttackButtonIcon.spriteName = WorldConsts.BuildIconName; } } } if (useItem) { UseItem(uiSlot.ItemModel); } } }