233 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			233 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			Lua
		
	
---
 | 
						||
--- Generated by EmmyLua(https://github.com/EmmyLua)
 | 
						||
--- Created by aaa.
 | 
						||
--- DateTime: 2019/8/30 15:40
 | 
						||
---
 | 
						||
local MatchFight = quick_class("MatchFight")
 | 
						||
local bloodyTask = ConfigManager.GetConfig(ConfigName.BloodyBattleTask)
 | 
						||
 | 
						||
function MatchFight:ctor(parent, root)
 | 
						||
    self.root = root
 | 
						||
    self:InitComponent(root)
 | 
						||
    self:BindEvent()
 | 
						||
end
 | 
						||
 | 
						||
function MatchFight:InitComponent(root)
 | 
						||
    self.spLoader = SpriteLoader.New()
 | 
						||
    self.btnFormat = Util.GetGameObject(root, "flag/btnFormat")
 | 
						||
    self.btnMatch = Util.GetGameObject(root, "rewardRoot/btnMatch")
 | 
						||
    -- 积分
 | 
						||
    self.score = Util.GetGameObject(root, "flag/Img/score"):GetComponent("Text")
 | 
						||
    -- 段位
 | 
						||
    self.level = Util.GetGameObject(root, "flag/KingLevel"):GetComponent("Text")
 | 
						||
    -- 结束时间
 | 
						||
    self.endTime = Util.GetGameObject(root, "flag/timeInfo/time"):GetComponent("Text")
 | 
						||
    self.roleList = {}
 | 
						||
    self.demoList = {}
 | 
						||
    self.btnBox = {}
 | 
						||
 | 
						||
    -- 下标对应的任务ID
 | 
						||
    self.missionIdList = {}
 | 
						||
 | 
						||
    --  5个编队数据
 | 
						||
    for  i = 1, 5 do
 | 
						||
        self.roleList[i] = Util.GetGameObject(root, "flag/roleList/head_" .. i)
 | 
						||
    end
 | 
						||
 | 
						||
    -- 3只异妖
 | 
						||
    for j = 1, 3 do
 | 
						||
        self.demoList[j] = Util.GetGameObject(root, "flag/demonList/deomon_" .. j)
 | 
						||
    end
 | 
						||
 | 
						||
    self.scoreProgress = Util.GetGameObject(root, "rewardBg/score/progress"):GetComponent("Slider")
 | 
						||
    self.scoreText = Util.GetGameObject(root, "rewardBg/score/progress/Text"):GetComponent("Text")
 | 
						||
    self.scoreReward = Util.GetGameObject(root, "rewardBg/score/reward")
 | 
						||
 | 
						||
    -- 每日任务的奖励
 | 
						||
    for k = 1, 4 do
 | 
						||
        self.btnBox[k] = Util.GetGameObject(root, "rewardRoot/rewardBg/daily/bxoRoot/reward_" .. k)
 | 
						||
    end
 | 
						||
 | 
						||
 | 
						||
end
 | 
						||
 | 
						||
 | 
						||
function MatchFight:BindEvent()
 | 
						||
    Util.AddClick(self.btnMatch, function ()
 | 
						||
        -- 校验编队
 | 
						||
        local checkPass = FormationManager.CheckFormationValid(FormationTypeDef.BLOODY_BATTLE_ATTACK)
 | 
						||
        if not checkPass then
 | 
						||
            PopupTipPanel.ShowTip(Language[10748])
 | 
						||
            return
 | 
						||
        end
 | 
						||
 | 
						||
        UIManager.OpenPanel(UIName.MatchingPopup)
 | 
						||
    end)
 | 
						||
 | 
						||
    Util.AddClick(self.btnFormat, function ()
 | 
						||
        UIManager.OpenPanel(UIName.FormationPanel, FORMATION_TYPE.BLOODY_BATTLE)
 | 
						||
    end)
 | 
						||
 | 
						||
    Util.AddClick(self.scoreReward, function ()
 | 
						||
        UIManager.OpenPanel(UIName.MapFightRewardPanel)
 | 
						||
    end)
 | 
						||
 | 
						||
    for i = 1, 4 do
 | 
						||
        Util.AddClick(self.btnBox[i], function ()
 | 
						||
            local info = TaskManager.GetTypeTaskInfo(TaskTypeDef.BloodyTask, self.missionIdList[i])
 | 
						||
 | 
						||
            --local taskData = TaskManager.GetTypeTaskList(TaskTypeDef.BloodyTask)
 | 
						||
            --for i = 1, #taskData do
 | 
						||
            --    Log("MissionId  == " .. taskData[i].missionId .. "Mission State == " .. taskData[i].state)
 | 
						||
            --end
 | 
						||
 | 
						||
            if info.state == 0 then
 | 
						||
                PopupTipPanel.ShowTip(Language[10749])
 | 
						||
            elseif info.state == 1 then
 | 
						||
                NetManager.TakeMissionRewardRequest(TaskTypeDef.BloodyTask, info.missionId, function (msg)
 | 
						||
                    UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
 | 
						||
                        TaskManager.SetTypeTaskState(TaskTypeDef.BloodyTask, info.missionId)
 | 
						||
                        self:ShowDailyRreward()
 | 
						||
                    end)
 | 
						||
                end)
 | 
						||
            elseif info.state == 2 then
 | 
						||
                PopupTipPanel.ShowTip(Language[10750])
 | 
						||
            end
 | 
						||
        end)
 | 
						||
 | 
						||
    end
 | 
						||
 | 
						||
