using ET; using FairyGUI; using Hutool; using System.Collections.Generic; using UI.League; using UnityEngine; namespace GFGGame { public class LeagueTeaPartyView : BaseWindow { private UI_LeagueTeaPartyUI _ui; private List teapartyRoleCfg; private List TeaPartyItemObj = new List(); public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_LeagueTeaPartyUI.PACKAGE_NAME; _ui = UI_LeagueTeaPartyUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _ui.m_loaBg.url = ResPathUtil.GetDressUpPath("chahuibg"); _ui.m_btnBack.onClick.Add(OnBtnBackClick); _ui.m_btnChat.onClick.Add(OnBtnChatClick); _ui.m_btnChallenge.onClick.Add(OnBtnChallengeClick); _ui.m_btnReward.onClick.Add(OnBtnRewardClick); _ui.m_teaPartyItemTips.target.onClick.Add(OnTeaPartyItemTipsClick); _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView); _ui.m_btnRule.data = 300022; _ui.m_ListTeaParty.itemRenderer = ListTeaPartyItemRender; teapartyRoleCfg = TeapartyRoleCfgArray.Instance.GetCfgsByid(LeagueDataManager.Instance.TeaPartyId); } private void ListTeaPartyItemRender(int index, GObject obj) { TeaPartyItemObj.Add(obj); UI_comTeaPartyItem itemObj = UI_comTeaPartyItem.Proxy(obj); itemObj.m_btnDetail.data = index; itemObj.m_btnDetail.onClick.Add(OnBtnDetailClick); itemObj.m_iconRole.data = index; itemObj.m_iconRole.onClick.Add(OnBtnIconRoleClick); itemObj.m_txtRoleName.text = teapartyRoleCfg[index].name; var roleContainerList = LeagueDataManager.Instance.RoleContainerList; if (roleContainerList != null && roleContainerList.Count > 0) { itemObj.m_txtMaxValue.text = roleContainerList[index].MaxScore.ToString(); itemObj.m_txtNumber.text = roleContainerList[index].PerNum.ToString(); itemObj.m_txtMaxName.text = roleContainerList[index].MaxScoreRoleName; } var roleTeapartyInfo = LeagueDataManager.Instance.RoleTeapartyInfo; if (roleTeapartyInfo != null) itemObj.m_imgChoose.visible = index == (roleTeapartyInfo.TeapartyRoleId - 1); UI_comTeaPartyItem.ProxyEnd(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.TEA_PARTY_ROLE_CONTAINER, RefreshListTeaParty); EventAgent.AddEventListener(ConstMessage.TEA_PARTY_STATU, TeaPartyStatuChange); } protected override void OnShown() { base.OnShown(); var openCfg = TeapartyOpenCfgArray.Instance.GetCfg(LeagueDataManager.Instance.TeaPartyId); _ui.m_txtTeaName.text = openCfg.name; _ui.m_teaPartyItemTips.target.visible = false; int myPos = LeagueDataManager.Instance.GetMyPos(); bool isLeader = myPos == LeaguePos.Owner || myPos == LeaguePos.SubOwner; _ui.m_btnChallenge.visible = isLeader; GetTeapartyMatchingInfos(); GetRoleContainerInfos(); } protected override void OnHide() { base.OnHide(); QuitTeapparty(); Timers.inst.Remove(UpDataTime); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_ROLE_CONTAINER, RefreshListTeaParty); EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_STATU, TeaPartyStatuChange); } private async void QuitTeapparty() { bool result = await LeagueSproxy.QuitTeapparty(RoleDataManager.roleId); if (result) { } } private void OnBtnChatClick() { ViewManager.Show(); } private void OnBtnChallengeClick() { if (LeagueDataManager.Instance.TeaPartyStatus != 1) return; TeapartyStartChallenge(); } private async void TeapartyStartChallenge() { bool result = await LeagueSproxy.TeapartyStartChallenge(RoleDataManager.roleId); if (result) { ViewManager.Show(); } } private void OnBtnRewardClick() { ViewManager.Show(); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(LeagueView).FullName); } private void OnBtnDetailClick(EventContext context) { GObject obj = context.sender as GObject; int index = (int)obj.data; Vector2 pos = new Vector2(); if (index % 2 == 0) { pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position); pos.x = pos.x + TeaPartyItemObj[index].width; pos.y = pos.y + TeaPartyItemObj[index].height / 2; } else { pos = _ui.m_ListTeaParty.LocalToGlobal(TeaPartyItemObj[index].position); pos.x = pos.x - TeaPartyItemObj[index].width; pos.y = pos.y + TeaPartyItemObj[index].height / 2; } _ui.m_teaPartyItemTips.m_window.position = pos; _ui.m_teaPartyItemTips.target.visible = true; _ui.m_teaPartyItemTips.m_txtName.text = teapartyRoleCfg[index].name; _ui.m_teaPartyItemTips.m_txtDesc.text = teapartyRoleCfg[index].desc; } private void OnTeaPartyItemTipsClick() { _ui.m_teaPartyItemTips.target.visible = false; } private void OnBtnIconRoleClick(EventContext context) { if (LeagueDataManager.Instance.TeaPartyStatus != 1) return; GObject obj = context.sender as GObject; LeagueDataManager.Instance.ChooseTeaPartId = (int)obj.data + 1; DressUpFightType dressUpFightType = new DressUpFightType(); dressUpFightType.levelID = 0; dressUpFightType.teaPartID = LeagueDataManager.Instance.ChooseTeaPartId; ViewManager.Show(dressUpFightType, new object[] { typeof(LeagueTeaPartyView).FullName, null }, true); } private void UpDataTime(object param = null) { UpDataOverTime(); if (TimeInfo.Instance.ServerNow() >= LeagueDataManager.Instance.TeaPartyCloseTime) Timers.inst.Remove(UpDataTime); } private void UpDataOverTime() { _ui.m_txtOverTime.text = "挑战剩余时间:" + TimeUtil.GetTimeLeft(TimeInfo.Instance.ServerNow(), LeagueDataManager.Instance.TeaPartyCloseTime); } private async void GetTeapartyMatchingInfos() { bool result = await LeagueSproxy.GetTeapartyMatchingInfos(RoleDataManager.roleId); if (result) { RefreshListTeaParty(); } } private async void GetRoleContainerInfos() { bool result = await LeagueSproxy.GetRoleContainerInfos(RoleDataManager.roleId); if (result) { UpDataOverTime(); Timers.inst.Add(1f, 0, UpDataTime); RefreshListTeaParty(); } } private void RefreshListTeaParty() { _ui.m_ListTeaParty.numItems = teapartyRoleCfg.Count; } private void TeaPartyStatuChange() { if (LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo) { if (LeagueDataManager.Instance.RoleTeapartyInfo.Status) ViewManager.Show(); else OnBtnRewardClick(); } } } }