Advertisement
PaymentOption

Website for Lieu

Sep 29th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.05 KB | None | 0 0
  1. --[[
  2. =========================================
  3.  
  4.                         Trystan Cannon
  5.                         9/29/12
  6. Website for lieu
  7.  
  8. A website designed for 1lann's firefox
  9. for lieu's company.
  10. =========================================
  11. --]]
  12.  
  13. --=Constants===========================--
  14. local nScreenWidth, nScreenHeight = term.getSize() -- Grab the dimensions of the screen ot put into the constants table.
  15. tConstants = {
  16.     ["SCREEN_HEIGHT"] = nScreenHeight,
  17.     ["SCREEN_WIDTH"] = nScreenWidth
  18. }
  19. nScreenWidth, nScreenHeight = nil, nil -- Free up the variabels for nScreenWidth and nScreenHeight because they're in the constants table now.
  20. --=====================================--
  21.  
  22. --=Basic Gui Methods=============--
  23. -- Prints the passed string in the exact center of the screen on the line (nHeight) provided.
  24. function printCentered(nHeight, sString)
  25.     term.setCursorPos(tConstants["SCREEN_WIDTH"]/2 - sString:len()/2, nHeight)
  26.     term.write(sString)
  27. end
  28.  
  29. -- Prints the passed string to the very right of the screen on the line (nHeight) provided.
  30. function printRight(nHeight, sString)
  31.     term.setCursorPos(tConstants["SCREEN_WIDTH"] - sString:len(), nHeight)
  32.     term.write(sString)
  33. end
  34.  
  35. -- Clears the screen of all text, and repositions the cursor to the upper right (1,1) of the screen.
  36. function clearScreen()
  37.     term.clear()
  38.     term.setCursorPos(1, 1)
  39. end
  40. --===============================--
  41.  
  42. --=Website specific GUI methods====================--
  43. -- Prints the screen border with the format:
  44. -- +-----+
  45. -- |     |
  46. -- +-----+
  47. function printBorder()
  48.     -- Prints a horizontal line with the border format.
  49.     local function printHorizontalLine(xPos, yPos)
  50.         term.setCursorPos(xPos, yPos)
  51.         term.write("+" .. string.rep("-", tConstants["SCREEN_WIDTH"] - 2) .. "+")
  52.     end
  53.  
  54.     -- Print the top line of the screen.
  55.     printHorizontalLine(1, 1)
  56.     -- Print the center of the screen with horizontal characters (pipes: | |).
  57.     for nHeight = 2, tConstants["SCREEN_HEIGHT"] - 1 do
  58.         term.setCursorPos(1, nHeight)
  59.         term.write("|")
  60.  
  61.         term.setCursorPos(tConstants["SCREEN_WIDTH"], nHeight)
  62.         term.write("|")
  63.     end
  64.     -- Print the bottom line of the screen.
  65.     printHorizontalLine(1, tConstants["SCREEN_HEIGHT"])
  66. end
  67.  
  68. -- Prints a box with the passed corner, horizontal, and vertical characters with the dimensions of the passed width and height with
  69. -- the upper left hand corner of the box beginning at (xPos, yPos).
  70. function printBox(cCornerChar, cHorizontalChar, cVerticalChar, nWidth, nHeight, xPos, yPos)
  71.     -- Establish the horizontal and vertical line local methods.
  72.     local function printHorizontalLine(cCornerChar, cHorizontalChar, nLength)
  73.         print(cCornerChar .. string.rep(cHorizontalChar, nLength - 2) .. cCornerChar)
  74.     end
  75.  
  76.     local function printVerticalLine(cVerticalChar, nLength)
  77.         print(cVerticalChar .. string.rep(" ", nLength - 2) .. cVerticalChar)
  78.     end
  79.  
  80.  
  81.     -- Set the cursor to the position of the upper left hand corner
  82.     -- of where the box will begin.
  83.     term.setCursorPos(xPos, yPos)
  84.     -- Print the top line of the box.
  85.     printHorizontalLine(cCornerChar, cHorizontalChar, nWidth)
  86.     -- Print as many vertical lines as the height of the box to create the "body" of the box.
  87.     for nLine=1, nHeight do
  88.         term.setCursorPos(xPos, yPos+nLine)
  89.         printVerticalLine(cVerticalChar, nWidth)
  90.     end
  91.     -- Print the bottom line of the box.
  92.     term.setCursorPos(xPos, yPos+nHeight)
  93.     printHorizontalLine(cCornerChar, cHorizontalChar, nWidth)
  94. end
  95.  
  96. -- Prints the header of the company website.
  97. function printHeader(sTitle)
  98.     -- Print a box that is wide enough for the title with two spaces on the outside; we can center the text inside the box.
  99.     printBox("*", "*", "*", sTitle:len() + 2, 3, tConstants["SCREEN_WIDTH"]/2 - (sTitle:len() + 4)/2, 2)
  100.     -- Print the title in the center of the box.
  101.     printCentered(3, sTitle) -- Assuming that the box has been centered correctly, this line should appear directly in the center of the box.
  102. end
  103. --=================================================--
  104.  
  105. --=Menu printing methods==============================--
  106. -- Prints a menu table with the format: tMenu[n] = {sTitle, fAssociatedFunction}
  107. -- *fAssociated function is the identifier of the method that will be called if
  108. -- that selection is selected by the user. (Enter is pressed on that selection).
  109. function printMenu(tMenu, nSelection, xPos, yPos)
  110.     for nOption, tOptionTable in ipairs(tMenu) do
  111.         term.setCursorPos(xPos, yPos + (nOption - 1)) -- Subtract one from the option when printing on the height to make sure that we use
  112.                                                       -- the original yPos provided in the parameters.
  113.  
  114.         -- If the option that is being printed is selected, then print brackets around it.
  115.         if nSelection == nOption then
  116.             term.write("[" .. tOptionTable.sTitle .. "]")
  117.         -- If the option that is being printed is not selected, then just print it regularly.
  118.         else
  119.             term.write(" " .. tOptionTable.sTitle .. " ") -- Print spaces around the option to compensate for the lack of brackets in the spacing.
  120.         end
  121.     end
  122. end
  123. --====================================================--
  124.  
  125. --=Key handling methods (for the menu)======================--
  126. -- Takes a key code and performs the appropriate operation depending on what the key code was.
  127. -- Executes the option depending on the menu provided with the format: tMenu[n] = {sTitle, fAssociatedFunction}
  128. -- WILL RETURN THE SELECTION!!!
  129. function handleKeyPress(nKey, nSelection, tMenu)
  130.     -- If the ENTER key was pressed, then execute the associated function with the option.
  131.     if nKey == 28 then
  132.         -- Execute the associated function.
  133.         tMenu[nSelection].fAssociatedFunction()
  134.     -- If the up key was pressed and the selection is currently greater than one, move the selection up.
  135.     elseif nKey == 200 and nSelection > 1 then
  136.         -- Move the selection up one.
  137.         nSelection = nSelection - 1
  138.     -- If the down key was pressed and the selection is currently less than the total number of selections, move the selection down.
  139.     elseif nKey == 208 and nSelection < #tMenu then
  140.         -- Move the selection down one.
  141.         nSelection = nSelection + 1
  142.     end
  143.  
  144.     return nSelection
  145. end
  146. --==========================================================--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement