Sawtaytoes
2/24/2019 - 4:14 PM

Determining a Mouse Click in StepMania

Def.Quad {
  LeftClickMessageCommand = function(
    self
  )
    self:playcommand(
      'MouseClicked',
      { LeftClick = true }
    )
  end,

  RightClickMessageCommand = function(
    self
  )
    self:playcommand(
      'MouseClicked',
      { LeftClick = false }
    )
  end,

  MouseClickedCommand = function(
    self,
    params
  )
    if not self.clickEnabled then
      return
    end

    local MouseX = INPUTFILTER:GetMouseX()
    local MouseY = INPUTFILTER:GetMouseY()

    local ItemX = (
      self:GetParent():GetX()
      + self:GetParent():GetParent():GetParent():GetX()
    )
    local ItemY = (
      self:GetParent():GetY()
      + self:GetParent():GetParent():GetParent():GetY()
    )

    local ItemXOffset = self:GetZoomX() / 2
    local ItemYOffset = self:GetZoomY() / 2

    if (
      (
        ItemX + ItemXOffset > MouseX
        and ItemX - ItemXOffset < MouseX
      )
      and (
        ItemY + ItemYOffset > MouseY
        and ItemY - ItemYOffset < MouseY
      )
    ) then
      -- Do Stuff
    end
  end,
}