Advertisement
Arc13

arcClock

Jul 16th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.84 KB | None | 0 0
  1. local args = {...}
  2. local funcRun = true
  3.  
  4. if not fs.exists("arcui") or args[1] == "true" then
  5.    print("Downloading arcUI...")
  6.    shell.run("pastebin get NuZUGEmn arcui")
  7. end
  8.  
  9. if not fs.exists("time") or args[1] == "true" then
  10.    print("Downloading time...")
  11.    shell.run("pastebin get 6nArsPfK time")
  12. end
  13.  
  14. os.loadAPI("arcui")
  15. os.loadAPI("time")
  16.  
  17. local monX, monY = term.getSize()
  18.  
  19. if settings.get("arcclock.lang", "not") == "not" or settings.get("arcclock.username", "not") == "not" then
  20.    local lang = "en"
  21.    local username = "player"
  22.  
  23.    arcui.drawWindow("arcClock")
  24.    arcui.drawLabel("welcome_label", 1, 3, "Welcome to arcClock setup !")
  25.    arcui.drawTextbox("username_textbox", 1, 6, monX, "Your username")
  26.    arcui.drawLabel("lang_label", 1, 8, "Language :")
  27.    arcui.drawButton("fr_btn", monX / 3 + monX / 3, 10, monX, 12, colors.cyan, "Français")
  28.    arcui.drawButton("en_btn", 1, 10, monX / 3, 12, colors.cyan, "English")
  29.    arcui.drawButton("ok_btn", 1, monY - 2, monX, monY, colors.green, ">")
  30.  
  31.    local function loop()
  32.       while true do
  33.          event, a1, a2 = os.pullEvent()
  34.  
  35.          if event == "button_close_clicked" then
  36.             arcui.closeWindow()
  37.  
  38.             return true
  39.          elseif event == "button_clicked" then
  40.             if a1 == "fr_btn" then
  41.                lang = "fr"
  42.             elseif a1 == "en_btn" then
  43.                lang = "en"
  44.             elseif a1 == "ok_btn" then
  45.                local rep = arcui.openDialog("confirm_dialog", "arcClock", "Save changes ?")
  46.                if rep == true then
  47.                   settings.set("arcclock.lang", lang)
  48.                   settings.set("arcclock.username", username)
  49.                   settings.save(".settings")
  50.                   arcui.closeWindow()
  51.  
  52.                   error("Please restart app")
  53.                   return true
  54.                else
  55.                   arcui.redrawWindow("arcClock")
  56.                end
  57.             end
  58.          elseif event == "textbox_text" then
  59.             if a1 == "username_textbox" then
  60.                if a2 ~= "" then
  61.                   username = a2
  62.                else
  63.                   username = "player"
  64.                end
  65.             end
  66.          end
  67.       end
  68.    end
  69.  
  70.    parallel.waitForAll(loop, arcui.eventHandler)
  71. end
  72.  
  73. local langTexts = {fr = {"Bonjour", "Bonne nuit", "Bonjour", "Bonsoir", "Il est "}, en = {"Good afternoon", "Good night", "Good morning", "Good evening", "It's "}}
  74.  
  75. arcui.deleteAllWidgets()
  76. arcui.bRun = true
  77.  
  78. arcui.drawWindow("arcClock")
  79. arcui.drawLabel("msg_label", 1, monY - 1, "N/A")
  80. arcui.drawLabel("time_label", 1, monY, "N/A")
  81.  
  82. local function eventHandler()
  83.    while true do
  84.       event, a1, a2 = os.pullEvent()
  85.  
  86.       if event == "button_close_clicked" then
  87.          funcRun = false
  88.          arcui.closeWindow()
  89.  
  90.          return true
  91.       end
  92.    end
  93. end
  94.  
  95. local function loop()
  96.    while funcRun do
  97.       arcui.changeValue("time_label", "text", langTexts[settings.get("arcclock.lang")][5]..time.getWorldComplete())
  98.  
  99.       if time.isWorldDay() then
  100.          arcui.changeValue("msg_label", "text", langTexts[settings.get("arcclock.lang")][1]..", "..settings.get("arcclock.username"))
  101.  
  102.          paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  103.          paintutils.drawBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.orange)
  104.          paintutils.drawFilledBox(monX / 2 - 2, 4, monX / 2 + 2, 8, colors.yellow)
  105.       elseif time.isWorldNight() then
  106.          arcui.changeValue("msg_label", "text", langTexts[settings.get("arcclock.lang")][2]..", "..settings.get("arcclock.username"))
  107.  
  108.          if time.getWorldMoonPhase() == 1 then
  109.            paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  110.            paintutils.drawBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  111.            paintutils.drawFilledBox(monX / 2 - 2, 3, monX / 2 + 3, 8, colors.white)
  112.          elseif time.getWorldMoonPhase() == 2 then
  113.            paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  114.            paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  115.            paintutils.drawFilledBox(monX / 2, 3, monX / 2 + 3, 9, colors.white)
  116.            paintutils.drawLine(monX / 2 - 1, 4, monX / 2 - 1, 8, colors.white)
  117.            paintutils.drawLine(monX / 2 - 2, 5, monX / 2 - 2, 7, colors.white)
  118.          elseif time.getWorldMoonPhase() == 3 then
  119.            paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  120.            paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  121.            paintutils.drawFilledBox(monX / 2, 3, monX / 2 + 3, 9, colors.gray)
  122.            paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 - 1, 9, colors.black)
  123.            paintutils.drawFilledBox(monX / 2 + 2, 3, monX / 2 + 3, 7, colors.white)
  124.          elseif time.getWorldMoonPhase() == 4 then
  125.            paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  126.            paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  127.            paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2, 9, colors.black)
  128.            paintutils.drawLine(monX / 2 + 1, 4, monX / 2 + 1, 8, colors.black)
  129.            paintutils.drawLine(monX / 2 + 2, 5, monX / 2 + 2, 7, colors.black)
  130.          elseif time.getWorldMoonPhase() == 5 then
  131.            paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  132.            paintutils.drawBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  133.            paintutils.drawFilledBox(monX / 2 - 2, 4, monX / 2 + 2, 8, colors.black)
  134.          elseif time.getWorldMoonPhase() == 6 then
  135.            paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  136.            paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  137.            paintutils.drawFilledBox(monX / 2, 3, monX / 2 + 3, 9, colors.black)
  138.            paintutils.drawLine(monX / 2 - 1, 4, monX / 2 - 1, 8, colors.black)
  139.            paintutils.drawLine(monX / 2 - 2, 5, monX / 2 - 2, 7, colors.black)
  140.          elseif time.getWorldMoonPhase() == 7 then
  141.              paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  142.              paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  143.              paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2, 9, colors.gray)
  144.              paintutils.drawFilledBox(monX / 2 + 1, 3, monX / 2 + 3, 9, colors.black)
  145.              paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 - 2, 7, colors.white)
  146.            elseif time.getWorldMoonPhase() == 8 then
  147.              paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  148.              paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  149.              paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2, 9, colors.white)
  150.              paintutils.drawLine(monX / 2 + 1, 4, monX / 2 + 1, 8, colors.white)
  151.              paintutils.drawLine(monX / 2 + 2, 5, monX / 2 + 2, 7, colors.white)
  152.          end
  153.       elseif time.isWorldDawn() then
  154.          arcui.changeValue("msg_label", "text", langTexts[settings.get("arcclock.lang")][3]..", "..settings.get("arcclock.username"))
  155.  
  156.          paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  157.          paintutils.drawBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.orange)
  158.          paintutils.drawFilledBox(monX / 2 - 2, 4, monX / 2 + 2, 8, colors.yellow)
  159.          paintutils.drawLine(monX / 2 + 3, 3, monX / 2 - 3, 9, colors.lightGray)
  160.          paintutils.drawLine(monX / 2 + 3, 4, monX / 2 - 2, 9, colors.lightGray)
  161.          paintutils.drawLine(monX / 2 + 3, 5, monX / 2 - 1, 9, colors.lightGray)
  162.          paintutils.drawLine(monX / 2 + 3, 6, monX / 2, 9, colors.lightGray)
  163.          paintutils.drawLine(monX / 2 + 3, 7, monX / 2 + 1, 9, colors.lightGray)
  164.          paintutils.drawLine(monX / 2 + 3, 8, monX / 2 + 2, 9, colors.lightGray)
  165.          paintutils.drawLine(monX / 2 + 3, 9, monX / 2 + 3, 9, colors.lightGray)
  166.       elseif time.isWorldDusk() then
  167.          arcui.changeValue("msg_label", "text", langTexts[settings.get("arcclock.lang")][4]..", "..settings.get("arcclock.username"))
  168.  
  169.          paintutils.drawFilledBox(1, 3, monX, 9, colors.lightGray)
  170.          paintutils.drawBox(monX / 2 - 3, 3, monX / 2 + 3, 9, colors.gray)
  171.          paintutils.drawFilledBox(monX / 2 - 3, 3, monX / 2 + 2, 8, colors.white)
  172.          paintutils.drawLine(monX / 2 + 3, 3, monX / 2 - 3, 9, colors.lightGray)
  173.          paintutils.drawLine(monX / 2 + 2, 3, monX / 2 - 3, 8, colors.lightGray)
  174.          paintutils.drawLine(monX / 2 + 1, 3, monX / 2 - 3, 7, colors.lightGray)
  175.          paintutils.drawLine(monX / 2, 3, monX / 2 - 3, 6, colors.lightGray)
  176.          paintutils.drawLine(monX / 2 - 1, 3, monX / 2 - 3, 5, colors.lightGray)
  177.          paintutils.drawLine(monX / 2 - 2, 3, monX / 2 - 3, 4, colors.lightGray)
  178.          paintutils.drawLine(monX / 2 - 3, 3, monX / 2 - 3, 3, colors.lightGray)
  179.       end
  180.  
  181.       term.setBackgroundColor(colors.lightGray)
  182.  
  183.       sleep(0.5)
  184.    end
  185. end
  186.  
  187. parallel.waitForAll(eventHandler, arcui.eventHandler, loop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement