How to re-create the previous UI
#1
Posted 10 December 2015 - 03:20 AM
I also thought of keeping a complete "log" of all of the functions ran and then running them all at once when you want to restore them, but that seems highly inefficient to me...
#2
Posted 10 December 2015 - 03:43 AM
#3
Posted 10 December 2015 - 03:54 AM
local Collect = true
local ScreenSaver = {}
sapis = {}
function sapis.toggleSS(bool)
Collect = bool or not Collect
end
local oldC = term.clear
function term.clear(...)
if Collect then
ScreenSaver = {}
end
return oldC(unpack(args))
end
for i,v in pairs(term)do
if i:lower() ~= "clear" then
local oldFunc = v
term[i] = function(...)
if Collect then
local tbl = {
["Function"] = oldFunc;
["Arguments"] = args;
}
table.insert(ScreenSaver,tbl)
end
return oldFunc(unpack(args))
end
end
end
for i,v in pairs(paintutils)do
if i:lower() ~= "loadimage" then
local oldFunc = v
term[i] = function(...)
if Collect then
local tbl = {
["Function"] = oldFunc;
["Arguments"] = args;
}
table.insert(ScreenSaver,tbl)
end
return oldFunc(unpack(args))
end
end
end
And this running to activate the "warning":
local function createWarning(func,args)
sapis.toggleSS(false)
local lastBC = term.getBackgroundColor()
local lastTC = term.getTextColor()
args = args or "None Specified"
local run = true
buttonapis.backupButtons()
term.setTextColor(colors.white)
paintutils.drawFilledBox(1,1,w,h,colors.red)
term.setCursorPos(1,1)
term.write("An unauthorized program is trying to use "..func..".")
term.setCursorPos(1,2)
term.write("Given Arguments: "..args)
term.setCursorPos(1,3)
term.write("Allow this?")
buttonapis.addButton(w-6,2,w-4,3,"yes")
buttonapis.addButton(w-2,2,w-1,3,"no")
term.setCursorPos(w-6,3)
term.write("Yes")
term.setCursorPos(w-2,3)
term.write("No")
bfunctions.yes = function(x,y,func)
restore()
end
bfunctions.no = function(x,y,func)
restore()
end
while run do
buttonapis.handleEvent()
end
term.getBackgroundColor(lastBC)
term.getTextColor(lastTC)
sapis.toggleSS(true)
end
After calling the createWarning function, the screen literally goes blank, like it shut off. I also have found you can't terminate the program.
EDIT: It is actually doing that at the startup.
Edited by Twijn, 10 December 2015 - 04:00 AM.
#4
Posted 10 December 2015 - 04:03 AM
#5
Posted 10 December 2015 - 04:04 AM
Example:
It waits 5 seconds then opens a popup then 5 seconds later it closes it. (then exits 5 seconds after that)
local mainCo = coroutine.create(function()
shell.run("shell")
end)
local mainWin = window.create(term.current(), 1, 1, term.getSize())
local mainFilter
local prev = term.redirect(mainWin)
_, mainFilter = coroutine.resume(mainCo)
term.redirect(prev)
local function resize()
mainWin.reposition(1, 1, term.getSize())
end
local w, h = term.getSize()
local popup
local popupWidth, popupHeight = 15, 10
local timer = os.startTimer(5)
local stage = 0
while true do
local ev = {os.pullEventRaw()}
if ev[1] == 'term_resize' then
w, h = term.getSize()
resize()
elseif ev[1] == 'timer' and ev[2] == timer then
if stage == 0 then
popup = window.create(term.current(), math.floor(w/2 - popupWidth/2), math.floor(h/2 - popupHeight/2), popupWidth, popupHeight)
local prevP = term.redirect(popup)
term.setBackgroundColor(colors.gray)
term.clear()
term.setCursorPos(1, 1)
print("popup")
term.redirect(prevP)
popup.redraw()
mainWin.restoreCursor()
elseif stage == 1 then
popup.setVisible(false)
mainWin.redraw()
mainWin.restoreCursor()
elseif stage == 2 then
break
end
timer = os.startTimer(5)
stage = stage + 1
end
if mainFilter == nil or mainFilter == ev[1] then
local prevTerm = term.redirect(mainWin)
_, mainFilter = coroutine.resume(mainCo, unpack(ev))
term.redirect(prevTerm)
mainWin.redraw()
if popup then
popup.redraw()
mainWin.restoreCursor()
end
end
end
Edited by CoderPuppy, 10 December 2015 - 04:15 AM.
#6
Posted 12 December 2015 - 12:03 AM
CoderPuppy, on 10 December 2015 - 04:04 AM, said:
Example:
It waits 5 seconds then opens a popup then 5 seconds later it closes it. (then exits 5 seconds after that)
local mainCo = coroutine.create(function()
shell.run("shell")
end)
local mainWin = window.create(term.current(), 1, 1, term.getSize())
local mainFilter
local prev = term.redirect(mainWin)
_, mainFilter = coroutine.resume(mainCo)
term.redirect(prev)
local function resize()
mainWin.reposition(1, 1, term.getSize())
end
local w, h = term.getSize()
local popup
local popupWidth, popupHeight = 15, 10
local timer = os.startTimer(5)
local stage = 0
while true do
local ev = {os.pullEventRaw()}
if ev[1] == 'term_resize' then
w, h = term.getSize()
resize()
elseif ev[1] == 'timer' and ev[2] == timer then
if stage == 0 then
popup = window.create(term.current(), math.floor(w/2 - popupWidth/2), math.floor(h/2 - popupHeight/2), popupWidth, popupHeight)
local prevP = term.redirect(popup)
term.setBackgroundColor(colors.gray)
term.clear()
term.setCursorPos(1, 1)
print("popup")
term.redirect(prevP)
popup.redraw()
mainWin.restoreCursor()
elseif stage == 1 then
popup.setVisible(false)
mainWin.redraw()
mainWin.restoreCursor()
elseif stage == 2 then
break
end
timer = os.startTimer(5)
stage = stage + 1
end
if mainFilter == nil or mainFilter == ev[1] then
local prevTerm = term.redirect(mainWin)
_, mainFilter = coroutine.resume(mainCo, unpack(ev))
term.redirect(prevTerm)
mainWin.redraw()
if popup then
popup.redraw()
mainWin.restoreCursor()
end
end
end
#8
Posted 12 December 2015 - 02:39 AM
Bomb Bloke, on 12 December 2015 - 02:30 AM, said:
#9
Posted 12 December 2015 - 02:35 PM
CoderPuppy, on 12 December 2015 - 02:39 AM, said:
Bomb Bloke, on 12 December 2015 - 02:30 AM, said:
#10
Posted 12 December 2015 - 11:45 PM
#11
Posted 12 December 2015 - 11:49 PM
If you really don't want to do that (and it beats me as to why you wouldn't), then you can cheat a little: at least, if you're using an advanced computer. Multishell automatically runs shell through a window, and it's a fair bet that the window's parent will be term.native(). That might not be true when your pop-up script runs, but it probably will be.
So the code would go along these lines:
-- Make sure we have multishell:
if not multishell then error("This requires an advanced computer with multishell active.") end
-- Wait until this script is running in the current multishell tab:
while multishell.getCurrent() ~= multishell.getFocus() do sleep(5) end -- An event for tab switching would be helpful here...
-- Make sure we have a window:
local win = term.current()
if not win.redraw then error("Multishell tab has already been redirected away from its window.") end
-- Make an assumption:
local parent = term.native()
-- Draw a pop-up:
local popup = window.create(parent, 10, 10, 5, 5)
popup.setBackgroundColour(colours.red)
popup.clear()
-- Wait a while:
sleep(5)
-- Revert back to the old screen:
win.redraw()
Edited by Bomb Bloke, 12 December 2015 - 11:51 PM.
#12
Posted 13 December 2015 - 02:37 AM
Bomb Bloke, on 12 December 2015 - 11:49 PM, said:
If you really don't want to do that (and it beats me as to why you wouldn't), then you can cheat a little: at least, if you're using an advanced computer. Multishell automatically runs shell through a window, and it's a fair bet that the window's parent will be term.native(). That might not be true when your pop-up script runs, but it probably will be.
So the code would go along these lines:
-- Make sure we have multishell:
if not multishell then error("This requires an advanced computer with multishell active.") end
-- Wait until this script is running in the current multishell tab:
while multishell.getCurrent() ~= multishell.getFocus() do sleep(5) end -- An event for tab switching would be helpful here...
-- Make sure we have a window:
local win = term.current()
if not win.redraw then error("Multishell tab has already been redirected away from its window.") end
-- Make an assumption:
local parent = term.native()
-- Draw a pop-up:
local popup = window.create(parent, 10, 10, 5, 5)
popup.setBackgroundColour(colours.red)
popup.clear()
-- Wait a while:
sleep(5)
-- Revert back to the old screen:
win.redraw()1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