end
 | 
						||
 | 
						||
function MatchFight:OnShow()
 | 
						||
    self.root:SetActive(true)
 | 
						||
    -- 初始化显示
 | 
						||
    self:InitShow()
 | 
						||
 | 
						||
    -- 请求数据
 | 
						||
    NetManager.RequestBloodyScoreRewardData(function()
 | 
						||
        -- 显示奖励
 | 
						||
        self:ShowReward()
 | 
						||
    end)
 | 
						||
 | 
						||
    -- 显示每日任务状态
 | 
						||
    self:ShowDailyRreward()
 | 
						||
end
 | 
						||
 | 
						||
function MatchFight:ReShowPanel()
 | 
						||
    -- 刷新编队数据
 | 
						||
    self:ReFreshTeamInfo()
 | 
						||
 | 
						||
end
 | 
						||
 | 
						||
-- 编队以及时间显示
 | 
						||
---- ===================================================
 | 
						||
function MatchFight:InitShow()
 | 
						||
    local score =  MatchDataManager.myScore >= 0 and MatchDataManager.myScore or 0
 | 
						||
    self.score.text = Language[10751] .. score
 | 
						||
    self.level.text = Language[10752] .. MatchDataManager.GetNickNameByScore(MatchDataManager.myScore)
 | 
						||
    self.endTime.text = ""
 | 
						||
 | 
						||
 | 
						||
    local upDate = function()
 | 
						||
        -- 定时器清除后,仍然会调用一次
 | 
						||
        local serData = ActTimeCtrlManager.GetSerDataByTypeId(47)
 | 
						||
        local endTime = serData.endTime
 | 
						||
        if not self.timer then return end
 | 
						||
        if PlayerManager.serverTime > endTime then
 | 
						||
            self.endTime.text = "00:00:00"
 | 
						||
            self.timer:Stop()
 | 
						||
        else
 | 
						||
            self.endTime.text = self:FormatTime(endTime - PlayerManager.serverTime)
 | 
						||
        end
 | 
						||
    end
 | 
						||
 | 
						||
    if not self.timer then
 | 
						||
        self.timer = Timer.New(upDate, 1, -1 , true)
 | 
						||
        self.timer:Start()
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
function MatchFight:FormatTime(second)
 | 
						||
    local minute = math.floor(second / 60) % 60
 | 
						||
    local sec = second % 60
 | 
						||
    local hour = math.floor(math.floor(second - sec - minute * 60) / 3600)
 | 
						||
 | 
						||
    return string.format("%02d:%02d:%02d", hour, minute, sec)
 | 
						||
