--beta release 2 --WARNING DEAR COMMENT READER --please refrain from looking at code before trying it --looking at the sauce might spoil some of the fun ^^ --Cruors list of todo's -- Add color support to loading screen local function printLogo(logo) local longest = 0 local termW, termH = term.getSize() for w in string.gmatch(logo, "[^\n]+") do longest = math.max(longest, #w) end local strStart = (termW - longest) / 2 + 0.5 for w in string.gmatch(logo, "[^\n]+") do local cursorX, cursorY = term.getCursorPos() term.setCursorPos(strStart, cursorY) term.write(w) print() end end local function newProgressBar(t) local mt = { borderStart = { text = "", textColor = nil, backgroundColor = nil, }, borderMiddleLoaded = { text = " ", textColor = nil, backgroundColor = colors.white }, borderEnd = { text = "", textColor = nil, backgroundColor = nil }, borderMiddleEmpty ={ text = " ", textColor = nil, backgroundColor = colors.black }, minValue = 1, maxValue = 100, currentValue = 1, pos = {1, 1}, size = {5, 1}, update = function(self, currentValue) self.currentValue = currentValue end, draw = function(self) local posX, posY = unpack(self.pos) local sizeX, sizeY = unpack(self.size) local percentage = (self.currentValue - self.minValue) / (self.maxValue - self.minValue) local loadedLength = math.floor(percentage * (sizeX - 1) + 0.5) for i = 1, 2 do local borderType = i == 1 and "borderMiddleLoaded" or "borderMiddleEmpty" if self[borderType].textColor then term.setTextColor(self[borderType].textColor) end if self[borderType].backgroundColor then term.setBackgroundColor(self[borderType].backgroundColor) end if type(self[borderType].text) == "string" then term.setCursorPos(posX + (i == 1 and 0 or loadedLength) + 1, posY) local emptyLength = (sizeX - loadedLength - 1) > 0 and (sizeX - loadedLength - 1) or 0 term.write(string.rep(self[borderType].text, (i == 1 and loadedLength or emptyLength))) elseif type(self[borderType].text) == "table" then for j, v in ipairs(self[borderType].text) do term.setCursorPos(posX + (i == 1 and 0 or loadedLength) + 1, posY + j - 1) term.write(string.rep(v, (i == 1 and loadedLength or emptyLength))) end end end for i = 1, 2 do local borderType = i == 1 and "borderStart" or "borderEnd" if self[borderType].textColor then term.setTextColor(self[borderType].textColor) end if self[borderType].backgroundColor then term.setBackgroundColor(self[borderType].backgroundColor) end if type(self[borderType].text) == "string" then term.setCursorPos(posX + (i == 1 and 0 or sizeX), posY) term.write(self[borderType].text) elseif type(self[borderType].text) == "table" then for j, v in ipairs(self[borderType].text) do term.setCursorPos(posX + (i == 1 and 0 or sizeX), posY + j - 1) term.write(v) end end end end } setmetatable(t, {__index = mt}) return t end local function kCode() local termW, termH = term.getSize() local kCode = {200, 200, 208, 208, 203, 205, 203, 205, 48, 30} local kCodeIndicatorLine = math.floor(termH / 2 + 0.5) local kCodeProgress = 0 local kCodeMessage = { "kCode entered...", "Easter egg found...", "Skipping loading screen", "......................." } while true do event, key = os.pullEvent("key") if key == kCode[kCodeProgress + 1] then kCodeProgress = kCodeProgress + 1 else kCodeProgress = 0 end term.setCursorPos((termW - kCodeProgress * 2) / 2, kCodeIndicatorLine) term.clearLine() term.write(string.rep("# ", kCodeProgress)) if kCodeProgress == #kCode then for i, v in ipairs(kCodeMessage) do for j = 1, #v do term.setCursorPos(j + 2, kCodeIndicatorLine + i + 1) term.write(string.sub(v, j, j)) sleep(.1) end end break end end end local function loadingScreen(logo, loadingMessages) term.clear() term.setCursorPos(1, 1) printLogo(logo) local termW, termH = term.getSize() local loadingBar = { pos = { 2, termH - 1 }, size = { termW - 3, 1 }, } loadingBar = newProgressBar(loadingBar) for i, v in ipairs(loadingMessages) do local delay = loadingMessages[i].delay local endValue = loadingMessages[i].endValue local increment = loadingMessages[i].increment local loadingText = loadingMessages[i].text local startValue = loadingMessages[i].startValue local textColor = loadingMessages[i].textColor local backgroundColor = loadingMessages[i].backgroundColor local clearLine = loadingMessages[i].clearLine if textColor then term.setTextColor(textColor) end if backgroundColor then term.setBackgroundColor(backgroundColor) end term.setCursorPos(3, termH) term.clearLine() term.write(loadingText) if clearLine then term.setCursorPos(unpack(loadingBar.pos)) term.clearLine() end sleep(delay) for j = startValue, endValue, increment do loadingBar:update(j) loadingBar:draw() sleep(delay) end end end local logo = [[ _ _ __ |_) _ _|_ _. _|_ / \ (_ | (_) |_ (_| |_ \_/ __) ]] local loadingMessages = { [1] = { text = "Loading progressbar...", textColor = colors.white, backgroundColor = colors.black, startValue = 0, endValue = 0, increment = 1, delay = 3, clearLine = false }, [2] = { text = "Loading loading messages...", textColor = colors.white, backgroundColor = colors.black, startValue = 1, endValue = 120, increment = 1, delay = 0.05, clearLine = false }, [3] = { text = "Loaded to many... putting some back...", textColor = colors.white, backgroundColor = colors.black, startValue = 120, endValue = 85, increment = -1, delay = 0.15, clearLine = false }, [4] = { text = "Ignoring mess after last bar...", textColor = colors.white, backgroundColor = colors.black, startValue = 1, endValue = 100, increment = 1, delay = 0.05, clearLine = true } } parallel.waitForAny( function() loadingScreen(logo, loadingMessages) end, kCode ) term.setCursorPos(1, 6) term.write("Debug print: loading screen done") term.setCursorPos(1, 7) term.write("wait for next beta release :P")