SHOW:
|
|
- or go back to the newest paste.
1 | - | --NhUI |
1 | + | -- future version wish: table implementation? |
2 | - | nhver = "v0.4u" |
2 | + | -- cfg: add nhui auto update preferences [versions, hotfixes] (under new menu under options > preferences > updating > versions/hotfixes) |
3 | - | wip = 0 |
3 | + | -- misc: swap uninstall and about |
4 | -- .nhuicfg: add variable to detect if config is outdated. give warning before install of a new version | |
5 | - | --Loading |
5 | + | -- desk: add hotfix handling structure (versions fed by legacy startup, handled by desktop) |
6 | - | if deskLoad==nil then |
6 | + | -- hotfix: detect on startup; have options for more information on the hotfix; option for to never ask again; version list keeps base installs; if multiple hotfixes available, let user select hotfix to view more info/install on startup |
7 | -- if auto update is true display message letting user know it's about to apply a hotfix | |
8 | - | local cycles = {" ",". ",".. ","..."," .."," ."," "} |
8 | + | -- hotfix function: checks for internet, runs hotfix link that detects target nhui programs and deletes them, downloads new versions in their place |
9 | - | local message = "Loading NhUI "..nhver |
9 | + | -- updates: add warning if version is not compatible |
10 | - | for i=0,7 do |
10 | + | -- add a spoof disclaimer for comedic effect (not responsible for damage caused for virtual computer etc) |
11 | - | term.setCursorPos(1,1) |
11 | + | |
12 | - | print(message..cycles[(i%#cycles)+1]) |
12 | + | -- basic variables and functions |
13 | - | sleep(.1) |
13 | + | nhver,wip="v0.5",true |
14 | local nhuiProgs={["login"]="UwwmSJwL",["updater"]="ag7RuWX4",[".nhuicfg"]="mbD7EU2J"} | |
15 | - | deskLoad=false |
15 | + | local nhuiProgList={"startup","desktop","updater","login",".nhuicfg"} |
16 | ||
17 | local colorList={["red"]=16384,["yellow"]=16,["white"]=1,["lightGrey"]=256,["grey"]=128} | |
18 | - | --Unstable version detected |
18 | + | local colorListMono={["red"]=1,["yellow"]=1,["white"]=1,["lightGrey"]=256,["grey"]=128} |
19 | - | local function suggestedUpdate() |
19 | + | local function setTxtColor(color) |
20 | - | if wip==2 and sugUpdate==nil then sugUpdate=false |
20 | + | term.setTextColor(term.isColor() and colorList[color] or colorListMono[color]) |
21 | - | term.clear() |
21 | + | |
22 | - | term.setCursorPos(1,1) |
22 | + | |
23 | - | sleep(.1) |
23 | + | local function printAt(text,setX,setY) |
24 | - | print("You're running an unstable WIP build.\nUpdate to the newest "..nhver.." build now?") |
24 | + | term.setCursorPos(setX,setY) print(text) |
25 | - | print("\n1|Yes\n2|No") |
25 | + | end |
26 | ||
27 | - | local event, b, x, y = os.pullEventRaw() |
27 | + | |
28 | - | if event == "key" then |
28 | + | term.clear() term.setCursorPos(1,1) |
29 | - | if b==2 then |
29 | + | |
30 | - | term.clear() |
30 | + | |
31 | - | term.setCursorPos(1,1) |
31 | + | local function pingPastebin() |
32 | - | shell.run("delete","installer") |
32 | + | http.request("http://pastebin.com") |
33 | - | shell.run("pastebin","get","WCdpCaEm","installer") |
33 | + | local requesting=true |
34 | - | shell.run("installer") |
34 | + | while requesting do |
35 | - | elseif b==3 then |
35 | + | |
36 | - | break |
36 | + | print("Waiting for pastebin.com...") |
37 | - | end |
37 | + | local event=os.pullEvent() |
38 | - | elseif event == "mouse_click" then |
38 | + | if event=="http_success" then internet,requesting=true,false |
39 | - | if b==1 and x>=1 and x<=5 and y==4 then |
39 | + | elseif event=="http_failure" then internet,requesting=false end |
40 | - | shell.run("delete","installer") |
40 | + | |
41 | - | shell.run("pastebin","get","WCdpCaEm","installer") |
41 | + | if internet==false then print("...could not connect.") sleep(1) resetScreen() end |
42 | - | shell.run("installer") |
42 | + | |
43 | - | elseif b==1 and x>=1 and x<=4 and y==5 then |
43 | + | |
44 | - | break |
44 | + | local function anyKey() |
45 | - | end |
45 | + | sleep(.2) |
46 | - | end |
46 | + | local event,b,x,y=os.pullEventRaw() |
47 | if (event=="key" and b~=0) or (event=="mouse_click" and x>0 and y>0) then anyKeyReq=nil end | |
48 | end | |
49 | ||
50 | ||
51 | - | --Variables |
51 | + | local function openConfig() -- needs to be formatted to fs.open |
52 | - | if not term.isColor then |
52 | + | local file=fs.open(".nhuicfg", "r") |
53 | - | else |
53 | + | sContents=file:read() |
54 | - | tBarC = 32768 |
54 | + | file:close() |
55 | - | tBartC = 1 |
55 | + | tContents=textutils.unserialize(sContents) |
56 | - | backColor = 32768 |
56 | + | |
57 | ||
58 | local function editConfigLine(line,text) -- needs to be formatted to fs.open | |
59 | - | --Desktop prep |
59 | + | table.remove(tContents,line) |
60 | table.insert(tContents,line,text) | |
61 | end | |
62 | - | term.setCursorPos(1,1) |
62 | + | |
63 | local function saveConfig() -- needs to be formatted to fs.open | |
64 | sContents=textutils.serialize(tContents) | |
65 | - | local function setBackColor() |
65 | + | local file=fs.open(".nhuicfg","w") |
66 | - | if not term.isColor then |
66 | + | file:write(sContents) |
67 | - | elseif term.isColor() then |
67 | + | file:close() |
68 | - | term.setBackgroundColor(backColor) |
68 | + | |
69 | - | else |
69 | + | |
70 | - | term.setBackgroundColor(backColor) |
70 | + | -- menu-related functions |
71 | openConfig() -- needs to be formatted to fs.open | |
72 | local deskColors={["menuColor"]=tContents[4],["menuTextColor"]=tContents[5],["backgroundColor"]=tContents[6],["textColor"]=tContents[7],["secondaryTextColor"]=tContents[8],["tertiaryTextColor"]=tContents[9]} | |
73 | saveConfig() | |
74 | - | local function setTextWhite() |
74 | + | |
75 | - | if not term.isColor then |
75 | + | local function menuBar() |
76 | - | elseif term.isColor() then |
76 | + | term.setCursorPos(1,1) term.clearLine() |
77 | - | term.setTextColor(1) |
77 | + | term.setBackgroundColor(deskColors["menuColor"]) |
78 | - | else |
78 | + | term.setTextColor(deskColors["menuTextColor"]) |
79 | - | term.setTextColor(1) |
79 | + | printAt((s==0 or s==nil) and "1|Start 2|Apps 3|Options 4|NhUI" or "-|Start -|Apps -|Options -|NhUI",2,1) |
80 | end | |
81 | ||
82 | local function drawMenus() | |
83 | - | local function titleBarColor() |
83 | + | term.setTextColor(deskColors["menuTextColor"]) |
84 | - | if not term.isColor then |
84 | + | term.setBackgroundColor(deskColors["menuColor"]) |
85 | - | elseif term.isColor() then |
85 | + | if s==1 then printAt("1|CraftOS\n ---------\n 2|Shutdown\n 3|Restart",2,2) |
86 | - | term.setBackgroundColor(tBarC) |
86 | + | elseif s==2 then printAt("1|Clock",12,2) |
87 | - | term.setTextColor(tBartC) |
87 | + | elseif s==3 then printAt("1|Password",21,2) |
88 | - | else |
88 | + | elseif s==4 then printAt("1|Versions\n 2|Uninstall\n 3|About",33,2) end |
89 | - | term.setBackgroundColor(tBarC) |
89 | + | |
90 | - | term.setTextColor(tBartC) |
90 | + | |
91 | local function drawDesktop() | |
92 | term.setBackgroundColor(deskColors["backgroundColor"]) | |
93 | term.clear() | |
94 | - | local function titleBar() |
94 | + | if wip==true then setTxtColor("red") printAt("NOTE: WIP BUILD - POSSIBLY UNSTABLE",2,17) end |
95 | - | term.setCursorPos(1,1) |
95 | + | setTxtColor("lightGrey") printAt("(Use " .. (term.isColor() and "mouse & " or "") .. "keyboard for selecting.)",2,18) |
96 | - | titleBarColor() |
96 | + | setTxtColor("grey") printAt(nhver,47,18) |
97 | - | term.clearLine() |
97 | + | menuBar() |
98 | - | term.setCursorPos(2, 1) |
98 | + | |
99 | - | term.write("1|Start") |
99 | + | |
100 | - | term.setCursorPos(12, 1) |
100 | + | |
101 | - | term.write("2|Options") |
101 | + | dispTime=true |
102 | - | term.setCursorPos(24, 1) |
102 | + | |
103 | - | term.write("3|NhUI") |
103 | + | local inGameTime=textutils.formatTime(os.time(),false) |
104 | local x=term.getSize() | |
105 | printAt(inGameTime,23,1) | |
106 | - | local function titleBarExt() |
106 | + | sleep(.01) |
107 | - | term.setCursorPos(1,1) |
107 | + | until dispTime==false |
108 | - | titleBarColor() |
108 | + | |
109 | - | term.clearLine() |
109 | + | |
110 | - | term.setCursorPos(2, 1) |
110 | + | local function displayTimeMenu() |
111 | - | term.write("-|Start") |
111 | + | printAt("Current in-game time:\n\n1|(Back)",1,1) |
112 | - | term.setCursorPos(12, 1) |
112 | + | |
113 | - | term.write("-|Options") |
113 | + | local event,b,x,y=os.pullEventRaw() |
114 | - | term.setCursorPos(24, 1) |
114 | + | if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=8 and y==3) then dispTime=false drawDesktop() return end |
115 | - | term.write("-|NhUI") |
115 | + | |
116 | end | |
117 | ||
118 | - | local function deskRun() |
118 | + | -- executable-related functions |
119 | - | if fs.exists("desktop") then |
119 | + | local function runMenu() |
120 | - | shell.run("desktop") |
120 | + | local yLine=2 |
121 | - | else |
121 | + | |
122 | - | shell.run("startup") |
122 | + | term.setCursorPos(1,yLine) term.clearLine() |
123 | yLine=yLine+1 | |
124 | until yLine==6 | |
125 | menuBar() | |
126 | drawMenus() | |
127 | - | setTextWhite() |
127 | + | |
128 | - | term.setCursorPos(43, 1) |
128 | + | |
129 | - | if os.time()>=10 and os.time()<13 then |
129 | + | |
130 | - | term.write(textutils.formatTime(os.time(), false )) |
130 | + | s=0 resetScreen() |
131 | - | elseif os.time()>=22 and os.time()>0 then |
131 | + | setTxtColor("yellow") print(os.version().." (run 'desktop' to return to desktop)") |
132 | - | term.write(textutils.formatTime(os.time(), false )) |
132 | + | setTxtColor("white") |
133 | - | else |
133 | + | |
134 | - | term.write(" "..textutils.formatTime(os.time(), false )) |
134 | + | |
135 | ||
136 | - | sleep(.83) |
136 | + | local function runClock() |
137 | s=0 resetScreen() | |
138 | parallel.waitForAny(displayTime,displayTimeMenu) | |
139 | - | local function displayTimeExt() |
139 | + | |
140 | - | setTextWhite() |
140 | + | |
141 | - | term.setCursorPos(43, 1) |
141 | + | local function runPasswordSetup() |
142 | - | if os.time()>=10 and os.time()<13 then |
142 | + | s=0 resetScreen() |
143 | - | term.write(textutils.formatTime(os.time(), false )) |
143 | + | pingPastebin() |
144 | - | elseif os.time()>=22 and os.time()>0 then |
144 | + | if internet==true then resetScreen() |
145 | - | term.write(textutils.formatTime(os.time(), false )) |
145 | + | openConfig() |
146 | - | else |
146 | + | if tContents[2]==true then print("This terminal is password protected.") else print("This terminal is not password protected.") end |
147 | - | term.write(" "..textutils.formatTime(os.time(), false )) |
147 | + | print("Would you like to set/change your password?\n\n1|Yes\n2|No\n3|(Back)") |
148 | while true do | |
149 | local event,b,x,y=os.pullEventRaw() | |
150 | if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=5 and y==4) then | |
151 | fs.delete("login") | |
152 | - | setBackColor() |
152 | + | shell.run("pastebin get",nhuiProgs["login"],"login") |
153 | resetScreen() | |
154 | - | term.setCursorPos(2,17) |
154 | + | print("Desired password? (Note: will display input.)") |
155 | - | if wip==1 then |
155 | + | editConfigLine(2,"true") |
156 | - | if not term.isColor then |
156 | + | local sInput=read() |
157 | - | term.write("NOTE: WIP BUILD - CURRENTLY STABLE") |
157 | + | if sInput~="" then sPass=sInput end |
158 | - | elseif term.isColor() then |
158 | + | editConfigLine(3,sPass) |
159 | - | term.setTextColor(8192) |
159 | + | saveConfig() |
160 | - | term.write("NOTE: WIP BUILD - CURRENTLY STABLE") |
160 | + | print("\n\n@Preferences saved.\n@Press any key to return to desktop.") |
161 | - | term.setTextColor(1) |
161 | + | anyKey() drawDesktop() return |
162 | - | else |
162 | + | elseif (event=="key" and b==keys.two) or (event=="mouse_click" and b==1 and x>=1 and x<=4 and y==5) then |
163 | - | term.setTextColor(1) |
163 | + | fs.delete("login") |
164 | - | term.write("NOTE: WIP BUILD - CURRENTLY STABLE") |
164 | + | editConfigLine(2,"") |
165 | editConfigLine(3,"") | |
166 | - | elseif wip==2 then |
166 | + | saveConfig() |
167 | - | if not term.isColor then |
167 | + | print("\n\n@Preferences saved.\n@Press any key to return to desktop.") |
168 | - | term.write("NOTE: WIP BUILD - CURRENTLY UNSTABLE") |
168 | + | anyKey() drawDesktop() return |
169 | - | elseif term.isColor() then |
169 | + | elseif (event=="key" and b==keys.three) or (event=="mouse_click" and b==1 and x>=1 and x<=8 and y==6) then drawDesktop() return end |
170 | - | term.setTextColor(16384) |
170 | + | |
171 | - | term.write("NOTE: WIP BUILD - CURRENTLY UNSTABLE") |
171 | + | elseif internet==false then drawDesktop() return end |
172 | - | else |
172 | + | |
173 | - | term.setTextColor(1) |
173 | + | |
174 | - | term.write("NOTE: WIP BUILD - CURRENTLY UNSTABLE") |
174 | + | local function runUpdater() |
175 | s=0 resetScreen() | |
176 | pingPastebin() | |
177 | - | if not term.isColor then |
177 | + | if internet==true then resetScreen() |
178 | - | term.setCursorPos(2,18) |
178 | + | shell.run("pastebin run",nhuiProgs["updater"]) |
179 | - | term.write("(Mouse and keyboard supported.)") |
179 | + | drawDesktop() |
180 | - | term.setCursorPos(47,17) |
180 | + | elseif internet==false then drawDesktop() return end |
181 | - | term.write("NhUI") |
181 | + | |
182 | - | term.setCursorPos(46,18) |
182 | + | |
183 | - | term.write(nhver) |
183 | + | local function runUninstallCheck() |
184 | - | else |
184 | + | s=0 resetScreen() |
185 | - | term.setTextColor(256) |
185 | + | print("Would you like to uninstall NhUI "..nhver.."?") |
186 | - | term.setCursorPos(2,18) |
186 | + | setTxtColor("lightGrey") print("(User-created programs will *not* be deleted.)") |
187 | - | term.write("(Mouse and keyboard supported.)") |
187 | + | setTxtColor("white") print("\n1|Yes\n2|No (Back)") |
188 | - | term.setTextColor(128) |
188 | + | |
189 | - | term.setCursorPos(47,17) |
189 | + | local event,b,x,y=os.pullEventRaw() |
190 | - | term.write("NhUI") |
190 | + | if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=5 and y==4) then |
191 | - | term.setCursorPos(46,18) |
191 | + | for i=1, #nhuiProgList do fs.delete(nhuiProgList[i]) end |
192 | - | term.write(nhver) |
192 | + | print("\n\n@NhUI "..nhver.." uninstalled successfully.\n@Press any key to reboot your computer.") |
193 | anyKey() os.reboot() | |
194 | - | titleBar() |
194 | + | elseif (event=="key" and b==keys.two) or (event=="mouse_click" and b==1 and x>=1 and x<=11 and y==5) then drawDesktop() return end |
195 | - | disptime=1 |
195 | + | |
196 | end | |
197 | - | displayTime() |
197 | + | |
198 | - | until disptime==0 |
198 | + | local function runAbout() |
199 | s=0 resetScreen() | |
200 | print("NhUI Author: Nhorr (Philip)\n(Pastebin Link: pastebin.com/u/Nhorr)\n\n1|(Back)") | |
201 | - | local function menuColor() |
201 | + | |
202 | - | if not term.isColor then |
202 | + | local event,b,x,y=os.pullEventRaw() |
203 | - | elseif term.isColor() then |
203 | + | if (event=="key" and b==keys.one) or (event=="mouse_click" and b==1 and x>=1 and x<=8 and y==4) then drawDesktop() return end |
204 | - | term.setTextColor(tBartC) |
204 | + | |
205 | - | term.setBackgroundColor(backColor) |
205 | + | |
206 | - | else |
206 | + | |
207 | - | term.setTextColor(tBartC) |
207 | + | -- desktop structure |
208 | - | term.setBackgroundColor(backColor) |
208 | + | |
209 | s=0 -- selection rule | |
210 | while true do | |
211 | local event,b,x,y=os.pullEventRaw() | |
212 | - | local function drawMenu1() |
212 | + | -- if selection rule = 0 |
213 | - | menuColor() |
213 | + | if (event=="key" and s==0 and b==keys.one) or (event=="mouse_click" and b==1 and x>=2 and x<=8 and y==1) then s=1 runMenu() |
214 | - | term.setCursorPos(2,2) |
214 | + | elseif (event=="key" and s==0 and b==keys.two) or (event=="mouse_click" and b==1 and x>=12 and x<=17 and y==1) then s=2 runMenu() |
215 | - | print("1|CraftOS") |
215 | + | elseif (event=="key" and s==0 and b==keys.three) or (event=="mouse_click" and b==1 and x>=21 and x<=29 and y==1) then s=3 runMenu() |
216 | - | term.setCursorPos(2,3) |
216 | + | elseif (event=="key" and s==0 and b==keys.four) or (event=="mouse_click" and b==1 and x>=33 and x<=38 and y==1) then s=4 runMenu() |
217 | - | print("---------") |
217 | + | -- if selection rule = 1 |
218 | - | term.setCursorPos(2,4) |
218 | + | elseif (event=="key" and s==1 and b==keys.one) or (event=="mouse_click" and s==1 and b==1 and x>=2 and x<=10 and y==2) then runShell() break |
219 | - | print("2|Shutdown") |
219 | + | elseif event=="mouse_click" and s==1 and b==1 and x>=2 and x<=10 and y==3 then s=1 drawMenus() |
220 | - | term.setCursorPos(2,5) |
220 | + | elseif (event=="key" and s==1 and b==keys.two) or (event=="mouse_click" and s==1 and b==1 and x>=2 and x<=11 and y==4) then os.shutdown() |
221 | - | print("3|Restart") |
221 | + | elseif (event=="key" and s==1 and b==keys.three) or (event=="mouse_click" and s==1 and b==1 and x>=2 and x<=10 and y==5) then os.reboot() |
222 | -- if selection rule = 2 | |
223 | elseif (event=="key" and s==2 and b==keys.one) or (event=="mouse_click" and s==2 and b==1 and x>=12 and x<=18 and y==2) then runClock() | |
224 | - | local function clearMenu1() |
224 | + | -- if selection rule = 3 |
225 | - | term.setCursorPos(2,2) |
225 | + | elseif (event=="key" and s==3 and b==keys.one) or (event=="mouse_click" and s==3 and b==1 and x>=21 and x<=30 and y==2) then runPasswordSetup() |
226 | - | term.clearLine() |
226 | + | -- if selection rule = 4 |
227 | - | term.setCursorPos(2,3) |
227 | + | elseif (event=="key" and s==4 and b==keys.one) or (event=="mouse_click" and s==4 and b==1 and x>=33 and x<=42 and y==2) then runUpdater() |
228 | - | term.clearLine() |
228 | + | elseif (event=="key" and s==4 and b==keys.two) or (event=="mouse_click" and s==4 and b==1 and x>=33 and x<=43 and y==3) then runUninstallCheck() |
229 | - | term.setCursorPos(2,4) |
229 | + | elseif (event=="key" and s==4 and b==keys.three) or (event=="mouse_click" and s==4 and b==1 and x>=33 and x<=39 and y==4) then runAbout() |
230 | - | term.clearLine() |
230 | + | elseif event=="key" or event=="mouse_click" then s=0 runMenu() end |
231 | - | term.setCursorPos(2,5) |
231 | + | |
232 | - | term.clearLine() |
232 | + | |
233 | ||
234 | -- run desktop | |
235 | - | local function drawMenu2() |
235 | + | |
236 | - | menuColor() |
236 | + | parallel.waitForAll(drawDesktop,runDesktop) |