miduo_client/Assets/ManagedResources/~Lua/Modules/GoodFriend/GoodFriendMainPanel.lua

722 lines
34 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
GoodFriendMainPanel = Inherit(BasePanel)
local this = GoodFriendMainPanel
local friendNumber = 0
local index = 1
--初始化组件(用于子类重写)
function GoodFriendMainPanel:InitComponent()
--this.BtView = SubUIManager.Open(SubUIConfig.BtView, self.gameObject.transform)
--this.BtView2 = SubUIManager.Open(SubUIConfig.BtView2, self.gameObject.transform)
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft })
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.friendListBtn = Util.GetGameObject(self.gameObject, "switchBtn/friendListBtn")
this.friendApplicationBtn = Util.GetGameObject(self.gameObject, "switchBtn/friendApplicationBtn")
this.friendSearchBtn = Util.GetGameObject(self.gameObject, "switchBtn/friendSearchBtn")
this.blackListBtn = Util.GetGameObject(self.gameObject, "switchBtn/blackListBtn")
this.friendListImage = Util.GetGameObject(self.gameObject, "switchBtn/friendListBtn/Image"):GetComponent("Image")
this.friendListText = Util.GetGameObject(self.gameObject, "switchBtn/friendListBtn/Text"):GetComponent("Text")
this.friendApplicationImage = Util.GetGameObject(self.gameObject, "switchBtn/friendApplicationBtn/Image"):GetComponent("Image")
this.friendApplicationText = Util.GetGameObject(self.gameObject, "switchBtn/friendApplicationBtn/Text"):GetComponent("Text")
this.friendSearchImage = Util.GetGameObject(self.gameObject, "switchBtn/friendSearchBtn/Image"):GetComponent("Image")
this.friendSearchText = Util.GetGameObject(self.gameObject, "switchBtn/friendSearchBtn/Text"):GetComponent("Text")
this.blackListImage = Util.GetGameObject(self.gameObject, "switchBtn/blackListBtn/Image"):GetComponent("Image")
this.blackListText = Util.GetGameObject(self.gameObject, "switchBtn/blackListBtn/Text"):GetComponent("Text")
this.blackListRemoveAllBtn=Util.GetGameObject(self.gameObject, "blackList/bottomImage/btn")
this.blackFriendNum=Util.GetGameObject(self.gameObject, "blackList/blackFriendNumber/blackFriendTextNumber"):GetComponent("Text")
this.friendList = Util.GetGameObject(self.gameObject, "friendList")
this.friendApplication = Util.GetGameObject(self.gameObject, "friendApplication")
this.friendSearch = Util.GetGameObject(self.gameObject, "friendSearch")
this.blackList = Util.GetGameObject(self.gameObject, "blackList")
this.item1 = Util.GetGameObject(self.gameObject, "friendList/item1")
this.item2 = Util.GetGameObject(self.gameObject, "friendApplication/item2")
this.item3 = Util.GetGameObject(self.gameObject, "friendSearch/item3")
this.item4 = Util.GetGameObject(self.gameObject, "blackList/item4")
this.friendListContentGrid = Util.GetGameObject(self.gameObject, "friendList/scrollRect")
this.friendApplicationContentGrid = Util.GetGameObject(self.gameObject, "friendApplication/scrollRect")
this.friendSearchContentGrid = Util.GetGameObject(self.gameObject, "friendSearch/scrollRect")
this.blackListContentGrid = Util.GetGameObject(self.gameObject, "blackList/scrollRect")
this.friendNumberText = Util.GetGameObject(self.gameObject, "friendList/friendNumber/friendTextNumber")
this.presentBtn = Util.GetGameObject(self.gameObject, "friendList/bottomImage/presentBtn")
this.receiveBtn = Util.GetGameObject(self.gameObject, "friendList/bottomImage/receiveBtn")
this.agreeAllBtn = Util.GetGameObject(self.gameObject, "friendApplication/bottomImage/agreeAllBtn")
this.refreshButton = Util.GetGameObject(self.gameObject, "refreshButton")
this.searchButton = Util.GetGameObject(self.gameObject, "friendSearch/bottomImage/searchButton")
this.searchUserNameText = Util.GetGameObject(self.gameObject, "friendSearch/bottomImage/InputField/roleNameSearchText"):GetComponent("Text")
this.roleImage1 = Util.GetGameObject(self.gameObject, "friendList/roleImage")
this.roleImage2 = Util.GetGameObject(self.gameObject, "friendApplication/roleImage")
this.roleImage3 = Util.GetGameObject(self.gameObject, "friendSearch/roleImage")
this.roleImage4 = Util.GetGameObject(self.gameObject, "blackList/roleImage")
this.roleTalk1 = Util.GetGameObject(self.gameObject, "friendList/roleImage/talkImage/Text"):GetComponent("Text")
this.roleTalk2 = Util.GetGameObject(self.gameObject, "friendApplication/roleImage/talkImage/Text"):GetComponent("Text")
this.roleTalk3 = Util.GetGameObject(self.gameObject, "friendSearch/roleImage/talkImage/Text"):GetComponent("Text")
this.roleTalk4 = Util.GetGameObject(self.gameObject, "blackList/roleImage/talkImage/Text"):GetComponent("Text")
this.titleText = Util.GetGameObject(self.gameObject, "friendSearch/titleBgImage/titleText"):GetComponent("Text")
this.haveGetRewardNumText=Util.GetGameObject(self.gameObject, "friendList/haveGetRewardNum/haveGetRewardNumText"):GetComponent("Text")
--GoodFriendManager.GetFriendInfoRequest(1)--1:好友, 2:推荐列表 3:申请列表
--GoodFriendManager.GetFriendInfoRequest(3)--1:好友, 2:推荐列表 3:申请列表
--GoodFriendManager.GetFriendInfoRequest(2)--1:好友, 2:推荐列表 3:申请列表
local v21 = this.friendListContentGrid:GetComponent("RectTransform").rect
this.ScrollView1 = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.friendListContentGrid.transform,
this.item1, nil, Vector2.New(-v21.x * 2, -v21.y * 2), 1, 1, Vector2.New(0, -4))
this.ScrollView1.moveTween.MomentumAmount = 1
this.ScrollView1.moveTween.Strength = 2
local v22 = this.friendApplicationContentGrid:GetComponent("RectTransform").rect
this.ScrollView2 = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.friendApplicationContentGrid.transform,
this.item2, nil, Vector2.New(-v22.x * 2, -v22.y * 2), 1, 1, Vector2.New(0, -4))
this.ScrollView2.moveTween.MomentumAmount = 1
this.ScrollView2.moveTween.Strength = 2
local v23 = this.friendSearchContentGrid:GetComponent("RectTransform").rect
this.ScrollView3 = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.friendSearchContentGrid.transform,
this.item3, nil, Vector2.New(-v23.x * 2, -v23.y * 2), 1, 1, Vector2.New(0, -4))
this.ScrollView3.moveTween.MomentumAmount = 1
this.ScrollView3.moveTween.Strength = 2
local v24 = this.blackListContentGrid:GetComponent("RectTransform").rect
this.ScrollView4 = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.blackListContentGrid.transform,
this.item4, nil, Vector2.New(-v24.x * 2, -v24.y * 2), 1, 1, Vector2.New(0, -4))
this.ScrollView4.moveTween.MomentumAmount = 1
this.ScrollView4.moveTween.Strength = 2
this.friendApplicationRedPoint = Util.GetGameObject(self.gameObject, "friendApplicationRedPoint")
this.friendListRedPoint = Util.GetGameObject(self.gameObject, "friendListRedPoint")
end
--绑定事件(用于子类重写)
function GoodFriendMainPanel:BindEvent()
Util.AddClick(this.btnBack, function()
self:ClosePanel()
--UIManager.OpenPanel(UIName.MainPanel)
end)
Util.AddClick(this.blackListRemoveAllBtn, function()
GoodFriendManager.RequestDeleteFromBlackList(0, function()
PopupTipPanel.ShowTip("移除成功!")
end)
end)
Util.AddClick(this.presentBtn, function()
local isCanPresent = false
for i, v in pairs(GoodFriendManager.friendAllData) do
if (v.isGive == 0) then
isCanPresent = true
end
end
if (isCanPresent == true) then
GoodFriendManager.FriendGivePresentRequest(2, 0)
else
PopupTipPanel.ShowTip("暂无可赠送好友")
end
end)
Util.AddClick(this.receiveBtn, function()
if (GoodFriendManager.MaxEnergyGet >= 1) then
local isCanGet = false
for i, v in pairs(GoodFriendManager.friendAllData) do
if (v.haveReward == 1) then
isCanGet = true
end
end
if (isCanGet == true) then
GoodFriendManager.FriendTakeHeartRequest(2, 0)
else
PopupTipPanel.ShowTip("暂无可领友情点")
end
else
PopupTipPanel.ShowTip("已达到友情点领取上限")
end
end)
Util.AddClick(this.agreeAllBtn, function()
if (table.nums(GoodFriendManager.friendAllData) < GoodFriendManager.goodFriendLimit) then
if (table.nums(GoodFriendManager.friendApplicationData) > 0) then
GoodFriendManager.FriendInviteOperationRequest(3, 0)
else
PopupTipPanel.ShowTip("暂无好友申请")
end
else
PopupTipPanel.ShowTip("好友列表已满")
end
end)
Util.AddClick(this.searchButton, function()
local userName = this.searchUserNameText.text
if (userName == "") then
PopupTipPanel.ShowTip("请输入角色姓名")
else
GoodFriendManager.FriendSearchRequest(userName)
end
this.isInRecommendPage = false
this.titleText.text = "搜索结果"
end)
Util.AddClick(this.refreshButton, function()
GoodFriendManager.RefreshRecommend(2)
this.titleText.text = "推荐好友"
this.isInRecommendPage = true
end)
Util.AddClick(this.friendListBtn, function()
this.BtnClickEvnet(1)
end)
Util.AddClick(this.friendApplicationBtn, function()
this.BtnClickEvnet(2)
end)
Util.AddClick(this.friendSearchBtn, function()
this.BtnClickEvnet(3)
end)
Util.AddClick(this.blackListBtn, function()
this.BtnClickEvnet(4)
end)
-- 绑定红点
BindRedPointObject(RedPointType.Friend_Reward, this.friendListRedPoint)
BindRedPointObject(RedPointType.Friend_Application, this.friendApplicationRedPoint)
end
--添加事件监听(用于子类重写)
function GoodFriendMainPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Friend.OnFriendList, this.FriendListDataShow)
Game.GlobalEvent:AddEvent(GameEvent.Friend.OnFriendApplication, this.FriendApplicationDataShow)
Game.GlobalEvent:AddEvent(GameEvent.Friend.OnFriendSearch, this.FriendSearchDataShow)
Game.GlobalEvent:AddEvent(GameEvent.Friend.OnBlackFriend, this.BlackListDataShow)
end
--移除事件监听(用于子类重写)
function GoodFriendMainPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Friend.OnFriendList, this.FriendListDataShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Friend.OnFriendApplication, this.FriendApplicationDataShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Friend.OnFriendSearch, this.FriendSearchDataShow)
Game.GlobalEvent:RemoveEvent(GameEvent.Friend.OnBlackFriend, this.BlackListDataShow)
end
--界面打开时调用(用于子类重写)
function GoodFriendMainPanel:OnOpen(...)
index = 1
local args = {...}
this.isBlackPage = args[1]
index = args[2] and args[2] or 1
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function GoodFriendMainPanel:OnShow()
--GoodFriendManager.OnRefreshDataNextDay()
this.roleImage1:SetActive(false)
this.roleImage2:SetActive(false)
this.roleImage3:SetActive(false)
this.roleImage4:SetActive(false)
this:FriendListDataShow()
this:FriendApplicationDataShow()
this:FriendSearchDataShow()
this:BlackListDataShow()
this.isInRecommendPage = true
this:OnRefreshData()
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.GoodFriend })
--this.BtView:OnOpen({ sortOrder = self.sortingOrder, panelType = PanelTypeView.RolePanel })
if(not this.isBlackPage) then
if(this.friendListRedPoint.activeSelf or (not this.friendApplicationRedPoint.activeSelf and not this.friendListRedPoint.activeSelf)) then
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendListText.text = "<color=#D0C3A6FF>好友</color>"
this.friendApplicationText.text = "<color=#A8A8A8FF>申请</color>"
this.friendSearchText.text = "<color=#A8A8A8FF>添加</color>"
this.blackListText.text = "<color=#A8A8A8FF>黑名单</color>"
this.friendList:SetActive(true)
this.friendApplication:SetActive(false)
this.friendSearch:SetActive(false)
this.blackList:SetActive(false)
else
this.friendList:SetActive(false)
this.friendApplication:SetActive(true)
this.friendSearch:SetActive(false)
this.blackList:SetActive(false)
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendListText.text = "<color=#A8A8A8FF>好友</color>"
this.friendApplicationText.text = "<color=#D0C3A6FF>申请</color>"
this.friendSearchText.text = "<color=#A8A8A8FF>添加</color>"
this.blackListText.text = "<color=#A8A8A8FF>黑名单</color>"
end
else
this.friendList:SetActive(false)
this.friendApplication:SetActive(false)
this.friendSearch:SetActive(false)
this.blackList:SetActive(true)
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.friendListText.text = "<color=#A8A8A8FF>好友</color>"
this.friendApplicationText.text = "<color=#A8A8A8FF>申请</color>"
this.friendSearchText.text = "<color=#A8A8A8FF>添加</color>"
this.blackListText.text = "<color=#D0C3A6FF>黑名单</color>"
end
--this.BtView2:OnOpen({ sortOrder = self.sortingOrder, panelType = PanelTypeView2.FriendPanel })
--this.friendNumberText:GetComponent("Text").text="好友数量:"..friendNumber.."/80"
this.BtnClickEvnet(index)
end
--刷新界面数据
function GoodFriendMainPanel:OnRefreshData()
if (table.nums(GoodFriendManager.friendAllData) <= 0) then
this.roleImage1:SetActive(true)
this.roleTalk1.text = "暂无好友"
else
this.roleImage1:SetActive(false)
end
if (table.nums(GoodFriendManager.friendApplicationData) <= 0) then
this.roleImage2:SetActive(true)
this.roleTalk2.text = "暂无好友申请"
else
this.roleImage2:SetActive(false)
end
if (table.nums(GoodFriendManager.friendSearchData) > 0) then
this.roleImage3:SetActive(false)
else
this.roleImage3:SetActive(true)
this.roleTalk3.text = "角色名不存在"
end
if (this.isInRecommendPage) then
this.roleTalk3.text = "暂无推荐好友"
end
if (table.nums(GoodFriendManager.blackFriendList) <= 0) then
this.roleImage4:SetActive(true)
else
this.roleImage4:SetActive(false)
end
end
--界面关闭时调用(用于子类重写)
function GoodFriendMainPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function GoodFriendMainPanel:OnDestroy()
SubUIManager.Close(this.UpView)
--SubUIManager.Close(this.BtView)
--SubUIManager.Close(this.BtView2)
ClearRedPointObject(RedPointType.Friend_Reward, this.friendListRedPoint)
ClearRedPointObject(RedPointType.Friend_Application, this.friendApplicationRedPoint)
this.ScrollView1 = nil
this.ScrollView2 = nil
this.ScrollView3 = nil
this.ScrollView4 = nil
end
--好友列表循环滚动数据
function GoodFriendMainPanel:FriendListDataShow()
CheckRedPointStatus(RedPointType.Friend_Reward)
this:OnRefreshData()
local list = {}
local j = 1
for i, v in pairs(GoodFriendManager.friendAllData) do
list[j] = v
if (table.nums(GoodFriendManager.friendAllData) > 1) then
if v.offLineTime == "0" then
list[j].onLineState = 1
else
list[j].onLineState = 2
end
end
j = j + 1
end
if (#list > 1) then
table.sort(list, function(a, b)
if a.onLineState == b.onLineState then
return tonumber(a.offLineTime) > tonumber(b.offLineTime)
else
return a.onLineState < b.onLineState
end
end)
end
this.ScrollView1:SetData(list, function(index, item)
local itemData = list[index]
this:FriendListRefreshData(item, itemData)
end)
this.friendNumberText:GetComponent("Text").text = "好友数量:" .. #list .. "/" .. GoodFriendManager.goodFriendLimit
this.haveGetRewardNumText.text="已领取: "..(GoodFriendManager.MaxEnergy-GoodFriendManager.MaxEnergyGet).."/"..GoodFriendManager.MaxEnergy
end
--好友申请循环滚动数据
function GoodFriendMainPanel:FriendApplicationDataShow()
-- 检测红点
CheckRedPointStatus(RedPointType.Friend_Application)
this:OnRefreshData()
local list = {}
local j = 1
for i, v in pairs(GoodFriendManager.friendApplicationData) do
list[j] = v
if (table.nums(GoodFriendManager.friendApplicationData) > 1) then
if v.offLineTime == "0" then
list[j].onLineState = 1
else
list[j].onLineState = 2
end
end
j = j + 1
end
if (#list >= 1) then
this.friendApplicationRedPoint:SetActive(true)
table.sort(list, function(a, b)
if a.onLineState == b.onLineState then
return tonumber(a.offLineTime) > tonumber(b.offLineTime)
else
return a.onLineState < b.onLineState
end
end)
else
this.friendApplicationRedPoint:SetActive(false)
end
this.ScrollView2:SetData(list, function(index, item)
local itemData = list[index]
this:FriendApplicationRefreshData(item, itemData)
end)
end
--好友搜索循环滚动数据
function GoodFriendMainPanel:FriendSearchDataShow()
this:OnRefreshData()
local list = {}
local j = 1
for i, v in pairs(GoodFriendManager.friendSearchData) do
list[j] = v
if (table.nums(GoodFriendManager.friendSearchData) > 1) then
if v.offLineTime == "0" then
list[j].onLineState = 1
else
list[j].onLineState = 2
end
end
j = j + 1
end
if (#list > 1) then
table.sort(list, function(a, b)
if a.onLineState == b.onLineState then
return tonumber(a.offLineTime) > tonumber(b.offLineTime)
else
return a.onLineState < b.onLineState
end
end)
end
this.ScrollView3:SetData(list, function(index, item)
local itemData = list[index]
this:FriendSearchRefreshData(item, itemData)
end)
end
--黑名单滚动数据
function GoodFriendMainPanel:BlackListDataShow()
this:OnRefreshData()
local list = {}
local j = 1
for i, v in pairs(GoodFriendManager.blackFriendList) do
list[j] = v
if (table.nums(GoodFriendManager.blackFriendList) > 1) then
if v.offLineTime == "0" then
list[j].onLineState = 1
else
list[j].onLineState = 2
end
end
j = j + 1
end
if (#list > 1) then
table.sort(list, function(a, b)
if a.onLineState == b.onLineState then
return tonumber(a.offLineTime) > tonumber(b.offLineTime)
else
return a.onLineState < b.onLineState
end
end)
end
this.ScrollView4:SetData(list, function(index, item)
local itemData = list[index]
this:BlackListRefreshData(item, itemData)
end)
this.blackFriendNum.text= "黑名单数:" .. #list .. "/" .. GoodFriendManager.blackFriendLimit
end
--好友
function GoodFriendMainPanel:FriendListRefreshData(item, itemData)
local head = Util.GetGameObject(item, "friendHeadIcon")
head:GetComponent("Image").sprite = GetPlayerHeadSprite(itemData.head)
Util.GetGameObject(item, "friendHeadIcon/friendHeadFrame"):GetComponent("Image").sprite = GetPlayerHeadFrameSprite(itemData.frame)
Util.GetGameObject(item, "Image/nameText"):GetComponent("Text").text = itemData.name
Util.GetGameObject(item, "lvbg/levelText"):GetComponent("Text").text = itemData.lv
local deleteFriendBtn = Util.GetGameObject(item, "deleteFriend")
local givingEnergyBtn = Util.GetGameObject(item, "givingEnergy")
local presentEnergyBtn = Util.GetGameObject(item, "presentEnergy")
local haveEnergyBtn = Util.GetGameObject(item, "havePresent")
local sendMessageBtn = Util.GetGameObject(item, "sendMessage")
if (itemData.offLineTime == "0") then
Util.GetGameObject(item, "Image/bg"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(false)
else
Util.GetGameObject(item, "Image/bg"):SetActive(false)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):GetComponent("Text").text = this:ShowTime(itemData.offLineTime)
end
if (GoodFriendManager.MaxEnergyGet >= 1) then
if (itemData.isGive == 0) then
Util.GetGameObject(item, "givingEnergy"):SetActive(false)
Util.GetGameObject(item, "presentEnergy"):SetActive(true)
Util.GetGameObject(item, "havePresent"):SetActive(false)
end
if (itemData.haveReward == 1) then
Util.GetGameObject(item, "givingEnergy"):SetActive(true)
Util.GetGameObject(item, "presentEnergy"):SetActive(false)
Util.GetGameObject(item, "havePresent"):SetActive(false)
Util.GetGameObject(item, "givingEnergy/givingEnergyRedPoint"):SetActive(true)
end
else
if (itemData.haveReward == 1) then
Util.GetGameObject(item, "givingEnergy"):SetActive(true)
Util.GetGameObject(item, "presentEnergy"):SetActive(false)
Util.GetGameObject(item, "havePresent"):SetActive(false)
Util.GetGameObject(item, "givingEnergy/givingEnergyRedPoint"):SetActive(false)
end
if (itemData.isGive == 0) then
Util.GetGameObject(item, "givingEnergy"):SetActive(false)
Util.GetGameObject(item, "presentEnergy"):SetActive(true)
Util.GetGameObject(item, "havePresent"):SetActive(false)
end
end
if (itemData.isGive == 1 and itemData.haveReward == 0) then
Util.GetGameObject(item, "givingEnergy"):SetActive(false)
Util.GetGameObject(item, "presentEnergy"):SetActive(false)
Util.GetGameObject(item, "havePresent"):SetActive(true)
end
Util.AddOnceClick(deleteFriendBtn, function()
local tip = string.format("确认将【%s】从好友列表删除吗", itemData.name)
MsgPanel.ShowTwo(tip, nil, function()
GoodFriendManager.DelFriendRequest(itemData.id)
end)
end)
Util.AddOnceClick(givingEnergyBtn, function()
if (GoodFriendManager.MaxEnergyGet >= 1) then
GoodFriendManager.FriendTakeHeartRequest(1, itemData.id)
else
PopupTipPanel.ShowTip("已达到友情点领取上限")
end
end)
Util.AddOnceClick(presentEnergyBtn, function()
GoodFriendManager.FriendGivePresentRequest(1, itemData.id)
end)
Util.AddOnceClick(haveEnergyBtn, function()
PopupTipPanel.ShowTip("已赠送过友情点给好友")
end)
Util.AddOnceClick(sendMessageBtn, function()
UIManager.OpenPanel(UIName.FriendChatPanel, itemData.id)
end)
Util.AddOnceClick(head, function()
UIManager.OpenPanel(UIName.PlayerInfoPopup, itemData.id)
end)
end
-- 好友申请
function GoodFriendMainPanel:FriendApplicationRefreshData(item, itemData)
local head = Util.GetGameObject(item, "friendHeadIcon")
head:GetComponent("Image").sprite = GetPlayerHeadSprite(itemData.head)
Util.GetGameObject(item, "friendHeadIcon/friendHeadFrame"):GetComponent("Image").sprite = GetPlayerHeadFrameSprite(itemData.frame)
item.gameObject:SetActive(true)
Util.GetGameObject(item, "Image/nameText"):GetComponent("Text").text = itemData.name
Util.GetGameObject(item, "lvbg/levelText"):GetComponent("Text").text = itemData.lv
local agreeBtn = Util.GetGameObject(item, "agree")
local refuseBtn = Util.GetGameObject(item, "refuse")
if (itemData.offLineTime == "0") then
Util.GetGameObject(item, "Image/bg"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(false)
else
Util.GetGameObject(item, "Image/bg"):SetActive(false)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):GetComponent("Text").text = this:ShowTime(itemData.offLineTime)
end
Util.AddOnceClick(agreeBtn, function()
if GoodFriendManager.IsInBlackList(itemData.id) then
PopupTipPanel.ShowTip("该玩家在黑名单列表中")
return
end
if (table.nums(GoodFriendManager.friendAllData) < GoodFriendManager.goodFriendLimit) then
GoodFriendManager.FriendInviteOperationRequest(1, itemData.id)
else
PopupTipPanel.ShowTip("好友列表已满")
end
end)
Util.AddOnceClick(refuseBtn, function()
GoodFriendManager.FriendInviteOperationRequest(2, itemData.id)
end)
Util.AddOnceClick(head, function()
UIManager.OpenPanel(UIName.PlayerInfoPopup, itemData.id)
end)
end
-- 好友搜索
function GoodFriendMainPanel:FriendSearchRefreshData(item, itemData)
local head = Util.GetGameObject(item, "friendHeadIcon")
head:GetComponent("Image").sprite = GetPlayerHeadSprite(itemData.head)
Util.GetGameObject(item, "friendHeadIcon/friendHeadFrame"):GetComponent("Image").sprite = GetPlayerHeadFrameSprite(itemData.frame)
Util.GetGameObject(item, "Image/nameText"):GetComponent("Text").text = itemData.name
Util.GetGameObject(item, "lvbg/levelText"):GetComponent("Text").text = itemData.lv
local applicationFriendBtn = Util.GetGameObject(item, "applicationFriend")
local applicationFriendText = Util.GetGameObject(item, "applicationFriend/applicationFriendText"):GetComponent("Text")
if (itemData.offLineTime == "0") then
Util.GetGameObject(item, "Image/bg"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(false)
else
Util.GetGameObject(item, "Image/bg"):SetActive(false)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):GetComponent("Text").text = this:ShowTime(itemData.offLineTime)
end
local isFriend = GoodFriendManager.IsMyFriend(itemData.id)
if isFriend then
Util.SetGray(applicationFriendBtn, true)
applicationFriendText.text = "已是好友"
elseif itemData.isApplyed == 1 then
Util.SetGray(applicationFriendBtn, true)
applicationFriendText.text = "已申请"
else
Util.SetGray(applicationFriendBtn, false)
applicationFriendText.text = "申请好友"
end
Util.AddOnceClick(applicationFriendBtn, function()
if isFriend then
PopupTipPanel.ShowTip("对方已经是您好友")
return
end
if itemData.isApplyed == 1 then
PopupTipPanel.ShowTip("已经申请过的好友")
return
end
if (table.nums(GoodFriendManager.friendAllData) >= GoodFriendManager.goodFriendLimit) then
PopupTipPanel.ShowTip("好友列表已满")
return
end
if GoodFriendManager.IsInBlackList(itemData.id) then
PopupTipPanel.ShowTip("该玩家在黑名单列表中")
return
end
GoodFriendManager.InviteFriendRequest(itemData.id,function ()
PopupTipPanel.ShowTip("申请成功")
end)
end)
Util.AddOnceClick(head, function()
UIManager.OpenPanel(UIName.PlayerInfoPopup, itemData.id)
end)
end
-- 黑名单
function GoodFriendMainPanel:BlackListRefreshData(item, itemData)
local head = Util.GetGameObject(item, "friendHeadIcon")
head:GetComponent("Image").sprite = GetPlayerHeadSprite(itemData.head)
Util.GetGameObject(item, "friendHeadIcon/friendHeadFrame"):GetComponent("Image").sprite = GetPlayerHeadFrameSprite(itemData.frame)
Util.GetGameObject(item, "Image/nameText"):GetComponent("Text").text = itemData.name
Util.GetGameObject(item, "lvbg/levelText"):GetComponent("Text").text = itemData.lv
if (itemData.offLineTime == "0") then
Util.GetGameObject(item, "Image/bg"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(false)
else
Util.GetGameObject(item, "Image/bg"):SetActive(false)
Util.GetGameObject(item, "Image/lastOnlineText"):SetActive(true)
Util.GetGameObject(item, "Image/lastOnlineText"):GetComponent("Text").text = this:ShowTime(itemData.offLineTime)
end
local removeBlackListBtn = Util.GetGameObject(item, "deleteFriend")
Util.AddOnceClick(removeBlackListBtn, function()
GoodFriendManager.RequestDeleteFromBlackList(itemData.id, function()
PopupTipPanel.ShowTip("移除成功!")
end)
end)
Util.AddOnceClick(head, function()
UIManager.OpenPanel(UIName.PlayerInfoPopup, itemData.id, PLAYER_INFO_VIEW_TYPE.BLACK_REMOVE)
end)
end
--格式化时间
function GoodFriendMainPanel:ShowTime(time)
local onlineTime = math.floor(PlayerManager.serverTime - time / 1000)
local timeText = ""
if (onlineTime < 60) then
timeText = "刚刚"
return timeText
elseif (onlineTime >= 60 and onlineTime < 3600) then
timeText = math.floor(onlineTime / 60) .. "分钟前"
return timeText
elseif (onlineTime >= 3600 and onlineTime < 3600 * 24) then
timeText = math.floor(onlineTime / 3600) .. "小时前"
return timeText
elseif (onlineTime >= 3600 * 24 and onlineTime <= 3600 * 24 * 30) then
timeText = math.floor(onlineTime / (3600 * 24)) .. "天前"
return timeText
elseif (onlineTime > 3600 * 24 * 30) then
timeText = "30天以上"
return timeText
end
end
function this.BtnClickEvnet(index)
if index == 1 then
this.friendList:SetActive(true)
this.friendApplication:SetActive(false)
this.friendSearch:SetActive(false)
this.blackList:SetActive(false)
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendListText.text = "<color=#D0C3A6FF>好友</color>"
this.friendApplicationText.text = "<color=#A8A8A8FF>申请</color>"
this.friendSearchText.text = "<color=#A8A8A8FF>添加</color>"
this.blackListText.text = "<color=#A8A8A8FF>黑名单</color>"
GoodFriendManager.RefreshFriendStateRequest()
elseif index == 2 then
this.friendList:SetActive(false)
this.friendApplication:SetActive(true)
this.friendSearch:SetActive(false)
this.blackList:SetActive(false)
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendListText.text = "<color=#A8A8A8FF>好友</color>"
this.friendApplicationText.text = "<color=#D0C3A6FF>申请</color>"
this.friendSearchText.text = "<color=#A8A8A8FF>添加</color>"
this.blackListText.text = "<color=#A8A8A8FF>黑名单</color>"
elseif index == 3 then
this.friendList:SetActive(false)
this.friendApplication:SetActive(false)
this.friendSearch:SetActive(true)
this.blackList:SetActive(false)
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendListText.text = "<color=#A8A8A8FF>好友</color>"
this.friendApplicationText.text = "<color=#A8A8A8FF>申请</color>"
this.friendSearchText.text = "<color=#D0C3A6FF>添加</color>"
this.blackListText.text = "<color=#A8A8A8FF>黑名单</color>"
GoodFriendManager.RefreshRecommend(2)
elseif index == 4 then
this.friendList:SetActive(false)
this.friendApplication:SetActive(false)
this.friendSearch:SetActive(false)
this.blackList:SetActive(true)
this.friendListImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendApplicationImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.friendSearchImage.sprite = Util.LoadSprite("r_hero_xuanze_002")
this.blackListImage.sprite = Util.LoadSprite("r_hero_xuanze_001")
this.friendListText.text = "<color=#A8A8A8FF>好友</color>"
this.friendApplicationText.text = "<color=#A8A8A8FF>申请</color>"
this.friendSearchText.text = "<color=#A8A8A8FF>添加</color>"
this.blackListText.text = "<color=#D0C3A6FF>黑名单</color>"
GoodFriendManager.RefreshRecommend(4)
end
end
return GoodFriendMainPanel