Advertisement
SuperMcBrent

main

Feb 24th, 2023 (edited)
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.30 KB | Gaming | 0 0
  1. -- load libraries
  2. os.loadAPI("drawLib")
  3. os.loadAPI("buttonLib")
  4. os.loadAPI("dataLib")
  5. -- peripheral setup
  6.  
  7. local controllername = "left"
  8. local controller = peripheral.wrap(controllername)
  9. -- local modem = peripheral.wrap('top')
  10. -- modem.closeAll()
  11. -- modem.open(2)
  12.  
  13. -- Application Variables Setup
  14. local controllerX, controllerY
  15. local currentApp = "home"
  16. local previousApp = "home"
  17.  
  18. function resizeMon()
  19.     controllerX, controllerY = controller.getSize()
  20. end
  21.  
  22. function transmitToSlaves(message)
  23.     -- print('Transmitting: ' .. message)
  24.     modem.transmit(1,2,message)
  25. end
  26.  
  27. for i = 2, 5 do
  28.     -- wmod.open(i)
  29. end
  30.  
  31. function clearAll()
  32.     drawLib.empty(controller)
  33. end
  34.  
  35. -- Startup Functions
  36. function bootSequence()
  37.     -- drawTitle(displayX/2-5, displayY/2, "Booting...", colors.white, colors.black,display)
  38.     -- Application Triggers
  39.    
  40.     loadingScreen(controllerX,controllerY,controller)
  41. end
  42. function loadingScreen(monX,monY,monitor)
  43.     drawLib.drawTitle(monX/2-11, monY/2, "Create Above and Beyond OS", colors.white, colors.black,monitor)
  44.     drawLib.drawTitle(monX/2-9, monY-3, "Loading... Please wait", colors.white, colors.black,monitor)
  45.     for i=1, 30 do
  46.         --drawContent(2, monY-1, monY-2, 2, i, 100, colors.red, colors.gray,monitor)
  47.         drawLib.drawProg(2,monY-1, monX-2, 1, i, 30, colors.white, colors.gray,monitor)
  48.         sleep(0.05)
  49.     end
  50.     drawLib.empty(monitor)
  51. end
  52.  
  53. -- Utility Functions
  54. function formatNumbers(number,length)
  55.     return tostring(math.floor(number))..string.rep(" ",length-#tostring(math.floor(number)))
  56. end
  57. function table_count(T)
  58.   local count = 0
  59.   for _ in pairs(T) do count = count + 1 end
  60.   return count
  61. end
  62.  
  63. -- Application Functions
  64.  
  65. -- Add all buttons
  66. function addButtons()
  67.     -- Homebar Page Change
  68.     buttonLib.addButton(1,1,3,1,"pageLeft",colors.cyan,colors.red,true,"<- ","",1,1,"")
  69.     buttonLib.addButton(controllerX-2,1,3,1,"pageRight",colors.cyan,colors.red,true," ->","",controllerX-2,1,"")
  70.     -- Homebar Home
  71.     buttonLib.addButton(1,1,5,1,"homeButton1",colors.lime,colors.lightGray,true,"/^\\","",2,1,"")
  72.     buttonLib.addButton(1,2,5,1,"homeButton2",colors.lime,colors.lightGray,true,"|#|","",2,2,"")
  73.     -- Homebar Back
  74.     buttonLib.addButton(controllerX-4,1,5,1,"backButton1",colors.red,colors.lightGray,true,"/__","",controllerX-3,1,"")
  75.     buttonLib.addButton(controllerX-4,2,5,1,"backButton2",colors.red,colors.lightGray,true,"\\  ","",controllerX-3,2,"")
  76.     -- Applications
  77.     buttonLib.addButton(3,4,11,3,"farms",colors.cyan,colors.gray,true,"Farms","",6,5,"")
  78.     buttonLib.addButton(17,4,11,3,"setting",colors.cyan,colors.gray,true,"Setting","",19,5,"")
  79.     buttonLib.addButton(3,8,11,3,"storage",colors.cyan,colors.gray,true,"Storage","",5,9,"")
  80.     buttonLib.addButton(17,8,11,3,"graphs",colors.cyan,colors.gray,true,"Diagram","",19,9,"")
  81.     --addButton(3,12,11,3,"timelog",colors.cyan,colors.gray,true,"TimeLog","",5,13,"")
  82.     --addButton(17,12,11,3,"nothing",colors.cyan,colors.gray,false,"","Nothing",19,13,"")
  83.    
  84.     -- Settings Application Buttons
  85.     buttonLib.addButton(3,4,11,3,"restart",colors.red,colors.gray,true,"Restart","",5,5,"")
  86. end
  87.  
  88. -- Generate The Gui Based On Current State
  89. function generateGUI(monitor)
  90.     -- Draw Home Bar
  91.     drawLib.drawLine(1,1,controllerX,2,colors.gray,monitor)
  92.     buttonLib.drawButton("homeButton1",monitor)
  93.     buttonLib.drawButton("homeButton2",monitor)
  94.     buttonLib.drawButton("backButton1",monitor)
  95.     buttonLib.drawButton("backButton2",monitor)
  96.     drawLib.clearBox(controllerX/2-1,1,1,5,monitor,colors.gray)
  97.     drawLib.putTime(controllerX/2-1,1,monitor,true,colors.gray)
  98.     -- Draw Application Specific Items
  99.     if currentApp == "home" then
  100.         buttonLib.drawButton("farms",monitor)
  101.         buttonLib.drawButton("storage",monitor)
  102.         buttonLib.drawButton("graphs",monitor)
  103.         buttonLib.drawButton("setting",monitor)
  104.     elseif currentApp == "farms" then
  105.         drawLib.drawTitle(controllerX/2-1, 2, "Farms", colors.white, colors.gray, monitor)
  106.        
  107.     elseif currentApp == "storage" then
  108.         drawLib.drawTitle(controllerX/2-2, 2, "Storage", colors.white, colors.gray, monitor)
  109.        
  110.     elseif currentApp == "graphs" then
  111.         drawLib.drawTitle(controllerX/2-2, 2, "Diagram", colors.white, colors.gray, monitor)
  112.        
  113.     elseif currentApp == "setting" then
  114.         drawLib.drawTitle(controllerX/2-2, 2, "Setting", colors.white, colors.gray, monitor)
  115.         buttonLib.drawButton("restart",monitor)
  116.            
  117.     else error("App not found") end
  118.  
  119.     -- drawButton("pageLeft",monitor)
  120.     -- drawButton("pageRight",monitor)
  121. end
  122.  
  123. -- React To Touch Events
  124. function touchAreas(x,y,side)
  125.     -- Is On the main controller screen
  126.     if side == controllername then
  127.         if buttonLib.isWithinBoundingBox(x,y,"homeButton1") then
  128.             currentApp = "home"
  129.             drawLib.empty(controller)
  130.         elseif buttonLib.isWithinBoundingBox(x,y,"homeButton2") then
  131.             currentApp = "home"
  132.             drawLib.empty(controller)
  133.         elseif buttonLib.isWithinBoundingBox(x,y,"backButton1") then
  134.            
  135.         elseif buttonLib.isWithinBoundingBox(x,y,"backButton2") then
  136.      
  137.         elseif currentApp == "home" then
  138.             if buttonLib.isWithinBoundingBox(x,y,"farms") then
  139.                 currentApp = "farms"
  140.                 previousApp = "home"
  141.                 drawLib.empty(controller)
  142.             elseif buttonLib.isWithinBoundingBox(x,y,"storage") then
  143.                 currentApp = "storage"
  144.                 previousApp = "home"
  145.                 drawLib.empty(controller)
  146.             elseif buttonLib.isWithinBoundingBox(x,y,"graphs") then
  147.                 currentApp = "graphs"
  148.                 previousApp = "home"
  149.                 drawLib.empty(controller)
  150.             elseif buttonLib.isWithinBoundingBox(x,y,"setting") then
  151.                 currentApp = "setting"
  152.                 previousApp = "home"
  153.                 drawLib.empty(controller)
  154.             end
  155.         elseif currentApp == "farms" then
  156.            
  157.         elseif currentApp == "setting" then
  158.             if buttonLib.isWithinBoundingBox(x,y,"restart") then
  159.                 os.reboot()
  160.             else
  161.             end
  162.         else
  163.         end
  164.     else
  165.     end
  166. end
  167.  
  168. function waitForTouch()
  169.     parallel.waitForAny(wait,getTouch)
  170. end
  171.  
  172. function getTouch()
  173.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  174.     touchAreas(xPos, yPos, side)
  175. end
  176.  
  177. function wait()
  178.     sleep(0.5)
  179. end
  180.  
  181. function init()
  182.     clearAll()
  183.     resizeMon()
  184.     bootSequence()
  185.     addButtons()
  186.     clearAll()
  187.     while true do
  188.         generateGUI(controller)
  189.         waitForTouch()
  190.     end
  191. end
  192.  
  193. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement