Advertisement
Chaos_Cash

schulApp.lua

Nov 22nd, 2024 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.41 KB | None | 0 0
  1. function startup()
  2. mobile.openKeyboard(false)
  3.  
  4. readingOutput = {}
  5.  
  6. blinkIsOn = true
  7.  
  8. menus = {}
  9.  
  10. scrollmenuLen={}
  11. scrollmenuInfos={}
  12.  
  13. dropdown = {}
  14. dropdown["loaded"] = {}
  15. dropdown["loaded"]["len"] = 0
  16.  
  17.  
  18. stunden = {}
  19.  
  20. menus[1] = homeMenu
  21. menus[2] = testMenu
  22. curMenuPos = 1
  23.  
  24. neueStunde("08:00","08:45","1. Stunde")
  25. neueStunde("08:45","09:30","2. Stunde")
  26. neueStunde("09:30","09:50","Hofpause")
  27. neueStunde("09:50","10:35","3. Stunde")
  28. neueStunde("10:40","11:25","4. Stunde")
  29. neueStunde("11:30","12:15","Mittagspause")
  30. neueStunde("12:15","13:00","5. Stunde")
  31. neueStunde("13:05","13:50","6. Stunde")
  32. neueStunde("13:55","14:40","7. Stunde")
  33. neueStunde("14:45","15:30","8. Stunde")
  34. neueStunde("19:00","19:45","15. Stunde")
  35. end
  36.  
  37.  
  38.  
  39. function neueStunde(anfang,ende,name)
  40. index = table.maxn(stunden)+1
  41. stunden[index] = {}
  42. stunden[index]["anfang"] = {}
  43. stunden[index]["anfang"]["stunde"] = tonumber(string.sub(anfang,1,2))
  44. stunden[index]["anfang"]["minute"] = tonumber(string.sub(anfang,4,5))
  45. stunden[index]["ende"] = {}
  46. stunden[index]["ende"]["stunde"] = tonumber(string.sub(ende,1,2))
  47. stunden[index]["ende"]["minute"] = tonumber(string.sub(ende,4,5))
  48. stunden[index]["name"] = name
  49.  
  50. end
  51.  
  52.  
  53.  
  54. function main()
  55.  
  56. while true do
  57.  
  58. info1,info2,info3,info4 = os.pullEvent()
  59. overwriteDropdown()
  60. swipeCheck()
  61.  
  62.  
  63.  
  64. end
  65.  
  66. end
  67.  
  68.  
  69.  
  70. function homeMenu()
  71. curEnv = homeMenu
  72. curEnvName = "homeMenu"
  73. term.clear()
  74. headline("Home")
  75.  
  76. end
  77.  
  78.  
  79.  
  80. function testMenu()
  81. curEnv = testMenu
  82. curEnvName = "testMenu"
  83. term.clear()
  84. printStunde()
  85.  
  86. end
  87.  
  88.  
  89.  
  90. function swipeCheck()
  91.  
  92. if info1 == "mouse_click" then
  93. lastClickPos = info3
  94. end
  95.  
  96. if info1 == "mouse_drag" and lastClickPos then
  97. if lastClickPos - info3 > 2 then
  98. lastClickPos = nil
  99. if menus[curMenuPos+1] then
  100. curMenuPos = curMenuPos + 1
  101. menus[curMenuPos]()
  102. end
  103. elseif lastClickPos - info3 < -2 then
  104. lastClickPos = nil
  105. if menus[curMenuPos-1] then
  106. curMenuPos = curMenuPos - 1
  107. menus[curMenuPos]()
  108. end
  109. end
  110. end
  111.  
  112. end
  113.  
  114.  
  115.  
  116. function printStunde()
  117.  
  118. zeit = getTime()
  119. curStundenNummer = nil
  120.  
  121. for k,v in pairs(stunden) do
  122. if (v["anfang"]["stunde"]*60 + v["anfang"]["minute"]) <= zeit and (v["ende"]["stunde"]*60 + v["ende"]["minute"]) >= zeit then
  123. curStundenNummer = k
  124. end
  125. end
  126.  
  127.  
  128. if not curStundenNummer then
  129. curNaechsteStundeNummer = nil
  130. for k,v in pairs(stunden) do
  131. if curNaechsteStundeNummer then
  132. if (v["anfang"]["stunde"]*60 + v["anfang"]["minute"]) < (stunden[curNaechsteStundeNummer]["anfang"]["stunde"]*60 + stunden[curNaechsteStundeNummer]["anfang"]["minute"]) then
  133. curNaechsteStundeNummer = k
  134. end
  135. elseif (v["anfang"]["stunde"]*60 + v["anfang"]["minute"]) >= zeit then
  136. curNaechsteStundeNummer = k
  137. end
  138. end
  139. end
  140.  
  141.  
  142. if curStundenNummer then
  143. headline(stunden[curStundenNummer]["name"] .. " geht noch " .. (stunden[curStundenNummer]["ende"]["stunde"]*60 + stunden[curStundenNummer]["ende"]["minute"]) - zeit .. "m")
  144. elseif curNaechsteStundeNummer then
  145. headline((stunden[curNaechsteStundeNummer]["anfang"]["stunde"]*60 + stunden[curNaechsteStundeNummer]["anfang"]["minute"]) - zeit .. "m zur " .. stunden[curNaechsteStundeNummer]["name"])
  146. else
  147. headline("Schule ist vorbei")
  148. end
  149.  
  150.  
  151.  
  152. end
  153.  
  154.  
  155.  
  156. function getTime()
  157. curDate = os.date("*t")
  158.  
  159. return curDate["hour"]*60 + curDate["min"]
  160.  
  161. end
  162.  
  163.  
  164. -- buttons and all that stuff
  165.  
  166. function betterRead(isBlacklist,filter)
  167. returnInfo = false
  168.  
  169. if curReading ~= nil then
  170.  
  171. if readingOutput[curReading] == nil then
  172. readingOutput[curReading] = ""
  173. end
  174.  
  175. if curReadingPosX == nil then
  176. curReadingPosX = readingPosX+string.len(readingOutput[curReading])
  177. end
  178.  
  179.  
  180. if cursorBlinkTimer == nil then
  181. cursorBlinkTimer = os.startTimer(0.5)
  182. end
  183.  
  184.  
  185. if info1 == "char" then
  186.  
  187. isBlacklisted = not isBlacklist
  188. for k,v in pairs(filter) do
  189.  
  190. if info2 == filter[k] then
  191. isBlacklisted = isBlacklist
  192. end
  193.  
  194. end
  195.  
  196.  
  197. if not isBlacklisted then
  198. if readingOutput[curReading] == nil then
  199. readingOutput[curReading] = ""
  200. end
  201.  
  202. readingOutput[curReading] = readingOutput[curReading] .. info2
  203. term.setCursorPos(curReadingPosX,readingPosY)
  204. term.write(info2)
  205. curReadingPosX = curReadingPosX+1
  206.  
  207. if blinkIsOn then
  208. term.write("_")
  209. end
  210.  
  211. returnInfo = true
  212. end
  213.  
  214. end
  215.  
  216.  
  217. if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
  218.  
  219. curReadingPosX = curReadingPosX-1
  220. term.setCursorPos(curReadingPosX+1,readingPosY)
  221. term.write(" ")
  222. term.setCursorPos(curReadingPosX,readingPosY)
  223. if blinkIsOn then
  224. term.write("_")
  225. else
  226. term.write(" ")
  227. end
  228.  
  229. readSave = readingOutput[curReading]
  230. readingOutput[curReading] = ""
  231. for i=1,string.len(readSave)-1 do
  232. readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
  233. end
  234.  
  235. returnInfo = true
  236. end
  237.  
  238.  
  239. if info1 == "timer" and info2 == cursorBlinkTimer then
  240.  
  241. if blinkIsOn then
  242. term.setCursorPos(curReadingPosX,readingPosY)
  243. term.write("_")
  244. else
  245. term.setCursorPos(curReadingPosX,readingPosY)
  246. term.write(" ")
  247. end
  248.  
  249. cursorBlinkTimer = os.startTimer(0.5)
  250. blinkIsOn = (not blinkIsOn)
  251. end
  252.  
  253.  
  254. end
  255.  
  256. return returnInfo
  257. end
  258.  
  259.  
  260.  
  261. function changeReading(readingName,xPos,yPos)
  262. if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
  263. term.setCursorPos(curReadingPosX,readingPosY)
  264. term.write(" ")
  265. end
  266.  
  267. blinkIsOn = true
  268. curReading = readingName
  269. readingPosX = xPos
  270. readingPosY = yPos
  271. curReadingPosX = nil
  272. if readingOutput[readingName] ~= nil then
  273. term.setCursorPos(xPos,yPos)
  274. term.write(readingOutput[readingName])
  275. end
  276. cursorBlinkTimer = os.startTimer(0.05)
  277.  
  278. end
  279.  
  280.  
  281.  
  282. function stopReading()
  283.  
  284. term.setCursorPos(curReadingPosX,readingPosY)
  285. term.write(" ")
  286. curReading = nil
  287. cursorBlinkTimer = nil
  288.  
  289. end
  290.  
  291.  
  292.  
  293. function resetEvent()
  294. info1 = nil
  295. end
  296.  
  297.  
  298.  
  299. function createScrollmenu(name,x1,y1,x2,y2,content,position)
  300. scrollmenuLen[name]=0
  301. scrollmenuInfos[name]={["x1"]=x1,["y1"]=y1,["x2"]=x2,["y2"]=y2,["content"]=content,["position"]=position}
  302.  
  303. for k,v in pairs(content) do
  304. if content[k] ~= nil then
  305. scrollmenuLen[name]=scrollmenuLen[name]+1
  306. else
  307. for i=1,table.maxn(content)-scrollmenuLen[name] do
  308. content[scrollmenuLen[name]+i] = content[scrollmenuLen[name]+1+i]
  309. end
  310. end
  311. end
  312.  
  313. end
  314.  
  315.  
  316.  
  317.  
  318. function printScrollmenu(name)
  319.  
  320. for i=1,math.min(scrollmenuLen[name],scrollmenuInfos[name]["y2"]-scrollmenuInfos[name]["y1"]+1) do
  321.  
  322. if (i+scrollmenuInfos[name]["position"])%2==0 then
  323. term.setBackgroundColor(colors.gray)
  324. else
  325. term.setBackgroundColor(colors.black)
  326. end
  327.  
  328. term.setCursorPos(scrollmenuInfos[name]["x1"],scrollmenuInfos[name]["y1"]+i-1)
  329. term.write(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]])
  330.  
  331. for i2=1,scrollmenuInfos[name]["x2"]-scrollmenuInfos[name]["x1"]+1-string.len(scrollmenuInfos[name]["content"][i+scrollmenuInfos[name]["position"]]) do
  332. term.write(" ")
  333. end
  334.  
  335. end
  336.  
  337.  
  338.  
  339. end
  340.  
  341.  
  342.  
  343. function checkScrollmenu(name)
  344.  
  345. 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
  346. resetEvent()
  347. return scrollmenuInfos[name]["content"][info4-scrollmenuInfos[name]["y1"]+1+scrollmenuInfos[name]["position"]]
  348. end
  349.  
  350. 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
  351. scrollmenuInfos[name]["position"] = scrollmenuInfos[name]["position"] + info2
  352. printScrollmenu(name)
  353. end
  354.  
  355.  
  356. end
  357.  
  358.  
  359.  
  360. function headline(headline)
  361. width = term.getSize()
  362. headline_lenght=string.len(" "..headline.." ")
  363. headline_pos=(width/2)-(headline_lenght/2)+1
  364. term.setCursorPos(headline_pos,1)
  365. term.setBackgroundColor(colors.yellow)
  366. term.setTextColor(colors.blue)
  367. term.write(" "..headline.." ")
  368. term.setBackgroundColor(colors.black)
  369. term.setTextColor(colors.white)
  370. end
  371.  
  372.  
  373.  
  374. function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
  375. term.setTextColor(colors.green)
  376.  
  377. if button_color~=nil then
  378. term.setTextColor(button_color)
  379. end
  380.  
  381. square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  382. 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)
  383. term.write(button_text)
  384. end
  385.  
  386.  
  387.  
  388. function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  389. 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
  390. resetEvent()
  391. return true
  392. else
  393. return false
  394. end
  395. end
  396.  
  397.  
  398.  
  399. function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  400. x_1=x1
  401. y_1=y1
  402. x_2=x2
  403. y_2=y2
  404. while x_1~=x2+1 do
  405. term.setBackgroundColor(back_color_square)
  406. term.setCursorPos(x_1,y_1)
  407. if text_color~=nil then
  408. term.setTextColor(text_color)
  409. end
  410. term.write(symbol_square_x)
  411. x_1=x_1+1
  412. end
  413.  
  414. while y_1~=y2-1 do
  415. term.setCursorPos(x_1-1,y_1+1)
  416. term.write(symbol_square_y)
  417. y_1=y_1+1
  418. end
  419. x2=x2-1
  420. while x_2~=x1-1 do
  421. term.setCursorPos(x_2,y_2)
  422. term.write(symbol_square_x)
  423. x_2=x_2-1
  424. end
  425.  
  426. while y_2~=y1+1 do
  427. term.setCursorPos(x_2+1,y_2-1)
  428. term.write(symbol_square_y)
  429. y_2=y_2-1
  430. end
  431. term.setBackgroundColor(colors.black)
  432. end
  433.  
  434.  
  435.  
  436. function overwriteDropdown()
  437.  
  438. for i=1,dropdown["loaded"]["len"] do
  439.  
  440. if not dropdown[dropdown["loaded"][i]]["is_open"] then
  441.  
  442. 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
  443. info1 = "dropdown_menu"
  444. end
  445.  
  446. else
  447.  
  448. 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
  449. info1 = "dropdown_menu"
  450. end
  451.  
  452. end
  453.  
  454. end
  455. end
  456.  
  457.  
  458.  
  459. function closeDropdownMenus()
  460. dropdown["loaded"]["len"]=0
  461. end
  462.  
  463.  
  464.  
  465. function createDropdownMenu(name,options,pos_x1,pos_y,pos_x2)
  466.  
  467. dropdown[name] = {}
  468. dropdown[name]["pos_x1"] = pos_x1
  469. dropdown[name]["pos_x2"] = pos_x2
  470. dropdown[name]["pos_y"] = pos_y
  471. dropdown[name]["is_open"] = false
  472. dropdown[name]["len"] = 0
  473.  
  474. i=1
  475. while options[i]~= nil do
  476. dropdown[name]["len"] = dropdown[name]["len"]+1
  477. dropdown[name]["option"..i] = options[i]
  478. i=i+1
  479. end
  480.  
  481. end
  482.  
  483.  
  484.  
  485. function printDropdownMenu(name)
  486.  
  487. for i=1,dropdown[name]["len"] do
  488. term.setCursorPos(dropdown[name]["pos_x1"],dropdown[name]["pos_y"]+i-1)
  489.  
  490. if not (i%2==0) then
  491. term.setBackgroundColor(colors.gray)
  492. term.setTextColor(colors.white)
  493. else
  494. term.setBackgroundColor(colors.lightGray)
  495. term.setTextColor(colors.black)
  496. end
  497.  
  498. if dropdown[name]["is_open"] or i==1 then
  499. term.write(dropdown[name]["option"..i])
  500. for i1=1,(dropdown[name]["pos_x2"]-dropdown[name]["pos_x1"])-string.len(dropdown[name]["option"..i])+1 do
  501. term.write(" ")
  502. end
  503. end
  504. end
  505.  
  506. term.setBackgroundColor(colors.black)
  507. term.setTextColor(colors.white)
  508. end
  509.  
  510.  
  511.  
  512. function dropdownMenuCheck(name)
  513.  
  514. if dropdown[name]["is_open"] then
  515.  
  516. 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
  517. dropdown[name]["is_open"]=false
  518. printMenu(curEnv)
  519. return "closed"
  520. end
  521.  
  522. 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
  523. option_save = dropdown[name]["option"..1]
  524. dropdown[name]["option"..1] = dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1]
  525. dropdown[name]["option"..info4-dropdown[name]["pos_y"]+1] = option_save
  526. dropdown[name]["is_open"]=false
  527. printMenu(curEnv)
  528. return "changed"
  529. end
  530.  
  531. else
  532.  
  533. 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
  534. dropdown[name]["is_open"]=true
  535. printDropdownMenu(name)
  536. return "opened"
  537. end
  538.  
  539. end
  540.  
  541. end
  542.  
  543.  
  544.  
  545. function loadDropdownMenu(name)
  546. dropdown["loaded"]["len"] = dropdown["loaded"]["len"]+1
  547. dropdown["loaded"][dropdown["loaded"]["len"]] = name
  548. printDropdownMenu(name)
  549. end
  550.  
  551.  
  552.  
  553. function printMenu(env)
  554.  
  555. blub = load(env)
  556.  
  557. end
  558.  
  559.  
  560.  
  561. function filledSquare(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
  562. term.setBackgroundColor(fill_color)
  563. curr_fill_pos_x=fill_x1
  564. curr_fill_pos_y=fill_y1
  565. while curr_fill_pos_y~=fill_y2+1 do
  566. while curr_fill_pos_x~=fill_x2+1 do
  567. term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
  568. term.write(" ")
  569. curr_fill_pos_x=curr_fill_pos_x+1
  570. end
  571. curr_fill_pos_x=fill_x1
  572. curr_fill_pos_y=curr_fill_pos_y+1
  573. end
  574. term.setBackgroundColor(colors.black)
  575. end
  576.  
  577.  
  578.  
  579. function lineCheck(y)
  580.  
  581. if info1 == "mouse_click" and info4 == y then
  582. return true
  583. else
  584. return false
  585. end
  586.  
  587. end
  588.  
  589. -------------------------------------------------
  590.  
  591.  
  592.  
  593.  
  594. startup()
  595. homeMenu()
  596. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement