Advertisement
Plazter

Sieve + GUI

Mar 25th, 2017
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.09 KB | None | 0 0
  1.   -- Components Definition
  2.  
  3. component = require("component")
  4. computer = require("computer")
  5. event = require("event")
  6. term = require("term")
  7. sides = require("sides")
  8. RScolors = require("colors")
  9. keyboard = require("keyboard")
  10. gpu = component.gpu
  11. trans = component.proxy(component.get("87c2"))
  12.  
  13.  
  14.   -- Variables Definition
  15.  
  16. Sleep_Loop = 2  
  17. colors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
  18. purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
  19. lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
  20. olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
  21. folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
  22. englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
  23. lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }
  24. button = {}
  25.  
  26. hammer = sides.north
  27. chest = sides.top
  28. siev = sides.south
  29.  
  30. borderColor = colors.orange
  31. TitleBorder = colors.lightBlue
  32. buttonColor = colors.white
  33.  
  34.   -- Functions
  35.  
  36. function draw_text(x, y, text, text_color, bg_color)
  37.     if text_color == nil then text_color = colors.white end
  38.     if bg_color == nil then bg_color = colors.black end
  39.     gpu.setBackground(bg_color)
  40.     gpu.setForeground(text_color)
  41.     gpu.set(x,y,text)
  42.     gpu.setBackground(colors.black)
  43.     gpu.setForeground(colors.white)
  44. end
  45.  
  46. function draw_line(x, y, length, height, bg_color)
  47.     gpu.setBackground(bg_color)
  48.     gpu.fill(x,y,length,height," ")
  49.     gpu.setBackground(colors.black)
  50. end
  51.  
  52. function draw_button(x, y, length, height, name, func, txt_color, bg_color, Active_bg_color, Active_name)
  53.     if Active_bg_color == nil then
  54.         Active_bg_color = bg_color
  55.     end
  56.     if Active_name == nil then
  57.         Active_name = name
  58.     end
  59.     if button[name] == nil then
  60.         button[name] = {}
  61.         button[name]["func"] = func
  62.         button[name]["active"] = false
  63.         button[name]["xmin"] = x
  64.         button[name]["ymin"] = y
  65.         button[name]["xmax"] = (x + length)-1
  66.         button[name]["ymax"] = (y + height)-1
  67.     end
  68.     if height > 1 then
  69.         yt = (y + tonumber(string.format("%.f",height/2))-1)
  70.     end
  71.     if button[name]["active"] == false then
  72.         if string.len(name) < length then
  73.             xt = x + ((length - string.len(name)) / 2)
  74.         end
  75.         draw_line(x, y, length, height, bg_color)
  76.         draw_text(xt, yt, name, txt_color, bg_color)
  77.     else
  78.         if string.len(Active_name) < length then
  79.             xt = x + ((length - string.len(Active_name)) / 2)
  80.         end
  81.         draw_line(x, y, length, height, Active_bg_color)
  82.         draw_text(xt, yt, Active_name, txt_color, Active_bg_color)
  83.     end
  84. end
  85.  
  86. function Progress_Bar(x, y , length, height , bg_empty_color, bg_full_color, progress)
  87.    
  88. end
  89.  
  90. function checkxy(x, y)
  91.     for name, data in pairs(button) do
  92.         if y>=data["ymin"] and  y <= data["ymax"] then
  93.             if x>=data["xmin"] and x<= data["xmax"] then
  94.                 data["func"]()
  95.                 return true
  96.             end
  97.         end
  98.     end
  99.     return false
  100. end
  101.  
  102. function getClick()
  103.     local _, _, x, y = event.pull(Sleep_Loop,touch)
  104.     if x == nil or y == nil then
  105.         local h, w = gpu.getResolution()
  106.         gpu.set(h, w, ".")
  107.         gpu.set(h, w, " ")
  108.     else
  109.         checkxy(x,y)
  110.     end
  111. end
  112.  
  113. function checkCobble()
  114.     top = trans.getInventorySize(chest)
  115.     for i = 1,top do
  116.         inventory = trans.getStackInSlot(chest, i)
  117.         if inventory ~= nil then
  118.             for k,v in pairs(inventory) do
  119.                 if k == "name" then
  120.                     if v == "minecraft:cobblestone" then
  121.                         trans.transferItem(chest, hammer, 1,i,1)
  122.                         os.sleep(.5)
  123.                         trans.transferItem(hammer, chest)
  124.                     end
  125.                 end
  126.             end
  127.         end
  128.     end
  129. end
  130.  
  131. function checkGravel()
  132.     checkCobble()
  133.     top = trans.getInventorySize(chest)
  134.     for i = 1,top do
  135.         inventory = trans.getStackInSlot(chest, i)
  136.         if inventory ~= nil then
  137.             for k,v in pairs(inventory) do
  138.                 if k == "name" then
  139.                     if v == "minecraft:gravel" then
  140.                         trans.transferItem(chest, siev, 1, i, 1)
  141.                         os.sleep(.5)
  142.                     end
  143.                 end
  144.             end
  145.         end
  146.     end
  147. end
  148.  
  149. function checkSand()
  150.     top = trans.getInventorySize(chest)
  151.     for i = 1,top do
  152.         inventory = trans.getStackInSlot(chest, i)
  153.         if inventory ~= nil then
  154.             for k,v in pairs(inventory) do
  155.                 if k == "name" then
  156.                     if v == "minecraft:cobblestone" then
  157.                         trans.transferItem(chest, hammer, 1,i, 1)
  158.                         os.sleep(.5)
  159.                         trans.transferItem(hammer, chest)
  160.                     elseif v == "minecraft:gravel" then
  161.                         trans.transferItem(chest,hammer, 1,i,1)
  162.                         os.sleep(.5)
  163.                         trans.transferItem(hammer, chest)
  164.                     end
  165.                     if v == "minecraft:sand" then
  166.                         trans.transferItem(chest, siev, 1,i, 1)
  167.                         os.sleep(.5)
  168.                     end
  169.                 end
  170.             end
  171.         end
  172.     end
  173. end
  174.  
  175. function Status()
  176.     if args[1] == "sand" then
  177.         checkSand()
  178.     elseif args[1] == "gravel" then
  179.         checkGrav()
  180.     end
  181. end
  182.  
  183. function border_Lines()
  184.     -- title borders
  185.     draw_line(10,3,41,1,TitleBorder)
  186.     draw_line(50,3,1,4,TitleBorder)
  187.     draw_line(10,7,41,1,TitleBorder)
  188.     draw_line(10,3,1,4,TitleBorder)
  189.     -- monitoring borders
  190.    
  191.     -- ext borders
  192.     draw_line(1,1,61,1,borderColor)
  193.     draw_line(1,1,1,30,borderColor)
  194.     draw_line(1,30,61,1,borderColor)
  195.     draw_line(60,1,1,60,borderColor)
  196. end
  197.  
  198. function toggle_Sand()
  199.     if button["Sand"]["active"] == false then
  200.         button["Sand"]["active"] = true
  201.     else
  202.         button["Sand"]["active"] = false
  203.     end
  204. end
  205.  
  206. function toggle_Gravel()
  207.     if button["Gravel"]["active"] == false then
  208.         button["Gravel"]["active"] = true
  209.     else
  210.         button["Gravel"]["active"] = false
  211.         end
  212. end
  213.  
  214. function toggle_Cobble()
  215.     if button["Cobblestone"]["active"] == false then
  216.         button["Cobblestone"]["active"] = true
  217.     else
  218.         button["Cobblestone"]["active"] = false
  219.     end
  220. end
  221.  
  222. function reboot()
  223.     computer.shutdown(true)
  224. end
  225.  
  226. function init()
  227.     term.clear()  
  228.     gpu.setResolution(60,30)
  229.     draw_text(21,5, "Selector for sieves")
  230. end
  231.  
  232.  
  233.   -- Main Code
  234.  
  235. init()
  236. while true do
  237.     draw_button(10,10,16,3,"Cobblestone",toggle_Cobble,colors.black,buttonColor,colors.green,"Cobble")
  238.     button["Cobblestone"]["displayed"] = true
  239.     draw_button(36,10,16,3,"Sand",toggle_Sand,colors.black,buttonColor,colors.green,"Sand")
  240.     button["Sand"]["displayed"] = true
  241.     draw_button(21,15,20,3,"Gravel",toggle_Gravel,colors.black,buttonColor,colors.green,"Gravel")
  242.     button["Gravel"]["displayed"] = true
  243.     border_Lines()
  244.     if button["Sand"]["active"] == true then checkSand() end
  245.     if button["Cobblestone"]["active"] == true then checkCobble() end
  246.     if button["Gravel"]["active"] == true then checkGravel() end
  247.     getClick()
  248. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement