Advertisement
Guest User

ACSII ard build 5 0.36 stable by BigSHinyToys

a guest
Sep 3rd, 2012
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.53 KB | None | 0 0
  1. --[[
  2.     ASCII art editer
  3.     by Big SHiny Toys
  4.    
  5. BUG savinf files when you have too many
  6. causes a nill probblem I dont know how to fix
  7. curretnly
  8. ]]
  9. ------- varibals ---------
  10. local curX,curY = 1,1
  11. local winX,winY = term.getSize()
  12. local picX,picY
  13. local offsX,offsY = 0,0
  14. local picT = {}
  15. local MMSelset = 1
  16. local ver = 0.36 -- lazy mans edition lol XD
  17. local mode = 1  -- mode 1 is static mode 2 is moving
  18. --------- end ------------
  19. ------- functions --------
  20.  
  21. local function dialogBox(mes,yes,no,ok,cancle,mes2)
  22.     local indexer ={}
  23.     local sel2 = 1
  24.     local sel3 = 1
  25.     local with,higth = 26,6
  26.     local x13,y13 = term.getSize()
  27.     local off1 = (x13/2)-(with/2)
  28.     local off2 = (y13/2)-(higth/2)
  29.     local barier = string.rep("-",with-2)
  30.     local blank = string.rep(" ",with-2)
  31.     term.setCursorPos(off1,off2)
  32.     write("+"..barier.."+")
  33.     term.setCursorPos(off1,off2+1)
  34.     write("|"..blank.."|")
  35.     term.setCursorPos(off1,off2+2)
  36.     write("+"..barier.."+")
  37.     term.setCursorPos(off1,off2+3)
  38.     write("|"..blank.."|")
  39.     term.setCursorPos(off1,off2+4)
  40.     write("|"..blank.."|")
  41.     term.setCursorPos(off1,off2+5)
  42.     write("+"..barier.."+")
  43.     if mes ~= nil then
  44.         term.setCursorPos(off1+1,off2+1)
  45.         write(mes)
  46.     end
  47.     if mes2 ~= nil then
  48.         term.setCursorPos(off1+1,off2+3)
  49.         write(mes2)
  50.     end
  51.     if yes == 1 then table.insert(indexer,1) end
  52.     if no == 1 then table.insert(indexer,2) end
  53.     if ok == 1 then table.insert(indexer,3) end
  54.     if cancle == 1 then table.insert(indexer,4) end
  55.    
  56.     sel2 = sel3
  57.     if sel3 > table.maxn(indexer) then
  58.         sel3 = table.maxn(indexer)
  59.         sel2 = indexer[sel3]
  60.     end
  61.     if sel3 < 1 then
  62.         sel3 = 1
  63.         sel2 = indexer[1]
  64.     end
  65.     sel2 = indexer[1]
  66.     while true do
  67.         if yes == 1 then
  68.             term.setCursorPos(off1+1,off2+4)
  69.             if sel2 == 1 then
  70.                 write("[YES]")
  71.             else
  72.                 write(" YES ")
  73.             end
  74.         end
  75.         if no == 1 then
  76.             term.setCursorPos(off1+7,off2+4)
  77.             if sel2 == 2 then
  78.                 write("[NO]")
  79.             else
  80.                 write(" NO ")
  81.             end
  82.         end
  83.         if ok == 1 then
  84.             term.setCursorPos(off1+12,off2+4)
  85.             if sel2 == 3 then
  86.                 write("[OK]")
  87.             else
  88.                 write(" OK ")
  89.             end
  90.         end
  91.         if cancle == 1 then
  92.             term.setCursorPos(off1+17,off2+4)
  93.             if sel2 == 4 then
  94.                 write("[CANCLE]")
  95.             else
  96.                 write(" CANCLE ")
  97.             end
  98.         end
  99.             e,e1,e2,e3,e4,e5 = os.pullEvent()
  100.         if e == "key" then
  101.             if e1 == 203 then -- left
  102.                 sel3 = sel3-1
  103.             end
  104.             if e1 == 205 then -- right
  105.                 sel3 = sel3+1
  106.             end
  107.             if e1 == 28 then -- enter
  108.                 if indexer[sel3] == 1 then return true end
  109.                 if indexer[sel3] == 2 then return false end
  110.                 return indexer[sel3]
  111.             end
  112.         end
  113.         sel2 = sel3
  114.         if sel3 > table.maxn(indexer) then
  115.             sel3 = table.maxn(indexer)
  116.             sel2 = indexer[sel3]
  117.         end
  118.         if sel3 < 1 then
  119.             sel3 = 1
  120.             sel2 = indexer[1]
  121.         end
  122.     end
  123. end
  124.  
  125. local function help()
  126.     term.clear()
  127.     term.setCursorPos(1,1)
  128.     write([[Use the direction keys to navigate menues and select size of new picture.
  129. To load a new picture use the up down keys to select the right file. Folders are represented by [] pressing Enter will open that folder. Using the \\ option will return you one directry back. Ounce selected you will be promped to confirm use keys to and enter to make elsection. To exit file selection without selecting a file press Ctrl key.
  130. when the new file is made or loaded the screen will clear and the  direction keys will move the cursor around the screen. pressing and ASCII charicter like "k" or "^" will make it apear on screen. the picture can be saved by pressing Ctrl and selecting save. you will need to select a file to over write or select the blank space bellow the list and use Tab to enyer a file name.
  131. That is about it have fun with ASCII art.
  132.     Press Enter to return.]])
  133.     local event,var
  134.     while true do
  135.         event,var = os.pullEvent()
  136.         if event == "key" and var == 28 then
  137.             return
  138.         end
  139.     end
  140. end
  141.  
  142. local function redrawfull()
  143.     term.setCursorBlink(false)
  144.     term.clear()
  145.     winX,winY = term.getSize()
  146.     for i = 1 , winX - 2 do
  147.         for v = 1 , winY - 1 do
  148.             term.setCursorPos(i,v)
  149.             if picT[i+offsX] == nil then
  150.             elseif picT[i+offsX][v+offsY] ~= nil then
  151.                 write(picT[i+offsX][v+offsY])
  152.             end
  153.         end
  154.     end
  155.     local scBar = math.floor(((offsY+1)/(picY-winY+1))*(winY-1))
  156.     for i = 1,winY-1 do
  157.         term.setCursorPos(winX-1,i)
  158.         if scBar == i then
  159.             write("#")
  160.         else
  161.             write("|")
  162.         end
  163.     end
  164.     scBar = math.floor(((offsX+1)/(picX-winX+2))*(winX-2))
  165.     for i = 1,winX-2 do
  166.         term.setCursorPos(i,winY)
  167.         if scBar == i then
  168.             write("#")
  169.         else
  170.             write("-")
  171.         end
  172.     end
  173.     term.setCursorBlink(true)
  174. end
  175.  
  176. local function CustomExit()
  177.     term.clear()
  178.     winX,winY = term.getSize()
  179.     term.setCursorPos((winX/2)-(string.len("Thank you for trying ASCII art")/2),(winY/2)-1)
  180.     write("Thank you for trying ASCII art")
  181.     term.setCursorPos((winX/2)-(string.len("Idear from Troll")/2),(winY/2))
  182.     write("Idear from Troll")
  183.     term.setCursorPos((winX/2)-(string.len("By Big SHiny Toys")/2),(winY/2)+1)
  184.     write("By Big SHiny Toys")
  185.     sleep(2)
  186.     term.clear()
  187.     term.setCursorPos(1,1)
  188.     error()
  189. end
  190.  
  191. local function fileList(mode)
  192.     local parth = {}
  193.     local sParth
  194.     local list = {}
  195.     local x12,y12 = term.getSize()
  196.     local sel = 3
  197.     local curent
  198.     local offset = 0
  199.     local flot = 0
  200.     local fileName
  201.    
  202.     local function pointer() -- yes it points lol XD
  203.         if sel > y12-2 then
  204.             sel = y12-2
  205.             offset = offset+1
  206.         end
  207.        
  208.         if sel < 3 then
  209.             sel = 3
  210.             offset = offset-1
  211.         end
  212.         if offset < 0 then offset = 0 end
  213.         term.setCursorPos(1,sel)
  214.         write(">")
  215.     end
  216.    
  217.     local function top()
  218.         sParth = [[\]]
  219.         for i = 1,table.maxn(parth) do
  220.             sParth = sParth..parth[i]..[[\]]
  221.         end
  222.         list = fs.list(sParth)
  223.         term.setCursorPos(1,1)
  224.         write("Dir: "..sParth)
  225.         local barier = string.rep("-",x12-2)
  226.         term.setCursorPos(1,2)
  227.         write(barier)
  228.     end
  229.    
  230.     local function middle()
  231.         local counter
  232.         local specal
  233.         local folder = {}
  234.         local file = {}
  235.         local this = nil
  236.         for i = 1, table.maxn(list) do
  237.             if fs.isDir(sParth..list[i]) then
  238.                 table.insert(folder,list[i])
  239.             else
  240.                 table.insert(file,list[i])
  241.             end
  242.         end
  243.         table.sort(folder)
  244.         table.sort(file)
  245.         table.insert(folder,1,[[\\]])
  246.         if offset > table.maxn(folder)+table.maxn(file)- (y12-5) then
  247.         offset = table.maxn(folder)+table.maxn(file)- (y12-5)
  248.         end
  249.         if offset < 0 then
  250.         offset = 0
  251.         end
  252.         for i = 1 , y12-4 do
  253.             if i+offset < table.maxn(folder)+1 then
  254.                 term.setCursorPos(3,i+2)
  255.                 this = folder[i+offset]
  256.                 write("[] "..folder[i+offset])
  257.                 counter = i
  258.             else
  259.                 if counter == nil then
  260.                     counter = 0
  261.                     flot = offset - table.maxn(folder)
  262.                 end
  263.                 if i-counter+flot < table.maxn(file)+1 then
  264.                 term.setCursorPos(3,i+2)
  265.                 this = file[i-counter+flot]
  266.                 write("   "..file[i-counter+flot])
  267.                 end
  268.             end
  269.             if i+2 == sel then curent = this
  270.             end
  271.             this = nil
  272.         end
  273.     end
  274.  
  275.     local function bottom()
  276.         local barier = string.rep("-",x12-2)
  277.         term.setCursorPos(1,y12-1)
  278.         write(barier)
  279.         term.setCursorPos(1,y12)
  280.         write("File Name: "..tostring(fileName))
  281.         term.setCursorPos(x12-string.len(tostring(curent))-1,y12)
  282.         write(tostring(curent))
  283.     end
  284.    
  285.     while true do
  286.         term.clear()
  287.         top()
  288.         pointer()
  289.         middle()
  290.         bottom()
  291.         e,e1,e2,e3,e4,e5 = os.pullEvent()
  292.         if e == "key" then
  293.             if e1 == 200 then -- up key
  294.                 sel = sel-1
  295.             end
  296.             if e1 == 208 then -- down key
  297.                 sel = sel+1
  298.             end
  299.             if e1 == 15 then -- tab
  300.                 term.setCursorPos(1,y12)
  301.                 term.clearLine()
  302.                 write("File Name: ")
  303.                 term.setCursorPos(12,y12)
  304.                 fileName = io.read()
  305.                 specal = true
  306.             end
  307.             if e1 == 29 then -- Ctrl
  308.                 if dialogBox("Message",1,1,0,0,"Exit file select") then
  309.                     return
  310.                 end
  311.             end
  312.             if e1 == 28 or specal then -- enter key
  313.                 if curent == [[\\]] then
  314.                     table.remove(parth)
  315.                 else
  316.                     if curent ~= nil then
  317.                         if fs.isDir(sParth..curent) then
  318.                             table.insert(parth,curent)
  319.                         end
  320.                     end
  321.                     if mode == "save" then
  322.                         if fs.isDir(sParth..tostring(curent)) or curent == [[\\]] then
  323.                         else
  324.                             if fileName == nil and curent == nil then
  325.                                     dialogBox("Enter a Name",0,0,1,0,"press Tab to add name")
  326.                             else
  327.                                 if fs.exists(sParth..tostring(curent)) and curent ~= nil then
  328.                                     if fs.isReadOnly(sParth..tostring(curent)) then
  329.                                             dialogBox("Error",0,0,1,0,"File is read only")
  330.                                         else
  331.                                         if dialogBox("Confirm OVER WRITE",1,1,0,0,"Save as:"..tostring(sParth)..tostring(curent)) then
  332.                                             return sParth..curent
  333.                                         end
  334.                                     end
  335.                                 else
  336.                                     if dialogBox("Confirm",1,1,0,0,"Save as:"..tostring(sParth)..tostring(fileName)) then
  337.                                         return sParth..fileName
  338.                                     end
  339.                                 end
  340.                             end
  341.                         end
  342.                     end
  343.                     if mode == "load" then
  344.                         if curent ~= nil then
  345.                             if fs.isDir(sParth..curent) then
  346.                                 else
  347.                                 if dialogBox("confirm",1,1,0,0,"load :"..sParth..curent) then
  348.                                     return sParth..curent
  349.                                 else
  350.                                 end
  351.                             end
  352.                         else
  353.                         dialogBox("Error",0,0,1,0,"No file selected")
  354.                         end
  355.                     end
  356.                 end
  357.                 specal = false
  358.             end
  359.         end
  360.     end
  361. end
  362.  
  363. local function clear()
  364.     local size = table.maxn(picT)
  365.     if size == 0 then
  366.         return
  367.     end
  368.     local size2 = table.maxn(picT[1])
  369.     for i = 1, size do
  370.         for b = 1, size2 do
  371.             picT[i][b] = nil
  372.         end
  373.         table.remove(picT[i])
  374.     end
  375. end
  376.  
  377. local function specialSave() -- exports image
  378.     local A = string.char(91)
  379.     local B = string.char(93)
  380.     local D = ","
  381.     local C = "}"
  382.     local fileLocation = fileList("save")
  383.     local contence = ""
  384.     if fileLocation ~= nil then
  385.         local x = picX
  386.         local y = picY
  387.             local builder = [[local tImage = {]]
  388.             for v = 1 , y do
  389.                 for i = 1 , x do
  390.                     contence = contence..picT[i][v]
  391.                 end
  392.                 if v == y then
  393.                     builder = builder..A..A..contence..B..B..C.."\n"
  394.                 else
  395.                     builder = builder..A..A..contence..B..B..D.."\n"
  396.                 end
  397.                 contence = ""
  398.             end
  399.         local file = fs.open(fileLocation,"w")
  400.         file.write(builder)
  401.         file.close()
  402.         contence = ""
  403.         dialogBox("Mesage",0,0,1,0,"Save Completed")
  404.         return true
  405.     end
  406.     dialogBox("Error",0,0,1,0,"Failed to save")
  407.     return false
  408. end
  409.  
  410. local function save() -- come up with format add that
  411.     local fileLocation = fileList("save")
  412.     local contence = ""
  413.     if fileLocation ~= nil then
  414.         local x = picX
  415.         local y = picY
  416.             for v = 1 , y do
  417.                 for i = 1 , x do
  418.                     contence = contence..picT[i][v]
  419.                 end
  420.                 if v == y then
  421.                 else
  422.                     contence = contence.."\n"
  423.                 end
  424.             end
  425.         local file = fs.open(fileLocation,"w")
  426.         file.write(contence)
  427.         file.close()
  428.         contence = ""
  429.         dialogBox("Mesage",0,0,1,0,"Save Completed")
  430.         return true
  431.     end
  432.     dialogBox("Error",0,0,1,0,"Failed to save")
  433.     return false
  434. end
  435.  
  436. local function load() -- come up with format add that
  437.     local fileLocation = fileList("load")
  438.     local contence = {}
  439.     local sLine
  440.     local allGood = true
  441.     if fileLocation ~= nil then
  442.         if fs.exists(fileLocation) then
  443.             local file = io.open( fileLocation, "r" )
  444.             sLine = file:read()
  445.             table.insert( contence, sLine )
  446.             sLine = file:read()
  447.             while sLine do
  448.                 if string.len(tostring(contence[1])) == string.len(tostring(sLine)) then
  449.                     table.insert( contence, sLine )
  450.                 else
  451.                     allGood = false
  452.                     break
  453.                 end
  454.                 sLine = file:read()
  455.                 if sLine == nil then break end
  456.             end
  457.         file:close()
  458.         end
  459.         if allGood then
  460.             clear()
  461.             local x = string.len(contence[1])
  462.             local y = table.maxn(contence)
  463.             picX,picY = x,y
  464.             for i = 1 , x do
  465.                 picT[i] = {}
  466.                 for v = 1 , y do
  467.                     picT[i][v] = string.sub(contence[v],i,i)
  468.                 end
  469.             end
  470.             dialogBox("Mesage",0,0,1,0,"File loaded")
  471.             return true
  472.         else
  473.             dialogBox("Error",0,0,1,0,"Not ACSCII art file")
  474.             return false
  475.         end
  476.     end
  477. end
  478.  
  479. local function Newgrid(x,y)
  480.     for i = 1 , x do
  481.         picT[i] = {}
  482.         for v = 1 , y do
  483.             picT[i][v] = " "
  484.         end
  485.     end
  486. end
  487.  
  488. local function newSelect()
  489.     local xTemp,yTemp = 1,1
  490.     local pos = 1
  491.     local sizex,sizey = term.getSize()
  492.     while true do
  493.         if pos > 4 then pos = 1 end
  494.         if pos < 1 then pos = 4 end
  495.         --if xTemp > sizex-2 then xTemp = sizex-2 end
  496.         --if xTemp < 1 then xTemp = 1 end
  497.         --if yTemp > sizey-2 then yTemp = sizey-2 end
  498.         --if yTemp < 1 then yTemp = 1 end
  499.         term.clear()
  500.         term.setCursorPos(1,1)
  501.         write("Please select size")
  502.         term.setCursorPos(1,3)
  503.         write("Size X : ")
  504.         if pos == 1 then write("< "..xTemp.." > ".."Recomended: "..tostring(sizex-2))
  505.         else
  506.             write("  "..xTemp.."   ".."Recomended: "..tostring(sizex-2))
  507.         end
  508.         term.setCursorPos(1,4)
  509.         write("Size Y : ")
  510.         if pos == 2 then write("< "..yTemp.." > ".."Recomended: "..tostring(sizey-2))
  511.         else
  512.             write("  "..yTemp.."   ".."Recomended: "..tostring(sizey-2))
  513.         end
  514.         term.setCursorPos(1,5)
  515.         if pos == 3 then write(" [Create] ")
  516.         else
  517.             write("  Create  ")
  518.         end
  519.         term.setCursorPos(1,6)
  520.         if pos == 4 then write(" [Return] ")
  521.         else
  522.             write("  Return  ")
  523.         end
  524.         while true do
  525.             e,e1 = os.pullEvent()
  526.             if e == "key" then
  527.                 if e1 == 200 then -- up
  528.                     pos = pos-1
  529.                     break
  530.                 end
  531.                 if e1 == 208 then -- down
  532.                     pos = pos+1
  533.                     break
  534.                 end
  535.                 if e1 == 203 then -- left
  536.                     if pos == 1 then
  537.                         xTemp = xTemp - 1
  538.                     end
  539.                     if pos == 2 then
  540.                         yTemp = yTemp - 1
  541.                     end
  542.                     break
  543.                 end
  544.                 if e1 == 205 then -- right
  545.                     if pos == 1 then
  546.                         xTemp = xTemp + 1
  547.                     end
  548.                     if pos == 2 then
  549.                         yTemp = yTemp + 1
  550.                     end
  551.                     break
  552.                 end
  553.                 if e1 == 28 then -- enter
  554.                     if pos == 3 then
  555.                         Newgrid(xTemp,yTemp)
  556.                         picX,picY = xTemp,yTemp
  557.                         return true
  558.                     end
  559.                     if pos == 4 then
  560.                         return false
  561.                     end
  562.                 end
  563.             end
  564.         end
  565.     end
  566. end
  567.  
  568. local function clearGrid()
  569.     local x = table.maxn(picT)
  570.     local y = table.maxn(picT[1])
  571.     for i = 1 , x do
  572.         for v = 1 , y do
  573.             picT[i][v] = " "
  574.         end
  575.     end
  576. end
  577.  
  578. local function menue2() -- save - load - new - exit 6 lines
  579.     local crnX,crnY = term.getSize()
  580.     local selected = 6
  581.     while true do
  582.         if selected > 7 then selected = 1
  583.         end
  584.         if selected < 1 then selected = 7
  585.         end
  586.         term.setCursorPos(crnX-9,crnY-8)
  587.         write("+-------+")
  588.         term.setCursorPos(crnX-9,crnY-7)
  589.         if selected == 6 then write("|> Mod "..mode.."|") else write("|  Mod "..mode.."|") end --new
  590.         term.setCursorPos(crnX-9,crnY-6)
  591.         if selected == 7 then write("|> EXPO |") else write("|  EXPO |") end
  592.         term.setCursorPos(crnX-9,crnY-5)
  593.         if selected == 1 then write("|> Save |") else write("|  Save |") end
  594.         term.setCursorPos(crnX-9,crnY-4)
  595.         if selected == 2 then write("|> Load |") else write("|  Load |") end
  596.         term.setCursorPos(crnX-9,crnY-3)
  597.         if selected == 3 then write("|> New  |") else write("|  New  |") end
  598.         term.setCursorPos(crnX-9,crnY-2)
  599.         if selected == 4 then write("|> Clear|") else write("|  Clear|") end
  600.         term.setCursorPos(crnX-9,crnY-1)
  601.         if selected == 5 then write("|> Exit |") else write("|  Exit |") end
  602.         term.setCursorPos(crnX-9,crnY)
  603.         write("+-------+")
  604.         while true do
  605.             e,e1,e2,e3,e4,e5 = os.pullEvent()
  606.             if e == "key" then
  607.                 if e1 == 200 then -- up key
  608.                     selected = selected-1
  609.                     break
  610.                 end
  611.                 if e1 == 208 then -- down key
  612.                     selected = selected+1
  613.                     break
  614.                 end
  615.                 if e1 == 203 then -- left key
  616.                     if selected == 6 then
  617.                         mode = 1
  618.                     end
  619.                     break
  620.                 end
  621.                 if e1 == 205 then -- right key
  622.                     if selected == 6 then
  623.                         mode = 2
  624.                     end
  625.                     break
  626.                 end
  627.                 if e1 == 29 then -- Ctrl
  628.                     return
  629.                 end
  630.                 if e1 == 28 then -- enter key
  631.                     if selected == 3 then --  new
  632.                         if newSelect() then
  633.                             return
  634.                         else
  635.                             break
  636.                         end
  637.                     end
  638.                     if selected == 6 then -- new
  639.                         return
  640.                     end
  641.                     if selected == 5 then
  642.                         CustomExit()
  643.                         return
  644.                     end
  645.                     if selected == 4 then
  646.                         clearGrid()
  647.                         return
  648.                     end
  649.                     if selected == 1 then -- neds work
  650.                         save()
  651.                         return
  652.                     end
  653.                     if selected == 2 then -- neds work
  654.                         load()
  655.                         return
  656.                     end
  657.                     if selected == 7 then
  658.                         specialSave()
  659.                         return
  660.                     end
  661.                 end
  662.             end
  663.         end
  664.     end
  665. end
  666.  
  667. ---------- end -----------
  668.  
  669. ------- Main Menue -------
  670. -- load - new - help - exit
  671. local function Mmenue()
  672.     MMSelset = 1
  673.     local s1 = "ASCII Art ver "..ver
  674.     local s2 = "--- Main Menue ---"
  675.     while true do
  676.         if MMSelset > 4 then MMSelset = 1
  677.         end
  678.         if MMSelset < 1 then MMSelset = 4
  679.         end
  680.         winX,winY = term.getSize()
  681.         term.clear()
  682.         term.setCursorPos((winX/2)-(string.len(s1)/2),1)
  683.         write(s1)
  684.         term.setCursorPos((winX/2)-(string.len(s2)/2),3)
  685.         write(s2)
  686.         term.setCursorPos((winX/2)-(string.len("  Load  ")/2),5)
  687.         if MMSelset == 1 then
  688.             write("> Load <")
  689.         else
  690.             write("  Load  ")      
  691.         end
  692.         term.setCursorPos((winX/2)-(string.len("  new  ")/2),6)
  693.         if MMSelset == 2 then
  694.             write("> New <")
  695.         else
  696.             write("  New  ")       
  697.         end
  698.         term.setCursorPos((winX/2)-(string.len("  Help  ")/2),7)
  699.         if MMSelset == 3 then
  700.             write("> Help <")
  701.         else
  702.             write("  Help  ")      
  703.         end
  704.         term.setCursorPos((winX/2)-(string.len("  Exit  ")/2),8)
  705.         if MMSelset == 4 then
  706.             write("> Exit <")
  707.         else
  708.             write("  Exit  ")      
  709.         end
  710.        
  711.         while true do
  712.             e,e1,e2,e3,e4,e5 = os.pullEvent()
  713.             if e == "key" then
  714.                 if e1 == 200 then -- up key
  715.                     MMSelset = MMSelset-1
  716.                     break
  717.                 end
  718.                 if e1 == 208 then -- down key
  719.                     MMSelset = MMSelset+1
  720.                     break
  721.                 end
  722.                 if e1 == 28 then -- enter key
  723.                     if MMSelset == 1 then
  724.                         if load() then
  725.                             return
  726.                         else
  727.                             break
  728.                         end
  729.                     end
  730.                    
  731.                     if MMSelset == 2 then -- new
  732.                         if newSelect() then
  733.                             return
  734.                         else
  735.                             break
  736.                         end
  737.                     end
  738.                    
  739.                     if MMSelset == 3 then -- will be help section
  740.                         help()
  741.                         break
  742.                     end
  743.                    
  744.                     if MMSelset == 4 then
  745.                         CustomExit()
  746.                     end
  747.                 end
  748.             end
  749.         end
  750.     end
  751. end
  752. ---------- end -----------
  753.  
  754. ------- Main loop --------
  755. Mmenue()
  756. redrawfull()
  757. curX,curY = 1,1
  758. term.setCursorBlink(true)
  759. term.setCursorPos(curX,curY)
  760. while true do
  761.     e,e1,e2,e3,e4,e5 = os.pullEvent()
  762.     if e == "key" then
  763.         if e1 == 200 then -- up key
  764.             curY = curY -1
  765.         end
  766.         if e1 == 29 then -- Ctrl key
  767.             term.setCursorBlink(false)
  768.             menue2()
  769.             redrawfull()
  770.             term.setCursorPos(curX,curY)
  771.             term.setCursorBlink(true)
  772.         end
  773.         if e1 == 208 then -- down key
  774.             curY = curY +1
  775.         end
  776.         if e1 == 203 then -- left key
  777.             curX = curX-1
  778.         end
  779.         if e1 == 205 then -- right key
  780.             curX = curX+1
  781.         end
  782.         if e1 == 14 then -- backspace
  783.             if mode == 2 then
  784.                 if curX-1 >= 1 then
  785.                     curX = curX-1
  786.                 else
  787.                     if curY-1 <= 1 then
  788.                         curX,curY = picX,curY-1
  789.                     end
  790.                 end
  791.                 picT[curX][curY] = " "
  792.                 term.setCursorPos(curX,curY)
  793.                 write(picT[curX][curY])
  794.             end
  795.         end
  796.        
  797.         if curX > winX-2 then
  798.             curX = winX-2
  799.             offsX = offsX+1
  800.             redrawfull()
  801.         elseif curX < offsX then
  802.             curX = 1
  803.             offsX = offsX-1
  804.             redrawfull()
  805.         end
  806.        
  807.         term.setCursorPos(curX,curY)
  808.        
  809.         if curX > picX-offsX-1 then
  810.             curX = picX-offsX
  811.         elseif curX < 1 then
  812.             curX = 1
  813.         end
  814.        
  815.         term.setCursorPos(curX,curY)
  816.        
  817.         if curY > winY-1 then
  818.             curY = winY -1
  819.             offsY = offsY+1
  820.             redrawfull()
  821.         elseif curY < offsY then
  822.             curY = 1
  823.             offsY = offsY-1
  824.             redrawfull()
  825.         end
  826.        
  827.         term.setCursorPos(curX,curY)
  828.        
  829.         if curY > picY-offsY-1 then
  830.             curY = picY-offsY
  831.         elseif curY < 1 then
  832.             curY = 1
  833.         end
  834.        
  835.         term.setCursorPos(curX,curY)
  836.     end
  837.     if e == "char" then
  838.         picT[curX+offsX][curY+offsY] = e1
  839.         write(picT[curX+offsX][curY+offsY])
  840.         if mode == 1 then
  841.         end
  842.         if mode == 2 then
  843.             if curX+1 > picX then
  844.                 if curY+1 <= picY then
  845.                     curX,curY = 1,curY+1
  846.                 end
  847.             else
  848.                 curX,curY = curX+1,curY
  849.             end
  850.         end
  851.         term.setCursorPos(curX,curY)
  852.     end
  853. end
  854. ---------- end -----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement