Advertisement
Guest User

draconicProgram.lua

a guest
Jan 24th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.16 KB | None | 0 0
  1. local component = require("component")
  2. local c = component.computer
  3. local cell = component.getPrimary("draconic_rf_storage")
  4. local gpu = component.gpu
  5. local colors = require("colors")
  6. local term = require("term")
  7. local event = require("event")
  8. local thread = require("thread")
  9.  
  10. local width, height = gpu.getResolution()
  11.  
  12. loopActive = true
  13. local userInputThread = thread.create(function()
  14.   while true do
  15.     if event.pull("touch") then
  16.       loopActive = false
  17.       gpu.setBackground(0x000000)
  18.       gpu.setForeground(0xFFFFFF)
  19.       os.sleep(0.01)
  20.       gpu.fill(1,1,width,height," ")
  21.       term.setCursor(1,1)
  22.       os.exit()
  23.     end
  24.   end
  25. end)
  26.  
  27. local powerLowAlert = thread.create(function()
  28.   while loopActive do
  29.     if ((cell.getEnergyStored()/cell.getMaxEnergyStored())*100)<5 then
  30.       c.beep(500,0.1)
  31.       os.sleep(0.4)
  32.     end
  33.     os.sleep(0.1)
  34.   end
  35. end)
  36.  
  37. local function cls()
  38.   gpu.fill(1,1,width,height," ")
  39. end
  40.  
  41. local function bgColor(color)
  42.   if color == 'black' then
  43.     gpu.setBackground(0x000000)
  44.   end
  45.   if color == 'darkgray' then
  46.     gpu.setBackground(0x444444)
  47.   end
  48.   if color == 'gray' then
  49.     gpu.setBackground(0x888888)
  50.   end
  51.   if color == 'lightgray' then
  52.     gpu.setBackground(0xBBBBBB)
  53.   end
  54.   if color == 'white' then
  55.     gpu.setBackground(0xFFFFFF)
  56.   end
  57.   if color == 'red' then
  58.     gpu.setBackground(0xFF0000)
  59.   end
  60.   if color == 'green' then
  61.     gpu.setBackground(0x00FF00)
  62.   end
  63.   if color == 'blue' then
  64.     gpu.setBackground(0x0000FF)
  65.   end
  66.   if color == 'yellow' then
  67.     gpu.setBackground(0xFFFF00)
  68.   end
  69.   if color == 'violet' then
  70.     gpu.setBackground(0xFF00FF)
  71.   end
  72.   if color == 'aqua' then
  73.     gpu.setBackground(0x00FFFF)
  74.   end
  75.   if color == 'orange' then
  76.     gpu.setBackground(0xFF8800)
  77.   end
  78.   if color == 'pink' then
  79.     gpu.setBackground(0xFF88FF)
  80.   end
  81.   if color == 'brown' then
  82.     gpu.setBackground(0x884400)
  83.   end
  84.   if color == 'darkgreen' then
  85.     gpu.setBackground(0x008800)
  86.   end
  87.   if color == 'purple' then
  88.     gpu.setBackground(0x990099)
  89.   end
  90. end
  91.  
  92. local function fgColor(color)
  93.   prevColor = gpu.getBackground()
  94.   bgColor(color)
  95.   gpu.setForeground(gpu.getBackground())
  96.   gpu.setBackground(prevColor)
  97. end
  98.  
  99. local function draw(x,y,a,b)
  100.   gpu.fill(x,y,a,b," ")
  101. end
  102.  
  103. local function colorDraw(x,y,a,b,color)
  104.   prevColor = gpu.getBackground()
  105.   bgColor(color)
  106.   gpu.fill(x,y,a,b," ")
  107.   gpu.setBackground(prevColor)
  108. end
  109.  
  110. local function text(x,y,text)
  111.   term.setCursor(x,y)
  112.   print(text)
  113. end
  114.  
  115. local function colorText(x,y,text,bColor,fColor)
  116.   prevBgColor = gpu.getBackground()
  117.   prevFgColor = gpu.getForeground()
  118.   bgColor(fColor)
  119.   gpu.setForeground(gpu.getBackground())
  120.   bgColor(bColor)
  121.   term.setCursor(x,y)
  122.   print(text)
  123.   gpu.setBackground(prevBgColor)
  124.   gpu.setForeground(prevFgColor)
  125. end
  126.  
  127. cls()
  128. text(1,1,"Damckell Graphical Interface; DGI")
  129. os.sleep(1.25)
  130. text(1,2,"DGI Initialized")
  131. os.sleep(0.01)
  132. text(1,3,"Click to exit")
  133. os.sleep(0.5)
  134.  
  135. local function getEnergyPercent()
  136.   return math.floor(cell.getEnergyStored()/cell.getMaxEnergyStored()*100)
  137. end
  138.  
  139. local function getEnergy()
  140.   return cell.getEnergyStored()
  141. end
  142.  
  143. local function getMaxEnergy()
  144.   return cell.getMaxEnergyStored()
  145. end
  146.  
  147. colorDraw(1,1,width,5,'gray')
  148. colorText(6,3,"Damckell Draconic Monitor; DDM",'gray','white')
  149.  
  150. cellType = "8 / Unknown"
  151.  
  152. if getMaxEnergy() == 45500000 then
  153.   cellType = "1"
  154. elseif getMaxEnergy() == 273000000 then
  155.   cellType = "2"
  156. elseif getMaxEnergy() == 1640000000 then
  157.   cellType = "3"
  158. elseif getMaxEnergy() == 9880000000 then
  159.   cellType = "4"
  160. elseif getMaxEnergy() == 59300000000 then
  161.   cellType = "5"
  162. elseif getMaxEnergy() == 356000000000 then
  163.   cellType = "6"
  164. elseif getMaxEnergy() == 2140000000000 then
  165.   cellType = "7"
  166. end
  167.  
  168. colorText(width-18,3,"Tier Level "..cellType,'gray','white')
  169.  
  170. bgColor('darkgray')
  171. fgColor('white')
  172. draw(8,9,100,3)
  173. colorDraw(8,9,getEnergyPercent(),3,'red')
  174. os.sleep(0.5)
  175.  
  176. prevPercent = getEnergyPercent()
  177.  
  178. while loopActive do
  179.   if getEnergyPercent() ~= prevPercent then
  180.     draw(8,9,100,3)
  181.     colorDraw(8,9,getEnergyPercent(),3,'red')
  182.     prevPercent = getEnergyPercent()
  183.   end
  184.   term.setCursor(14,8)
  185.   print("Energy Cell: "..getEnergy().." / "..getMaxEnergy().." ; "..getEnergyPercent().."% - Transfer Rate: "..cell.getTransferPerTick().." RF/t       ")
  186.   os.sleep(0.1)
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement