Daniel_I_Am

Pricelist 3.0

Nov 28th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.08 KB | None | 0 0
  1. comp = require("component")
  2. event = require("event")
  3. term = require("term")
  4. gpu = comp.gpu
  5. BA = require("ButtonAPI")
  6. colors = require("colors")
  7. os = require("os")
  8. io = require("io")
  9. uni = require("unicode")
  10.  
  11. function fileToArray(filepath)
  12.   array = {}
  13.   local file = io.open(filepath,"r")
  14.   if file~=nil then
  15.     repeat
  16.       line = file:read("*line")
  17.       if line ~= nil then
  18.         a = string.find(line,";")
  19.         if a then
  20.           print(string.sub(line,1,a-1)..":"..string.sub(line,a+1,-1))
  21.           table.insert(array,string.sub(line,1,a-1))
  22.           table.insert(array,string.sub(line,a+1,-1))
  23.           --os.sleep(0.01)
  24.         end
  25.       end
  26.     until line == nil
  27.     file:close()
  28.     return array
  29.   else
  30.     return {}
  31.   end
  32. end
  33.  
  34. pricelistCommon = fileToArray("/home/pricelistCommon.txt")
  35. pricelistUncommon = fileToArray("/home/pricelistUncommon.txt")
  36. pricelistRare = fileToArray("/home/pricelistRare.txt")
  37. pricelistEpic = fileToArray("/home/pricelistEpic.txt")
  38. pricelistLegendary = fileToArray("/home/pricelistLegendary.txt")
  39.  
  40. information = {
  41. "--------------------------------------","",
  42. "             INFORMATION","",
  43. "--------------------------------------","",
  44. "This is the server's pricelist.","",
  45. "This list lists the lowest price you,","",
  46. "as a player, can sell at.","",
  47. "Of course you can sell above these","",
  48. "prices.","",
  49. "","",
  50. "Use the buttons on the side","",
  51. "and bottom to navigate.","",
  52. "","",
  53. "If you have any questions regarding","",
  54. "this pricelist and its rules, ask","",
  55. "the other players.","",
  56. "If there are still questions, be sure","",
  57. "to hit up one of the BOE members.","",
  58. "If there are mistakes or missing","",
  59. "items, be sure to do the same thing.",""
  60. }
  61.  
  62. list = {}
  63. page = 0
  64.  
  65. gpu.setResolution(60,25)
  66. gpu.setBackground(0x000000)
  67. gpu.setForeground(0xffffff)
  68. term.clear()
  69. width,height = gpu.getResolution()
  70. BA.clear() -- clears the buttons stored
  71.  
  72. --xOffset, yOffset, width, height, Background Color, Text Color, textXOffset, textYOffset, text
  73. BA.makeButton(width-21,height-3,19,3,0x808080,0xffffff,-1,-1,"Common") --1
  74. BA.makeButton(width-21,height-7,19,3,0x36c95e,0xffffff,-1,-1,"Uncommon") --2
  75. BA.makeButton(width-21,height-11,19,3,0x4283d8,0xffffff,-1,-1,"Rare") --3
  76. BA.makeButton(width-21,height-15,19,3,0x9c52c8,0xffffff,-1,-1,"Epic") --4
  77. BA.makeButton(width-21,height-19,19,3,0xdd871c,0xffffff,-1,-1,"Legendary") --5
  78. BA.makeButton(width-21,height-23,19,3,0xffffff,0x000000,-1,-1,"Information") --6
  79. BA.makeButton(8,height-3,6,3,0xffffff,0x000000,-1,-1,"next") --7
  80. BA.makeButton(1,height-3,6,3,0xffffff,0x000000,-1,-1,"prev") --8
  81. --xOff,yOff,w,h,Bcolor if -1 then transparent,Tcolor if -1 then transparent,sXOff if -1 then center,sYOff if -1 then center,str
  82.  
  83. function checkButtons()
  84.   l = BA.updateAll(event.pull("touch"))
  85.   for k,v in pairs(l) do
  86.     buttonNumber = v
  87.   end
  88.   l = {}
  89.   return buttonNumber
  90. end
  91.  
  92. function selectList()
  93.   buttonNumber = checkButtons()
  94.   if buttonNumber == 1 then
  95.     list = pricelistCommon
  96.     page = 0
  97.   elseif buttonNumber == 2 then
  98.     list = pricelistUncommon
  99.     page = 0
  100.   elseif buttonNumber == 3 then
  101.     list = pricelistRare
  102.     page = 0
  103.   elseif buttonNumber == 4 then
  104.     list = pricelistEpic
  105.     page = 0
  106.   elseif buttonNumber == 5 then
  107.     list = pricelistLegendary
  108.     page = 0
  109.   elseif buttonNumber == 6 then
  110.     page = 0
  111.     list = information
  112.   elseif buttonNumber == 7 then
  113.     page = page + 1
  114.     gpu.set(1,1,tostring(page))
  115.     if page > math.floor(#list/38) then page = 0 end
  116.   elseif buttonNumber == 8 then
  117.     page = page - 1
  118.     if page < 0 then page = math.floor(#list/38) end
  119.   else
  120.     print("you broke it")
  121.     buttonNumber = 1
  122.   end
  123. end
  124.  
  125. repeat
  126.   BA.drawAll() --Draws all buttons
  127.   selectList()
  128.   term.clear()
  129.   print("")
  130.   for i=1+38*page,38+38*page,2 do
  131.     if i>#list then
  132.       print("")
  133.     else
  134.       gpu.set(1,(i+1)/2-19*page+1,list[i])
  135.       gpu.set(width-24-uni.len(list[i+1]),(i+1)/2-19*page+1,list[i+1])
  136.       --print(tostring(list[i]).." "..tostring(list[i+1]))
  137.     end
  138.   end
  139. until false --forever (until true==false)
Advertisement
Add Comment
Please, Sign In to add comment