9551

Untitled

Sep 10th, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.99 KB | None | 0 0
  1. local arg = ...
  2. if not fs.exists("ButtonH") then shell.run("pastebin get LTDZZZEJ ButtonH") end
  3. local b = require("ButtonH").terminal
  4. local xs, ys = term.getSize()
  5. local win = window.create(term.current(), 1, 1, xs, ys)
  6. local oldTerm = term.redirect(win)
  7. local mainCode = function()
  8.     local function printToDebug(...)
  9.         local old = term.redirect(debugWindow)
  10.         print(...)
  11.         term.redirect(old)
  12.     end
  13.     --if arg then
  14.         local mclick = {"timeout",0,-1,-1}
  15.         local dclick = {"timeout",0,-1,-1}
  16.         local pixelmap = {}
  17.         local drawmap = {}
  18.         local openmap
  19.         local cCol = colors.black
  20.         local cBac = colors.white
  21.         local cSym = " "
  22.         local sizeUpdate = function()
  23.             xs, ys = term.getSize()
  24.             term.setBackgroundColor(colors.black)
  25.             term.setTextColor(colors.white)
  26.         end
  27.         sizeUpdate()
  28.         term.clear()
  29.         local menuClick = function()
  30.             while true do
  31.                 mclick = b.timetouch(1,{[2]=true,[3]=true})
  32.             end
  33.         end
  34.         local drawClick = function()
  35.             while true do
  36.                 dclick = b.timetouch(1,{[2]=true,[3]=true},true)
  37.             end
  38.         end
  39.         local dfs = {3,7,11,4}
  40.         local windowbug = 1
  41.         local wincount = 0
  42.         local yy = 2
  43.         local draw = function()
  44.             local drawBox = function()
  45.                 sizeUpdate()
  46.                 win.setVisible(false)
  47.                 if wincount >= windowbug then
  48.                     win.clear()
  49.                     wincount = 0
  50.                 end
  51.                 wincount = wincount + 1
  52.                 if dfs[3] < xs-8  then
  53.                     term.setTextColor(colors.green)
  54.                     if b.boxButton(1,dclick,dfs[1]+dfs[3]+2,dfs[2]-2,"green","black"," +",2,1) then
  55.                         dfs[3] = dfs[3] + 1
  56.                     end
  57.                 end
  58.                 if dfs[3] > 11 then
  59.                     term.setTextColor(colors.red)
  60.                     if b.boxButton(1,dclick,dfs[1]+dfs[3]+2,dfs[2]+2,"red","black"," -",2,1) then
  61.                         dfs[3] = dfs[3] - 1
  62.                     end
  63.                 end
  64.                 if dfs[4] < ys-13 then
  65.                     if b.boxButton(1,dclick,dfs[1]+2,dfs[4]*2+5,"green","black","+",2,1) then
  66.                         dfs[4] = dfs[4] + 0.5
  67.                         dfs[2] = dfs[2] + 0.5
  68.                         yy = yy + 1
  69.                     end
  70.                 end
  71.                 if dfs[4] > 4 then
  72.                     if b.boxButton(1,dclick,dfs[1]+8,dfs[4]*2+5,"red","black","-",2,1) then
  73.                         dfs[4] = dfs[4] - 0.5
  74.                         dfs[2] = dfs[2] - 0.5
  75.                         yy = yy - 1
  76.                     end
  77.                 end
  78.                 term.setBackgroundColor(colors.black)
  79.                 term.setTextColor(colors.black)
  80.                 b.fill(nil,nil,nil,nil,"\127")
  81.                 b.frame(dfs[1],dfs[2],dfs[3],dfs[4],"lightGray","gray",false)
  82.                 for x=dfs[1], dfs[1]+dfs[3]-2 do
  83.                     for y=dfs[2]-dfs[4]+2, dfs[2]+dfs[4] do
  84.                         if b.API(dclick,x,y-1,1,1) then
  85.                             term.setTextColor(colors.white)
  86.                             if not pixelmap[x-dfs[1]+1] then pixelmap[x-dfs[1]+1] = {} end
  87.                             if not pixelmap[x-dfs[1]+1][y-dfs[2]+yy+1] then pixelmap[x-dfs[1]+1][y-dfs[2]+yy+1] = {} end
  88.                             pixelmap[x-dfs[1]+1][y-dfs[2]+yy+1] = {
  89.                                 tcol = cCol,
  90.                                 bcol = cBac,
  91.                                 sym = cSym
  92.                             }
  93.                             if not drawmap[x] then drawmap[x] = {} end
  94.                             if not drawmap[x][y] then drawmap[x][y] = {} end
  95.                             drawmap[x][y] = {}
  96.                             drawmap[x][y] = {
  97.                                 tcol = cCol,
  98.                                 bcol = cBac,
  99.                                 sym = cSym
  100.                             }
  101.                         end
  102.                     end
  103.                 end
  104.                 openmap = {}
  105.                 for k,v in pairs(drawmap) do
  106.                     for k2,v2 in pairs(v) do
  107.                         if k < dfs[1]+dfs[3]-1 then
  108.                             if k2 < dfs[2]+dfs[4]+1 then
  109.                                 term.setCursorPos(k,k2-1)
  110.                                 term.setBackgroundColor(v2.bcol)
  111.                                 term.setTextColor(v2.tcol)
  112.                                 term.write(v2.sym)
  113.                                 if not openmap[k-dfs[1]+1] then openmap[k-dfs[1]+1] = {} end
  114.                                 if not openmap[k-dfs[1]+1][k2-dfs[2]+yy+1] then openmap[k-dfs[1]+1][k2-dfs[2]+yy+1] = {} end
  115.                                 openmap[k-dfs[1]+1][k2-dfs[2]+yy+1] = {
  116.                                     tcol = v2.tcol,
  117.                                     bcol = v2.bcol,
  118.                                     sym = v2.sym
  119.                                 }
  120.                             end
  121.                         end
  122.                     end
  123.                 end
  124.             end
  125.             local menu = function()
  126.                 term.setCursorPos(1,1)
  127.                 term.setBackgroundColor(colors.gray)
  128.                 term.write((" "):rep(xs))
  129.                 term.setCursorPos(1,2)
  130.                 term.write((" "):rep(xs))
  131.                 term.setBackgroundColor(colors.black)
  132.                 win.setVisible(true)
  133.                 sleep(0.05)
  134.             end
  135.             while true do
  136.                 drawBox()
  137.                 menu()
  138.             end
  139.         end
  140.         parallel.waitForAll(menuClick,drawClick,draw)
  141.     --end
  142. end
  143.  
  144. local ok,err = pcall(mainCode)
  145. term.redirect(oldTerm)
  146. term.setTextColor(colors.white)
  147. term.setBackgroundColor(colors.black)
  148. term.clear()
  149. term.setCursorPos(1,1)
  150. if not ok then
  151.     error(err,2)
  152. end
  153.  
Add Comment
Please, Sign In to add comment