Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.88 KB | None | 0 0
  1. --load list
  2. local file = fs.open("itemlist","r")
  3. local ilist = file.readAll()
  4. file.close()
  5. list = textutils.unserialise(ilist)
  6. serverAdress = "hxc1bf1744b72771683e8b4956"
  7. baseURL = "hexdev.ddnss.de/hexcoin/api/"
  8. --for key,val in pairs(list) do
  9. --print(key.." | "..val)
  10. --end
  11.  
  12. function log(text)
  13. m = peripheral.wrap("right")
  14. m.setCommand("msg scopeFX "..text)
  15. m.runCommand()
  16. end
  17.  
  18. --screen settings
  19. term.setBackgroundColor(colors.white)
  20. term.setTextColor(colors.black)
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. x,y = term.getSize()
  24. doGrey = false
  25. for i=1,y do
  26. if doGray then
  27. doGray = false
  28. paintutils.drawLine(1,i,x,i,colors.lightGray)
  29. else
  30. doGray = true
  31. paintutils.drawLine(1,i,x,i,colors.white)
  32. end
  33. end
  34.  
  35. --print item list on screen
  36. counter = 1
  37. xoffset = 0
  38. yoffset = 0
  39.  
  40. local buttons = {}
  41. local itembuttons = {}
  42. doGray = false
  43. for key,val in pairs(list) do
  44. local tempList = {}
  45. term.setCursorPos(1+xoffset,counter+yoffset)
  46. term.setTextColor(colors.black)
  47. if doGray then
  48. doGray = false
  49. term.setBackgroundColor(colors.lightGray)
  50. else
  51. doGray = true
  52. term.setBackgroundColor(colors.white)
  53. end
  54. term.write(key)
  55. term.setCursorPos(25+xoffset,counter+yoffset)
  56. term.write(val)
  57. term.setCursorPos(31+xoffset,counter+yoffset)
  58. term.setTextColor(colors.black)
  59. term.setBackgroundColor(colors.green)
  60. tx,ty = term.getCursorPos()
  61. term.write("buy"..ty)
  62. tempList = {31+xoffset,ty+yoffset,33+xoffset,ty+yoffset,key,val}
  63. table.insert(itembuttons,tempList)
  64. counter = counter+1
  65. end
  66.  
  67. function amount()
  68. amount = 0
  69. amountPrefix = "x"
  70. payScreen = false
  71. --amount screen
  72. term.setBackgroundColor(colors.white)
  73. term.setTextColor(colors.black)
  74. term.clear()
  75. local s = selection["item"]
  76. sx,sy = term.getSize()
  77. local temp = sy/4
  78. term.setCursorPos(sx/2-#s/2,sy/2-temp)
  79. term.write(s)
  80. tx,ty = term.getCursorPos()
  81. s = "how much do you want?"
  82. term.setCursorPos(sx/2-#s/2,ty+2)
  83. term.write(s)
  84. term.setCursorPos(sx/2,sy/2)
  85. --middlepixel paintutils.drawPixel(sx/2,sy/2,colors.black)
  86. --event,side,x,y = os.pullEvent("monitor_touch")
  87. buttons = {}
  88. table.insert(buttons,{"-1",21,22,colors.red,colors.white})
  89. table.insert(buttons,{"-10",16,18,colors.red,colors.red,colors.white})
  90. table.insert(buttons,{"-64",11,13,colors.red,colors.white})
  91. table.insert(buttons,{"1",28,29,colors.green,colors.white})
  92. table.insert(buttons,{"10",32,34,colors.green,colors.white})
  93. table.insert(buttons,{"64",37,39,colors.green,colors.white})
  94.  
  95. --draw buttons
  96. --print(textutils.serialise(buttons))
  97. sx,sy = term.getSize()
  98. textY = sy/2
  99. modY = textY % 1
  100.  
  101. if modY == 0 then
  102. --all gud
  103. else
  104. textY = textY-0.5
  105. end
  106.  
  107. confirmbtn = {15,11,21,11}
  108. cancelbtn = {29,11,34,11}
  109.  
  110. mX, mY = term.getSize()
  111. mX = mX/2
  112. mY = mY/2
  113.  
  114. amountX = mX - #tostring(amountPrefix..amount)/2
  115. amountY = mY+2
  116.  
  117. term.setCursorPos(amountX,amountY)
  118. term.setTextColor(colors.blue)
  119. term.setBackgroundColor(colors.white)
  120. if payScreen == true then
  121. term.write(amountPrefix..tostring(amount))
  122. end
  123. for i=1,#buttons do
  124. --print("button nr: "..i.." | "..buttons[i][1])
  125. tx = buttons[i][2]
  126. tx2 = buttons[i][3]
  127. sx,sy = term.getSize()
  128. mY = sy/2
  129. paintutils.drawLine(tx,mY,tx2,mY,buttons[i][4])
  130. term.setCursorPos(tx,mY)
  131. prefix = ""
  132. text = buttons[i][1]
  133. num = tonumber(text)
  134. if num >= 0 then
  135. prefix = "+"
  136. end
  137. term.write(prefix..text)
  138. end
  139. term.setCursorPos(sx/2-10,sy/2+2)
  140. term.setBackgroundColor(colors.green)
  141. term.setTextColor(colors.black)
  142. term.write("Confirm")
  143. term.setCursorPos(sx/2+4,sy/2+2)
  144. term.setBackgroundColor(colors.red)
  145. term.setTextColor(colors.black)
  146. term.write("Cancel")
  147.  
  148. local amountSelect = true
  149. --increase/decrase touch events listen
  150. payScreen = false
  151. while amountSelect do
  152. term.setBackgroundColor(colors.white)
  153. term.setTextColor(colors.black)
  154. event,side,x,y = os.pullEvent("monitor_touch")
  155. curbtn = 0
  156. for i=1,#buttons do
  157. if x >= buttons[i][2] and x <= buttons[i][3] and y == textY then
  158. amount = amount + tonumber(buttons[i][1])
  159. if amount < 0 then
  160. amount = 0
  161. end
  162. if amount > 64 then
  163. amount = 64
  164. end
  165.  
  166. end
  167. if x >= cancelbtn[1] and x <= cancelbtn[3] and y == cancelbtn[2] then
  168. shell.run("monitor top shop")
  169. end
  170.  
  171. if x >= confirmbtn[1] and x <= confirmbtn[3] and y == confirmbtn[2] then
  172. payScreen = true
  173. amountSelect = false
  174. term.setBackgroundColor(colors.white)
  175. term.setTextColor(colors.black)
  176. mX,mY = term.getSize()
  177. mX = mX/2
  178. mY = mY/2
  179. coinsToPay = amount * tonumber(selection["value"])
  180. s = "Please pay "..coinsToPay.." coins"
  181. term.clear()
  182. term.setCursorPos(mX-#s/2,mY-3)
  183. term.write(s)
  184. s = "to the following adress:"
  185. term.setCursorPos(mX-#s/2,mY-2)
  186. term.write(s)
  187. term.setCursorPos(mX-#serverAdress/2,mY)
  188. term.write(serverAdress)
  189. term.setCursorPos(sx/2-10,sy/2+2)
  190. term.setBackgroundColor(colors.green)
  191. term.setTextColor(colors.black)
  192. term.write("Confirm")
  193. term.setCursorPos(sx/2+4,sy/2+2)
  194. term.setBackgroundColor(colors.red)
  195. term.setTextColor(colors.black)
  196. term.write("Cancel")
  197. event,side,x,y = os.pullEvent("monitor_touch")
  198.  
  199. if x >= confirmbtn[1] and x <= confirmbtn[3] and y == confirmbtn[2] then
  200. curTime = http.get(baseURL.."getUnixTimestamp.php").readAll()
  201. tTime = curTime + 120
  202. curTime = http.get(baseURL.."unixToDatetime.php?timestamp="..tTime).readAll()
  203. futTime = http.get(baseURL.."unixToDatetime.php?timestamp="..tTime).readAll()
  204. url = baseURL.."checktxn.php?fromdate="..curTime.."&todate="..futTime.."&toadress="..serverAdress.."&amount="..coinsToPay
  205. log(url)
  206. txndata = http.get(url).readAll()
  207. log(txndata)
  208. end
  209.  
  210. if x >= cancelbtn[1] and x <= cancelbtn[3] and y == cancelbtn[2] then
  211. shell.run("monitor top shop")
  212. end
  213. break
  214. end
  215. end
  216. term.setCursorPos(amountX,amountY)
  217. term.setTextColor(colors.blue)
  218. term.setBackgroundColor(colors.white)
  219. if payScreen == true then
  220. term.write(amountPrefix..tostring(amount).." ")
  221. end
  222. end
  223. end
  224.  
  225. --listen for touch events
  226. event,side,x,y = os.pullEvent("monitor_touch")
  227. selection = {}
  228. for i=1,#itembuttons do
  229. if x >= itembuttons[i][1] and x <= itembuttons[i][3] and y >= itembuttons[i][2] and y <= itembuttons[i][4] then
  230. selection["item"] = itembuttons[i][5]
  231. selection["value"] = itembuttons[i][6]
  232. break
  233. end
  234. --[[
  235. print("")
  236. print(itembuttons[i][1])
  237. print(itembuttons[i][2])
  238. print(itembuttons[i][3])
  239. print(itembuttons[i][4])
  240. print(itembuttons[i][5])
  241. print(itembuttons[i][6])
  242. print("-----")
  243. print(x)
  244. print(y)
  245. ]]--
  246. end
  247. amount()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement