Daniel_I_Am

pricelist.lua

Nov 14th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 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.05)
  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. information = {"--------------------------------------","","             INFORMATION","","--------------------------------------","","This is the server's pricelist.","","This list lists the lowest price you,","","as a player, can sell at.","","Of course you can sell above these","","prices.","","","","Use the buttons on the side","","and bottom to navigate.","","","","If you have any questions regarding","","this pricelist and its rules, ask","","the other players.","","If they also do not know it,","","then ask a staff member.",""}
  40.  
  41. list = {}
  42. page = 0
  43.  
  44. gpu.setResolution(60,25)
  45. gpu.setBackground(0x000000)
  46. gpu.setForeground(0xffffff)
  47. term.clear()
  48. width,height = gpu.getResolution()
  49. BA.clear() -- clears the buttons stored
  50.  
  51. --xOffset, yOffset, width, height, Background Color, Text Color, textXOffset, textYOffset, text
  52. BA.makeButton(width-21,height-3,19,3,0x808080,0xffffff,-1,-1,"Common") --1
  53. BA.makeButton(width-21,height-7,19,3,0x36c95e,0xffffff,-1,-1,"Uncommon") --2
  54. BA.makeButton(width-21,height-11,19,3,0x4283d8,0xffffff,-1,-1,"Rare") --3
  55. BA.makeButton(width-21,height-15,19,3,0x9c52c8,0xffffff,-1,-1,"Epic") --4
  56. BA.makeButton(width-21,height-19,19,3,0xdd871c,0xffffff,-1,-1,"Legendary") --5
  57. BA.makeButton(width-21,height-23,19,3,0xffffff,0x000000,-1,-1,"Information") --6
  58. BA.makeButton(8,height-3,6,3,0xffffff,0x000000,-1,-1,"next") --7
  59. BA.makeButton(1,height-3,6,3,0xffffff,0x000000,-1,-1,"prev") --8
  60. --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
  61.  
  62. function checkButtons()
  63.   l = BA.updateAll(event.pull("touch"))
  64.   for k,v in pairs(l) do
  65.     buttonNumber = v
  66.   end
  67.   l = {}
  68.   return buttonNumber
  69. end
  70.  
  71. function selectList()
  72.   buttonNumber = checkButtons()
  73.   if buttonNumber == 1 then
  74.     list = pricelistCommon
  75.     page = 0
  76.   elseif buttonNumber == 2 then
  77.     list = pricelistUncommon
  78.     page = 0
  79.   elseif buttonNumber == 3 then
  80.     list = pricelistRare
  81.     page = 0
  82.   elseif buttonNumber == 4 then
  83.     list = pricelistEpic
  84.     page = 0
  85.   elseif buttonNumber == 5 then
  86.     list = pricelistLegendary
  87.     page = 0
  88.   elseif buttonNumber == 6 then
  89.     page = 0
  90.     list = information
  91.   elseif buttonNumber == 7 then
  92.     page = page + 1
  93.     gpu.set(1,1,tostring(page))
  94.     if page > math.floor(#list/38) then page = 0 end
  95.   elseif buttonNumber == 8 then
  96.     page = page - 1
  97.     if page < 0 then page = math.floor(#list/38) end
  98.   else
  99.     print("you broke it")
  100.     buttonNumber = 1
  101.   end
  102. end
  103.  
  104. repeat
  105.   BA.drawAll() --Draws all buttons
  106.   selectList()
  107.   term.clear()
  108.   print("")
  109.   for i=1+38*page,38+38*page,2 do
  110.     if i>#list then
  111.       print("")
  112.     else
  113.       gpu.set(1,(i+1)/2-19*page+1,list[i])
  114.       gpu.set(width-24-uni.len(list[i+1]),(i+1)/2-19*page+1,list[i+1])
  115.       --print(tostring(list[i]).." "..tostring(list[i+1]))
  116.     end
  117.   end
  118. until false --forever (until true==false)
Advertisement
Add Comment
Please, Sign In to add comment