Flaghacker

speef mode changer

May 25th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. --[[Settings]]--
  2. --Peripherals
  3. local modemName = "back"
  4. local monitorName = "monitor_0"
  5. local chestName = "container_chest_1"
  6. local channel = 1
  7. --relative to chest
  8. local projectorSide = "left"
  9.  
  10. --Slots
  11. local projectorModeSlot = 1
  12. local projectorPatternSlot = 5
  13.  
  14. --Id's
  15. local patternId = 387
  16. local modeStabelize = 280
  17. local modeClear = 281
  18.  
  19. --Design
  20. design =
  21.     {
  22.     selectedColorText = colors.red,
  23.     selectedColorBack = colors.yellow,
  24.    
  25.     deselectColorText = colors.white,
  26.     deselectColorBack = colors.green,
  27.  
  28.     actionColoText = colors.white,
  29.     actionColorBack = colors.red,
  30.    
  31.     sideBorder = 2
  32.     topBorder = 4
  33.     bottomBorder = 4
  34.     }
  35.  
  36.  
  37.  
  38. --[[Variables & peripherals]]--
  39. local modem = peripheral.wrap(modemName)
  40. local monitor = peripheral.wrap(monitorName)
  41. local chest = peripheral.wrap(chestName)
  42.  
  43. modem.open(channel)
  44. local width, height = monitor.getSize()
  45. local objects = {}
  46.  
  47. local buttons = {}
  48.  
  49.  
  50. --[[Functions]]--
  51. local function round(number)
  52.     return math.floor(number + 0.5)
  53. end
  54.  
  55. local function clear()
  56.     term.clear()
  57.     term.setCursorPos(1,1)
  58.     monitor.setTextColor(colors.white)
  59.     monitor.setBackgroundColor(colors.black)
  60.     monitor.setCursorPos(1,1)
  61.     monitor.clear()
  62. end
  63.  
  64. local function scanForModes()
  65.     local chestInv = chest.getAllStacks()
  66.     local modes = {}
  67.     for i, data in pairs(chestInv) do
  68.         if data.id == patternId then
  69.             modes[i] = data.name
  70.         end
  71.     end
  72.     return modes
  73. end
  74.  
  75. local function drawButton(x1, y1, x2, y2, text, textColor, backgroundColor)
  76.     monitor.setBackgroundColor(backgroundColor)
  77.     monitor.setTextColor(textColor)
  78.     for x = x1, x2 do
  79.         for y = y1, y2 do
  80.             monitor.setCursorPos(x, y)
  81.             monitor.write(" ")
  82.         end
  83.     end
  84.     monitor.setCursorPos(round(x1 + math.abs(x2 - x1) / 2 - #text / 2), round(math.abs(y2 - y1) / 2))
  85.     monitor.write(text)
  86.     table.insert(buttons, {text = text, x1 = x1, y1 = y2, x2 = x2, y2 = y1})
  87. end
  88.  
  89. local function printModes(data)
  90.     local longest = 0
  91.     for i, j in pairs(data.modes) do
  92.         if #j > longest then
  93.             longest = #j
  94.         end
  95.     end
  96.     for colums = 20, 1, -1 do
  97.         if width - 2 * data.design.sideBorder - colums * longest >= 2(colums - 1) then
  98.             break
  99.         end
  100.     end
  101.     local rows = math.ceil(#data.modes / colums)
  102.     local space = (width - 2 * data.design.sideBorder - colums * longest) / (colors - 1)
  103.     for rowPos = 1, rows do
  104.         for columPos = 1, colums do
  105.             local pos = columPos + rowPos * colums
  106.             local x1 = data.design.sideBorder + (columPos - 1) * (longest + space)
  107.             local x2 = x1 + longest
  108.             local y = data.design.topBorder
  109.         end
  110.     end
  111. end
  112.  
  113. --[[Main program]]--
  114. local data = {}
  115. data.design = design
  116.  
  117. clear()
  118. drawButton(16, 1, 31, 10, "Henryk", colors.white, colors.blue)
  119. print(textutils.serialize(buttons))
Advertisement
Add Comment
Please, Sign In to add comment