Advertisement
KidBrine

Yeh

Aug 18th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.29 KB | None | 0 0
  1. -- Settings
  2. _G.Units = {
  3.   [1] = {"Flux", "KiloFlux", "MegaFlux", "GigaFlux", "TeraFlux", "PetaFlux", "ExaFlux", "ZettaFlux", "YottaFlux"};
  4.   [2] = {"RF", "KRF", "MRF", "GRF", "TRF", "PRF", "ERF", "ZRF", "YRF"}
  5. }
  6. integtick = 10
  7.  
  8. UnitMult = 1000
  9.  
  10. -- Peripherals
  11. _G.m = peripheral.wrap("left")
  12. _G.ec = peripheral.wrap("Induction Matrix_4")
  13. _G.ae = peripheral.wrap("appliedenergistics2:energy_acceptor_0")
  14. _G.meter = peripheral.wrap("rfmeter_1")
  15.  
  16. function _G.testae(ae)
  17.     if ae == nil then
  18.         rs.setOutput("back",true)
  19.         sleep(1)
  20.         rs.setOutput("back",false)
  21.         sleep(1)
  22.         rs.setOutput("back",true)
  23.         sleep(1)
  24.         rs.setOutput("back",false)
  25.         sleep(1)
  26.         ae = peripheral.wrap("appliedenergistics2:energy_acceptor_0")
  27.     else ae = ae end
  28.     return ae    
  29. end
  30. sleep(1)
  31. _G.ae = testae(ae)
  32. -- Peripheral Stuff
  33. _G.maxX, _G.maxY = m.getSize()
  34.  
  35. -- Initialization
  36. m.setTextScale(0.5)
  37. m.clear()
  38. m.setCursorPos(1,1)
  39. _G.function m.print(STR)
  40.     Mx, My = m.getCursorPos()
  41.     m.write(STR)
  42.     m.setCursorPos(1,My+1)
  43. end
  44.  
  45. _G.hr = ("-"):rep(maxX)
  46. notation = 1
  47.  
  48. -- Buttons
  49. _G.buttons = {} -- format: title = {x1=x1,y1=y1,x2=x2,y2=y2,callback}
  50.  
  51. --[[
  52.   common functions start here
  53. ]]--
  54.  
  55. -- Printing to screen
  56. function _G.writeIndent(str, indent)
  57.     if indent == nil then indent = 20 end
  58.     local y = ({m.getCursorPos()})[2]
  59.     m.setCursorPos(indent, y)
  60.     m.write((" "):rep(maxX - indent))
  61.     m.setCursorPos(indent, y)
  62.     m.write(str)
  63.     m.setCursorPos(1, y+1)
  64. end
  65.  
  66. -- Colors
  67. function _G.themeComponent(bg, fg)
  68.     local component = {}
  69.  
  70.     component.bg = bg
  71.     component.fg = fg
  72.  
  73.     function component:apply()
  74.         m.setBackgroundColor(self.bg)
  75.         m.setTextColor(self.fg)
  76.     end
  77.  
  78.     return component
  79. end
  80.  
  81. _G.theme = {
  82.     primary = themeComponent(colors.black, colors.white),
  83.     button = themeComponent(colors.yellow, colors.white),
  84.     button_muted = themeComponent(colors.black, colors.white)
  85. }
  86.  
  87. -- Rounding
  88. function _G.round(num, numDecimalPlaces)
  89.     local mult = 10^(numDecimalPlaces or 0)
  90.     return math.floor(num * mult + 0.5) / mult
  91. end
  92.  
  93. -- Energy Formatting
  94. function _G.formatEnergy(E, Unit)
  95.     if E < 0 then
  96.         M = -1
  97.     else
  98.         M = 1
  99.     end
  100.     local I = 1
  101.     E = E*M
  102.     while E >= UnitMult do
  103.         E = E/UnitMult
  104.         I = I+1
  105.     end
  106.     E = E*M
  107.     return round(E,2).." "..Units[Unit][I]
  108. end
  109.  
  110. --[[
  111.   event processing starts here
  112. ]]--
  113. function _G.onTouch(x,y)
  114.   for k,v in pairs(buttons) do
  115.     if v.x1 <= x and
  116.        v.y1 <= y and
  117.        v.x2 >= x and
  118.        v.y2 >= y then
  119.          v.callback(k, x, y)
  120.     end
  121.   end
  122. end
  123.  
  124.  
  125. --[[
  126.   per-peripheral functions start here
  127. ]]--
  128.  
  129. function _G.totalAEItems()
  130.     local all = ae.listAvailableItems()
  131.     local total = 0
  132.     for k,v in pairs(all) do
  133.         total = total + v.count
  134.     end
  135.     return total
  136. end
  137.  
  138. --[[
  139.   custom notation nonsense starts here
  140. ]]--
  141. m.setCursorPos(1,maxY)
  142. m.write("Notation: ")
  143. m.setCursorPos(20,maxY)
  144.  
  145. local _G.NotationText = {"Long", "Short"}
  146.  
  147.  
  148. function _G.renderButtons()
  149.   local before = {m.getCursorPos()}
  150.   m.setCursorPos(20, maxY)
  151.   if notation == 1 then theme.button:apply() else theme.button_muted:apply() end
  152.   m.write(NotationText[1])
  153.  
  154.   m.setCursorPos(25, maxY)
  155.   if notation == 2 then theme.button:apply() else theme.button_muted:apply() end
  156.   m.write(NotationText[2])
  157.  
  158.   theme.primary:apply()
  159.   m.setCursorPos(unpack(before))
  160. end
  161.  
  162. function changeNotation(notationId)
  163.   notation = notationId
  164.   renderButtons()
  165. end
  166.  
  167. buttons[1] = {x1 = 20, y1 = maxY, x2 = 23, y2 = maxY, callback = changeNotation}
  168. buttons[2] = {x1 = 25, y1 = maxY, x2 = 28, y2 = maxY, callback = changeNotation}
  169.  
  170. --[[
  171.   more nonsense starts here
  172. ]]--
  173.  
  174. function _G.formatTimer(S)
  175.     local M = 0
  176.     local H = 0
  177.     local D = 0
  178.     S2 = S%60
  179.     M = (S-S2)/60
  180.     M2 = M%60
  181.     H = (M-M2)/60
  182.     H2 = H%24
  183.     D = (H-H2)/24
  184.     S, M, H = S2, M2, H2
  185.     if S <= 9 then S = "0"..S end
  186.     if M <= 9 then M = "0"..M end
  187.     if H <= 9 then H = "0"..H end
  188.     if D <= 9 then D = "0"..D end
  189.     return (D..":"..H..":"..M..":"..S)
  190. end
  191.  
  192. m.setCursorPos(1,1)
  193. m.print("AE Stuff")
  194. m.print(hr)
  195. m.print("AE Energy Usage: ")
  196. m.print("AE Energy Storage: ")
  197. m.print(hr)
  198. m.print("I/O Rate: ")
  199.  
  200. m.setCursorPos(1,10)
  201. m.print("Energy Stuff")
  202. m.print(hr)
  203. m.print("Energy Net: ")
  204. m.setTextColor(colors.lime)
  205. m.print("|Energy Input: ")
  206. m.setTextColor(colors.red)
  207. m.print("|Energy Output: ")
  208. m.setTextColor(colors.white)
  209. m.print("Energy Meter: ")
  210. m.print("Energy Available: ")
  211. m.print("Energy Storage: ")
  212. m.print("Time Till 0 RF: ")
  213. m.setCursorPos(1,21)
  214. m.print("Notation Conversion")
  215. m.print(hr)
  216. m.print("Kilo - Thousand (K - K)")
  217. m.print("Mega - Million (M - M)")
  218. m.print("Giga - Billion (G - B)")
  219. m.print("Tera - Trillion (T - T)")
  220. m.print("Peta - Quadrillion (P - Qa)")
  221. m.print("Exa - Quintillion (E - Qi)")
  222. m.print("Zetta - Sextillion (Z - Sx)")
  223. m.print("Yotta - Septillion (Y - Sp)")
  224.  
  225. renderButtons()
  226.  
  227. lastTotal = 0
  228. lastIOTime = os.clock()
  229.  
  230. parallel.waitForAny(function()
  231. Tnum = 0
  232. Tneb = {}
  233. while true do
  234.     --shell.run("ExtrTresBG")
  235.     sleep(0)
  236. end
  237. end,
  238. function()
  239. while true do
  240.     local event, side, x, y = os.pullEvent("monitor_touch")
  241.     onTouch(x,y)
  242. end
  243. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement