123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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> teapartyRoleCfg;
- private List<GObject> TeaPartyItemObj = new List<GObject>();
- Dictionary<int, int> TeapartyRoleIdList = new Dictionary<int, int>();
- 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;
- isReturnView = true;
- _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("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;
- }
- 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);
- var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
- itemObj.m_iconRole.data = index;
- itemObj.m_iconRole.onClick.Add(OnBtnIconRoleClick);
- itemObj.m_txtRoleName.text = teapartyRoleCfg[index].name;
- 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 headItemId = roleContainerList[index].HeadItemId;
- ItemCfg itemHeadCfg = ItemCfgArray.Instance.GetCfg(5000001);
- if (headItemId > 0)
- {
- itemHeadCfg = ItemCfgArray.Instance.GetCfg(headItemId);
- }
- itemObj.m_iconRole.url = ResPathUtil.GetHeadPath(itemHeadCfg.res);
- var headBorderItemId = roleContainerList[index].HeadBorderItemId;
- ItemCfg itemBorderCfg = ItemCfgArray.Instance.GetCfg(5005001);
- if (headBorderItemId > 0)
- {
- itemBorderCfg = ItemCfgArray.Instance.GetCfg(headBorderItemId);
- }
- itemObj.m_iconRoleBg.url = ResPathUtil.GetHeadBorderPath(itemBorderCfg.res);
- }
- 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);
- EventAgent.AddEventListener(ConstMessage.TEA_PARTY_REWARD, ReferBtnRewardRed);
- }
- protected override void OnShown()
- {
- base.OnShown();
- teapartyRoleCfg = TeapartyRoleCfgArray.Instance.GetCfgsByid(LeagueDataManager.Instance.TeaPartyId);
- 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;
- _ui.m_btnChallenge.grayed = LeagueDataManager.Instance.TeaPartyStatus != LeagueTeaPartyStatus.YesOpen;
- GetTeapartyMatchingInfos();
- GetRoleContainerInfos();
- ReferBtnRewardRed();
- if (LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo
- && LeagueDataManager.Instance.CheckTeaPartyRewardCanGet())
- OnBtnRewardClick();
- }
- protected override void OnHide()
- {
- Timers.inst.Remove(UpDataTime);
- QuitTeapparty();
- base.OnHide();
- }
- protected override void RemoveEventListener()
- {
- base.RemoveEventListener();
- EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_ROLE_CONTAINER, RefreshListTeaParty);
- EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_STATU, TeaPartyStatuChange);
- EventAgent.RemoveEventListener(ConstMessage.TEA_PARTY_REWARD, ReferBtnRewardRed);
- }
- private async void QuitTeapparty()
- {
- bool result = await LeagueSproxy.QuitTeapparty(RoleDataManager.roleId);
- if (result)
- {
- }
- }
- private void OnBtnChatClick()
- {
- ViewManager.Show<LeagueChatView>();
- }
- private void OnBtnChallengeClick()
- {
- if (LeagueDataManager.Instance.TeaPartyStatus != LeagueTeaPartyStatus.YesOpen)
- return;
- string strAlertText = "";
- var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
- int countRoleId = 0;
- TeapartyRoleIdList.Clear();
- foreach (var info in roleContainerList) {
- if (info.PerNum <= 0) {
- TeapartyRoleIdList.Add(countRoleId,info.TeapartyRoleId);
- countRoleId += 1;
- }
- }
- if (TeapartyRoleIdList.Count > 0) {
- string strRoleName = "";
- for (int index = 0; index < TeapartyRoleIdList.Count; index++) {
- strRoleName = strRoleName + teapartyRoleCfg[TeapartyRoleIdList[index]-1].name;
- if (index < TeapartyRoleIdList.Count - 1)
- strRoleName = strRoleName + "、";
- }
- strAlertText = string.Format("茶话会角色:[color=#FF0000]{0}[/color]参与人数不足,确认是否开启!", strRoleName);
- }
- else
- strAlertText = "是否开启茶话会?";
- AlertUI.Show(strAlertText)
- .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
- {
- TeapartyStartChallenge();
- });
- }
- private async void TeapartyStartChallenge()
- {
- bool result = await LeagueSproxy.TeapartyStartChallenge(RoleDataManager.roleId);
- if (result)
- {
- _ui.m_btnChallenge.grayed = LeagueDataManager.Instance.TeaPartyStatus != LeagueTeaPartyStatus.YesOpen;
- TeaPartyStatuChange();
- }
- }
- private void OnBtnRewardClick()
- {
- ViewManager.Show<LeagueTeaPartyRewardView>();
- }
- private void OnBtnBackClick()
- {
- ViewManager.GoBackFrom(typeof(LeagueTeaPartyView).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<DressUpFightView>(dressUpFightType, true);
- }
- private void UpDataTime(object param = null)
- {
- UpDataOverTime();
- if (TimeInfo.Instance.ServerNow() >= LeagueDataManager.Instance.TeaPartyCloseTime)
- Timers.inst.Remove(UpDataTime);
- }
- private void UpDataOverTime()
- {
- string strTimeText = "挑战剩余时间:";
- if(LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo)
- strTimeText = "公开剩余时间:";
- _ui.m_txtOverTime.text = strTimeText + 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()
- {
- ReferBtnRewardRed();
- if (LeagueDataManager.Instance.TeaPartyStatus == LeagueTeaPartyStatus.YesGo) {
- if (LeagueDataManager.Instance.RoleTeapartyInfo.Status && !LeagueDataManager.Instance.RoleTeapartyInfo.IsComplete) {
- ViewManager.Show<LeagueTeaPartyShowView>();
- }
- else if(LeagueDataManager.Instance.CheckTeaPartyRewardCanGet())
- OnBtnRewardClick();
- }
- }
- private void ReferBtnRewardRed()
- {
- RedDotController.Instance.SetComRedDot(_ui.m_btnReward, LeagueDataManager.Instance.CheckTeaPartyRewardCanGet(), "", 0);
- }
- }
- }
|