TeoMessiKing

Booga Booga Gui

Feb 17th, 2019 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.98 KB | None | 0 0
  1. -- tables to do add on functions on
  2.  
  3. local table = table -- orig table functions
  4. local term = term -- orig term functions
  5.  
  6. -- table add on functions
  7.  
  8. table.find = function(tbl, value)
  9. local index
  10. for i,v in next, tbl do
  11. if type(i)=="number" then
  12. if v == value then
  13. index = i
  14. break
  15. end
  16. end
  17. end
  18. return index
  19. end
  20.  
  21.  
  22.  
  23. table.pack = function(...)
  24. local args = {...}
  25. local rettbl = {}
  26. for i,v in next, args do
  27. table.insert(rettbl, v)
  28. end
  29. return rettbl
  30. end
  31.  
  32. string.split = function(str, splitchar)
  33. local ret = {""}
  34. local curtest = ""
  35. str:gsub(".", function(char)
  36. if char==string.sub(splitchar,#curtest+1,#curtest+1) then
  37. curtest = curtest..char
  38. if curtest==splitchar then
  39. ret[#ret+1]=""
  40. curtest = ""
  41. end
  42. else
  43. ret[#ret] = ret[#ret]..char
  44. end
  45. end)
  46. return ret
  47. end
  48.  
  49.  
  50.  
  51. -- general functions
  52.  
  53.  
  54. local getNames = function()
  55. return peripheral.getNames()
  56. end
  57.  
  58. local getWirelessModems = function()
  59. local modems = {}
  60. local names = getNames()
  61. for i,v in next, names do
  62. if table.find(peripheral.getMethods(v), "isWireless") ~= nil then
  63. if peripheral.wrap(v).isWireless() == true then
  64. table.insert(modems, v)
  65. end
  66. end
  67. end
  68. return modems
  69. end
  70.  
  71. local getPrinters = function()
  72. local modems = {}
  73. local names = getNames()
  74. for i,v in next, names do
  75. if string.find(v:lower(),"printer") then
  76. table.insert(modems, v)
  77. end
  78. end
  79. return modems
  80. end
  81.  
  82. local openModems = function()
  83. local modems = getWirelessModems()
  84. for i,v in next, modems do
  85. rednet.open(v)
  86. end
  87. end
  88.  
  89.  
  90.  
  91. openModems()
  92.  
  93. local roundNumber = function(num)
  94. local ret = num
  95. local fullNum = math.floor(num)
  96. if num-fullNum % 1 ~= 0 then
  97. if num-fullNum % 1 >= 0.5 then
  98. ret = fullNum+1
  99. elseif num-fullNum % 1 < 0.5 then
  100. ret = fullNum
  101. end
  102. end
  103. return ret
  104. end
  105.  
  106. local round = function(number, ...)
  107. local args = {...}
  108. local retNum, retDiff = 0, math.huge
  109. for i,v in next, args do
  110. if number >= 0 then
  111. if math.abs(number-v) < retDiff then
  112. retNum = v
  113. retDiff = math.abs(number-v)
  114. end
  115. elseif number <= 0 then
  116. if number+v < retDiff then
  117. retNum = v
  118. retDiff = number+v
  119. end
  120. end
  121. end
  122. return retNum, retDiff
  123. end
  124.  
  125. local getSimilarString = function(str, ...)
  126. local searchtbl = {}
  127. local args = {...}
  128. for i,v in next, args do
  129. if table.find(searchtbl, v) == nil then
  130. table.insert(searchtbl, v)
  131. end
  132. end
  133. local curNUM, curSTR = 0, {}
  134. local similarChars = 0
  135. local sc = {}
  136. local numTBL = {}
  137. for i,v in next, searchtbl do
  138. sc[v]=0
  139. end
  140. local curCHAR = 0
  141. str:gsub(".", function(char)
  142. curCHAR = curCHAR+1
  143. for i,v in next, searchtbl do
  144. if v:sub(curCHAR,curCHAR):lower() == char:lower() then
  145. sc[v] = sc[v]+1
  146. end
  147. end
  148. end)
  149. for i,v in next, sc do
  150. if v>curNUM then
  151. curNUM = v
  152. end
  153. end
  154. for i,v in next, sc do
  155. if v==curNUM then
  156. table.insert(curSTR, tostring(i))
  157. end
  158. end
  159. return curSTR
  160. end
  161.  
  162.  
  163.  
  164. local getColors = function()
  165. local retTBL = {}
  166. local usedColors = {}
  167. for i,v in next, colors do
  168. if type(v) == "number" and usedColors[i:lower()] == nil then
  169. table.insert(retTBL, {["CCode"]=v, ["CName"]=i})
  170. usedColors[i:lower()]=true
  171. end
  172. end
  173. return retTBL
  174. end
  175.  
  176. local getColor = function(color)
  177. local clrTBL = getColors()
  178. for i,v in next, clrTBL do
  179. end
  180. local names, codes = {}, {}
  181. for i,v in next, clrTBL do
  182. table.insert(names, v.CName)
  183. table.insert(codes, v.CCode)
  184. end
  185.  
  186. if type(color) == "number" then
  187. local closestNumber = round(color, unpack(codes))
  188. return closestNumber
  189. elseif type(color) == "string" then
  190. local simstr = getSimilarString(color, unpack(names))
  191. if #simstr>1 then
  192. return colors[simstr[math.random(1, #simstr)]]
  193. elseif #simstr<1 then
  194. return colors[names[math.random(1, #names)]]
  195. elseif #simstr==1 then
  196. return colors[simstr[1]]
  197. end
  198. end
  199. end
  200.  
  201. local setBackgroundColor = function(color)
  202. local clr = getColor(color)
  203. term.setBackgroundColor(clr)
  204. end
  205.  
  206. local setTextColor = function(color)
  207. local clr = getColor(color)
  208. term.setTextColor(clr)
  209. end
  210.  
  211. local draw = {}
  212.  
  213. draw.fillPixel = function(x, y, color)
  214. setBackgroundColor(color)
  215. term.setCursorPos(x,y)
  216. term.write(" ")
  217. end
  218.  
  219. draw.fillSquare = function(startX, startY, endX, endY, color)
  220. setBackgroundColor(color)
  221. local x, y = term.getSize()
  222. for k=math.min(startY, endY), math.max(startY, endY) do
  223. term.setCursorPos(math.min(startX, endX), k)
  224. write(string.rep(" ", math.max(startX, endX)-math.min(startX, endX)))
  225. end
  226. end
  227.  
  228. draw.createText = function(X, Y, text, textcolor, backgroundcolor)
  229. setTextColor(textcolor)
  230. setBackgroundColor(backgroundcolor)
  231. local posX = X-#text/2
  232. term.setCursorPos(posX, Y)
  233. term.write(text)
  234. end
  235.  
  236. draw.createNormalText = function(x, y, text, textcolor, backgroundcolor)
  237. setTextColor(textcolor)
  238. setBackgroundColor(backgroundcolor)
  239. term.setCursorPos(x,y)
  240. term.write(text)
  241. end
  242.  
  243. draw.createColoredText = function(x, y, text, backgroundcolor)
  244. local colorCodePrefix = "&"
  245. local colorCodes = {
  246. ["0"]=colors.white,
  247. ["1"]=colors.orange,
  248. ["2"]=colors.magenta,
  249. ["3"]=colors.lightBlue,
  250. ["4"]=colors.yellow,
  251. ["5"]=colors.lime,
  252. ["6"]=colors.pink,
  253. ["7"]=colors.gray,
  254. ["8"]=colors.lightGray,
  255. ["9"]=colors.cyan,
  256. ["a"]=colors.purple,
  257. ["b"]=colors.blue,
  258. ["c"]=colors.brown,
  259. ["d"]=colors.green,
  260. ["e"]=colors.red,
  261. ["f"]=colors.black,
  262. }
  263. setBackgroundColor(backgroundcolor)
  264. term.setCursorPos(x, y)
  265. local curSTR = ""text:gsub(".", function(str)
  266. local ret = ""
  267. if str == colorCodePrefix then
  268. curSTR = colorCodePrefix
  269. elseif colorCodes[str] ~= nil then
  270. if curSTR == colorCodePrefix then
  271. term.setTextColor(colorCodes[str])
  272. curSTR = ""
  273. else
  274. write(str)
  275. end
  276. else
  277. curSTR = ""
  278. write(str)
  279. end
  280.  
  281. end)
  282. end
  283.  
  284. draw.fillBackground = function(color)
  285. local x, y = term.getSize()
  286. setBackgroundColor(color)
  287. for k=1,y do
  288. term.setCursorPos(1, k)
  289. write(string.rep(" ", x))
  290. end
  291. end
  292.  
  293. draw.fillLine = function(y, color)
  294. local sizex, sizey = term.getSize()
  295. setBackgroundColor(color)
  296. term.setCursorPos(1,y)
  297. write(string.rep(" ", sizex))
  298. end
  299.  
  300. -- GUI making
  301.  
  302. local zoostatus = true
  303.  
  304. local generateExpirationDay = function(length)
  305. local daytoadd = 0
  306. if length == "Forever" then
  307. daytoadd = math.huge
  308. elseif length == "Month" then
  309. daytoadd = 2160
  310. elseif length == "Day" then
  311. daytoadd = 72
  312. end
  313. local curDay = os.day()
  314. local time = os.time()
  315. return {curDay+daytoadd, time}
  316. end
  317.  
  318. -- Database --
  319.  
  320. if fs.isDir("saves") == false then
  321. fs.makeDir("saves")
  322. end
  323.  
  324. if fs.exists("saves/IDs") == false then
  325. local file = fs.open("saves/IDs", "w")
  326. file.writeLine("090={[\"ExpirationDay\"]={math.huge,0}, [\"Disabled\"]=false}")
  327. file.close()
  328. end
  329.  
  330. local decode = function(line)
  331. local ID = line:gmatch("%d*")()
  332. local Disabled = string.gmatch(line, "%[\"Disabled\"%]=\"%a*\"")()
  333. local Days = string.gmatch(line, "[{](%d*)[,]")()
  334. local Time = string.gmatch(line, "[,](%d*)[}]")()
  335. dataTable={["ExpirationDay"]={tonumber(Days), tonumber(Time)}, ["Disabled"]=Disabled}
  336. return {ID, dataTable}
  337. end
  338.  
  339. local getIDs = function()
  340. local tbl = {}
  341. local file = fs.open("saves/IDs", "r")
  342. local line = file.readLine()
  343. repeat
  344. if line ~= nil or line ~="" then
  345. local split = decode(line)
  346. tbl[split[1]]=split[2]
  347. else
  348. end
  349. line = file.readLine()
  350. until line==nil
  351. file.close()
  352. return tbl
  353. end
  354.  
  355. local IDs = getIDs()
  356.  
  357.  
  358. local addCode = function(code, tbl)
  359. local file = fs.open("saves/IDs", "a")
  360. local str = tostring(code).."={".."[\"ExpirationDay\"]={"..tbl.ExpirationDay[1]..","..tbl.ExpirationDay[2].."},".."[\"Disabled\"]=\""..tbl.Disabled.."\"}"
  361. file.writeLine(str)
  362. file.close()
  363. IDs = getIDs()
  364. end
  365.  
  366.  
  367. local odds = {
  368. ["1"]={1,1},
  369. ["2"]={1,100},
  370. ["3"]={100,300},
  371. ["4"]={300,1000},
  372. ["5"]={600, 2500},
  373. ["6"]={800, 3000}
  374. }
  375.  
  376. local generateIDlength = function()
  377. local ret = 0
  378. local num = math.random(1,3000)
  379. for i,v in next, odds do
  380. if num>v[1] and num<=v[2] then
  381. ret = i
  382. break
  383. end
  384. end
  385. return ret
  386. end
  387.  
  388. local IDgenerator = function()
  389. local cur = string.rep("#", generateIDlength())
  390. local id = cur:gsub(".", function(str)
  391. return string.char(math.random(48, 57))
  392. end)
  393. return id
  394. end
  395.  
  396. local generateID = function()
  397. local id = IDgenerator()
  398. for i=1,20 do
  399. if IDs[tostring(id)] ~= nil then
  400. id = IDgenerator()
  401. else
  402. break
  403. end
  404. end
  405.  
  406. if IDs[tostring(id)]~=nil then
  407. return "failed"
  408. else
  409. return id
  410. end
  411. end
  412.  
  413. local createNewID = function(length)
  414. local id = generateID()
  415. if id == "failed" then
  416. return "failed"
  417. else
  418. addCode(tostring(id), {
  419. ["ExpirationDay"]=generateExpirationDay(length),
  420. ["Disabled"]="false"
  421. })
  422. return id
  423. end
  424. end
  425.  
  426. local checkValidID = function(id)
  427. local returnMessage = ""
  428. if IDs[tostring(id)] == nil then
  429. returnMessage="false"
  430. else
  431. local tbl = IDs[tostring(id)]
  432. local day = os.day()
  433. local time = os.time()
  434. print(tbl[1])
  435. if tbl["Disabled"]==true then
  436. returnMessage="false"
  437. else
  438. if day>=tbl["ExpirationDay"][1] then
  439. returnMessage = "false"
  440. else
  441. returnMessage = "true"
  442. end
  443. end
  444. end
  445. return returnMessage
  446. end
  447.  
  448. local getTimeLeft = function(id)
  449. local ret = "nil"
  450. if IDs[tostring(id)] == nil then
  451. else
  452. local tbl = IDs[tostring(id)]
  453. local expiring = tbl.ExpirationDay
  454.  
  455. ret = tostring(((expiring[1]-os.day())*20)/60).." - Hours"
  456. end
  457. return ret
  458. end
  459.  
  460. local blacklistID = function(id)
  461. if IDs[tostring(id)] ~= nil then
  462. local tbl = IDs[id]
  463. IDs[id]["Disabled"]=true
  464. end
  465. end
  466.  
  467. local dayInMonths = {
  468. ["january"]=31,
  469. ["february"]=28,
  470. ["mars"]=31,
  471. ["april"]=30,
  472. ["may"]=31,
  473. ["june"]=30,
  474. ["july"]=31,
  475. ["august"]=31,
  476. ["september"]=30,
  477. ["october"]=31,
  478. ["november"]=30,
  479. ["december"]=31
  480. }
  481.  
  482. local monthOrder = {
  483. ["january"]=1,
  484. ["february"]=2,
  485. ["mars"]=3,
  486. ["april"]=4,
  487. ["may"]=5,
  488. ["june"]=6,
  489. ["july"]=7,
  490. ["august"]=8,
  491. ["september"]=9,
  492. ["october"]=10,
  493. ["november"]=11,
  494. ["december"]=12
  495. }
  496.  
  497. local getRealTime = function()
  498. local api = "http://worldtimeapi.org/api/timezone/Etc/GMT.txt"
  499. local httpget = http.get(api)
  500. local readAll = httpget.readAll()
  501. local date = readAll:gmatch("datetime: %d*-%d*-%d*")()
  502. local realDate = date:gsub(".", function(str)
  503. if str:match("%d") or str:match("-") then
  504. return str
  505. else
  506. return ""
  507. end
  508. end)
  509. local time = readAll:gmatch("%d*:%d*:%d*")()
  510. return {realDate, time}
  511. end
  512.  
  513. local getTimeOneDayOffset = function(tbl)
  514. local curtime = tbl[2]
  515. local date = tbl[1]
  516. local ret = {}
  517. local newDate = {
  518. ["year"]="",
  519. ["month"]="",
  520. ["day"]=""
  521. }
  522. local split = string.split(date,"-")
  523. for i,v in next, split do
  524. if i==1 then
  525. newDate.year = v
  526. elseif i==2 then
  527. newDate.month = v
  528. elseif i==3 then
  529. newDate.day = v
  530. end
  531. end
  532. local currentMonth = ""
  533. for i,v in next, monthOrder do
  534. if v==tonumber(newDate.month) then
  535. currentMonth = i
  536. end
  537. end
  538. local daysinthismonth = dayInMonths[currentMonth]
  539. if tonumber(newDate.day)+1>daysinthismonth then
  540. if newDate.month=="12" then
  541. newDate.year = tonumber(newDate.year)+1
  542. newDate.month = "01"
  543. newDate.day = "01"
  544. else
  545. local nextMonthNumber = monthOrder[currentMonth]+1
  546. local nextMonth = ""
  547. for i,v in next, monthOrder do
  548. if v==nextMonthNumber then
  549. nextMonth=i
  550. end
  551. end
  552. newDate.day = "01"
  553. if #tostring(nextMonthNumber)==1 then
  554. newDate.month="0"..tostring(nextMonthNumber)
  555. else
  556. newDate.month=tostring(nextMonthNumber)
  557. end
  558. end
  559. else
  560. local newday = tonumber(newDate.day)+1
  561. if #tostring(newday) == 1 then
  562. newday = "0"..tostring(newday)
  563. else
  564. newday = tostring(newday)
  565. end
  566. newDate.day = newday
  567. end
  568. ret[1] = tostring(newDate.year).."-"..tostring(newDate.month).."-"..tostring(newDate.day)
  569. ret[2] = tbl[2]
  570. return ret
  571. end
  572.  
  573.  
  574.  
  575. local printInfo = function(id)
  576. local printers = getPrinters()
  577. if #printers >= 1 then
  578. local printer = printers[1]
  579. if peripheral.wrap(printer).getPaperLevel() > 0 and peripheral.wrap(printer).getInkLevel() > 0 then
  580. local pos = 1
  581. local str = ""
  582. local tbl = IDs[id]
  583. if tbl ~= nil then
  584. peripheral.wrap(printer).newPage()
  585. peripheral.wrap(printer).write(str)
  586.  
  587. local valid = checkValidID(id)
  588. local time = getTimeLeft(id)
  589. pos = pos+2
  590. peripheral.wrap(printer).setCursorPos(1,pos)
  591. peripheral.wrap(printer).write("Expires in "..getTimeLeft(id))
  592. pos=pos+2
  593. peripheral.wrap(printer).setCursorPos(1,pos)
  594. peripheral.wrap(printer).write("Your ID is "..id)
  595. pos=pos+1
  596. peripheral.wrap(printer).setCursorPos(1,pos)
  597. peripheral.wrap(printer).write("EXPIRES: ")
  598. local expirationdate = getTimeOneDayOffset(getRealTime())
  599. pos=pos+1
  600. peripheral.wrap(printer).setCursorPos(1,pos)
  601. peripheral.wrap(printer).write(expirationdate[1])
  602. pos=pos+1
  603. peripheral.wrap(printer).setCursorPos(1,pos)
  604. peripheral.wrap(printer).write(expirationdate[2].." GMT+1")
  605. pos=pos+2
  606. peripheral.wrap(printer).setCursorPos(1,pos)
  607. peripheral.wrap(printer).write("ID is valid: "..valid)
  608. pos=pos+2
  609. peripheral.wrap(printer).setCursorPos(1,pos)
  610. peripheral.wrap(printer).write("Welcome to the zoo :)")
  611. peripheral.wrap(printer).endPage()
  612. else
  613.  
  614. end
  615. end
  616. end
  617. end
  618.  
  619. local isTyping = false
  620. local onEnter = function()
  621.  
  622. end
  623. local typingtext = ""
  624. local typingX, typingY = 0, 0
  625. local maxTypingLetters = 0
  626. local typingColor = colors.white
  627. local currentGUI = "main"
  628. local loadinggui = false
  629.  
  630. local guitbl = {}
  631.  
  632. local checkvalididinfo = {}
  633.  
  634. local checkvalidcurrentid = ""
  635. local isvalid = "nil"
  636. local validexpiratondate = "nil"
  637. local timeleft = "nil"
  638.  
  639. local checkvalidinfomt = {
  640. __newindex = function(table, key, value)
  641. if key=="CurrentID" then
  642. checkvalidcurrentid = value
  643. guitbl["switchgui"]="checkidvalid"
  644. return nil
  645. elseif key=="checkvalid" then
  646. isvalid=value
  647. guitbl["switchgui"]="checkidvalid"
  648. elseif key=="timeleft" then
  649. timeleft=value
  650. guitbl["switchgui"]="checkidvalid"
  651. end
  652. return nil
  653. end
  654. }
  655.  
  656. setmetatable(checkvalididinfo, checkvalidinfomt)
  657.  
  658. local generateidNewID = "nil"
  659.  
  660. local generateidinfo = {}
  661.  
  662. local generateidinfomt = {
  663. __newindex = function(table, key, value)
  664. if key=="newid" then
  665. generateidNewID = value
  666. guitbl["switchgui"]="generateid"
  667. end
  668. end
  669. }
  670.  
  671. setmetatable(generateidinfo, generateidinfomt)
  672.  
  673. local checkcancelcurrentid = "nil"
  674. local checkcancelidinfo = {}
  675.  
  676. local checkcancelidinfomt = {
  677. __newindex = function(table, key, value)
  678. if key=="CurrentID" then
  679. checkcancelcurrentid = value
  680. guitbl["switchgui"]="cancelid"
  681. end
  682. end
  683. }
  684.  
  685. setmetatable(checkcancelidinfo, checkcancelidinfomt)
  686.  
  687. local zootbl = {}
  688.  
  689. local zoomt = {
  690. __newindex = function(self, key, value)
  691. if key == "closezoo" then
  692. zoostatus = false
  693. guitbl["switchgui"]="zoo"
  694. elseif key == "openzoo" then
  695. zoostatus = true
  696. guitbl["switchgui"]="zoo"
  697. end
  698. end
  699. }
  700.  
  701. setmetatable(zootbl, zoomt)
  702.  
  703. local guiDrawing = {
  704. ["main"]=function()
  705. loadinggui = true
  706. draw.fillBackground("magenta")
  707. draw.fillLine(1, "pink")
  708. local sizeX, sizeY = term.getSize()
  709. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  710. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  711. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  712. draw.createText((sizeX)/2, (sizeY-1)/2+0, "Zoo Admin Panel", "white", "magenta")
  713. draw.createText((sizeX)/2, (sizeY-1)/2+1, "Controls the whole Zoo!", "white", "magenta")
  714. draw.createText((sizeX)/2, (sizeY-1)/2+2, "Computer #"..os.getComputerID(), "white", "magenta")
  715. loadinggui = false
  716. end,
  717. ["idmenu"]=function()
  718. loadinggui = true
  719. draw.fillBackground("magenta")
  720. draw.fillLine(1, "pink")
  721. local sizeX, sizeY = term.getSize()
  722. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  723. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  724. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  725. draw.createText((sizeX)/2, 2, "ID Admin Panel", "white", "magenta")
  726. draw.createNormalText((sizeX/2)-10, sizeY/2, "Generate ID"..string.rep(" ",21-#"Generate ID"), "white", "pink")
  727. draw.createNormalText((sizeX/2)-10, sizeY/2+2, "Check Valid ID"..string.rep(" ",21-#"Check Valid ID"), "white", "pink")
  728. draw.createNormalText((sizeX/2)-10, sizeY/2+4, "Cancel ID"..string.rep(" ",21-#"Cancel ID"), "white", "pink")
  729. loadinggui = false
  730.  
  731. end,
  732. ["checkidvalid"]=function()
  733. loadinggui = true
  734. draw.fillBackground("magenta")
  735. draw.fillLine(1, "pink")
  736. local sizeX, sizeY = term.getSize()
  737. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  738. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  739. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  740. draw.createText((sizeX)/2, 2, "ID Information", "white", "magenta")
  741. draw.fillSquare(math.floor(sizeX/2)-15, sizeY/2-3, math.ceil(sizeX/2)+15, sizeY/2-3, "pink")
  742. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  743. draw.createText(math.floor(sizeX/2), sizeY/2+2, "Check Is Valid", "white", "pink")
  744. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
  745. draw.createText(math.floor(sizeX/2), sizeY/2-1, "Current ID", "white", "magenta")
  746. draw.createText(math.floor(sizeX/2), sizeY/2, checkvalidcurrentid:sub(1,21), "white", "pink")
  747. draw.createText(math.floor(sizeX/2), sizeY/2+4, "Is Valid", "white", "magenta")
  748. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+5, math.ceil(sizeX/2)+10, sizeY/2+5, "pink")
  749. draw.createText(math.floor(sizeX/2), sizeY/2+5, isvalid, "white", "pink")
  750. draw.createText(math.floor(sizeX/2), sizeY/2+7, "Time Left", "white", "magenta")
  751. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+8, math.ceil(sizeX/2)+10, sizeY/2+8, "pink")
  752. draw.createText(math.floor(sizeX/2), sizeY/2+8, timeleft, "white", "pink")
  753. loadinggui = false
  754. end,
  755. ["generateid"]=function()
  756. loadinggui = true
  757. draw.fillBackground("magenta")
  758. draw.fillLine(1, "pink")
  759. local sizeX, sizeY = term.getSize()
  760. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  761. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  762. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  763. draw.createText((sizeX)/2, 2, "Generate ID", "white", "magenta")
  764. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2-3, math.ceil(sizeX/2)+10, sizeY/2-3, "pink")
  765. draw.createText(sizeX/2, sizeY/2-3, "Generate ID", "white", "pink")
  766. draw.createText(sizeX/2, sizeY/2+1, "New Generated ID", "white", "magenta")
  767. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  768. draw.createText(sizeX/2, sizeY/2+2, tostring(generateidNewID), "white", "pink")
  769. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+4, math.ceil(sizeX/2)+10, sizeY/2+4, "pink")
  770. draw.createText(sizeX/2, sizeY/2+4, tostring("Print Information"), "white", "pink")
  771.  
  772. loadinggui = false
  773. end,
  774. ["cancelid"]=function()
  775. loadinggui = true
  776. draw.fillBackground("magenta")
  777. draw.fillLine(1, "pink")
  778. local sizeX, sizeY = term.getSize()
  779. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  780. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  781. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  782. draw.createText((sizeX)/2, 2, "Cancel IDs", "white", "magenta")
  783. draw.fillSquare(math.floor(sizeX/2)-15, sizeY/2-3, math.ceil(sizeX/2)+15, sizeY/2-3, "pink")
  784. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
  785. draw.createText(math.floor(sizeX/2), sizeY/2-1, "Current ID", "white", "magenta")
  786. draw.createText(math.floor(sizeX/2), sizeY/2, checkcancelcurrentid:sub(1,21), "white", "pink")
  787. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  788. draw.createText(sizeX/2, sizeY/2+2, tostring("Cancel ID"), "white", "pink")
  789. loadinggui = false
  790. end,
  791. ["zoo"]=function()
  792. loadinggui = true
  793. draw.fillBackground("magenta")
  794. draw.fillLine(1, "pink")
  795. local sizeX, sizeY = term.getSize()
  796. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  797. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  798. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  799. draw.createText((sizeX)/2, 2, "Zoo Admin Panel", "white", "magenta")
  800. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
  801. draw.createText(sizeX/2, sizeY/2, tostring("Close Down Zoo"), "white", "pink")
  802. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  803. draw.createText(sizeX/2, sizeY/2+2, tostring("Open Up Zoo"), "white", "pink")
  804. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+5, math.ceil(sizeX/2)+10, sizeY/2+5, "pink")
  805. draw.createText(sizeX/2, sizeY/2+5, tostring((function() if zoostatus == true then return "Open" else return "Closed" end end)()), "white", "pink")
  806. loadinggui = false
  807. end
  808. }
  809.  
  810. local drawGUI = function()
  811. if guiDrawing[currentGUI] ~= nil then
  812. guiDrawing[currentGUI]()
  813. end
  814. end
  815.  
  816.  
  817. local guimt = {
  818. __newindex = function(table, key, value)
  819. if key == "switchgui" and loadinggui == false then
  820. typingtext=""
  821. isTyping=false
  822. currentGUI = value
  823. drawGUI()
  824. end
  825. end
  826. }
  827.  
  828. setmetatable(guitbl, guimt)
  829.  
  830. local termSizeX, termSizeY = term.getSize()
  831.  
  832. local buttons = {
  833. ["main"]={
  834. ["mainmenu"]={
  835. ["posX"]=1,
  836. ["posY"]=1,
  837. ["sizeX"]=11,
  838. ["sizeY"]=1,
  839. ["func"]=function()
  840. guitbl["switchgui"]="main"
  841. end
  842. },
  843. ["idmenu"]={
  844. ["posX"]=13,
  845. ["posY"]=1,
  846. ["sizeX"]=9,
  847. ["sizeY"]=1,
  848. ["func"]=function()
  849. guitbl["switchgui"]="idmenu"
  850. end
  851. },
  852. ["zoo"]={
  853. ["posX"]=22,
  854. ["posY"]=1,
  855. ["sizeX"]=5,
  856. ["sizeY"]=1,
  857. ["func"]=function()
  858. guitbl["switchgui"]="zoo"
  859. end
  860. }
  861. },
  862. ["idmenu"]={
  863. ["mainmenu"]={
  864. ["posX"]=1,
  865. ["posY"]=1,
  866. ["sizeX"]=11,
  867. ["sizeY"]=1,
  868. ["func"]=function()
  869. guitbl["switchgui"]="main"
  870. end
  871. },
  872. ["idmenu"]={
  873. ["posX"]=13,
  874. ["posY"]=1,
  875. ["sizeX"]=9,
  876. ["sizeY"]=1,
  877. ["func"]=function()
  878. guitbl["switchgui"]="idmenu"
  879. end
  880. },
  881. ["zoo"]={
  882. ["posX"]=22,
  883. ["posY"]=1,
  884. ["sizeX"]=5,
  885. ["sizeY"]=1,
  886. ["func"]=function()
  887. guitbl["switchgui"]="zoo"
  888. end
  889. },
  890. ["generateid"]={
  891. ["posX"]=(termSizeX/2)-10,
  892. ["posY"]=(termSizeY/2),
  893. ["sizeX"]=21,
  894. ["sizeY"]=1,
  895. ["func"]=function()
  896. guitbl["switchgui"]="generateid"
  897. end
  898. },
  899. ["checkvalidid"]={
  900. ["posX"]=(termSizeX/2)-10,
  901. ["posY"]=(termSizeY/2)+2,
  902. ["sizeX"]=21,
  903. ["sizeY"]=1,
  904. ["func"]=function()
  905. guitbl["switchgui"]="checkidvalid"
  906. end
  907. },
  908. ["cancelid"]={
  909. ["posX"]=(termSizeX/2)-10,
  910. ["posY"]=(termSizeY/2)+4,
  911. ["sizeX"]=21,
  912. ["sizeY"]=1,
  913. ["func"]=function()
  914. guitbl["switchgui"]="cancelid"
  915. end
  916. }
  917. },
  918. ["zoo"]={
  919. ["mainmenu"]={
  920. ["posX"]=1,
  921. ["posY"]=1,
  922. ["sizeX"]=11,
  923. ["sizeY"]=1,
  924. ["func"]=function()
  925. guitbl["switchgui"]="main"
  926. end
  927. },
  928. ["idmenu"]={
  929. ["posX"]=13,
  930. ["posY"]=1,
  931. ["sizeX"]=9,
  932. ["sizeY"]=1,
  933. ["func"]=function()
  934. guitbl["switchgui"]="idmenu"
  935. end
  936. },
  937. ["zoo"]={
  938. ["posX"]=22,
  939. ["posY"]=1,
  940. ["sizeX"]=5,
  941. ["sizeY"]=1,
  942. ["func"]=function()
  943. guitbl["switchgui"]="zoo"
  944. end
  945. },
  946. ["closezoo"]={
  947. ["posX"]=math.floor(termSizeX/2)-10,
  948. ["posY"]=termSizeY/2,
  949. ["sizeX"]=21,
  950. ["sizeY"]=1,
  951. ["func"]=function()
  952. zootbl["closezoo"]=false
  953. end
  954. },
  955. ["openzoo"]={
  956. ["posX"]=math.floor(termSizeX/2)-10,
  957. ["posY"]=termSizeY/2+2,
  958. ["sizeX"]=21,
  959. ["sizeY"]=1,
  960. ["func"]=function()
  961. zootbl["openzoo"]=true
  962. end
  963. }
  964. },
  965. ["checkidvalid"]={
  966. ["mainmenu"]={
  967. ["posX"]=1,
  968. ["posY"]=1,
  969. ["sizeX"]=11,
  970. ["sizeY"]=1,
  971. ["func"]=function()
  972. guitbl["switchgui"]="main"
  973. end
  974. },
  975. ["idmenu"]={
  976. ["posX"]=13,
  977. ["posY"]=1,
  978. ["sizeX"]=9,
  979. ["sizeY"]=1,
  980. ["func"]=function()
  981. guitbl["switchgui"]="idmenu"
  982. end
  983. },
  984. ["zoo"]={
  985. ["posX"]=22,
  986. ["posY"]=1,
  987. ["sizeX"]=5,
  988. ["sizeY"]=1,
  989. ["func"]=function()
  990. guitbl["switchgui"]="zoo"
  991. end
  992. },
  993. ["searchbar"]={
  994. ["posX"]=math.floor(termSizeX/2)-15,
  995. ["posY"]=termSizeY/2-3,
  996. ["sizeX"]=31,
  997. ["sizeY"]=1,
  998. ["func"]=function()
  999. typingX = math.floor(termSizeX/2)-15
  1000. typingY = termSizeY/2-3
  1001. typingColor = colors.pink
  1002. maxTypingLetters = 31
  1003. isTyping = true
  1004. onEnter = function(text)
  1005. checkvalididinfo["CurrentID"]=text
  1006. end
  1007. end
  1008. },
  1009. ["validbutton"]={
  1010. ["posX"]=math.floor(termSizeX/2)-10,
  1011. ["posY"]=math.floor(termSizeY/2)+2,
  1012. ["sizeX"]=21,
  1013. ["sizeY"]=1,
  1014. ["func"]=function()
  1015. checkvalididinfo["checkvalid"]=checkValidID(checkvalidcurrentid)
  1016. checkvalididinfo["timeleft"]=getTimeLeft(checkvalidcurrentid)
  1017. end
  1018. },
  1019. },
  1020. ["generateid"]={
  1021. ["generateidbutton"]={
  1022. ["posX"]=math.floor(termSizeX/2)-10,
  1023. ["posY"]=termSizeY/2-3,
  1024. ["sizeX"]=21,
  1025. ["sizeY"]=1,
  1026. ["func"]=function()
  1027. generateidinfo["newid"]=createNewID("Day")
  1028. end
  1029. },
  1030. ["mainmenu"]={
  1031. ["posX"]=1,
  1032. ["posY"]=1,
  1033. ["sizeX"]=11,
  1034. ["sizeY"]=1,
  1035. ["func"]=function()
  1036. guitbl["switchgui"]="main"
  1037. end
  1038. },
  1039. ["idmenu"]={
  1040. ["posX"]=13,
  1041. ["posY"]=1,
  1042. ["sizeX"]=9,
  1043. ["sizeY"]=1,
  1044. ["func"]=function()
  1045. guitbl["switchgui"]="idmenu"
  1046. end
  1047. },
  1048. ["zoo"]={
  1049. ["posX"]=22,
  1050. ["posY"]=1,
  1051. ["sizeX"]=5,
  1052. ["sizeY"]=1,
  1053. ["func"]=function()
  1054. guitbl["switchgui"]="zoo"
  1055. end
  1056. },
  1057. ["printinformation"]={
  1058. ["posX"]=math.floor(termSizeX/2)-10,
  1059. ["posY"]=termSizeY/2+4,
  1060. ["sizeX"]=21,
  1061. ["sizeY"]=1,
  1062. ["func"]=function()
  1063. if generateidNewID ~= "nil" then
  1064. printInfo(generateidNewID)
  1065. end
  1066. end
  1067. }
  1068. },
  1069. ["cancelid"]={
  1070. ["mainmenu"]={
  1071. ["posX"]=1,
  1072. ["posY"]=1,
  1073. ["sizeX"]=11,
  1074. ["sizeY"]=1,
  1075. ["func"]=function()
  1076. guitbl["switchgui"]="main"
  1077. end
  1078. },
  1079. ["idmenu"]={
  1080. ["posX"]=13,
  1081. ["posY"]=1,
  1082. ["sizeX"]=9,
  1083. ["sizeY"]=1,
  1084. ["func"]=function()
  1085. guitbl["switchgui"]="idmenu"
  1086. end
  1087. },
  1088. ["zoo"]={
  1089. ["posX"]=22,
  1090. ["posY"]=1,
  1091. ["sizeX"]=5,
  1092. ["sizeY"]=1,
  1093. ["func"]=function()
  1094. guitbl["switchgui"]="zoo"
  1095. end
  1096. },
  1097. ["search"]={
  1098. ["posX"]=math.floor(termSizeX/2-15),
  1099. ["posY"]=termSizeY/2-3,
  1100. ["sizeX"]=31,
  1101. ["sizeY"]=1,
  1102. ["func"]=function()
  1103. typingX = math.floor(termSizeX/2)-15
  1104. typingY = termSizeY/2-3
  1105. typingColor = colors.pink
  1106. maxTypingLetters = 31
  1107. isTyping = true
  1108. onEnter = function(text)
  1109. checkcancelidinfo["CurrentID"]=text
  1110. end
  1111. end
  1112. },
  1113. ["cancelid"]={
  1114. ["posX"]=math.floor(termSizeX/2)-10,
  1115. ["posY"]=termSizeY/2+2,
  1116. ["sizeX"]=21,
  1117. ["sizeY"]=2,
  1118. ["func"]=function()
  1119. if checkcancelcurrentid ~= "nil" then
  1120. blacklistID(checkcancelcurrentid)
  1121. end
  1122. end
  1123. }
  1124. }
  1125.  
  1126. }
  1127.  
  1128. local updateText = function()
  1129. draw.fillSquare(typingX, typingY, typingX+maxTypingLetters, typingY, typingColor)
  1130. typingtext=typingtext:sub(1,maxTypingLetters)
  1131. term.setCursorPos(typingX, typingY)
  1132. write(typingtext)
  1133. end
  1134.  
  1135. guitbl["switchgui"]="main"
  1136.  
  1137. local onButton = function(x, y)
  1138. if buttons[tostring(currentGUI)] ~= nil then
  1139. for i,v in next, buttons[currentGUI] do
  1140. if x>=math.floor(v.posX) and x<=math.floor(v.posX+(v.sizeX-1)) then
  1141. if y>=math.floor(v.posY) and y<=math.floor(v.posY+(v.sizeY-1)) then
  1142. v.func()
  1143. break
  1144. else
  1145. isTyping=false
  1146. end
  1147. else
  1148. isTyping=false
  1149. end
  1150. end
  1151. end
  1152. end
  1153.  
  1154.  
  1155. local eventloop = function()
  1156. while true do
  1157. local event, a1, a2, a3 = os.pullEvent()
  1158. if event == "mouse_click" then
  1159. if a1 == 1 then
  1160.  
  1161. onButton(a2, a3)
  1162. end
  1163. elseif event == "key" then
  1164. if isTyping == true then
  1165. if #keys.getName(a1) == 1 then
  1166. typingtext=typingtext..keys.getName(a1)
  1167. elseif a1>=2 and a1<=10 then
  1168. typingtext=typingtext..tostring(a1-1)
  1169. elseif a1==11 then
  1170. typingtext=typingtext.."0"
  1171. elseif a1==14 then
  1172. typingtext=typingtext:sub(1, #typingtext-1)
  1173. elseif a1==28 then
  1174.  
  1175. elseif a1==57 then
  1176. typingtext=typingtext.." "
  1177. end
  1178. if a1==28 then
  1179. onEnter(typingtext)
  1180. isTyping=false
  1181. typingtext = ""
  1182. updateText()
  1183. else
  1184. updateText()
  1185. end
  1186. end
  1187. if a1==50 then
  1188. error("hey")
  1189. end
  1190. end
  1191. end
  1192. end
  1193.  
  1194. local rednetloop = function()
  1195. while true do
  1196. local id, message, protocol = rednet.receive()
  1197. if message:gmatch("validid_%d+")() then
  1198. local validstatus = checkValidID(message:sub(#"validid_.",#message))
  1199. if validstatus == "true" then
  1200. if zoostatus == false then
  1201. rednet.send(id, "Zoo is closed")
  1202. else
  1203. rednet.send(id, "isvalid_"..message:sub(#"validid_.", #message).."_".."true")
  1204. end
  1205. elseif validstatus == "false" then
  1206. rednet.send(id, "isvalid_"..message:sub(#"validid_.", #message).."_".."false")
  1207. end
  1208. end
  1209. end
  1210. end
  1211.  
  1212. parallel.waitForAny(rednetloop, eventloop)
Add Comment
Please, Sign In to add comment