local this = class("moduleMovementBlockMobile", require("ui.modulePages.moduleMovementBlockBase"))

function this.bind()
  return {
    module_attackMount = {
      moduleName = "pages/battle/moduleMountSkillBtn"
    },
    module_dodgeMount = {
      moduleName = "pages/battle/moduleMountDodgeBtn"
    }
  }
end

function this.methods()
  return {
    onClick_jump = function(self)
      self:doJump()
    end,
    onClick_dodge = function(self)
      self:doDodge()
    end,
    onDown_attack = function(self)
      L_PlayerManager:fireAttackDown()
    end,
    onUp_attack = function(self)
      L_PlayerManager:fireAttackUp()
    end,
    onClick_mountJump = function(self)
      self:doJump()
    end,
    onClick_mountDodge = function(self)
      self:doDodge()
    end,
    onDown_flyUp = function(self)
      L_PlayerManager:fireFlyUp(true)
    end,
    onUp_flyUp = function(self)
      L_PlayerManager:fireFlyUp(false)
    end,
    onDown_flyDown = function(self)
      L_PlayerManager:fireFlyFall(true)
    end,
    onUp_flyDown = function(self)
      L_PlayerManager:fireFlyFall(false)
    end
  }
end

function this:initBtnMap()
  self.blockBtnMap = {
    [L_Const.movementBlockType.default] = {
      [L_Const.movementBtnType.Atk] = true,
      [L_Const.movementBtnType.Jump] = true,
      [L_Const.movementBtnType.Dodge] = true,
      [L_Const.movementBtnType.MountFlyUp] = false,
      [L_Const.movementBtnType.MountFlyDown] = false,
      [L_Const.movementBtnType.MountDodge] = false,
      [L_Const.movementBtnType.MountAtk] = false,
      [L_Const.movementBtnType.MountJump] = false
    },
    [L_Const.movementBlockType.fly] = {
      [L_Const.movementBtnType.Atk] = false,
      [L_Const.movementBtnType.Jump] = false,
      [L_Const.movementBtnType.Dodge] = false,
      [L_Const.movementBtnType.MountFlyUp] = true,
      [L_Const.movementBtnType.MountFlyDown] = true,
      [L_Const.movementBtnType.MountDodge] = true,
      [L_Const.movementBtnType.MountAtk] = true,
      [L_Const.movementBtnType.MountJump] = false
    },
    [L_Const.movementBlockType.mount] = {
      [L_Const.movementBtnType.Atk] = false,
      [L_Const.movementBtnType.Jump] = false,
      [L_Const.movementBtnType.Dodge] = false,
      [L_Const.movementBtnType.MountFlyUp] = false,
      [L_Const.movementBtnType.MountFlyDown] = false,
      [L_Const.movementBtnType.MountDodge] = true,
      [L_Const.movementBtnType.MountAtk] = true,
      [L_Const.movementBtnType.MountJump] = true
    }
  }
end

function this:open()
  this.super.open(self)
  L_GameUtil.setJoyStick(self.bindComponents.joystick)
end

function this:refreshCtrlBtnState()
  self.modules.module_attackMount:initSkillType(L_Const.skillType.attack)
  for k, v in pairs(self.btnRects) do
    local stateInMap = self.blockBtnMap[self.ctrlType][k]
    v.gameObject:SetActive(stateInMap and self:getBtnTypeLock(self.ctrlType, k))
  end
end

function this:close()
  this.super.close(self)
  if L_CommonUtil.isValid(self.oldJoyStick) then
    L_GameUtil.setJoyStick(self.oldJoyStick)
  end
end

return this
