Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

278 linhas
13 KiB

  1. mainMenu = Class{}
  2. function mainMenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds, location)
  3. if (gameState == 'editor')
  4. then
  5. ev_button_width = VIRTUAL_WIDTH * (1/72)
  6. ev_BUTTON_HEIGHT = VIRTUAL_WIDTH * (1/72)
  7. local margin = 16
  8. local hot = false
  9. local cursor_y = 0
  10. blockinput = false
  11. local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
  12. for i, button in ipairs(buttons) do
  13. button.last = button.now
  14. ev_bx = (VIRTUAL_WIDTH*0.05) - (ev_button_width * 0.5)
  15. ev_by = (VIRTUAL_HEIGHT * 0.1) - (total_height * 0.5) + cursor_y
  16. local color = {255, 255, 255, 255}
  17. local mx, my = love.mouse.getPosition()
  18. mx = mx
  19. my = my
  20. mx = mx * DIFFERENCE_X
  21. my = my * DIFFERENCE_Y
  22. hot = (mx > ev_bx and mx < ev_bx + ev_button_width and my > ev_by and my < ev_by + ev_BUTTON_HEIGHT) and i
  23. if (hot == i) then
  24. blockinput = blockinput or true
  25. color = {10, 10, 0, 255}
  26. end
  27. button.now = love.keyboard.mouseWasReleased()
  28. if button.now and not button.last and hot == i then
  29. love.keyboard.mouseisReleased = false
  30. love.graphics.setColor(0,0,0,1)
  31. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  32. sounds['wallhit']:play()
  33. button.fn()
  34. end
  35. love.graphics.setColor(unpack(color))
  36. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  37. love.graphics.setColor(0, 0, 0, 255)
  38. local textW = smallfont:getWidth(button.text)
  39. local textH = smallfont:getHeight(button.text)
  40. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.05 - textW*0.5, ev_by*0.9+textH*0.01)
  41. love.graphics.setColor(255, 255, 255, 255)
  42. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  43. end
  44. else
  45. if location == 'middle' then
  46. locationx = (VIRTUAL_WIDTH * 0.5)
  47. locationy = (VIRTUAL_HEIGHT* 0.5)
  48. elseif location == 'right' then
  49. locationx = (VIRTUAL_WIDTH * 0.8)
  50. locationy = (VIRTUAL_HEIGHT* 0.5)
  51. elseif location == 'control' then
  52. locationx = (VIRTUAL_WIDTH * 0.2)
  53. locationy = (VIRTUAL_HEIGHT* 0.5)
  54. elseif location == "android" then
  55. locationx = (VIRTUAL_WIDTH * 0.5)
  56. locationy = (10)
  57. end
  58. local ev_button_width = VIRTUAL_WIDTH * (1/3)
  59. local ev_BUTTON_HEIGHT = 50
  60. if location == "android" then
  61. ev_button_width = 30
  62. ev_BUTTON_HEIGHT = 30
  63. end
  64. local margin = 16
  65. local hot = false
  66. local cursor_y = 0
  67. local total_height = (ev_BUTTON_HEIGHT + margin) * #buttons
  68. local ev_bx, ev_by
  69. for i, button in ipairs(buttons) do
  70. --print("Button")
  71. button.last = button.now
  72. if button.x ~= -1 then
  73. ev_bx = button.x
  74. else
  75. ev_bx = locationx - (ev_button_width * 0.5)
  76. end
  77. if (location == 'control') then
  78. if string.sub(button.text, 1, 1) == '2' then
  79. ev_bx = (VIRTUAL_WIDTH*0.2) - (ev_button_width * 0.5)
  80. ev_by = locationy - (total_height * 0.5) + cursor_y
  81. elseif string.sub(button.text, 1, 1) == '1' then
  82. ev_bx = (VIRTUAL_WIDTH*0.8) - (ev_button_width * 0.5)
  83. ev_by = locationy - (total_height * 0.5) + cursor_y
  84. else
  85. ev_bx = (VIRTUAL_WIDTH*0.5) - (ev_button_width * 0.5)
  86. ev_by = locationy - (total_height * 0.5) + cursor_y
  87. end
  88. elseif button.text == 'NUCLEAR MODE' and easternum < 11 then
  89. ev_bx = -400
  90. ev_by = -400
  91. elseif button.x > locationx - (ev_button_width * 0.5) then
  92. --print("moving from" .. button.x)
  93. if lowcpu then
  94. button.x = locationx - (ev_button_width * 0.5)
  95. else
  96. button.x = button.x - 15
  97. end
  98. --print("moving!" .. button.x)
  99. ev_by = locationy - (total_height * 0.5) + cursor_y
  100. else
  101. ev_by = locationy - (total_height * 0.5) + cursor_y
  102. end
  103. color = {255, 255, 255, 255}
  104. if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255}
  105. elseif (button.text == 'NUCLEAR MODE' and easternum > 10) then
  106. color = {0,0,0,1}
  107. end
  108. local mx, my = love.mouse.getPosition()
  109. local mx = mx * DIFFERENCE_X
  110. local my = my * DIFFERENCE_Y
  111. 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
  112. if (hot == i) then
  113. color = {10, 10, 0, 255}
  114. end
  115. --print(love.keyboard.mouseisReleased)
  116. button.now = love.keyboard.mouseisReleased
  117. if location == "android" then
  118. button.now = love.mouse.isDown(1)
  119. end
  120. if button.now and hot == i then
  121. love.keyboard.mouseisReleased = false
  122. love.graphics.setColor(0,0,0,1)
  123. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  124. sounds['wallhit']:play()
  125. if button.skipAnim then
  126. print("skipped anim")
  127. else
  128. for j, buttons in ipairs(buttons) do
  129. buttons.x = 1300
  130. print("making" .. j)
  131. end
  132. end
  133. button.fn()
  134. break
  135. end
  136. love.graphics.setColor(unpack(color))
  137. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  138. print(ev_bx .. " " .. i)
  139. love.graphics.setColor(0, 0, 0, 255)
  140. local textW = smallfont:getWidth(button.text)
  141. local textH = smallfont:getHeight(button.text)
  142. if (location == 'control') then
  143. if danger == button.text or danger2 == button.text then
  144. love.graphics.setColor(1,0,0,1)
  145. else
  146. love.graphics.setColor(0,0,0,1)
  147. end
  148. if (button.text == "1up") then
  149. love.graphics.print("P1 UP: " .. string.upper(p1control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  150. elseif button.text == '2up' then
  151. love.graphics.print("P2 UP: " .. string.upper(p2control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  152. elseif button.text == '1down' then
  153. love.graphics.print("P1 DOWN: " .. string.upper(p1control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  154. elseif button.text == '2down' then
  155. love.graphics.print("P2 DOWN: " .. string.upper(p2control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  156. elseif button.text == '1special' then
  157. love.graphics.print("P1 SPECIAL: " .. string.upper(p1control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  158. elseif button.text == '2special' then
  159. love.graphics.print("P2 SPECIAL: " .. string.upper(p2control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  160. elseif button.text == '1ct' then
  161. love.graphics.print("P1 COUNTER: " .. string.upper(p1control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  162. elseif button.text == '2ct' then
  163. love.graphics.print("P2 COUNTER: " .. string.upper(p2control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  164. else
  165. love.graphics.print(button.text, smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  166. end
  167. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  168. else
  169. if (button.text == '1v1') then
  170. love.graphics.print(playertext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, by+textH*0.5)
  171. elseif button.text == 'snc' then
  172. if (nuckemodactive == 1) then
  173. textW = smallfont:getWidth(synctext)
  174. love.graphics.setColor(1,0,0,1)
  175. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  176. love.graphics.setColor(1,1,1,1)
  177. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  178. love.graphics.setColor(0,0,0,1)
  179. else
  180. textW = smallfont:getWidth(synctext)
  181. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  182. end
  183. elseif (button.text == 'ballCount') then
  184. local tempstr = "Ball Count: " .. maxBalls
  185. textW = smallfont:getWidth(tempstr)
  186. love.graphics.print("Ball Count: " .. maxBalls, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  187. elseif (button.text == "Ball Speed: ") then
  188. if (nuckemodactive == 1) then
  189. love.graphics.setColor(1,0,0,1)
  190. love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  191. love.graphics.setColor(1,1,1,1)
  192. love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  193. love.graphics.setColor(0,0,0,1)
  194. else
  195. textW = smallfont:getWidth(button.text .. ballSet)
  196. love.graphics.print(button.text .. ballSet, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  197. end
  198. elseif button.text == 'ptw' then
  199. local tempstr = "Points to Win: " .. ptw
  200. textW = smallfont:getWidth(tempstr)
  201. love.graphics.print("Points to Win: " .. ptw, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  202. elseif (button.text == 'Silverblade') then
  203. local tempstr = "Difficulty: " .. prtext
  204. textW = smallfont:getWidth(tempstr)
  205. love.graphics.print("Difficulty: " .. prtext, smallfont,ev_bx + ev_button_width*0.5 - textW*0.5 , ev_by+textH*0.5)
  206. else
  207. love.graphics.print(button.text, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  208. end
  209. love.graphics.setColor(255, 255, 255, 255)
  210. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  211. end
  212. end
  213. end
  214. end
  215. function mainMenu:addButton(text, fn)
  216. if isButtonAnimated == true then
  217. print("Button shall be animated!")
  218. newButtonXVariable = 1290
  219. else
  220. print("Button shall NOT be animated!")
  221. newButtonXVariable = -1
  222. end
  223. return {
  224. x = newButtonXVariable,
  225. text = text,
  226. fn = fn,
  227. now = false,
  228. last = false
  229. }
  230. end
  231. function menuButtons()
  232. local button_width = VIRTUAL_WIDTH * (1/3)
  233. local BUTTON_HEIGHT = 50
  234. local margin = 16
  235. local hot = false
  236. local cursor_y = 0
  237. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  238. for i, button in ipairs(buttons) do
  239. button.last = button.now
  240. local bx = (VIRTUAL_WIDTH*0.5) - (button_width * 0.5)
  241. local by = (VIRTUAL_HEIGHT * 0.8) - (total_height * 0.5) + cursor_y
  242. local color = {255, 255, 255, 255}
  243. local mx, my = love.mouse.getPosition()
  244. mx = mx
  245. my = my
  246. mx = mx * DIFFERENCE_X
  247. my = my * DIFFERENCE_Y
  248. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  249. if (hot == i) then
  250. color = {10, 10, 0, 255}
  251. end
  252. button.now = love.keyboard.mouseWasReleased()
  253. if button.now and not button.last and hot == i then
  254. love.keyboard.mouseisReleased = false
  255. love.graphics.setColor(0,0,0,1)
  256. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  257. sounds['wallhit']:play()
  258. button.fn()
  259. end
  260. love.graphics.setColor(unpack(color))
  261. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  262. love.graphics.setColor(0, 0, 0, 255)
  263. local textW = smallfont:getWidth(button.text)
  264. local textH = smallfont:getHeight(button.text)
  265. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  266. love.graphics.setColor(255, 255, 255, 255)
  267. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  268. end
  269. end