Daniel_I_Am

PricelistTest.lua

Nov 21st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.39 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.         a = nil
  26.       end
  27.     until line == nil
  28.     file:close()
  29.     return array
  30.   else
  31.     return {}
  32.   end
  33. end
  34.  
  35. pricelistCommon = fileToArray("/home/pricelistCommon.txt")
  36. pricelistUncommon = fileToArray("/home/pricelistUncommon.txt")
  37. pricelistRare = fileToArray("/home/pricelistRare.txt")
  38. pricelistEpic = fileToArray("/home/pricelistEpic.txt")
  39. pricelistLegendary = fileToArray("/home/pricelistLegendary.txt")
  40.  
  41. information = {
  42. "--------------------------------------","",
  43. "             INFORMATION              ","",
  44. "--------------------------------------","",
  45. "This is the server's pricelist.       ","",
  46. "This list lists the lowest price you, ","",
  47. "as a player, can sell at.             ","",
  48. "Of course you can sell above these    ","",
  49. "prices.                               ","",
  50. "                                      ","",
  51. "Use the buttons on the side           ","",
  52. "and bottom to navigate.               ","",
  53. "                                      ","",
  54. "If you have any questions regarding   ","",
  55. "this pricelist and its rules, ask     ","",
  56. "the other players.                    ","",
  57. "If they don't know it either, don't   ","",
  58. "hesitate to ask a BOE member. Any     ","",
  59. "missing items or mistakes in the list ","",
  60. "should be reported to a BOE member.   ",""
  61. }
  62.  
  63. list = {}
  64. page = 0
  65.  
  66. funtion GUI()
  67.     gpu.setResolution(60,25)
  68.     gpu.setBackground(0x000000)
  69.     gpu.setForeground(0xffffff)
  70.     term.clear()
  71.     width,height = gpu.getResolution()
  72.     BA.clear() -- clears the buttons stored
  73. end
  74.    
  75. function createButtons()
  76.     --xOffset, yOffset, width, height, Background Color, Text Color, textXOffset, textYOffset, text
  77.     BA.makeButton(width-21,height-3,19,3,0x808080,0xffffff,-1,-1,"Common") --1
  78.     BA.makeButton(width-21,height-7,19,3,0x36c95e,0xffffff,-1,-1,"Uncommon") --2
  79.     BA.makeButton(width-21,height-11,19,3,0x4283d8,0xffffff,-1,-1,"Rare") --3
  80.     BA.makeButton(width-21,height-15,19,3,0x9c52c8,0xffffff,-1,-1,"Epic") --4
  81.     BA.makeButton(width-21,height-19,19,3,0xdd871c,0xffffff,-1,-1,"Legendary") --5
  82.     BA.makeButton(width-21,height-23,19,3,0xffffff,0x000000,-1,-1,"Information") --6
  83.     BA.makeButton(8,height-3,6,3,0xffffff,0x000000,-1,-1,"next") --7
  84.     BA.makeButton(1,height-3,6,3,0xffffff,0x000000,-1,-1,"prev") --8
  85.     --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
  86. end
  87.  
  88. function checkButtons()
  89.   l = BA.updateAll(event.pull("touch"))
  90.   for k,v in pairs(l) do
  91.     buttonNumber = v
  92.   end
  93.   l = {}
  94.   return buttonNumber
  95. end
  96.  
  97. function selectList()
  98.   buttonNumber = checkButtons()
  99.   if buttonNumber == 1 then
  100.     list = pricelistCommon
  101.     page = 0
  102.   elseif buttonNumber == 2 then
  103.     list = pricelistUncommon
  104.     page = 0
  105.   elseif buttonNumber == 3 then
  106.     list = pricelistRare
  107.     page = 0
  108.   elseif buttonNumber == 4 then
  109.     list = pricelistEpic
  110.     page = 0
  111.   elseif buttonNumber == 5 then
  112.     list = pricelistLegendary
  113.     page = 0
  114.   elseif buttonNumber == 6 then
  115.     page = 0
  116.     list = information
  117.   elseif buttonNumber == 7 then
  118.     page = page + 1
  119.     gpu.set(1,1,tostring(page))
  120.     if page > math.floor(#list/38) then page = 0 end
  121.   elseif buttonNumber == 8 then
  122.     page = page - 1
  123.     if page < 0 then page = math.floor(#list/38) end
  124.   else
  125.     print("you broke it")
  126.     buttonNumber = 1
  127.   end
  128. end
  129.  
  130. GUI()
  131. createButtons()
  132.  
  133. repeat
  134.   BA.drawAll() --Draws all buttons
  135.   selectList()
  136.   term.clear()
  137.   print("")
  138.   for i=1+38*page,38+38*page,2 do
  139.     if i>#list then
  140.       print("")
  141.     else
  142.       gpu.set(1,(i+1)/2-19*page+1,list[i])
  143.       gpu.set(width-24-uni.len(list[i+1]),(i+1)/2-19*page+1,list[i+1])
  144.       --print(tostring(list[i]).." "..tostring(list[i+1]))
  145.     end
  146.   end
  147. until false --forever (until true==false)
Advertisement
Add Comment
Please, Sign In to add comment