Advertisement
smigger22

index

Feb 16th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.70 KB | None | 0 0
  1. -- Variables
  2. local compX, compY = 51, 19
  3. local page = 1
  4. -- Tables
  5. local buttons = {}
  6.  
  7. -- Design Code
  8. function centered(str, height)
  9.      term.setCursorPos(x / 2 - #str / 2, height)
  10.     term.write(str)
  11. end
  12.  
  13. function indented(str, indent, height)
  14.     term.setCursorPos(indent, height)
  15.     term.write(str)
  16. end
  17.  
  18. function left(str, height)
  19.     term.setCursorPos(1, height)
  20.     term.write(str)
  21. end
  22.  
  23. function right(str, height)
  24.   term.setCursorPos(compX - #str, height)
  25.   term.write(str)
  26. end
  27.  
  28. function clearLine(colour, height)
  29.     term.setCursorPos(1, height)
  30.     term.setBackgroundColour(colours[colour])
  31.     term.clearLine()
  32. end
  33.  
  34. function drawBorder(xMin, yMin, xMax, yMax, colour)
  35.     paintutils.drawBox(xMin, yMin, xMax, yMax, colours[colour])
  36. end
  37.  
  38. function drawBox(xMin, yMin, xMax, yMax, colour)
  39.     paintutils.drawFilledBox(xMin, yMin, xMax, yMax, colours[colour])
  40. end
  41.  
  42. function enableButton(buttonName)
  43.     for k,v in pairs(buttons) do
  44.     if v["buttonName"] == buttonName then
  45.         buttons[k]["Enabled"] = true
  46.         return true
  47.     end
  48.     end
  49.   return false
  50. end
  51.  
  52. function disableButton(buttonName)
  53.     for k,v in pairs(buttons) do
  54.     if v["buttonName"] == buttonName then
  55.         buttons[k]["Enabled"] = false
  56.         return true
  57.     end
  58.     end
  59.   return false
  60. end
  61.  
  62. function buttonNameToNumber(buttonName)
  63.     for k,v in pairs(buttons) do
  64.     if v["buttonName"] == buttonName then
  65.         return k
  66.     end
  67.     end
  68.   return false
  69. end
  70.  
  71. function removeButton(buttonName)
  72.     table.remove(buttons, buttonNameToNumber(buttonName))
  73. end
  74.  
  75. function drawButton(xPos,yPos,bgColor,txtColor,length,txt,buttonName,functionName)
  76.   term.setBackgroundColour(colours[bgColor])
  77.   term.setTextColour(colours[txtColor])
  78.   local X = xPos + math.floor((length/2)-(string.len(txt)/2))
  79.   if not buttonName then
  80.     buttonName = "Test"..tostring(#buttons+1)
  81.   end
  82.   for i = yPos,yPos+2 do
  83.     if i ~= yPos+1 then
  84.         term.setCursorPos(xPos,i)
  85.         term.write(string.rep(" ", length))
  86.     else
  87.         term.setCursorPos(xPos,i)
  88.         term.write(string.rep(" ", length))  
  89.         term.setCursorPos(X,i)
  90.         buttons[#buttons+1] = {["Function"] = functionName, ["buttonName"] = buttonName, ["xPosStart"] = xPos, ["xPosStop"] = xPos+length-1, ["yPos"] = yPos, ["Enabled"] = true}
  91.         term.write(txt)
  92.     end
  93.     end
  94. end
  95.  
  96. -- Main Code
  97. function header()
  98.   term.setTextColour(colours.white)
  99.   clearLine("blue", 1)
  100.   clearLine("blue", 2)
  101.   clearLine("blue", 3)
  102.   indented("smigger.22", 2, 2)
  103.   right("My blog! ", 2)
  104. end
  105.  
  106. -- Computer Code
  107. function checkButtonClick()
  108.     while true do
  109.     event, button, xPos, yPos = os.pullEvent("mouse_click")
  110.     if event == "mouse_click" then
  111.       for k,v in pairs(buttons) do
  112.             if xPos >= v["xPosStart"] and xPos <= v["xPosStop"] and yPos >= v["yPos"] and yPos <= v["yPos"]+2 and v["Enabled"] == true then
  113.                 if v["Function"] then
  114.                     if v["Function"] == "info" and page == 1 then
  115.                         page = 2
  116.                         pageLayout()
  117.             elseif v["Function"] == "exit" and page == 1 then
  118.               return
  119.                     elseif v["Function"] == "contact" and page == 1 then
  120.                         page = 3
  121.                         pageLayout()
  122.                     elseif v["Function"] == "otherWeb" and page == 1 then
  123.                         page = 4
  124.                 pageLayout()
  125.  
  126.                     elseif v["Function"] == "backAbout" and page == 2 then
  127.                       page = 1
  128.                         pageLayout()
  129.                     elseif v["Function"] == "backContact" and page == 3 then
  130.                         page = 1
  131.                         pageLayout()
  132.                     elseif v["Function"] == "backWebsites" and page == 4 then
  133.                         page = 1
  134.                         pageLayout()
  135.                     end
  136.               end
  137.             end
  138.         end
  139.     end
  140.     end
  141. end
  142.  
  143. function pageLayout()
  144.   term.setBackgroundColour(colours.cyan)
  145.   term.clear()
  146.   header()
  147.   if page == 1 then
  148.     term.setBackgroundColour(colours.cyan)
  149.     drawButton(3, 5, "blue", "lightBlue", 10, "About me", "info", "info")
  150.     drawButton(14, 5, "blue", "lightBlue", 9, "Contact", "contact", "contact")
  151.     drawButton(24, 5, "blue", "lightBlue", 16, "Other Websites", "otherWeb", "otherWeb")
  152.     drawButton(3, 12, "blue", "lightBlue", 6, "Exit", "exit", "exit")
  153.     checkButtonClick()
  154.   elseif page == 2 then
  155.     term.setBackgroundColour(colours.cyan)
  156.     left("I am a video gamer and a blogger as you can see.", 6)
  157.     left("Currently, I am working in a company called EpicCo, ", 7)
  158.     left("a company that designs games and software that all", 8)
  159.     left("can use with ease. I also help with the development", 9)
  160.     left("of the offical LuaLand website, created by me and ", 10)
  161.     left("robbiesymonds.", 11)
  162.     drawButton(43, 12, "blue", "lightBlue", 6, "Back", "backAbout", "backAbout")
  163.     checkButtonClick()
  164.   elseif page == 3 then
  165.     term.setBackgroundColour(colours.cyan)
  166.     left("You can contact me in various ways. The easiest way", 6)
  167.     left("would be to message me or tweet to me on Twitter!", 7)
  168.     left("Twitter: www.twitter.com/smigger22", 9)
  169.     left("Youtube: www.youtube.com/smigger22", 10)
  170.     left("Instagram: www.instagram.com/smigger22", 11)
  171.     left("Email: ryans810@hotmail.co.uk", 12)
  172.     drawButton(43, 12, "blue", "lightBlue", 6, "Back", "backContact", "backContact")
  173.     checkButtonClick()
  174.   elseif page == 4 then
  175.     term.setBackgroundColour(colours.cyan)
  176.     left("Here are some cool websites, all hosted by CWC, a", 6)
  177.     left("Great hosting company with 90% uptime!", 7)
  178.     left("rod.net thepiratebay.se machine.net wiggle.it", 9)
  179.     left("CWC.com quest.dia green.com wagon.com", 10)
  180.     left("MicroCorp.net.cc", 11)
  181.     drawButton(43, 12, "blue", "lightBlue", 6, "Back", "backWebsites", "backWebsites")
  182.     checkButtonClick()
  183.   end
  184. end
  185.  
  186.  
  187. function begin()
  188.   parallel.waitForAll(pageLayout, checkButtonClick)
  189. end
  190.  
  191. -- Start
  192. term.clear()
  193. begin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement