GuildSceneEventBtnItem = GuildSceneEventBtnItem or BaseClass(BaseItem)
local GuildSceneEventBtnItem = GuildSceneEventBtnItem
function GuildSceneEventBtnItem:__init(parent_wnd,prefab_asset,layer_name)
self.base_file = "guildScene"
self.layout_file = "GuildSceneEventBtnItem"
self.parent_wnd = parent_wnd
self.layer_name = layer_name
self.main_vo = RoleManager.Instance.mainRoleInfo
self.model = GuildModel:getInstance()
self.tv_model = GuildTVModel:GetInstance()
self:Load()
end
function GuildSceneEventBtnItem:Load_callback()
local nodes = {
"icon:obj:img", "icon/name:tmp", "tip_timer_bg:obj", "tip_timer:txt",
"num_reddot:obj", "num_reddot_lb:tmp",
}
self:GetChildren(nodes)
self:AddEvents()
if self.need_refreshData then
self:UpdateView()
end
end
function GuildSceneEventBtnItem:AddEvents( )
local function click_event(target)
if target == self.icon_obj then
self:OnClickIcon()
end
end
AddClickEvent(self.icon_obj, click_event)
-- 按需更新按钮状态
local function update_dance_status_func()
if self.data and self.data.fun_id == 4007 then
self:UpdateView()
end
end
self.update_dance_status = self.main_vo:BindOne("dance_status", update_dance_status_func)
--更新自动封印按钮状态
local function updateGuildCollectIcon()
if self.data and self.data.fun_id == 408 then
self:UpdateView()
end
end
self:BindEvent(self.model, GuildModel.UPDATE_AUTO_GUILD_COLLECT_STATE, updateGuildCollectIcon)
local function update_tip()
local function call_back( )
if self._use_delete_method then
return
end
self:ShowBtnTips(1420)
end
TimeManager.GetInstance():StartTime("GuildSceneEventBtnItem:ShowBtnTips1420",0.5,call_back)--限制刷新频率
end
self:BindEvent(self.tv_model, GuildTVConst.UPDATE_GUILDTV_BTN_TIPS, update_tip)
local function update_btn_num_red(fun_id)
self:ShowBtnNumReddot(fun_id)
end
self:BindEvent(self.model, GuildModel.UPDATE_SCENE_FUNCBTN_NUM_RED, update_btn_num_red)
end
function GuildSceneEventBtnItem:UpdateView( )
if self.data.fun_id == 400799 or self.data.fun_id == 40699 or self.data.fun_id == 40899 then
lua_resM:setImageSprite(self, self.icon_img, "guildScene_asset", "guild_btn_40099")
else
lua_resM:setImageSprite(self, self.icon_img, "guildScene_asset", "guild_btn_" .. self.data.fun_id)
end
if self.data.fun_id == 4007 then -- 社团派对
local dance_status = RoleManager.Instance.mainRoleInfo.dance_status
self.name_tmp.text = dance_status == 0 and "狂狼热舞" or "热舞中..."
elseif self.data.fun_id == 408 then -- 封印裂隙
-- local fight_state = AutoFightManager:getInstance():GetAutoFightState()
local auto_collect_state = self.model:IsAutoGuildCollectState()
self.name_tmp.text = auto_collect_state and "自动封印中..." or "封印裂隙"
elseif self.data.fun_id == 400799 or self.data.fun_id == 40699 or self.data.fun_id == 40899 then -- 召唤社员
self.name_tmp.text = "召唤社员"
elseif self.data.fun_id == 406 then --击杀使徒
self.name_tmp.text = "击杀使徒"
else
self.name_tmp.text = self.data.name
end
self:ShowBtnTips(self.data.fun_id)
self:ShowBtnNumReddot(self.data.fun_id)
end
function GuildSceneEventBtnItem:SetData( data )
self.data = data
if self.is_loaded then
self.need_refreshData = false
self:UpdateView()
else
self.need_refreshData = true
end
end
function GuildSceneEventBtnItem:OnClickIcon( )
if not self.data then return end
local callback = {
[4007] = function () -- 社团派对祝火状态变更
if not self.model._waiting_12025_respon then
-- 请求切换祝火状态
local dance_status = RoleManager.Instance.mainRoleInfo.dance_status
-- self.model:Fire(GuildModel.CHANGE_GUILDDANCE_ACTION, dance_status == 0 and 1 or 0)
DanceModel:getInstance():Fire(DanceModel.CHANGE_DANCE_STATUS, dance_status == 0)
end
end,
[1420] = function () -- 社团派跑马
GlobalEventSystem:Fire(GuildTVConst.OPEN_GUILDTV_MAIN_VIEW)
end,
[408] = function()--自动封印状态变更
local auto_collect_state = self.model:IsAutoGuildCollectState()
if not auto_collect_state then--要开启自动采集状态时,取消自动挂机状态
GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
end
self.model:SetAutoGuildCollectState(not auto_collect_state)--切换采集状态
self.model:Fire(GuildModel.UPDATE_AUTO_GUILD_COLLECT_STATE)--通知按钮变化
end,
[406] = function() -- 寻路打社团boss
local call_back = function ()
GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
end
-- 社团场景有两个,所以直接改为获取当前场景即可
local scene_id = SceneManager:getInstance():GetSceneId()
local pos_x, pos_y = self.model:GetGuildBossPos()
local findVo = FindVo.New()
findVo.type = FindVo.POINT
findVo.sceneId = scene_id
findVo.x = pos_x / SceneObj.LogicRealRatio.x
findVo.y = pos_y / SceneObj.LogicRealRatio.y
findVo.call_back = call_back
GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
Scene:getInstance():FindElement(findVo)
end,
[400799] = function() --社团晚宴召唤社员
local content = string.format("[社团晚宴]正在进行中,海量经验等你来拿,大家快来加入这场狂欢派对吧![点击前往]", RoleManager.Instance.mainRoleInfo.name)
ChatModel:getInstance():Fire(ChatModel.SEND_MSG,ChatModel.CHANNEL_GUILD,content,0,nil,ChatModel.CHAT_COMMON_TYPE.SYSTEM)
-- self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40064, 4007)
end,
[40699] = function() --社团boss召唤社员
local content = "[社团幻魔]已现身,大家快来一起抵御幻魔入侵吧! [立即前往]"
ChatModel:getInstance():Fire(ChatModel.SEND_MSG,ChatModel.CHANNEL_GUILD,content,0,nil,ChatModel.CHAT_COMMON_TYPE.SYSTEM)
-- self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40064, 406)
end,
[40899] = function() --封印裂隙召唤社员
-- self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40064, 408)
local content = "[封印裂隙]活动已经开始啦,大家快来一起封印吧! [立即前往]"
ChatModel:getInstance():Fire(ChatModel.SEND_MSG,ChatModel.CHANNEL_GUILD,content,0,nil,ChatModel.CHAT_COMMON_TYPE.SYSTEM)
end,
[4062] = function()
self.model:Fire(GuildModel.OPEN_BOSS_ROLL_VIEW, true)
end,
}
if callback[self.data.fun_id] then
callback[self.data.fun_id]()
end
end
function GuildSceneEventBtnItem:ShowBtnTips(fun_id)
if self.data.fun_id == fun_id then
if fun_id == 1420 then--目前只有跑马需要这个tips 其他人要的时候再在下面加自己的逻辑 并且在上面addevent绑刷新方法
local bool = self.tv_model:IsCanShowBtnTips()
if bool then
self.tip_timer_bg_obj:SetActive(true)
self.tip_timer_txt.text = "新一轮押注开始了!"
else
self.tip_timer_bg_obj:SetActive(false)
self.tip_timer_txt.text = ""
end
else
self.tip_timer_bg_obj:SetActive(false)
self.tip_timer_txt.text = ""
end
end
end
-- 显示按钮的数量红点
function GuildSceneEventBtnItem:ShowBtnNumReddot(fun_id)
if self.data.fun_id == fun_id then
if fun_id == 4062 then
local red_num = self.model:GetGuildBossNumRed()
-- print("Saber:GuildSceneEventBtnItem [191] red_num: ",red_num)
self.num_reddot_obj:SetActive(red_num > 0)
self.num_reddot_lb_tmp.text = red_num > 0 and red_num or ""
else
self.num_reddot_obj:SetActive(false)
self.num_reddot_lb_tmp.text = ""
end
end
end
function GuildSceneEventBtnItem:__delete( )
if self.update_dance_status then
self.main_vo:UnBind(self.update_dance_status)
self.update_dance_status = nil
end
end