25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Menubutton.lua 1.9 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. Menubutton = Class {}
  2. function Menubutton:init(tempX, tempY, tempW, tempH, tempState, tempFormat, tempText, tempTC, tempBC)
  3. -- Position and Dimensions:
  4. self.x = tempX
  5. self.y = tempY
  6. self.w = tempW
  7. self.h = tempH
  8. -- State to jump to:
  9. self.toState = tempState
  10. -- Formatting:
  11. self.format = tempFormat
  12. if self.format == "center" or self.format == "centre" then
  13. self.x = self.x - self.w
  14. self.y = self.y - self.h
  15. end
  16. -- Text and Colours:
  17. self.text = tempText
  18. self.colour = {
  19. text = tempTC,
  20. background = tempBC
  21. }
  22. end
  23. -- FUNCTIONS
  24. function Menubutton:hover()
  25. local hover = false
  26. local x,y = love.mouse.getPosition()
  27. if x > self.x and x < self.x + self.w and y > self.y and y < self.y + self.h then
  28. hover = true
  29. end
  30. return hover
  31. end
  32. function Menubutton:click()
  33. local click = false
  34. if self:hover() and love.mouse.isDown(1) then
  35. click = true
  36. end
  37. return click
  38. end
  39. -- MAIN
  40. function Menubutton:update(dt)
  41. if self:click() then
  42. -- Here is room for calling effects or something... looking at you madi qwq xD
  43. GAMESTATE = self.toState
  44. end
  45. end
  46. function Menubutton:draw()
  47. local x, y, w, h = self.x, self.y, self.w, self.h
  48. local bg, tx = self.colour.background, self.colour.text
  49. bg, tx = calc.colour(bg[1], bg[2], bg[3]), calc.colour(tx[1], tx[2], tx[3])
  50. -- Hover Effects
  51. if self:hover() then
  52. -- Slight Colour Lightup
  53. for i = 1, #bg do
  54. bg[i] = bg[i]*1.1
  55. end
  56. -- Slight pop up effect (purly visual)
  57. local pop = 3
  58. x, y, w, h = x-pop, y-pop, w+pop*2, h+pop*2
  59. end
  60. -- Draw Background
  61. love.graphics.setColor(bg[1], bg[2], bg[3])
  62. love.graphics.rectangle("fill", x, y, w, h)
  63. -- Draw Text
  64. love.graphics.setFont(font.default)
  65. love.graphics.setColor(tx[1], tx[2], tx[3])
  66. love.graphics.printf(self.text, x, y, w, "center")
  67. end