Clem105

WorkShop

Jun 16th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.65 KB | None | 0 0
  1. --Workshop main Computer
  2. --Variables
  3. os.loadAPI("button")
  4. os.loadAPI("button2")
  5. local screen = peripheral.wrap("monitor_1")
  6. local MonitorKeyboard = peripheral.wrap("monitor_0")
  7. local sensor = peripheral.wrap("left")
  8. local AE = peripheral.wrap("back")
  9. local ChestPrice = peripheral.wrap("chest_0")
  10. local ChestInput = peripheral.wrap("right")
  11. local xSize,ySize = screen.getSize()
  12. local ItemPrice = {}
  13. local FluidPrice = {}
  14. local Alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}
  15. local file = fs.open("Price","r")
  16. ItemPrice = textutils.unserialize(file.readAll())
  17. local MetaResearch = ""
  18. local IDResearch = ""
  19. local page = 1
  20. local pages = 0
  21. local Search = ""
  22. local Data = {}
  23. local t ={}
  24. --MainProgramm
  25. MonitorKeyboard.clear()
  26. screen.clear()
  27. AffichageMonitorItem()
  28. function addItemPrice()
  29.     term.clear()
  30.     print("Please insert an item into the first slot of the chest")
  31.     while ChestInput.getStackInSlot(1) ~= nil do
  32.         print("Begin Analyzing")
  33.         for k,v in pairs(ChestInput.getStackInSlot(1)) do
  34.             if k == "name" then
  35.                 t["Name"] = v
  36.             end
  37.             if k == "dmg" then
  38.                 t["Dmg"] = v
  39.             end
  40.             if k == "id" then
  41.                 t["Id"] = v
  42.             end
  43.         end
  44.         print(" Now please enter the price :")
  45.         t["Price"] = read()
  46.         table.insert(ItemPrice,t)
  47.         print("Work done.")
  48.         AffichageComputer()
  49.         break
  50.     end
  51. end
  52. function AffichageComputer()
  53.     for i = 1,3 do
  54.         paintutils.drawLine(1,i,51,i,Color)
  55.         paintutils.drawLine(1,27-i,51,27-i,Color)
  56.     end
  57.     for i  = 1,4 do
  58.         paintutils.drawLine(i,1,i,17,Color)
  59.         paintutils.drawLine(51-i,1,51-i,17,Color)
  60.     end
  61.     term.setCursorPos(5,4)
  62.     for i = 1,#CustomerName do
  63.         if i > 6 then
  64.             break
  65.         break
  66.         end
  67.         paintutils.drawImage(paintutils.loadImage(string.sub(CustomerName,i,i)))
  68.         term.setCursorPos(3+term.getCursorPos()[1],3+term.getCursorPos()[2])
  69.     end
  70.     term.setCursorPos(20,24)
  71.     print("> ")
  72.        
  73. end
  74. function AffichageMonitorKeyboard()
  75.     MonitorKeyboard.clear()
  76.     button2.clearTable()
  77.     local CurrentLetter = 0
  78.     local countRow = 1
  79.     local Col = 2
  80.     local Row = 8
  81.     for CurrentLetter = 1,#Alphabet do
  82.         Row = 4+(CountRow)
  83.         button2.setTable(Alphabet[CurrentLetter],Press,Alphabet[CurrentLetter],Col,Col+17,Row,Row)
  84.         if Col == 21 then
  85.             Col = 2
  86.             countRow = countRow+2
  87.         else
  88.             Col = Col+4
  89.         end
  90.     end
  91.     button2.setTable("Space",Press," ",21,29,19,19,)
  92.     button2.setTable("<",Press,"<",31,38,19,19)
  93.     button2.setTable("Switch to Id",AffichageMonitorIdResearch,"",21,38,26,26)
  94.     button2.setTable("Research",Research,(Search,"Name"),21,38,22,22)
  95.     button.sreen()
  96. end
  97. function Research(Search,type)
  98.     if type == "Name" then
  99.         for i = 1,#ItemPrice do
  100.             if not string.find(ItemPrice[i]["Name"],Search) == nil then  
  101.                 table.insert(Data[i],ItemPrice[i]["Name"])
  102.             end
  103.         end
  104.     else
  105.         for i =  1,#ItemPrice do
  106.             if ItemPrice[i]["Id"] == Search[1] and ItemPrice[i]["Dmg"] == Search[2] then
  107.                 table.insert(Data[i],ItemPrice[i]["Name"])
  108.             end
  109.         end
  110.     end
  111.     AffichageMonitorItem()
  112. end
  113. function Press(char)
  114.     if char == "<" then
  115.         Search = string.gsub(Search,-1,1)
  116.     else
  117.         Search = Search..char
  118.     end
  119.     AffichageMonitorKeyboard()
  120. end
  121. function AffichageMonitorItem(o)
  122.     if o == nil then
  123.         screen.clear()
  124.         button.clearTable()
  125.         local CurrentItem = 0
  126.         local countRow = 1
  127.         local Col = 2
  128.         local Row = 12
  129.         local nbItemPerPage = 8
  130.         pages = math.ceil(#ItemPrice/nbItemPerPage)
  131.         for CurrentItem = 1,#ItemPrice do
  132.             if CurrentItem > nbItemPerPage*(page - 1) and CurrentItem < nbItemPerPage*page+1 then
  133.                 Row = 4+(CountRow)
  134.                 button.setTable(ItemPrice[CurrentItem]["Name"],BuyItem,ItemPrice[CurrentItem]["Name"],Col, Col+17 , Row, Row)
  135.                 if Col == 21 then
  136.                     Col = 2
  137.                     countRow = countRow + 2
  138.                 else
  139.                     Col = Col+19
  140.                 end
  141.             end
  142.         end
  143.         button.label(15,3,"Page "..tostring(page).." on "..tostring(pages))
  144.         button.setTable("Buy Liquids",AffichageMonitorLiquid,"",21,38,19,19)
  145.         button.setTable("Next Page", nextPage, "", 21, 38, 1, 1)
  146.         button.setTable("Prev Page", prevPage, "", 2, 19, 1, 1)
  147.         button.sreen()
  148.     elseif  string.find(o,%a) ~= nil then
  149.         screen.clear()
  150.         button.clearTable()
  151.         local CurrentItem = 0
  152.         local countRow = 1
  153.         local Col = 2
  154.         local Row = 12
  155.         local nbItemPerPage = 8
  156.         pages = math.ceil(#Data/nbItemPerPage)
  157.         for CurrentItem = 1,#Data do
  158.             if CurrentItem > nbItemPerPage*(page - 1) and CurrentItem < nbItemPerPage*page+1 then
  159.                 Row = 4+(CountRow)
  160.                 button.setTable(Data[CurrentItem]["Name"],BuyItem,Data[CurrentItem]["Name"],Col, Col+17 , Row, Row)
  161.                 if Col == 21 then
  162.                     Col = 2
  163.                     countRow = countRow + 2
  164.                 else
  165.                     Col = Col+19
  166.                 end
  167.             end
  168.         end
  169.         button.label(15,3,"Page "..tostring(page).." on "..tostring(pages))
  170.         button.setTable("Buy Liquids",AffichageMonitorLiquid,"",21,38,19,19)
  171.         button.setTable("Next Page", nextPage, "", 21, 38, 1, 1)
  172.         button.setTable("Prev Page", prevPage, "", 2, 19, 1, 1)
  173.         button.sreen()
  174.     else
  175.         Data = o
  176.         screen.clear()
  177.         button.clearTable()
  178.         local CurrentItem = 0
  179.         local countRow = 1
  180.         local Col = 2
  181.         local Row = 12
  182.         local nbItemPerPage = 8
  183.         pages = math.ceil(#Data/nbItemPerPage)
  184.         for CurrentItem = 1,#Data do
  185.             for i = 1,#ItemPrice do
  186.                 if tonumber
  187.             if CurrentItem > nbItemPerPage*(page - 1) and CurrentItem < nbItemPerPage*page+1 then
  188.                 Row = 4+(CountRow)
  189.                 button.setTable(,BuyItem,,Col, Col+17 , Row, Row)
  190.                 if Col == 21 then
  191.                     Col = 2
  192.                     countRow = countRow + 2
  193.        
  194.     end
  195. end
  196. function AffichageMonitorIdResearch()
  197.     MonitorKeyboard.clear()
  198.     button2.clear()
  199.     local CurrentNumber = 0
  200.     local CurrentRow = 1
  201.     local Row = 4
  202.     local Col = 4
  203.     for i =1,9 do
  204.         Row = 4+(CountRow)
  205.         button2.setTable(tostring(i),PressNumber,tostring(i),Col,Col+6,Row,Row)
  206.         if Col == 12 then
  207.             Col = 4
  208.             countRow = countRow+4
  209.         else
  210.             Col = Col+4
  211.         end
  212.     end
  213.     button2.setTable("<",Press,"<",2,15,24,24)
  214.     button2.setTable("Switch to Name",AffichageMonitorKeyboard,"",17,38,24,24)
  215.     button2.setTable("Research",Research,({IDResearch,MeataResearch},"ID"),2,38,26,26)
  216.     button2.setTable("Id",SwitchIdMeta,"Id",21, 38, 1, 1)
  217.     button2.setTable("Metadata",SwitchIdMeta,"Metadata",2, 19, 1, 1)
  218.     button2.label(3,19,tostring(IDResearch))
  219.     button2.label(8,19,tostring(MetaResearch))
  220.     if idMeta ~= nil then
  221.         button2["Id"]["active"] = false
  222.         button2["Metadata"]["active"] = false
  223.         button2["idMeta"]["active"] = true
  224.     end
  225.     button2.screen()
  226. end
  227. function PressNumber(num)
  228.     if button2["Id"]["active"] == true then
  229.         if num == "<" then
  230.                 IDResearch = string.gsub(IDResearch,-1,1)
  231.         else
  232.             IDResearch = IDResearch..num
  233.         end
  234.     else
  235.         if num == "<" then
  236.                 MetaResearch = string.gsub(MetaResearch,-1,1)
  237.         else
  238.             MetaResearch = MetaResearch..num
  239.         end
  240.     end
  241. end
  242. function SwitchIdMeta(o)
  243.     IdMeta = o
  244.     AffichageMonitorIdResearch()
  245. end
  246. function BuyItem(name)
  247.     screen.clear()
  248.     Item = name
  249.     AffichageMonitorItem2(name)
  250. end
  251. function getPrice(name)
  252.     for i = 1, #ItemPrice do
  253.         if ItemPrice[i]["Name"] == name then
  254.             return ItemPrice[i]["Price"]
  255.         end
  256.     end
  257. end
  258. function AffichageMonitorItem2(name)
  259.     button.label(7,1,"Combien de "..name.." souhaitez-vous acheter ?")
  260.     button.setTable("+1", addItem, 1, 8, 18, 6,6)
  261.     button.setTable("+10", addItem, 10, 20, 30, 6, 6)
  262.        button.setTable("+64", addItem, 64, 32, 42, 6, 6)
  263.        button.setTable("-1", addItem, -1, 8, 18, 8, 8)
  264.        button.setTable("-10", addItem, -10, 20, 30, 8, 8)
  265.        button.setTable("-64", addItem, -64, 32, 42, 8 ,8)
  266.     button.setTable("LE MAX !", addItem, 512-ItemRequested, 8, 42, 10, 10)
  267.     button.setTable("Execute Item Request", Transaction,getPrice(name), 8, 42, 16, 18)
  268.     button.label(7,20,"Cela vous coutera"..getPrice(name).." diamonds.")
  269.     button.label(7, 4, "Pour l'instant vous désirez" ..tostring(ItemRequested).." "..name.." .")
  270. end
  271. function addItem(num)
  272.     ItemRequested = ItemRequested+num
  273.     if ItemRequested < 0 then
  274.         ItemRequested = 0
  275.     end
  276.     if ItelRequested > 512 then
  277.         ItemRequested = 512
  278.     end
  279.     sreen.clear()
  280.     AffichageMonitorItem2(Item)
  281. end
  282. function nextPage()
  283.     if page+1 <= pages then
  284.         page = page+1
  285.     end
  286.     AffichageMonitorItem()
  287. end
  288. function prevPage()
  289.     if page-1 >= 1 then
  290.         page = page-1
  291.     end
  292.        AffichageMonitorItem()
  293.     end  
  294. function getClick()
  295.        event, side, x,y = os.pullEvent()
  296.        if event == "monitor_touch" and side == "montitor_0" then
  297.           button.checkxy(x,y)
  298.     end
  299. end
  300. function getClickBis()
  301.        event, side, x,y = os.pullEvent()
  302.        if event == "monitor_touch" and side == "monitor_1" then
  303.           button2.checkxy(x,y)
  304.     end
  305. end
  306. function Openfile(mode)
  307.     file.close()
  308.     file = fs.open("Price",mode)
  309. end
  310.  
  311. while true do
  312.     parallel.waitForAny(getClick,getClickBis,AffichageComputer)
  313. end
Advertisement
Add Comment
Please, Sign In to add comment