Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.23 KB | None | 0 0
  1. -----------------------?????? ??????????----------------------
  2. if not term.isColor() then error("This program will work only on advanced computer.") end
  3. local Args = {...}
  4. shell.run("clear")
  5. print("Loading apis from pastebin...")
  6. print("-----------------------------")
  7. print("Downloading context API...")
  8.  
  9. shell.run("pastebin get vvZveb97 context")
  10. os.loadAPI("context")
  11. fs.delete("context")
  12. print("donwloaded")
  13. print("-----------------------------")
  14.  
  15. print("Downloading image API...")
  16. shell.run("pastebin get 6gTj9LxN image")
  17. os.loadAPI("image")
  18. fs.delete("image")
  19. print("donwloaded")
  20. print("-----------------------------")
  21.  
  22. print("Downloading filemanager API...")
  23. shell.run("pastebin get JPYBYVTd filemanager")
  24. os.loadAPI("filemanager")
  25. fs.delete("filemanager")
  26. print("donwloaded")
  27. print("-----------------------------")
  28.  
  29. print("Downloading windows API...")
  30. shell.run("pastebin get D1QiSj9L windows")
  31. os.loadAPI("windows")
  32. fs.delete("windows")
  33. print("donwloaded")
  34. print("-----------------------------")
  35.  
  36. print("Loaded")
  37. print("Press any key to continue")
  38. os.pullEvent()
  39. ----------------------?????????? ??????????----------------------
  40. local xSize, ySize = term.getSize()
  41.  
  42. --?????-????????????? ???????? ???????? ???? - ??? ??? ?????? ???????, ??? ??? ????????, ?? ???????? ????
  43. --???????? ???? ?? ???????? ????????? ????? ??? ???????? ?????????? DEFAULTTERM
  44. local windowForDrawing = window.create(term.current(), 3, 2, xSize-12, ySize-1,true)
  45. local defaultTerm = term.redirect(windowForDrawing)
  46. --?????????????? ???????????? ????????? TERM
  47. term.redirect(term.native())
  48. --???????? ???? ??? ?????? ? ????????, ?????
  49. windowForDrawing = window.create(term.native(), 3, 2, xSize-12, ySize-1,true)
  50.  
  51. --??????? ????????
  52. local Obj = {}
  53. local ObjColor = {}
  54.  
  55. --?????? ????? ? ??????????? ???????????? ???????????
  56. local imageSizeX = 36
  57. local imageSizeY = 15
  58. local transparentSymbol = "+"
  59. local displayImageFromX = 4
  60. local displayImageFromY = 3
  61. local displayImageEndX = displayImageFromX + imageSizeX - 1
  62. local displayImageEndY = displayImageFromY + imageSizeY - 1
  63.  
  64. --????? ??????????? ? ???? ?????? ?????? ??? ?????????? ??????????? ? ????
  65. local Colors = {
  66. ["0"] = 1,
  67. ["1"] = 2,
  68. ["2"] = 4,
  69. ["3"] = 8,
  70. ["4"] = 16,
  71. ["5"] = 32,
  72. ["6"] = 64,
  73. ["7"] = 128,
  74. ["8"] = 256,
  75. ["9"] = 512,
  76. ["a"] = 1024,
  77. ["b"] = 2048,
  78. ["c"] = 4096,
  79. ["d"] = 8192,
  80. ["e"] = 16384,
  81. ["f"] = 32768
  82. }
  83.  
  84. --?????? ???????????? ????? ?? ?????? ????? ? ???? ?????
  85. local Blocks = {
  86. [1] = {["id"]="quartz_block",["data"]="0"},
  87. [2] = {["id"]="wool",["data"]="1"},
  88. [4] = {["id"]="wool",["data"]="2"},
  89. [8] = {["id"]="wool",["data"]="3"},
  90. [16] = {["id"]="gold_block",["data"]="0"},
  91. [32] = {["id"]="emerald_block",["data"]="0"},
  92. [64] = {["id"]="wool",["data"]="6"},
  93. [128] = {["id"]="wool",["data"]="7"},
  94. [256] = {["id"]="wool",["data"]="8"},
  95. [512] = {["id"]="wool",["data"]="9"},
  96. [1024] = {["id"]="wool",["data"]="10"},
  97. [2048] = {["id"]="wool",["data"]="11"},
  98. [4096] = {["id"]="wool",["data"]="12"},
  99. [8192] = {["id"]="wool",["data"]="13"},
  100. [16384] = {["id"]="wool",["data"]="14"},
  101. [32768] = {["id"]="wool",["data"]="15"}
  102. }
  103.  
  104. --?????? ???????? ?? ??????
  105. local Pixels = {}
  106.  
  107. --?????? ?????, ?????????? ????????????, ?????? ? ???????
  108. local currentInstrument = "B"
  109. local currentTextColor = colors.white
  110. local currentBackColor = colors.black
  111. local currentSymbol = " "
  112.  
  113. --?????? ????? ??? ????????? ?????
  114. local CommandBlockIsActive = false
  115. local commandBlockAttachedAt = ""
  116. local CommandBlock = {}
  117.  
  118. --??????? ??? ???? ????? ????????
  119. local fastFileMode = false
  120. local fastFilePath = nil
  121.  
  122. local pathForFastSaving = nil
  123.  
  124. ------------------------?????????? ???????-----------------------
  125.  
  126. --????? ????????? ? ???? ?????????? ?????. ???? ?? ???????, ?? NIL
  127. function findCommandBlock()
  128. local PeriList = peripheral.getNames()
  129. for i=1,#PeriList do
  130. if peripheral.getType(PeriList[i]) == "command" then
  131. return PeriList[i]
  132. end
  133. end
  134. end
  135.  
  136. --????????? ? ?????? ??????? ? ????????? ????
  137. local function cb(command)
  138. CommandBlock.setCommand(command)
  139. CommandBlock.runCommand()
  140. end
  141.  
  142. --????????? ????? ? ???? ????? ?? ???????????
  143. local function setBlock(x,y,id,data)
  144. cb("/setblock ~"..(x-math.floor(imageSizeX/2)).." ~"..(ySize+3-y).." ~0 minecraft:"..id.." "..data)
  145. end
  146.  
  147. --??????? ???? ???????????? ?????? ? ???? ?????
  148. local function clearAll()
  149. for x=1,xSize do
  150. for y=1,ySize do
  151. setBlock(x,y,"air","0")
  152. end
  153. end
  154. end
  155.  
  156. local function changeDisplayImageFromParameters(x,y)
  157. displayImageFromX = x
  158. displayImageFromY = y
  159. displayImageEndX = displayImageFromX + imageSizeX - 1
  160. displayImageEndY = displayImageFromY + imageSizeY - 1
  161. end
  162.  
  163. --???????? ???????? ??????
  164. local function newObj(name,x1,y1,width,height)
  165. Obj[name]={}
  166. Obj[name]["x1"]=x1
  167. Obj[name]["y1"]=y1
  168. Obj[name]["x2"]=x1+width-1
  169. Obj[name]["y2"]=y1+height-1
  170. end
  171.  
  172. --???????? ??????? ??????
  173. local function newObjColor(name,x1,y1,width)
  174. ObjColor[name]={}
  175. ObjColor[name]["x1"]=x1
  176. ObjColor[name]["y1"]=y1
  177. ObjColor[name]["x2"]=x1+width-1
  178. end
  179.  
  180. --??????? ??????????? ?????? ?? ???????????
  181. local function usualText(x,y,text)
  182. term.setCursorPos(x,y)
  183. term.write(text)
  184. end
  185.  
  186. --????????????? ??????? ??? ??????????? ?????? ?? ?????? ??????
  187. local function centerText(how,coord,text,textColor,backColor)
  188. term.setTextColor(textColor)
  189. term.setBackgroundColor(backColor)
  190. if how == "xy" then
  191. term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))
  192. elseif how == "x" then
  193. term.setCursorPos(math.floor(xSize/2-#text/2),coord)
  194. elseif how == "y" then
  195. term.setCursorPos(coord,math.floor(ySize/2))
  196. end
  197. term.write(text)
  198. end
  199.  
  200. --????????? ???????? ? ????????
  201. local function square(x1,y1,width,height,color)
  202. local string = string.rep(" ",width)
  203. term.setBackgroundColor(color)
  204. for y=y1,(y1+height-1) do
  205. usualText(x1,y,string)
  206. end
  207. end
  208.  
  209. --??????? ?????? ??????
  210. local function clearScreen(color)
  211. term.setBackgroundColor(color)
  212. term.clear()
  213. end
  214.  
  215. --??????? ????????? ??????
  216. local function fadeIn(time)
  217. clearScreen(colors.gray)
  218. sleep(time)
  219. clearScreen(colors.lightGray)
  220. sleep(time)
  221. clearScreen(colors.white)
  222. sleep(time)
  223. end
  224.  
  225. --??????? ????????? ??????
  226. local function fadeOut(time)
  227. clearScreen(colors.lightGray)
  228. sleep(time)
  229. clearScreen(colors.gray)
  230. sleep(time)
  231. clearScreen(colors.black)
  232. sleep(time)
  233. term.setCursorPos(1,1)
  234. term.setTextColor(colors.white)
  235. end
  236.  
  237. --????????? ???????? ???????
  238. local function topBar()
  239. local function topBarButton(x,y,text)
  240. usualText(x,y,text)
  241. newObj(text,x,y,#text,1)
  242. end
  243.  
  244. for i=1,xSize do
  245. paintutils.drawPixel(i,1,colors.gray)
  246. end
  247.  
  248. term.setTextColor(colors.lightGray)
  249. topBarButton(1,1,"File")
  250. topBarButton(Obj["File"]["x2"]+3,1,"Edit")
  251. topBarButton(Obj["Edit"]["x2"]+3,1,"Quit")
  252. end
  253.  
  254. --????????? ?????????? ????? ? ??????? ?? ????? ???????
  255. local function leftBarColorBar()
  256. square(1,ySize-2,2,2,currentTextColor)
  257. paintutils.drawPixel(1,ySize-2,currentBackColor)
  258. term.setTextColor(currentTextColor)
  259. term.setCursorPos(1,ySize-2)
  260. term.write(currentSymbol)
  261. end
  262.  
  263. --????????? ?????? ?? ????? ???????
  264. local function leftBarButton(x,y,symbol)
  265. if currentInstrument == symbol then
  266. term.setTextColor(colors.white)
  267. square(x,y,2,2,colors.blue)
  268. else
  269. term.setTextColor(colors.gray)
  270. square(x,y,2,2,colors.black)
  271. end
  272. usualText(x,y+1,symbol)
  273. newObj(symbol,x,y,2,2)
  274. end
  275.  
  276. --????????? ????????? ?????? ?? ????? ???????
  277. local function leftBarButtonPersonal(x,y,symbol,colorOfButton,colorOfText)
  278. term.setTextColor(colorOfText)
  279. square(x,y,2,2,colorOfButton)
  280. usualText(x,y+1,symbol)
  281. newObj(symbol,x,y,2,2)
  282. end
  283.  
  284. --????????? ?????? ???????
  285. local function leftBar(activeInstrument)
  286. square(1,2,2,ySize-1,colors.gray)
  287. leftBarButton(1,2,"M")
  288. leftBarButton(1,5,"B")
  289. leftBarButton(1,8,"E")
  290. leftBarButton(1,11,"F")
  291. if CommandBlockIsActive then
  292. leftBarButtonPersonal(1,14,"CB",colors.green,colors.white)
  293. else
  294. leftBarButtonPersonal(1,14,"CB",colors.black,colors.gray)
  295. end
  296. leftBarColorBar()
  297. end
  298.  
  299. --????????? ??????? ???????
  300. local function rightBar()
  301. --?????????? ????????? ? ????????? ?????? (??? ???????)
  302. local function drawColor(x,y,color)
  303. for i=x,(x+1) do
  304. paintutils.drawPixel(i,y,color)
  305. newObjColor(color,x,y,2)
  306. end
  307. end
  308.  
  309. square(xSize-9,2,10,ySize-1,colors.gray)
  310.  
  311. for i=(xSize-9),xSize do
  312. paintutils.drawPixel(i,2,colors.black)
  313. end
  314. term.setTextColor(colors.lightGray)
  315. usualText(xSize-8,2,"Colors")
  316.  
  317. --for i=(xSize-9),xSize do
  318. -- paintutils.drawPixel(i,9,colors.black)
  319. --end
  320. --term.setTextColor(colors.lightGray)
  321. --usualText(xSize-8,9,"Layers")
  322.  
  323. --????? ??????? ????, ??????????? ???????? ???????
  324. local startXColor = 0
  325. local startYColor = 0
  326. for i=0,3 do
  327. startXColor = xSize-8+i*2
  328. startYColor = 4
  329. drawColor(startXColor,startYColor,2^i)
  330. newObjColor(2^i,startXColor,startYColor,2)
  331. end
  332. for i=4,7 do
  333. startXColor = xSize-8+(i-4)*2
  334. startYColor = 5
  335. drawColor(startXColor,startYColor,2^i)
  336. newObjColor(2^i,startXColor,startYColor,2)
  337. end
  338. for i=8,11 do
  339. startXColor = xSize-8+(i-8)*2
  340. startYColor = 6
  341. drawColor(startXColor,startYColor,2^i)
  342. newObjColor(2^i,startXColor,startYColor,2)
  343. end
  344. for i=12,15 do
  345. startXColor = xSize-8+(i-12)*2
  346. startYColor = 7
  347. drawColor(startXColor,startYColor,2^i)
  348. newObjColor(2^i,startXColor,startYColor,2)
  349. end
  350. end
  351.  
  352. --????????? ??????????? ???? ? ?????? ??????????? ?? ?????? ?? ??????? PIXELS
  353. local function drawingArea()
  354.  
  355. --????????????? ? TERM ?? ????????? ????
  356. term.redirect(windowForDrawing)
  357.  
  358. --??????? ????????? "?????????? ????" ? ???? ???????? ????????????, ????????? ?????
  359. local function cresti(x1,y1,width,height,color)
  360. local string = string.rep(transparentSymbol,width)
  361. term.setBackgroundColor(color)
  362. term.setTextColor(colors.lightGray)
  363. for y=y1,(y1+height-1) do
  364. usualText(x1,y,string)
  365. end
  366. end
  367.  
  368. --???????? ?? ??????????? ??? ?????????? ????
  369. local smeshenieX = 2
  370. local smeshenieY = 1
  371.  
  372. --????????? ????? ???????? ? ???????? ???????????? (???? ?????????? ???)
  373. square(1,1,xSize-12,ySize-1,colors.lightGray)
  374. cresti(displayImageFromX-smeshenieX,displayImageFromY-smeshenieY,imageSizeX,imageSizeY,colors.white)
  375.  
  376. --????????? "????" ???????????
  377. for i=1,imageSizeY do
  378. paintutils.drawPixel(displayImageFromX+imageSizeX-smeshenieX,displayImageFromY+i-smeshenieY,colors.gray)
  379. end
  380. square(displayImageFromX+1-smeshenieX,displayImageFromY+imageSizeY-smeshenieY,imageSizeX,1,colors.gray)
  381.  
  382. --????????? ?????? ??????????? ?? ??????
  383. for y=1,#Pixels do
  384. for x=1,#Pixels[y] do
  385. if Pixels[y][x]["symbol"] ~= "#" then
  386. term.setTextColor(Pixels[y][x]["textColor"])
  387. term.setBackgroundColor(Pixels[y][x]["backColor"])
  388. term.setCursorPos(displayImageFromX+x-1-smeshenieX,displayImageFromY+y-1-smeshenieY)
  389. term.write(Pixels[y][x]["symbol"])
  390. end
  391. end
  392. end
  393.  
  394. --????????????? ??????? ?? ??????????? TERM
  395. term.redirect(term.native())
  396. end
  397.  
  398. --????????? ????? ??????????
  399. local function drawAllGui()
  400. drawingArea()
  401. topBar()
  402. leftBar(currentInstrument)
  403. rightBar()
  404. end
  405.  
  406. --????????? ?????????? ??????? ??????????? ? ??????
  407. local function changeImageSizeInMemory(width,height)
  408. imageSizeX = width
  409. imageSizeY = height
  410. displayImageEndX = displayImageFromX + imageSizeX - 1
  411. displayImageEndY = displayImageFromY + imageSizeY - 1
  412. end
  413.  
  414. --???????? ?????? ????? ? ?????? ? ?????????? ??????? PIXELS ??????? ??????????
  415. local function newFile(override)
  416. Pixels = {}
  417.  
  418. local loadData = nil
  419. if override == nil then
  420. loadData = windows.input(math.floor(xSize/2-14),math.floor(ySize/2-3),"New file",12,{"Width",""},{"Height",""})
  421. changeImageSizeInMemory(loadData[1],loadData[2])
  422. end
  423.  
  424. for y=1,imageSizeY do
  425. Pixels[y] = {}
  426. for x=1,imageSizeX do
  427. Pixels[y][x] = {}
  428. Pixels[y][x]["symbol"] = "#"
  429. Pixels[y][x]["textColor"] = "0"
  430. Pixels[y][x]["backColor"] = "0"
  431. end
  432. end
  433.  
  434. displayImageFromX = 4
  435. displayImageFromY = 3
  436. end
  437.  
  438. --??????????? ?? ??????, ???????? ??, ? ?????, ???????? ???? ?????, ? ????????
  439. local function convert(mode,color)
  440. if mode == "from cc" then
  441. for key,value in pairs(Colors) do
  442. if color == value then
  443. return key
  444. end
  445. end
  446. else
  447. if color == "#" then
  448. return "0"
  449. else
  450. return Colors[color]
  451. end
  452. end
  453. end
  454.  
  455. --?????????? ??????? PIXELS ? ????
  456. local function save(path)
  457. local file = fs.open(path,"w")
  458. for j=1,#Pixels do
  459. local line = ""
  460. for i=1,#Pixels[j] do
  461. if Pixels[j][i]["symbol"] == "#" and Pixels[j][i]["textColor"] == "0" and Pixels[j][i]["backColor"] == "0" then
  462. line = line.."#".."#".."#"
  463. else
  464. line = line..Pixels[j][i]["symbol"]..convert("from cc",Pixels[j][i]["textColor"])..convert("from cc",Pixels[j][i]["backColor"])
  465. end
  466. end
  467. file.writeLine(line)
  468. end
  469. file.close()
  470. end
  471.  
  472. --???????? ?????? ?? ????????????? ????? ? ?????? PIXELS
  473. local function load(path)
  474. Pixels = {}
  475. local file = fs.open(path,"r")
  476. local lineCounter = 1
  477. while true do
  478. local line = file.readLine()
  479. Pixels[lineCounter]={}
  480. if line ~= "" and line ~= nil then
  481. for i=1,#line,3 do
  482. local posX = (i+2)/3
  483. Pixels[lineCounter][posX]={}
  484. Pixels[lineCounter][posX]["symbol"] = string.sub(line,i,i)
  485. Pixels[lineCounter][posX]["textColor"] = convert("to cc",string.sub(line,i+1,i+1))
  486. Pixels[lineCounter][posX]["backColor"] = convert("to cc",string.sub(line,i+2,i+2))
  487. if CommandBlockIsActive then
  488. if Pixels[lineCounter][posX]["backColor"] ~= "0" then
  489. setBlock(posX,lineCounter,Blocks[convert("to cc",string.sub(line,i+2,i+2))]["id"],Blocks[convert("to cc",string.sub(line,i+2,i+2))]["data"])
  490. end
  491. end
  492. end
  493. lineCounter = lineCounter + 1
  494. else
  495. break
  496. end
  497. end
  498.  
  499. changeImageSizeInMemory(#Pixels[1],lineCounter-1)
  500. file.close()
  501. end
  502.  
  503. local function moveImage(direction)
  504. if direction == "up" then
  505. if displayImageEndY > ySize-2 then
  506. changeDisplayImageFromParameters(displayImageFromX,displayImageFromY-1)
  507. drawingArea()
  508. end
  509. elseif direction == "down" then
  510. if displayImageFromY < 3 then
  511. changeDisplayImageFromParameters(displayImageFromX,displayImageFromY+1)
  512. drawingArea()
  513. end
  514. elseif direction == "left" then
  515. if displayImageEndX > xSize-12 then
  516. changeDisplayImageFromParameters(displayImageFromX-1,displayImageFromY)
  517. drawingArea()
  518. end
  519. elseif direction == "right" then
  520. if displayImageFromX < 4 then
  521. changeDisplayImageFromParameters(displayImageFromX+1,displayImageFromY)
  522. drawingArea()
  523. end
  524. end
  525. end
  526.  
  527. ---------------------????? ?????????----------------------------
  528.  
  529. --???? ?????? ???????? ????, ?? ?????????? ???
  530. if fs.exists("System/Photoshop/pslogo.png") then
  531. --image.draw(math.floor(xSize/2-13),3,"System/Photoshop/pslogo.png")
  532. --os.unloadAPI("System/API/image")
  533. sleep(2)
  534. end
  535.  
  536. fadeIn(0)
  537.  
  538. --????? ???????? ? ?????? ??????? ?? ??????????
  539. local mode = Args[1]
  540. if mode == "n" then
  541. --??????? ????? ???? ??? ????????
  542. changeImageSizeInMemory(tonumber(Args[2]),tonumber(Args[3]))
  543. newFile("Cyka")
  544. fastFileMode = true
  545. fastFilePath = Args[4]
  546. drawAllGui()
  547. elseif mode == "o" then
  548. --??????? ???????????? ???? ?? ?????
  549. pathForFastSaving = Args[2]
  550. load(Args[2])
  551. drawAllGui()
  552. else
  553. --??????? ??????
  554. drawAllGui()
  555. newFile()
  556. drawAllGui()
  557. end
  558.  
  559. --???????? ?????????? ??? ??????????? MOVE
  560. local coordXForMoveInstrument = nil
  561. local coordYForMoveInstrument = nil
  562.  
  563. --???????????? ???????? ? ??????
  564. while true do
  565. local event,button,x,y = os.pullEvent()
  566. --???? ???-?? ??????? ? ??????, ??
  567. if event == "mouse_click" or event == "mouse_drag" then
  568. --???? ????? ????, ??
  569. if button == 1 then
  570. --???? ?? ??????? ???? ? ??????? ?????????
  571. if x>=displayImageFromX and x<=displayImageEndX and y>=displayImageFromY and y<=displayImageEndY and y>=2 and x>=3 and x<= xSize-10 then
  572. --???? ?????? ?????????? "?????"
  573. if currentInstrument == "B" then
  574. Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["symbol"] = currentSymbol
  575. Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["textColor"] = currentTextColor
  576. Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["backColor"] = currentBackColor
  577. term.setTextColor(currentTextColor)
  578. term.setBackgroundColor(currentBackColor)
  579. term.setCursorPos(x,y)
  580. term.write(currentSymbol)
  581. if CommandBlockIsActive then setBlock(x,y,Blocks[currentBackColor]["id"],Blocks[currentBackColor]["data"]) end
  582. --???? ?????? ?????????? "??????"
  583. elseif currentInstrument == "E" then
  584. Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["symbol"] = "#"
  585. Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["textColor"] = "0"
  586. Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["backColor"] = "0"
  587. term.setTextColor(colors.lightGray)
  588. term.setBackgroundColor(colors.white)
  589. term.setCursorPos(x,y)
  590. term.write(transparentSymbol)
  591. if CommandBlockIsActive then setBlock(x,y,"air","0") end
  592.  
  593. --???? ?????? ?????????? "MOVE"
  594. elseif currentInstrument == "M" then
  595.  
  596. if coordXForMoveInstrument ~= nil then
  597. if x > coordXForMoveInstrument then
  598. moveImage("right")
  599. elseif x < coordXForMoveInstrument then
  600. moveImage("left")
  601. end
  602.  
  603. if y < coordYForMoveInstrument then
  604. moveImage("up")
  605. elseif y > coordYForMoveInstrument then
  606. moveImage("down")
  607. end
  608. end
  609.  
  610. coordXForMoveInstrument = x
  611. coordYForMoveInstrument = y
  612.  
  613. --???? ?????? ?????????? "???????"
  614. elseif currentInstrument == "F" then
  615. local colorToReplace = Pixels[y-displayImageFromY+1][x-displayImageFromX+1]["backColor"]
  616. for j=1,#Pixels do
  617. for i=1,#Pixels[j] do
  618. if Pixels[j][i]["backColor"] == colorToReplace then
  619. Pixels[j][i]["backColor"] = currentBackColor
  620. Pixels[j][i]["textColor"] = currentTextColor
  621. Pixels[j][i]["symbol"] = " "
  622. if CommandBlockIsActive then setBlock(i,j,Blocks[currentBackColor]["id"],Blocks[currentBackColor]["data"]) end
  623. end
  624. end
  625. end
  626. drawAllGui()
  627. end
  628. --???? ?????? ??????? ??????????? "MOVE"
  629. elseif x>=Obj["M"]["x1"] and x<=Obj["M"]["x2"] and y>=Obj["M"]["y1"] and y<=Obj["M"]["y2"] then
  630. currentInstrument = "M"
  631. leftBar(currentInstrument)
  632. --???? ?????? ??????? ??????????? "?????"
  633. elseif x>=Obj["B"]["x1"] and x<=Obj["B"]["x2"] and y>=Obj["B"]["y1"] and y<=Obj["B"]["y2"] then
  634. currentInstrument = "B"
  635. leftBar(currentInstrument)
  636. --???? ?????? ??????? ??????????? "??????"
  637. elseif x>=Obj["E"]["x1"] and x<=Obj["E"]["x2"] and y>=Obj["E"]["y1"] and y<=Obj["E"]["y2"] then
  638. currentInstrument = "E"
  639. leftBar(currentInstrument)
  640. --???? ?????? ??????? ??????????? "???????"
  641. elseif x>=Obj["F"]["x1"] and x<=Obj["F"]["x2"] and y>=Obj["F"]["y1"] and y<=Obj["F"]["y2"] then
  642. currentInstrument = "F"
  643. leftBar(currentInstrument)
  644. --???? ?????? ??????? ??????????? ?????????? ?????
  645. elseif x>=Obj["CB"]["x1"] and x<=Obj["CB"]["x2"] and y>=Obj["CB"]["y1"] and y<=Obj["CB"]["y2"] then
  646. --??????? ????? ????????? ????, ???? ?? ??????, ?? NIL
  647. commandBlockAttachedAt = findCommandBlock()
  648. --???? ?? ?????, ?? ?????? ??????????? ?????? ???????
  649. if commandBlockAttachedAt == nil or commandBlockAttachedAt == "" then
  650. leftBarButtonPersonal(1,11,"CB",colors.red,colors.white)
  651. sleep(0.5)
  652. leftBarButtonPersonal(1,11,"CB",colors.black,colors.gray)
  653. CommandBlockIsActive = false
  654. --???? ?????, ?? ???????????? ????????? ???? ??? ?????????
  655. else
  656. CommandBlock = peripheral.wrap(commandBlockAttachedAt)
  657. if CommandBlockIsActive then
  658. CommandBlockIsActive = false
  659. else
  660. CommandBlockIsActive = true
  661. end
  662. end
  663. --???????????? ????? ?????? (????? ?? ????????? - ????? ?????? ????? ???????)
  664. leftBar(currentInstrument)
  665.  
  666. --???? ?????? ?????? "FILE"
  667. elseif x>=Obj["File"]["x1"] and x<=Obj["File"]["x2"] and y>=Obj["File"]["y1"] and y<=Obj["File"]["y2"] then
  668. --????? ???????????? ???? ? ?????? ? ?????????? ACTION ???????? ????? ????
  669. local action = nil
  670. local canNotSave = true; if pathForFastSaving ~= nil then canNotSave = false end
  671.  
  672. if fastFileMode then
  673. action = context.menu(Obj["File"]["x1"]-1,Obj["File"]["y1"]+1,{""},{"Save and continue",false,colors.red},{""})
  674. else
  675. action = context.menu(Obj["File"]["x1"]-1,Obj["File"]["y1"]+1,{"New"},{"Open"},{"Save",canNotSave},{"Save as"},"-",{"Put to Pastebin",true},{"Get from Pastebin",true})
  676. end
  677. --???? ?? ?????? ?????? "SAVE" ? ????, ?? ????????, ???? ????????? ? ?????????
  678. if action == "Save" then
  679. fs.delete(pathForFastSaving)
  680. save(pathForFastSaving)
  681. windows.attention({"Success!",},{"File saved to","/"..pathForFastSaving})
  682. drawAllGui()
  683.  
  684. elseif action == "Save as" then
  685. local savePath = windows.input("auto","auto","Save as",15,{"Name","Images/"})
  686. save(savePath[1]..".png")
  687. windows.attention({"Success!"},{"File saved as",savePath[1]..".png"})
  688. pathForFastSaving = savePath[1]..".png"
  689. windows.attention({"Success!"},{"path for fast saving:", pathForFastSaving})
  690. drawAllGui()
  691.  
  692. --???? ?? ?????? ?????? "NEW" ? ????, ?? ??????? ????? ????, ???????? ??? ????? ? ???? ????? ?? ? ???????????? GUI
  693. elseif action == "New" then
  694. newFile()
  695. if CommandBlockIsActive then clearAll() end
  696. drawAllGui()
  697. --???? ?? ?????? ?????? "OPEN" ? ????, ?? ????????, ??? ?????? ??????? ? ???????
  698. elseif action == "Open" then
  699. local pathToOpen = filemanager.open("")
  700. if pathToOpen == nil then
  701. drawAllGui()
  702. elseif windows.getFileFormat(pathToOpen) ~= ".png" then
  703. windows.attention({"Can't open file"},{"This file format","is not supported."})
  704. drawAllGui()
  705. else
  706. load(pathToOpen)
  707. drawAllGui()
  708. end
  709. --????????? ???? ?? ?????, ???? ????? ?? ???????
  710. elseif action == "Save and continue" then
  711. save(fastFilePath..".png")
  712. fadeOut(0)
  713. return "Ok!"
  714. --???? ?? ?????? ??????, ?? ???????????? ????? ??????????, ????? ??????? ??????????? ????
  715. else
  716. drawingArea()
  717. leftBar(currentInstrument)
  718. end
  719.  
  720. --???? ?????? ?????? "QUIT" ?? ??????? ???????, ??
  721. elseif x>=Obj["Quit"]["x1"] and x<=Obj["Quit"]["x2"] and y>=Obj["Quit"]["y1"] and y<=Obj["Quit"]["y2"] then
  722. break
  723. end
  724.  
  725. --???? ???????? ????? ???? ?? ???????? ??????? (??????? ???? ????????? ?????? ? ????? ????? ????)
  726. for i=0,15 do
  727. if x>=ObjColor[2^i]["x1"] and x<=ObjColor[2^i]["x2"] and y==ObjColor[2^i]["y1"] then
  728. currentBackColor = 2^i
  729. leftBarColorBar()
  730. break
  731. end
  732. end
  733.  
  734. --???? ???????? ?????? ???? ?????, ??
  735. else
  736. --??????? ???? ????????? ?????? ? ????? ????? ??????
  737. for i=0,15 do
  738. if x>=ObjColor[2^i]["x1"] and x<=ObjColor[2^i]["x2"] and y==ObjColor[2^i]["y1"] then
  739. currentTextColor = 2^i
  740. leftBarColorBar()
  741. break
  742. end
  743. end
  744. end
  745.  
  746. --???? ?? ?????? ????? ?????????? ??????? ?? ??????????
  747. elseif event == "char" then
  748. currentSymbol = button
  749. leftBarColorBar()
  750. elseif event == "key" then
  751. if button == 208 then
  752. moveImage("up")
  753. elseif button == 200 then
  754. moveImage("down")
  755. elseif button == 205 then
  756. moveImage("left")
  757. elseif button == 203 then
  758. moveImage("right")
  759. end
  760.  
  761. end
  762. end
  763.  
  764. --??????? ?????? ? ????? ?? ?????????
  765. windowForDrawing = nil
  766. term.redirect(defaultTerm)
  767. fadeOut(0)
  768. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement