Advertisement
Guest User

startup

a guest
Sep 20th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.43 KB | None | 0 0
  1. --controller=peripheral.wrap("appeng_me_tilecontroller_0")
  2. --terminal=peripheral.wrap("appeng_me_tileterminal_0")
  3. --craftingmon=peripheral.wrap("appeng_me_tilecraftingmonitor_0")
  4. mon=peripheral.wrap("top")
  5. steam=peripheral.wrap("right")
  6. buttons={}
  7. buttonTexts={}
  8. buttonFunctions={}
  9. mon.clear()
  10. mon.setTextScale(.5)
  11. function cText(msg, x1, x2, y, bColor, tColor)
  12.     mon.setBackgroundColor(colors[bColor])
  13.     mon.setTextColor(colors[tColor])
  14.     sizeX=(((x2)/2)-(string.len(msg)/2))-1
  15.     mon.setCursorPos(x1+sizeX, y)
  16.     mon.write(msg)
  17.     sizeX, sizeY=mon.getSize()
  18. end
  19. function fillArea(x1, x2, y1, y2, color)
  20.   mon.setBackgroundColor(colors[color])
  21.   for y=1,1+y2-y1 do
  22.     for x=1,1+x2-x1 do
  23.       mon.setCursorPos(x1+x-1, y1+y-1)
  24.       mon.write(" ")
  25.     end
  26.   end
  27. end
  28. function addButton(x1, x2, y1, y2, name, text)
  29.   table.insert(buttonFunctions, name)
  30.   table.insert(buttons, x1 .."-" ..x2 .."-" ..y1 .."-" ..y2)
  31.   mon.setBackgroundColor(colors.green)
  32.   for y=1,1+y2-y1 do
  33.     for x=1,1+x2-x1 do
  34.       mon.setCursorPos(x1+x-1, y1+y-1)
  35.       mon.write(" ")
  36.     end
  37.   end
  38.   if text~= nil then
  39.     cText(text, x1, x2, ((y1+y2)/2), "green", "white")
  40.     table.insert(buttonTexts, text)
  41.   else
  42.     table.insert(buttonTexts, "")
  43.   end
  44.   mon.setBackgroundColor(colors.black)
  45. end
  46. local function readButton(number)
  47.   splits={}
  48.   for i=1,string.len(buttons[number]) do
  49.     if string.sub(buttons[number], i, i)=="-" then
  50.       table.insert(splits, i)
  51.     end
  52.   end
  53.   values={}
  54.   table.insert(values, string.sub(buttons[number], 1, splits[1]-1))
  55.   table.insert(values, string.sub(buttons[number], splits[1]+1, splits[2]-1))
  56.   table.insert(values, string.sub(buttons[number], splits[2]+1, splits[3]-1))
  57.   table.insert(values, string.sub(buttons[number], splits[3]+1, string.len(buttons[number])))
  58.   newValues={}
  59.   for i=1, #values do
  60.     table.insert(newValues, tonumber(values[i]))
  61.   end
  62.   return newValues
  63. end
  64. local function isButton(posX, posY)
  65.   found=false
  66.   for i=1,#buttons do
  67.     local coords=readButton(i)
  68.     x1=coords[1]
  69.     x2=coords[2]
  70.     y1=coords[3]
  71.     y2=coords[4]
  72.     for y=1,1+y2-y1 do
  73.       for x=1,1+x2-x1 do
  74.         if x1+x-1==posX and y1+y-1==posY then
  75.           found=true
  76.           return true, i
  77.         end
  78.       end
  79.     end
  80.   end
  81.   if not found then
  82.     return false, 0
  83.   end
  84. end
  85. function getButton(x, y)
  86.     local val, num=isButton(x, y)
  87.     if val then
  88.         local coords=readButton(num)
  89.         x1=coords[1]
  90.         x2=coords[2]
  91.         y1=coords[3]
  92.         y2=coords[4]
  93.         fillArea(x1, x2, y1, y2, "red")
  94.         cText(buttonTexts[num], x1, x2, ((y1+y2)/2), "red", "white")
  95.         if string.sub(buttonFunctions[num], 1, 4)~="code" then
  96.             shell.run(buttonFunctions[num])
  97.         else
  98.             run(string.sub(buttonFunctions[num], 6, string.len(buttonFunctions[num])))
  99.         end
  100.             sleep(.2)
  101.             fillArea(x1, x2, y1, y2, "green")
  102.             cText(buttonTexts[num], x1, x2, ((y1+y2)/2), "green", "white")
  103.     end
  104. end
  105. function run(code)
  106.     if code=="view ME" then
  107.        
  108.     end
  109. end
  110. sizeX, sizeY=mon.getSize()
  111. fillArea(1, sizeX, 1, sizeY, "yellow")
  112. fillArea(2, sizeX-1, 2, sizeY-1, "gray")
  113. cText("Awesomeness Innovations", 1, sizeX, sizeY, "yellow", "black")
  114. cText("Base Management", 1, sizeX, 1, "yellow", "black")
  115. fillArea(3, 15, 3, 3, "lightGray")
  116. cText("Steam Dynamo", 3, 15, 3, "lightGray", "black")
  117. addButton(3, 15, 4, 6, "steam", "View")
  118. while true do
  119.     local e, side, x, y=os.pullEvent("monitor_touch")
  120.     if side=="top" then
  121.         getButton(x, y)
  122.     end
  123.     sleep(.000001)
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement