SHOW:
|
|
- or go back to the newest paste.
| 1 | --КОНСТАНТЫ-- | |
| 2 | - | os.loadAPI("System/API/context")
|
| 2 | + | local APIs_DESTINATION = "MineCodeAPIs/" |
| 3 | - | local versionOfMineCode = 0.4 |
| 3 | + | local PERMANENT_INDENT = 1 |
| 4 | ||
| 5 | - | local currentProjectName = "" |
| 5 | + | --ЗАГРУЗКА СТОРОННИХ БИБЛИОТЕК, ПЕРВОНАЧАЛЬНАЯ ИНИЦИАЛИЗАЦИЯ ПРОГРАММЫ-- |
| 6 | - | local computerLabel = os.getComputerLabel() |
| 6 | + | --os.loadAPI(apis_path .. "graphics") |
| 7 | - | if computerLabel == nil then computerLabel = "unknown user" end |
| 7 | + | os.loadAPI(APIs_DESTINATION .. "SyntaxHighlight") |
| 8 | - | local xSize,ySize = term.getSize() |
| 8 | + | |
| 9 | - | local Strings = {}
|
| 9 | + | --if (os.version() ~= "CraftOS 1.6") then error("Require " .. os.version() .. ".") end
|
| 10 | - | local numberOfStrings = #Strings |
| 10 | + | |
| 11 | ||
| 12 | - | local Obj = {}
|
| 12 | + | term.clear() |
| 13 | - | local function newObj(name,x1,y1,width,height) |
| 13 | + | |
| 14 | - | Obj[name]={}
|
| 14 | + | --ПЕРЕМЕННЫЕ-- |
| 15 | - | Obj[name]["x1"]=x1 |
| 15 | + | local sizeOfLineCounter = 1 |
| 16 | - | Obj[name]["y1"]=y1 |
| 16 | + | |
| 17 | - | Obj[name]["x2"]=x1+width-1 |
| 17 | + | local termWidth, termHeight = term.getSize() |
| 18 | - | Obj[name]["y2"]=y1+height-1 |
| 18 | + | local xAbsoluteCursor, yAbsoluteCursor = 4, 1 |
| 19 | local xPrevDeltaCursor, yPrevDeltaCursor = 0, 0 | |
| 20 | local xDeltaCursor, yDeltaCursor = 0, 0 | |
| 21 | - | local function centerText(how,coord,text,textColor,backColor) |
| 21 | + | |
| 22 | - | term.setTextColor(textColor) |
| 22 | + | local linesArray = {}
|
| 23 | - | term.setBackgroundColor(backColor) |
| 23 | + | local editedLine = nil |
| 24 | - | if how == "xy" then |
| 24 | + | |
| 25 | - | term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2)) |
| 25 | + | local GUIWindow = window.create(term.current(), 1, 1, termWidth-1, termHeight-1) |
| 26 | - | elseif how == "x" then |
| 26 | + | GUIWindow.clear() |
| 27 | - | term.setCursorPos(math.floor(xSize/2-#text/2),coord) |
| 27 | + | |
| 28 | - | elseif how == "y" then |
| 28 | + | local LineCounterWindow = window.create(term.current(), 1, 3, sizeOfLineCounter, termHeight-2) |
| 29 | - | term.setCursorPos(coord,math.floor(ySize/2)) |
| 29 | + | LineCounterWindow.clear() |
| 30 | ||
| 31 | - | term.write(text) |
| 31 | + | local WorkspaceWindow = window.create(term.current(), sizeOfLineCounter+1, 3, termWidth-1, termHeight-2) |
| 32 | WorkspaceWindow.setCursorPos(xAbsoluteCursor, yAbsoluteCursor) | |
| 33 | WorkspaceWindow.clear() | |
| 34 | - | local function square(x1,y1,xSize,ySize,color) |
| 34 | + | local workspaceWidth, workspaceHeight = WorkspaceWindow.getSize() |
| 35 | - | for y=y1,(y1+ySize-1) do |
| 35 | + | |
| 36 | - | for x=x1,(x1+xSize-1) do |
| 36 | + | --РАБОТА С ФАЙЛАМИ-- |
| 37 | - | paintutils.drawPixel(x,y,color) |
| 37 | + | local function openFile(filename) |
| 38 | for readedLine in io.lines(filename) do | |
| 39 | table.insert(linesArray, readedLine) | |
| 40 | end | |
| 41 | ||
| 42 | - | local function clearScreen(color) |
| 42 | + | editedLine = linesArray[1] |
| 43 | - | term.setBackgroundColor(color) |
| 43 | + | |
| 44 | - | term.clear() |
| 44 | + | |
| 45 | local function saveFile(filename) | |
| 46 | local _file = fs.open(filename, "w") | |
| 47 | - | local function fadeIn(time) |
| 47 | + | |
| 48 | - | clearScreen(colors.gray) |
| 48 | + | for i = 1, #linesArray do |
| 49 | - | sleep(time) |
| 49 | + | _file.writeLine(linesArray[i]) |
| 50 | - | clearScreen(colors.lightGray) |
| 50 | + | |
| 51 | - | sleep(time) |
| 51 | + | |
| 52 | - | clearScreen(colors.white) |
| 52 | + | _file.close() |
| 53 | - | sleep(time) |
| 53 | + | |
| 54 | ||
| 55 | --ОТРИСОВКА-- | |
| 56 | - | local function fadeOut(time) |
| 56 | + | local function draw_gui() |
| 57 | - | clearScreen(colors.lightGray) |
| 57 | + | |
| 58 | - | sleep(time) |
| 58 | + | |
| 59 | - | clearScreen(colors.gray) |
| 59 | + | |
| 60 | - | sleep(time) |
| 60 | + | local function draw_line(wWindow, iLine) |
| 61 | - | clearScreen(colors.black) |
| 61 | + | WorkspaceWindow.setBackgroundColor(colors.white) |
| 62 | - | sleep(time) |
| 62 | + | WorkspaceWindow.setTextColor(colors.black) |
| 63 | - | term.setCursorPos(1,1) |
| 63 | + | WorkspaceWindow.setCursorPos(PERMANENT_INDENT, iLine) |
| 64 | - | term.setTextColor(colors.white) |
| 64 | + | |
| 65 | local _tmpLine = linesArray[yDeltaCursor+iLine]:sub(xDeltaCursor+1, -1) | |
| 66 | ||
| 67 | - | local function drawButton(x,y,text,textColor,backColor) |
| 67 | + | WorkspaceWindow.write(" " .. _tmpLine .. string.rep(" ", workspaceWidth-1))
|
| 68 | - | square(x,y,#text+2,1,backColor) |
| 68 | + | |
| 69 | - | term.setCursorPos(x+1,y) |
| 69 | + | SyntaxHighlight.syntaxString(WorkspaceWindow, iLine, PERMANENT_INDENT+1, _tmpLine) |
| 70 | - | term.setTextColor(textColor) |
| 70 | + | |
| 71 | - | term.write(text) |
| 71 | + | |
| 72 | - | newObj(text,x,y,#text+2,1) |
| 72 | + | local function drawLineCounter() |
| 73 | LineCounterWindow.setBackgroundColor(colors.lightGray) | |
| 74 | LineCounterWindow.setTextColor(colors.white) | |
| 75 | - | local function topBar() |
| 75 | + | LineCounterWindow.clear() |
| 76 | - | square(1,1,xSize,3,colors.lightGray) |
| 76 | + | |
| 77 | - | square(math.floor(xSize/2-10),1,20,3,colors.lightBlue) |
| 77 | + | for i = 1, #linesArray-yDeltaCursor do |
| 78 | - | drawButton(2,2,">",colors.white,colors.gray) |
| 78 | + | LineCounterWindow.setCursorPos(1, i) |
| 79 | - | drawButton(6,2,"File",colors.white,colors.gray) |
| 79 | + | |
| 80 | - | drawButton(xSize-6,2,"Exit",colors.white,colors.gray) |
| 80 | + | LineCounterWindow.write(yDeltaCursor+i .. string.rep(" ", sizeOfLineCounter))
|
| 81 | - | centerText("x",1,currentProjectName..".proj",colors.white,colors.lightBlue)
|
| 81 | + | |
| 82 | - | centerText("x",2,math.ceil(fs.getSize("Documents/MineCode/"..currentProjectName.."/"..currentProjectName..".proj")/1024).."KB",colors.white,colors.lightBlue)
|
| 82 | + | |
| 83 | - | centerText("x",3,numberOfStrings.." lines",colors.white,colors.lightBlue)
|
| 83 | + | |
| 84 | - | square(math.floor(xSize/2-10),1,1,3,colors.blue) |
| 84 | + | --draw_workspace() redraw all |
| 85 | - | square(math.floor(xSize/2+10),1,1,3,colors.blue) |
| 85 | + | --draw_workspace([startRedrawPos]) redraw startRedrawPos to workspaceHeight lines |
| 86 | --draw_workspace([startRedrawPos, [endRedrawPos]]) redraw startRedrawPos to endRedrawPos lines | |
| 87 | local function draw_workspace(startRedrawPos, endRedrawPos) | |
| 88 | - | local function displayRightScroll(stroka) |
| 88 | + | local prev_xCur, prev_yCur = WorkspaceWindow.getCursorPos() |
| 89 | - | local displayCanShow = ySize - 2 |
| 89 | + | |
| 90 | - | local showPercent = displayCanShow/numberOfStrings |
| 90 | + | WorkspaceWindow.setCursorBlink(false) |
| 91 | - | local sizeOfShowBar = math.ceil(displayCanShow*showPercent) |
| 91 | + | |
| 92 | - | local displayBarFrom = math.floor(displayCanShow*(stroka/numberOfStrings)+3) |
| 92 | + | local prevSoLC = sizeOfLineCounter |
| 93 | - | square(xSize,3,1,displayCanShow,colors.gray) |
| 93 | + | sizeOfLineCounter = #tostring(#linesArray) |
| 94 | - | square(xSize,displayBarFrom,1,sizeOfShowBar,colors.lightBlue) |
| 94 | + | |
| 95 | if prevSoLC ~= sizeOfLineCounter then | |
| 96 | WorkspaceWindow = window.create(term.current(), sizeOfLineCounter+1, 3, termWidth-1-sizeOfLineCounter, termHeight-2) | |
| 97 | - | local function stringsNumber(from) |
| 97 | + | workspaceWidth, workspaceHeight = WorkspaceWindow.getSize() |
| 98 | - | local hernyaColor = colors.gray |
| 98 | + | |
| 99 | - | local ending = from + ySize - 3 |
| 99 | + | |
| 100 | - | local sizeOfLastNumber = #tostring(ending) |
| 100 | + | for i = startRedrawPos or 1, endRedrawPos or workspaceHeight do |
| 101 | - | term.setTextColor(colors.white) |
| 101 | + | if linesArray[yDeltaCursor+i] then |
| 102 | - | term.setBackgroundColor(hernyaColor) |
| 102 | + | draw_line(WorkspaceWindow, i) |
| 103 | - | local tempLine = "" |
| 103 | + | |
| 104 | - | for i=from,ending do |
| 104 | + | WorkspaceWindow.setCursorPos(PERMANENT_INDENT, i) |
| 105 | - | tempLine = i..string.rep(" ", sizeOfLastNumber-#tostring(i))
|
| 105 | + | write(string.rep(" ", workspaceWidth))
|
| 106 | - | term.setCursorPos(1,4+i-from) |
| 106 | + | |
| 107 | - | term.write(tempLine) |
| 107 | + | |
| 108 | ||
| 109 | - | if ending > numberOfStrings then square(1,ySize-numberOfStrings,sizeOfLastNumber,ySize,hernyaColor) end |
| 109 | + | if prevSoLC ~= sizeOfLineCounter then |
| 110 | - | return sizeOfLastNumber |
| 110 | + | LineCounterWindow = window.create(term.current(), 1, 3, sizeOfLineCounter, termHeight-2) |
| 111 | draw_workspace() | |
| 112 | end | |
| 113 | - | local function displayText(leftMargin,from) |
| 113 | + | drawLineCounter() |
| 114 | - | local ending = from + ySize - 3 |
| 114 | + | |
| 115 | - | term.setBackgroundColor(colors.white) |
| 115 | + | WorkspaceWindow.setBackgroundColor(colors.white) |
| 116 | - | term.setTextColor(colors.black) |
| 116 | + | WorkspaceWindow.setTextColor(colors.black) |
| 117 | - | for i=from,ending do |
| 117 | + | WorkspaceWindow.setCursorPos(prev_xCur, prev_yCur) |
| 118 | - | if Strings[i] ~= nil then |
| 118 | + | WorkspaceWindow.setCursorBlink(true) |
| 119 | - | local tempLine = " " .. Strings[i] |
| 119 | + | |
| 120 | - | if #Strings[i]+leftMargin+2 < xSize then |
| 120 | + | |
| 121 | - | tempLine = tempLine .. string.rep(" ", xSize-#Strings[i]-leftMargin-2)
|
| 121 | + | local function range(bottom, top, value, step) |
| 122 | - | end |
| 122 | + | if value + step > top then |
| 123 | - | term.setCursorPos(leftMargin+1,4+i-from) |
| 123 | + | return top |
| 124 | - | term.write(tempLine) |
| 124 | + | elseif value + step < bottom then |
| 125 | return bottom | |
| 126 | end | |
| 127 | ||
| 128 | return value + step | |
| 129 | - | local function stringsAndText(from) |
| 129 | + | |
| 130 | - | local leftMargin = stringsNumber(from) |
| 130 | + | |
| 131 | - | displayText(leftMargin,from) |
| 131 | + | --РАБОТА С КУРСОРАМИ-- |
| 132 | local function checkEndLine() | |
| 133 | return xAbsoluteCursor + 1 > #linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1 | |
| 134 | - | local function save(path) |
| 134 | + | |
| 135 | - | local f = fs.open(path,"w") |
| 135 | + | |
| 136 | - | for i=1,#Strings do |
| 136 | + | local function checkStartLine() |
| 137 | - | f.writeLine(Strings[i]) |
| 137 | + | return xAbsoluteCursor - 1 < PERMANENT_INDENT + 1 |
| 138 | end | |
| 139 | - | f.close() |
| 139 | + | |
| 140 | local function checkTopLinesArray() | |
| 141 | return yAbsoluteCursor - 1 < 1 | |
| 142 | - | local function welcome() |
| 142 | + | |
| 143 | - | paintutils.drawImage(paintutils.loadImage("System/MineCode/logo.png"), math.floor(xSize/2-5), 2)
|
| 143 | + | |
| 144 | - | local startY = 10 |
| 144 | + | local function checkBottomLinesArray() |
| 145 | - | local sizeOfButton = 28 |
| 145 | + | return yAbsoluteCursor + 1 > #linesArray |
| 146 | - | centerText("x",startY,"Welcome to MineCode",colors.gray,colors.white)
|
| 146 | + | |
| 147 | - | centerText("x",startY+1,"Version "..versionOfMineCode,colors.lightGray,colors.white)
|
| 147 | + | |
| 148 | - | centerText("x",startY+4,string.rep("-",sizeOfButton),colors.lightGray,colors.white)
|
| 148 | + | |
| 149 | - | centerText("x",startY+5,"Create new project",colors.gray,colors.white)
|
| 149 | + | |
| 150 | - | newObj("New",math.floor(xSize/2-sizeOfButton/2),startY+5,sizeOfButton,1)
|
| 150 | + | local function calculateCursors(xRelCur, yRelCur) |
| 151 | - | centerText("x",startY+6,string.rep("-",sizeOfButton),colors.lightGray,colors.white)
|
| 151 | + | WorkspaceWindow.setCursorPos(xRelCur, yRelCur) |
| 152 | - | centerText("x",startY+7,"Open existing project",colors.gray,colors.white)
|
| 152 | + | |
| 153 | - | newObj("Open",math.floor(xSize/2-sizeOfButton/2),startY+7,sizeOfButton,1)
|
| 153 | + | xPrevDeltaCursor = xDeltaCursor |
| 154 | - | centerText("x",startY+8,string.rep("-",sizeOfButton),colors.lightGray,colors.white)
|
| 154 | + | yPrevDeltaCursor = yDeltaCursor |
| 155 | ||
| 156 | - | local action = 1 |
| 156 | + | xDeltaCursor = xAbsoluteCursor - xRelCur |
| 157 | - | while true do |
| 157 | + | yDeltaCursor = yAbsoluteCursor - yRelCur |
| 158 | - | local event,side,x,y = os.pullEvent("mouse_click")
|
| 158 | + | |
| 159 | - | if x>=Obj["New"]["x1"] and x<=Obj["New"]["x2"] and y>=Obj["New"]["y2"] and y<=Obj["New"]["y2"] then |
| 159 | + | |
| 160 | - | square(Obj["New"]["x1"],Obj["New"]["y1"],sizeOfButton,1,colors.lightGray) |
| 160 | + | |
| 161 | - | centerText("x",Obj["New"]["y1"],"Create new project",colors.white,colors.lightGray)
|
| 161 | + | |
| 162 | - | action = 1 |
| 162 | + | local function moveCursorsToStartLine() |
| 163 | - | break |
| 163 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 164 | - | elseif x>=Obj["Open"]["x1"] and x<=Obj["Open"]["x2"] and y>=Obj["Open"]["y2"] and y<=Obj["Open"]["y2"] then |
| 164 | + | |
| 165 | - | square(Obj["Open"]["x1"],Obj["Open"]["y1"],sizeOfButton,1,colors.lightGray) |
| 165 | + | xAbsoluteCursor = PERMANENT_INDENT + 1 |
| 166 | - | centerText("x",Obj["Open"]["y1"],"Open existing project",colors.white,colors.lightGray)
|
| 166 | + | xRelativeCursor = PERMANENT_INDENT + 1 |
| 167 | - | action = 2 |
| 167 | + | |
| 168 | - | break |
| 168 | + | calculateCursors(xRelativeCursor, yRelativeCursor) |
| 169 | end | |
| 170 | ||
| 171 | - | sleep(0.5) |
| 171 | + | local function moveCursorsToEndLine() |
| 172 | - | fadeOut(0) |
| 172 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 173 | - | fadeIn(0) |
| 173 | + | |
| 174 | - | if action == 1 then |
| 174 | + | xAbsoluteCursor = #linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1 |
| 175 | - | centerText("x",math.floor(ySize/2),"Enter product name:",colors.gray,colors.white)
|
| 175 | + | xRelativeCursor = math.min(#linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1, workspaceWidth) |
| 176 | - | term.setTextColor(colors.lightGray) |
| 176 | + | |
| 177 | - | term.setCursorPos(math.floor(xSize/2-9),math.floor(ySize/2+1)) |
| 177 | + | calculateCursors(xRelativeCursor, yRelativeCursor) |
| 178 | - | local fileName = read() |
| 178 | + | |
| 179 | - | if fileName == nil or fileName == " " or fileName == "" then fileName = "Untitled" end |
| 179 | + | |
| 180 | - | Strings = {[1]="--"..fileName..".project",[2]="--Written by "..computerLabel.." at "..textutils.formatTime(os.time(), false),[3]="",[4]="print(\"Hello world!\")",[5]="print(\"Pir lox!\")"}
|
| 180 | + | local function moveCursorsUpAndDown(step) |
| 181 | - | save("Documents/MineCode/"..fileName.."/"..fileName..".proj")
|
| 181 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 182 | - | currentProjectName = fileName |
| 182 | + | |
| 183 | - | elseif action == 2 then |
| 183 | + | yAbsoluteCursor = range(1, #linesArray, yAbsoluteCursor, step) |
| 184 | - | centerText("x",2,string.rep("-",sizeOfButton),colors.lightGray,colors.white)
|
| 184 | + | yRelativeCursor = range(1, math.min(workspaceHeight, #linesArray), yRelativeCursor, step) |
| 185 | - | for i=1,5 do |
| 185 | + | |
| 186 | - | paintutils.drawPixel(math.floor(xSize/2-sizeOfButton/2),i*2+1,colors.gray) |
| 186 | + | if checkEndLine() then |
| 187 | - | term.setCursorPos(math.floor(xSize/2-sizeOfButton/2)+2,i*2+1) |
| 187 | + | xAbsoluteCursor = #linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1 |
| 188 | - | term.setTextColor(colors.gray) |
| 188 | + | xRelativeCursor = #linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1 |
| 189 | - | term.setBackgroundColor(colors.white) |
| 189 | + | |
| 190 | - | term.write("Empty")
|
| 190 | + | |
| 191 | - | centerText("x",i*2+2,string.rep("-",sizeOfButton),colors.lightGray,colors.white)
|
| 191 | + | calculateCursors(xRelativeCursor, yRelativeCursor) |
| 192 | end | |
| 193 | ||
| 194 | - | centerText("x",startY+5,"Create new project",colors.gray,colors.white)
|
| 194 | + | local function moveCursorsRightAndLeft(step) |
| 195 | - | newObj("New",math.floor(xSize/2-sizeOfButton/2),startY+5,sizeOfButton,1)
|
| 195 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 196 | - | centerText("x",startY+6,string.rep("-",sizeOfButton),colors.lightGray,colors.white)
|
| 196 | + | |
| 197 | if step < 0 and checkStartLine() and yAbsoluteCursor > 1 then | |
| 198 | - | os.pullEvent("mouse_click")
|
| 198 | + | xAbsoluteCursor = #linesArray[yAbsoluteCursor - 1] + PERMANENT_INDENT + 2 |
| 199 | xRelativeCursor = math.min(#linesArray[yAbsoluteCursor - 1] + PERMANENT_INDENT + 2, workspaceWidth) | |
| 200 | ||
| 201 | - | fadeOut(0) |
| 201 | + | yAbsoluteCursor = yAbsoluteCursor - 1 |
| 202 | yRelativeCursor = math.max(yRelativeCursor - 1, 1) | |
| 203 | end | |
| 204 | - | ------------------------------------------------------------ |
| 204 | + | |
| 205 | - | fadeIn(0) |
| 205 | + | if step > 0 and checkEndLine() and yAbsoluteCursor < #linesArray then |
| 206 | xAbsoluteCursor = PERMANENT_INDENT | |
| 207 | - | welcome() |
| 207 | + | xRelativeCursor = PERMANENT_INDENT |
| 208 | ||
| 209 | - | fadeIn(0) |
| 209 | + | yAbsoluteCursor = yAbsoluteCursor + 1 |
| 210 | - | ------------------------------------------------------------ |
| 210 | + | yRelativeCursor = math.min(yRelativeCursor + 1, workspaceHeight) |
| 211 | end | |
| 212 | - | --if #Strings < ySize-2 then |
| 212 | + | |
| 213 | - | -- for i=1,(ySize-1-#Strings) do |
| 213 | + | xAbsoluteCursor = range(PERMANENT_INDENT + 1, #linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1, xAbsoluteCursor, step) |
| 214 | - | -- Strings[#Strings+1] = "" |
| 214 | + | xRelativeCursor = range(PERMANENT_INDENT + 1, math.min(workspaceWidth, #linesArray[yAbsoluteCursor] + PERMANENT_INDENT + 1), xRelativeCursor, step) |
| 215 | - | -- end |
| 215 | + | |
| 216 | - | -- numberOfStrings = #Strings |
| 216 | + | calculateCursors(xRelativeCursor, yRelativeCursor) |
| 217 | - | --end |
| 217 | + | |
| 218 | ||
| 219 | - | topBar() |
| 219 | + | --РЕДАКТИРОВАНЕ ТЕКСТА-- |
| 220 | - | local stringToDisplay = 1 |
| 220 | + | local function removeChar() |
| 221 | - | local contextAction = "" |
| 221 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 222 | - | stringsAndText(stringToDisplay) |
| 222 | + | |
| 223 | - | displayRightScroll(stringToDisplay) |
| 223 | + | if xAbsoluteCursor > PERMANENT_INDENT + 1 then |
| 224 | linesArray[yAbsoluteCursor] = linesArray[yAbsoluteCursor]:sub(1, xAbsoluteCursor-(PERMANENT_INDENT + 2)) .. linesArray[yAbsoluteCursor]:sub(xAbsoluteCursor-PERMANENT_INDENT, -1) | |
| 225 | xAbsoluteCursor = xAbsoluteCursor - 1 | |
| 226 | - | local event,button,x,y = os.pullEvent() |
| 226 | + | xRelativeCursor = xRelativeCursor - 1 |
| 227 | - | if event == "mouse_click" or event == "mouse_drag" then |
| 227 | + | draw_workspace(yRelativeCursor, yRelativeCursor) |
| 228 | - | if button == 1 then |
| 228 | + | elseif yAbsoluteCursor > 1 then |
| 229 | - | if x == xSize and y >= 3 and y <= ySize then |
| 229 | + | local _temp = #linesArray[yAbsoluteCursor - 1] |
| 230 | - | stringToDisplay = math.ceil((y-3)/(ySize-2) * #Strings) |
| 230 | + | |
| 231 | - | if x == xSize and y == ySize then stringToDisplay = #Strings-ySize+3 end |
| 231 | + | linesArray[yAbsoluteCursor - 1] = linesArray[yAbsoluteCursor - 1] .. linesArray[yAbsoluteCursor]:sub(xAbsoluteCursor-PERMANENT_INDENT, -1) |
| 232 | - | if stringToDisplay < 1 then stringToDisplay = 1 end |
| 232 | + | table.remove(linesArray, yAbsoluteCursor) |
| 233 | - | stringsAndText(stringToDisplay) |
| 233 | + | |
| 234 | - | displayRightScroll(stringToDisplay) |
| 234 | + | yAbsoluteCursor = yAbsoluteCursor - 1 |
| 235 | - | elseif x>=Obj["Run"]["x1"] and x<=Obj["Run"]["x2"] and y>=Obj["Run"]["y1"] and y<=Obj["Run"]["y2"] then |
| 235 | + | yRelativeCursor = math.max(yRelativeCursor - 1, 1) |
| 236 | - | drawButton(Obj["Run"]["x1"],Obj["Run"]["y1"],"Run",colors.white,colors.blue) |
| 236 | + | xAbsoluteCursor = _temp + PERMANENT_INDENT + 1 |
| 237 | - | sleep(0.3) |
| 237 | + | xRelativeCursor = math.min(_temp + PERMANENT_INDENT + 1, workspaceWidth) |
| 238 | - | fadeOut(0) |
| 238 | + | draw_workspace(yRelativeCursor, workspaceHeight) |
| 239 | - | term.setCursorPos(1,1) |
| 239 | + | |
| 240 | - | |
| 240 | + | |
| 241 | - | fs.copy("Documents/MineCode/"..string.sub(currentProjectName,1,-9).."/"..currentProjectName,"System/MineCode/temp.proj")
|
| 241 | + | calculateCursors(xRelativeCursor, yRelativeCursor) |
| 242 | - | shell.run("System/MineCode/temp.proj")
|
| 242 | + | |
| 243 | ||
| 244 | - | os.pullEvent("mouse_click")
|
| 244 | + | local function writeChar(char) |
| 245 | - | fs.delete("System/MineCode/temp.proj")
|
| 245 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 246 | linesArray[yAbsoluteCursor] = linesArray[yAbsoluteCursor]:sub(1, xAbsoluteCursor-(PERMANENT_INDENT + 1)) .. char .. linesArray[yAbsoluteCursor]:sub(xAbsoluteCursor-PERMANENT_INDENT, -1) | |
| 247 | - | fadeIn(0) |
| 247 | + | draw_workspace(yRelativeCursor, yRelativeCursor) |
| 248 | - | stringsAndText(stringToDisplay) |
| 248 | + | |
| 249 | - | displayRightScroll(stringToDisplay) |
| 249 | + | |
| 250 | - | topBar() |
| 250 | + | local function newLine() |
| 251 | - | elseif x>=Obj["Exit"]["x1"] and x<=Obj["Exit"]["x2"] and y>=Obj["Exit"]["y1"] and y<=Obj["Exit"]["y2"] then |
| 251 | + | local xRelativeCursor, yRelativeCursor = WorkspaceWindow.getCursorPos() |
| 252 | - | drawButton(Obj["Exit"]["x1"],Obj["Exit"]["y1"],"Exit",colors.white,colors.blue) |
| 252 | + | |
| 253 | - | sleep(0.3) |
| 253 | + | table.insert(linesArray, yAbsoluteCursor + 1, linesArray[yAbsoluteCursor]:sub(xAbsoluteCursor-PERMANENT_INDENT, -1)) |
| 254 | - | fadeOut() |
| 254 | + | linesArray[yAbsoluteCursor] = linesArray[yAbsoluteCursor]:sub(1, xAbsoluteCursor-(PERMANENT_INDENT + 1)) |
| 255 | - | term.setCursorPos(1,1) |
| 255 | + | |
| 256 | - | break |
| 256 | + | yAbsoluteCursor = range(1, #linesArray, yAbsoluteCursor, 1) |
| 257 | - | end |
| 257 | + | yRelativeCursor = range(1, math.min(workspaceHeight, #linesArray), yRelativeCursor, 1) |
| 258 | xAbsoluteCursor = PERMANENT_INDENT + 1 | |
| 259 | - | if x>=stringsNumber(stringToDisplay)+1 and x<=xSize-1 and y>=3 and y<=ySize then |
| 259 | + | xRelativeCursor = PERMANENT_INDENT + 1 |
| 260 | - | contextAction = context.menu(x,y,{"Cut",false},{"Copy",false},{"Paste",true},{"Clear",false},"-",{"Save",false})
|
| 260 | + | |
| 261 | - | local leftMargin = stringsNumber(stringToDisplay) |
| 261 | + | calculateCursors(xRelativeCursor, yRelativeCursor) |
| 262 | - | displayText(leftMargin,stringToDisplay) |
| 262 | + | draw_workspace(yRelativeCursor-1, workspaceHeight) |
| 263 | - | end |
| 263 | + | |
| 264 | ||
| 265 | - | elseif event == "mouse_scroll" then |
| 265 | + | --openFile("edt")
|
| 266 | - | if button == 1 then |
| 266 | + | openFile("test")
|
| 267 | - | stringToDisplay = stringToDisplay + 1 |
| 267 | + | draw_workspace() |
| 268 | ||
| 269 | - | stringToDisplay = stringToDisplay - 1 |
| 269 | + | --ГЛАВНЫЙ ЦИКЛ ПРОГРАММЫ-- |
| 270 | while true do | |
| 271 | - | if stringToDisplay < 1 then stringToDisplay = 1 end |
| 271 | + | if xDeltaCursor ~= xPrevDeltaCursor or yDeltaCursor ~= yPrevDeltaCursor then |
| 272 | - | if stringToDisplay > #Strings-ySize+3 then stringToDisplay = #Strings-ySize+3 end |
| 272 | + | draw_workspace() |
| 273 | - | stringsAndText(stringToDisplay) |
| 273 | + | |
| 274 | - | displayRightScroll(stringToDisplay) |
| 274 | + | |
| 275 | --GUIWindow.clearLine() | |
| 276 | --GUIWindow.setCursorPos(1, 1) | |
| 277 | --GUIWindow.write("xDC: " .. xDeltaCursor .. ". yDC: " .. yDeltaCursor .. ". xpDC: " .. xPrevDeltaCursor .. ". ypDC: " .. yPrevDeltaCursor)
| |
| 278 | ||
| 279 | local event, par1, par2, par3, par4 = os.pullEvent() | |
| 280 | ||
| 281 | if event == "key" then | |
| 282 | if par1 == keys.down then | |
| 283 | moveCursorsUpAndDown(1) | |
| 284 | elseif par1 == keys.up then | |
| 285 | moveCursorsUpAndDown(-1) | |
| 286 | elseif par1 == keys.left then | |
| 287 | moveCursorsRightAndLeft(-1) | |
| 288 | elseif par1 == keys.right then | |
| 289 | moveCursorsRightAndLeft(1) | |
| 290 | elseif par1 == keys.home then | |
| 291 | moveCursorsToStartLine() | |
| 292 | elseif par1 == keys["end"] then | |
| 293 | moveCursorsToEndLine() | |
| 294 | elseif par1 == keys.backspace then | |
| 295 | removeChar() | |
| 296 | elseif par1 == keys.enter then | |
| 297 | newLine() | |
| 298 | elseif par1 == keys.insert then | |
| 299 | saveFile("test")
| |
| 300 | end | |
| 301 | end | |
| 302 | ||
| 303 | if event == "char" then | |
| 304 | writeChar(par1) | |
| 305 | moveCursorsRightAndLeft(1) | |
| 306 | end | |
| 307 | end |