SHOW:
|
|
- or go back to the newest paste.
| 1 | --v3 | |
| 2 | local function update() | |
| 3 | shell.run("delete","lg")
| |
| 4 | shell.run("pastebin","get","sSF7NPYC","lg")
| |
| 5 | os.reboot() | |
| 6 | end | |
| 7 | local args = {...}
| |
| 8 | - | term.redirect(m) |
| 8 | + | if (args[1] == "update") then |
| 9 | update() | |
| 10 | end | |
| 11 | function setup(name) | |
| 12 | sx,sy = nil | |
| 13 | buttons = {}
| |
| 14 | tname = name | |
| 15 | pixels = {}
| |
| 16 | local bg = colors.black | |
| 17 | sprites = {}
| |
| 18 | inputs = {}
| |
| 19 | oterm = term.current() | |
| 20 | if (name == "term") then | |
| 21 | sx,sy = term.getSize() | |
| 22 | local previous = term | |
| 23 | else | |
| 24 | m = peripheral.wrap(name) | |
| 25 | local previous = term.redirect(m) | |
| 26 | sx,sy = m.getSize() | |
| 27 | end | |
| 28 | end | |
| 29 | function createWindow(x,y,w,h,visible) | |
| 30 | local window = window.create(term.current(), x, y, w,h,visible) | |
| 31 | local scene = {oterm=oterm,x=x,y=y,window = window, bg=colors.black,w=w,h=h,buttons = {}, pixels = {}, sprites = {}, inputs = {},
| |
| 32 | drawText = function (self, x,y,color,colorb,text) | |
| 33 | term.setCursorPos(x,y) | |
| 34 | term.setTextColor(color) | |
| 35 | term.setBackgroundColor(colorb) | |
| 36 | term.write(text) | |
| 37 | end, | |
| 38 | clearScreen = function () | |
| 39 | term.clear() | |
| 40 | end, | |
| 41 | setBackgroundColor = function (color) | |
| 42 | - | term.setCursorPos(x,textline) |
| 42 | + | term.setBackgroundColor(color) |
| 43 | end, | |
| 44 | setTextColor = function(color) | |
| 45 | term.setTextColor(color) | |
| 46 | end, | |
| 47 | drawBT = function(self,name,x,xe,y,ye,color,colorb,text) | |
| 48 | term.setBackgroundColor(colorb) | |
| 49 | term.setTextColor(color) | |
| 50 | for i=x,xe do | |
| 51 | for g=y,ye do | |
| 52 | term.setCursorPos(i,g) | |
| 53 | term.write(" ")
| |
| 54 | end | |
| 55 | end | |
| 56 | textline = (y + ye) / 2 | |
| 57 | textline = string.format("%.1f", textline)
| |
| 58 | textline = tonumber(textline) | |
| 59 | lines = {}
| |
| 60 | for word in string.gmatch(text,"[^\n]+") do | |
| 61 | table.insert(lines,word) | |
| 62 | end | |
| 63 | if (#lines > 1) then | |
| 64 | for w=1,#lines do | |
| 65 | term.setCursorPos(x,y+w) | |
| 66 | term.write(lines[w]) | |
| 67 | end | |
| 68 | else | |
| 69 | term.setCursorPos(x,textline) | |
| 70 | term.write(text) | |
| 71 | end | |
| 72 | table.insert(self.buttons,name..";"..x..";"..xe..";"..y..";"..ye) | |
| 73 | end, | |
| 74 | - | |
| 74 | + | isButton = function(self,x,y) |
| 75 | for i=1,#self.buttons do | |
| 76 | local parts = {}
| |
| 77 | for word in string.gmatch(self.buttons[i],"[^;]+") do | |
| 78 | table.insert(parts,word) | |
| 79 | end | |
| 80 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 81 | if (bx-1 < x and x < bxe + 1 ) then | |
| 82 | if (by-1 < y and bye+1 > y) then | |
| 83 | return name | |
| 84 | end | |
| 85 | end | |
| 86 | end | |
| 87 | return self.buttons[1] | |
| 88 | end, | |
| 89 | fill = function(x1,x2,y1,y2,color) | |
| 90 | term.setBackgroundColor(color) | |
| 91 | for i=x1,x2 do | |
| 92 | for g=y1,y2 do | |
| 93 | term.setCursorPos(i,g) | |
| 94 | self.pixels[x..y] = color | |
| 95 | term.write(" ")
| |
| 96 | end | |
| 97 | end | |
| 98 | end, | |
| 99 | fillScreen = function(self,color) | |
| 100 | term.setBackgroundColor(color) | |
| 101 | term.clear() | |
| 102 | self.pixels = {}
| |
| 103 | end, | |
| 104 | drawImage = function(x,y,name) | |
| 105 | image = paintutils.loadImage(name) | |
| 106 | paintutils.drawImage(image,x,y) | |
| 107 | end, | |
| 108 | getSize = function(self) | |
| 109 | local sizet = {}
| |
| 110 | sizet.x = self.w | |
| 111 | sizet.y = self.h | |
| 112 | return sizet | |
| 113 | end, | |
| 114 | drawInput = function(self,name,x,x2,y,y2,limit) | |
| 115 | term.setBackgroundColor(colors.gray) | |
| 116 | term.setTextColor(colors.white) | |
| 117 | for i=x,x2 do | |
| 118 | for g=y,y2 do | |
| 119 | term.setCursorPos(i,g) | |
| 120 | term.write(" ")
| |
| 121 | end | |
| 122 | end | |
| 123 | table.insert(self.inputs,name..";"..x..";"..x2..";"..y..";"..y2..";"..limit) | |
| 124 | end, | |
| 125 | isInput = function(self,x,y) | |
| 126 | term.setTextColor(colors.white) | |
| 127 | for i=1,#self.inputs do | |
| 128 | local parts = {}
| |
| 129 | for word in string.gmatch(self.inputs[i],"[^;]+") do | |
| 130 | table.insert(parts,word) | |
| 131 | end | |
| 132 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 133 | if (bx-1 < x and x < bxe + 1 ) then | |
| 134 | if (by-1 < y and bye+1 > y) then | |
| 135 | return name | |
| 136 | end | |
| 137 | end | |
| 138 | end | |
| 139 | return false | |
| 140 | end, | |
| 141 | getInput = function(self,x,y,safe) | |
| 142 | for i=1,#self.inputs do | |
| 143 | local parts = {}
| |
| 144 | for word in string.gmatch(self.inputs[i],"[^;]+") do | |
| 145 | table.insert(parts,word) | |
| 146 | end | |
| 147 | name,bx,bxe,by,bye,limit = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]),tonumber(parts[6]) | |
| 148 | if (bx-1 < x and x < bxe + 1 ) then | |
| 149 | if (by-1 < y and bye+1 > y) then | |
| 150 | term.setCursorPos(bx,by) | |
| 151 | local text = limitRead(limit, safe) | |
| 152 | return text | |
| 153 | end | |
| 154 | end | |
| 155 | end | |
| 156 | return false | |
| 157 | end, | |
| 158 | hide = function(self) | |
| 159 | self.window.setVisible(false) | |
| 160 | if (tname == "term") then | |
| 161 | term.redirect(self.oterm) | |
| 162 | else | |
| 163 | term.redirect(m) | |
| 164 | end | |
| 165 | paintutils.drawFilledBox(self.x, self.y, self.w, self.h, self.bg) | |
| 166 | ||
| 167 | end, | |
| 168 | getPos = function() | |
| 169 | return self.window.getPosition() | |
| 170 | end, | |
| 171 | rePos = function(self,x,y,h2,w2) | |
| 172 | if (h2 and w2) then | |
| 173 | self.window.reposition(x,y,h2,w2) | |
| 174 | else | |
| 175 | self.window.reposition(x,y) | |
| 176 | end | |
| 177 | end | |
| 178 | } | |
| 179 | if (visible) then | |
| 180 | term.redirect(window) | |
| 181 | end | |
| 182 | return scene | |
| 183 | end | |
| 184 | function exit() | |
| 185 | term.native() | |
| 186 | end | |
| 187 | function drawText(x,y,color,colorb,text) | |
| 188 | term.setCursorPos(x,y) | |
| 189 | term.setTextColor(color) | |
| 190 | term.setBackgroundColor(colorb) | |
| 191 | term.write(text) | |
| 192 | end | |
| 193 | function clearScreen() | |
| 194 | term.clear() | |
| 195 | end | |
| 196 | function setBackgroundColor(color) | |
| 197 | term.setBackgroundColor(color) | |
| 198 | end | |
| 199 | function setTextColor(color) | |
| 200 | term.setTextColor(color) | |
| 201 | end | |
| 202 | function drawBT(name,x,xe,y,ye,color,colorb,text) | |
| 203 | term.setBackgroundColor(colorb) | |
| 204 | term.setTextColor(color) | |
| 205 | for i=x,xe do | |
| 206 | for g=y,ye do | |
| 207 | term.setCursorPos(i,g) | |
| 208 | term.write(" ")
| |
| 209 | end | |
| 210 | end | |
| 211 | textline = (y + ye) / 2 | |
| 212 | textline = string.format("%.1f", textline)
| |
| 213 | textline = tonumber(textline) | |
| 214 | lines = {}
| |
| 215 | for word in string.gmatch(text,"[^\n]+") do | |
| 216 | table.insert(lines,word) | |
| 217 | end | |
| 218 | if (#lines > 1) then | |
| 219 | for w=1,#lines do | |
| 220 | term.setCursorPos(x,y+w) | |
| 221 | term.write(lines[w]) | |
| 222 | end | |
| 223 | else | |
| 224 | term.setCursorPos(x,textline) | |
| 225 | term.write(text) | |
| 226 | end | |
| 227 | table.insert(buttons,name..";"..x..";"..xe..";"..y..";"..ye) | |
| 228 | end | |
| 229 | function clearBTNS() | |
| 230 | buttons = {}
| |
| 231 | end | |
| 232 | function isButton(x,y) | |
| 233 | for i=1,#buttons do | |
| 234 | local parts = {}
| |
| 235 | for word in string.gmatch(buttons[i],"[^;]+") do | |
| 236 | table.insert(parts,word) | |
| 237 | end | |
| 238 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 239 | if (bx-1 < x and x < bxe + 1 ) then | |
| 240 | if (by-1 < y and bye+1 > y) then | |
| 241 | return name | |
| 242 | end | |
| 243 | end | |
| 244 | end | |
| 245 | return false | |
| 246 | end | |
| 247 | function fill(x,x2,y,y2,color) | |
| 248 | term.setBackgroundColor(color) | |
| 249 | for i=x,x2 do | |
| 250 | for g=y,y2 do | |
| 251 | term.setCursorPos(i,g) | |
| 252 | term.write(" ")
| |
| 253 | end | |
| 254 | end | |
| 255 | end | |
| 256 | function fillScreen(color) | |
| 257 | term.setBackgroundColor(color) | |
| 258 | term.clear() | |
| 259 | end | |
| 260 | function drawLine(x1, y1, x2, y2, color) | |
| 261 | local dx = math.abs(x2 - x1) | |
| 262 | local dy = math.abs(y2 - y1) | |
| 263 | local sx, sy | |
| 264 | ||
| 265 | if x1 < x2 then | |
| 266 | sx = 1 | |
| 267 | else | |
| 268 | sx = -1 | |
| 269 | end | |
| 270 | ||
| 271 | if y1 < y2 then | |
| 272 | sy = 1 | |
| 273 | else | |
| 274 | sy = -1 | |
| 275 | end | |
| 276 | ||
| 277 | local err = dx - dy | |
| 278 | ||
| 279 | while true do | |
| 280 | term.setCursorPos(x1, y1) | |
| 281 | term.setTextColor(color) | |
| 282 | term.write(" ")
| |
| 283 | ||
| 284 | if x1 == x2 and y1 == y2 then | |
| 285 | break | |
| 286 | end | |
| 287 | ||
| 288 | local err2 = 2 * err | |
| 289 | ||
| 290 | if err2 > -dy then | |
| 291 | err = err - dy | |
| 292 | x1 = x1 + sx | |
| 293 | end | |
| 294 | ||
| 295 | if err2 < dx then | |
| 296 | err = err + dx | |
| 297 | y1 = y1 + sy | |
| 298 | end | |
| 299 | end | |
| 300 | end | |
| 301 | function drawImage(x,y,name) | |
| 302 | image = paintutils.loadImage(name) | |
| 303 | paintutils.drawImage(image,x,y) | |
| 304 | end | |
| 305 | function getSize() | |
| 306 | local sizet = {}
| |
| 307 | sizet.x = sx | |
| 308 | sizet.y = sy | |
| 309 | return sizet | |
| 310 | end | |
| 311 | function drawInput(name,x,x2,y,y2,limit) | |
| 312 | term.setBackgroundColor(colors.gray) | |
| 313 | term.setTextColor(colors.white) | |
| 314 | for i=x,x2 do | |
| 315 | for g=y,y2 do | |
| 316 | term.setCursorPos(i,g) | |
| 317 | term.write(" ")
| |
| 318 | end | |
| 319 | end | |
| 320 | table.insert(inputs,name..";"..x..";"..x2..";"..y..";"..y2..";"..limit) | |
| 321 | end | |
| 322 | function isInput(x,y) | |
| 323 | for i=1,#inputs do | |
| 324 | local parts = {}
| |
| 325 | for word in string.gmatch(inputs[i],"[^;]+") do | |
| 326 | table.insert(parts,word) | |
| 327 | end | |
| 328 | name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]) | |
| 329 | if (bx-1 < x and x < bxe + 1 ) then | |
| 330 | if (by-1 < y and bye+1 > y) then | |
| 331 | return name | |
| 332 | end | |
| 333 | end | |
| 334 | end | |
| 335 | return false | |
| 336 | end | |
| 337 | function getInput(x,y,safe) | |
| 338 | for i=1,#inputs do | |
| 339 | local parts = {}
| |
| 340 | for word in string.gmatch(inputs[i],"[^;]+") do | |
| 341 | table.insert(parts,word) | |
| 342 | end | |
| 343 | name,bx,bxe,by,bye,limit = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]),tonumber(parts[6]) | |
| 344 | if (bx-1 < x and x < bxe + 1 ) then | |
| 345 | if (by-1 < y and bye+1 > y) then | |
| 346 | term.setCursorPos(bx,by) | |
| 347 | local text = limitRead(limit, safe) | |
| 348 | return text | |
| 349 | end | |
| 350 | end | |
| 351 | end | |
| 352 | return false | |
| 353 | end | |
| 354 | function setCursorPos(x,y) | |
| 355 | term.setCursorPos(x,y) | |
| 356 | end | |
| 357 | function drawAdvancedImage(x,y,img) | |
| 358 | if img then | |
| 359 | for i=1,#img do | |
| 360 | pixel = img[i] | |
| 361 | local var1, var2, var3, var4, var5 = pixel:match("([^|]+)|([^|]+)|([^|]+)|([^|]+)|([^|]+)")
| |
| 362 | term.setCursorPos(x + tonumber(var2),y + tonumber(var3)) | |
| 363 | term.setBackgroundColor(getColor(var4)) | |
| 364 | term.setTextColor(getColor(var5)) | |
| 365 | if string.find(var1,"\space") then | |
| 366 | term.write(" ")
| |
| 367 | else | |
| 368 | term.write(var1) | |
| 369 | end | |
| 370 | end | |
| 371 | end | |
| 372 | end | |
| 373 | ||
| 374 | ||
| 375 | ||
| 376 | ||
| 377 | ||
| 378 | ||
| 379 | ||
| 380 | ||
| 381 | ||
| 382 | ||
| 383 | ||
| 384 | ||
| 385 | ||
| 386 | ||
| 387 | ||
| 388 | -- FUNC | |
| 389 | function getColor(colorName) | |
| 390 | local colors = {
| |
| 391 | white = colors.white, | |
| 392 | orange = colors.orange, | |
| 393 | magenta = colors.magenta, | |
| 394 | lightBlue = colors.lightBlue, | |
| 395 | yellow = colors.yellow, | |
| 396 | lime = colors.lime, | |
| 397 | pink = colors.pink, | |
| 398 | gray = colors.gray, | |
| 399 | lightGray = colors.lightGray, | |
| 400 | cyan = colors.cyan, | |
| 401 | purple = colors.purple, | |
| 402 | blue = colors.blue, | |
| 403 | brown = colors.brown, | |
| 404 | green = colors.green, | |
| 405 | red = colors.red, | |
| 406 | black = colors.black | |
| 407 | } | |
| 408 | ||
| 409 | return colors[colorName] | |
| 410 | end | |
| 411 | function isColor(value) | |
| 412 | local table = {
| |
| 413 | white = colors.white, | |
| 414 | orange = colors.orange, | |
| 415 | magenta = colors.magenta, | |
| 416 | lightBlue = colors.lightBlue, | |
| 417 | yellow = colors.yellow, | |
| 418 | lime = colors.lime, | |
| 419 | pink = colors.pink, | |
| 420 | gray = colors.gray, | |
| 421 | lightGray = colors.lightGray, | |
| 422 | cyan = colors.cyan, | |
| 423 | purple = colors.purple, | |
| 424 | blue = colors.blue, | |
| 425 | brown = colors.brown, | |
| 426 | green = colors.green, | |
| 427 | red = colors.red, | |
| 428 | black = colors.black | |
| 429 | } | |
| 430 | for k, v in pairs(table) do | |
| 431 | if k == value then | |
| 432 | return true | |
| 433 | end | |
| 434 | end | |
| 435 | return false | |
| 436 | end | |
| 437 | function limitRead(limX, rChar,color,colorb) | |
| 438 | term.setBackgroundColor(colors.gray) | |
| 439 | term.setTextColor(colors.white) | |
| 440 | term.setCursorBlink(true) | |
| 441 | local origX, origY = term.getCursorPos() | |
| 442 | local returnString = "" | |
| 443 | while true do | |
| 444 | local xPos, yPos = term.getCursorPos() | |
| 445 | local event, p1, p2 = os.pullEvent() | |
| 446 | if event == "char" then | |
| 447 | returnString = returnString..p1 | |
| 448 | if not rChar then | |
| 449 | if not limX then | |
| 450 | write(p1) | |
| 451 | else | |
| 452 | if string.len(returnString) >= limX then | |
| 453 | term.setCursorPos(origX, origY) | |
| 454 | write(string.sub(returnString, (string.len(returnString)-limX)+1)) | |
| 455 | elseif string.len(returnString) < limX then | |
| 456 | write(p1) | |
| 457 | end | |
| 458 | end | |
| 459 | else | |
| 460 | if not limX then | |
| 461 | write(rChar) | |
| 462 | else | |
| 463 | if string.len(returnString) >= limX then | |
| 464 | term.setCursorPos(origX, origY) | |
| 465 | write(string.rep(rChar, limX)) | |
| 466 | elseif string.len(returnString) < limX then | |
| 467 | write(rChar) | |
| 468 | end | |
| 469 | end | |
| 470 | end | |
| 471 | elseif event == "key" and p1 == 259 then --backspace | |
| 472 | returnString = string.sub(returnString, 1, (string.len(returnString))-1) | |
| 473 | term.setCursorPos(xPos-1,yPos) | |
| 474 | write(" ")
| |
| 475 | term.setCursorPos(origX, origY) | |
| 476 | if string.len(returnString) >= limX then | |
| 477 | if not rChar then | |
| 478 | write(string.sub(returnString, (string.len(returnString)-limX)+1)) | |
| 479 | else | |
| 480 | write(string.rep(rChar,limX)) | |
| 481 | end | |
| 482 | else | |
| 483 | if not rChar then | |
| 484 | write(returnString) | |
| 485 | else | |
| 486 | write(string.rep(rChar, string.len(returnString))) | |
| 487 | end | |
| 488 | end | |
| 489 | elseif event == "key" and p1 == 257 then --enter | |
| 490 | break | |
| 491 | end | |
| 492 | end | |
| 493 | term.setCursorBlink(false) | |
| 494 | return returnString | |
| 495 | end |