You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.0 KiB

  1. mainMenu = Class{}
  2. function resolutionButtons(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons)
  3. if (gameState == 'windowsettings') then
  4. local ev_button_width = VIRTUAL_WIDTH * (1/3)
  5. local ev_BUTTON_HEIGHT = 50
  6. local margin = 16
  7. local hot = false
  8. local cursor_y = 0
  9. local total_height = (ev_BUTTON_HEIGHT + margin) * #settings
  10. for i, button in ipairs(buttons) do
  11. button.last = button.now
  12. local ev_bx = (VIRTUAL_WIDTH*0.8) - (ev_button_width * 0.5)
  13. local ev_by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  14. local color = {255, 255, 255, 255}
  15. local mx, my = love.mouse.getPosition()
  16. local mx = mx * DIFFERENCE_X
  17. local my = my * DIFFERENCE_Y
  18. local hot = (mx > ev_bx and mx < ev_bx + ev_button_width and my > ev_by and my < ev_by + ev_BUTTON_HEIGHT) and i
  19. if (hot == i) then
  20. color = {10, 10, 0, 255}
  21. end
  22. button.now = love.mouse.isDown(1)
  23. if button.now and not button.last and hot == i then
  24. love.graphics.setColor(0,0,0,1)
  25. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  26. -- sounds['wallhit']:play()
  27. button.fn()
  28. end
  29. love.graphics.setColor(unpack(color))
  30. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  31. love.graphics.setColor(0, 0, 0, 255)
  32. local textW = smallfont:getWidth(button.text)
  33. local textH = smallfont:getHeight(button.text)
  34. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.8 - textW*0.5, ev_by+textH*0.5)
  35. love.graphics.setColor(255, 255, 255, 255)
  36. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  37. end
  38. end
  39. end