using System; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class FairySiegeBasePrepWin : Window { [SerializeField] FairySiegeStarGroup baseStarGroup; [SerializeField] ButtonEx btnHighDonation; [SerializeField] ButtonEx btnLowDonation; [SerializeField] ScrollerController scrHighReward; [SerializeField] ScrollerController scrLowReward; [SerializeField] Slider slidBase; [SerializeField] Text txtSlidExp; [SerializeField] ImageEx imgBase; [SerializeField] TextEx txtLV; [SerializeField] TextEx txtResNext; [SerializeField] TextEx txtResNow; [SerializeField] TextEx txtTip; [SerializeField] ButtonEx btnLvInfo; [SerializeField] Transform transHigh; [SerializeField] ImageEx imgHighDonateItem; [SerializeField] TextEx txtHighDonateMoneyCnt; [SerializeField] TextEx txtHighDonationName; [SerializeField] TextEx txtHighRemainDonateCnt; [SerializeField] Transform transLow; [SerializeField] TextEx txtLowDonateMoneyCnt; [SerializeField] TextEx txtLowDonationCnt; [SerializeField] TextEx txtLowDonationName; [SerializeField] ImageEx imgNoLowDonationCnt; [SerializeField] ImageEx imgLowDonateMoneyType; [SerializeField] RedpointBehaviour rpLowDonation; [SerializeField] RedpointBehaviour rpHighDonation; FairySiegeActModel model { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } #region Build-in protected override void AddListeners() { btnLowDonation.SetListener(LowDonationClick); btnHighDonation.SetListener(HighDonationClick); btnLvInfo.SetListener(() => WindowCenter.Instance.Open()); } protected override void BindController() { } protected override void OnPreOpen() { rpLowDonation.redpointId = model.GetRedpointId(FairySiegeRedPointType.BaseLowContribution); rpHighDonation.redpointId = model.GetRedpointId(FairySiegeRedPointType.BaseHighContribution); scrLowReward.OnRefreshCell += OnRefreshLowRewardCell; scrHighReward.OnRefreshCell += OnRefreshHighRewardCell; PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent; packModel.refreshItemCountEvent += OnRefreshItemCountEvent; model.UpdateCampInfoEvent += OnUpdateCampInfoEvent; model.UpdateFamilyGCZPlayerInfoEvent += OnUpdateFamilyGCZPlayerInfoEvent; GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; ShowPrep(); } protected override void OnPreClose() { scrLowReward.OnRefreshCell -= OnRefreshLowRewardCell; scrHighReward.OnRefreshCell -= OnRefreshHighRewardCell; PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent; packModel.refreshItemCountEvent -= OnRefreshItemCountEvent; model.UpdateCampInfoEvent -= OnUpdateCampInfoEvent; model.UpdateFamilyGCZPlayerInfoEvent -= OnUpdateFamilyGCZPlayerInfoEvent; GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; } private void OnSecondEvent() { txtTip.SetActive(model.matchRound == model.matchRoundMax && model.TryGetCurrentStateValue(out int stateValue) && model.GetStateByStateValue(stateValue) >= 2); } private void OnUpdateFamilyGCZPlayerInfoEvent() { ShowPrep(); } private void OnUpdateCampInfoEvent() { ShowPrep(); } protected override void OnAfterOpen() { } protected override void OnAfterClose() { } #endregion private void OnPlayerDataRefreshEvent(PlayerDataType type) { if (type != PlayerDataType.GoldPaper) return; ShowPrep(); } private void OnRefreshItemCountEvent(PackType type, int arg2, int arg3) { if (type != PackType.Item && arg3 != model.highDonateItemId) return; ShowPrep(); } private void OnRefreshLowRewardCell(ScrollerDataType type, CellView cell) { var _cell = cell.GetComponent(); _cell?.Display(cell.index); } private void OnRefreshHighRewardCell(ScrollerDataType type, CellView cell) { var _cell = cell.GetComponent(); _cell?.Display(cell.index); } private void CreateLowRewardScroller() { scrLowReward.Refresh(); var list = model.GetAllUniqueItemIDs(model.lowDonateRewardDict); if (!list.IsNullOrEmpty()) { for (var i = 0; i < list.Count; i++) { scrLowReward.AddCell(ScrollerDataType.Header, i); } } scrLowReward.Restart(); } private void CreateHighRewardScroller() { scrHighReward.Refresh(); var list = model.GetAllUniqueItemIDs(model.highDonateRewardDict); if (!list.IsNullOrEmpty()) { for (var i = 0; i < list.Count; i++) { scrHighReward.AddCell(ScrollerDataType.Header, i); } } scrHighReward.Restart(); } private void DisplayBaseInfo() { if (!FamilyGCZCampLVConfig.Has(model.myCampLV)) { DebugEx.LogError($"X.仙盟攻城战大本营等级表 中没有找到当前大本营等级:{model.myCampLV}"); return; } FamilyGCZCampLVConfig config = FamilyGCZCampLVConfig.Get(model.myCampLV); txtLV.text = Language.Get("FashionDress106", model.myCampLV); float fillAmount = Mathf.Round((float)model.myCampExp / config.LVUPNeedExp * 1000f) / 1000f; string info = Language.Get("FairySiege125", model.myCampExp, config.LVUPNeedExp); slidBase.value = fillAmount; txtSlidExp.text = info; baseStarGroup.Display(config.StarCount); txtResNow.text = Language.Get("FairySiege056", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege140", config.AddHPPer))); bool hasNext = model.TryGetNextHPPer(model.myCampLV, out int nextAddHPPer); txtResNext.text = Language.Get("FairySiege057", hasNext ? UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege140", nextAddHPPer)) : Language.Get("HallTipsWin__5")); } public int GetNowExp() { if (!FamilyGCZCampLVConfig.Has(model.myCampLV)) return 0; var list = FamilyGCZCampLVConfig.GetKeys().Select(s => int.Parse(s)).ToList(); list.Sort(); int index = list.IndexOf(model.myCampLV); if (index == -1) return 0; int res = (int)model.myCampExp; for (int i = 0; i < index; i++) { res -= FamilyGCZCampLVConfig.Get(list[i]).LVUPNeedExp; } return res; } public void ShowPrep() { transLow.SetActive(model.lowDonateMoneyType > 0); DisplayBaseInfo(); bool hasLowDonationCnt = model.TryGetNeedMoney(out int needMoney); imgNoLowDonationCnt.SetActive(!hasLowDonationCnt); btnLowDonation.SetActive(hasLowDonationCnt); imgLowDonateMoneyType.SetActive(hasLowDonationCnt); txtLowDonateMoneyCnt.SetActive(hasLowDonationCnt); imgLowDonateMoneyType.SetIconWithMoneyType(model.lowDonateMoneyType); txtLowDonationName.text = Language.Get("FairySiege052", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege054", model.lowDonateOnceExpAdd))); int remainLowDonationCnt = model.lowDonateMaxCnt - model.contributionCnt; txtLowDonationCnt.text = Language.Get("FairySiege053", UIHelper.AppendColor(remainLowDonationCnt > 0 ? TextColType.DarkGreen : TextColType.Red, remainLowDonationCnt.ToString())); var hasMoney = UIHelper.GetMoneyCnt(model.lowDonateMoneyType); txtLowDonateMoneyCnt.text = UIHelper.AppendColor(hasMoney >= (ulong)needMoney ? TextColType.DarkGreen : TextColType.Red, StringUtility.Contact(UIHelper.ReplaceLargeNum(hasMoney), "/", needMoney)); CreateLowRewardScroller(); txtHighDonationName.text = Language.Get("FairySiege089", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege054", model.highDonateOnceExpAdd))); txtHighRemainDonateCnt.text = Language.Get("FairySiege053", UIHelper.AppendColor(TextColType.DarkGreen, Language.Get("FairySiege119"))); imgHighDonateItem.SetSprite(ItemConfig.Get(model.highDonateItemId).IconKey); var hasItemCnt = packModel.GetItemCountByID(PackType.Item, model.highDonateItemId); txtHighDonateMoneyCnt.text = UIHelper.AppendColor(hasItemCnt > 0 ? TextColType.DarkGreen : TextColType.Red, StringUtility.Contact(UIHelper.ReplaceLargeNum(hasItemCnt), "/", 1)); CreateHighRewardScroller(); OnSecondEvent(); } private void LowDonationClick() { if (model.myCityHP <= 0) { SysNotifyMgr.Instance.ShowTip("FairySiege05"); return; } //货币数量不足 var hasMoney = UIHelper.GetMoneyCnt(model.lowDonateMoneyType); if (model.TryGetNeedMoney(out int needMoney)) { if (hasMoney < (ulong)needMoney) { SysNotifyMgr.Instance.ShowTip("FairySiege03"); return; } } model.nowContiributionType = 0; model.SendContribution(0, (uint)needMoney); } private void HighDonationClick() { //我方大本营已被摧毁 var familyId = (int)PlayerDatas.Instance.baseData.FamilyId; if (model.myCityHP <= 0) { SysNotifyMgr.Instance.ShowTip("FairySiege05"); return; } WindowCenter.Instance.Open(); } } }