Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- sleep(1)
- for k,v in pairs(peripheral.getNames()) do
- if peripheral.getType(peripheral.getNames()[k]) == "modem" then
- rednet.open(peripheral.getNames()[k])
- end
- end
- shopComputerId = 968
- if fs.exists("password") then
- file = fs.open("password","r")
- password = file.readAll()
- file.close()
- fs.delete("password")
- rednet.send(shopComputerId,{["action"]="newPocket",["password"]=password})
- end
- readingOutput = {}
- blinkIsOn = true
- scrollmenuLen={}
- scrollmenuInfos={}
- dropdown = {}
- dropdown["loaded"] = {}
- dropdown["loaded"]["len"] = 0
- shopItems = getItems()
- shopItemNumbers = {}
- shopItemNames = {}
- itemCost = {}
- for k,v in pairs(shopItems) do
- shopItemNames[k] = shopItems[k]["name"]
- itemCost[k] = shopItems[k]["price"] .. "c"
- shopItemNumbers[shopItems[k]["name"]] = k
- end
- cartContent = {}
- cartContentPrices = {}
- totalPrice = 0
- chestIDs = {972}
- cart = {}
- createScrollmenu("cartContent",1,10,26,20,cartContent,0)
- createScrollmenu("standardShop",1,10,26,20,shopItemNames,0,itemCost)
- end
- function main()
- while true do
- info1,info2,info3,info4 = os.pullEventRaw()
- overwriteDropdown()
- if info1 == "rednet_message" and info2 == shopComputerId then
- if type(info3) == "table" then
- if info3["action"] == "paid" then
- pay(info3["amount"])
- end
- if info3["action"] == "orderIsDone" then
- thanksMenu()
- end
- end
- end
- if info1 == "timer" and info2 == reduceTimeTimer then
- timeLeft = timeLeft-1
- if curEnvName == "payMenu" or curEnvName == "areYouSureMenu" then
- if timeLeft > 59 then
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- if timeLeft-60 > 9 then
- headline("1:" .. timeLeft-60)
- else
- headline("1:0" .. timeLeft-60)
- end
- reduceTimeTimer = os.startTimer(1)
- elseif timeLeft > 0 then
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- if timeLeft > 9 then
- headline("0:" .. timeLeft)
- else
- headline("0:0" .. timeLeft)
- end
- reduceTimeTimer = os.startTimer(1)
- else
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.red)
- print("Your order was canceled due to inactivity.")
- amountPaid = 0
- sleep(3)
- cartMenu()
- end
- end
- end
- if curEnvName == "areYouSureMenu" then
- if buttonCheck(4,8,12,10) then
- rednet.send(shopComputerId,{["action"]="canceledOrder"})
- cartMenu()
- end
- if buttonCheck(15,8,22,10) then
- payMenu()
- end
- end
- if curEnvName == "homeMenu" then
- if buttonCheck(10,4,17,6) then
- shopMenu()
- end
- if buttonCheck(10,7,17,9) then
- cartMenu()
- end
- end
- if curEnvName == "payMenu" then
- if buttonCheck(19,18,26,20) then
- if amountPaid == 0 then
- rednet.send(shopComputerId,{["action"]="canceledOrder"})
- cartMenu()
- else
- areYouSureMenu()
- end
- end
- end
- if curEnvName == "cartMenu" then
- scrollmenuOut = checkScrollmenu("cartContent")
- if buttonCheck(21,6,26,8) then
- homeMenu()
- end
- if buttonCheck(1,6,5,8) and totalPrice > 0 then
- addOrder()
- payMenu()
- end
- if scrollmenuOut ~= nil then
- end
- end
- if curEnvName == "shopMenu" then
- scrollmenuOut = checkScrollmenu("standardShop")
- if buttonCheck(21,6,26,8) then
- stopReading()
- homeMenu()
- end
- if scrollmenuOut ~= nil then
- buyMenu(scrollmenuOut)
- end
- if betterRead(true,{}) then
- search()
- filledSquare(1,10,26,20,colors.black)
- printScrollmenu("standardShop")
- end
- end
- if curEnvName == "buyMenu" then
- if buttonCheck(21,18,26,20) then
- shopMenu()
- end
- if buttonCheck(21,9,26,11) then
- updateBuyMenu(1)
- end
- if buttonCheck(21,6,26,8) then
- updateBuyMenu(10)
- end
- if buttonCheck(21,3,26,5) then
- updateBuyMenu(100)
- end
- if buttonCheck(1,9,6,11) then
- updateBuyMenu(-1)
- end
- if buttonCheck(1,6,6,8) then
- updateBuyMenu(-10)
- end
- if buttonCheck(1,3,6,5) then
- updateBuyMenu(-100)
- end
- if buttonCheck(1,18,13,20) then
- addToCart()
- shopMenu()
- end
- end
- end
- end
- function addOrder()
- amountPaid = 0
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting for main computer to respond\n")
- term.setTextColor(colors.green)
- term.write("Info: ")
- term.setTextColor(colors.white)
- print("You need to be in the market for this to work.")
- term.setTextColor(colors.green)
- rednet.send(shopComputerId,{["action"]="newOrder",["order"]={["cartInfo"]=cart,["content"]=scrollmenuInfos["cartContent"]["content"],["price"]=totalPrice,["id"]=os.getComputerID()}})
- dotCount = 0
- rightMessage = false
- repeat
- timer = os.startTimer(0.5)
- info1,info2,info3,info4 = os.pullEventRaw()
- os.cancelTimer(timer)
- if info1 == "timer" and info2 == timer then
- if dotCount < 3 then
- dotCount = dotCount+1
- term.setCursorPos(10+dotCount,2)
- term.write(". ")
- else
- dotCount = 0
- term.setCursorPos(11,2)
- term.write(" ")
- end
- rednet.send(shopComputerId,{["action"]="newOrder",["order"]={["cartInfo"]=cart,["content"]=scrollmenuInfos["cartContent"]["content"],["price"]=totalPrice,["id"]=os.getComputerID()}})
- end
- if type(info3) == "table" then
- if info3["action"] == "listedOrder" then
- rightMessage = true
- end
- end
- until info1 == "rednet_message" and info2 == shopComputerId and rightMessage
- term.setTextColor(colors.red)
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting to reach end of queue\n")
- term.setTextColor(colors.green)
- term.write("Position in queue: ")
- term.setTextColor(colors.white)
- print(info3["orderPos"].."\n")
- term.setTextColor(colors.green)
- term.write("Info: ")
- term.setTextColor(colors.white)
- print("There is currently a different order being processed, this should at")
- term.write("most take ")
- term.setTextColor(colors.green)
- term.write(1.5*(info3["orderPos"]-1))
- term.write(" minutes.")
- term.setTextColor(colors.white)
- print(" If this takes longer please inform me when im online (Chaos_Chash) or on Discord (SeNN/Chaos_Cash).")
- term.setTextColor(colors.green)
- while info3["orderPos"] > 1 do
- dotCount = 0
- rightMessage = false
- repeat
- timer = os.startTimer(0.5)
- info1,info2,info3,info4 = os.pullEventRaw()
- os.cancelTimer(timer)
- if info1 == "timer" and info2 == timer then
- if dotCount < 3 then
- dotCount = dotCount+1
- term.setCursorPos(5+dotCount,2)
- term.write(". ")
- else
- dotCount = 0
- term.setCursorPos(6,2)
- term.write(" ")
- end
- end
- if type(info3) == "table" then
- if info3["action"] == "changedOrder" then
- rightMessage = true
- end
- end
- until info1 == "rednet_message" and info2 == shopComputerId and rightMessage
- end
- timeLeft = 90
- reduceTimeTimer = os.startTimer(1)
- end
- function areYouSureMenu()
- curEnv = areYouSureMenu
- curEnvName = "areYouSureMenu"
- term.setBackgroundColor(colors.black)
- term.clear()
- if timeLeft > 59 then
- if timeLeft-60 > 9 then
- headline("1:" .. timeLeft-60)
- else
- headline("1:0" .. timeLeft-60)
- end
- elseif timeLeft > 0 then
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- if timeLeft > 9 then
- headline("0:" .. timeLeft)
- else
- headline("0:0" .. timeLeft)
- end
- end
- term.setCursorPos(1,3)
- term.setTextColor(colors.red)
- print("Are you sure? If you cancel your order everything you paid will get lost.")
- button("Confirm",4,8,12,10)
- button("Deny",15,8,22,10,colors.red)
- end
- function thanksMenu()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.green)
- print("Thank you for your purchase.")
- cart = {}
- cartContent = {}
- cartContentPrices = {}
- createScrollmenu("cartContent",1,10,26,20,cartContent,0,cartContentPrices)
- totalPrice = 0
- amountPaid = 0
- sleep(3)
- homeMenu()
- end
- function pay(amount)
- amountPaid = amountPaid+amount
- term.setCursorPos(7,5)
- term.setTextColor(colors.white)
- print(amountPaid)
- term.setCursorPos(12,6)
- term.setTextColor(colors.white)
- print(totalPrice-amountPaid.." ")
- end
- function payMenu()
- curEnv = payMenu
- curEnvName = "payMenu"
- term.clear()
- if timeLeft > 59 then
- if timeLeft-60 > 9 then
- headline("1:" .. timeLeft-60)
- else
- headline("1:0" .. timeLeft-60)
- end
- elseif timeLeft > 0 then
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- if timeLeft > 9 then
- headline("0:" .. timeLeft)
- else
- headline("0:0" .. timeLeft)
- end
- end
- button("Cancel",19,18,26,20,colors.red)
- term.setCursorPos(1,4)
- term.setTextColor(colors.green)
- term.write("Price: ")
- term.setTextColor(colors.white)
- print(totalPrice)
- term.setTextColor(colors.green)
- term.write("Paid: ")
- term.setTextColor(colors.white)
- print(amountPaid)
- term.setTextColor(colors.green)
- term.write("Remaining: ")
- term.setTextColor(colors.white)
- print(totalPrice-amountPaid)
- end
- function cartMenu()
- curEnv = cartMenu
- curEnvName = "cartMenu"
- term.clear()
- headline("Cart")
- button("Back",21,6,26,8)
- if totalPrice > 0 then
- button("Buy",1,6,5,8)
- else
- button("Buy",1,6,5,8,colors.red)
- end
- printScrollmenu("cartContent")
- end
- function addToCart()
- table.insert(cartContent,buyAmount .. "x " .. curItem)
- table.insert(cartContentPrices,shopItems[shopItemNumbers[curItem]]["price"]*buyAmount.."c")
- createScrollmenu("cartContent",1,10,26,20,cartContent,scrollmenuInfos["cartContent"]["position"],cartContentPrices)
- totalPrice = totalPrice+(shopItems[shopItemNumbers[curItem]]["price"]*buyAmount)
- table.insert(cart,{["slot"]=shopItems[curItemNumber]["slot"],["chest"]=shopItems[curItemNumber]["chest"],["amount"]=buyAmount})
- end
- function updateBuyMenu(change)
- if buyAmount + change > 0 then
- if buyAmount + change < amountInStorage+1 then
- buyAmount = buyAmount + change
- else
- buyAmount = amountInStorage
- end
- term.setTextColor(colors.white)
- term.setCursorPos(9,15)
- term.write(buyAmount .. " ")
- term.setCursorPos(8,16)
- term.write((shopItems[shopItemNumbers[curItem]]["price"]*buyAmount) .. "c ")
- elseif amountInStorage > 0 then
- buyAmount = 1
- term.setTextColor(colors.white)
- term.setCursorPos(9,15)
- term.write(buyAmount .. " ")
- term.setCursorPos(8,16)
- term.write((shopItems[shopItemNumbers[curItem]]["price"]*buyAmount) .. "c ")
- end
- end
- function homeMenu()
- curEnv = homeMenu
- curEnvName = "homeMenu"
- term.setBackgroundColor(colors.black)
- term.clear()
- headline("Home")
- button("Shop",10,4,17,6)
- button("Cart",10,7,17,9)
- end
- function shopMenu()
- curEnv = shopMenu
- curEnvName = "shopMenu"
- term.clear()
- headline("Shop")
- button("Back",21,6,26,8)
- term.setCursorPos(1,9)
- term.setTextColor(colors.green)
- term.write("Search: ")
- printScrollmenu("standardShop")
- changeReading("shopSearch",9,9)
- end
- function buyMenu(item)
- if item ~= nil then
- curItem = scrollmenuInfos["standardShop"]["content"][item]
- curItemNumber = shopItemNumbers[scrollmenuInfos["standardShop"]["content"][item]]
- end
- amountInStorage = getItemCount(shopItemNumbers[curItem])
- curEnv = buyMenu
- curEnvName = "buyMenu"
- term.setBackgroundColor(colors.black)
- term.clear()
- headline(curItem)
- button("Back",21,18,26,20)
- button("Add to cart",1,18,13,20)
- button("-100",1,3,6,5,colors.red)
- button("-10",1,6,6,8,colors.red)
- button("-1",1,9,6,11,colors.red)
- button("+100",21,3,26,5)
- button("+10",21,6,26,8)
- button("+1",21,9,26,11)
- term.setCursorPos(1,13)
- term.setTextColor(colors.green)
- term.write("Item: ")
- term.setTextColor(colors.white)
- term.write(curItem)
- term.setCursorPos(1,14)
- term.setTextColor(colors.green)
- term.write("Storage: ")
- term.setTextColor(colors.white)
- term.write(amountInStorage)
- if amountInStorage > 0 then
- buyAmount = 1
- else
- buyAmount = 0
- end
- term.setCursorPos(1,15)
- term.setTextColor(colors.green)
- term.write("Amount: ")
- term.setTextColor(colors.white)
- term.write(buyAmount)
- term.setCursorPos(1,16)
- term.setTextColor(colors.green)
- term.write("Price: ")
- term.setTextColor(colors.white)
- term.write((shopItems[shopItemNumbers[curItem]]["price"]*buyAmount).."c")
- end
- function getItemCount(item)
- rednet.send(chestIDs[shopItems[item]["chest"]],{["action"]="getItemCount",["item"]=shopItems[item]["slot"]})
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting for main computer to respond\n")
- term.setTextColor(colors.green)
- term.write("Info: ")
- term.setTextColor(colors.white)
- print("You need to be in the market for this to work.")
- term.setTextColor(colors.green)
- dotCount = 0
- rightMessage = false
- rednet.send(chestIDs[shopItems[item]["chest"]],{["action"]="getItemCount",["item"]=shopItems[item]["slot"]})
- repeat
- timer = os.startTimer(0.5)
- info1,info2,info3,info4 = os.pullEventRaw()
- os.cancelTimer(timer)
- if info1 == "timer" and info2 == timer then
- if dotCount < 3 then
- dotCount = dotCount+1
- term.setCursorPos(10+dotCount,2)
- term.write(". ")
- else
- dotCount = 0
- term.setCursorPos(11,2)
- term.write(" ")
- end
- rednet.send(chestIDs[shopItems[item]["chest"]],{["action"]="getItemCount",["item"]=shopItems[item]["slot"]})
- end
- if type(info3) == "table" then
- if info3["action"] == "sendingItemCount" then
- rightMessage = true
- end
- end
- until info1 == "rednet_message" and info2 == chestIDs[shopItems[item]["chest"]] and rightMessage
- return info3["itemCount"]
- end
- function getItems()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting for main computer to respond\n")
- term.setTextColor(colors.green)
- term.write("Info: ")
- term.setTextColor(colors.white)
- print("You need to be in the market for this to work.")
- term.setTextColor(colors.green)
- dotCount = 0
- rightMessage = false
- rednet.send(shopComputerId,{["action"]="getItems"})
- repeat
- timer = os.startTimer(0.5)
- info1,info2,info3,info4 = os.pullEventRaw()
- os.cancelTimer(timer)
- if info1 == "timer" and info2 == timer then
- if dotCount < 3 then
- dotCount = dotCount+1
- term.setCursorPos(10+dotCount,2)
- term.write(". ")
- else
- dotCount = 0
- term.setCursorPos(11,2)
- term.write(" ")
- end
- rednet.send(shopComputerId,{["action"]="getItems"})
- end
- if type(info3) == "table" then
- if info3["action"] == "sendingItems" then
- rightMessage = true
- end
- end
- until info1 == "rednet_message" and info2 == shopComputerId and rightMessage
- return info3["items"]
- end
- function search()
- curShopItems = {}
- curShopItemPrices = {}
- for k,v in pairs(shopItemNames) do
- if string.find(string.lower(shopItemNames[k]),string.lower(readingOutput["shopSearch"])) ~= nil then
- curShopItems[table.maxn(curShopItems)+1] = shopItemNames[k]
- curShopItemPrices[table.maxn(curShopItems)] = shopItems[k]["price"]
- end
- end
- createScrollmenu("standardShop",1,10,26,20,curShopItems,0,curShopItemPrices)
- end
- -- buttons and all that stuff
- function betterRead(isBlacklist,filter)
- returnInfo = false
- if curReading ~= nil then
- if readingOutput[curReading] == nil then
- readingOutput[curReading] = ""
- end
- if curReadingPosX == nil then
- curReadingPosX = readingPosX+string.len(readingOutput[curReading])
- end
- if cursorBlinkTimer == nil then
- cursorBlinkTimer = os.startTimer(0.5)
- end
- if info1 == "char" then
- isBlacklisted = not isBlacklist
- for k,v in pairs(filter) do
- if info2 == filter[k] then
- isBlacklisted = isBlacklist
- end
- end
- if not isBlacklisted then
- if readingOutput[curReading] == nil then
- readingOutput[curReading] = ""
- end
- readingOutput[curReading] = readingOutput[curReading] .. info2
- term.setCursorPos(curReadingPosX,readingPosY)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.write(info2)
- curReadingPosX = curReadingPosX+1
- if blinkIsOn then
- term.write("_")
- end
- returnInfo = true
- end
- end
- if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
- curReadingPosX = curReadingPosX-1
- term.setCursorPos(curReadingPosX+1,readingPosY)
- term.setBackgroundColor(colors.black)
- term.write(" ")
- term.setCursorPos(curReadingPosX,readingPosY)
- if blinkIsOn then
- term.write("_")
- else
- term.write(" ")
- end
- readSave = readingOutput[curReading]
- readingOutput[curReading] = ""
- for i=1,string.len(readSave)-1 do
- readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
- end
- returnInfo = true
- end
- if info1 == "timer" and info2 == cursorBlinkTimer then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- if blinkIsOn then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write("_")
- else
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- cursorBlinkTimer = os.startTimer(0.5)
- blinkIsOn = (not blinkIsOn)
- end
- end
- return returnInfo
- end
- function changeReading(readingName,xPos,yPos)
- if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- blinkIsOn = true
- curReading = readingName
- readingPosX = xPos
- readingPosY = yPos
- curReadingPosX = nil
- if readingOutput[readingName] ~= nil then
- term.setCursorPos(xPos,yPos)
- term.setBackgroundColor(colors.black)
- term.write(readingOutput[readingName])
- end
- cursorBlinkTimer = os.startTimer(0.05)
- end
- function stopReading()
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- curReading = nil
- cursorBlinkTimer = nil
- end
- function resetEvent()
- info1 = nil
- end
- function createScrollmenu(name,x1,y1,x2,y2,content,position,cost)
- scrollmenuLen[name]=0
- scrollmenuInfos[name]={["x1"]=x1,["y1"]=y1,["x2"]=x2,["y2"]=y2,["content"]=content,["position"]=position,["cost"]=cost}
- for k,v in pairs(content) do
- if content[k] ~= nil then
- scrollmenuLen[name]=scrollmenuLen[name]+1
- else
- for i=1,table.maxn(content)-scrollmenuLen[name] do
- content[scrollmenuLen[name]+i] = content[scrollmenuLen[name]+1+i]
- end
- end
- end
- end
- function printScrollmenu(name)
- term.setTextColor(colors.white)
- for i=1,math.min(scrollmenuLen[name],scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1) do
- if (i+scrollmenuInfos[name]["position"])%2==0 then
- term.setBackgroundColor(colors.gray)
- else
- term.setBackgroundColor(colors.black)
- end
- term.setCursorPos(scrollmenuInfos[name]["x1"],scrollmenuInfos[name]["y1"]+i-1)
- term.write(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]])
- if scrollmenuInfos[name]["cost"] == nil then
- for i2=1,scrollmenuInfos[name]["x2"]-scrollmenuInfos[name]["x1"]+1-string.len(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]]) do
- term.write(" ")
- end
- else
- 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
- term.write(" ")
- end
- term.write(scrollmenuInfos[name]["cost"][i+scrollmenuInfos[name]["position"]])
- end
- end
- end
- function checkScrollmenu(name)
- 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
- resetEvent()
- if info4-scrollmenuInfos[name]["y1"]+1+scrollmenuInfos[name]["position"] < table.maxn(scrollmenuInfos[name]["content"])+1 then
- return info4-scrollmenuInfos[name]["y1"]+1+scrollmenuInfos[name]["position"]
- end
- end
- 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
- scrollmenuInfos[name]["position"] = scrollmenuInfos[name]["position"] + info2
- printScrollmenu(name)
- end
- end
- function headline(headline)
- width = term.getSize()
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=(width/2)-(headline_lenght/2)+1
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- term.setTextColor(colors.green)
- if button_color~=nil then
- term.setTextColor(button_color)
- end
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- 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)
- term.write(button_text)
- end
- function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- 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
- resetEvent()
- return true
- else
- return false
- end
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- function overwriteDropdown()
- for i=1,dropdown["loaded"]["len"] do
- if not dropdown[dropdown["loaded"][i]]["is_open"] then
- 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
- info1 = "dropdown_menu"
- end
- else
- 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
- info1 = "dropdown_menu"
- end
- end
- end
- end
- function closeDropdownMenus()
- dropdown["loaded"]["len"]=0
- end
- function createDropdownMenu(name,options,pos_x1,pos_y,pos_x2)
- dropdown[name] = {}
- dropdown[name]["pos_x1"] = pos_x1
- dropdown[name]["pos_x2"] = pos_x2
- dropdown[name]["pos_y"] = pos_y
- dropdown[name]["is_open"] = false
- dropdown[name]["len"] = 0
- i=1
- while options[i]~= nil do
- dropdown[name]["len"] = dropdown[name]["len"]+1
- dropdown[name]["option"..i] = options[i]
- i=i+1
- end
- end
- function printDropdownMenu(name)
- for i=1,dropdown[name]["len"] do
- term.setCursorPos(dropdown[name]["pos_x1"],dropdown[name]["pos_y"]+i-1)
- if not (i%2==0) then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- else
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- end
- if dropdown[name]["is_open"] or i==1 then
- term.write(dropdown[name]["option"..i])
- for i1=1,(dropdown[name]["pos_x2"]-dropdown[name]["pos_x1"])-string.len(dropdown[name]["option"..i])+1 do
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function dropdownMenuCheck(name)
- if dropdown[name]["is_open"] then
- 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
- dropdown[name]["is_open"]=false
- printMenu(curEnv)
- return "closed"
- end
- 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
- option_save = dropdown[name]["option"..1]
- dropdown[name]["option"..1] = dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1]
- dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1] = option_save
- dropdown[name]["is_open"]=false
- printMenu(curEnv)
- return "changed"
- end
- else
- 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
- dropdown[name]["is_open"]=true
- printDropdownMenu(name)
- return "opened"
- end
- end
- end
- function loadDropdownMenu(name)
- dropdown["loaded"]["len"] = dropdown["loaded"]["len"]+1
- dropdown["loaded"][dropdown["loaded"]["len"]] = name
- printDropdownMenu(name)
- end
- function printMenu(env)
- blub = load(env)
- end
- function filledSquare(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
- term.setBackgroundColor(fill_color)
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=fill_y1
- while curr_fill_pos_y~=fill_y2+1 do
- while curr_fill_pos_x~=fill_x2+1 do
- term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
- term.write(" ")
- curr_fill_pos_x=curr_fill_pos_x+1
- end
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=curr_fill_pos_y+1
- end
- term.setBackgroundColor(colors.black)
- end
- function lineCheck(y)
- if info1 == "mouse_click" and info4 == y then
- return true
- else
- return false
- end
- end
- -------------------------------------------------
- startup()
- homeMenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement