153 lines
4.7 KiB
Lua
153 lines
4.7 KiB
Lua
-- 牌友圈助手界面
|
|
local FGAssistInviteView = import(".FGAssistInviteView")
|
|
|
|
local FGAssistView = {}
|
|
|
|
local M = FGAssistView
|
|
setmetatable(M, {__index = BaseWindow})
|
|
|
|
function FGAssistView.new(blur_view, callback)
|
|
|
|
local self = setmetatable({}, {__index = M})
|
|
self.class = "FGAssistView"
|
|
self._blur_view = blur_view
|
|
self._full = true
|
|
self._anim_pop = 1
|
|
self._animation = true
|
|
|
|
self.callback = callback
|
|
self:init("ui://FGAssist/panel_assist")
|
|
return self
|
|
end
|
|
|
|
function M:ReloadView()
|
|
self._view:GetChild("btn_auto_invite").onClick:Clear()
|
|
self.lst_player:RemoveChildrenToPool()
|
|
self:FillData()
|
|
end
|
|
|
|
function M:init(url)
|
|
BaseWindow.init(self, url)
|
|
self.lst_player = self._view:GetChild("lst_player")
|
|
local btn_refresh = self._view:GetChild("btn_refresh")
|
|
btn_refresh.onClick:Set(function()
|
|
self:ReloadView()
|
|
end)
|
|
|
|
self._timer = 0
|
|
UpdateBeat:Add(self.OnUpdate,self)
|
|
end
|
|
|
|
function M:FillData()
|
|
local mgr_ctr = ControllerManager.GetController(GroupMgrController)
|
|
if not mgr_ctr._mgr_client then
|
|
return
|
|
else
|
|
self:GetOnlinePlayers()
|
|
end
|
|
end
|
|
|
|
function M:GetOnlinePlayers()
|
|
local mgr_ctr = ControllerManager.GetController(GroupMgrController)
|
|
mgr_ctr:FG_GetOnlinePlayers(function(res)
|
|
if res.ReturnCode ~= 0 then
|
|
ViewUtil.ErrorTip(res.ReturnCode, "获取在线成员失败")
|
|
else
|
|
self.players = res.Data.onlines
|
|
-- self._view:GetController("empty").selectedIndex = #self.players == 0 and 1 or 0
|
|
self:ShowOnlinePlayers()
|
|
end
|
|
end)
|
|
end
|
|
|
|
local function _showLeftTime(item, time)
|
|
item:GetChild("tex_left_time").text = time .. "s"
|
|
end
|
|
|
|
local _list_invite_time = {}
|
|
function M:ShowOnlinePlayers()
|
|
local players = self.players
|
|
for i = 1, #players do
|
|
if self.lst_player.isDisposed then return end
|
|
local item = self.lst_player:AddItemFromPool()
|
|
local p = players[i]
|
|
item:GetChild("tex_name").text = p.nick
|
|
item:GetChild("tex_id").text = "ID:" .. ViewUtil.HideID(p.uid)
|
|
local btn_head = item:GetChild("btn_head")
|
|
ImageLoad.Load(p.portrait, btn_head._iconObject)
|
|
local ctr_enable = item:GetController("enable")
|
|
ctr_enable.selectedIndex = 0
|
|
item:GetChild("btn_invite").onClick:Set(function()
|
|
local mgr_ctr = ControllerManager.GetController(GroupMgrController)
|
|
local room = DataManager.CurrenRoom
|
|
mgr_ctr:FG_InvitePlayer(p.uid, room.room_id, room.play_id, room.room_config:GetGameName(), function()
|
|
end)
|
|
|
|
local time = os.time()
|
|
_list_invite_time[p.uid] = time
|
|
ctr_enable.selectedIndex = 1
|
|
_showLeftTime(item, 15)
|
|
end)
|
|
local invite_time = _list_invite_time[p.uid]
|
|
if invite_time then
|
|
local i_timer = os.time() - invite_time
|
|
if i_timer < 15 then
|
|
ctr_enable.selectedIndex = 1
|
|
_showLeftTime(item, 15 - i_timer)
|
|
else
|
|
_list_invite_time[p.uid] = nil
|
|
ctr_enable.selectedIndex = 0
|
|
end
|
|
end
|
|
end
|
|
local btn_auto_invite = self._view:GetChild("btn_auto_invite")
|
|
btn_auto_invite.onClick:Set(function()
|
|
local mgr_ctr = ControllerManager.GetController(GroupMgrController)
|
|
local room = DataManager.CurrenRoom
|
|
for i = 1, #players do
|
|
local p = players[i]
|
|
mgr_ctr:FG_InvitePlayer(p.uid, room.room_id, room.play_id, room.room_config:GetGameName(), function()
|
|
end)
|
|
|
|
local time = os.time()
|
|
_list_invite_time[p.uid] = time
|
|
item = self.lst_player:GetChildAt(i - 1)
|
|
item:GetController("enable").selectedIndex = 1
|
|
_showLeftTime(item, 15)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function M:OnUpdate()
|
|
local deltaTime = Time.deltaTime
|
|
self._timer = self._timer + deltaTime
|
|
if self._timer >= 1 then
|
|
self._timer = 0
|
|
|
|
if self.lst_player.numChildren == 0 then return end
|
|
for i = 1, #self.players do
|
|
local p = self.players[i]
|
|
local invite_time = _list_invite_time[p.uid]
|
|
if invite_time then
|
|
local i_timer = os.time() - invite_time
|
|
local item = self.lst_player:GetChildAt(i - 1)
|
|
if not item then break end
|
|
if i_timer < 15 then
|
|
_showLeftTime(item, 15 - i_timer)
|
|
else
|
|
item:GetController("enable").selectedIndex = 0
|
|
_list_invite_time[p.uid] = nil
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function M:Close()
|
|
BaseWindow.Close(self)
|
|
if self.callback then
|
|
self.callback()
|
|
end
|
|
end
|
|
|
|
return M |