// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-09 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** namespace G.UI { using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; /// /// /// partial class EquipmentDetailBox { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] GameObject __goIcon; [KUIFlag] GameObject _goSlot; [KUIFlag] KUIImage _imgSlotSuit; [KUIFlag] TextMeshProUGUI _tmpSlotLevel; [KUIFlag] TextMeshProUGUI _tmpName; [KUIFlag] TextMeshProUGUI _tmpWeaponType; [KUIFlag] TextMeshProUGUI _tmpElementType; [KUIFlag] TextMeshProUGUI _tmpType; [KUIFlag] TextMeshProUGUI _tmpForce; [KUIFlag] TextMeshProUGUI _tmpQuality; [KUIFlag] GameObject _goForce; [KUIFlag] TextMeshProUGUI _tmpDescribe; [KUIFlag] Toggle _tgLock; [KUIFlag] GameObject _goWeapon; [KUIFlag] GameObject _goElement; [KUIFlag] KUIImage _imgElement; [KUIFlag] GameObject __goExtraAttributes; [KUIFlag] GameObject __goSpecialAttributes; [KUIFlag] GameObject __goGemAttributes; [KUIFlag] GameObject __goSuitAttributes; [KUIFlag] GameObject __goSuitAttributes2; [KUIFlag] GameObject _goDescribe; [KUIFlag] GameObject _goRequire; [KUIFlag] Button _btnSet; [KUIFlag] Button _btnBlack; [KUIFlag] Button _btnSell; [KUIFlag] Button _btnUpgrade; [KUIFlag] Button _btnOneKeyUpgrade; [KUIFlag] GameObject __goUpgradeCost; [KUIFlag] GameObject _tmpMaxGrade; [KUIFlag] GameObject __goOnekeyUpgradeCost; [KUIFlag] Button _btnActivateSuit; [KUIFlag] GameObject __goActivateSuitCost; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null private EquipmentWidget _equipmentItem; private KUIList _extraAttributes; private KUIList _specialAttributes; private KUIList _gemAttributes; private KUIList _suitAttributes; private TextMeshProUGUI _suitDescription; private KUIList _suitAttributes2; private TextMeshProUGUI _suitDescription2; private CostWidget _upgradeCost; private CostWidget _onekeyUpgradeCost; private CostWidget _activateSuitCost; bool _upgraded; #endregion #region Method /// /// /// public void InitView() { SetViewData(); _btnSet.onClick.AddListener(this.OnSetBtnClick); _btnSell.onClick.AddListener(this.OnSellBtnClick); _btnUpgrade.onClick.AddListener(this.OnUpgradeBtnClick); _btnOneKeyUpgrade.onClick.AddListener(this.OnOneKeyUpgradeBtnClick); _btnActivateSuit.onClick.AddListener(this.OnActivateSuitBtnClick); _btnBlack.onClick.AddListener(this.OnCloseBtnClick); _equipmentItem = __goIcon.AddComponent(); _extraAttributes = __goExtraAttributes.GetComponent(); _extraAttributes.AddTemplate(true); _specialAttributes = __goSpecialAttributes.GetComponent(); _specialAttributes.AddTemplate(true); _gemAttributes = __goGemAttributes.GetComponent(); _gemAttributes.AddTemplate(true); _suitAttributes = __goSuitAttributes.GetComponent(); _suitAttributes.AddTemplate(true); _suitAttributes2 = __goSuitAttributes2.GetComponent(); _suitAttributes2.AddTemplate(true); _upgradeCost = __goUpgradeCost.AddComponent(); _onekeyUpgradeCost = __goOnekeyUpgradeCost.AddComponent(); _activateSuitCost = __goActivateSuitCost.AddComponent(); _suitDescription = __goSuitAttributes.transform.Find("Image/Text").GetComponent(); _suitDescription2 = __goSuitAttributes2.transform.Find("Image/Text").GetComponent(); } /// /// /// public void RefreshView() { _tgLock.onValueChanged.RemoveAllListeners(); if (this.data is EntityItemEquipment equipment) { ShowEquipment(equipment); } else if (this.data is ItemEquipment equipmentItem) { ShowEquipment(equipmentItem); } } void ShowEquipment(EntityItemEquipment equipment) { var propItem = equipment.propItem; _tmpName.text = propItem.name; _tmpQuality.text = Item.GetQualityText(propItem.quality); _tmpQuality.color = Item.GetQualityColor(propItem.quality); _tmpDescribe.text = propItem.text; _goForce.SetActive(true); _equipmentItem.SetData(equipment); _tmpType.text = equipment.item.partName; //this.SetWeapon(equipment.isWeapon ? equipment.weaponKind : 0); this.SetElement(equipment.isWeapon ? equipment.basicAttribute : default); this.SetSpecial(equipment.specialAttributes); this.SetSuit2(equipment.suitId); var slot = PlayerProxy.Instance.GetEquipmentSlot(equipment); if (slot != null) { this.SetExtra(equipment.extraAttributes, slot.upgradeAttributes); this.SetGems(slot); this.SetSlotSuit(!GlobalVar.IsBattling && FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.解锁武林大会功能) ? slot.id : -1); _goSlot.SetActive(true); if (slot.grade > 0) _tmpSlotLevel.text = $"+{slot.grade}"; else _tmpSlotLevel.text = ""; var suitInfo = PlayerProxy.Instance.GetCurrEquipmentSuit(); int suitGrade = suitInfo != null ? suitInfo.GetGrade(slot.id) : 0; if (suitGrade > 0) { _imgSlotSuit.gameObject.SetActive(true); _imgSlotSuit.ShowSprite(suitGrade - 1); } else { _imgSlotSuit.gameObject.SetActive(false); } _tmpForce.text = (equipment.combatValue + slot.gradeCombatValue).ToString(); _btnSet.gameObject.SetActive(false); _btnSell.gameObject.SetActive(false); _btnOneKeyUpgrade.gameObject.SetActive(false); if (!GlobalVar.IsBattling && FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.强化)) { bool enough = PlayerProxy.Instance.GetUpgradeEquipmentSlotCost(equipment.equipmentType, false, out int costId, out int costAmount); if (costAmount > 0) { _upgradeCost.gameObject.SetActive(true); _upgradeCost.SetPrice(costId, costAmount, enough); _tmpMaxGrade.SetActive(false); } else { _upgradeCost.gameObject.SetActive(false); _tmpMaxGrade.SetActive(true); } _btnUpgrade.gameObject.SetActive(true); } else { _btnUpgrade.gameObject.SetActive(false); } _tgLock.gameObject.SetActive(false); } else { this.SetExtra(equipment.extraAttributes); SetGems(null); SetSlotSuit(-1); _goSlot.SetActive(false); _tmpForce.text = equipment.combatValue.ToString(); _btnUpgrade.gameObject.SetActive(false); _btnOneKeyUpgrade.gameObject.SetActive(false); _btnSet.gameObject.SetActive(!GlobalVar.IsBattling); _btnSell.gameObject.SetActive(!GlobalVar.IsBattling); if (!GlobalVar.IsBattling) { _tgLock.gameObject.SetActive(true); _tgLock.isOn = equipment.isLock; _tgLock.onValueChanged.AddListener(this.OnLockToggleValueChanged); _btnSell.gameObject.SetActive(!equipment.isLock); } else { _tgLock.gameObject.SetActive(false); } } } void ShowEquipment(ItemEquipment equipmentItem) { var propItem = equipmentItem.propItem; _tmpName.text = propItem.name; //_tmpName.color = Item.GetQualityColor(propItem.quality); _tmpQuality.text = Item.GetQualityText(propItem.quality); _tmpQuality.color = Item.GetQualityColor(propItem.quality); _tmpDescribe.text = propItem.text; _tmpType.text = equipmentItem.partName; _goForce.SetActive(false); _equipmentItem.SetData(propItem); _tgLock.gameObject.SetActive(false); SetWeapon(0); SetElement(default); SetExtra(null); SetSpecial(null); SetGems(null); SetSlotSuit(-1); _btnUpgrade.gameObject.SetActive(false); _btnOneKeyUpgrade.gameObject.SetActive(false); _btnSet.gameObject.SetActive(false); _btnSell.gameObject.SetActive(false); } void SetWeapon(int weaponType) { if (weaponType > 0) { _goWeapon.SetActive(true); var weaponItem = ItemProxy.Instance.GetStaticItem(weaponType); if (weaponItem.attributes != null && weaponItem.attributes.Length > 0) { _tmpWeaponType.text = weaponItem.attributes[0]; } } else { _goWeapon.SetActive(false); } } void SetElement(CombatAttribute attribute) { if (attribute.id > CombatAttributeId.ElementNone) { _goElement.SetActive(true); //var attrItem = attribute.item; //if (attrItem != null) //{ // _tmpElementType.text = attrItem.name; //} switch (attribute.id) { case CombatAttributeId.ElementFire: _imgElement.ShowSprite(0); _tmpElementType.text = KLocalization.GetLocalString(83); break; case CombatAttributeId.ElementIce: _imgElement.ShowSprite(1); _tmpElementType.text = KLocalization.GetLocalString(84); break; case CombatAttributeId.ElementLightning: _imgElement.ShowSprite(2); _tmpElementType.text = KLocalization.GetLocalString(85); break; case CombatAttributeId.ElementCurse: _imgElement.ShowSprite(3); _tmpElementType.text = KLocalization.GetLocalString(86); break; } } else { _goElement.SetActive(false); } } void SetExtra(List attributes) { if (attributes != null && attributes.Count > 0) { __goExtraAttributes.SetActive(true); _extraAttributes.Clear(); for (int i = 0; i < attributes.Count; i++) { var at = _extraAttributes.GetItem(); at.SetData(attributes[i].ToString()); } } else { __goExtraAttributes.SetActive(false); } } void SetExtra(List attributes, List attributes2) { if (attributes != null && attributes.Count > 0) { __goExtraAttributes.SetActive(true); _extraAttributes.Clear(); for (int i = 0; i < attributes.Count; i++) { var at = _extraAttributes.GetItem(); if (i < attributes2.Count) at.SetData(attributes[i].ToString() + "(强化+" + attributes2[i].value + ")"); else at.SetData(attributes[i].ToString()); } } else { __goExtraAttributes.SetActive(false); } } void SetSpecial(List attributes) { if (attributes != null && attributes.Count > 0) { __goSpecialAttributes.SetActive(true); _specialAttributes.Clear(); for (int i = 0; i < attributes.Count; i++) { var at = _specialAttributes.GetItem(); at.SetData(attributes[i].ToString()); } } else { __goSpecialAttributes.SetActive(false); } } /// /// /// /// void SetGems(PlayerProxy.EquipmentSlotInfo slot) { int unlockCount = 0; EntityItemGem[] gems = null; if (slot != null) { gems = slot.gems; unlockCount = slot.setGemCountMax; } if (unlockCount > 0 && gems != null && gems.Length > 0) { __goGemAttributes.SetActive(true); _gemAttributes.Clear(); for (int i = 0; i < unlockCount && i < gems.Length; i++) { var atW = _gemAttributes.GetItem(); if (gems[i] != null) { atW.SetData(gems[i]); } else { atW.SetData("可镶嵌宝石"); } } for (int i = unlockCount; i < gems.Length; i++) { var atW = _gemAttributes.GetItem(); atW.SetData($"强化等级{slot.GetGemUnlockGrade(i + 1)}解锁"); } } else { __goGemAttributes.SetActive(false); } } void SetSlotSuit(int slotId) { if (slotId >= 0) { var suit = PlayerProxy.Instance.GetCurrEquipmentSuit(); _btnActivateSuit.gameObject.SetActive(suit.CanUpgrade(slotId)); var cost = suit.GetUpgradeCost(slotId); _activateSuitCost.SetAndCheckPrice(cost.id, cost.count); __goSuitAttributes.SetActive(true); _suitDescription.text = suit.description; _suitAttributes.Clear(); var at = _suitAttributes.GetItem(); at.SetData(suit.suitAttributesText2); at = _suitAttributes.GetItem(); at.SetData(suit.suitAttributesText4); at = _suitAttributes.GetItem(); at.SetData(suit.suitAttributesText6); } else { _btnActivateSuit.gameObject.SetActive(false); __goSuitAttributes.SetActive(false); } } void SetSuit2(int suitId) { if (suitId > 0) { __goSuitAttributes2.SetActive(true); var suitItem = ItemProxy.Instance.GetStaticItem(suitId); _tmpName.text = suitItem.name + "-" + _tmpName.text; int activeCount = PlayerProxy.Instance.GetEquipmentSuitActiveCount(suitId); _suitDescription2.text = suitItem.description + $"({activeCount}/6)"; _suitAttributes2.Clear(); var at = _suitAttributes2.GetItem(); at.SetData(suitItem.GetStageText(activeCount, 2)); at = _suitAttributes2.GetItem(); at.SetData(suitItem.GetStageText(activeCount, 4)); at = _suitAttributes2.GetItem(); at.SetData(suitItem.GetStageText(activeCount, 6)); } else { __goSuitAttributes2.SetActive(false); } } private void OnSetBtnClick() { if (this.data is EntityItemEquipment equipment) { if (PlayerProxy.Instance.SetEquipment(equipment)) { CloseWindow(this); } else { ToastBox.ShowText(KLocalization.GetLocalString(17)); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnSellBtnClick() { if (BagProxy.Instance.Sell(this.data as EntityItemEquipment)) { CloseWindow(this); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnUpgradeBtnClick() { if (this.data is EntityItemEquipment equipment) { if (PlayerProxy.Instance.UpgradeEquipmentSlot(equipment.equipmentType, false, false)) { _upgraded = true; RefreshView(); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnOneKeyUpgradeBtnClick() { if (this.data is EntityItemEquipment equipment) { if (PlayerProxy.Instance.UpgradeEquipmentSlot(equipment.equipmentType, true, false)) { _upgraded = true; RefreshView(); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnActivateSuitBtnClick() { if (this.data is EntityItemEquipment equipment) { if (PlayerProxy.Instance.UpgradeEquipmentSlotSuit(equipment.equipmentType)) { RefreshView(); ToastBox.ShowEffect("UI_fx_Forging01"); } else { ToastBox.ShowText("陨铁材料不足"); OpenWindow(ItemProxy.Instance.GetStaticItem(Item.Id.kStone)); } } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnLockToggleValueChanged(bool value) { if (this.data is EntityItemEquipment equipment) { OnEquipmentLockChanged?.Invoke(value); equipment.isLock = value; _btnSell.gameObject.SetActive(!value); } } private void OnCloseBtnClick() { OnEquipmentLockChanged = null; if (_upgraded) { PostNotification(GlobalDefine.EVENT_PLAYER_EQUIPMENT_CHANGED, "", "upgrade"); } CloseWindow(this); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } #endregion } }