public void OnExitWeaponMount(Image image) { if (image == null) { return; } image.color = _mountColor; _selectedPanelType = InventoryPanelType.None; }
public void OnExitFoodMount(Image image) { if (image != null) { image.color = _mountColor; } _selectedPanelType = InventoryPanelType.None; }
public void OnEnterWeaponMount(Image image) { var itemMount = _inventory.GetWeapon(0); if (itemMount == null || itemMount.Weapon == null) { return; } if (_selectedPanelType != InventoryPanelType.Weapons) { image.color = _mountHover; } _selectedPanelType = InventoryPanelType.Weapons; }
public void OnEnterAmmoMount(Image image) { var itemMount = _inventory.GetAmmo(0); if (itemMount == null || itemMount.Ammo == null) { return; } if (_selectedPanelType != InventoryPanelType.AmmoBelt) { image.color = _mountHover; } _selectedPanelType = InventoryPanelType.AmmoBelt; }
public void OnEnterFoodMount(Image image) { var itemMount = _inventory.GetFood(0); if (itemMount == null || itemMount.Item == null) { return; } if (_selectedPanelType != InventoryPanelType.Backpack) { image.color = _mountHover; } _selectedPanelType = InventoryPanelType.Backpack; }
// -------------------------------------------------------------------------------- // Name : OnPointerClickBackpackSlot // Desc : Called when user clicks on a Backpack Mount's frame // -------------------------------------------------------------------------------- public void OnClickBackpackMount(Image image) { // Get mountfrom name int mount; if (image == null || !int.TryParse(image.name, out mount)) { Debug.Log("OnClickBackpackError : Could not parse image name as INT"); return; } // Is this a valid mount that's been clicked if (mount >= 0 && mount < _backpackMounts.Count) { // Get Inventory Item InventoryBackpackMountInfo itemMount = _inventory.GetBackpack(mount); // No highlight if nothing at this slot if (itemMount == null || itemMount.Item == null) { return; } // We are clicking on the selected item so unselect if (mount == _selectedMount && _selectedPanelType == InventoryPanelType.Backpack) { Invalidate(); image.color = _backpackMountHover; image.fillCenter = false; DisplayGeneralDescription(itemMount.Item); } else { Invalidate(); _selectedPanelType = InventoryPanelType.Backpack; _selectedMount = mount; image.color = _backpackMountColor; image.fillCenter = true; DisplayGeneralDescription(itemMount.Item); } } }
// ---------------------------------------------------------------------------- // Name : OnClickWeaponMount // Desc : Called when mouse clicks on a Weapon Mount's frame // ---------------------------------------------------------------------------- public void OnClickWeaponMount(Image image) { int mount; if (image == null || !int.TryParse(image.name, out mount)) { Debug.Log("OnEnterWeaponMount Error! Could not parse image name as int"); return; } // Is this a valid mount that's been clicked if (mount >= 0 && mount < _ammoMounts.Count) { // Get Inventory Item InventoryWeaponMountInfo itemMount = _inventory.GetWeapon(mount); // No highlight if nothing at this slot if (itemMount == null || itemMount.Weapon == null) { return; } // We are clicking on the selected item so unselect if (mount == _selectedMount && _selectedPanelType == InventoryPanelType.Weapons) { Invalidate(); image.color = _weaponMountHover; image.fillCenter = false; DisplayWeaponDescription(itemMount.Weapon); } else { Invalidate(); _selectedPanelType = InventoryPanelType.Weapons; _selectedMount = mount; image.color = _weaponMountColor; image.fillCenter = true; DisplayWeaponDescription(itemMount.Weapon); } } }
// -------------------------------------------------------------------------------------------- // Name : Invalidate // Desc : This function updates the UI so all elements reflect the current state of the // user's inventory. This function also resets the Inventory to an unselected // state. // -------------------------------------------------------------------------------------------- protected virtual void Invalidate() { // Make sure its initialized before its is rendered for the first time if (!_isInitialized) { Initialize(); } // Reset Selections _selectedPanelType = InventoryPanelType.None; _selectedMount = -1; // Deactivate Description Panels if (_generalDescriptionLayout.LayoutContainer != null) { _generalDescriptionLayout.LayoutContainer.SetActive(false); } if (_weaponDescriptionLayout.LayoutContainer != null) { _weaponDescriptionLayout.LayoutContainer.SetActive(false); } // Deactivate the action buttons if (_actionButton1.GameObject != null) { _actionButton1.GameObject.SetActive(false); } if (_actionButton2.GameObject != null) { _actionButton2.GameObject.SetActive(false); } // Clear the Weapon Mounts for (int i = 0; i < _weaponMounts.Count; i++) { if (_weaponMounts[i] != null) { if (_weaponMountImages[i] != null) { _weaponMountImages[i].sprite = null; } if (_weaponMountNames[i] != null) { _weaponMountNames[i].text = ""; } if (_weaponMountSliders[i] != null) { _weaponMountSliders[i].enabled = false; } _weaponMounts[i].SetActive(false); _weaponMounts[i].transform.GetComponent <Image>().fillCenter = false; } } // Iterate over the UI Backpack mounts and set all to empty and unselected for (int i = 0; i < _backpackMounts.Count; i++) { // Clear sprite and deactivate mount if (_backpackMountImages[i] != null) { _backpackMountImages[i].gameObject.SetActive(false); _backpackMountImages[i].sprite = null; } // Enable the text for this slot that says "EMPTY" if (_backpackMountText[i] != null) { _backpackMountText[i].gameObject.SetActive(true); } // Make all mounts look unselected if (_backpackMounts[i] != null) { // Get the image of the mount itself (the frame) Image img = _backpackMounts[i].GetComponent <Image>(); if (img) { img.fillCenter = false; img.color = _backpackMountColor; } } } // Configure the ammo slots for (int i = 0; i < _ammoMounts.Count; i++) { // Clear Sprite and deactivate mount if (_ammoMounts[i] != null) { if (_ammoMountImages[i]) { _ammoMountImages[i].gameObject.SetActive(false); _ammoMountImages[i].sprite = null; } } // Enable the text for this slot that says "EMPTY" if (_ammoMountEmptyText[i] != null) { _ammoMountEmptyText[i].gameObject.SetActive(true); } if (_ammoMountRoundsText[i] != null) { _ammoMountRoundsText[i].gameObject.SetActive(false); } // Give Mount Frame unselected look if (_ammoMounts[i] != null) { Image img = _ammoMounts[i].GetComponent <Image>(); if (img) { img.fillCenter = false; img.color = _ammoMountColor; } } } // Other PDA things if (_pDAReferences._autoplayOnPickup) { if (_audioPlayOnPickup) { _pDAReferences._autoplayOnPickup.isOn = true; } else { _pDAReferences._autoplayOnPickup.isOn = false; } } // Finally update the status panel if (_statusPanelUI.HealthSlider) { _statusPanelUI.HealthSlider.value = _health.value; } if (_statusPanelUI.InfectionSlider) { _statusPanelUI.InfectionSlider.value = _infection.value; } if (_statusPanelUI.StaminaSlider) { _statusPanelUI.StaminaSlider.value = _stamina.value; } if (_statusPanelUI.FlashlightSlider) { _statusPanelUI.FlashlightSlider.value = _flashlight.value; } if (_statusPanelUI.NightVisionSlider) { _statusPanelUI.NightVisionSlider.value = _nightvision.value; } // DO we have a valid Inventory Referenc. If so...let's paint it if (_inventory != null) { // Configure Weapons Panel by iterating through each mount for (int i = 0; i < _weaponMounts.Count; i++) { // Do we have a weapon mount here if (_weaponMounts[i] != null) { // Get the matching mount and weapon data from the inventory InventoryWeaponMountInfo weaponMountInfo = _inventory.GetWeapon(i); InventoryItemWeapon weapon = null; if (weaponMountInfo != null) { weapon = weaponMountInfo.Weapon; } // No weapon info here to skip this mount if (weapon == null) { continue; } // Set sprite and name of weapon if (_weaponMountImages[i] != null) { _weaponMountImages[i].sprite = weapon.inventoryImage; } if (_weaponMountNames[i] != null) { _weaponMountNames[i].text = weapon.inventoryName; } // If its a melee weapon then deactivate the entire AmmoInfo section of the UI // otherwise Enabled it and show the Reload Type and Rounds in Gun if (_weaponMountAmmoInfo[i] != null) { if (weapon.weaponFeedType == InventoryWeaponFeedType.Melee) { _weaponMountAmmoInfo[i].SetActive(false); } else { // Activate Mount _weaponMountAmmoInfo[i].SetActive(true); // Display Reload Type if (_weaponMountReloadType[i] != null) { _weaponMountReloadType[i].text = weapon.reloadType.ToString(); } if (_weaponMountRounds[i] != null) { _weaponMountRounds[i].text = weaponMountInfo.InGunRounds + " / " + weapon.ammoCapacity; } } } // Update the condition slider if (_weaponMountSliders[i] != null) { _weaponMountSliders[i].enabled = true; _weaponMountSliders[i].value = weaponMountInfo.Condition; } _weaponMounts[i].SetActive(true); } } // Configure Ammo Mounts for (int i = 0; i < _ammoMounts.Count; i++) { // Clear Sprite and deactivate mount if (_ammoMounts[i] != null) { // Get the ammo and it's mount info for this mount InventoryAmmoMountInfo ammoMountInfo = _inventory.GetAmmo(i); InventoryItemAmmo ammo = null; if (ammoMountInfo != null) { ammo = ammoMountInfo.Ammo; } // No weapon at this mount so skip if (ammo == null) { continue; } // Set image if (_ammoMountImages[i]) { _ammoMountImages[i].gameObject.SetActive(true); _ammoMountImages[i].sprite = ammoMountInfo.Ammo.inventoryImage; } // Set and Enable Rounds Text if (_ammoMountRoundsText[i] != null) { _ammoMountRoundsText[i].gameObject.SetActive(true); _ammoMountRoundsText[i].text = ammoMountInfo.Rounds.ToString(); } // Disable Empty text if (_ammoMountEmptyText[i] != null) { _ammoMountEmptyText[i].gameObject.SetActive(false); } } } // Iterate over the UI Backpack mounts and set all to empty and unselected for (int i = 0; i < _backpackMounts.Count; i++) { if (_backpackMounts[i] != null) { InventoryBackpackMountInfo backpackMountInfo = _inventory.GetBackpack(i); InventoryItem item = null; if (backpackMountInfo != null) { item = backpackMountInfo.Item; } if (item != null) { // Set sprite and activate mount if (_backpackMountImages[i] != null) { _backpackMountImages[i].gameObject.SetActive(true); _backpackMountImages[i].sprite = item.inventoryImage; } // Disable the text for this slot that says "EMPTY" if (_backpackMountText[i] != null) { _backpackMountText[i].gameObject.SetActive(false); } } } } } }
protected virtual void Invalidate() { _selectedPanelType = InventoryPanelType.None; if (_weaponMount != null) { if (_weaponMountImage != null) { _weaponMountImage.sprite = null; } if (_weaponMountName != null) { _weaponMountName.text = ""; } if (_weaponMountWeight != null) { _weaponMountWeight.text = ""; } if (_weaponMountID != null) { _weaponMountID.text = ""; } if (_weaponMountRounds != null) { _weaponMountRounds.text = ""; } _weaponMount.SetActive(false); _weaponMount.transform.GetComponent <Image>().fillCenter = false; } if (_foodMount != null) { if (_foodMountImage != null) { _foodMountImage.sprite = null; } if (_foodMountName != null) { _foodMountName.text = ""; } if (_foodMountWeight != null) { _foodMountWeight.text = ""; } if (_foodMountID != null) { _foodMountID.text = ""; } _foodMount.SetActive(false); _foodMount.transform.GetComponent <Image>().fillCenter = false; } if (_ammoMount != null) { if (_ammoMountImage != null) { _ammoMountImage.sprite = null; } if (_ammoMountName != null) { _ammoMountName.text = ""; } if (_ammoMountWeight != null) { _ammoMountWeight.text = ""; } if (_ammoMountID != null) { _ammoMountID.text = ""; } _ammoMount.SetActive(false); _ammoMount.transform.GetComponent <Image>().fillCenter = false; } if (_inventory != null) { if (_weaponMount != null) { var weaponMountInfo = _inventory.GetWeapon(0); InventoryItemWeapon weapon = null; if (weaponMountInfo != null) { weapon = weaponMountInfo.Weapon; } if (weapon != null) { if (_weaponMountImage != null) { _weaponMountImage.sprite = weapon.Image; } if (_weaponMountName != null) { _weaponMountName.text = weapon.Name; } if (_weaponMountWeight != null) { _weaponMountWeight.text = weapon.Weight.ToString() + " kg"; } if (_weaponMountID != null) { _weaponMountID.text = weapon.Identifier; } if (_weaponMountRounds != null) { _weaponMountRounds.text = weaponMountInfo.Rounds.ToString(); } _weaponMount.SetActive(true); } } if (_foodMount != null) { var foodMountInfo = _inventory.GetFood(0); InventoryItemFood food = null; if (foodMountInfo != null) { food = foodMountInfo.Item; } if (food != null) { if (_foodMountImage != null) { _foodMountImage.sprite = food.Image; } if (_foodMountName != null) { _foodMountName.text = food.Name; } if (_foodMountWeight != null) { _foodMountWeight.text = food.Weight.ToString() + " kg"; } if (_foodMountID != null) { _foodMountID.text = food.Identifier; } _foodMount.SetActive(true); } } if (_ammoMount != null) { var ammoMountInfo = _inventory.GetAmmo(0); InventoryItemAmmo ammo = null; if (ammoMountInfo != null) { ammo = ammoMountInfo.Ammo; } if (ammo != null) { if (_ammoMountImage != null) { _ammoMountImage.sprite = ammo.Image; } if (_ammoMountName != null) { _ammoMountName.text = ammo.Name; } if (_ammoMountWeight != null) { _ammoMountWeight.text = ammo.Weight.ToString() + " kg"; } if (_ammoMountID != null) { _ammoMountID.text = ammo.Identifier; } _ammoMount.SetActive(true); } } } }