Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- mobile.openKeyboard(false)
- readingOutput = {}
- blinkIsOn = true
- menus = {}
- scrollmenuLen={}
- scrollmenuInfos={}
- dropdown = {}
- dropdown["loaded"] = {}
- dropdown["loaded"]["len"] = 0
- stunden = {}
- menus[1] = homeMenu
- menus[2] = testMenu
- curMenuPos = 1
- neueStunde("08:00","08:45","1. Stunde")
- neueStunde("08:45","09:30","2. Stunde")
- neueStunde("09:30","09:50","Hofpause")
- neueStunde("09:50","10:35","3. Stunde")
- neueStunde("10:40","11:25","4. Stunde")
- neueStunde("11:30","12:15","Mittagspause")
- neueStunde("12:15","13:00","5. Stunde")
- neueStunde("13:05","13:50","6. Stunde")
- neueStunde("13:55","14:40","7. Stunde")
- neueStunde("14:45","15:30","8. Stunde")
- neueStunde("19:00","19:45","15. Stunde")
- end
- function neueStunde(anfang,ende,name)
- index = table.maxn(stunden)+1
- stunden[index] = {}
- stunden[index]["anfang"] = {}
- stunden[index]["anfang"]["stunde"] = tonumber(string.sub(anfang,1,2))
- stunden[index]["anfang"]["minute"] = tonumber(string.sub(anfang,4,5))
- stunden[index]["ende"] = {}
- stunden[index]["ende"]["stunde"] = tonumber(string.sub(ende,1,2))
- stunden[index]["ende"]["minute"] = tonumber(string.sub(ende,4,5))
- stunden[index]["name"] = name
- end
- function main()
- while true do
- info1,info2,info3,info4 = os.pullEvent()
- overwriteDropdown()
- swipeCheck()
- end
- end
- function homeMenu()
- curEnv = homeMenu
- curEnvName = "homeMenu"
- term.clear()
- headline("Home")
- end
- function testMenu()
- curEnv = testMenu
- curEnvName = "testMenu"
- term.clear()
- printStunde()
- end
- function swipeCheck()
- if info1 == "mouse_click" then
- lastClickPos = info3
- end
- if info1 == "mouse_drag" and lastClickPos then
- if lastClickPos - info3 > 2 then
- lastClickPos = nil
- if menus[curMenuPos+1] then
- curMenuPos = curMenuPos + 1
- menus[curMenuPos]()
- end
- elseif lastClickPos - info3 < -2 then
- lastClickPos = nil
- if menus[curMenuPos-1] then
- curMenuPos = curMenuPos - 1
- menus[curMenuPos]()
- end
- end
- end
- end
- function printStunde()
- zeit = getTime()
- curStundenNummer = nil
- for k,v in pairs(stunden) do
- if (v["anfang"]["stunde"]*60 + v["anfang"]["minute"]) <= zeit and (v["ende"]["stunde"]*60 + v["ende"]["minute"]) >= zeit then
- curStundenNummer = k
- end
- end
- if not curStundenNummer then
- curNaechsteStundeNummer = nil
- for k,v in pairs(stunden) do
- if curNaechsteStundeNummer then
- if (v["anfang"]["stunde"]*60 + v["anfang"]["minute"]) < (stunden[curNaechsteStundeNummer]["anfang"]["stunde"]*60 + stunden[curNaechsteStundeNummer]["anfang"]["minute"]) then
- curNaechsteStundeNummer = k
- end
- elseif (v["anfang"]["stunde"]*60 + v["anfang"]["minute"]) >= zeit then
- curNaechsteStundeNummer = k
- end
- end
- end
- if curStundenNummer then
- headline(stunden[curStundenNummer]["name"] .. " geht noch " .. (stunden[curStundenNummer]["ende"]["stunde"]*60 + stunden[curStundenNummer]["ende"]["minute"]) - zeit .. "m")
- elseif curNaechsteStundeNummer then
- headline((stunden[curNaechsteStundeNummer]["anfang"]["stunde"]*60 + stunden[curNaechsteStundeNummer]["anfang"]["minute"]) - zeit .. "m zur " .. stunden[curNaechsteStundeNummer]["name"])
- else
- headline("Schule ist vorbei")
- end
- end
- function getTime()
- curDate = os.date("*t")
- return curDate["hour"]*60 + curDate["min"]
- end
- -- buttons and all that stuff
- function betterRead(isBlacklist,filter)
- returnInfo = false
- if curReading ~= nil then
- if readingOutput[curReading] == nil then
- readingOutput[curReading] = ""
- end
- if curReadingPosX == nil then
- curReadingPosX = readingPosX+string.len(readingOutput[curReading])
- end
- if cursorBlinkTimer == nil then
- cursorBlinkTimer = os.startTimer(0.5)
- end
- if info1 == "char" then
- isBlacklisted = not isBlacklist
- for k,v in pairs(filter) do
- if info2 == filter[k] then
- isBlacklisted = isBlacklist
- end
- end
- if not isBlacklisted then
- if readingOutput[curReading] == nil then
- readingOutput[curReading] = ""
- end
- readingOutput[curReading] = readingOutput[curReading] .. info2
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(info2)
- curReadingPosX = curReadingPosX+1
- if blinkIsOn then
- term.write("_")
- end
- returnInfo = true
- end
- end
- if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
- curReadingPosX = curReadingPosX-1
- term.setCursorPos(curReadingPosX+1,readingPosY)
- term.write(" ")
- term.setCursorPos(curReadingPosX,readingPosY)
- if blinkIsOn then
- term.write("_")
- else
- term.write(" ")
- end
- readSave = readingOutput[curReading]
- readingOutput[curReading] = ""
- for i=1,string.len(readSave)-1 do
- readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
- end
- returnInfo = true
- end
- if info1 == "timer" and info2 == cursorBlinkTimer then
- if blinkIsOn then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write("_")
- else
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- cursorBlinkTimer = os.startTimer(0.5)
- blinkIsOn = (not blinkIsOn)
- end
- end
- return returnInfo
- end
- function changeReading(readingName,xPos,yPos)
- if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- blinkIsOn = true
- curReading = readingName
- readingPosX = xPos
- readingPosY = yPos
- curReadingPosX = nil
- if readingOutput[readingName] ~= nil then
- term.setCursorPos(xPos,yPos)
- term.write(readingOutput[readingName])
- end
- cursorBlinkTimer = os.startTimer(0.05)
- end
- function stopReading()
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- curReading = nil
- cursorBlinkTimer = nil
- end
- function resetEvent()
- info1 = nil
- end
- function createScrollmenu(name,x1,y1,x2,y2,content,position)
- scrollmenuLen[name]=0
- scrollmenuInfos[name]={["x1"]=x1,["y1"]=y1,["x2"]=x2,["y2"]=y2,["content"]=content,["position"]=position}
- for k,v in pairs(content) do
- if content[k] ~= nil then
- scrollmenuLen[name]=scrollmenuLen[name]+1
- else
- for i=1,table.maxn(content)-scrollmenuLen[name] do
- content[scrollmenuLen[name]+i] = content[scrollmenuLen[name]+1+i]
- end
- end
- end
- end
- function printScrollmenu(name)
- for i=1,math.min(scrollmenuLen[name],scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1) do
- if (i+scrollmenuInfos[name]["position"])%2==0 then
- term.setBackgroundColor(colors.gray)
- else
- term.setBackgroundColor(colors.black)
- end
- term.setCursorPos(scrollmenuInfos[name]["x1"],scrollmenuInfos[name]["y1"]+i-1)
- term.write(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]])
- for i2=1,scrollmenuInfos[name]["x2"]-scrollmenuInfos[name]["x1"]+1-string.len(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]]) do
- term.write(" ")
- end
- end
- end
- function checkScrollmenu(name)
- if info1 == "mouse_click" and info3 > scrollmenuInfos[name]["x1"]-1 and info3 < scrollmenuInfos[name]["x2"]+1 and info4 > scrollmenuInfos[name]["y1"]-1 and info4 < scrollmenuInfos[name]["y2"]+1 then
- resetEvent()
- return scrollmenuInfos[name]["content"][info4-scrollmenuInfos[name]["y1"]+1+scrollmenuInfos[name]["position"]]
- end
- if info1 == "mouse_scroll" and not (scrollmenuInfos[name]["position"]+info2 > scrollmenuLen[name]-(scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1)) and not (scrollmenuInfos[name]["position"]+info2 < 0) then
- scrollmenuInfos[name]["position"] = scrollmenuInfos[name]["position"] + info2
- printScrollmenu(name)
- end
- end
- function headline(headline)
- width = term.getSize()
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=(width/2)-(headline_lenght/2)+1
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- term.setTextColor(colors.green)
- if button_color~=nil then
- term.setTextColor(button_color)
- end
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- term.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
- term.write(button_text)
- end
- function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- if info1=="mouse_click" and info3 > b_check_x1-1 and info3 < b_check_x2+1 and info4 > b_check_y1-1 and info4 < b_check_y2+1 then
- resetEvent()
- return true
- else
- return false
- end
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- function overwriteDropdown()
- for i=1,dropdown["loaded"]["len"] do
- if not dropdown[dropdown["loaded"][i]]["is_open"] then
- if info1=="mouse_click" and info3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info4==dropdown[dropdown["loaded"][i]]["pos_y"] then
- info1 = "dropdown_menu"
- end
- else
- if info1=="mouse_click" and info3 < dropdown[dropdown["loaded"][i]]["pos_x2"]+1 and info3 > dropdown[dropdown["loaded"][i]]["pos_x1"]-1 and info4 < dropdown[dropdown["loaded"][i]]["pos_y"]+dropdown[dropdown["loaded"][i]]["len"] and info4 > dropdown[dropdown["loaded"][i]]["pos_y"]-1 then
- info1 = "dropdown_menu"
- end
- end
- end
- end
- function closeDropdownMenus()
- dropdown["loaded"]["len"]=0
- end
- function createDropdownMenu(name,options,pos_x1,pos_y,pos_x2)
- dropdown[name] = {}
- dropdown[name]["pos_x1"] = pos_x1
- dropdown[name]["pos_x2"] = pos_x2
- dropdown[name]["pos_y"] = pos_y
- dropdown[name]["is_open"] = false
- dropdown[name]["len"] = 0
- i=1
- while options[i]~= nil do
- dropdown[name]["len"] = dropdown[name]["len"]+1
- dropdown[name]["option"..i] = options[i]
- i=i+1
- end
- end
- function printDropdownMenu(name)
- for i=1,dropdown[name]["len"] do
- term.setCursorPos(dropdown[name]["pos_x1"],dropdown[name]["pos_y"]+i-1)
- if not (i%2==0) then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- else
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- end
- if dropdown[name]["is_open"] or i==1 then
- term.write(dropdown[name]["option"..i])
- for i1=1,(dropdown[name]["pos_x2"]-dropdown[name]["pos_x1"])-string.len(dropdown[name]["option"..i])+1 do
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function dropdownMenuCheck(name)
- if dropdown[name]["is_open"] then
- if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4==dropdown[name]["pos_y"] then
- dropdown[name]["is_open"]=false
- printMenu(curEnv)
- return "closed"
- end
- if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4 < dropdown[name]["pos_y"]+dropdown[name]["len"]+1 and info4 > dropdown[name]["pos_y"] then
- option_save = dropdown[name]["option"..1]
- dropdown[name]["option"..1] = dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1]
- dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1] = option_save
- dropdown[name]["is_open"]=false
- printMenu(curEnv)
- return "changed"
- end
- else
- if info1=="dropdown_menu" and info3 < dropdown[name]["pos_x2"]+1 and info3 > dropdown[name]["pos_x1"]-1 and info4==dropdown[name]["pos_y"] then
- dropdown[name]["is_open"]=true
- printDropdownMenu(name)
- return "opened"
- end
- end
- end
- function loadDropdownMenu(name)
- dropdown["loaded"]["len"] = dropdown["loaded"]["len"]+1
- dropdown["loaded"][dropdown["loaded"]["len"]] = name
- printDropdownMenu(name)
- end
- function printMenu(env)
- blub = load(env)
- end
- function filledSquare(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
- term.setBackgroundColor(fill_color)
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=fill_y1
- while curr_fill_pos_y~=fill_y2+1 do
- while curr_fill_pos_x~=fill_x2+1 do
- term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
- term.write(" ")
- curr_fill_pos_x=curr_fill_pos_x+1
- end
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=curr_fill_pos_y+1
- end
- term.setBackgroundColor(colors.black)
- end
- function lineCheck(y)
- if info1 == "mouse_click" and info4 == y then
- return true
- else
- return false
- end
- end
- -------------------------------------------------
- startup()
- homeMenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement