SkyFlash21

ClientV

Jul 22nd, 2021 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.11 KB | None | 0 0
  1. ------Main------
  2. shell.run("rm Anita/API/rgb")
  3. shell.run("pastebin get BCSWghjR Anita/API/rgb")
  4. os.loadAPI("Anita/API/rgb")
  5. shell.run("label set Rubi")
  6. shell.run("clear")
  7.  
  8. local version = 1.0
  9. local ItemsList = {}
  10. local ActiveItemList = {}
  11.  
  12. local MenuBackgroundColor = colors.fromRGB(0, 48, 73)
  13. local MenuTextColor = colors.fromRGB(247, 127, 0)
  14.  
  15.  
  16. -----------------------------------------------------------------------------------
  17. local function GUInit()
  18. SetButton("Serveur", ServerButtonfunction, 3, 18, 3, 5,colors.fromRGB(85,195,186),colors.fromRGB(236, 240, 241),"ServerMenu")
  19. SetButton("Client", ClientButtonfunction, 21, 36, 3, 5,colors.fromRGB(253, 179, 20),colors.fromRGB(236, 240, 241),"ClientMenu")
  20.  
  21. SetButton("QuarryButton", QuarryButtonfunction, 2, 9, 3, 5,colors.fromRGB(132, 83, 26),colors.fromRGB(236, 240, 241),"Quarry")
  22. SetButton("FarmButton", FarmButtonfunction, 2, 9, 6, 8,colors.fromRGB(112, 140, 0),colors.fromRGB(236, 240, 241),"Farm")
  23.  
  24. SetButton("ReturnBack", MainMenu, 1, 6, 13, 13,colors.fromRGB(252, 0, 0),colors.fromRGB(212, 212, 212),"retour")
  25. end
  26.  
  27. function SetButton(name, func, xmin, xmax, ymin, ymax,bcolor,tcolor,text)
  28. ItemsList[name] = {}
  29. ItemsList[name]["function"] = func
  30. ItemsList[name]["active"] = false
  31. ItemsList[name]["xmin"] = xmin
  32. ItemsList[name]["ymin"] = ymin
  33. ItemsList[name]["xmax"] = xmax
  34. ItemsList[name]["ymax"] = ymax
  35. ItemsList[name]["backcolor"] = bcolor
  36. ItemsList[name]["textcolor"] = tcolor
  37. ItemsList[name]["text"] = text
  38. end
  39.  
  40. function SetText(name, xmin, xmax, ymin, ymax,bcolor,tcolor,text)
  41. ItemsList[name] = {}
  42. ItemsList[name]["active"] = false
  43. ItemsList[name]["xmin"] = xmin
  44. ItemsList[name]["ymin"] = ymin
  45. ItemsList[name]["xmax"] = xmax
  46. ItemsList[name]["ymax"] = ymax
  47. ItemsList[name]["backcolor"] = bcolor
  48. ItemsList[name]["textcolor"] = tcolor
  49. ItemsList[name]["text"] = text
  50. end
  51.  
  52. function fill(text, color,textcolor, bData)
  53.  
  54. term.setTextColor(textcolor)
  55. term.setBackgroundColor(color)
  56. local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  57. local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  58. for j = bData["ymin"], bData["ymax"] do
  59. term.setCursorPos(bData["xmin"], j)
  60. if j == yspot then
  61. for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  62. if k == xspot then
  63. term.write(text)
  64. else
  65. term.write(" ")
  66. end
  67. end
  68. else
  69. for i = bData["xmin"], bData["xmax"] do
  70. term.write(" ")
  71. end
  72. end
  73. end
  74.  
  75. term.setTextColor(colors.black)
  76. term.setBackgroundColor(colors.black)
  77. end
  78.  
  79. function InitiateButton(MenuButton)
  80. ActiveItemList = MenuButton
  81. for k,Button in pairs(MenuButton) do
  82. fill(Button["text"],Button["backcolor"],Button["textcolor"],Button)
  83. end
  84.  
  85. if ItemsList["Return"]["function"] ~= nil then
  86. local Button = ItemsList["Return"]
  87.  
  88. fill(Button["text"],Button["backcolor"],Button["textcolor"],Button)
  89. ActiveItemList["Return"] = ItemsList["Return"]
  90. end
  91. end
  92.  
  93. -------------------------------------------------------------------
  94.  
  95. function ServerButtonfunction()
  96. Title()
  97. ItemsList["ReturnBack"]["function"] = MainMenu
  98. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  99. Draw()
  100. end
  101. function ClientButtonfunction()
  102. Title()
  103. ItemsList["ReturnBack"]["function"] = MainMenu
  104. ActiveItemList["QuarryButton"] = ItemsList["QuarryButton"]
  105. ActiveItemList["FarmButton"] = ItemsList["FarmButton"]
  106. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  107. Draw()
  108. end
  109. function QuarryButtonfunction()
  110. Title()
  111.  
  112.  
  113. ItemsList["ReturnBack"]["function"] = ClientButtonfunction
  114. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  115. Draw()
  116. end
  117. function FarmButtonfunction()
  118. Title()
  119.  
  120.  
  121. ItemsList["ReturnBack"]["function"] = ClientButtonfunction
  122. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  123. Draw()
  124. end
  125.  
  126. -------------------------------------------------------------------
  127. ----------------------Menu-----------------------------------------
  128. -------------------------------------------------------------------
  129.  
  130. function Title()
  131. ActiveItemList = {}
  132. term.setBackgroundColor(MenuBackgroundColor)
  133. term.setTextColor(MenuTextColor)
  134. term.clear()
  135. term.setCursorPos(1,1)
  136. term.write("Programme Anita V")
  137. term.setTextColor(colors.fromRGB(247, 127, 0))
  138. term.write(version)
  139. term.setCursorPos(1,2)
  140. term.setTextColor(MenuTextColor)
  141. term.write("---------------------------------------")
  142. term.setTextColor(colors.black)
  143. end
  144.  
  145. function MainMenu()
  146. Title()
  147. ActiveItemList["Serveur"] = ItemsList["Serveur"]
  148. ActiveItemList["Client"] = ItemsList["Client"]
  149. Draw()
  150. end
  151.  
  152. -------------------------------------------------------------------
  153. ----------------------Feature--------------------------------------
  154. -------------------------------------------------------------------
  155. local function Com()
  156. while true do
  157. local sender, message = rednet.receive()
  158. term.setBackgroundColor(colors.white)
  159. term.setTextColor(colors.black)
  160. term.setCursorPos(99,99)
  161. print(message)
  162. rednet.send(sender, "Réponse")
  163. end
  164. end
  165.  
  166. function Draw()
  167. for k,Button in pairs(ActiveItemList) do
  168. fill(Button["text"],Button["backcolor"],Button["textcolor"],Button)
  169. end
  170. end
  171. local function LeftButton()
  172. write("Fuck you")
  173. end
  174.  
  175.  
  176. -----------------------------------------------------------------------------------
  177. ------------------------------------Quarry---------------------------------------
  178. -----------------------------------------------------------------------------------
  179. Pos = {0,0,0}
  180. shell.run("label set " .. Pos[1])
  181.  
  182. -----------------------------------------------------------------------------------
  183. -------------------------------Main------------------------------------------------
  184. -----------------------------------------------------------------------------------
  185. GUInit()
  186. inputCoroutine = coroutine.create(Com)
  187. coroutine.resume(inputCoroutine)
  188. MainMenu()
  189.  
  190. while true do
  191. myEvent = { os.pullEvent() }
  192.  
  193. if myEvent[1] == "mouse_click" then
  194.  
  195. for k,Element in pairs(ActiveItemList) do
  196. if myEvent[3] >= Element["xmin"] and myEvent[3] < Element["xmax"] and myEvent[4] >= Element["ymin"] and myEvent[4] <= Element["ymax"] then
  197. if Element["function"] ~= nil then
  198.  
  199. fill(Element["text"],colors.fromRGB(46, 204, 113),Element["textcolor"],Element)
  200. sleep(0.4)
  201. Element["function"]()
  202. else
  203. shell.run("label set Fail " .. Element["text"])
  204. end
  205. end
  206. end
  207.  
  208. end
  209. if myEvent[1] == "rednet_message" or myEvent[1] == "timer" then
  210. coroutine.resume( comCoroutine, unpack( myEvent ) )
  211. end
  212. end
Add Comment
Please, Sign In to add comment