--快速密聊界面
|
|
CecretView = CecretView or BaseClass(BaseView)
|
|
function CecretView:__init()
|
|
self.base_file = "chat"
|
|
self.layout_file = "cecretView"
|
|
self.layer_name = "UI"
|
|
self.use_background = true
|
|
self.click_bg_toClose = true
|
|
self.model = ChatModel:getInstance()
|
|
self.memberVo = nil
|
|
self.friendVo = nil
|
|
self.cur_selected_index = 0
|
|
self.tabbar_list = {}
|
|
self.cecret_item_list = {}
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
self:SwitchBar(1)
|
|
end
|
|
self.destroy_callback = function ()
|
|
self:Clear()
|
|
end
|
|
end
|
|
|
|
-- function cecretView:Close()
|
|
-- BaseView:Close(self)
|
|
-- end
|
|
|
|
function CecretView:Clear()
|
|
for i,item in ipairs(self.cecret_item_list) do
|
|
item:DeleteMe()
|
|
end
|
|
self.cecret_item_list = {}
|
|
|
|
if self.member_id then
|
|
self.model:UnBind(self.member_id)
|
|
self.member_id = nil
|
|
end
|
|
|
|
if self.friend_id then
|
|
self.model:UnBind(self.friend_id)
|
|
self.friend_id = nil
|
|
end
|
|
|
|
end
|
|
|
|
function CecretView:LoadSuccess()
|
|
self.scrollView = self:GetChild("Window/ScrollView")
|
|
self.scroll_content = self:GetChild("Window/ScrollView/Viewport/Content")
|
|
self.closeBtn = self:GetChild("Window/winBg/closeBtn").gameObject
|
|
for i = 1, 2 do
|
|
table.insert(self.tabbar_list,self:GetChild("Window/tarbarCon/btn"..i).gameObject)
|
|
end
|
|
end
|
|
|
|
function CecretView:InitEvent()
|
|
local function onTarBtnClickHandler(target)
|
|
local index = string.gsub(target.name,"btn","")
|
|
self:SwitchBar(tonumber(index))
|
|
end
|
|
for i = 1, 2 do
|
|
AddClickEvent(self.tabbar_list[i],onTarBtnClickHandler)
|
|
end
|
|
local function onBtnClickHandler(target)
|
|
if target == self.closeBtn then
|
|
self:Close()
|
|
end
|
|
end
|
|
AddClickEvent(self.closeBtn,onBtnClickHandler)
|
|
|
|
local function onRefreshFriendList(vo)
|
|
self:SetFriendList(vo)
|
|
end
|
|
self.friend_id = self.model:Bind(ChatModel.REFRESH_FRIEND,onRefreshFriendList)
|
|
|
|
local function onRefreshMemberList(vo)
|
|
self:SetMemberList(vo)
|
|
end
|
|
self.member_id = self.model:Bind(ChatModel.REFRESH_MEMBER,onRefreshMemberList)
|
|
|
|
end
|
|
|
|
function CecretView:SwitchBar(index)
|
|
if self.cur_selected_index == index then return end
|
|
self.cur_selected_index = index
|
|
if index == 1 then
|
|
--获取所有好友信息 --获取关系列表 1好友,2仇人,3黑名单
|
|
GlobalEventSystem:Fire(SocialityModel.GET_RELATIONSHIP_LIST,1)
|
|
elseif index == 2 then
|
|
--获取所有社团成员信息 --多少个成员(100最大),页号,排序类型,排序标识,成员类型,特殊类型 --40006协议
|
|
-- GuildModel:getInstance():Fire(GuildModel.RequestMainViewMemberInfoEvt,100,1,5,0,1,0)
|
|
end
|
|
end
|
|
|
|
function CecretView:SetFriendList(vo)
|
|
-- PrintTable(vo)
|
|
if not vo then return end
|
|
if not vo.rela_list then return end
|
|
self.friendVo = vo
|
|
self:SetItemList(vo.rela_list)
|
|
end
|
|
|
|
function CecretView:SetMemberList(vo)
|
|
-- PrintTable(vo)
|
|
if not vo then return end
|
|
if not vo.member_list then return end
|
|
self.memberVo = vo
|
|
self:SetItemList(vo.member_list)
|
|
end
|
|
|
|
function CecretView:SetItemList(list)
|
|
local item = nil
|
|
local item_len = #self.cecret_item_list
|
|
--移除自己和密聊列表已有的人
|
|
local tmp_list = {}
|
|
for i=1,#list do
|
|
if list[i].role_id ~= RoleManager.Instance:GetMainRoleId() then
|
|
if self:IsSameInCecretChatList(list[i]) == false then
|
|
table.insert(tmp_list,list[i])
|
|
end
|
|
end
|
|
end
|
|
|
|
if item_len > #tmp_list then
|
|
for i=1,item_len - #tmp_list do
|
|
local t = self.cecret_item_list[i]
|
|
t:SetVisible(false)
|
|
end
|
|
elseif item_len < #tmp_list then
|
|
for i=1,#tmp_list - item_len do
|
|
item = CecretShowItem.New(self.scroll_content)
|
|
table.insert(self.cecret_item_list,item)
|
|
end
|
|
end
|
|
for i,v in ipairs(tmp_list) do
|
|
self.cecret_item_list[i]:SetData(i,v)
|
|
self.cecret_item_list[i]:SetVisible(true)
|
|
end
|
|
self.scroll_content.sizeDelta = Vector2(460,math.min(440,#self.cecret_item_list * 100))
|
|
end
|
|
|
|
function CecretView:IsSameInCecretChatList(vo)
|
|
for i,v in ipairs(self.model.cecret_chat_list) do
|
|
if vo.role_id == v.player_id or vo.role_id == v.key_id then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|