local this = class("moduleBattleControlNew", G_UIModuleBase)

function this.bind()
  return {
    goContent = true,
    moduleBattleAttackBtn = {
      moduleName = "pages/battle/moduleBattleAttackBtn"
    },
    modulePetCatchBtn = {
      moduleName = "pages/battle/modulePetCatchBtn"
    },
    moduleBattlePetSkill = {
      moduleName = "pages/battle/moduleBattlePetSkill"
    },
    moduleHeroESkill = {
      moduleName = "pages/battle/moduleBattleHeroSkillBtn"
    },
    moduleHeroUltimateSkill = {
      moduleName = "pages/battle/moduleBattleHeroUltimateSkillBtn"
    },
    moduleCountermeasuresSkill = {
      moduleName = "pages/battle/skillBtn/moduleBattleCountermeasuresSkillBtn"
    },
    moduleBattleDodgeSkillBtn = {
      moduleName = "pages/battle/skillBtn/moduleBattleDodgeSkillBtn"
    },
    moduleUIChargingSkill = {
      moduleName = "pages/battle/moduleUIChargingSkill"
    },
    moduleCollectSkillBtn = {
      moduleName = "pages/battle/moduleCollectSkillBtn"
    }
  }
end

function this.methods()
  return {
    onClick_jump = function(self)
      L_PlayerManager:fireJump()
    end
  }
end

function this:open(...)
  this.super.open(self, ...)
  L_PlayerManager:addListener(L_PlayerManager.event.setMainControl, self.setMainControl, self)
  L_PlayerManager:addListener(L_PlayerManager.event.playMount, self.onPlayerOnMount, self)
  L_PlayerManager:addListener(L_PlayerManager.event.outMountEnd, self.onPlayerOutMount, self)
  L_MountManager:addListener(L_MountManager.event.onCSEntityMountStateChange, self.onEvent_CsEntityStateChange, self)
  self:refreshSkillIcon()
  self.bind.goContent = not L_PlayerManager:isInMounting() and L_PlayerManager:getMainHeroEntity() ~= nil
end

function this:onEvent_CsEntityStateChange()
  self.bind.goContent = not L_PlayerManager:isInMounting()
end

function this:onPlayerOnMount()
  self.bind.goContent = false
end

function this:onPlayerOutMount()
  self.bind.goContent = true
end

function this:show()
  self:showModules()
  self:refreshSkillIcon()
end

function this:close(...)
  this.super.close(self, ...)
  L_PlayerManager:removeListener(L_PlayerManager.event.setMainControl, self.setMainControl, self)
  L_PlayerManager:removeListener(L_PlayerManager.event.playMount, self.onPlayerOnMount, self)
  L_PlayerManager:removeListener(L_PlayerManager.event.outMountEnd, self.onPlayerOutMount, self)
  L_MountManager:removeListener(L_MountManager.event.onCSEntityMountStateChange, self.onEvent_CsEntityStateChange)
end

function this:setMainControl()
  self:refreshSkillIcon()
end

function this:refreshSkillIcon()
  local playerUnit = L_PlayerManager:getPlayerUnit()
  if not playerUnit then
    return
  end
  local mainControlType = L_PlayerManager:getPlayerUnit():getMainControlType()
  self.bind.goContent = mainControlType == C_EPlayerMainControlType.Formation and L_PlayerManager:getPlayerUnit():getMainHeroEntity_cs() ~= nil
end

function this:hide()
  self:hideModules()
end

function this:activate()
  self:open()
  self:openModules()
  self:show()
  self:showModules()
end

function this:deActivate()
  self:hide()
  self:hideModules()
  self:close()
  self:closeModules()
end

return this
