Advertisement
Guest User

ASCII art build 4 ver 0.35 by Big SHiny Toys

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