using UnityEngine; using FairyGUI; using UI.Friend; namespace GFGGame { public class FriendView : BaseView { private UI_FriendUI _ui; private GameObject _scenePrefab; private GameObject _sceneObject; private FriendInfoData _curSelectedInfo; public override void Dispose() { if (_sceneObject != null) { GameObject.Destroy(_sceneObject); _sceneObject = null; } if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void Init() { base.Init(); packageName = UI_FriendUI.PACKAGE_NAME; _ui = UI_FriendUI.Create(); viewCom = _ui.target; isfullScreen = true; _scenePrefab = GFGAsset.Load(ResPathUtil.GetPrefabPath("SceneFriend")); _ui.m_list.SetVirtual(); _ui.m_list.itemRenderer = RenderListItem; _ui.m_list.onClickItem.Add(OnListItemClick); _ui.m_btnSolgan.onClick.Add(OnBtnSloganClick); _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick); _ui.m_btnAdd.onClick.Add(OnBtnAddClick); _ui.m_btnSendAll.onClick.Add(OnBtnSendAllClick); } protected override void OnInit() { base.OnInit(); _ui.m_btnBack.onClick.Add(OnHide); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.FRIEND_REFRESH, RefreshView); EventAgent.AddEventListener(ConstMessage.FRIEND_REMOVE, RefreshRemoveFriend); EventAgent.AddEventListener(ConstMessage.FRIEND_ADD, RefreshAddFriend); EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot); } protected override void OnShown() { base.OnShown(); if (_sceneObject == null) { CustomSuitData customSuit = CustomSuitDataManager.GetSuitList(CustomSuitDataManager.currentIndex); _sceneObject = GameObject.Instantiate(_scenePrefab); EquipDataCache.cacher.setSceneObj(_sceneObject); EquipDataCache.cacher.AddOrRemove(customSuit.bg, true); } _ui.m_grpSlogan.visible = false; FriendDataManager.Instance.UpdateFriendList(true); _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count; if (_ui.m_list.numItems > 0) { _ui.m_list.selectedIndex = 0; ReqFriendDetialInfo(0); } else { ReqFriendDetialInfo(-1); } RefreshView(); UpdateRedDot(); } protected override void OnHide() { base.OnHide(); if (_sceneObject != null) { GameObject.Destroy(_sceneObject); _sceneObject = null; } _ui.m_list.numItems = 0; ViewManager.GoBackFrom(typeof(FriendView).FullName); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.FRIEND_REFRESH, RefreshView); EventAgent.RemoveEventListener(ConstMessage.FRIEND_REMOVE, RefreshRemoveFriend); EventAgent.RemoveEventListener(ConstMessage.FRIEND_ADD, RefreshAddFriend); EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot); } private void RefreshView() { _ui.m_list.RefreshVirtualList(); _ui.m_txtCount.text = string.Format("好友数:{0}/{1}", _ui.m_list.numItems, GlobalCfgArray.globalCfg.maxFriendCount); _ui.m_btnSendAll.text = RedDotDataManager.Instance.GetFriendGiftRed() ? "一键领取并赠送" : "一键赠送"; } private void RenderListItem(int index, GObject obj) { FriendInfoData friendInfo = FriendDataManager.Instance.FriendDatas[index]; UI_ListItem item = UI_ListItem.Proxy(obj); item.m_txtName.text = friendInfo.roleInfo.roleName; item.m_txtLvl.text = friendInfo.roleInfo.roleLv.ToString(); item.m_c2.selectedIndex = friendInfo.roleInfo.offlineTimeSec == 0 ? 0 : 1; item.m_c1.selectedIndex = FriendDataManager.Instance.GetGiftState(friendInfo.roleInfo.roleId); if (item.m_btnSend.data == null) { item.m_btnSend.onClick.Add(OnClickBtnSend); } item.m_btnSend.data = friendInfo; item.target.data = index; UI_ListItem.ProxyEnd(); } private void OnClickBtnSend(EventContext context) { GObject item = context.sender as GObject; FriendInfoData friendInfo = item.data as FriendInfoData; if (friendInfo.takeGiftState == ConstBonusStatus.CAN_GET) { // if (FriendDataManager.Instance.Count >= GlobalCfgArray.globalCfg.maxGetPowerCount) // { // PromptController.Instance.ShowFloatTextPrompt("今日体力已全部领取"); // return; // } FriendSProxy.ReqTakeGiftFromFriend(friendInfo.roleInfo.roleId).Coroutine(); } else if (friendInfo.giveGiftState == (int)ConstGiveGiftStatus.CanGave) { FriendSProxy.ReqGiveGiftToFriend(friendInfo.roleInfo.roleId).Coroutine(); } } private void OnListItemClick(EventContext context) { GObject item = context.data as GObject; int index = (int)item.data; ReqFriendDetialInfo(index); } private void OnBtnSendAllClick() { if (RedDotDataManager.Instance.GetFriendGiftRed() && FriendDataManager.Instance.Count < GlobalCfgArray.globalCfg.maxGetPowerCount) { FriendSProxy.ReqTakeGiftFromAllFriend().Coroutine(); } else { FriendSProxy.ReqGiveGiftToAllFriend().Coroutine(); } } private void OnBtnDeleteClick() { if (_ui.m_list.numItems == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无好友可删除"); return; } AlertUI.Show("是否删除好友?").SetLeftButton(true).SetRightButton(true, "确定", (object data) => { int index = _ui.m_list.selectedIndex; long roleId = FriendDataManager.Instance.FriendDatas[index].roleInfo.roleId; FriendSProxy.ReqDeleteFriend(roleId).Coroutine(); }); } private void RefreshRemoveFriend() { int index = _ui.m_list.selectedIndex; _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count; if (FriendDataManager.Instance.FriendDatas.Count > 0) { if (index >= FriendDataManager.Instance.FriendDatas.Count) { index = FriendDataManager.Instance.FriendDatas.Count - 1;//选中最后一个 } _ui.m_list.selectedIndex = index; } else { index = -1;//无好友 } ReqFriendDetialInfo(index); _ui.m_txtCount.text = string.Format("好友数:{0}/{1}", _ui.m_list.numItems, GlobalCfgArray.globalCfg.maxFriendCount); } private void RefreshAddFriend() { int selectedIndex = 0; if (_ui.m_list.numItems > 0) { int childIndex = _ui.m_list.ItemIndexToChildIndex(_ui.m_list.selectedIndex); GButton item = _ui.m_list.GetChildAt(childIndex).asButton.GetChild("btnSend").asButton; FriendInfoData friendInfo = item.data as FriendInfoData; selectedIndex = FriendDataManager.Instance.FriendDatas.IndexOf(friendInfo); } _ui.m_list.numItems = FriendDataManager.Instance.FriendDatas.Count; _ui.m_list.selectedIndex = selectedIndex; ReqFriendDetialInfo(selectedIndex); _ui.m_txtCount.text = string.Format("好友数:{0}/{1}", _ui.m_list.numItems, GlobalCfgArray.globalCfg.maxFriendCount); } private async void ReqFriendDetialInfo(int index) { if (index >= 0) { long roleId = FriendDataManager.Instance.FriendDatas[index].roleInfo.roleId; OtherRoleInfoDetailData roleInfoDetail = await RoleInfoSProxy.ReqOtherRoleDetailInfo(roleId); if (roleInfoDetail != null) { UpdateScene(roleInfoDetail.customSuitData); _ui.m_txtSlogan.text = string.IsNullOrEmpty(roleInfoDetail.slogan) ? "暂无简介" : roleInfoDetail.slogan; } } else { CustomSuitData customSuit = CustomSuitDataManager.GetSuitList(CustomSuitDataManager.currentIndex); UpdateScene(customSuit); _ui.m_txtSlogan.text = string.IsNullOrEmpty(RoleDataManager.slogan) ? "暂无简介" : RoleDataManager.slogan; } } private void UpdateScene(CustomSuitData suitSavedData) { if (suitSavedData != null) { EquipDataCache.cacher.PutOnSuitMemory(suitSavedData); _ui.m_txtName.text = string.Format("我的套装{0}", NumberUtil.GetChiniseNumberText(suitSavedData.pos + 1)); } else { EquipDataCache.cacher.PutOnDefaultSuitSaved(); _ui.m_txtName.text = string.Format("我的套装{0}", NumberUtil.GetChiniseNumberText(1)); } } private void OnBtnSloganClick() { _ui.m_grpSlogan.visible = !_ui.m_grpSlogan.visible; } private void OnBtnAddClick() { ViewManager.Show(); } private void UpdateRedDot() { RedDotController.Instance.SetComRedDot(_ui.m_btnAdd, RedDotDataManager.Instance.GetFriendApplyRed()); RedDotController.Instance.SetComRedDot(_ui.m_btnSendAll, RedDotDataManager.Instance.GetFriendGiftRed()); RefreshView(); } } }