2025-05-18 01:04:31 +08:00

613 lines
20 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-09
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "EquipmentBox.View" company="KUNPO"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
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
/// <summary>
///
/// </summary>
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<EquipmentWidget>();
_extraAttributes = __goExtraAttributes.GetComponent<KUIList>();
_extraAttributes.AddTemplate<EquipmentAttributeItem>(true);
_specialAttributes = __goSpecialAttributes.GetComponent<KUIList>();
_specialAttributes.AddTemplate<EquipmentAttributeItem>(true);
_gemAttributes = __goGemAttributes.GetComponent<KUIList>();
_gemAttributes.AddTemplate<GemAttributeItem>(true);
_suitAttributes = __goSuitAttributes.GetComponent<KUIList>();
_suitAttributes.AddTemplate<EquipmentAttributeItem>(true);
_suitAttributes2 = __goSuitAttributes2.GetComponent<KUIList>();
_suitAttributes2.AddTemplate<EquipmentAttributeItem>(true);
_upgradeCost = __goUpgradeCost.AddComponent<CostWidget>();
_onekeyUpgradeCost = __goOnekeyUpgradeCost.AddComponent<CostWidget>();
_activateSuitCost = __goActivateSuitCost.AddComponent<CostWidget>();
_suitDescription = __goSuitAttributes.transform.Find("Image/Text").GetComponent<TextMeshProUGUI>();
_suitDescription2 = __goSuitAttributes2.transform.Find("Image/Text").GetComponent<TextMeshProUGUI>();
}
/// <summary>
///
/// </summary>
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<ItemWeapon>(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<CombatAttribute> attributes)
{
if (attributes != null && attributes.Count > 0)
{
__goExtraAttributes.SetActive(true);
_extraAttributes.Clear();
for (int i = 0; i < attributes.Count; i++)
{
var at = _extraAttributes.GetItem<EquipmentAttributeItem>();
at.SetData(attributes[i].ToString());
}
}
else
{
__goExtraAttributes.SetActive(false);
}
}
void SetExtra(List<CombatAttribute> attributes, List<CombatAttribute> attributes2)
{
if (attributes != null && attributes.Count > 0)
{
__goExtraAttributes.SetActive(true);
_extraAttributes.Clear();
for (int i = 0; i < attributes.Count; i++)
{
var at = _extraAttributes.GetItem<EquipmentAttributeItem>();
if (i < attributes2.Count)
at.SetData(attributes[i].ToString() + "(<color=#349652>强化+" + attributes2[i].value + "</color>)");
else
at.SetData(attributes[i].ToString());
}
}
else
{
__goExtraAttributes.SetActive(false);
}
}
void SetSpecial(List<CombatAttribute> 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);
}
}
/// <summary>
///
/// </summary>
/// <param name="gems"></param>
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<ItemSuit>(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<PropTipsBox>(ItemProxy.Instance.GetStaticItem<ItemProp>(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
}
}