SkyFlash21

Client

Jul 25th, 2021 (edited)
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.40 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("rm Anita/API/ToolBox")
  6. shell.run("pastebin get iiqvdU1J Anita/API/ToolBox")
  7. os.loadAPI("Anita/API/ToolBox")
  8. shell.run("label set Rubi")
  9. shell.run("clear")
  10.  
  11. shell.run("rm Anita/Anitas.last")
  12.  
  13. local version = "1.0"
  14. ItemsList = {}
  15. local ActiveItemList = {}
  16.  
  17. local MenuBackgroundColor = colors.fromRGB(0, 48, 73)
  18. local MenuTextColor = colors.fromRGB(247, 127, 0)
  19.  
  20. Page = 0
  21. CurrentProgramme = "none"
  22. LastTime = os.time()
  23. CurrentFunction = nil
  24. function TestScript()
  25. CurrentProgramme = "Quarry"
  26. end
  27.  
  28. function PageNext() if Page < 1 then Page = Page + 1 end QuarryButtonfunction() end
  29. function PageBack() if Page > 0 then Page = Page - 1 end QuarryButtonfunction() end
  30. -----------------------------------------------------------------------------------
  31. function GUInit()
  32. SetItem("Serveur", ServerButtonfunction, 3, 18, 3, 5,colors.fromRGB(85,195,186),colors.fromRGB(236, 240, 241),"ServerMenu")
  33. SetItem("Client", ClientButtonfunction, 21, 36, 3, 5,colors.fromRGB(253, 179, 20),colors.fromRGB(236, 240, 241),"ClientMenu")
  34.  
  35. SetItem("QuarryButton", QuarryButtonfunction, 2, 9, 3, 5,colors.fromRGB(132, 83, 26),colors.fromRGB(236, 240, 241),"Quarry")
  36. SetItem("FarmButton", FarmButtonfunction, 2, 9, 7, 9,colors.fromRGB(112, 140, 0),colors.fromRGB(236, 240, 241),"Farm")
  37.  
  38. SetItem("ReturnBack", MainMenu, 1, 6, 13, 13,colors.fromRGB(252, 0, 0),colors.fromRGB(212, 212, 212),"retour")
  39. SetItem("QuarryStart", TestScript, 35, 39, 13, 13,colors.blue,colors.fromRGB(212, 212, 212),"Start")
  40.  
  41.  
  42. SetItem("Suivant", PageNext, 26, 33, 13, 13,colors.purple,colors.fromRGB(212, 212, 212),"Suivant")
  43. SetItem("Arriere", PageBack, 8, 14, 13, 13,colors.purple,colors.fromRGB(212, 212, 212),"Arrière")
  44. end
  45. -----------------------------------------------------------------------------------
  46.  
  47. function SetItem(name, func, xmin, xmax, ymin, ymax,bcolor,tcolor,text)
  48. ItemsList[name] = {}
  49. ItemsList[name]["function"] = func
  50. ItemsList[name]["xmin"] = xmin
  51. ItemsList[name]["ymin"] = ymin
  52. ItemsList[name]["xmax"] = xmax
  53. ItemsList[name]["ymax"] = ymax
  54. ItemsList[name]["backcolor"] = bcolor
  55. ItemsList[name]["textcolor"] = tcolor
  56. ItemsList[name]["text"] = text
  57. end
  58.  
  59. ------------------------Button----------------------------------
  60.  
  61. function ServerButtonfunction()
  62. Title()
  63. ItemsList["ReturnBack"]["function"] = MainMenu
  64. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  65. ToolBox.Draw(ActiveItemList)
  66. end
  67.  
  68. function ClientButtonfunction()
  69. Title()
  70. ItemsList["ReturnBack"]["function"] = MainMenu
  71. ActiveItemList["QuarryButton"] = ItemsList["QuarryButton"]
  72. ActiveItemList["FarmButton"] = ItemsList["FarmButton"]
  73. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  74. ToolBox.Draw(ActiveItemList)
  75. end
  76.  
  77. function QuarryButtonfunction()
  78. Title()
  79. local TurtleTable = ToolBox.AnitaRead()
  80. local TurtlePos = TurtleTable["Position"]
  81. local TurtleDir = TurtleTable["Orientation"]
  82. local TurtleSize = TurtleTable["Size"]
  83. ActiveItemList["QuarryPos"] = ItemsList["QuarryPos"]
  84. ItemsList["ReturnBack"]["function"] = ClientButtonfunction
  85. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  86. ActiveItemList["QuarryStart"] = ItemsList["QuarryStart"]
  87. ActiveItemList["Suivant"] = ItemsList["Suivant"]
  88. ActiveItemList["Arriere"] = ItemsList["Arriere"]
  89.  
  90.  
  91. TurtleSize[1] = 100
  92. TurtleSize[2] = 100
  93. TurtleSize[3] = 100
  94. if Page == 0 then
  95. term.setCursorPos(1,3)
  96. local QuarryMenuColor = colors.fromRGB(236, 240, 241)
  97. term.setBackgroundColor(MenuBackgroundColor)
  98. ColorList= {QuarryMenuColor,colors.fromRGB(192, 57, 43),colors.white,colors.fromRGB(46, 204, 113),colors.white,colors.fromRGB(52, 152, 219),colors.white,colors.orange,colors.white}
  99. TextList = {"Pos actuelle : ","x:",TurtlePos[1]," y:",TurtlePos[2]," z:",TurtlePos[3]," dir: ",TurtleDir}
  100. ToolBox.WriteText(ColorList,TextList)
  101.  
  102. term.setCursorPos(1,4)
  103. term.setBackgroundColor(MenuBackgroundColor)
  104. ColorList= {QuarryMenuColor,colors.fromRGB(192, 57, 43),colors.white,colors.fromRGB(46, 204, 113),colors.white,colors.fromRGB(52, 152, 219),colors.white}
  105. TextList = {"WorkZone : ", "L:",TurtleSize[1] , " l:",TurtleSize[2] ," h:" ,TurtleSize[3]}
  106. ToolBox.WriteText(ColorList,TextList)
  107.  
  108. term.setCursorPos(1,5)
  109. ColorList= {QuarryMenuColor ,colors.cyan}
  110. TextList = {"Volume : " ,TurtleSize[1]*TurtleSize[2]*TurtleSize[3]}
  111. ToolBox.WriteText(ColorList,TextList)
  112.  
  113. term.setCursorPos(1,6)
  114. ColorList= {QuarryMenuColor ,colors.cyan,colors.white}
  115. TextList = {"Block Miné : " , TurtleTable["Block miné"], " Block Miné"}
  116. ToolBox.WriteText(ColorList,TextList)
  117.  
  118. term.setCursorPos(1,7)
  119. term.setBackgroundColor(MenuBackgroundColor)
  120. term.setTextColor(MenuTextColor)
  121. term.write("---------------------------------------")
  122.  
  123. term.setCursorPos(1,8)
  124. term.setBackgroundColor(MenuBackgroundColor)
  125. term.setTextColor(colors.white)
  126. ColorList= {QuarryMenuColor,colors.cyan,QuarryMenuColor,colors.green}
  127. TextList = {"Carburant : ",TurtleTable["Fuel Level"],"/",TurtleTable["Total Fuel"]}
  128. ToolBox.WriteText(ColorList,TextList)
  129.  
  130. term.setCursorPos(1,9)
  131. term.setBackgroundColor(MenuBackgroundColor)
  132. term.setTextColor(colors.white)
  133. term.write("Mouvement : " .. TurtleTable["Mouvement"])
  134. elseif Page == 1 then
  135. term.setCursorPos(1,3)
  136. term.setBackgroundColor(MenuBackgroundColor)
  137. term.setTextColor(colors.white)
  138. if TurtleTable["EnderChest"] ~= 0 then
  139. term.write("EnderChest : slot n°" .. TurtleTable["EnderChest"])
  140. else
  141. term.write("EnderChest : Désactivé")
  142. end
  143. end
  144.  
  145. ToolBox.Draw(ActiveItemList)
  146.  
  147. term.setCursorPos(1,10)
  148. term.setBackgroundColor(MenuBackgroundColor)
  149. term.setTextColor(MenuTextColor)
  150. term.write("___________________________________________")
  151.  
  152.  
  153.  
  154. term.setCursorPos(1,12)
  155. term.setBackgroundColor(MenuBackgroundColor)
  156. term.setTextColor(MenuTextColor)
  157. term.write("---------------------------------------")
  158.  
  159.  
  160. Pourcentage = 68 ---ToolBox.AnitaRead("Progression")
  161. PourTrente = ToolBox.round((Pourcentage / 100)*39)
  162. local text = "Progression " .. Pourcentage .." % "
  163. for i=1,39 do
  164. local pixelcolor = colors.black
  165. if i < (PourTrente+1) then
  166. pixelcolor = colors.green
  167. else
  168. pixelcolor = colors.gray
  169. end
  170.  
  171. if i > 11 and i < 28 then
  172. term.setBackgroundColor(pixelcolor)
  173. term.setTextColor(colors.white)
  174. if (i-11)<string.len(text) then
  175. term.write(string.sub(text, (i-11)), (i-11))
  176. end
  177. else
  178. paintutils.drawPixel(i, 11, pixelcolor)
  179. end
  180. end
  181. end
  182.  
  183.  
  184. function FarmButtonfunction()
  185. Title()
  186. ItemsList["ReturnBack"]["function"] = ClientButtonfunction
  187. ActiveItemList["ReturnBack"] = ItemsList["ReturnBack"]
  188. ToolBox.Draw(ActiveItemList)
  189. end
  190.  
  191. -------------------------------------------------------------------
  192. ----------------------Menu-----------------------------------------
  193. -------------------------------------------------------------------
  194.  
  195. function Title()
  196. ActiveItemList = {}
  197. term.setBackgroundColor(MenuBackgroundColor)
  198. term.setTextColor(MenuTextColor)
  199. term.clear()
  200. term.setCursorPos(1,1)
  201. local time = os.time()
  202. local formattedTime = textutils.formatTime(time, false)
  203. term.write("Programme Anita V")
  204. term.write(version)
  205. for i = 1, (22 - string.len(version) - string.len(tostring(formattedTime))) do
  206. term.write(" ")
  207. end
  208. term.setTextColor(colors.white)
  209. term.write(formattedTime)
  210. term.setCursorPos(1,2)
  211. term.setTextColor(MenuTextColor)
  212. term.write("---------------------------------------")
  213. term.setTextColor(colors.black)
  214. end
  215.  
  216. function MainMenu()
  217. Title()
  218. ActiveItemList["Serveur"] = ItemsList["Serveur"]
  219. ActiveItemList["Client"] = ItemsList["Client"]
  220. ToolBox.Draw(ActiveItemList)
  221. end
  222. -------------------------------------------------------------------
  223. ----------------------Feature--------------------------------------
  224. -------------------------------------------------------------------
  225.  
  226. local function QuarryTurn()
  227. local Direction = ToolBox.AnitaRead("Last turn")
  228. shell.run('label set ' .. tostring(Direction))
  229. EmptySpace = false
  230. for i = 1,16 do
  231. if turtle.getItemCount(i)==0 then
  232. EmptySpace = true
  233. end
  234. end
  235. if EmptySpace == false then
  236. Home = true
  237. end
  238.  
  239. if Direction then
  240. ToolBox.MoveLeft()
  241. turtle.digDown()
  242. turtle.digUp()
  243. ToolBox.MoveForward()
  244.  
  245. turtle.digDown()
  246. turtle.digUp()
  247.  
  248. ToolBox.MoveLeft()
  249. else
  250. ToolBox.MoveRight()
  251. turtle.digDown()
  252. turtle.digUp()
  253. ToolBox.MoveForward()
  254.  
  255. turtle.digDown()
  256. turtle.digUp()
  257.  
  258. ToolBox.MoveRight()
  259. end
  260. Direction = not Direction
  261. ToolBox.AnitaWrite("Last turn", Direction)
  262. end
  263.  
  264. function Quarry()
  265. largeur = 7
  266. longueur = 7
  267. while true do
  268. if CurrentProgramme == "Quarry" then
  269. ToolBox.MoveDown()
  270. ToolBox.MoveDown()
  271. turtle.digDown()
  272. for i = 1,(largeur-1) do
  273. for i = 1,(longueur-1) do
  274. ToolBox.MoveForward()
  275. turtle.digDown()
  276. turtle.digUp()
  277. end
  278. QuarryTurn()
  279. end
  280. for i = 1,(longueur-1) do
  281. ToolBox.MoveForward()
  282. turtle.digDown()
  283. turtle.digUp()
  284. end
  285. ToolBox.AnitaWrite("Last turn", false)
  286. ToolBox.MoveRight()
  287. for i = 1,(largeur-1) do
  288. ToolBox.MoveForward()
  289. end
  290. ToolBox.MoveRight()
  291. ToolBox.MoveForward()
  292. end
  293. sleep(0.05)
  294. end
  295. end
  296.  
  297. local function Com()
  298. while true do
  299. local sender, message = rednet.receive()
  300. term.setBackgroundColor(colors.white)
  301. term.setTextColor(colors.black)
  302. term.setCursorPos(99,99)
  303. print(message)
  304. rednet.send(sender, "Réponse")
  305. end
  306. end
  307.  
  308. local function UI()
  309. while true do
  310. local myEvent = { os.pullEvent() }
  311. if myEvent[1] == "mouse_click" then
  312. for k,Element in pairs(ActiveItemList) do
  313. if Element["function"] ~= nil and myEvent[3] >= Element["xmin"] and myEvent[3] < Element["xmax"] and myEvent[4] >= Element["ymin"] and myEvent[4] <= Element["ymax"] then
  314. if Element["function"] ~= nil then
  315. Element["function"]()
  316. CurrentFunction = Element["function"]
  317. end
  318. end
  319. end
  320. end
  321. end
  322. end
  323.  
  324. local function Update()
  325. local time = os.time()
  326. term.setCursorPos(1,1)
  327. term.setTextColor(MenuTextColor)
  328. term.setBackgroundColor(MenuBackgroundColor)
  329. term.setCursorPos(1,1)
  330. term.clearLine()
  331. local time = os.time()
  332. local formattedTime = textutils.formatTime(time, false)
  333. term.write("Programme Anita V")
  334. term.write(version)
  335. for i = 1, (22 - string.len(version) - string.len(tostring(formattedTime))) do
  336. term.write(" ")
  337. end
  338. term.setTextColor(colors.white)
  339. term.write(formattedTime)
  340. sleep(0.05)
  341. end
  342.  
  343. local function Time()
  344. while true do
  345. if os.time() ~= LastTime then
  346. if CurrentFunction ~= nil then
  347. CurrentFunction()
  348. end
  349. LastTime = os.time()
  350. Update()
  351. else
  352. sleep(0.05)
  353. end
  354. end
  355. end
  356. -----------------------------------------------------------------------------------
  357. -------------------------------Main------------------------------------------------
  358. -----------------------------------------------------------------------------------
  359. GUInit()
  360. MainMenu()
  361.  
  362.  
  363. parallel.waitForAny(Quarry,UI,Com,Time)
Add Comment
Please, Sign In to add comment