//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, March 08, 2019 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; namespace Snxxz.UI { public class EquipTrainPropertyBarBehaviour : MonoBehaviour { [SerializeField] int m_Index; [SerializeField] Text m_PropertyName; [SerializeField] Text m_Value; [SerializeField] Slider m_Progress; [SerializeField] Text m_DeltaValue; [SerializeField] ToggleButton m_Inevitable; EquipTrainModel model { get { return ModelCenter.Instance.GetModel(); } } EquipTrainPropertyBar propertyBar; public void Display(EquipTrainPropertyBar propertyBar) { this.propertyBar = propertyBar; DisplayBaseInfo(); DisplayDynamicInfo(true); m_Inevitable.SetListener(SwitchInevitable); } private void LateUpdate() { DisplayDynamicInfo(false); } private void DisplayBaseInfo() { var config = PlayerPropertyConfig.Get(propertyBar.propertyId); m_PropertyName.text = config.Name; switch (propertyBar.trainState) { case EquipTrainModel.TrainState.Empty: m_Progress.value = 0; m_Value.text = "0"; m_DeltaValue.gameObject.SetActive(false); m_Inevitable.gameObject.SetActive(true); break; case EquipTrainModel.TrainState.StarLimit: m_Progress.value = 1; m_Value.text = string.Format("{0}/{1}", propertyBar.propertyValue, propertyBar.upperLimit); m_DeltaValue.gameObject.SetActive(true); m_Inevitable.gameObject.SetActive(true); break; case EquipTrainModel.TrainState.MaxLevel: m_Progress.value = 1; m_Value.text = string.Format("{0}/{1}", propertyBar.propertyValue, propertyBar.upperLimit); m_DeltaValue.gameObject.SetActive(true); m_Inevitable.gameObject.SetActive(false); break; case EquipTrainModel.TrainState.Allowable: m_Inevitable.gameObject.SetActive(true); m_DeltaValue.gameObject.SetActive(true); break; } } private void DisplayDynamicInfo(bool force) { if (force || propertyBar.propertyValue.dirty) { var value = propertyBar.propertyValue.Fetch(); var maxValue = propertyBar.upperLimit; m_Value.text = string.Format("{0}/{1}", value, maxValue); m_Progress.value = Mathf.Clamp01((float)value / maxValue); } if (force || propertyBar.deltaValue.dirty || propertyBar.operateType.dirty || propertyBar.inevitable.dirty) { var deltaValue = propertyBar.deltaValue.Fetch(); var operateType = propertyBar.operateType.Fetch(); var inevitable = propertyBar.inevitable.Fetch(); m_Inevitable.isOn = inevitable; var isPerfect = propertyBar.upperLimit > 0 && propertyBar.propertyValue.value >= propertyBar.upperLimit; if (isPerfect) { m_DeltaValue.text = "完美"; m_DeltaValue.color = UIHelper.GetUIColor(TextColType.Green, true); } else { if (operateType == EquipTrainModel.TrainOperateType.Train) { m_DeltaValue.text = inevitable ? "必增" : ""; m_DeltaValue.color = UIHelper.GetUIColor(TextColType.Green, true); } else if (operateType == EquipTrainModel.TrainOperateType.Save) { if (deltaValue > 0) { m_DeltaValue.text = string.Format("+{0}", deltaValue); m_DeltaValue.color = UIHelper.GetUIColor(TextColType.Green, true); } else if (deltaValue < 0) { m_DeltaValue.text = deltaValue.ToString(); m_DeltaValue.color = UIHelper.GetUIColor(TextColType.Red, true); } else { m_DeltaValue.text = string.Format("+{0}", deltaValue); m_DeltaValue.color = UIHelper.GetUIColor(TextColType.Green, true); } } else { m_DeltaValue.text = ""; } } } } private void SwitchInevitable() { switch (propertyBar.trainState) { case EquipTrainModel.TrainState.Empty: SysNotifyMgr.Instance.ShowTip("Wash_NoEquip1"); break; case EquipTrainModel.TrainState.StarLimit: SysNotifyMgr.Instance.ShowTip("WashStarRequirement"); break; case EquipTrainModel.TrainState.Allowable: model.SetInevitable(m_Index - 1, !propertyBar.inevitable.value); break; case EquipTrainModel.TrainState.MaxLevel: break; } } } }