end
 | 
						||
 | 
						||
function MatchFight:ReFreshTeamInfo()
 | 
						||
    local teamInfo = FormationManager.GetFormationByID(FormationTypeDef.BLOODY_BATTLE_ATTACK)
 | 
						||
    for i = 1, #teamInfo.teamHeroInfos do
 | 
						||
        local roleData = teamInfo.teamHeroInfos[i]
 | 
						||
        if roleData then
 | 
						||
            self.roleList[i]:SetActive(true)
 | 
						||
            local demonData = HeroManager.GetSingleHeroData(roleData.heroId)
 | 
						||
            self.roleList[i]:GetComponent("Image").sprite = self.spLoader:LoadSprite(GetQuantityImageByquality(demonData.heroConfig.Quality))
 | 
						||
            Util.GetGameObject(self.roleList[i], "icon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(demonData.icon)
 | 
						||
        end
 | 
						||
    end
 | 
						||
 | 
						||
    for d = #teamInfo.teamHeroInfos + 1, 5 do
 | 
						||
        self.roleList[d]:SetActive(false)
 | 
						||
    end
 | 
						||
 | 
						||
 | 
						||
    -- 设置异妖
 | 
						||
    for j = 1, #teamInfo.teamPokemonInfos do
 | 
						||
        local demoInfo = teamInfo.teamPokemonInfos[j]
 | 
						||
        if demoInfo then
 | 
						||
            self.demoList[j]:SetActive(true)
 | 
						||
            local resId = ConfigManager.GetConfigData(ConfigName.DifferDemonsConfig, demoInfo.pokemonId).LiveIcon
 | 
						||
            self.demoList[j]:GetComponent("Image").sprite = self.spLoader:LoadSprite(GetResourcePath(resId))
 | 
						||
        else
 | 
						||
            self.demoList[j]:SetActive(false)
 | 
						||
        end
 | 
						||
    end
 | 
						||
 | 
						||
    for p = #teamInfo.teamPokemonInfos + 1, 3 do
 | 
						||
        self.demoList[p]:SetActive(false)
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
---- ===================================================
 | 
						||
-- 赛季奖励数据显示
 | 
						||
function MatchFight:ShowReward()
 | 
						||
    local curRewardScore = MatchDataManager.GetRewardScore()
 | 
						||
    local curStageRewardScore = MatchDataManager.GetCurStageRewardScore()
 | 
						||
    self.scoreText.text = string.format("%s/%s", curRewardScore, curStageRewardScore)
 | 
						||
    self.scoreProgress.value = curRewardScore/curStageRewardScore
 | 
						||
 | 
						||
 | 
						||
end
 | 
						||
 | 
						||
-- 每日任务, state : 1未完成 2可领取 3已领取
 | 
						||
function MatchFight:ShowDailyRreward()
 | 
						||
    Log("设置血战每日任务状态")
 | 
						||
    local taskData = TaskManager.GetTypeTaskList(TaskTypeDef.BloodyTask)
 | 
						||
 | 
						||
    for i = 1, #taskData do
 | 
						||
        local missionId = taskData[i].missionId
 | 
						||
        local state = taskData[i].state
 | 
						||
        local doingImg = Util.GetGameObject(self.btnBox[i], "default")
 | 
						||
        local doneImg = Util.GetGameObject(self.btnBox[i], "choose")
 | 
						||
        local context = Util.GetGameObject(self.btnBox[i], "context"):GetComponent("Text")
 | 
						||
        doingImg:SetActive(state == 0)
 | 
						||
        doneImg:SetActive(state ~= 0)
 | 
						||
        Util.SetGray(doneImg, state == 2)
 | 
						||
        context.text = Language[10753] .. bloodyTask[missionId].TaskValue[2][1]
 | 
						||
 | 
						||
        self.missionIdList[i] = missionId
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
 | 
						||
function MatchFight:OnHidePanel()
 | 
						||
    self.root:SetActive(false)
 | 
						||
    if self.timer then
 | 
						||
        self.timer:Stop()
 | 
						||
        self.timer = nil
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
return MatchFight |