// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2021-02-18 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using TMPro; using UnityEngine; using UnityEngine.UI; namespace G.UI { partial class BusinessWindow { /// /// /// class BusinessItemWidget : KUIWidget { #region Field #pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null [KUIFlag] GameObject _goValid; [KUIFlag] GameObject _goUnlock; [KUIFlag] GameObject _goLocked; [KUIFlag] TextMeshProUGUI _tmpName; [KUIFlag] TextMeshProUGUI _tmpContent; [KUIFlag] Slider _sldProgress; [KUIFlag] TextMeshProUGUI _tmpTimer; [KUIFlag] KUIList __listRewards; [KUIFlag] Button _btnGet; [KUIFlag] Button _btnUnlock; [KUIFlag] TextMeshProUGUI _tmpRequired; [KUIFlag] Image _imgPicture; [KUIFlag] GameObject _goAddition; [KUIFlag] TextMeshProUGUI _tmpAddition; [KUIFlag] Button _btnSee; [KUIFlag] KUIImage _imgBg; [KUIFlag] Button _btnNotFriend; #pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null #endregion #region Method public override void Refresh() { if (this.data is BusinessProxy.BusinessInfo businessInfo) { var beauty = BeautyProxy.Instance.GetBeauty(businessInfo.beautyId); if (businessInfo.status == 2)//已运行 { _goLocked.SetActive(false); _goUnlock.SetActive(false); _goValid.SetActive(true); var affairItem = businessInfo.item; _tmpName.text = affairItem.matter_1; //_tmpContent.text = affairItem.description; _imgBg.ShowSprite(this.index); _btnSee.gameObject.SetActive(beauty != null); _goAddition.gameObject.SetActive(beauty != null); if (beauty != null) { if (beauty.isFriend) { _tmpAddition.text = $"产业加成{beauty.businessFactor}%"; _imgPicture.color = Color.white; _imgPicture.material = null; _btnNotFriend.gameObject.SetActive(false); } else { _btnSee.gameObject.SetActive(false); _tmpAddition.text = KLocalization.GetLocalString(65); _btnNotFriend.gameObject.SetActive(true); _imgPicture.color = Color.gray; _imgPicture.GetComponent().ShowSketch(true); } IconProxy.Instance.SetSpriteAsync(_imgPicture, beauty.skinItem.icon[0]); } else { _imgPicture.color = Color.white; _imgPicture.material = null; _btnNotFriend.gameObject.SetActive(false); _tmpAddition.text = ""; } UpdateRewards(businessInfo, true); } else if (businessInfo.status == 1)//已解锁 { _goUnlock.SetActive(true); _goLocked.SetActive(false); _goValid.SetActive(false); } else { _goUnlock.SetActive(false); _goValid.SetActive(false); _goLocked.SetActive(true); if (beauty != null) { _tmpRequired.text = string.Format(KLocalization.GetLocalString(60), beauty.gainWayText); } } } } private void OnGetBtnClick() { if (this.data is BusinessProxy.BusinessInfo affair) { BusinessProxy.Instance.GetBusinessRewards(affair, (error, message) => { UpdateRewards(affair, true); PostNotification(GlobalDefine.EVENT_MONEY_CHANGED); }); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnSeeBtnClick() { if (this.data is BusinessProxy.BusinessInfo affair) { KUIWindow.CloseWindow(); var beauty = BeautyProxy.Instance.GetBeauty(affair.beautyId); KUIWindow.OpenWindow(beauty); } SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnTravelBtnClick() { KUIWindow.CloseWindow(); PostNotification(GlobalDefine.EVENT_MAIN_WINDOW_PAGE, null, "0"); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void OnUnlockBtnClick() { if (BusinessProxy.Instance.UnlockBusiness(this.data as BusinessProxy.BusinessInfo)) Refresh(); SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND); } private void UpdateRewards(BusinessProxy.BusinessInfo affair, bool force = false) { if (affair.status == 2) { int accumS = affair.accumS; int totalS = affair.totalS; _sldProgress.value = accumS / (float)totalS; _tmpTimer.text = "" + F.Utils.Time.ToTimeString(accumS) + "/" + F.Utils.Time.ToTimeString(totalS); var results = F.ListPool.Get(); int state = affair.GetRewards(results); if (state > 0 || force) { __listRewards.Clear(); foreach (var reward in results) { __listRewards.GetItem().SetMoney(reward.id, reward.count); } } _btnGet.interactable = state >= 0; F.ListPool.Release(results); } } private void UpdateView() { if (this.data is BusinessProxy.BusinessInfo affair) { UpdateRewards(affair); } } #endregion #region Unity /// /// /// private void Awake() { SetViewData(); __listRewards.AddTemplate(true); _btnGet.onClick.AddListener(this.OnGetBtnClick); _btnUnlock.onClick.AddListener(this.OnUnlockBtnClick); _btnSee.onClick.AddListener(this.OnSeeBtnClick); _btnNotFriend.onClick.AddListener(this.OnTravelBtnClick); } float _lastUpdateTime; private void LateUpdate() { _lastUpdateTime += Time.deltaTime; if (_lastUpdateTime >= 1f) { _lastUpdateTime -= 1f; UpdateView(); } } #endregion } } }