local UIGuildWarMapBtns = UIViewClass() local EventSystem = require('Event/EventSystem') local ResourcesWarnInterval = 10 local CostTipsInterval = 3 function UIGuildWarMapBtns:OnOpened(context) if LogicUpdateManager.IsReplayOrServerCheck then return end MDL.GuildWar.SendGetGuildWarScoutsList() --这里弹个加入战场频道的提示 CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_JoinBattleChannelTip) self:OpenListen() self:CheckNeedShowOpenMicTip() self:RegistSystemEvent(EventID.UI_RefresGuildWarMapBtnsUI,self.RefreshChatUI) self:RegistSystemEvent(EventID.SDK_OnVoiceRoomStateChange,self.RefreshChatUI) self:RegistSystemEvent(EventID.UI_GuildWarCanBuyNotify, self.RefreshShopRedPoint) self:RegistSystemEvent(EventID.UI_Guild_SelfInfoRefresh, self.OnJobChange) CTL.Sound.PlayGameSound("UI_voice_system") UIUtils.SetActive(self.group_goods, BattleDataGetter.GetCurLevelType() == LuaConst.LevelType.SyncGuildWarMapResources) if BattleDataGetter.GetCurLevelType() == LuaConst.LevelType.SyncGuildWarMapResources then self:RegistSystemEvent(EventID.UI_GuildWarResourceUpdate, self.OnResourcesUpdate) self:RegistSystemEvent(EventID.UI_GuildWarResourceScoreChange, self.OnMyResourcesUpdate) self:RegistSystemEvent(EventID.UI_GuildWarResourceCostNotify, self.ResourceCostNotify) self.costValue = 0 self.txt_MyInfo.text = BattleDataGetter.GetGuildWarHandInResourceAmount_MySelf() end UIUtils.SetActive(self.btn_Command, MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildWarCommander) and not BattleDataGetter.IsGuildWarWaitingArea()) if MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildWarCommander) and not BattleDataGetter.IsGuildWarWaitingArea() then self.btn_Command:SetRedPoint(MDL.GuildWar.GetClickCommandBtn() == nil) end UIUtils.SetActive(self.commandCanvas, false) if BattleDataGetter.IsGuildWarWaitingArea() then if GameAppInfo.IsVietnamPackage() or GameAppInfo.IsJapanesePackage() then self.state_btn:SetState(3) else self.state_btn:SetState(1) end else if GameAppInfo.IsVietnamPackage() or GameAppInfo.IsJapanesePackage() then self.state_btn:SetState(2) else self.state_btn:SetState(0) end end end --刷新聊天相关UI function UIGuildWarMapBtns:RefreshChatUI() --收听 local isListening=CTL.VoiceRoom.IsEnabledListener() if isListening then UIUtils.SetLabelText(self.lab_ListenIn, Const_IDS.IDS_WarChannel_Listening) self.img_ListenIn:SetState(1) else UIUtils.SetLabelText(self.lab_ListenIn, Const_IDS.IDS_WarChannel_NotListening) self.img_ListenIn:SetState(0) end --开闭麦 local isOpenMic=CTL.VoiceRoom.IsEnabledMicrophone() if isOpenMic then UIUtils.SetLabelText(self.lab_OpenMic, Const_IDS.IDS_WarChannel_NotSpeakingBtn) self.img_OpenMic:SetState(1) else UIUtils.SetLabelText(self.lab_OpenMic, Const_IDS.IDS_WarChannel_SpeakingBtn) self.img_OpenMic:SetState(0) end local isCanOpenMic= CTL.ChannelChat.IsCanOpenGuildWarVoice() self.event_OpenMic.gameObject:SetActive(isCanOpenMic) if not isCanOpenMic and isOpenMic then CTL.VoiceRoom.EnableMicrophone(MDL.VoiceRoom.VoiceRoomType.GuildWar, false) end --召集 local isCanConvene=CTL.ChannelChat.IsCanConvene() end function UIGuildWarMapBtns:OnButtonClicked(comp) if comp == self.event_BattleFieldInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarMapInfo) elseif comp == self.event_Leave then if BattleDataGetter.IsGuildWarWaitingArea() then MDL.Level.SendRoleLeaveFubenFromSetting() else local backToHome = function() LuaInputManager.SetSpecialCommand(LuaConst.SpecialCommandType.QuitRoom) end UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_ExitBarrier, Const_IDS.IDS_GuildWar_QuitConfirm,backToHome, nil) end elseif comp == self.event_MaterialShop then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarShopPanel) elseif comp == self.event_ListenIn then --修改收听状态 self:ChangeListenStatus() elseif comp == self.event_OpenMic then --修改麦克状态 self:ChangeMicStatus() elseif comp == self.event_Convene then --召集 local isCanConvene=CTL.ChannelChat.IsCanConvene() --有权限的可以召集,无权限的提示 if isCanConvene then local conveneFunc=function() local isCanConvene2=CTL.ChannelChat.IsCanConvene() if isCanConvene2 then MDL.GuildWar.SendGuildWarConvene() CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonSucceed1) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail4) end end UTL.MessageBox.ShowOKCancelBox("", Const_IDS.IDS_WarChannel_CommanderCallupConfirm,conveneFunc, nil) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail4) end elseif comp == self.event_Data then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarDataView) elseif comp == self.event_Explain then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildWarBattleGround) elseif comp == self.btn_Command then MDL.GuildWar.SetClickCommandBtn(false) self.btn_Command:SetRedPoint(false) if MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildWarCommander) then self:OpenCommand() else CTL.Tips.AddTipsMsg(Const_IDS["IDS_SiegeCity_Command4"]) end elseif comp == self.btn_Mask then UIUtils.SetActive(self.commandCanvas, false) elseif comp == self.group_Search then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDescriptionPanel, {target = self.descPos, posType = LuaConst.DescriptionPanelType.RightUpper, text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildWar_MiniMapSupportTips), },"GuildWar/UIGuildWarDescriptionPanel") else for i, v in ipairs(self.CommandMsg) do if v.btn_Click == comp then self:OnClickedCommand(i) break end end end end function UIGuildWarMapBtns:CheckButtonCD(cdtime) local isCanChange=false --1秒cd if cdtime ==nil then cdtime=UTL.Time.GetServerTimestamp() isCanChange=true else local currentTime=UTL.Time.GetServerTimestamp() --1秒cd if (currentTime- cdtime) >1 then cdtime=currentTime isCanChange=true end end return cdtime,isCanChange end --改变收听状态 function UIGuildWarMapBtns:ChangeListenStatus() --检查是否到了CD时间 local isCD self.lastChangeListenTime,isCD=self:CheckButtonCD(self.lastChangeListenTime) if not isCD then return end local isListening = CTL.VoiceRoom.IsEnabledListener() CTL.VoiceRoom.EnableListener(MDL.VoiceRoom.VoiceRoomType.GuildWar, not isListening) if isListening then CTL.Tips.AddTipsMsg(Const_IDS.IDS_WarChannel_QuitListening) MDL.GuildWar.SendGuildWarCancelListen(PlayerInfoManager.AcID) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_WarChannel_EnterListening) MDL.GuildWar.SendGuildWarListen(PlayerInfoManager.AcID) end end --改变麦克风状态 function UIGuildWarMapBtns:ChangeMicStatus() --检查是否到了CD时间 local isCD self.lastChangeMicTime,isCD=self:CheckButtonCD(self.lastChangeMicTime) if not isCD then return end local isOpenMic=CTL.VoiceRoom.IsEnabledMicrophone() CTL.VoiceRoom.EnableMicrophone(MDL.VoiceRoom.VoiceRoomType.GuildWar, not isOpenMic) if not isOpenMic then CTL.Tips.AddTipsMsg(Const_IDS.IDS_WarChannel_Speaking) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_WarChannel_NotSpeaking) end end --是否有开麦权限 function UIGuildWarMapBtns:CheckNeedShowOpenMicTip() local isHasOpenMicRight=CTL.ChannelChat.IsCanOpenGuildWarVoice() if isHasOpenMicRight then if not CTL.ChannelChat.GetHasShowMicTip() then local openMicFunc=function() CTL.VoiceRoom.EnableMicrophone(MDL.VoiceRoom.VoiceRoomType.GuildWar, true) CTL.ChannelChat.RefreshGuildWarMapUI() CTL.Tips.AddTipsMsg(Const_IDS.IDS_WarChannel_Speaking) end UTL.MessageBox.ShowOKCancelBox("", Const_IDS.IDS_WarChannel_CommanderEnterBattlegroundTip,openMicFunc, nil) CTL.ChannelChat.SetHasShowMicTip() CTL.Sound.PlayGameSound("UI_voice_system") end end end --默认一开始就打开收听 function UIGuildWarMapBtns:OpenListen() local guildInfo = MDL.Guild.GetMyGuildInfo() CTL.VoiceRoom.EnterVoiceRoom(MDL.VoiceRoom.VoiceRoomType.GuildWar, guildInfo.guildId, true, false) CTL.Tips.AddTipsMsg(Const_IDS.IDS_WarChannel_EnterListening) end --收到召集消息后,有召集权限的提示,没有的弹窗 是否收听 function UIGuildWarMapBtns:OnPushConvene() local isCanConvene=CTL.ChannelChat.IsCanConvene() if isCanConvene then CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS. IDS_Guild_CommonSucceed1)) else local listenFunc=function() CTL.VoiceRoom.EnableListener(MDL.VoiceRoom.VoiceRoomType.GuildWar, true) MDL.GuildWar.SendGuildWarListen(PlayerInfoManager.AcID) end UTL.MessageBox.ShowOKCancelBox("", Const_IDS.IDS_WarChannel_CallupReceiveConfirm,listenFunc, nil) CTL.Sound.PlayGameSound("UI_voice_system") end end local function SortCommand(a, b) return a.sort < b.sort end function UIGuildWarMapBtns:SendCommand(index) UIUtils.SetActive(self.commandCanvas, false) MDL.GuildWar.GuildWarSendCommandTipsReq(self.sortCommandList[index].ID) end function UIGuildWarMapBtns:OpenCommand() if self.sortCommandList == nil then self.sortCommandList = {} for i, v in DataSheetManager.GuildWarCommand:GetEnumerator() do table.insert(self.sortCommandList, v) end table.sort(self.sortCommandList, SortCommand) end for i, v in ipairs(self.CommandMsg) do if self.sortCommandList[i] == nil then else v.txt_Words.text = UIUtils.GetLocalizedTxt(Const_IDS[self.sortCommandList[i].BtnText]) end end UIUtils.SetActive(self.commandCanvas, true) self.commandCanvas.overrideSorting = true self.commandCanvas.sortingLayerName = "UIPopup" self.commandCanvas.sortingOrder = 0 end function UIGuildWarMapBtns:OnClickedCommand(index) if BattleDataGetter.IsCityWarWaitingLevel() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_SiegeCity_Command14"]) return end self:SendCommand(index) end function UIGuildWarMapBtns:OnResourcesUpdate(resources) if self.showResourcesParamDict and resources < self.oldResources then CTL.GuildWar.ShowResources(self, resources, self.oldResources, self.showResourcesParamDict) self.oldResources = resources else self.showResourcesParamDict = {Txt_AddNum = self.txt_AddInfo, txt_Num = self.txt_TotalInfo, updateFun = self.ShowResourcesUpdateFun} self.txt_TotalInfo.text = resources self.oldResources = resources or 0 end if resources <= 1000 then if self.lastShowTime == nil or Time.realtimeSinceStartup - self.lastShowTime >= ResourcesWarnInterval then self.lastShowTime = Time.realtimeSinceStartup UIUtils.SetActive(self.Img_pop2, true) self.showWarnTipsIng = CostTipsInterval self.txt_time2.text = self.showWarnTipsIng.."s" self:StartRepeatFunc(self.ShowResourcesWarnUpdate, 1) end end end function UIGuildWarMapBtns:ShowResourcesWarnUpdate() self.showWarnTipsIng = self.showWarnTipsIng - 1 if self.showWarnTipsIng > 0 then self.txt_time2.text = self.showWarnTipsIng.."s" else self:StopRepeatFunc(self.ShowResourcesWarnUpdate) UIUtils.SetActive(self.Img_pop2, false) end end function UIGuildWarMapBtns:ShowResourcesUpdateFun(deltaTime, timeSinceUpdate) CTL.GuildWar.ShowResourcesUpdateFun(deltaTime, timeSinceUpdate, self.showResourcesParamDict,self) end function UIGuildWarMapBtns:OnMyResourcesUpdate() local resources = BattleDataGetter.GetGuildWarHandInResourceAmount_MySelf() if self.showMyResourcesParamDict then CTL.GuildWar.ShowResources(self, resources, self.myOldResources, self.showMyResourcesParamDict) self.myOldResources = resources else self.showMyResourcesParamDict = {Txt_AddNum = self.txt_MyAdd, txt_Num = self.txt_MyInfo, updateFun = self.ShowMyResourcesUpdateFun} self.txt_MyInfo.text = resources self.myOldResources = resources end end function UIGuildWarMapBtns:ShowMyResourcesUpdateFun(deltaTime, timeSinceUpdate) CTL.GuildWar.ShowResourcesUpdateFun(deltaTime, timeSinceUpdate, self.showMyResourcesParamDict,self) end function UIGuildWarMapBtns:ResourceCostNotify(params) if params[1] then local value = tonumber(params[1]) if value then if self.showTipsIng then self.costValue = self.costValue + value else UIUtils.SetActive(self.Img_pop1, true) self:ShowCostTips(value) end end end end function UIGuildWarMapBtns:ShowCostTips(value) UIUtils.SetActive(self.Img_pop1, true) self.txt_CostInfo.text = string.FormatByIdsId(Const_IDS.IDS_GuildWar_SupportMessage, value) self.showTipsIng = CostTipsInterval self:StartRepeatFunc(self.ShowCostUpdateFun, 1) self.txt_time1.text = self.showTipsIng.."s" end function UIGuildWarMapBtns:ShowCostUpdateFun() self.showTipsIng = self.showTipsIng - 1 if self.showTipsIng > 0 then self.txt_time1.text = self.showTipsIng.."s" else self.showTipsIng = nil self:StopRepeatFunc(self.ShowCostUpdateFun) if self.costValue > 0 then self:ShowCostTips(self.costValue) self.costValue = 0 else UIUtils.SetActive(self.Img_pop1, false) end end end function UIGuildWarMapBtns:RefreshShopRedPoint(value) UIUtils.SetActive(self.materialShop_arrow, value) end function UIGuildWarMapBtns:OnJobChange() local isHasJob = MDL.Guild.JobHasPermission(MDL.Guild.GetMyGuildInfo().jobTitle,MDL.Guild.AuthorityEnum.GuildWarCommander) and not BattleDataGetter.IsGuildWarWaitingArea() UIUtils.SetActive(self.btn_Command, isHasJob) if not isHasJob then self:OnButtonClicked(self.btn_Mask) end MDL.GuildWar.C2GGetGuildWarProductReq() end return UIGuildWarMapBtns