Advertisement
Chaos_Cash

shopMain2

Sep 23rd, 2024 (edited)
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 26.63 KB | None | 0 0
  1. function startup()
  2. sleep(1)
  3.  
  4.     for k,v in pairs(peripheral.getNames()) do
  5.         if peripheral.getType(peripheral.getNames()[k]) == "modem" then
  6.         rednet.open(peripheral.getNames()[k])
  7.         end
  8.     end
  9.  
  10. shopComputerId = 968
  11.  
  12.  
  13.     if fs.exists("password") then
  14.     file = fs.open("password","r")
  15.     password = file.readAll()
  16.     file.close()
  17.     fs.delete("password")
  18.     rednet.send(shopComputerId,{["action"]="newPocket",["password"]=password})
  19.     end
  20.    
  21.  
  22. readingOutput = {}
  23.  
  24. blinkIsOn = true
  25.  
  26. scrollmenuLen={}
  27. scrollmenuInfos={}
  28.  
  29. dropdown = {}
  30. dropdown["loaded"] = {}
  31. dropdown["loaded"]["len"] = 0
  32.  
  33.  
  34. shopItems = getItems()
  35.  
  36.  
  37. shopItemNumbers = {}
  38. shopItemNames = {}
  39. itemCost = {}
  40.     for k,v in pairs(shopItems) do
  41.     shopItemNames[k] = shopItems[k]["name"]
  42.     itemCost[k] = shopItems[k]["price"] .. "c"
  43.     shopItemNumbers[shopItems[k]["name"]] = k
  44.     end
  45.    
  46.    
  47. cartContent = {}
  48. cartContentPrices = {}
  49.  
  50. totalPrice = 0
  51.  
  52. chestIDs = {972}
  53.  
  54. cart = {}
  55.  
  56. createScrollmenu("cartContent",1,10,26,20,cartContent,0)
  57. createScrollmenu("standardShop",1,10,26,20,shopItemNames,0,itemCost)
  58. end
  59.  
  60.  
  61.  
  62. function main()
  63.  
  64.     while true do
  65.  
  66.     info1,info2,info3,info4 = os.pullEventRaw()
  67.     overwriteDropdown()
  68.        
  69.    
  70.         if info1 == "rednet_message" and info2 == shopComputerId then  
  71.            
  72.            
  73.                 if type(info3) == "table" then
  74.                
  75.                
  76.                     if info3["action"] == "paid" then
  77.                     pay(info3["amount"])
  78.                     end
  79.                    
  80.                    
  81.                     if info3["action"] == "orderIsDone" then
  82.                     thanksMenu()
  83.                     end
  84.                
  85.                
  86.                 end
  87.        
  88.        
  89.         end
  90.        
  91.        
  92.        
  93.         if info1 == "timer" and info2 == reduceTimeTimer then
  94.             timeLeft = timeLeft-1
  95.                 if curEnvName == "payMenu" or curEnvName == "areYouSureMenu" then
  96.                     if timeLeft > 59 then
  97.                     term.setCursorPos(1,1)
  98.                     term.setBackgroundColor(colors.black)
  99.                     term.write("                                                ")
  100.                         if timeLeft-60 > 9 then
  101.                         headline("1:" .. timeLeft-60)
  102.                         else
  103.                         headline("1:0" .. timeLeft-60)
  104.                         end
  105.                     reduceTimeTimer = os.startTimer(1)
  106.                     elseif timeLeft > 0 then
  107.                     term.setCursorPos(1,1)
  108.                     term.setBackgroundColor(colors.black)
  109.                     term.write("                                                ")
  110.                     if timeLeft > 9 then
  111.                         headline("0:" .. timeLeft)
  112.                         else
  113.                         headline("0:0" .. timeLeft)
  114.                         end
  115.                     reduceTimeTimer = os.startTimer(1)
  116.                     else
  117.                     term.setBackgroundColor(colors.black)
  118.                     term.clear()
  119.                     term.setCursorPos(1,1)
  120.                     term.setTextColor(colors.red)
  121.                     print("Your order was canceled due to inactivity.")
  122.                    
  123.                     amountPaid = 0
  124.                    
  125.                     sleep(3)
  126.                     cartMenu()
  127.                     end
  128.                 end
  129.             end
  130.        
  131.        
  132.        
  133.         if curEnvName == "areYouSureMenu" then
  134.        
  135.             if buttonCheck(4,8,12,10) then
  136.             rednet.send(shopComputerId,{["action"]="canceledOrder"})
  137.             cartMenu()
  138.             end
  139.            
  140.             if buttonCheck(15,8,22,10) then
  141.             payMenu()
  142.             end
  143.        
  144.         end
  145.        
  146.        
  147.         if curEnvName == "homeMenu" then
  148.            
  149.            
  150.             if buttonCheck(10,4,17,6) then
  151.             shopMenu()
  152.             end
  153.            
  154.            
  155.             if buttonCheck(10,7,17,9) then
  156.             cartMenu()
  157.             end
  158.        
  159.         end
  160.        
  161.        
  162.         if curEnvName == "payMenu" then
  163.        
  164.             if buttonCheck(19,18,26,20) then
  165.                 if amountPaid == 0 then
  166.                 rednet.send(shopComputerId,{["action"]="canceledOrder"})
  167.                 cartMenu()
  168.                 else
  169.                 areYouSureMenu()
  170.                 end
  171.             end
  172.        
  173.            
  174.         end
  175.        
  176.        
  177.         if curEnvName == "cartMenu" then
  178.         scrollmenuOut = checkScrollmenu("cartContent")
  179.            
  180.             if buttonCheck(21,6,26,8) then
  181.             homeMenu()
  182.             end
  183.            
  184.             if buttonCheck(1,6,5,8) and totalPrice > 0 then
  185.             addOrder()
  186.             payMenu()
  187.             end
  188.        
  189.        
  190.             if scrollmenuOut ~= nil then
  191.            
  192.             end
  193.         end
  194.        
  195.        
  196.         if curEnvName == "shopMenu" then
  197.        
  198.         scrollmenuOut = checkScrollmenu("standardShop")
  199.            
  200.             if buttonCheck(21,6,26,8) then
  201.             stopReading()
  202.             homeMenu()
  203.             end
  204.            
  205.            
  206.             if scrollmenuOut ~= nil then
  207.             buyMenu(scrollmenuOut)
  208.             end
  209.            
  210.             if betterRead(true,{}) then
  211.             search()
  212.             filledSquare(1,10,26,20,colors.black)
  213.             printScrollmenu("standardShop")
  214.             end
  215.        
  216.         end
  217.        
  218.        
  219.         if curEnvName == "buyMenu" then
  220.            
  221.             if buttonCheck(21,18,26,20) then
  222.             shopMenu()
  223.             end
  224.            
  225.            
  226.             if buttonCheck(21,9,26,11) then
  227.             updateBuyMenu(1)
  228.             end
  229.            
  230.             if buttonCheck(21,6,26,8) then
  231.             updateBuyMenu(10)
  232.             end
  233.            
  234.             if buttonCheck(21,3,26,5) then
  235.             updateBuyMenu(100)
  236.             end
  237.            
  238.             if buttonCheck(1,9,6,11) then
  239.             updateBuyMenu(-1)
  240.             end
  241.            
  242.             if buttonCheck(1,6,6,8) then
  243.             updateBuyMenu(-10)
  244.             end
  245.            
  246.             if buttonCheck(1,3,6,5) then
  247.             updateBuyMenu(-100)
  248.             end
  249.            
  250.            
  251.             if buttonCheck(1,18,13,20) then
  252.             addToCart()
  253.             shopMenu()
  254.             end
  255.        
  256.         end
  257.    
  258.     end
  259.    
  260. end
  261.  
  262.  
  263.  
  264. function addOrder()
  265.  
  266. amountPaid = 0
  267.  
  268. term.setBackgroundColor(colors.black)
  269. term.setTextColor(colors.red)
  270. term.clear()
  271. term.setCursorPos(1,1)
  272. print("Waiting for main computer to respond\n")
  273. term.setTextColor(colors.green)
  274. term.write("Info: ")
  275. term.setTextColor(colors.white)
  276. print("You need to be in the market for this to work.")
  277. term.setTextColor(colors.green)
  278.  
  279. rednet.send(shopComputerId,{["action"]="newOrder",["order"]={["cartInfo"]=cart,["content"]=scrollmenuInfos["cartContent"]["content"],["price"]=totalPrice,["id"]=os.getComputerID()}})
  280.  
  281. dotCount = 0
  282. rightMessage = false
  283.  
  284.     repeat
  285.     timer = os.startTimer(0.5)
  286.     info1,info2,info3,info4 = os.pullEventRaw()
  287.     os.cancelTimer(timer)
  288.         if info1 == "timer" and info2 == timer then
  289.             if dotCount < 3 then
  290.             dotCount = dotCount+1
  291.             term.setCursorPos(10+dotCount,2)
  292.             term.write(".  ")
  293.             else
  294.             dotCount = 0
  295.             term.setCursorPos(11,2)
  296.             term.write("    ")
  297.             end
  298.         rednet.send(shopComputerId,{["action"]="newOrder",["order"]={["cartInfo"]=cart,["content"]=scrollmenuInfos["cartContent"]["content"],["price"]=totalPrice,["id"]=os.getComputerID()}})
  299.         end
  300.    
  301.         if type(info3) == "table" then
  302.             if info3["action"] == "listedOrder" then
  303.             rightMessage = true
  304.             end
  305.         end
  306.        
  307.     until info1 == "rednet_message" and info2 == shopComputerId and rightMessage
  308.    
  309.    
  310. term.setTextColor(colors.red)
  311. term.clear()
  312. term.setCursorPos(1,1)
  313. print("Waiting to reach end of queue\n")
  314. term.setTextColor(colors.green)
  315. term.write("Position in queue: ")
  316. term.setTextColor(colors.white)
  317. print(info3["orderPos"].."\n")
  318. term.setTextColor(colors.green)
  319.  
  320. term.write("Info: ")
  321. term.setTextColor(colors.white)
  322. print("There is currently a different order being processed, this should at")
  323. term.write("most take ")
  324. term.setTextColor(colors.green)
  325. term.write(1.5*(info3["orderPos"]-1))
  326. term.write(" minutes.")
  327. term.setTextColor(colors.white)
  328. print(" If this takes longer please inform me when im online (Chaos_Chash) or on Discord (SeNN/Chaos_Cash).")
  329. term.setTextColor(colors.green)
  330.  
  331.    
  332.     while info3["orderPos"] > 1 do
  333.    
  334.     dotCount = 0
  335.     rightMessage = false
  336.  
  337.         repeat
  338.         timer = os.startTimer(0.5)
  339.         info1,info2,info3,info4 = os.pullEventRaw()
  340.         os.cancelTimer(timer)
  341.             if info1 == "timer" and info2 == timer then
  342.                 if dotCount < 3 then
  343.                 dotCount = dotCount+1
  344.                 term.setCursorPos(5+dotCount,2)
  345.                 term.write(".  ")
  346.                 else
  347.                 dotCount = 0
  348.                 term.setCursorPos(6,2)
  349.                 term.write("    ")
  350.                 end
  351.             end
  352.        
  353.             if type(info3) == "table" then
  354.                 if info3["action"] == "changedOrder" then
  355.                 rightMessage = true
  356.                 end
  357.             end
  358.            
  359.         until info1 == "rednet_message" and info2 == shopComputerId and rightMessage
  360.    
  361.     end
  362.  
  363.  
  364. timeLeft = 90
  365. reduceTimeTimer = os.startTimer(1)
  366. end
  367.  
  368.  
  369.  
  370. function areYouSureMenu()
  371. curEnv = areYouSureMenu
  372. curEnvName = "areYouSureMenu"
  373. term.setBackgroundColor(colors.black)
  374. term.clear()
  375.  
  376.  
  377.     if timeLeft > 59 then
  378.    
  379.         if timeLeft-60 > 9 then
  380.         headline("1:" .. timeLeft-60)
  381.         else
  382.         headline("1:0" .. timeLeft-60)
  383.         end
  384.        
  385.     elseif timeLeft > 0 then
  386.    
  387.     term.setCursorPos(1,1)
  388.     term.setBackgroundColor(colors.black)
  389.     term.write("                                                ")
  390.         if timeLeft > 9 then
  391.         headline("0:" .. timeLeft)
  392.         else
  393.         headline("0:0" .. timeLeft)
  394.         end
  395.    
  396.     end
  397.  
  398.  
  399. term.setCursorPos(1,3)
  400. term.setTextColor(colors.red)
  401. print("Are you sure? If you cancel your order everything you paid will get lost.")
  402.  
  403. button("Confirm",4,8,12,10)
  404. button("Deny",15,8,22,10,colors.red)
  405.  
  406. end
  407.  
  408.  
  409.  
  410. function thanksMenu()
  411. term.setBackgroundColor(colors.black)
  412. term.clear()
  413. term.setCursorPos(1,1)
  414. term.setTextColor(colors.green)
  415. print("Thank you for your purchase.")
  416.  
  417. cart = {}
  418. cartContent = {}
  419. cartContentPrices = {}
  420. createScrollmenu("cartContent",1,10,26,20,cartContent,0,cartContentPrices)
  421. totalPrice = 0
  422. amountPaid = 0
  423.  
  424. sleep(3)
  425. homeMenu()
  426. end
  427.  
  428.  
  429.  
  430. function pay(amount)
  431.  
  432. amountPaid = amountPaid+amount
  433.  
  434. term.setCursorPos(7,5)
  435. term.setTextColor(colors.white)
  436. print(amountPaid)
  437.  
  438. term.setCursorPos(12,6)
  439. term.setTextColor(colors.white)
  440. print(totalPrice-amountPaid.."               ")
  441.  
  442. end
  443.  
  444.  
  445.  
  446. function payMenu()
  447. curEnv = payMenu
  448. curEnvName = "payMenu"
  449. term.clear()
  450.     if timeLeft > 59 then
  451.    
  452.         if timeLeft-60 > 9 then
  453.         headline("1:" .. timeLeft-60)
  454.         else
  455.         headline("1:0" .. timeLeft-60)
  456.         end
  457.        
  458.     elseif timeLeft > 0 then
  459.    
  460.     term.setCursorPos(1,1)
  461.     term.setBackgroundColor(colors.black)
  462.     term.write("                                                ")
  463.         if timeLeft > 9 then
  464.         headline("0:" .. timeLeft)
  465.         else
  466.         headline("0:0" .. timeLeft)
  467.         end
  468.    
  469.     end
  470.  
  471.  
  472.  
  473. button("Cancel",19,18,26,20,colors.red)
  474.  
  475. term.setCursorPos(1,4)
  476. term.setTextColor(colors.green)
  477. term.write("Price: ")
  478. term.setTextColor(colors.white)
  479. print(totalPrice)
  480.  
  481. term.setTextColor(colors.green)
  482. term.write("Paid: ")
  483. term.setTextColor(colors.white)
  484. print(amountPaid)
  485.  
  486. term.setTextColor(colors.green)
  487. term.write("Remaining: ")
  488. term.setTextColor(colors.white)
  489. print(totalPrice-amountPaid)
  490. end
  491.  
  492.  
  493.  
  494. function cartMenu()
  495. curEnv = cartMenu
  496. curEnvName = "cartMenu"
  497. term.clear()
  498. headline("Cart")
  499.  
  500. button("Back",21,6,26,8)
  501.     if totalPrice > 0 then
  502.     button("Buy",1,6,5,8)
  503.     else
  504.     button("Buy",1,6,5,8,colors.red)
  505.     end
  506.  
  507. printScrollmenu("cartContent")
  508. end
  509.  
  510.  
  511.  
  512. function addToCart()
  513.  
  514. table.insert(cartContent,buyAmount .. "x " .. curItem)
  515. table.insert(cartContentPrices,shopItems[shopItemNumbers[curItem]]["price"]*buyAmount.."c")
  516. createScrollmenu("cartContent",1,10,26,20,cartContent,scrollmenuInfos["cartContent"]["position"],cartContentPrices)
  517.  
  518. totalPrice = totalPrice+(shopItems[shopItemNumbers[curItem]]["price"]*buyAmount)
  519. table.insert(cart,{["slot"]=shopItems[curItemNumber]["slot"],["chest"]=shopItems[curItemNumber]["chest"],["amount"]=buyAmount})
  520.  
  521. end
  522.  
  523.  
  524.  
  525. function updateBuyMenu(change)
  526.  
  527.     if buyAmount + change > 0 then
  528.         if  buyAmount + change < amountInStorage+1  then
  529.         buyAmount = buyAmount + change
  530.         else
  531.         buyAmount = amountInStorage
  532.         end
  533.    
  534.     term.setTextColor(colors.white)
  535.    
  536.     term.setCursorPos(9,15)
  537.     term.write(buyAmount .. "                                ")
  538.  
  539.     term.setCursorPos(8,16)
  540.     term.write((shopItems[shopItemNumbers[curItem]]["price"]*buyAmount) .. "c                               ")
  541.     elseif amountInStorage > 0 then
  542.     buyAmount = 1
  543.     term.setTextColor(colors.white)
  544.    
  545.     term.setCursorPos(9,15)
  546.     term.write(buyAmount .. "                                ")
  547.  
  548.     term.setCursorPos(8,16)
  549.     term.write((shopItems[shopItemNumbers[curItem]]["price"]*buyAmount) .. "c                               ")
  550.     end
  551.  
  552. end
  553.  
  554.  
  555.  
  556. function homeMenu()
  557. curEnv = homeMenu
  558. curEnvName = "homeMenu"
  559. term.setBackgroundColor(colors.black)
  560. term.clear()
  561. headline("Home")
  562.  
  563. button("Shop",10,4,17,6)
  564. button("Cart",10,7,17,9)
  565. end
  566.  
  567.  
  568.  
  569. function shopMenu()
  570. curEnv = shopMenu
  571. curEnvName = "shopMenu"
  572. term.clear()
  573. headline("Shop")
  574.  
  575. button("Back",21,6,26,8)
  576.  
  577. term.setCursorPos(1,9)
  578. term.setTextColor(colors.green)
  579. term.write("Search: ")
  580.  
  581. printScrollmenu("standardShop")
  582.  
  583. changeReading("shopSearch",9,9)
  584. end
  585.  
  586.  
  587.  
  588. function buyMenu(item)
  589.     if item ~= nil then
  590.     curItem = scrollmenuInfos["standardShop"]["content"][item]
  591.     curItemNumber = shopItemNumbers[scrollmenuInfos["standardShop"]["content"][item]]
  592.     end
  593.  
  594. amountInStorage = getItemCount(shopItemNumbers[curItem])
  595.  
  596.  
  597. curEnv = buyMenu
  598. curEnvName = "buyMenu"
  599. term.setBackgroundColor(colors.black)
  600. term.clear()
  601. headline(curItem)
  602.  
  603. button("Back",21,18,26,20)
  604. button("Add to cart",1,18,13,20)
  605.  
  606. button("-100",1,3,6,5,colors.red)
  607. button("-10",1,6,6,8,colors.red)
  608. button("-1",1,9,6,11,colors.red)
  609. button("+100",21,3,26,5)
  610. button("+10",21,6,26,8)
  611. button("+1",21,9,26,11)
  612.  
  613.  
  614.  
  615. term.setCursorPos(1,13)
  616. term.setTextColor(colors.green)
  617. term.write("Item: ")
  618. term.setTextColor(colors.white)
  619. term.write(curItem)
  620.  
  621. term.setCursorPos(1,14)
  622. term.setTextColor(colors.green)
  623. term.write("Storage: ")
  624. term.setTextColor(colors.white)
  625. term.write(amountInStorage)
  626.  
  627.     if amountInStorage > 0 then
  628.     buyAmount = 1
  629.     else
  630.     buyAmount = 0
  631.     end
  632.  
  633. term.setCursorPos(1,15)
  634. term.setTextColor(colors.green)
  635. term.write("Amount: ")
  636. term.setTextColor(colors.white)
  637. term.write(buyAmount)
  638.  
  639. term.setCursorPos(1,16)
  640. term.setTextColor(colors.green)
  641. term.write("Price: ")
  642. term.setTextColor(colors.white)
  643. term.write((shopItems[shopItemNumbers[curItem]]["price"]*buyAmount).."c")
  644.  
  645.  
  646.  
  647. end
  648.  
  649.  
  650.  
  651. function getItemCount(item)
  652. rednet.send(chestIDs[shopItems[item]["chest"]],{["action"]="getItemCount",["item"]=shopItems[item]["slot"]})
  653. term.setBackgroundColor(colors.black)
  654. term.setTextColor(colors.red)
  655. term.clear()
  656. term.setCursorPos(1,1)
  657. print("Waiting for main computer to respond\n")
  658. term.setTextColor(colors.green)
  659. term.write("Info: ")
  660. term.setTextColor(colors.white)
  661. print("You need to be in the market for this to work.")
  662. term.setTextColor(colors.green)
  663.  
  664. dotCount = 0
  665. rightMessage = false
  666.  
  667.  
  668. rednet.send(chestIDs[shopItems[item]["chest"]],{["action"]="getItemCount",["item"]=shopItems[item]["slot"]})
  669.     repeat
  670.     timer = os.startTimer(0.5)
  671.     info1,info2,info3,info4 = os.pullEventRaw()
  672.     os.cancelTimer(timer)
  673.         if info1 == "timer" and info2 == timer then
  674.             if dotCount < 3 then
  675.             dotCount = dotCount+1
  676.             term.setCursorPos(10+dotCount,2)
  677.             term.write(".  ")
  678.             else
  679.             dotCount = 0
  680.             term.setCursorPos(11,2)
  681.             term.write("    ")
  682.             end
  683.         rednet.send(chestIDs[shopItems[item]["chest"]],{["action"]="getItemCount",["item"]=shopItems[item]["slot"]})
  684.         end
  685.    
  686.         if type(info3) == "table" then
  687.             if info3["action"] == "sendingItemCount" then
  688.             rightMessage = true
  689.             end
  690.         end
  691.        
  692.     until info1 == "rednet_message" and info2 == chestIDs[shopItems[item]["chest"]] and rightMessage
  693.  
  694.  
  695. return info3["itemCount"]
  696. end
  697.  
  698.  
  699.  
  700. function getItems()
  701.  
  702. term.setBackgroundColor(colors.black)
  703. term.setTextColor(colors.red)
  704. term.clear()
  705. term.setCursorPos(1,1)
  706. print("Waiting for main computer to respond\n")
  707. term.setTextColor(colors.green)
  708. term.write("Info: ")
  709. term.setTextColor(colors.white)
  710. print("You need to be in the market for this to work.")
  711. term.setTextColor(colors.green)
  712.  
  713.  
  714.  
  715. dotCount = 0
  716. rightMessage = false
  717.  
  718. rednet.send(shopComputerId,{["action"]="getItems"})
  719.     repeat
  720.     timer = os.startTimer(0.5)
  721.     info1,info2,info3,info4 = os.pullEventRaw()
  722.     os.cancelTimer(timer)
  723.         if info1 == "timer" and info2 == timer then
  724.             if dotCount < 3 then
  725.             dotCount = dotCount+1
  726.             term.setCursorPos(10+dotCount,2)
  727.             term.write(".  ")
  728.             else
  729.             dotCount = 0
  730.             term.setCursorPos(11,2)
  731.             term.write("    ")
  732.             end
  733.         rednet.send(shopComputerId,{["action"]="getItems"})
  734.         end
  735.    
  736.         if type(info3) == "table" then
  737.             if info3["action"] == "sendingItems" then
  738.             rightMessage = true
  739.             end
  740.         end
  741.        
  742.     until info1 == "rednet_message" and info2 == shopComputerId and rightMessage
  743.  
  744. return info3["items"]
  745. end
  746.  
  747.  
  748.  
  749. function search()
  750. curShopItems = {}
  751. curShopItemPrices = {}
  752.  
  753.     for k,v in pairs(shopItemNames) do
  754.         if string.find(string.lower(shopItemNames[k]),string.lower(readingOutput["shopSearch"])) ~= nil then
  755.         curShopItems[table.maxn(curShopItems)+1] = shopItemNames[k]
  756.         curShopItemPrices[table.maxn(curShopItems)] = shopItems[k]["price"]
  757.         end
  758.     end
  759.    
  760. createScrollmenu("standardShop",1,10,26,20,curShopItems,0,curShopItemPrices)
  761.  
  762. end
  763.  
  764.  
  765.  
  766.  
  767.  
  768. -- buttons and all that stuff
  769.  
  770. function betterRead(isBlacklist,filter)
  771. returnInfo = false
  772.  
  773.     if curReading ~= nil then
  774.    
  775.         if readingOutput[curReading] == nil then
  776.         readingOutput[curReading] = ""
  777.         end
  778.    
  779.         if curReadingPosX == nil then
  780.         curReadingPosX = readingPosX+string.len(readingOutput[curReading])
  781.         end
  782.        
  783.        
  784.         if cursorBlinkTimer == nil then
  785.         cursorBlinkTimer = os.startTimer(0.5)
  786.         end
  787.        
  788.  
  789.         if info1 == "char" then
  790.        
  791.         isBlacklisted = not isBlacklist
  792.             for k,v in pairs(filter) do
  793.            
  794.                 if info2 == filter[k] then
  795.                 isBlacklisted = isBlacklist
  796.                 end
  797.            
  798.             end
  799.        
  800.        
  801.             if not isBlacklisted then
  802.                 if readingOutput[curReading] == nil then
  803.                 readingOutput[curReading] = ""
  804.                 end
  805.    
  806.             readingOutput[curReading] = readingOutput[curReading] .. info2
  807.             term.setCursorPos(curReadingPosX,readingPosY)
  808.             term.setBackgroundColor(colors.black)
  809.             term.setTextColor(colors.white)
  810.             term.write(info2)
  811.             curReadingPosX = curReadingPosX+1
  812.        
  813.                 if blinkIsOn then
  814.                 term.write("_")
  815.                 end
  816.            
  817.             returnInfo = true
  818.             end
  819.    
  820.         end
  821.    
  822.    
  823.         if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
  824.    
  825.         curReadingPosX = curReadingPosX-1
  826.         term.setCursorPos(curReadingPosX+1,readingPosY)
  827.         term.setBackgroundColor(colors.black)
  828.         term.write("           ")
  829.         term.setCursorPos(curReadingPosX,readingPosY)
  830.             if blinkIsOn then
  831.             term.write("_")
  832.             else
  833.             term.write(" ")
  834.             end
  835.    
  836.         readSave = readingOutput[curReading]
  837.         readingOutput[curReading] = ""
  838.             for i=1,string.len(readSave)-1 do
  839.             readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
  840.             end
  841.        
  842.         returnInfo = true
  843.         end
  844.        
  845.        
  846.         if info1 == "timer" and info2 == cursorBlinkTimer then
  847.         term.setBackgroundColor(colors.black)
  848.         term.setTextColor(colors.white)
  849.             if blinkIsOn then
  850.             term.setCursorPos(curReadingPosX,readingPosY)
  851.             term.write("_")
  852.             else
  853.             term.setCursorPos(curReadingPosX,readingPosY)
  854.             term.write(" ")
  855.             end
  856.        
  857.         cursorBlinkTimer = os.startTimer(0.5)
  858.         blinkIsOn = (not blinkIsOn)
  859.         end
  860.    
  861.        
  862.     end
  863.  
  864. return returnInfo
  865. end
  866.  
  867.  
  868.  
  869. function changeReading(readingName,xPos,yPos)
  870.     if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
  871.     term.setCursorPos(curReadingPosX,readingPosY)
  872.     term.write(" ")
  873.     end
  874.  
  875. blinkIsOn = true
  876. curReading = readingName
  877. readingPosX = xPos
  878. readingPosY = yPos
  879. curReadingPosX = nil
  880.     if readingOutput[readingName] ~= nil then
  881.     term.setCursorPos(xPos,yPos)
  882.     term.setBackgroundColor(colors.black)
  883.     term.write(readingOutput[readingName])
  884.     end
  885. cursorBlinkTimer = os.startTimer(0.05)
  886.  
  887. end
  888.  
  889.  
  890.  
  891. function stopReading()
  892.  
  893. term.setCursorPos(curReadingPosX,readingPosY)
  894. term.write(" ")
  895. curReading = nil
  896. cursorBlinkTimer = nil
  897.  
  898. end
  899.  
  900.  
  901.  
  902. function resetEvent()
  903. info1 = nil
  904. end
  905.  
  906.  
  907.  
  908. function createScrollmenu(name,x1,y1,x2,y2,content,position,cost)
  909. scrollmenuLen[name]=0
  910. scrollmenuInfos[name]={["x1"]=x1,["y1"]=y1,["x2"]=x2,["y2"]=y2,["content"]=content,["position"]=position,["cost"]=cost}
  911.  
  912.     for k,v in pairs(content) do
  913.         if content[k] ~= nil then
  914.         scrollmenuLen[name]=scrollmenuLen[name]+1
  915.         else
  916.             for i=1,table.maxn(content)-scrollmenuLen[name] do
  917.             content[scrollmenuLen[name]+i] = content[scrollmenuLen[name]+1+i]
  918.             end
  919.         end
  920.     end
  921.  
  922. end
  923.  
  924.  
  925.  
  926. function printScrollmenu(name)
  927. term.setTextColor(colors.white)
  928.  
  929.     for i=1,math.min(scrollmenuLen[name],scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1) do
  930.    
  931.         if (i+scrollmenuInfos[name]["position"])%2==0 then
  932.         term.setBackgroundColor(colors.gray)
  933.         else
  934.         term.setBackgroundColor(colors.black)
  935.         end
  936.        
  937.     term.setCursorPos(scrollmenuInfos[name]["x1"],scrollmenuInfos[name]["y1"]+i-1)
  938.     term.write(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]])
  939.    
  940.         if scrollmenuInfos[name]["cost"] == nil then
  941.             for i2=1,scrollmenuInfos[name]["x2"]-scrollmenuInfos[name]["x1"]+1-string.len(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]]) do
  942.             term.write(" ")
  943.             end
  944.         else
  945.             for i2=1,scrollmenuInfos[name]["x2"]-scrollmenuInfos[name]["x1"]+1-string.len(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]])-string.len(scrollmenuInfos[name]["cost"][i+scrollmenuInfos[name]["position"]]) do
  946.             term.write(" ")
  947.             end
  948.         term.write(scrollmenuInfos[name]["cost"][i+scrollmenuInfos[name]["position"]])
  949.         end
  950.  
  951.     end
  952.  
  953.  
  954.  
  955. end
  956.  
  957.  
  958.  
  959. function checkScrollmenu(name)
  960.  
  961.     if info1 == "mouse_click" and info3 > scrollmenuInfos[name]["x1"]-1 and info3 < scrollmenuInfos[name]["x2"]+1 and info4 > scrollmenuInfos[name]["y1"]-1 and info4 < scrollmenuInfos[name]["y2"]+1 then
  962.     resetEvent()
  963.         if info4-scrollmenuInfos[name]["y1"]+1+scrollmenuInfos[name]["position"] < table.maxn(scrollmenuInfos[name]["content"])+1 then
  964.         return info4-scrollmenuInfos[name]["y1"]+1+scrollmenuInfos[name]["position"]
  965.         end
  966.     end
  967.    
  968.     if info1 == "mouse_scroll" and not (scrollmenuInfos[name]["position"]+info2 > scrollmenuLen[name]-(scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1)) and not (scrollmenuInfos[name]["position"]+info2 < 0) then
  969.     scrollmenuInfos[name]["position"] = scrollmenuInfos[name]["position"] + info2
  970.     printScrollmenu(name)
  971.     end
  972.  
  973. end
  974.  
  975.  
  976.  
  977. function headline(headline)
  978. width = term.getSize()
  979. headline_lenght=string.len("   "..headline.."   ")
  980. headline_pos=(width/2)-(headline_lenght/2)+1
  981. term.setCursorPos(headline_pos,1)
  982. term.setBackgroundColor(colors.yellow)
  983. term.setTextColor(colors.blue)
  984. term.write("   "..headline.."   ")
  985. term.setBackgroundColor(colors.black)
  986. term.setTextColor(colors.white)
  987. end
  988.  
  989.  
  990.  
  991. function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
  992. term.setTextColor(colors.green)
  993.  
  994.   if button_color~=nil then
  995.   term.setTextColor(button_color)
  996.   end
  997.  
  998. square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  999. term.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
  1000. term.write(button_text)
  1001. end
  1002.  
  1003.  
  1004.  
  1005. function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  1006.   if info1=="mouse_click" and info3 > b_check_x1-1 and info3 < b_check_x2+1 and info4 > b_check_y1-1 and info4 < b_check_y2+1 then
  1007.   resetEvent()
  1008.   return true
  1009.   else
  1010.   return false
  1011.   end
  1012. end
  1013.  
  1014.  
  1015.  
  1016. function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  1017. x_1=x1
  1018. y_1=y1
  1019. x_2=x2
  1020. y_2=y2
  1021.   while x_1~=x2+1 do
  1022.   term.setBackgroundColor(back_color_square)
  1023.   term.setCursorPos(x_1,y_1)
  1024.     if text_color~=nil then
  1025.     term.setTextColor(text_color)
  1026.     end
  1027.   term.write(symbol_square_x)
  1028.   x_1=x_1+1
  1029.   end
  1030.  
  1031.   while y_1~=y2-1 do
  1032.   term.setCursorPos(x_1-1,y_1+1)
  1033.   term.write(symbol_square_y)
  1034.   y_1=y_1+1
  1035.   end
  1036. x2=x2-1
  1037.   while x_2~=x1-1 do
  1038.   term.setCursorPos(x_2,y_2)
  1039.   term.write(symbol_square_x)
  1040.   x_2=x_2-1
  1041.   end
  1042.  
  1043.   while y_2~=y1+1 do
  1044.   term.setCursorPos(x_2+1,y_2-1)
  1045.   term.write(symbol_square_y)
  1046.   y_2=y_2-1
  1047.   end
  1048. term.setBackgroundColor(colors.black)
  1049. end
  1050.  
  1051.  
  1052.  
  1053. function overwriteDropdown()
  1054.  
  1055.   for i=1,dropdown["loaded"]["len"] do
  1056.  
  1057.     if not dropdown[dropdown["loaded"][i]]["is_open"] then
  1058.  
  1059.       if info1=="mouse_click" and info3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info4==dropdown[dropdown["loaded"][i]]["pos_y"] then
  1060.       info1 = "dropdown_menu"
  1061.       end
  1062.  
  1063.     else
  1064.  
  1065.       if info1=="mouse_click" and info3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info4 < dropdown[dropdown["loaded"][i]]["pos_y"]+dropdown[dropdown["loaded"][i]]["len"] and info4 > dropdown[dropdown["loaded"][i]]["pos_y"]-1  then
  1066.       info1 = "dropdown_menu"
  1067.       end
  1068.  
  1069.     end
  1070.  
  1071.   end
  1072. end
  1073.  
  1074.  
  1075.  
  1076. function closeDropdownMenus()
  1077. dropdown["loaded"]["len"]=0
  1078. end
  1079.  
  1080.  
  1081.  
  1082. function createDropdownMenu(name,options,pos_x1,pos_y,pos_x2)
  1083.  
  1084. dropdown[name] = {}
  1085. dropdown[name]["pos_x1"] = pos_x1
  1086. dropdown[name]["pos_x2"] = pos_x2
  1087. dropdown[name]["pos_y"] = pos_y
  1088. dropdown[name]["is_open"] = false
  1089. dropdown[name]["len"] = 0
  1090.  
  1091. i=1
  1092.   while options[i]~= nil do
  1093.   dropdown[name]["len"] = dropdown[name]["len"]+1
  1094.   dropdown[name]["option"..i] = options[i]
  1095.   i=i+1
  1096.   end
  1097.  
  1098. end
  1099.  
  1100.  
  1101.  
  1102. function printDropdownMenu(name)
  1103.  
  1104.   for i=1,dropdown[name]["len"] do
  1105.   term.setCursorPos(dropdown[name]["pos_x1"],dropdown[name]["pos_y"]+i-1)
  1106.  
  1107.     if not (i%2==0) then
  1108.     term.setBackgroundColor(colors.gray)
  1109.     term.setTextColor(colors.white)
  1110.     else
  1111.     term.setBackgroundColor(colors.lightGray)
  1112.     term.setTextColor(colors.black)
  1113.     end
  1114.  
  1115.     if dropdown[name]["is_open"] or i==1 then
  1116.     term.write(dropdown[name]["option"..i])
  1117.       for i1=1,(dropdown[name]["pos_x2"]-dropdown[name]["pos_x1"])-string.len(dropdown[name]["option"..i])+1 do
  1118.       term.write(" ")
  1119.       end
  1120.     end
  1121.   end
  1122.  
  1123. term.setBackgroundColor(colors.black)
  1124. term.setTextColor(colors.white)
  1125. end
  1126.  
  1127.  
  1128.  
  1129. function dropdownMenuCheck(name)
  1130.  
  1131.   if dropdown[name]["is_open"] then
  1132.  
  1133.     if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4==dropdown[name]["pos_y"] then
  1134.     dropdown[name]["is_open"]=false
  1135.     printMenu(curEnv)
  1136.     return "closed"
  1137.     end
  1138.    
  1139.     if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4 < dropdown[name]["pos_y"]+dropdown[name]["len"]+1 and info4 > dropdown[name]["pos_y"] then
  1140.     option_save = dropdown[name]["option"..1]
  1141.     dropdown[name]["option"..1] = dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1]
  1142.     dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1] = option_save
  1143.     dropdown[name]["is_open"]=false
  1144.     printMenu(curEnv)
  1145.     return "changed"
  1146.     end
  1147.  
  1148.   else
  1149.  
  1150.     if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4==dropdown[name]["pos_y"] then
  1151.     dropdown[name]["is_open"]=true
  1152.     printDropdownMenu(name)
  1153.     return "opened"
  1154.     end
  1155.  
  1156.   end
  1157.  
  1158. end
  1159.  
  1160.  
  1161.  
  1162. function loadDropdownMenu(name)
  1163. dropdown["loaded"]["len"] = dropdown["loaded"]["len"]+1
  1164. dropdown["loaded"][dropdown["loaded"]["len"]] = name
  1165. printDropdownMenu(name)
  1166. end
  1167.  
  1168.  
  1169.  
  1170. function printMenu(env)
  1171.  
  1172. blub = load(env)
  1173.  
  1174. end
  1175.  
  1176.  
  1177.  
  1178. function filledSquare(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
  1179. term.setBackgroundColor(fill_color)
  1180. curr_fill_pos_x=fill_x1
  1181. curr_fill_pos_y=fill_y1
  1182.   while curr_fill_pos_y~=fill_y2+1 do
  1183.     while curr_fill_pos_x~=fill_x2+1 do
  1184.     term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
  1185.     term.write(" ")
  1186.     curr_fill_pos_x=curr_fill_pos_x+1
  1187.     end
  1188.   curr_fill_pos_x=fill_x1
  1189.   curr_fill_pos_y=curr_fill_pos_y+1
  1190.   end
  1191. term.setBackgroundColor(colors.black)
  1192. end
  1193.  
  1194.  
  1195.  
  1196. function lineCheck(y)
  1197.  
  1198.     if info1 == "mouse_click" and info4 == y then
  1199.     return true
  1200.     else
  1201.     return false
  1202.     end
  1203.  
  1204. end
  1205.  
  1206. -------------------------------------------------
  1207.  
  1208.  
  1209.  
  1210.  
  1211. startup()
  1212. homeMenu()
  1213. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement