Advertisement
Stravides

helpAPI

Dec 6th, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.79 KB | None | 0 0
  1. --[[Nebulae Interactive API (nInteractive)]]--
  2. --[[Made by GamerNebulae]]--
  3. --[[You are allowed to modify the code, as long as I get credit..]]
  4.  
  5. --Declaring variables
  6.  
  7. --Local variables
  8.         local bInactiveBackground
  9.         local bActiveBackground
  10.  
  11. --Global variables
  12.         bData = {}
  13.         pbData = {}
  14.         clickedID = ""
  15.         m = ""
  16.  
  17. --Monitor Functions
  18. function findMonitor()
  19.         local p = peripheral.getNames()
  20.         for k,v in pairs(p) do
  21.                 if (v == "top" or v == "bottom" or v == "left" or v == "back" or v == "right" or v == "front") then
  22.                         if (string.find(peripheral.getType(v), "monitor")) then
  23.                                 m = peripheral.wrap(v)
  24.                         end
  25.                 elseif (string.find(v, "monitor")) then
  26.                         m = peripheral.wrap(v)
  27.                 end
  28.         end
  29. end
  30.  
  31. function mClear()
  32.         m.clear()
  33.         m.setTextColor(colors.white)
  34.         m.setBackgroundColor(colors["black"])
  35. end
  36.  
  37. function mCreatePage()
  38. end
  39.  
  40. function mHeadline(text)
  41.         local x,y = m.getSize()
  42.         xText = math.floor((x / 2) - (#text / 2) + 1)
  43.         m.setCursorPos(xText, 1)
  44.         m.write(text)
  45. end
  46.  
  47. function mOverrideInactiveBackground(color)
  48.         bInactiveBackground = tostring(color)
  49. end
  50.  
  51. function mOverrideActiveBackground(color)
  52.         bActiveBackground = tostring(color)
  53. end
  54.  
  55. function mCreateButton(ID, text, pX, qX, pY, qY)
  56.         bData[ID] = {}
  57.         bData[ID]["text"] = text
  58.         bData[ID]["pX"] = pX
  59.         bData[ID]["qX"] = qX
  60.         bData[ID]["pY"] = pY
  61.         bData[ID]["qY"] = qY
  62.         bData[ID]["state"] = false
  63.         mDrawButton(ID)
  64. end
  65.  
  66. function mDrawButton(ID)
  67.         if (not bData[ID]["state"] and not bInactiveBackground) then
  68.                 m.setBackgroundColor(colors["red"])
  69.         elseif (not bData[ID]["state"]) then
  70.                 m.setBackgroundColor(colors[bInactiveBackground])
  71.         elseif (bData[ID]["state"] and not bActiveBackground) then
  72.                 m.setBackgroundColor(colors["lime"])
  73.         elseif (bData[ID]["state"]) then
  74.                 m.setBackgroundColor(colors[bActiveBackground])
  75.         end
  76.  
  77.         local yText = math.floor((bData[ID]["pY"] + bData[ID]["qY"]) / 2)
  78.         local xText = math.floor(((bData[ID]["pX"] + bData[ID]["qX"]) / 2) - (#bData[ID]["text"] / 2) + 1)
  79.         for y = bData[ID]["pY"], bData[ID]["qY"] do
  80.                 if (y == yText) then
  81.                         for x = bData[ID]["pX"], (bData[ID]["pX"] + bData[ID]["qX"]) / 2 do
  82.                                 m.setCursorPos(x,y)
  83.                                 m.write(" ")
  84.                         end
  85.                         m.setCursorPos(xText, y)
  86.                         m.write(bData[ID]["text"])
  87.                         for x = xText + #bData[ID]["text"], bData[ID]["qX"] do
  88.                                 m.setCursorPos(x,y)
  89.                                 m.write(" ")
  90.                         end
  91.                 else
  92.                         for x = bData[ID]["pX"], bData[ID]["qX"] do
  93.                                 m.setCursorPos(x,y)
  94.                                 m.write(" ")
  95.                         end
  96.                 end
  97.         end
  98.         m.setBackgroundColor(colors["black"])
  99. end
  100.  
  101. function splitText(xText, xSteps, y, text, color)
  102.         local dataText = {}
  103.         for k,v in text:gmatch"." do
  104.                 dataText[#dataText + 1] = tostring(k)
  105.         end
  106.  
  107.         local lettersColored = xSteps - xText + 1
  108.         m.setBackgroundColor(colors[color])
  109.         for x = xText, xText + lettersColored - 1 do
  110.                 m.setCursorPos(x, y)
  111.                 m.write(dataText[x - (xText - 1)])
  112.         end
  113.         m.setBackgroundColor(colors["black"])
  114.         for x = xText + lettersColored - 1, xText + #text - 1 do
  115.                 m.setCursorPos(x, y)
  116.                 m.write(dataText[x - (xText - 1)])
  117.         end
  118. end
  119.  
  120. function mDrawProgressBar(ID)
  121.         local xSize, ySize = m.getSize()
  122.         local xTitle = math.floor(((1 + xSize) / 2) - (#pbData[ID]["title"] / 2) + 1)
  123.         m.setCursorPos(xTitle, pbData[ID]["yTitle"])
  124.         m.setTextColor(colors[pbData[ID]["titleColor"]])
  125.         m.write(pbData[ID]["title"])
  126.  
  127.         local percent = pbData[ID]["value"] / pbData[ID]["maximum"]
  128.         local xSteps = math.floor(xSize * percent)
  129.         local text = pbData[ID]["value"].." / "..pbData[ID]["maximum"]
  130.         local textLength = #(text)
  131.         local xText = math.floor(((1 + xSize) / 2) - (textLength / 2) + 1)
  132.  
  133.         m.setBackgroundColor(colors[pbData[ID]["barColor"]])
  134.         m.setTextColor(colors["white"])
  135.         if (xSteps < xText) then
  136.                 for x = 1, xSteps do
  137.                         m.setCursorPos(x, pbData[ID]["yBar"])
  138.                         m.write(" ")
  139.                 end
  140.                 m.setBackgroundColor(colors["black"])
  141.                 m.setCursorPos(xText, pbData[ID]["yBar"])
  142.                 m.write(text)
  143.                 for x = xText + #text, xSize do
  144.                         m.setCursorPos(x, pbData[ID]["yBar"])
  145.                         m.write(" ")
  146.                 end
  147.         elseif (xSteps == (xText + #text - 1)) then
  148.                 for x = 1, xText - 1 do
  149.                         m.setCursorPos(x, pbData[ID]["yBar"])
  150.                         m.write(" ")
  151.                 end
  152.                 m.write(text)
  153.                 m.setBackgroundColor(colors["black"])
  154.                 for x = xText + #text, xSize do
  155.                         m.setCursorPos(x, pbData[ID]["yBar"])
  156.                         m.write(" ")
  157.                 end
  158.         elseif (xSteps >= xText and xSteps < (xText + #text - 1)) then
  159.                 for x = 1, xText - 1 do
  160.                         m.setCursorPos(x, pbData[ID]["yBar"])
  161.                         m.write(" ")
  162.                 end
  163.                 splitText(xText, xSteps, pbData[ID]["yBar"], text, pbData[ID]["barColor"])
  164.                 m.setBackgroundColor(colors["black"])
  165.                 for x = xText + #text, xSize do
  166.                         m.setCursorPos(x, pbData[ID]["yBar"])
  167.                         m.write(" ")
  168.                 end
  169.         else
  170.                 for x = 1, xSteps do
  171.                         m.setCursorPos(x, pbData[ID]["yBar"])
  172.                         m.write(" ")
  173.                 end
  174.                 m.setCursorPos(xText, pbData[ID]["yBar"])
  175.                 m.write(text)
  176.                 for x = xText + #text, xSteps do
  177.                         m.setCursorPos(x, pbData[ID]["yBar"])
  178.                         m.write(" ")
  179.                 end
  180.                 if xSteps ~= xSize then
  181.                         m.setBackgroundColor(colors["black"])
  182.                         for x = xSteps + 1, xSize do
  183.                                 m.setCursorPos(x, pbData[ID]["yBar"])
  184.                                 m.write(" ")
  185.                         end
  186.                 end
  187.         end
  188.         m.setBackgroundColor(colors["black"])
  189. end
  190.  
  191. function mCreateProgressBar(ID, title, yTitle, titleColor, value, maximum, yBar, barColor)
  192.         pbData[ID] = {}
  193.         pbData[ID]["title"] = title
  194.         pbData[ID]["yTitle"] = yTitle
  195.         pbData[ID]["titleColor"] = titleColor
  196.         pbData[ID]["value"] = value
  197.         pbData[ID]["maximum"] = maximum
  198.         pbData[ID]["yBar"] = yBar
  199.         pbData[ID]["barColor"] = barColor
  200.         mDrawProgressBar(ID)
  201. end
  202.  
  203. function mButtonListen()
  204.         event, _, x, y = os.pullEvent()
  205.         if (event == "monitor_touch") then
  206.                 for key, value in pairs(bData) do
  207.                         if (x >= bData[key]["pX"] and x <= bData[key]["qX"] and y >= bData[key]["pY"] and y <= bData[key]["qY"]) then
  208.                                 clickedID = key
  209.                         end
  210.                 end
  211.         end
  212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement