Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --load list
- local file = fs.open("itemlist","r")
- local ilist = file.readAll()
- file.close()
- list = textutils.unserialise(ilist)
- serverAdress = "hxc1bf1744b72771683e8b4956"
- baseURL = "hexdev.ddnss.de/hexcoin/api/"
- --for key,val in pairs(list) do
- --print(key.." | "..val)
- --end
- function log(text)
- m = peripheral.wrap("right")
- m.setCommand("msg scopeFX "..text)
- m.runCommand()
- end
- --screen settings
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- x,y = term.getSize()
- doGrey = false
- for i=1,y do
- if doGray then
- doGray = false
- paintutils.drawLine(1,i,x,i,colors.lightGray)
- else
- doGray = true
- paintutils.drawLine(1,i,x,i,colors.white)
- end
- end
- --print item list on screen
- counter = 1
- xoffset = 0
- yoffset = 0
- local buttons = {}
- local itembuttons = {}
- doGray = false
- for key,val in pairs(list) do
- local tempList = {}
- term.setCursorPos(1+xoffset,counter+yoffset)
- term.setTextColor(colors.black)
- if doGray then
- doGray = false
- term.setBackgroundColor(colors.lightGray)
- else
- doGray = true
- term.setBackgroundColor(colors.white)
- end
- term.write(key)
- term.setCursorPos(25+xoffset,counter+yoffset)
- term.write(val)
- term.setCursorPos(31+xoffset,counter+yoffset)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.green)
- tx,ty = term.getCursorPos()
- term.write("buy"..ty)
- tempList = {31+xoffset,ty+yoffset,33+xoffset,ty+yoffset,key,val}
- table.insert(itembuttons,tempList)
- counter = counter+1
- end
- function amount()
- amount = 0
- amountPrefix = "x"
- payScreen = false
- --amount screen
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- local s = selection["item"]
- sx,sy = term.getSize()
- local temp = sy/4
- term.setCursorPos(sx/2-#s/2,sy/2-temp)
- term.write(s)
- tx,ty = term.getCursorPos()
- s = "how much do you want?"
- term.setCursorPos(sx/2-#s/2,ty+2)
- term.write(s)
- term.setCursorPos(sx/2,sy/2)
- --middlepixel paintutils.drawPixel(sx/2,sy/2,colors.black)
- --event,side,x,y = os.pullEvent("monitor_touch")
- buttons = {}
- table.insert(buttons,{"-1",21,22,colors.red,colors.white})
- table.insert(buttons,{"-10",16,18,colors.red,colors.red,colors.white})
- table.insert(buttons,{"-64",11,13,colors.red,colors.white})
- table.insert(buttons,{"1",28,29,colors.green,colors.white})
- table.insert(buttons,{"10",32,34,colors.green,colors.white})
- table.insert(buttons,{"64",37,39,colors.green,colors.white})
- --draw buttons
- --print(textutils.serialise(buttons))
- sx,sy = term.getSize()
- textY = sy/2
- modY = textY % 1
- if modY == 0 then
- --all gud
- else
- textY = textY-0.5
- end
- confirmbtn = {15,11,21,11}
- cancelbtn = {29,11,34,11}
- mX, mY = term.getSize()
- mX = mX/2
- mY = mY/2
- amountX = mX - #tostring(amountPrefix..amount)/2
- amountY = mY+2
- term.setCursorPos(amountX,amountY)
- term.setTextColor(colors.blue)
- term.setBackgroundColor(colors.white)
- if payScreen == true then
- term.write(amountPrefix..tostring(amount))
- end
- for i=1,#buttons do
- --print("button nr: "..i.." | "..buttons[i][1])
- tx = buttons[i][2]
- tx2 = buttons[i][3]
- sx,sy = term.getSize()
- mY = sy/2
- paintutils.drawLine(tx,mY,tx2,mY,buttons[i][4])
- term.setCursorPos(tx,mY)
- prefix = ""
- text = buttons[i][1]
- num = tonumber(text)
- if num >= 0 then
- prefix = "+"
- end
- term.write(prefix..text)
- end
- term.setCursorPos(sx/2-10,sy/2+2)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.black)
- term.write("Confirm")
- term.setCursorPos(sx/2+4,sy/2+2)
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- term.write("Cancel")
- local amountSelect = true
- --increase/decrase touch events listen
- payScreen = false
- while amountSelect do
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- event,side,x,y = os.pullEvent("monitor_touch")
- curbtn = 0
- for i=1,#buttons do
- if x >= buttons[i][2] and x <= buttons[i][3] and y == textY then
- amount = amount + tonumber(buttons[i][1])
- if amount < 0 then
- amount = 0
- end
- if amount > 64 then
- amount = 64
- end
- end
- if x >= cancelbtn[1] and x <= cancelbtn[3] and y == cancelbtn[2] then
- shell.run("monitor top shop")
- end
- if x >= confirmbtn[1] and x <= confirmbtn[3] and y == confirmbtn[2] then
- payScreen = true
- amountSelect = false
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- mX,mY = term.getSize()
- mX = mX/2
- mY = mY/2
- coinsToPay = amount * tonumber(selection["value"])
- s = "Please pay "..coinsToPay.." coins"
- term.clear()
- term.setCursorPos(mX-#s/2,mY-3)
- term.write(s)
- s = "to the following adress:"
- term.setCursorPos(mX-#s/2,mY-2)
- term.write(s)
- term.setCursorPos(mX-#serverAdress/2,mY)
- term.write(serverAdress)
- term.setCursorPos(sx/2-10,sy/2+2)
- term.setBackgroundColor(colors.green)
- term.setTextColor(colors.black)
- term.write("Confirm")
- term.setCursorPos(sx/2+4,sy/2+2)
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- term.write("Cancel")
- event,side,x,y = os.pullEvent("monitor_touch")
- if x >= confirmbtn[1] and x <= confirmbtn[3] and y == confirmbtn[2] then
- curTime = http.get(baseURL.."getUnixTimestamp.php").readAll()
- tTime = curTime + 120
- curTime = http.get(baseURL.."unixToDatetime.php?timestamp="..tTime).readAll()
- futTime = http.get(baseURL.."unixToDatetime.php?timestamp="..tTime).readAll()
- url = baseURL.."checktxn.php?fromdate="..curTime.."&todate="..futTime.."&toadress="..serverAdress.."&amount="..coinsToPay
- log(url)
- txndata = http.get(url).readAll()
- log(txndata)
- end
- if x >= cancelbtn[1] and x <= cancelbtn[3] and y == cancelbtn[2] then
- shell.run("monitor top shop")
- end
- break
- end
- end
- term.setCursorPos(amountX,amountY)
- term.setTextColor(colors.blue)
- term.setBackgroundColor(colors.white)
- if payScreen == true then
- term.write(amountPrefix..tostring(amount).." ")
- end
- end
- end
- --listen for touch events
- event,side,x,y = os.pullEvent("monitor_touch")
- selection = {}
- for i=1,#itembuttons do
- if x >= itembuttons[i][1] and x <= itembuttons[i][3] and y >= itembuttons[i][2] and y <= itembuttons[i][4] then
- selection["item"] = itembuttons[i][5]
- selection["value"] = itembuttons[i][6]
- break
- end
- --[[
- print("")
- print(itembuttons[i][1])
- print(itembuttons[i][2])
- print(itembuttons[i][3])
- print(itembuttons[i][4])
- print(itembuttons[i][5])
- print(itembuttons[i][6])
- print("-----")
- print(x)
- print(y)
- ]]--
- end
- amount()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement