Just have to fix sPhone.menu

This commit is contained in:
Ale32bit 2016-03-19 23:01:02 +01:00
parent f1c61c898b
commit c9e30d782c

View file

@ -1,6 +1,6 @@
local function kernel() local function kernel()
_G.sPhone = { _G.sPhone = {
version = "Alpha 2.12.2", version = "Alpha 2.12.2 DEV",
user = "Guest", user = "Guest",
devMode = false, devMode = false,
mainTerm = term.current() mainTerm = term.current()
@ -92,6 +92,10 @@ local function kernel()
return "sPhone "..sPhone.version return "sPhone "..sPhone.version
end end
function sPhone.getSize()
return term.getSize()
end
local function clear() local function clear()
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.clear() term.clear()
@ -103,6 +107,7 @@ local function kernel()
sPhone.forceReboot = os.reboot sPhone.forceReboot = os.reboot
function os.shutdown() function os.shutdown()
sPhone.inHome = false
os.pullEvent = os.pullEventRaw os.pullEvent = os.pullEventRaw
if sPhone.doneShutdown then if sPhone.doneShutdown then
clear() clear()
@ -125,6 +130,7 @@ local function kernel()
end end
function os.reboot() function os.reboot()
sPhone.inHome = false
os.pullEvent = os.pullEventRaw os.pullEvent = os.pullEventRaw
if sPhone.doneShutdown then if sPhone.doneShutdown then
clear() clear()
@ -153,7 +159,7 @@ local function kernel()
user = "Unknown", user = "Unknown",
} }
end end
local function upd()
local w, h = term.getSize() local w, h = term.getSize()
paintutils.drawLine(1,1,w,1, colors.blue) paintutils.drawLine(1,1,w,1, colors.blue)
@ -161,12 +167,17 @@ local function kernel()
term.setCursorPos(1,1) term.setCursorPos(1,1)
write(" "..sPhone.user) write(" "..sPhone.user)
term.setCursorPos(w,1) term.setCursorPos(w,1)
write("X") if butt then
write(butt)
end
term.setBackgroundColor(colors.white) term.setBackgroundColor(colors.white)
term.setTextColor(colors.black) term.setTextColor(colors.black)
term.setCursorPos(1,3) term.setCursorPos(1,3)
end end
upd()
end
function sPhone.menu(items, title, closeButton) function sPhone.menu(items, title, closeButton)
local function cprint(text) local function cprint(text)
if type(text) ~= 'table' then if type(text) ~= 'table' then
@ -237,7 +248,7 @@ local function kernel()
sPhone.header(closeButton) sPhone.header(closeButton)
term.setCursorPos(1,3) term.setCursorPos(1,3)
if not title then if not title then
title = "sPhone" title = " sPhone"
end end
cprint(" "..title) cprint(" "..title)
if moreTitle then if moreTitle then
@ -292,10 +303,9 @@ local function kernel()
redraw() redraw()
local eventData = {os.pullEventRaw()} local eventData = {os.pullEventRaw()}
if eventData[1] == 'mouse_click' then if eventData[1] == 'mouse_click' then
if eventData[4] == 1 and eventData[3] == 26 then if eventData[4] == 1 and eventData[3] == termWidth then
return false, 0 return false, 0
end elseif eventData[4] > 3 then
if eventData[4] > 3 then
clear() clear()
selected = (eventData[4]-6+((page-1)*drawSize))+1 selected = (eventData[4]-6+((page-1)*drawSize))+1
if selected then if selected then
@ -420,6 +430,10 @@ end
local f = fs.open(_rApp, "r") local f = fs.open(_rApp, "r")
local script = f.readAll() local script = f.readAll()
f.close() f.close()
if sPhone.inHome then
local sPhoneWasInHome = true
sPhone.inHome = false
end
os.pullEvent = os.oldPullEvent os.pullEvent = os.oldPullEvent
local ok, err = pcall(function() setfenv(loadstring(script),getfenv())() end) local ok, err = pcall(function() setfenv(loadstring(script),getfenv())() end)
if not ok then if not ok then
@ -434,10 +448,11 @@ end
print("") print("")
visum.align("center"," Press Any Key") visum.align("center"," Press Any Key")
os.pullEvent("key") os.pullEvent("key")
return false
end end
os.pullEvent = os.pullEventRaw os.pullEvent = os.pullEventRaw
return true if sPhoneWasInHome then
sPhone.inHome = true
end
end end
local function lChat() local function lChat()
@ -526,6 +541,8 @@ end
local function home() local function home()
sPhone.inHome = true
local buttonsInHome = { local buttonsInHome = {
{"sPhone.header",23,1,25,1,colors.blue,colors.white,"vvv"}, {"sPhone.header",23,1,25,1,colors.blue,colors.white,"vvv"},
{"sPhone.appsButton",12,20,14,20,colors.white,colors.blue,"==="}, {"sPhone.appsButton",12,20,14,20,colors.white,colors.blue,"==="},
@ -553,13 +570,6 @@ end
["sPhone.store"] = "/.sPhone/apps/store", ["sPhone.store"] = "/.sPhone/apps/store",
} }
--if not fs.exists("/.sPhone/config/resetDBNews") then
--sPhone.winOk("We wiped sID Database","for security issues")
--local f = fs.open("/.sPhone/config/resetDBNews","w")
--f.write("Ignore me")
--f.close()
--end
if not sPhone.locked then if not sPhone.locked then
sPhone.lock() sPhone.lock()
end end
@ -574,18 +584,14 @@ end
write(text) write(text)
end end
clear() clear()
visum.buttons(buttonsInHome,true)
local w, h = term.getSize() local w, h = term.getSize()
paintutils.drawLine(1,1,w,1, colors.blue) paintutils.drawLine(1,1,w,1, colors.blue)
term.setTextColor(colors.white) term.setTextColor(colors.white)
visum.align("right","vvv ",false,1) visum.align("right","vvv ",false,1)
term.setCursorPos(1,1)
if not sPhone.newUpdate then
write(" "..sPhone.user)
else
write(" New Update!")
end
visum.buttons(buttonsInHome,true)
end end
local function footerMenu() local function footerMenu()
sPhone.isFooterMenuOpen = true sPhone.isFooterMenuOpen = true
@ -604,6 +610,7 @@ end
end end
while true do while true do
term.redirect(sPhone.mainTerm) term.redirect(sPhone.mainTerm)
drawHome()
redraw() redraw()
local _,_,x,y = os.pullEvent("mouse_click") local _,_,x,y = os.pullEvent("mouse_click")
if y == 3 then if y == 3 then
@ -612,7 +619,9 @@ end
elseif x > 19 and x < 26 then elseif x > 19 and x < 26 then
os.reboot() os.reboot()
elseif x > 10 and x < 19 then elseif x > 10 and x < 19 then
shell.run("/.sPhone/apps/system/settings") sPhone.inHome = false
sPhone.run("/.sPhone/apps/system/settings")
sPhone.inHome = true
drawHome() drawHome()
end end
elseif y == 1 then elseif y == 1 then
@ -623,25 +632,56 @@ end
end end
end end
end end
local function buttonHomeLoop()
while true do while true do
drawHome() drawHome()
term.setCursorBlink(false) term.setCursorBlink(false)
local autoLockTimer = os.startTimer(120) local autoLockTimer = os.startTimer(10)
local id = visum.buttons(buttonsInHome) local id = visum.buttons(buttonsInHome)
if id == "sPhone.header" then if id == "sPhone.header" then
footerMenu() footerMenu()
elseif id == "sPhone.appsButton" then elseif id == "sPhone.appsButton" then
sPhone.inHome = false
installedApps() installedApps()
sPhone.inHome = true
elseif id == "sPhone.lock" then elseif id == "sPhone.lock" then
sPhone.inHome = false
login() login()
sPhone.inHome = true
elseif id == "sPhone.chat" then elseif id == "sPhone.chat" then
sPhone.inHome = false
lChat() lChat()
sPhone.inHome = true
elseif appsOnHome[id] then elseif appsOnHome[id] then
sPhone.inHome = false
sPhone.run(appsOnHome[id]) sPhone.run(appsOnHome[id])
sPhone.inHome = true
end end
end end
sPhone.inHome = false
end
local function updateClock()
while true do
if sPhone.inHome then
term.setCursorPos(1,1)
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.white)
write(" ")
term.setCursorPos(1,1)
write(" "..textutils.formatTime(os.time(),true))
end
sleep(0)
end
end
parallel.waitForAll(buttonHomeLoop, updateClock)
sPhone.inHome = false
end end
function login() function login()
@ -674,7 +714,7 @@ end
local fpw = fs.open("/.sPhone/config/.password","r") local fpw = fs.open("/.sPhone/config/.password","r")
if sha256.sha256(passwordLogin) == fpw.readLine() then if sha256.sha256(passwordLogin) == fpw.readLine() then
sPhone.wrongPassword = false sPhone.wrongPassword = false
home() return
else else
sPhone.wrongPassword = true sPhone.wrongPassword = true
end end