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.

275 lines
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.x > locationx - (ev_button_width * 0.5) then
  89. --print("moving from" .. button.x)
  90. if lowcpu then
  91. button.x = locationx - (ev_button_width * 0.5)
  92. else
  93. button.x = button.x - 15
  94. end
  95. --print("moving!" .. button.x)
  96. ev_by = locationy - (total_height * 0.5) + cursor_y
  97. else
  98. ev_by = locationy - (total_height * 0.5) + cursor_y
  99. end
  100. color = {255, 255, 255, 255}
  101. if (button.text == 'Play') and location == 'playercount' then color = {0/255, 255/255, 0/255, 255}
  102. elseif (button.text == 'NUCLEAR MODE' and easternum > 10) then
  103. color = {0,0,0,1}
  104. end
  105. local mx, my = love.mouse.getPosition()
  106. local mx = mx * DIFFERENCE_X
  107. local my = my * DIFFERENCE_Y
  108. 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
  109. if (hot == i) then
  110. color = {10, 10, 0, 255}
  111. end
  112. --print(love.keyboard.mouseisReleased)
  113. button.now = love.keyboard.mouseisReleased
  114. if location == "android" then
  115. button.now = love.mouse.isDown(1)
  116. end
  117. if button.now and hot == i then
  118. love.keyboard.mouseisReleased = false
  119. love.graphics.setColor(0,0,0,1)
  120. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  121. sounds['wallhit']:play()
  122. if button.skipAnim then
  123. print("skipped anim")
  124. else
  125. for j, buttons in ipairs(buttons) do
  126. buttons.x = 1300
  127. print("making" .. j)
  128. end
  129. end
  130. button.fn()
  131. break
  132. end
  133. love.graphics.setColor(unpack(color))
  134. love.graphics.rectangle("fill", ev_bx,ev_by, ev_button_width, ev_BUTTON_HEIGHT)
  135. print(ev_bx .. " " .. i)
  136. love.graphics.setColor(0, 0, 0, 255)
  137. local textW = smallfont:getWidth(button.text)
  138. local textH = smallfont:getHeight(button.text)
  139. if (location == 'control') then
  140. if danger == button.text or danger2 == button.text then
  141. love.graphics.setColor(1,0,0,1)
  142. else
  143. love.graphics.setColor(0,0,0,1)
  144. end
  145. if (button.text == "1up") then
  146. love.graphics.print("P1 UP: " .. string.upper(p1control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  147. elseif button.text == '2up' then
  148. love.graphics.print("P2 UP: " .. string.upper(p2control.up), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  149. elseif button.text == '1down' then
  150. love.graphics.print("P1 DOWN: " .. string.upper(p1control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  151. elseif button.text == '2down' then
  152. love.graphics.print("P2 DOWN: " .. string.upper(p2control.down), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  153. elseif button.text == '1special' then
  154. love.graphics.print("P1 SPECIAL: " .. string.upper(p1control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  155. elseif button.text == '2special' then
  156. love.graphics.print("P2 SPECIAL: " .. string.upper(p2control.super), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  157. elseif button.text == '1ct' then
  158. love.graphics.print("P1 COUNTER: " .. string.upper(p1control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  159. elseif button.text == '2ct' then
  160. love.graphics.print("P2 COUNTER: " .. string.upper(p2control.counter), smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  161. else
  162. love.graphics.print(button.text, smallfont, ev_bx + (ev_button_width * 0.1), ev_by+textH*0.5)
  163. end
  164. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  165. else
  166. if (button.text == '1v1') then
  167. love.graphics.print(playertext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, by+textH*0.5)
  168. elseif button.text == 'snc' then
  169. if (nuckemodactive == 1) then
  170. textW = smallfont:getWidth(synctext)
  171. love.graphics.setColor(1,0,0,1)
  172. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  173. love.graphics.setColor(1,1,1,1)
  174. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  175. love.graphics.setColor(0,0,0,1)
  176. else
  177. textW = smallfont:getWidth(synctext)
  178. love.graphics.print(synctext, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  179. end
  180. elseif (button.text == 'ballCount') then
  181. local tempstr = "Ball Count: " .. maxBalls
  182. textW = smallfont:getWidth(tempstr)
  183. love.graphics.print("Ball Count: " .. maxBalls, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  184. elseif (button.text == "Ball Speed: ") then
  185. if (nuckemodactive == 1) then
  186. love.graphics.setColor(1,0,0,1)
  187. love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  188. love.graphics.setColor(1,1,1,1)
  189. love.graphics.print("shaitan machina", smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  190. love.graphics.setColor(0,0,0,1)
  191. else
  192. textW = smallfont:getWidth(button.text .. ballSet)
  193. love.graphics.print(button.text .. ballSet, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  194. end
  195. elseif button.text == 'ptw' then
  196. local tempstr = "Points to Win: " .. ptw
  197. textW = smallfont:getWidth(tempstr)
  198. love.graphics.print("Points to Win: " .. ptw, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  199. elseif (button.text == 'Silverblade') then
  200. local tempstr = "Difficulty: " .. prtext
  201. textW = smallfont:getWidth(tempstr)
  202. love.graphics.print("Difficulty: " .. prtext, smallfont,ev_bx + ev_button_width*0.5 - textW*0.5 , ev_by+textH*0.5)
  203. else
  204. love.graphics.print(button.text, smallfont, ev_bx + ev_button_width*0.5 - textW*0.5, ev_by+textH*0.5)
  205. end
  206. love.graphics.setColor(255, 255, 255, 255)
  207. cursor_y = cursor_y + (ev_BUTTON_HEIGHT + margin)
  208. end
  209. end
  210. end
  211. end
  212. function mainMenu:addButton(text, fn)
  213. if isButtonAnimated == true then
  214. print("Button shall be animated!")
  215. newButtonXVariable = 1290
  216. else
  217. print("Button shall NOT be animated!")
  218. newButtonXVariable = -1
  219. end
  220. return {
  221. x = newButtonXVariable,
  222. text = text,
  223. fn = fn,
  224. now = false,
  225. last = false
  226. }
  227. end
  228. function menuButtons()
  229. local button_width = VIRTUAL_WIDTH * (1/3)
  230. local BUTTON_HEIGHT = 50
  231. local margin = 16
  232. local hot = false
  233. local cursor_y = 0
  234. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  235. for i, button in ipairs(buttons) do
  236. button.last = button.now
  237. local bx = (VIRTUAL_WIDTH*0.5) - (button_width * 0.5)
  238. local by = (VIRTUAL_HEIGHT * 0.8) - (total_height * 0.5) + cursor_y
  239. local color = {255, 255, 255, 255}
  240. local mx, my = love.mouse.getPosition()
  241. mx = mx
  242. my = my
  243. mx = mx * DIFFERENCE_X
  244. my = my * DIFFERENCE_Y
  245. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  246. if (hot == i) then
  247. color = {10, 10, 0, 255}
  248. end
  249. button.now = love.keyboard.mouseWasReleased()
  250. if button.now and not button.last and hot == i then
  251. love.keyboard.mouseisReleased = false
  252. love.graphics.setColor(0,0,0,1)
  253. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  254. sounds['wallhit']:play()
  255. button.fn()
  256. end
  257. love.graphics.setColor(unpack(color))
  258. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  259. love.graphics.setColor(0, 0, 0, 255)
  260. local textW = smallfont:getWidth(button.text)
  261. local textH = smallfont:getHeight(button.text)
  262. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH*0.5 - textW*0.5, by+textH*0.5)
  263. love.graphics.setColor(255, 255, 255, 255)
  264. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  265. end
  266. end