Advertisement
Impshial

Tekkit Base Monitor

Jun 5th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.15 KB | None | 0 0
  1. -- Base Monitoring System
  2. -- Version 0.2
  3. -----------------------------------------------------------------------------------------------------------------
  4. -- Tested on Computercraft version 1.58
  5. -- Minecraft version 1.6.4
  6. -----------------------------------------------------------------------------------------------------------------
  7. -- NOTE: THIS IS A WORK IN PROGRESS
  8. -----------------------------------------------------------------------------------------------------------------
  9. --
  10. -- This code was written by Impshial and is free software:
  11. -- You can redistribute it and/or modify
  12. -- it under the terms of the GNU General Public License as published by
  13. -- the Free Software Foundation, either version 3 of the License, or
  14. -- (at your option) any later version.
  15.  
  16. -- This program is distributed in the hope that it will be useful,
  17. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. -- GNU General Public License for more details.
  20. --
  21. -- See https://www.gnu.org/licenses/ for details
  22. --
  23. -- Pastebin for this program: https://pastebin.com/B6kvjRxZ
  24. --
  25. -- Pastebin for the ImpShial API: https://pastebin.com/pwBMKNCb
  26. --
  27. -- Instructions:
  28. --      1. Place an Advanced Computer
  29. --      2. Attach wired Modem to computer
  30. --      3. Set up a monitor (if there is no monitor present, the program will let you know)
  31. --      4. Attach wired Modem to monitor
  32. --      5. Connect computer and monitor via Network Cables
  33. --      6. Right-click each modem to connect devices to network
  34. --      7. Run the following command in Computer Terminal: "pastebin get B6kvjRxZ startup"
  35. --      8. Run "startup" (API will be downloaded and installed in this step)
  36. --      9. Attach machines via Modems and newtwork cable. Machines will automatically show up on monitor when connected
  37. --      10. Right-click on machine name to get details
  38. --
  39. -----------------------------------------------------------------------------------------------------------------
  40. -- Version notes:
  41. --  Added button-click capability for machines
  42. --  Works with all Thermal expansion machines
  43. --  Works with most Minefactory Reloaded machines
  44. --  GPL License verbiage added
  45. -----------------------------------------------------------------------------------------------------------------
  46. -- Bugs:
  47. --  Right-click intermittantly works
  48. --  Delay between right-click and machine being selected
  49. -----------------------------------------------------------------------------------------------------------------
  50. --
  51. -- Begin Program
  52. --
  53. -----------------------------------------------------------------------------------------------------------------
  54.  
  55. -- Variables
  56. local version = "0.2"       -- Program Version
  57. local scale                 -- the text scale for the monitor
  58. local monX                  -- Monitor Width
  59. local monY                  -- Monitor Height
  60. local line                  -- Monitor line variable
  61. local sizeXY                -- Text scale
  62. local mainLoop              -- Main loop variable. set to < 1 to stop loop
  63. local tableMachines = {}    -- Main machine table
  64. local render                -- Should we render the machine list?
  65. local renderReason          -- Why is our monitor too small?
  66. local clicked               -- Has the user clicked a machine?
  67. local clickedLine           -- which line was clicked
  68. local headerFooterColor     -- Color for the header/footer bar
  69. local headerFooterTextColor -- Color for header/footer text
  70. local selectedBackColor     -- Colors for selected item background
  71. local selectedTextColor     -- Colors for selected item text
  72. local detailsKeyColumn      -- Column to start at for details Key
  73. local detailsValueColumn        -- Column to start at for details Value
  74. local debugMode             -- For testing
  75.  
  76. -----------------------------------------------------------------------------------------------------------------
  77. -- Local Functions
  78. -----------------------------------------------------------------------------------------------------------------
  79.  
  80. -- Get number from machine/entity name
  81. function getMachineEntityNumber(machineName)
  82.     lastChars = string.sub(machineName, -2)
  83.    
  84.     if string.match(lastChars, "_") then
  85.         return string.sub(lastChars, -1)
  86.     else
  87.         return string.sub(lastChars, -2)
  88.     end
  89.    
  90.    
  91. end
  92. -----------------------------------------------------------------------------------------------------------------
  93. -- Startup code
  94. -----------------------------------------------------------------------------------------------------------------
  95.  
  96. -- Write startup message to Terminal
  97. term.clear()
  98.  
  99. -- Check to see if the API file exists
  100. if fs.exists("ImpAPI") == false then
  101.     term.setCursorPos(1,1)
  102.     term.setTextColor(colors.red)
  103.     term.write("Missing API File! Attempting to download...")
  104.     term.setTextColor(colors.white)
  105.     shell.run("pastebin get pwBMKNCb ImpAPI")   -- Go out and download it
  106.     sInput = nil
  107.     term.setCursorPos(1,5)
  108.     term.setTextColor(colors.green)
  109.     term.write("API Loaded.")
  110.     term.setCursorPos(1,7)
  111.     term.setTextColor(colors.white)
  112.     term.write("Press enter to continue...")
  113.     while true do
  114.        sInput = read()
  115.        if sInput ~= nil or sInput ~= "" then
  116.              break
  117.              
  118.        end
  119.     end
  120. end
  121.  
  122. os.loadAPI("ImpAPI")
  123.  
  124. term.clear()
  125. ImpAPI.draw_line_term(1,1,55,colors.green)
  126. term.setCursorPos(1,1)
  127. term.write("Base Monitoring System")
  128. ImpAPI.draw_line_term(1,2,55,colors.black)
  129. term.setCursorPos(1,3)
  130. term.write("Version"..version)
  131. term.setCursorPos(1,5)
  132. term.write("Finding Monitor...")
  133.  
  134. -- Find our monitor and define it
  135. mon=ImpAPI.monitorSearch()
  136.  
  137. -- Check to see if a monitor exists
  138. if mon then     -- Found it
  139.     ImpAPI.CTWrite(1,6,"Monitor Found!",colors.green)
  140.     ImpAPI.CTWrite(1,8,"System Running",colors.orange)
  141.    
  142. else            -- No monitor Present
  143.     ImpAPI.CTWrite(1,6,"Monitor Not Found!",colors.red)
  144.     ImpAPI.CTWrite(1,8,"Please Attach a Monitor",colors.red)
  145.     term.setCursorPos(1,9)
  146.     return
  147. end
  148.  
  149. -- Set the initial text scale
  150. scale = 0.5
  151.  
  152. -- Set the begining line for our text
  153. line = 1
  154.  
  155. -- Set the initial text scale
  156. sizeXY = 1
  157.  
  158. -- Set the main Loop variable
  159. mainLoop = 1
  160.  
  161. -- Set our monitor to the initial text scale
  162. mon.setTextScale(sizeXY)
  163.  
  164. -- Write out our machine list
  165. render = true
  166.  
  167. -- Nothing has been clicked
  168. clicked = false
  169.  
  170. -- Set our header/footer color
  171. headerFooterColor = colors.blue
  172.  
  173. -- Set our header/footer text color
  174. headerFooterTextColor = colors.white
  175.  
  176. -- Set background color for selected machine
  177. selectedBackColor = colors.white
  178.  
  179. -- Set text color for selected machine
  180. selectedTextColor = colors.black
  181.  
  182. -- Set the details Key column
  183. detailsKeyColumn = 43
  184.  
  185. -- Set the details value column value
  186. detailsValueColumn = 55
  187.  
  188. -- Debug mode?
  189. debugMode = false
  190. -----------------------------------------------------------------------------------------------------------------
  191. -- Main Loop
  192. -----------------------------------------------------------------------------------------------------------------
  193.  
  194. while mainLoop > 0 do
  195.    
  196.     -- Get our monitor size
  197.     monX, monY = mon.getSize()
  198.    
  199.     -- Change textScale when monitor size changes
  200.     if monX < 62 and scale == 1 then
  201.        
  202.         scale = 0.5
  203.     elseif monX > 142 and scale < 1 then
  204.        
  205.         scale = 1
  206.     elseif monX < 143 and scale < 1 then
  207.        
  208.         scale = 0.5
  209.     end
  210.            
  211.     mon.setTextScale(scale)
  212.    
  213.     -- If monitor is too small, let the user know
  214.    
  215.     if monX < 79 and scale == 0.5 then
  216.         render = false
  217.         renderReason = "Reason: Width"
  218.     elseif monY < 24 and scale == .05 then
  219.         render = false
  220.         renderReason = "Reason: Height"
  221.     elseif monY < 19 and scale == 1 then
  222.         render = false
  223.         renderReason = "Reason: Height"
  224.     else
  225.         render = true
  226.     end
  227.    
  228.     -- Get all peripherals on the network
  229.     machines=peripheral.getNames()
  230.        
  231.     --Create/Clear out main machine table
  232.     tableMachines = {}
  233.    
  234.    
  235.     if render == true then
  236.  
  237. -----------------------------------------------------------------------------------------------------------------
  238. -- Loop through machines
  239. -----------------------------------------------------------------------------------------------------------------
  240.         for i = 1, #machines do
  241.             machNbr = getMachineEntityNumber(machines[i])
  242.            
  243.             if string.match(machines[i], "thermalexpansion_machine_furnace") then
  244.                
  245.                 -- Check to see if furnace is active
  246.                 machine=peripheral.wrap(machines[i])
  247.                 isActive=machine.getStackInSlot(1)
  248.                 itemInSlot1 = ""
  249.                 itemQtyInSlot1 = ""
  250.                 itemInSlot2 = ""
  251.                 ItemQtyInSlot2 = ""
  252.                
  253.                 activeText = ""
  254.                
  255.                 if isActive then
  256.                     activeText = "Active"
  257.                 else
  258.                     activeText = "InActive"
  259.                 end
  260.                
  261.                 processing=machine.getStackInSlot(1)
  262.                 processed1=machine.getStackInSlot(2)
  263.                
  264.                 if processing then
  265.                
  266.                     for k,v in pairs(processing) do
  267.                         if k == "name" then
  268.                             itemInSlot1 = v
  269.                         elseif k == ("qty") then
  270.                             itemQtyInSlot1 = tostring(v)
  271.                         end
  272.                     end
  273.                 else
  274.                     itemInSlot1 = "Nothing"
  275.                     itemQtyInSlot1 = "0"
  276.                 end
  277.                
  278.                 if processed1 then 
  279.                     for k,v in pairs(processed1) do
  280.                         if k == "name" then
  281.                             itemInSlot2 = v
  282.                         elseif k == ("qty") then
  283.                             itemQtyInSlot2 = tostring(v)
  284.                         end
  285.                     end
  286.                 else
  287.                     itemInSlot2 = "Nothing"
  288.                     itemQtyInSlot2 = "0"
  289.                 end
  290.                
  291.                 table.insert(tableMachines, {   ["Machine"]="Redstone Furnace",
  292.                                                 ["Number"]=machNbr,
  293.                                                 ["HasEnergy"]=true,
  294.                                                 ["Energy"]=machine.getEnergy(),
  295.                                                 ["IsActive"]=activeText,
  296.                                                 ["PerName"]=machines[i],
  297.                                                 ["MaxEnergy"]=machine.getMaxEnergy(),
  298.                                                 ["ItemInSlot1"]=itemInSlot1,
  299.                                                 ["ItemQtyInSlot1"]=itemQtyInSlot1,
  300.                                                 ["slot1Name"]="Processing: ",
  301.                                                 ["ItemInSlot2"]=itemInSlot2,
  302.                                                 ["ItemQtyInSlot2"]=itemQtyInSlot2,
  303.                                                 ["slot2Name"]="Output: ",
  304.                                                 ["InventorySlots"]=2})
  305.                
  306.  
  307.             elseif string.match(machines[i], "thermalexpansion_machine_pulverizer") then
  308.                
  309.                 -- Check to see if pulverizer is active
  310.                 -- Check to see if furnace is active
  311.                 machine=peripheral.wrap(machines[i])
  312.                 isActive=machine.getStackInSlot(1)
  313.                 itemInSlot1 = ""
  314.                 itemQtyInSlot1 = ""
  315.                 itemInSlot2 = ""
  316.                 ItemQtyInSlot2 = ""
  317.                 itemInSlot3 = ""
  318.                 ItemQtyInSlot3 = ""
  319.                
  320.                 activeText = ""
  321.                
  322.                 if isActive then
  323.                     activeText = "Active"
  324.                 else
  325.                     activeText = "InActive"
  326.                 end
  327.                
  328.                 processing=machine.getStackInSlot(1)
  329.                 processed1=machine.getStackInSlot(2)
  330.                 processed2=machine.getStackInSlot(3)
  331.                
  332.                 if processing then
  333.                
  334.                     for k,v in pairs(processing) do
  335.                         if k == "name" then
  336.                             itemInSlot1 = v
  337.                         elseif k == ("qty") then
  338.                             itemQtyInSlot1 = tostring(v)
  339.                         end
  340.                     end
  341.                 else
  342.                     itemInSlot1 = "Nothing"
  343.                     itemQtyInSlot1 = "0"
  344.                 end
  345.                
  346.                 if processed1 then 
  347.                     for k,v in pairs(processed1) do
  348.                         if k == "name" then
  349.                             itemInSlot2 = v
  350.                         elseif k == ("qty") then
  351.                             itemQtyInSlot2 = tostring(v)
  352.                         end
  353.                     end
  354.                 else
  355.                     itemInSlot2 = "Nothing"
  356.                     itemQtyInSlot2 = "0"
  357.                 end
  358.                
  359.                 if processed2 then 
  360.                     for k,v in pairs(processed2) do
  361.                         if k == "name" then
  362.                             itemInSlot3 = v
  363.                         elseif k == ("qty") then
  364.                             itemQtyInSlot3 = tostring(v)
  365.                         end
  366.                     end
  367.                 else
  368.                     itemInSlot3 = "Nothing"
  369.                     itemQtyInSlot3 = "0"
  370.                 end
  371.                
  372.                 table.insert(tableMachines, {   ["Machine"]="Pulverizer",
  373.                                                 ["Number"]=machNbr,
  374.                                                 ["HasEnergy"]=true,
  375.                                                 ["Energy"]=machine.getEnergy(),
  376.                                                 ["IsActive"]=activeText,
  377.                                                 ["PerName"]=machines[i],
  378.                                                 ["MaxEnergy"]=machine.getMaxEnergy(),
  379.                                                 ["ItemInSlot1"]=itemInSlot1,
  380.                                                 ["ItemQtyInSlot1"]=itemQtyInSlot1,
  381.                                                 ["slot1Name"]="Processing: ",
  382.                                                 ["ItemInSlot2"]=itemInSlot2,
  383.                                                 ["ItemQtyInSlot2"]=itemQtyInSlot2,
  384.                                                 ["slot2Name"]="Output: ",
  385.                                                 ["ItemInSlot3"]=itemInSlot3,
  386.                                                 ["ItemQtyInSlot3"]=itemQtyInSlot3,
  387.                                                 ["slot3Name"]="Bonus: ",
  388.                                                 ["InventorySlots"]=3})
  389.                
  390.  
  391.             elseif string.match(machines[i], "thermalexpansion_machine_smelter") then
  392.                
  393.                 -- Check to see if induction smelter is active
  394.                 machine=peripheral.wrap(machines[i])
  395.                 isActive=machine.getStackInSlot(1)
  396.                
  397.                 if isActive then
  398.                     tableMachines["Induction Smelter "..machNbr] = "Active"
  399.                 else
  400.                     tableMachines["Induction Smelter "..machNbr] = "Inactive"
  401.                 end
  402.             elseif string.match(machines[i], "thermalexpansion_machine_crucible") then
  403.                
  404.                 -- Check to see if pulverizer is active
  405.                 machine=peripheral.wrap(machines[i])
  406.                 isActive=machine.getStackInSlot(1)
  407.                 if isActive then
  408.                     tableMachines["Magma Crucible "..machNbr] = "Active"
  409.                 else
  410.                     tableMachines["Magma Crucible "..machNbr] = "Inactive"
  411.                 end
  412.             elseif string.match(machines[i], "thermalexpansion_machine_transposer") then
  413.                
  414.                 -- Check to see if pulverizer is active
  415.                 machine=peripheral.wrap(machines[i])
  416.                 isActive=machine.getStackInSlot(1)
  417.                 if isActive then
  418.                     tableMachines["Fluid Transposer "..machNbr] = "Active"
  419.                 else
  420.                     tableMachines["Fluid Transposer "..machNbr] = "Inactive"
  421.                 end
  422.             end
  423.         end
  424.        
  425. -----------------------------------------------------------------------------------------------------------------
  426. -- Write static text to main monitor
  427. -----------------------------------------------------------------------------------------------------------------      
  428.         mon.clear()
  429.        
  430.         -- Header
  431.         ImpAPI.draw_line(1, line, monX, headerFooterColor, mon)
  432.         ImpAPI.CWrite(1, line, mon, "Networked Machines", headerFooterTextColor)
  433.         ImpAPI.CWrite(29, line, mon, "Status", headerFooterTextColor)
  434.        
  435.         -- Center details location based on monitor width
  436.         startLeft = 41 + ((monX - 41) / 2 - 3)
  437.         ImpAPI.CWrite(startLeft, line, mon, "Details", headerFooterTextColor)
  438.        
  439.         line = line + 2
  440.        
  441.         -- Details line
  442.         for l = 2,(monY -1) do
  443.             ImpAPI.draw_line(40,l, 1, headerFooterColor, mon)
  444.         end
  445.        
  446.        
  447.         -- Footer
  448.         ImpAPI.draw_line(1, monY, monX, headerFooterColor, mon)
  449.         ImpAPI.CWrite(1,monY,mon,"Impshial Base Monitor: v"..version, headerFooterTextColor)
  450.         ImpAPI.draw_line(1, (monY+1), monX, colors.black, mon)
  451.                
  452. -----------------------------------------------------------------------------------------------------------------
  453. -- Begin machine loop
  454. -----------------------------------------------------------------------------------------------------------------                  
  455.         for i = 1,#tableMachines do
  456.             machName = tableMachines[i].Machine
  457.             machNumber = tableMachines[i].Number
  458.             machHasEnergy = tableMachines[i].HasEnergy
  459.             invSlots = tableMachines[i].InventorySlots
  460.                        
  461.             machColor = colors.white
  462.            
  463.             if clicked == true and clickedLine == line then
  464.                 -- machine selected...
  465.                 ImpAPI.draw_line(1,line, 39, selectedBackColor, mon)
  466.             else
  467.                 -- machine NOT selected...
  468.                 ImpAPI.draw_line(1,line, 39, colors.black, mon)
  469.             end
  470.            
  471.             mon.setCursorPos(2,line)
  472.            
  473.             if clicked == true and clickedLine == line then
  474.                     machColor = selectedTextColor
  475.             else
  476.                 if string.match(machName,"Furnace") then
  477.                     machColor = colors.cyan
  478.                 elseif string.match(machName,"Pulverizer") then
  479.                     machColor = colors.orange
  480.                 elseif string.match(machName,"Induction") then
  481.                     machColor = colors.lime
  482.                 elseif string.match(machName,"Crucible") then
  483.                     machColor = colors.lightBlue
  484.                 elseif string.match(machName,"Transposer") then
  485.                     machColor = colors.lightGray
  486.                 end
  487.             end
  488.  
  489.            
  490.             ImpAPI.CWrite(2,line,mon, machName.." "..machNumber, machColor)
  491.             -- Status
  492.             if tableMachines[i].IsActive == "InActive" then
  493.                 ImpAPI.CWrite(28,line,mon, tableMachines[i].IsActive, colors.red)
  494.                
  495.             else
  496.                 ImpAPI.CWrite(28,line,mon, tableMachines[i].IsActive, colors.green)
  497.                
  498.             end
  499.            
  500.            
  501. -----------------------------------------------------------------------------------------------------------------          
  502. -- Details
  503. -----------------------------------------------------------------------------------------------------------------
  504.  
  505.             detailsLine = 3
  506.            
  507.             if clicked == true and clickedLine == line then
  508.                 -- Machine Name
  509.                 ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  510.                 ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, "Machine: ", colors.orange)
  511.                 ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, machName.." "..machNumber, colors.white)
  512.                 detailsLine = detailsLine + 1
  513.                
  514.                 -- Energy (if applicable)
  515.                 if machHasEnergy == true then
  516.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  517.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, "Energy: ", colors.orange)
  518.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].Energy.."/"..tableMachines[i].MaxEnergy, colors.white)
  519.                     detailsLine = detailsLine + 2
  520.                 else
  521.                     detailsLine = detailsLine + 3
  522.                 end
  523.                    
  524.                     -- Slot 1 Item
  525.                 if invSlots > 0 then
  526.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  527.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, tableMachines[i].slot1Name, colors.orange)
  528.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].ItemInSlot1, colors.white)
  529.                     detailsLine = detailsLine + 1
  530.                    
  531.                     -- Slot 1 Qty
  532.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  533.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, "Qty: ", colors.orange)
  534.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].ItemQtyInSlot1, colors.white)
  535.                     detailsLine = detailsLine + 2
  536.                 end
  537.                
  538.                 if invSlots > 1 then
  539.                     -- Slot 2 Item
  540.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  541.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, tableMachines[i].slot2Name, colors.orange)
  542.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].ItemInSlot2, colors.white)
  543.                     detailsLine = detailsLine + 1
  544.                    
  545.                     -- Slot 2 Qty
  546.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  547.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, "Qty: ", colors.orange)
  548.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].ItemQtyInSlot2, colors.white)
  549.                     detailsLine = detailsLine + 2
  550.                 end
  551.                
  552.                 if invSlots > 2 then
  553.                     -- Slot 3 Item
  554.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  555.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, tableMachines[i].slot3Name, colors.orange)
  556.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].ItemInSlot3, colors.white)
  557.                     detailsLine = detailsLine + 1
  558.                    
  559.                     -- Slot 3 Qty
  560.                     ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  561.                     ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, "Qty: ", colors.orange)
  562.                     ImpAPI.CWrite(detailsValueColumn, detailsLine, mon, tableMachines[i].ItemQtyInSlot3, colors.white)
  563.                     detailsLine = detailsLine + 2
  564.                 end
  565.                
  566.             elseif clicked == false then
  567.                 ImpAPI.draw_line(detailsKeyColumn, detailsLine, (monX - detailsKeyColumn), colors.black, mon)
  568.                 ImpAPI.CWrite(detailsKeyColumn, detailsLine, mon, "No Machine Selected", colors.red)
  569.                 detailsLine = detailsLine + 1
  570.             end
  571.            
  572.            
  573.            
  574.            
  575.            
  576.            
  577.            
  578.             ImpAPI.draw_line(1,line+1, 39, colors.black, mon)  
  579.             line = line + 1
  580.                    
  581.         end    
  582.        
  583. -----------------------------------------------------------------------------------------------------------------
  584. -- Watch for mouse events
  585. -----------------------------------------------------------------------------------------------------------------
  586.         local myTimer = os.startTimer(.2)
  587.        
  588.         local exitConditionVariable = false
  589.        
  590.         while not exitConditionVariable do
  591.                 myEvent = {os.pullEvent()}
  592.                 if myEvent[1] == "monitor_touch" then
  593.                     xClicked=myEvent[3]
  594.                     yClicked=myEvent[4]
  595.                     --ImpAPI.CWrite(1,27,mon,ImpAPI.tablelength(tableMachines) + 2,colors.orange)
  596.                     if yClicked > 2 and yClicked <= (ImpAPI.tablelength(tableMachines) + 2) then
  597.                         clicked = true
  598.                         clickedLine = yClicked
  599.                     else   
  600.                         clicked = false
  601.                     end
  602.                    
  603.                    
  604.                         --button.checkxy(myEvent[3],myEvent[4])
  605.                 elseif myEvent[1] == "timer" and myEvent[2] == myTimer then
  606.                         exitConditionVariable = true
  607.                 end
  608.         end
  609.        
  610.         -- Debug for monitor size
  611.         if debugMode then
  612.             mon.setCursorPos(1,line)
  613.             mon.write("S: "..sizeXY)
  614.             line = line + 1
  615.             mon.setCursorPos(1,line)
  616.             mon.write("H: "..monY)
  617.             line = line + 1
  618.             mon.setCursorPos(1,line)
  619.             mon.write("W: "..monX)
  620.         end
  621.     else   
  622.         mon.clear()
  623.         ImpAPI.draw_line(1,1,monX, colors.red, mon)
  624.         mon.setCursorPos(1,1)
  625.         mon.setTextColor(colors.white)
  626.         mon.write("Monitor Too Small")
  627.         ImpAPI.draw_line(1,2,monX, colors.black, mon)
  628.         mon.setCursorPos(1,3)
  629.         mon.write("Please increase the")
  630.         mon.setCursorPos(1,4)
  631.         mon.write("size of your monitor")
  632.         mon.setCursorPos(1,5)
  633.         mon.write(renderReason)
  634.     end
  635.    
  636.     -- Reset line variable
  637.     line = 1
  638.  
  639.     -- Loop timer
  640.     sleep(.25)
  641. end
  642.  
  643. -----------------------------------------------------------------------------------------------------------------
  644. -- End of Program
  645. -----------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement