SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --0.5.2 by UNOBTANIUM 09.06.2015 |
| 1 | + | --0.5.1 by UNOBTANIUM 25.03.2014 |
| 2 | local site = {}
| |
| 3 | local screen = {}
| |
| 4 | local selected = 1 | |
| 5 | local selectedObj = 1 | |
| 6 | local z = 1 | |
| 7 | local mode = "mainmenu" | |
| 8 | local errorText = nil | |
| 9 | local w,h = term.getSize() | |
| 10 | w = w + 1 | |
| 11 | local updateInterval = 2 | |
| 12 | local delay = os.startTimer(0.5) | |
| 13 | local colorName = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black}
| |
| 14 | local colorHex = {0xFFFFFF,0xFF8800,0xFF8CFF,0x00FFFF,0xFFF700,0x00FF11,0xF7B5DE,0xBFBFBF,0x65A1D6,0xAF56B3,0x0000FF,0x754302,0x004000,0xFF0000,0x000000}
| |
| 15 | local rednetSide = {"top","bottom","right","front"}
| |
| 16 | local b = peripheral.wrap("left")
| |
| 17 | local net = peripheral.wrap("back")
| |
| 18 | ||
| 19 | ||
| 20 | -- type x y w h {c} {t} unit method {param} {var} minNumber maxNumber fadeout action
| |
| 21 | ||
| 22 | -- type text x y c | |
| 23 | -- type x y text unit method maxNumber c cMax var param | |
| 24 | -- type x y w h cBorder tBorder cBack tBack cOne tOne cTwo tTwo unit method maxNumber var param | |
| 25 | -- type x y w h minNumber maxNumber c t fadeout unit method var param | |
| 26 | -- type unit method operator limitNumber action | |
| 27 | - | -- type x y w h liquid cBorder tBorder cBack tBack unit method maxNumber var param |
| 27 | + | |
| 28 | for i=1, 199 do | |
| 29 | site[i] = {}
| |
| 30 | screen[i] = {}
| |
| 31 | end | |
| 32 | - | -- tank with liquid |
| 32 | + | |
| 33 | - | -- addLiquid(number x, number y, number width, number height, string liquid) |
| 33 | + | |
| 34 | - | -- or? |
| 34 | + | |
| 35 | - | -- addFluid(number x, number y, number width, number height, string liquid) add a box textured like a liquid to the screen |
| 35 | + | |
| 36 | - | -- addIcon(number x, number y, string id, number meta) add an icom of an item to the screen (height width?) |
| 36 | + | |
| 37 | file.writeLine(textutils.serialize(site)) | |
| 38 | file.writeLine(textutils.serialize(screen)) | |
| 39 | file.writeLine(updateInterval) | |
| 40 | file.writeLine(selected) | |
| 41 | file.close() | |
| 42 | end | |
| 43 | ||
| 44 | function buildString(stringBuilder, site) | |
| 45 | stringBuilder = stringBuilder .. "{"
| |
| 46 | local added = false | |
| 47 | - | file.writeLine(string.gsub(textutils.serialize(site),"\n%S-","")) |
| 47 | + | |
| 48 | - | file.writeLine(string.gsub(textutils.serialize(screen),"\n%S-","")) |
| 48 | + | |
| 49 | if type(var) == "string" then | |
| 50 | stringBuilder = stringBuilder .. "\"" .. var .. "\"" | |
| 51 | elseif type(var) == "number" then | |
| 52 | stringBuilder = stringBuilder .. var | |
| 53 | elseif type(var) == "boolean" then | |
| 54 | stringBuilder = stringBuilder .. tostring(var) | |
| 55 | elseif type(var) == "table" then | |
| 56 | stringBuilder = buildString(stringBuilder, site[i]) | |
| 57 | end | |
| 58 | stringBuilder = stringBuilder .. "," | |
| 59 | end | |
| 60 | if added then | |
| 61 | stringBuilder = stringBuilder:sub(1,stringBuilder:len()-1) | |
| 62 | end | |
| 63 | return stringBuilder .. "}" | |
| 64 | end | |
| 65 | ||
| 66 | function load() | |
| 67 | if not fs.exists("openPeripheralClient") then return end
| |
| 68 | local file = fs.open("openPeripheralClient","r")
| |
| 69 | local firstLine = file.readLine() | |
| 70 | if firstLine == "OPEN PERIPHERAL CLIENT DATABASE" then -- NEWEST since 0.5 | |
| 71 | site = textutils.unserialize(file.readLine()) | |
| 72 | screen = textutils.unserialize(file.readLine()) | |
| 73 | updateInterval = tonumber(file.readLine()) | |
| 74 | selected = tonumber(file.readLine()) | |
| 75 | file.close() | |
| 76 | elseif firstLine == "OPEN PERIPHERAL CLIENT DATA" then -- since 0.3 | |
| 77 | site = textutils.unserialize(file.readLine()) | |
| 78 | file.close() | |
| 79 | oldLoad03() | |
| 80 | else -- OLDEST since 0.1 | |
| 81 | file.close() | |
| 82 | oldLoad01() | |
| 83 | end | |
| 84 | end | |
| 85 | ||
| 86 | -- OLD LOAD | |
| 87 | ||
| 88 | function oldLoad03() | |
| 89 | local newDB = {}
| |
| 90 | for i=1,199 do | |
| 91 | newDB[i] = {}
| |
| 92 | end | |
| 93 | ||
| 94 | for siteID, s in pairs(site) do | |
| 95 | for objID, obj in pairs(s) do | |
| 96 | if obj[1] == "text" then | |
| 97 | newDB[siteID][objID] = {type=obj[1],text=obj[2],x=obj[3],y=obj[4],color=obj[5]}
| |
| 98 | elseif obj[1] == "box" then | |
| 99 | newDB[siteID][objID] = {type=obj[1],x=obj[2],y=obj[3],w=obj[4],h=obj[5],inner_color=obj[6],inner_transparency=obj[7],border_color=obj[8],border_transparency=obj[9]}
| |
| 100 | elseif obj[1] == "number" then | |
| 101 | newDB[siteID][objID] = {type=obj[1],x=obj[2],y=obj[3],text=obj[4],unit=obj[5],method=obj[6],maxNumber=obj[7],text_standardColor=obj[8],text_maxNumberColor=obj[9],arguments=obj[10]}
| |
| 102 | elseif obj[1] == "bar" then | |
| 103 | newDB[siteID][objID] = {type=obj[1],x=obj[2],y=obj[3],w=obj[4],h=obj[5],color=obj[6],transparency=obj[7],color2=obj[8],transparency2=obj[9],color3=obj[10],transparency3=obj[11],color4=obj[12],transparency4=obj[13],unit=obj[14],method=obj[15],maxNumber=obj[16], arguments=obj[17]}
| |
| 104 | elseif obj[1] == "graphPillar" or obj[1] == "graphPoint" then | |
| 105 | newDB[siteID][objID] = {type=obj[1],x=obj[2],y=obj[3],w=obj[4],h=obj[5],minNumber=obj[6],maxNumber=obj[7],color=obj[8],transparency=obj[9],fadeout=obj[10],unit=obj[11],method=obj[12],arguments=obj[14]}
| |
| 106 | elseif obj[1] == "frame" then | |
| 107 | newDB[siteID][objID] = {type=obj[1],frame=obj[2],x=obj[3],y=obj[4]}
| |
| 108 | elseif obj[1] == "ALARM" then | |
| 109 | if obj[7] == "TEXT" then | |
| 110 | newDB[siteID][objID] = {type=obj[1] ,unit=obj[2], method=obj[3], arguments=obj[4], operator=obj[5], number=obj[6], action_type=obj[7],action_x=obj[8],action_y=obj[9],action_text=obj[10], action_text_color=obj[11]}
| |
| 111 | elseif obj[7] == "ACTIVATION" then | |
| 112 | newDB[siteID][objID] = {type=obj[1] ,unit=obj[2], method=obj[3], arguments=obj[4], operator=obj[5], number=obj[6], action_type=obj[7],action_unit=obj[8],action_method=obj[9],action_arguments=obj[10]}
| |
| 113 | elseif obj[7] == "REDNET" then | |
| 114 | newDB[siteID][objID] = {type=obj[1] ,unit=obj[2], method=obj[3], arguments=obj[4], operator=obj[5], number=obj[6], action_type=obj[7],action_text=obj[9]}
| |
| 115 | else | |
| 116 | newDB[siteID][objID] = {type=obj[1] ,unit=obj[2], method=obj[3], arguments=obj[4], operator=obj[5], number=obj[6], action_type=obj[7]}
| |
| 117 | end | |
| 118 | elseif obj[1] == "CHAT" then | |
| 119 | if obj[3] == "TEXT" then | |
| 120 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3],action_x=obj[4],action_y=obj[5],action_text=obj[6], action_text_color=obj[7]}
| |
| 121 | elseif obj[3] == "ACTIVATION" then | |
| 122 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3],action_unit=obj[4],action_method=obj[5],action_arguments=obj[6]}
| |
| 123 | elseif obj[3] == "REDNET" then | |
| 124 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3],action_text=obj[5]}
| |
| 125 | else | |
| 126 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3]}
| |
| 127 | end | |
| 128 | elseif obj[1] == "REDNET" then | |
| 129 | if obj[3] == "TEXT" then | |
| 130 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3],action_x=obj[4],action_y=obj[5],action_text=obj[6], action_text_color=obj[7]}
| |
| 131 | elseif obj[3] == "ACTIVATION" then | |
| 132 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3],action_unit=obj[4],action_method=obj[5],action_arguments=obj[6]}
| |
| 133 | elseif obj[3] == "REDNET" then | |
| 134 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3],action_text=obj[5]}
| |
| 135 | else | |
| 136 | newDB[siteID][objID] = {type=obj[1],text=obj[2],action_type=obj[3]}
| |
| 137 | end | |
| 138 | end | |
| 139 | end | |
| 140 | end | |
| 141 | site = newDB | |
| 142 | save() | |
| 143 | load() | |
| 144 | end | |
| 145 | ||
| 146 | function oldLoad01() | |
| 147 | if not fs.exists("openPeripheralClient") then return end
| |
| 148 | local file = fs.open("openPeripheralClient","r")
| |
| 149 | for i=1,198 do | |
| 150 | local amountObj = tonumber(file.readLine()) | |
| 151 | for k=1,amountObj do | |
| 152 | local amountVars = tonumber(file.readLine()) | |
| 153 | local typ = file.readLine() | |
| 154 | site[i][k] = {}
| |
| 155 | site[i][k][1] = typ | |
| 156 | for m=2,amountVars do | |
| 157 | if typ == "text" then | |
| 158 | if m == 2 then | |
| 159 | site[i][k][m] = file.readLine() | |
| 160 | else | |
| 161 | site[i][k][m] = tonumber(file.readLine()) | |
| 162 | end | |
| 163 | elseif typ == "box" then | |
| 164 | site[i][k][m] = tonumber(file.readLine()) | |
| 165 | elseif typ == "number" then | |
| 166 | if m == 2 or m == 3 or m >= 7 then | |
| 167 | site[i][k][m] = tonumber(file.readLine()) | |
| 168 | else | |
| 169 | site[i][k][m] = file.readLine() | |
| 170 | end | |
| 171 | elseif typ == "bar" then | |
| 172 | if (m >= 2 and m <=13) or m == 16 then | |
| 173 | site[i][k][m] = tonumber(file.readLine()) | |
| 174 | else | |
| 175 | site[i][k][m] = file.readLine() | |
| 176 | end | |
| 177 | elseif typ == "graphPillar" or typ == "graphPoint" then | |
| 178 | if m >= 2 and m <= 9 then | |
| 179 | site[i][k][m] = tonumber(file.readLine()) | |
| 180 | elseif m == 10 then | |
| 181 | if file.readLine() == "true" then | |
| 182 | site[i][k][m] = true | |
| 183 | else | |
| 184 | site[i][k][m] = false | |
| 185 | end | |
| 186 | elseif m == 11 or m == 12 then | |
| 187 | site[i][k][m] = file.readLine() | |
| 188 | else | |
| 189 | local amount = tonumber(file.readLine()) | |
| 190 | site[i][k][m] = {}
| |
| 191 | for a=1,amount do | |
| 192 | site[i][k][m][a] = tonumber(file.readLine()) | |
| 193 | end | |
| 194 | end | |
| 195 | elseif typ == "frame" then | |
| 196 | site[i][k][m] = tonumber(file.readLine()) | |
| 197 | end | |
| 198 | end | |
| 199 | end | |
| 200 | save() | |
| 201 | load() | |
| 202 | end | |
| 203 | ||
| 204 | file.close() | |
| 205 | end | |
| 206 | ||
| 207 | function clear(color) | |
| 208 | color = color or colors.black | |
| 209 | term.setBackgroundColor(color) | |
| 210 | term.clear() | |
| 211 | term.setCursorPos(1,1) | |
| 212 | end | |
| 213 | ||
| 214 | function countArray(a) | |
| 215 | local amount = 0 | |
| 216 | for k,v in pairs(a) do | |
| 217 | amount = amount + 1 | |
| 218 | end | |
| 219 | return amount | |
| 220 | end | |
| 221 | ||
| 222 | function write(text,x,y,c) | |
| 223 | c = c or colors.white | |
| 224 | term.setCursorPos(x,y) | |
| 225 | term.setTextColor(c) | |
| 226 | term.write(text) | |
| 227 | end | |
| 228 | ||
| 229 | function centered(text,y,c) | |
| 230 | c = c or colors.white | |
| 231 | term.setCursorPos(w/2-math.ceil(#tostring(text)/2),y) | |
| 232 | term.setTextColor(c) | |
| 233 | term.write(tostring(text)) | |
| 234 | end | |
| 235 | ||
| 236 | function fill(text,y) | |
| 237 | centered(string.rep(tostring(text), w), y) | |
| 238 | end | |
| 239 | ||
| 240 | function setColors(text,background) | |
| 241 | background = background or colors.lightGray | |
| 242 | term.setTextColor(text) | |
| 243 | term.setBackgroundColor(background) | |
| 244 | end | |
| 245 | ||
| 246 | function drawArrows(y) | |
| 247 | write("<",14,y)
| |
| 248 | write(">",36,y)
| |
| 249 | end | |
| 250 | ||
| 251 | -- CHECK ALARM AND ACTIVATIONS | |
| 252 | ||
| 253 | function checkAlarm(chatCommand, rednetMessage) -- DONE 1 | |
| 254 | chatCommand = chatCommand or "" | |
| 255 | rednetMessage = rednetMessage or "" | |
| 256 | local number = 0 | |
| 257 | for objID, obj in pairs(site[199]) do | |
| 258 | if obj.type == "ALARM" then -- ALARM | |
| 259 | number = table.remove(screen[199][objID]["values"], 1) | |
| 260 | if type(number) == "number" then -- ERROR | |
| 261 | if obj.operator == "=" and number == obj.number then | |
| 262 | makeAction(obj, objID) | |
| 263 | elseif obj.operator == ">" and number > obj.number then | |
| 264 | makeAction(obj, objID) | |
| 265 | elseif obj.operator == "<"and number < obj.number then | |
| 266 | makeAction(obj, objID) | |
| 267 | end | |
| 268 | end | |
| 269 | elseif not (chatCommand == "") and obj.type == "CHAT" and obj.text == chatCommand then -- CHAT | |
| 270 | makeAction(obj, objID) | |
| 271 | elseif not (rednetMessage == "") and obj.type == "REDNET" and obj.text == rednetMessage then -- REDNET | |
| 272 | makeAction(obj, objID) | |
| 273 | end | |
| 274 | end | |
| 275 | end | |
| 276 | ||
| 277 | function makeAction(obj, objID) | |
| 278 | if obj.action_type == "TEXT" then | |
| 279 | drawText(199, objID) | |
| 280 | elseif obj.action_type == "ACTIVATION" then | |
| 281 | if net.isPresentRemote(obj.action_unit) and obj.action_method ~= "NONE" and type(obj.action_arguments) == "table" then | |
| 282 | if countArray(obj.action_arguments) >= 1 then | |
| 283 | local noErr,res = pcall( net.callRemote, obj.action_unit, obj.action_method, unpack(obj.action_arguments)) | |
| 284 | if not noErr then | |
| 285 | if errorText == nil then | |
| 286 | errorText = {"ERROR!!! ALARM'N'ACTION CALLING WITH ARGUMENTS! Object: " .. objID, "ORIGINAL ERROR MESSAGE: ".. res}
| |
| 287 | end | |
| 288 | end | |
| 289 | - | drawText(199, objID, 0, 0) |
| 289 | + | |
| 290 | local noErr,res = pcall( net.callRemote, obj.action_unit, obj.action_method, unpack(obj.action_arguments)) | |
| 291 | if not noErr then | |
| 292 | if errorText == nil then | |
| 293 | errorText = {"ERROR!!! ALARM'N'ACTION CALLING WITHOUT ARGUMENTS! Object: " .. objID, "ORIGINAL ERROR MESSAGE: ".. res}
| |
| 294 | end | |
| 295 | end | |
| 296 | end | |
| 297 | end | |
| 298 | elseif obj.action_type == "REDNET" then | |
| 299 | rednet.broadcast(obj.action_text) | |
| 300 | end | |
| 301 | end | |
| 302 | ||
| 303 | ||
| 304 | ||
| 305 | ||
| 306 | -- ON SCREEN OBJECT DRAWING | |
| 307 | ||
| 308 | -- type text x y c | |
| 309 | function drawText(siteID, objID, relX, relY) | |
| 310 | local obj = site[siteID][objID] | |
| 311 | if obj.type == "text" then | |
| 312 | local var = b.addText(obj.x+relY,obj.y+relY,obj.text,colorHex[obj.text_color]) | |
| 313 | setZDimension(var) | |
| 314 | elseif obj.action_type == "TEXT" then | |
| 315 | local var = b.addText(obj.action_x+relX,obj.action_y+relY,obj.action_text,colorHex[obj.action_text_color]) | |
| 316 | setZDimension(var) | |
| 317 | end | |
| 318 | end | |
| 319 | ||
| 320 | -- type x y w h cOne tOne cTwo tTwo | |
| 321 | function drawBox(siteID, objID, relX, relY) | |
| 322 | local obj = site[siteID][objID] | |
| 323 | local cOne = colorHex[obj.inner_color] | |
| 324 | local cTwo = colorHex[obj.border_color] | |
| 325 | local var1 = b.addBox(obj.x+relX,obj.y+relY,obj.w,2,cTwo,obj.border_transparency) | |
| 326 | setZDimension(var1) | |
| 327 | local var2 = b.addBox(obj.x+relX,obj.y+2+relY,2,obj.h-4,cTwo,obj.border_transparency) | |
| 328 | setZDimension(var2) | |
| 329 | local var3 = b.addBox(obj.x+relX,obj.y+relY+obj.h-2,obj.w,2,cTwo,obj.border_transparency) | |
| 330 | setZDimension(var3) | |
| 331 | local var4 = b.addBox(obj.x+relX+obj.w-2,obj.y+relY+2,2,obj.h-4,cTwo,obj.border_transparency) | |
| 332 | setZDimension(var4) | |
| 333 | local var5 = b.addBox(obj.x+relX+2,obj.y+relY+2,obj.w-4,obj.h-4,cOne,obj.inner_transparency) | |
| 334 | setZDimension(var5) | |
| 335 | end | |
| 336 | ||
| 337 | -- type x y text unit method maxNumber c cMax | |
| 338 | function drawNumber(siteID, objID, relX, relY) | |
| 339 | local obj = site[siteID][objID] | |
| 340 | local c = colorHex[obj.text_standardColor] | |
| 341 | local cMax = colorHex[obj.text_maxNumberColor] | |
| 342 | local number = table.remove(screen[siteID][objID]["values"], 1) | |
| 343 | local lengthText = ((#obj.text) + 2)*6 | |
| 344 | local lengthNumber = (#(tostring(number)))*6 | |
| 345 | local maxLength = (#(tostring(obj.maxNumber)))*6 | |
| 346 | if type(number) == "string" or (type(number) == "number" and number == maxNumber) then | |
| 347 | local var1 = b.addText(obj.x+relX,obj.y+relY,obj.text .. ":",c) | |
| 348 | setZDimension(var1) | |
| 349 | local var2 = b.addText(obj.x+relX+lengthText,obj.y+relY,tostring(number),cMax) | |
| 350 | setZDimension(var2) | |
| 351 | local var3 = b.addText(obj.x+relX+lengthText+(#(tostring(number)))*6,obj.y+relY, " / " .. obj.maxNumber, c) | |
| 352 | setZDimension(var3) | |
| 353 | - | if (type(number) == "table") then |
| 353 | + | |
| 354 | - | number = "ERROR table" |
| 354 | + | |
| 355 | setZDimension(var1) | |
| 356 | - | local lengthText = ((#tostring(obj.text)) + 2)*6 |
| 356 | + | local var2 = b.addText(obj.x+relX+lengthText+(maxLength-lengthNumber),obj.y+relY, number .. " / " .. obj.maxNumber,c) |
| 357 | setZDimension(var2) | |
| 358 | end | |
| 359 | end | |
| 360 | ||
| 361 | -- type x y w h cBorder tBorder cBack tBack cOne tOne cTwo tTwo unit method maxNumber | |
| 362 | function drawBar(siteID, objID, relX, relY) | |
| 363 | local obj = site[siteID][objID] | |
| 364 | local cBorder = colorHex[obj.color3] | |
| 365 | local cBack = colorHex[obj.color4] | |
| 366 | local cOne = colorHex[obj.color] | |
| 367 | local cTwo = colorHex[obj.color2] | |
| 368 | local tBorder = obj.transparency3 | |
| 369 | - | local var2 = b.addText(obj.x+relX+lengthText+(maxLength-lengthNumber),obj.y+relY, tostring(number) .. " / " .. obj.maxNumber,c) |
| 369 | + | |
| 370 | local tOne = obj.transparency | |
| 371 | local tTwo = obj.transparency2 | |
| 372 | local var1 = b.addBox(obj.x+relX+2,obj.y+relY+2,obj.w-4,obj.h-4,cBack,tBack) | |
| 373 | setZDimension(var1) | |
| 374 | local var2 = b.addBox(obj.x+relX,obj.y+relY,obj.w,2,cBorder,tBorder) | |
| 375 | setZDimension(var2) | |
| 376 | local var3 = b.addBox(obj.x+relX,obj.y+relY+obj.h-2,obj.w,2,cBorder,tBorder) | |
| 377 | setZDimension(var3) | |
| 378 | local var4 = b.addBox(obj.x+relX,obj.y+relY+2,2,obj.h-4,cBorder,tBorder) | |
| 379 | setZDimension(var4) | |
| 380 | local var5 = b.addBox(obj.x+relX+obj.w-2,obj.y+relY+2,2,obj.h-4,cBorder,tBorder) | |
| 381 | setZDimension(var5) | |
| 382 | local number = table.remove(screen[siteID][objID]["values"], 1) | |
| 383 | if type(number) == "number" then | |
| 384 | local box = b.addGradientBox(obj.x+relX+2,obj.y+relY+2,math.ceil((number/obj.maxNumber)*(obj.w-4)),obj.h-4,cOne,tOne,cTwo,tTwo,2) | |
| 385 | z = z + 1 | |
| 386 | setZDimension(box) | |
| 387 | end | |
| 388 | end | |
| 389 | ||
| 390 | -- type x y w h minNumber maxNumber c t fadeout unit method var | |
| 391 | function drawGraph(siteID, objID, rX, rY) | |
| 392 | local obj = site[siteID][objID] | |
| 393 | local var = screen[siteID][objID]["values"] | |
| 394 | table.remove(screen[siteID][objID]["values"], math.ceil(obj.w+2/2)) | |
| 395 | local t = obj.transparency | |
| 396 | local decrease = obj.transparency/20 | |
| 397 | local c = colorHex[obj.color] | |
| 398 | for relX=2,obj.w,2 do | |
| 399 | if obj.fadeout and relX >= obj.w-20 and t > 0.05 then | |
| 400 | t = t - decrease | |
| 401 | end | |
| 402 | if obj.type == "graphPillar" then | |
| 403 | if type(var[relX/2]) == "number" then | |
| 404 | if var[relX/2] > obj.minNumber then | |
| 405 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+(obj.h-1-(math.ceil((var[relX/2]/(obj.maxNumber))*obj.h))),2,(math.ceil((var[relX/2]/(obj.maxNumber))*obj.h)),c,t) | |
| 406 | setZDimension(box) | |
| 407 | else | |
| 408 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+obj.h-2,2,1,c,t) | |
| 409 | setZDimension(box) | |
| 410 | end | |
| 411 | else | |
| 412 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+obj.h-2,2,1,c,t) | |
| 413 | setZDimension(box) | |
| 414 | end | |
| 415 | else | |
| 416 | if type(var[relX/2]) == "number" then | |
| 417 | if var[relX/2] > obj.minNumber then | |
| 418 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+(obj.h-1-((math.ceil((var[relX/2]/(obj.maxNumber))*obj.h)))),2,2,c,t) | |
| 419 | setZDimension(box) | |
| 420 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+obj.h-1,2,1,c,t) | |
| 421 | setZDimension(box) | |
| 422 | else | |
| 423 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+obj.h-1,2,1,c,t) | |
| 424 | setZDimension(box) | |
| 425 | end | |
| 426 | else | |
| 427 | local box = b.addBox(obj.x+rX+relX-2,obj.y+rY+obj.h-1,2,1,c,t) | |
| 428 | setZDimension(box) | |
| 429 | end | |
| 430 | end | |
| 431 | end | |
| 432 | end | |
| 433 | ||
| 434 | function setZDimension(obj) | |
| 435 | local wtf = ( obj.setZ and obj.setZ(z) ) or ( obj.setZIndex and obj.setZIndex(z) ) | |
| 436 | z = z + 1 | |
| 437 | end | |
| 438 | ||
| 439 | ||
| 440 | ||
| 441 | -- ON SCREEN DRAWING MAIN METHODS | |
| 442 | ||
| 443 | ||
| 444 | ||
| 445 | ||
| 446 | function drawSite() | |
| 447 | - | function drawTank(siteID, objID, relX, relY) |
| 447 | + | update() |
| 448 | if selected == 0 then return end | |
| 449 | - | local cBorder = colorHex[obj.cBorder] |
| 449 | + | |
| 450 | - | local cBack = colorHex[obj.cBack] |
| 450 | + | |
| 451 | - | local tBorder = obj.tBorder |
| 451 | + | |
| 452 | - | local tBack = obj.tBack |
| 452 | + | |
| 453 | end | |
| 454 | checkAlarm() | |
| 455 | save() | |
| 456 | end | |
| 457 | ||
| 458 | ||
| 459 | ||
| 460 | function update() -- DONE 1 | |
| 461 | for siteID, selectedSite in pairs(site) do -- SITE | |
| 462 | for objID, obj in pairs(selectedSite) do -- OBJECT | |
| 463 | if siteID == selected or ( obj.type == "graphPillar" or obj.type == "graphPoint" or obj.type == "ALARM" or obj.type == "CHAT" or obj.type == "REDNET") then -- JUST NEEDED INFORMATION. | |
| 464 | if obj.unit ~= nil and obj.method ~= nil then | |
| 465 | - | local relH = obj.h-math.ceil((number/obj.maxNumber)*obj.h) |
| 465 | + | |
| 466 | - | local box = b.addLiquid(obj.x+relX+2,obj.y+relH+relY+2,obj.w-4,obj.h-relH-4, obj.liquid) |
| 466 | + | |
| 467 | if obj.action_type ~= "ACTIVATION" and obj.action_unit ~= nil and obj.action_method ~= nil then | |
| 468 | callMethod(siteID, objID, obj, "action_unit", "action_method", "action_arguments", "action_values") | |
| 469 | end | |
| 470 | end | |
| 471 | end | |
| 472 | end | |
| 473 | end | |
| 474 | ||
| 475 | function callMethod(siteID, objID, obj, unit_pos, method_pos, arguments_pos, values_pos) -- DONE 1 | |
| 476 | if screen[siteID][objID] == nil then | |
| 477 | screen[siteID][objID] = {}
| |
| 478 | screen[siteID][objID]["values"] = {}
| |
| 479 | screen[siteID][objID]["action_values"] = {}
| |
| 480 | screen[siteID][objID]["objects"] = {}
| |
| 481 | end | |
| 482 | if net.isPresentRemote(obj[unit_pos]) and obj[method_pos] ~= "NONE" then | |
| 483 | if type(obj[arguments_pos]) ~= "table" then | |
| 484 | - | function drawSite(doUpdate) |
| 484 | + | |
| 485 | - | doUpdate = doUpdate or true |
| 485 | + | |
| 486 | - | if (doUpdate) then |
| 486 | + | |
| 487 | - | update() |
| 487 | + | |
| 488 | if countArray(obj[arguments_pos]) == 0 then | |
| 489 | local noError, value = pcall( net.callRemote, obj[unit_pos], obj[method_pos] ) | |
| 490 | if noError then | |
| 491 | table.insert(screen[siteID][objID][values_pos], 1, value) | |
| 492 | elseif errorText == nil then | |
| 493 | table.insert(screen[siteID][objID][values_pos], 1, "ERROR") | |
| 494 | if siteID <= 99 then siteID = "Site: " .. siteID | |
| 495 | elseif siteID <= 198 then siteID = "Frame: " .. siteID-99 | |
| 496 | - | b.sync() |
| 496 | + | |
| 497 | end | |
| 498 | errorText = {"ERROR! ".. siteID .. " Object: " .. objID .. " Unit: " .. obj[unit_pos] .. " Method: " .. obj[method_pos] .. " No arguments!", "Original Error Code: " .. value}
| |
| 499 | end | |
| 500 | else | |
| 501 | local noError, value = pcall( net.callRemote, obj[unit_pos], obj[method_pos], unpack(obj[arguments_pos]) ) | |
| 502 | if noError then | |
| 503 | table.insert(screen[siteID][objID][values_pos], 1, value) | |
| 504 | elseif errorText == nil then | |
| 505 | table.insert(screen[siteID][objID][values_pos], 1, "ERROR") | |
| 506 | if siteID <= 99 then siteID = "Site: " .. siteID | |
| 507 | elseif siteID <= 198 then siteID = "Frame: " .. siteID-99 | |
| 508 | else siteID = "ALARM'N'ACTION" | |
| 509 | end | |
| 510 | errorText = {"ERROR! ".. siteID .. " Object: " .. objID .. " Unit: " .. obj[unit_pos] .. " Method: " .. obj[method_pos] .. " Arguments: " .. countArray(obj[arguments_pos]), "Original Error Code: " .. value}
| |
| 511 | end | |
| 512 | end | |
| 513 | elseif countArray(screen[siteID][objID]["values"]) == 0 or countArray(screen[siteID][objID]["action_values"]) then | |
| 514 | table.insert(screen[siteID][objID]["values"], 1, "ERROR") | |
| 515 | table.insert(screen[siteID][objID]["action_values"], 1, "ERROR") | |
| 516 | end | |
| 517 | end | |
| 518 | ||
| 519 | ||
| 520 | function innerDraw(relX, relY, s, layer) -- DONE 1 | |
| 521 | if layer == 4 then -- ERROR | |
| 522 | if type(errorText) == "table" then | |
| 523 | local length = #errorText[1] | |
| 524 | if #errorText[1] < #errorText[2] then | |
| 525 | length = errorText[2] | |
| 526 | end | |
| 527 | local box1 = b.addBox(0,0,math.ceil(length*5.3),28,colorHex[1],1) | |
| 528 | setZDimension(box1) | |
| 529 | local box2 = b.addBox(0,28,1+math.ceil(length*5.3),2,colorHex[14],1) | |
| 530 | setZDimension(box2) | |
| 531 | local box3 = b.addBox(math.ceil(length*5.3),0,2,29,colorHex[14],1) | |
| 532 | - | if noError and (type(value) == "number" or type(value) == "string" or type(value) == "boolean") then |
| 532 | + | |
| 533 | local var1 = b.addText(5,5,errorText[1],colorHex[14]) | |
| 534 | setZDimension(var1) | |
| 535 | local var2 = b.addText(5,15, errorText[2],colorHex[14]) | |
| 536 | setZDimension(var2) | |
| 537 | errorText = nil | |
| 538 | end | |
| 539 | end | |
| 540 | - | if type(value) == "table" then |
| 540 | + | |
| 541 | - | value = "(Original Error code was a table. Unable to print.)" |
| 541 | + | |
| 542 | if obj.type == "frame" then | |
| 543 | - | errorText = {"ERROR! ".. siteID .. " Object: " .. objID .. " Unit: " .. obj[unit_pos] .. " Method: " .. obj[method_pos] .. " No arguments!", "Original Error Code: " .. tostring(value)}
|
| 543 | + | |
| 544 | elseif layer == 1 then -- BOX | |
| 545 | if obj.type == "box" then | |
| 546 | drawBox(s, objID, relX, relY) | |
| 547 | - | if noError and (type(value) == "number" or type(value) == "string" or type(value) == "boolean") then |
| 547 | + | |
| 548 | elseif layer == 2 then -- NUMBER, BAR, GRAPH | |
| 549 | if obj.type == "number" then | |
| 550 | drawNumber(s, objID, relX, relY) | |
| 551 | elseif obj.type == "bar" then | |
| 552 | drawBar(s, objID, relX, relY) | |
| 553 | elseif obj.type == "graphPillar" or obj.type == "graphPoint" then | |
| 554 | drawGraph(s, objID, relX, relY) | |
| 555 | - | if type(value) == "table" then |
| 555 | + | |
| 556 | - | value = "(Original Error code was a table. Unable to print.)" |
| 556 | + | |
| 557 | if obj.type == "text" or obj.action_type == "TEXT" then | |
| 558 | - | errorText = {"ERROR! ".. siteID .. " Object: " .. objID .. " Unit: " .. obj[unit_pos] .. " Method: " .. obj[method_pos] .. " Arguments: " .. countArray(obj[arguments_pos]), "Original Error Code: " .. tostring(value)}
|
| 558 | + | |
| 559 | end | |
| 560 | end | |
| 561 | end | |
| 562 | end | |
| 563 | ||
| 564 | ||
| 565 | ||
| 566 | -- MENU FUNCTIONS | |
| 567 | ||
| 568 | function betterRead(x,y,numberOnly,pos,clickX) -- DONE 1 | |
| 569 | local previousMode = mode | |
| 570 | local selectedSite = selected | |
| 571 | mode = "betterRead" | |
| 572 | term.setTextColor(colors.lightGray) | |
| 573 | - | length = #errorText[2] |
| 573 | + | |
| 574 | local s | |
| 575 | if clickX < x then | |
| 576 | s = "" | |
| 577 | else | |
| 578 | s = tostring(site[selected][selectedObj][pos]) | |
| 579 | end | |
| 580 | ||
| 581 | ||
| 582 | while true do | |
| 583 | term.setCursorPos(x,y) | |
| 584 | term.write( string.rep(' ', w - x + 1) )
| |
| 585 | term.setCursorPos(x,y) | |
| 586 | if s:len()+x < w then | |
| 587 | term.write(s) | |
| 588 | else | |
| 589 | term.write(s:sub( s:len() - (w-x-2))) | |
| 590 | end | |
| 591 | local e = { os.pullEvent() }
| |
| 592 | if checkEvent(e, false, true) then | |
| 593 | if e[1] == "mouse_click" then | |
| 594 | mode = "back" | |
| 595 | elseif e[1] == "char" then | |
| 596 | s = s .. e[2] | |
| 597 | elseif e[1] == "key" then | |
| 598 | if e[2] == keys.enter then | |
| 599 | mode = "back" | |
| 600 | elseif e[2] == keys.backspace then | |
| 601 | s = s:sub( 1, s:len() - 1 ) | |
| 602 | end | |
| 603 | - | elseif obj.type == "tank" then |
| 603 | + | |
| 604 | - | drawTank(s, objID, relX, relY) |
| 604 | + | |
| 605 | if mode == "back" then | |
| 606 | mode = previousMode | |
| 607 | break | |
| 608 | elseif not (mode == "betterRead") then | |
| 609 | break | |
| 610 | end | |
| 611 | end | |
| 612 | ||
| 613 | term.setTextColor(colors.white) | |
| 614 | if numberOnly then | |
| 615 | s = tonumber(s) | |
| 616 | if s then | |
| 617 | site[selectedSite][selectedObj][pos] = s | |
| 618 | end | |
| 619 | else | |
| 620 | site[selectedSite][selectedObj][pos] = s | |
| 621 | end | |
| 622 | term.setCursorBlink(false) | |
| 623 | drawSite() | |
| 624 | end | |
| 625 | ||
| 626 | ||
| 627 | function drawColor(color,y) -- DONE 1 | |
| 628 | drawArrows(y) | |
| 629 | term.setBackgroundColor(colorName[color]) | |
| 630 | centered(" ",y)
| |
| 631 | term.setBackgroundColor(colors.black) | |
| 632 | end | |
| 633 | ||
| 634 | function drawTransparent(transparency,y) -- DONE 1 | |
| 635 | drawArrows(y) | |
| 636 | centered(transparency, y) | |
| 637 | end | |
| 638 | ||
| 639 | ||
| 640 | function changeColor(x, color) -- DONE 1 | |
| 641 | if x < 25 then | |
| 642 | - | if e[1] == "mouse_click" then |
| 642 | + | |
| 643 | - | mode = "back" |
| 643 | + | |
| 644 | - | elseif e[1] == "char" then |
| 644 | + | |
| 645 | - | s = s .. e[2] |
| 645 | + | |
| 646 | - | elseif e[1] == "key" then |
| 646 | + | |
| 647 | - | if e[2] == keys.enter then |
| 647 | + | |
| 648 | elseif site[selected][selectedObj][color] >= 16 then | |
| 649 | - | elseif e[2] == keys.backspace then |
| 649 | + | |
| 650 | - | s = s:sub( 1, s:len() - 1 ) |
| 650 | + | |
| 651 | end | |
| 652 | ||
| 653 | - | checkEvent(e, false) |
| 653 | + | |
| 654 | if x < 25 then | |
| 655 | site[selected][selectedObj][transparency] = site[selected][selectedObj][transparency] - 0.1 | |
| 656 | else | |
| 657 | site[selected][selectedObj][transparency] = site[selected][selectedObj][transparency] + 0.1 | |
| 658 | end | |
| 659 | if site[selected][selectedObj][transparency] < 0 then | |
| 660 | site[selected][selectedObj][transparency] = 1 | |
| 661 | elseif site[selected][selectedObj][transparency] > 1 then | |
| 662 | site[selected][selectedObj][transparency] = 0 | |
| 663 | end | |
| 664 | end | |
| 665 | ||
| 666 | ||
| 667 | ||
| 668 | -- QUATERNARY MENUS | |
| 669 | ||
| 670 | function menuArguments(unit_pos, method_pos, arguments_pos, amount, args, advancedMethodsSupport) -- DONE 1 | |
| 671 | local previousMode = mode | |
| 672 | mode = "arguments" | |
| 673 | ||
| 674 | local param = site[selected][selectedObj][arguments_pos] | |
| 675 | if advancedMethodsSupport then | |
| 676 | for i=1, amount do | |
| 677 | if args[i]["type"] == "NUMBER" and param[i] == nil then | |
| 678 | param[i] = i | |
| 679 | elseif param[i] == nil then | |
| 680 | param[i] = "Argument" .. i | |
| 681 | end | |
| 682 | end | |
| 683 | end | |
| 684 | ||
| 685 | ||
| 686 | while true do | |
| 687 | -- DRAW | |
| 688 | amount = countArray(param) | |
| 689 | clear() | |
| 690 | centered("ENTER ARGUMENTS FOR METHOD " .. site[selected][selectedObj][method_pos], 1)
| |
| 691 | fill("-", 2)
| |
| 692 | centered("APPLY", 15)
| |
| 693 | for i=1, amount do | |
| 694 | write("ARG ".. i ..": " .. param[i],11,3+i)
| |
| 695 | end | |
| 696 | if not advancedMethodsSupport and amount <= 10 then | |
| 697 | centered("ADD NEW MANUAL ARGUMENT", 16)
| |
| 698 | end | |
| 699 | if not advancedMethodsSupport and amount > 0 then | |
| 700 | centered("DELETE LAST ARGUMENT", 17)
| |
| 701 | end | |
| 702 | ||
| 703 | -- EVENT | |
| 704 | local event = { os.pullEvent() }
| |
| 705 | if checkEvent(event) then | |
| 706 | x,y = event[3], event[4] | |
| 707 | if y >= 4 and y <= amount+3 then | |
| 708 | site[selected][selectedObj][arguments_pos] = param[y-3] | |
| 709 | if advancedMethodsSupport then | |
| 710 | if args[y-3]["type"] == "NUMBER" then | |
| 711 | betterRead(18,y,true,arguments_pos,x) | |
| 712 | else | |
| 713 | betterRead(18,y,false,arguments_pos,x) | |
| 714 | end | |
| 715 | else -- not advancedMethodsSupport | |
| 716 | betterRead(18,y,false,arguments_pos,x) | |
| 717 | local tempVar = tonumber(site[selected][selectedObj][arguments_pos]) | |
| 718 | if tempVar then | |
| 719 | site[selected][selectedObj][arguments_pos] = tempVar | |
| 720 | end | |
| 721 | end | |
| 722 | param[y-3] = site[selected][selectedObj][arguments_pos] | |
| 723 | elseif not advancedMethodsSupport and amount <= 10 and y == 16 then | |
| 724 | param[amount+1] = "Manual Argument" .. amount+1 | |
| 725 | elseif not advancedMethodsSupport and amount > 0 and y == 17 then | |
| 726 | param[amount] = nil | |
| 727 | elseif y == 15 then | |
| 728 | mode = "back" | |
| 729 | end | |
| 730 | end | |
| 731 | ||
| 732 | -- BACK TO MENU | |
| 733 | if mode == "back" then | |
| 734 | mode = previousMode | |
| 735 | break | |
| 736 | elseif not (mode == "arguments") then | |
| 737 | break | |
| 738 | end | |
| 739 | end | |
| 740 | site[selected][selectedObj][arguments_pos] = param | |
| 741 | save() | |
| 742 | end | |
| 743 | ||
| 744 | ||
| 745 | ||
| 746 | ||
| 747 | ||
| 748 | ||
| 749 | -- TERTIARY MENUS | |
| 750 | ||
| 751 | function menuUnit(unit_pos, method_pos, arguments_pos) -- DONE 1 | |
| 752 | clear() | |
| 753 | local list = net.getNamesRemote() | |
| 754 | if countArray(list) == 0 then | |
| 755 | centered("NOTHING ATTACHED TO THE NETWORK!",9)
| |
| 756 | while true do | |
| 757 | local event = {os.pullEvent()}
| |
| 758 | if event[1] == "timer" and event[2] == delay then | |
| 759 | drawSite() | |
| 760 | delay = os.startTimer(updateInterval) | |
| 761 | else | |
| 762 | return "NONE" | |
| 763 | end | |
| 764 | end | |
| 765 | end | |
| 766 | ||
| 767 | local selectedUnit = 1 | |
| 768 | for k,v in pairs(list) do | |
| 769 | selectedUnit = selectedUnit + 1 | |
| 770 | if advancedMethodsSupport and v["name"] == site[selected][selectedObj][unit_pos] then | |
| 771 | break | |
| 772 | elseif not advancedMethodsSupport and v == site[selected][selectedObj][unit_pos] then | |
| 773 | break | |
| 774 | end | |
| 775 | end | |
| 776 | selectedUnit = selectedUnit - 1 | |
| 777 | ||
| 778 | selectedUnit = 1 | |
| 779 | local previousMode = mode | |
| 780 | mode = "unit" | |
| 781 | while true do | |
| 782 | -- DRAW | |
| 783 | clear() | |
| 784 | centered("SELECT A UNIT",1)
| |
| 785 | fill("-",2)
| |
| 786 | centered("SELECT",14)
| |
| 787 | fill(" ",9)
| |
| 788 | drawArrows(9) | |
| 789 | centered(list[selectedUnit],9) | |
| 790 | ||
| 791 | -- EVENT | |
| 792 | local event = { os.pullEvent() }
| |
| 793 | if checkEvent(event) then | |
| 794 | x,y = event[3], event[4] | |
| 795 | if y >= 8 and y <= 10 then | |
| 796 | if x <= 25 then | |
| 797 | selectedUnit = selectedUnit - 1 | |
| 798 | else | |
| 799 | selectedUnit = selectedUnit + 1 | |
| 800 | end | |
| 801 | if selectedUnit == 0 then | |
| 802 | selectedUnit = countArray(list) | |
| 803 | elseif selectedUnit > countArray(list) then | |
| 804 | selectedUnit = 1 | |
| 805 | end | |
| 806 | elseif y == 14 then | |
| 807 | mode = "back" | |
| 808 | end | |
| 809 | end | |
| 810 | ||
| 811 | -- BACK TO MENU | |
| 812 | if mode == "back" then | |
| 813 | mode = previousMode | |
| 814 | break | |
| 815 | elseif not (mode == "unit") then | |
| 816 | break | |
| 817 | end | |
| 818 | end | |
| 819 | site[selected][selectedObj][unit_pos] = list[selectedUnit] | |
| 820 | site[selected][selectedObj][method_pos] = "NONE" | |
| 821 | site[selected][selectedObj][arguments_pos] = {}
| |
| 822 | end | |
| 823 | ||
| 824 | ||
| 825 | ||
| 826 | ||
| 827 | function menuMethod(method_pos, unit_pos, arguments_pos, allReturnTypes) -- DONE 1 | |
| 828 | local unit = site[selected][selectedObj][unit_pos] | |
| 829 | allReturnTypes = allReturnTypes or false | |
| 830 | clear() | |
| 831 | if not net.isPresentRemote(unit) then | |
| 832 | return "NONE" | |
| 833 | end | |
| 834 | ||
| 835 | -- methods available? | |
| 836 | local basicMethods = net.getMethodsRemote(unit) | |
| 837 | if basicMethods ~= nil and countArray(basicMethods) == 0 then | |
| 838 | centered("NO METHOD FOUND!",9)
| |
| 839 | while true do | |
| 840 | local event = {os.pullEvent()}
| |
| 841 | if event[1] == "timer" and event[2] == delay then | |
| 842 | drawSite() | |
| 843 | delay = os.startTimer(updateInterval) | |
| 844 | else | |
| 845 | break | |
| 846 | end | |
| 847 | end | |
| 848 | return "NONE" | |
| 849 | end | |
| 850 | ||
| 851 | -- advanced or normal support? (fixed by blunty666) | |
| 852 | local advancedMethodsSupport = false | |
| 853 | local unitType = "NONE" | |
| 854 | local tempList = {}
| |
| 855 | for k,v in pairs(basicMethods) do | |
| 856 | if v == "getAdvancedMethodsData" then | |
| 857 | advancedMethodsSupport = true | |
| 858 | unitType = net.getTypeRemote(unit) | |
| 859 | tempList = net.callRemote(unit, "getAdvancedMethodsData") | |
| 860 | break | |
| 861 | end | |
| 862 | end | |
| 863 | ||
| 864 | --[[ get advanced methods if possible | |
| 865 | local list = {}
| |
| 866 | if advancedMethodsSupport then | |
| 867 | local counter = 1 | |
| 868 | for k,v in pairs(tempList) do | |
| 869 | if allReturnTypes or ( v["returnType"] ~= nil and v["returnType"] ) or ( v["returnTypes"][1] == "NUMBER" ) then | |
| 870 | table.insert(list, 1, v) | |
| 871 | counter = counter - 1 | |
| 872 | end | |
| 873 | counter = counter + 1 | |
| 874 | end | |
| 875 | else | |
| 876 | list = net.getMethodsRemote(unit) | |
| 877 | end]] | |
| 878 | ||
| 879 | ||
| 880 | -- get advanced methods if possible (fixed by blunty666) | |
| 881 | local list = {}
| |
| 882 | if advancedMethodsSupport then | |
| 883 | local counter = 1 | |
| 884 | for k,v in pairs(tempList) do | |
| 885 | if allReturnTypes or ( v["returnType"] ~= nil and v["returnType"] ) or ( v["returnTypes"][1] == "NUMBER" ) then | |
| 886 | local tempT = v --same as v | |
| 887 | v.name = k --adds name to v which is the index k in tempList | |
| 888 | table.insert(list, 1, tempT) | |
| 889 | counter = counter - 1 | |
| 890 | end | |
| 891 | counter = counter + 1 | |
| 892 | end | |
| 893 | else | |
| 894 | list = net.getMethodsRemote(unit) | |
| 895 | end | |
| 896 | ||
| 897 | ||
| 898 | ||
| 899 | ||
| 900 | -- still methods with number as return value available? | |
| 901 | if advancedMethodsSupport and list ~= nil and countArray(list) == 0 then | |
| 902 | centered("NO METHOD FOUND!",9)
| |
| 903 | - | local advancedMethodsList = {}
|
| 903 | + | |
| 904 | local event = {os.pullEvent()}
| |
| 905 | if event[1] == "timer" and event[2] == delay then | |
| 906 | drawSite() | |
| 907 | delay = os.startTimer(updateInterval) | |
| 908 | - | advancedMethodsList = net.callRemote(unit, "getAdvancedMethodsData") |
| 908 | + | |
| 909 | break | |
| 910 | end | |
| 911 | end | |
| 912 | return "NONE" | |
| 913 | end | |
| 914 | ||
| 915 | ||
| 916 | - | for k,v in pairs(advancedMethodsList) do |
| 916 | + | |
| 917 | - | if allReturnTypes or ( v["returnType"] ~= nil and v["returnType"] ) or ( v["returnTypes"][1] == "number" ) then |
| 917 | + | |
| 918 | -- selection of the method | |
| 919 | local method = 1 | |
| 920 | for k,v in pairs(list) do | |
| 921 | method = method + 1 | |
| 922 | if advancedMethodsSupport and v["name"] == site[selected][selectedObj][method_pos] then | |
| 923 | break | |
| 924 | elseif not advancedMethodsSupport and v == site[selected][selectedObj][method_pos] then | |
| 925 | break | |
| 926 | end | |
| 927 | end | |
| 928 | method = method - 1 | |
| 929 | - | for k,v in pairs(advancedMethodsList) do |
| 929 | + | |
| 930 | - | if allReturnTypes or ( v["returnType"] ~= nil and v["returnType"] ) or ( v["returnTypes"][1] == "number" ) then |
| 930 | + | |
| 931 | - | v.name = k |
| 931 | + | |
| 932 | mode = "method" | |
| 933 | while true do | |
| 934 | -- DRAW | |
| 935 | clear() | |
| 936 | centered("SELECT A METHOD FROM " .. unit ,1)
| |
| 937 | fill("-",2)
| |
| 938 | centered("SELECT",16)
| |
| 939 | local methodName = "UNKNOWN" | |
| 940 | local methodDescription = "UNKNOWN! No Advanced Methods Support available!" | |
| 941 | local methodReturnType = "UNKNOWN" | |
| 942 | local methodArgumentamount = 1337 | |
| 943 | - | if advancedMethodsSupport and (list == nil or countArray(list) == 0) then |
| 943 | + | |
| 944 | if advancedMethodsSupport then | |
| 945 | local counter = 1 | |
| 946 | for k, v in pairs(list) do | |
| 947 | if counter == method then | |
| 948 | methodName = v["name"] | |
| 949 | methodDescription = v["description"] | |
| 950 | methodReturnType = v["returnType"] or v["returnTypes"][1] | |
| 951 | methodArgumentamount = countArray(v["args"]) or 0 | |
| 952 | methodArgs = v["args"] or {}
| |
| 953 | break | |
| 954 | end | |
| 955 | counter = counter + 1 | |
| 956 | end | |
| 957 | else | |
| 958 | methodDescription = "UNKNOWN! No Advanced Methods Support available!" | |
| 959 | methodReturnType = "UNKNOWN" | |
| 960 | methodArgumentamount = 0 | |
| 961 | methodName = list[method] | |
| 962 | end | |
| 963 | ||
| 964 | ||
| 965 | fill(" ",6)
| |
| 966 | drawArrows(6) | |
| 967 | centered(methodName, 6) | |
| 968 | term.setCursorPos(1,8) | |
| 969 | print(" Description: " .. methodDescription)
| |
| 970 | print(" Returns: " .. methodReturnType)
| |
| 971 | print(" Arguments: " .. methodArgumentamount)
| |
| 972 | if advancedMethodsSupport and methodArgumentamount >= 1 then | |
| 973 | centered("SET OR CHANGE ARGUMENTS", 15)
| |
| 974 | elseif not advancedMethodsSupport then | |
| 975 | centered("SET OR CHANGE ARGUMENTS (OWN RISK)", 15)
| |
| 976 | end | |
| 977 | ||
| 978 | -- EVENT | |
| 979 | local event = { os.pullEvent() }
| |
| 980 | if checkEvent(event) then | |
| 981 | site[selected][selectedObj][method_pos] = methodName | |
| 982 | x,y = event[3], event[4] | |
| 983 | if y >= 5 and y <= 8 then | |
| 984 | site[selected][selectedObj][arguments_pos] = {}
| |
| 985 | screen[selected][selectedObj][arguments_pos] = {}
| |
| 986 | if x <= 25 then | |
| 987 | method = method - 1 | |
| 988 | else | |
| 989 | method = method + 1 | |
| 990 | end | |
| 991 | if method == 0 then | |
| 992 | - | methodReturnType = v["returnType"] or v["returnTypes"][1] or "nil" |
| 992 | + | |
| 993 | elseif method > countArray(list) then | |
| 994 | method = 1 | |
| 995 | end | |
| 996 | elseif advancedMethodsSupport and methodArgumentamount >= 1 and y == 15 then | |
| 997 | menuArguments(unit_pos, method_pos, arguments_pos, methodArgumentamount, methodArgs, true) | |
| 998 | elseif not advancedMethodsSupport and y == 15 then | |
| 999 | menuArguments(unit_pos, method_pos, arguments_pos, countArray(site[selected][selectedObj][arguments_pos]), methodArgs, false) | |
| 1000 | elseif y == 16 then | |
| 1001 | mode = "back" | |
| 1002 | end | |
| 1003 | end | |
| 1004 | ||
| 1005 | -- BACK TO MENU | |
| 1006 | if mode == "back" then | |
| 1007 | mode = previousMode | |
| 1008 | break | |
| 1009 | elseif not (mode == "method") then | |
| 1010 | break | |
| 1011 | end | |
| 1012 | end | |
| 1013 | end | |
| 1014 | ||
| 1015 | ||
| 1016 | -- SECONDARY MENUS | |
| 1017 | ||
| 1018 | function menuSiteOrFrame(setMode) -- DONE 1 | |
| 1019 | mode = setMode | |
| 1020 | local selectedFrame = 100 | |
| 1021 | if mode == "site" then | |
| 1022 | selected = 1 | |
| 1023 | else | |
| 1024 | selected = 100 | |
| 1025 | end | |
| 1026 | selectedObj = 1 | |
| 1027 | while true do | |
| 1028 | -- DRAW | |
| 1029 | clear() | |
| 1030 | drawArrows(1) | |
| 1031 | if mode == "site" then | |
| 1032 | centered("SITE " .. selected ,1)
| |
| 1033 | elseif mode == "frame" then | |
| 1034 | centered("FRAME " .. selected-99 ,1)
| |
| 1035 | end | |
| 1036 | fill("-",2)
| |
| 1037 | local obj = site[selected][selectedObj] | |
| 1038 | if type(obj) == "table" then | |
| 1039 | centered(selectedObj.. " - " .. obj.type , 3) | |
| 1040 | else | |
| 1041 | centered(selectedObj , 3) | |
| 1042 | end | |
| 1043 | drawArrows(3) | |
| 1044 | fill("-",4)
| |
| 1045 | write("BACK",48,1)
| |
| 1046 | if type(obj) == "table" then -- object exists | |
| 1047 | write("DELETE",1,1)
| |
| 1048 | if obj.type == "text" then -- TEXT | |
| 1049 | write("TEXT: " .. obj.text,10,7)
| |
| 1050 | write("X: " .. obj.x,10,9)
| |
| 1051 | write("Y: " .. obj.y,10,11)
| |
| 1052 | drawColor(obj.text_color,13) | |
| 1053 | elseif obj.type == "box" then -- BOX | |
| 1054 | write("X: " .. obj.x,10,5)
| |
| 1055 | write("Y: " .. obj.y,10,6)
| |
| 1056 | write("WIDTH: " .. obj.w,10,7)
| |
| 1057 | write("HEIGHT: " .. obj.h,10,8)
| |
| 1058 | drawColor(obj.border_color,9) | |
| 1059 | drawTransparent(obj.border_transparency,10) | |
| 1060 | drawColor(obj.inner_color,11) | |
| 1061 | drawTransparent(obj.inner_transparency,12) | |
| 1062 | elseif obj.type == "number" then -- NUMBER | |
| 1063 | write("X: "..obj.x,10,5)
| |
| 1064 | write("Y: "..obj.y,10,6)
| |
| 1065 | write("TEXT: "..obj.text,10,7)
| |
| 1066 | write("UNIT: "..obj.unit,10,8)
| |
| 1067 | write("METHOD: "..obj.method,10,9)
| |
| 1068 | write("MAX: "..obj.maxNumber,10,10)
| |
| 1069 | drawColor(obj.text_standardColor,11) | |
| 1070 | drawColor(obj.text_maxNumberColor,12) | |
| 1071 | elseif obj.type == "bar" then -- BAR | |
| 1072 | write("X: "..obj.x,10,5)
| |
| 1073 | write("Y: "..obj.y,10,6)
| |
| 1074 | write("WIDTH: "..obj.w,10,7)
| |
| 1075 | write("HEIGHT: "..obj.h,10,8)
| |
| 1076 | write("UNIT: "..obj.unit,10,9)
| |
| 1077 | write("METHOD: "..obj.method,29,9)
| |
| 1078 | write("MAX: "..obj.maxNumber,10,10)
| |
| 1079 | drawColor(obj.color,11) | |
| 1080 | drawTransparent(obj.transparency,12) | |
| 1081 | drawColor(obj.color2,13) | |
| 1082 | drawTransparent(obj.transparency2,14) | |
| 1083 | drawColor(obj.color3,15) | |
| 1084 | drawTransparent(obj.transparency3,16) | |
| 1085 | drawColor(obj.color4,17) | |
| 1086 | drawTransparent(obj.transparency4,18) | |
| 1087 | write("ADD AUTO TEXT", 10, 19)
| |
| 1088 | elseif obj.type == "graphPillar" or obj.type == "graphPoint" then | |
| 1089 | -- GRAPHS | |
| 1090 | write("X: "..obj.x,10,5)
| |
| 1091 | write("Y: "..obj.y,10,6)
| |
| 1092 | write("WIDTH: "..obj.w,10,7)
| |
| 1093 | write("HEIGHT: "..obj.h,10,8)
| |
| 1094 | write("UNIT: "..obj.unit,10,9)
| |
| 1095 | write("METHOD: "..obj.method,10,10)
| |
| 1096 | write("MIN: "..obj.minNumber,10,11)
| |
| 1097 | write("MAX: "..obj.maxNumber,10,12)
| |
| 1098 | drawColor(obj.color,13) | |
| 1099 | drawTransparent(obj.transparency,14) | |
| 1100 | write("FADEOUT: "..tostring(obj.fadeout),10,15)
| |
| 1101 | write("TYPE: " ..obj.type,10,16)
| |
| 1102 | write("ADD AUTO BOX", 10, 17)
| |
| 1103 | elseif obj.type == "frame" then -- FRAME | |
| 1104 | centered(obj.frame-99,5) | |
| 1105 | drawArrows(5) | |
| 1106 | fill("-",6)
| |
| 1107 | write("X: "..obj.x,10,8)
| |
| 1108 | write("Y: "..obj.y,10,10)
| |
| 1109 | end | |
| 1110 | else --create new object | |
| 1111 | write("TEXT",20,6)
| |
| 1112 | write("BOX",20,7)
| |
| 1113 | write("NUMBER",20,8)
| |
| 1114 | write("BAR",20,9)
| |
| 1115 | write("GRAPH (PILLAR)",20,10)
| |
| 1116 | write("GRAPH (POINT)",20,11)
| |
| 1117 | if mode == "site" then | |
| 1118 | write("FRAME",20,12)
| |
| 1119 | end | |
| 1120 | end | |
| 1121 | ||
| 1122 | -- EVENT | |
| 1123 | local event = { os.pullEvent() }
| |
| 1124 | if checkEvent(event) then | |
| 1125 | x, y = event[3], event[4] | |
| 1126 | if y == 1 and x >= w-4 then | |
| 1127 | mode = "mainmenu" | |
| 1128 | elseif type(site[selected][selectedObj]) == "table" and y == 1 and x <=6 then | |
| 1129 | site[selected][selectedObj] = nil | |
| 1130 | if selectedObj >= 2 then | |
| 1131 | selectedObj = selectedObj - 1 | |
| 1132 | end | |
| 1133 | elseif y == 1 then | |
| 1134 | selectedObj = 1 | |
| 1135 | if x < 25 then | |
| 1136 | selected = selected - 1 | |
| 1137 | else | |
| 1138 | selected = selected + 1 | |
| 1139 | end | |
| 1140 | if mode == "site" then | |
| 1141 | if selected <= 0 then | |
| 1142 | selected = 99 | |
| 1143 | elseif selected >= 100 then | |
| 1144 | selected = 1 | |
| 1145 | end | |
| 1146 | elseif mode == "frame" then | |
| 1147 | if selected <= 99 then | |
| 1148 | selected = 198 | |
| 1149 | elseif selected >= 199 then | |
| 1150 | - | elseif obj.type == "tank" then -- TANK |
| 1150 | + | |
| 1151 | end | |
| 1152 | end | |
| 1153 | elseif y >= 2 and y <= 4 then | |
| 1154 | if x < 25 then | |
| 1155 | selectedObj = selectedObj - 1 | |
| 1156 | - | write("METHOD: "..obj.method,10,10)
|
| 1156 | + | |
| 1157 | - | write("MAX: "..obj.maxNumber,10,11)
|
| 1157 | + | |
| 1158 | - | write("LIQUID: "..obj.liquid,10,12)
|
| 1158 | + | |
| 1159 | - | drawColor(obj.cBorder,13) |
| 1159 | + | |
| 1160 | - | drawTransparent(obj.tBorder,14) |
| 1160 | + | |
| 1161 | - | drawColor(obj.cBack,15) |
| 1161 | + | |
| 1162 | - | drawTransparent(obj.tBack,16) |
| 1162 | + | |
| 1163 | if site[selected][selectedObj].type == "text" then | |
| 1164 | if y == 7 then | |
| 1165 | betterRead(16,y,false,"text",x) | |
| 1166 | elseif y == 9 then | |
| 1167 | betterRead(16,y,true,"x",x) | |
| 1168 | elseif y == 11 then | |
| 1169 | betterRead(16,y,true,"y",x) | |
| 1170 | elseif y == 13 then | |
| 1171 | - | write("TANK",20,12)
|
| 1171 | + | |
| 1172 | end | |
| 1173 | - | write("FRAME",20,13)
|
| 1173 | + | |
| 1174 | if y == 5 then | |
| 1175 | betterRead(18,y,true,"x",x) | |
| 1176 | elseif y == 6 then | |
| 1177 | betterRead(18,y,true,"y",x) | |
| 1178 | elseif y == 7 then | |
| 1179 | betterRead(18,y,true,"w",x) | |
| 1180 | elseif y == 8 then | |
| 1181 | betterRead(18,y,true,"h",x) | |
| 1182 | elseif y == 9 then | |
| 1183 | changeColor(x,"border_color") | |
| 1184 | elseif y == 10 then | |
| 1185 | changeTransparence(x,"border_transparency") | |
| 1186 | elseif y == 11 then | |
| 1187 | changeColor(x,"inner_color") | |
| 1188 | elseif y == 12 then | |
| 1189 | changeTransparence(x,"inner_transparency") | |
| 1190 | end | |
| 1191 | elseif site[selected][selectedObj].type == "number" then | |
| 1192 | if y == 5 then | |
| 1193 | betterRead(18,y,true,"x",x) | |
| 1194 | elseif y == 6 then | |
| 1195 | betterRead(18,y,true,"y",x) | |
| 1196 | elseif y == 7 then | |
| 1197 | betterRead(18,y,false,"text",x) | |
| 1198 | elseif y == 8 then | |
| 1199 | menuUnit("unit","method","arguments")
| |
| 1200 | elseif y == 9 then | |
| 1201 | if x < 18 then | |
| 1202 | menuMethod("method","unit","arguments",true)
| |
| 1203 | else | |
| 1204 | menuMethod("method","unit","arguments",false)
| |
| 1205 | end | |
| 1206 | elseif y == 10 then | |
| 1207 | betterRead(18,y,true,"maxNumber",x) | |
| 1208 | elseif y == 11 then | |
| 1209 | changeColor(x,"text_standardColor") | |
| 1210 | elseif y == 12 then | |
| 1211 | changeColor(x,"text_maxNumberColor") | |
| 1212 | end | |
| 1213 | elseif site[selected][selectedObj].type == "bar" then | |
| 1214 | if y == 5 then | |
| 1215 | betterRead(18,y,true,"x",x) | |
| 1216 | elseif y == 6 then | |
| 1217 | betterRead(18,y,true,"y",x) | |
| 1218 | elseif y == 7 then | |
| 1219 | betterRead(18,y,true,"w",x) | |
| 1220 | elseif y == 8 then | |
| 1221 | betterRead(18,y,true,"h",x) | |
| 1222 | elseif y == 9 then | |
| 1223 | if x < 28 then | |
| 1224 | menuUnit("unit","method","arguments")
| |
| 1225 | else | |
| 1226 | if x < 18 then | |
| 1227 | menuMethod("method","unit","arguments",true)
| |
| 1228 | else | |
| 1229 | menuMethod("method","unit","arguments",false)
| |
| 1230 | end | |
| 1231 | end | |
| 1232 | elseif y == 10 then | |
| 1233 | betterRead(18,y,true,"maxNumber",x) | |
| 1234 | elseif y == 11 then | |
| 1235 | changeColor(x,"color") | |
| 1236 | elseif y == 12 then | |
| 1237 | changeTransparence(x,"transparency") | |
| 1238 | elseif y == 13 then | |
| 1239 | changeColor(x,"color2") | |
| 1240 | elseif y == 14 then | |
| 1241 | changeTransparence(x,"transparency2") | |
| 1242 | elseif y == 15 then | |
| 1243 | changeColor(x,"color3") | |
| 1244 | elseif y == 16 then | |
| 1245 | changeTransparence(x,"transparency3") | |
| 1246 | elseif y == 17 then | |
| 1247 | changeColor(x,"color4") | |
| 1248 | elseif y == 18 then | |
| 1249 | changeTransparence(x,"transparency4") | |
| 1250 | elseif y == 19 then | |
| 1251 | local bar = site[selected][selectedObj] | |
| 1252 | local textProperties = {type="text",text="YOUR TEXT",x=bar.x-59,y=bar.y+4,text_color=bar.color}
| |
| 1253 | table.insert(site[selected], selectedObj+1, textProperties ) | |
| 1254 | selectedObj = selectedObj+1 | |
| 1255 | ||
| 1256 | betterRead(25,y,false,"text",50) | |
| 1257 | site[selected][selectedObj].x = bar.x - 10 - math.floor(5.5 * #site[selected][selectedObj].text) | |
| 1258 | end | |
| 1259 | elseif site[selected][selectedObj].type == "graphPillar" or site[selected][selectedObj].type == "graphPoint" then | |
| 1260 | if y == 5 then | |
| 1261 | betterRead(19,y,true,"x",x) | |
| 1262 | elseif y == 6 then | |
| 1263 | betterRead(19,y,true,"y",x) | |
| 1264 | elseif y == 7 then | |
| 1265 | betterRead(19,y,true,"w",x) | |
| 1266 | elseif y == 8 then | |
| 1267 | betterRead(19,y,true,"h",x) | |
| 1268 | elseif y == 9 then | |
| 1269 | menuUnit("unit","method","arguments")
| |
| 1270 | elseif y == 10 then | |
| 1271 | if x < 18 then | |
| 1272 | menuMethod("method","unit","arguments",true)
| |
| 1273 | else | |
| 1274 | menuMethod("method","unit","arguments",false)
| |
| 1275 | end | |
| 1276 | elseif y == 11 then | |
| 1277 | betterRead(19,y,true,"minNumber",x) | |
| 1278 | elseif y == 12 then | |
| 1279 | betterRead(19,y,true,"maxNumber",x) | |
| 1280 | elseif y == 13 then | |
| 1281 | changeColor(x,"color") | |
| 1282 | elseif y == 14 then | |
| 1283 | changeTransparence(x,"transparency") | |
| 1284 | elseif y == 15 then | |
| 1285 | site[selected][selectedObj].fadeout = not site[selected][selectedObj].fadeout | |
| 1286 | elseif y == 16 then | |
| 1287 | if site[selected][selectedObj].type == "graphPoint" then | |
| 1288 | site[selected][selectedObj].type = "graphPillar" | |
| 1289 | elseif site[selected][selectedObj].type == "graphPillar" then | |
| 1290 | site[selected][selectedObj].type = "graphPoint" | |
| 1291 | end | |
| 1292 | elseif y == 17 then | |
| 1293 | local g = site[selected][selectedObj] | |
| 1294 | local boxProperties = {type="box", x=g.x-4, y=g.y-6, w=g.w+8, h=g.h+10, inner_color=1, inner_transparency=0.4, border_color=g.color, border_transparency=0.9}
| |
| 1295 | table.insert(site[selected], selectedObj+1, boxProperties ) | |
| 1296 | selectedObj = selectedObj+1 | |
| 1297 | end | |
| 1298 | elseif site[selected][selectedObj].type == "frame" then | |
| 1299 | if y == 5 then | |
| 1300 | if x < 25 then | |
| 1301 | site[selected][selectedObj].frame = site[selected][selectedObj].frame - 1 | |
| 1302 | else | |
| 1303 | site[selected][selectedObj].frame = site[selected][selectedObj].frame + 1 | |
| 1304 | end | |
| 1305 | if site[selected][selectedObj].frame == 99 then | |
| 1306 | site[selected][selectedObj].frame = 198 | |
| 1307 | elseif site[selected][selectedObj].frame == 199 then | |
| 1308 | site[selected][selectedObj].frame = 100 | |
| 1309 | end | |
| 1310 | elseif y == 8 then | |
| 1311 | betterRead(13,y,true,"x",x) | |
| 1312 | elseif y == 10 then | |
| 1313 | betterRead(13,y,true,"y",x) | |
| 1314 | end | |
| 1315 | end | |
| 1316 | else -- CREATE | |
| 1317 | if y == 6 then | |
| 1318 | site[selected][selectedObj] = {type="text",text="UNOBTANIUM",x=1,y=1,text_color=1}
| |
| 1319 | elseif y == 7 then | |
| 1320 | site[selected][selectedObj] = {type="box",x=1,y=1,w=10,h=10,inner_color=1,inner_transparency=0.4,border_color=15,border_transparency=1}
| |
| 1321 | elseif y == 8 then | |
| 1322 | site[selected][selectedObj] = {type="number",x=1,y=1,text="UNOBTANIUM",unit="NONE",method="NONE",maxNumber=1337,text_standardColor=1,text_maxNumberColor=14,arguments={}}
| |
| 1323 | elseif y == 9 then | |
| 1324 | site[selected][selectedObj] = {type="bar",x=1,y=1,w=40,h=15,color=1,transparency=1,color2=2,transparency2=1,color3=3,transparency3=1,color4=4,transparency4=1,unit="NONE",method="NONE",maxNumber=1337, arguments={}}
| |
| 1325 | elseif y == 10 then | |
| 1326 | site[selected][selectedObj] = {type="graphPillar",x=1,y=1,w=100,h=40,minNumber=0,maxNumber=1337,color=1,transparency=1,fadeout=false,unit="NONE",method="NONE",arguments={}}
| |
| 1327 | elseif y == 11 then | |
| 1328 | site[selected][selectedObj] = {type="graphPoint",x=1,y=1,w=100,h=40,minNumber=0,maxNumber=1337,color=1,transparency=1,fadeout=false,unit="NONE",method="NONE",arguments={}}
| |
| 1329 | elseif y == 12 and mode == "site" then | |
| 1330 | site[selected][selectedObj] = {type="frame",frame=100,x=0,y=0}
| |
| 1331 | end | |
| 1332 | end | |
| 1333 | end | |
| 1334 | ||
| 1335 | -- BACK TO MENU | |
| 1336 | if not (mode == "site" or mode == "frame") then | |
| 1337 | break | |
| 1338 | end | |
| 1339 | end | |
| 1340 | end | |
| 1341 | ||
| 1342 | ||
| 1343 | ||
| 1344 | function menuAlarm() -- DONE 1 | |
| 1345 | mode = "alarm" | |
| 1346 | local previousSelected = selected | |
| 1347 | selected = 199 | |
| 1348 | selectedObj = 1 | |
| 1349 | while true do | |
| 1350 | local obj = site[199][selectedObj] | |
| 1351 | -- DRAW | |
| 1352 | clear() | |
| 1353 | - | elseif site[selected][selectedObj].type == "tank" then |
| 1353 | + | |
| 1354 | centered("ALARM'N'ACTION", 1)
| |
| 1355 | fill("-",2)
| |
| 1356 | if type(site[199][selectedObj]) == "table" then | |
| 1357 | centered(selectedObj .. " - " .. obj.type, 3) | |
| 1358 | else | |
| 1359 | centered(selectedObj, 3) | |
| 1360 | end | |
| 1361 | drawArrows(3) | |
| 1362 | fill("-",4)
| |
| 1363 | write("BACK", 48, 1)
| |
| 1364 | local relY = 0 | |
| 1365 | if type(obj) == "table" and obj.type == "ALARM" then | |
| 1366 | write("DELETE", 1, 1)
| |
| 1367 | write("UNIT: "..obj.unit, 10, 6)
| |
| 1368 | write("METHOD: "..obj.method, 10, 7)
| |
| 1369 | write("NUMBER: "..obj.operator .. " " .. obj.number, 10, 8)
| |
| 1370 | write("ACTION: "..obj.action_type, 10, 9)
| |
| 1371 | relY = 2 | |
| 1372 | elseif type(obj) == "table" and obj.type == "CHAT" then | |
| 1373 | - | betterRead(18,y,false,"liquid",x) |
| 1373 | + | |
| 1374 | write("COMMAND: $$"..obj.text, 10, 6)
| |
| 1375 | - | changeColor(x,"cBorder") |
| 1375 | + | |
| 1376 | elseif type(obj) == "table" and obj.type == "REDNET" then | |
| 1377 | - | changeTransparence(x,"tBorder") |
| 1377 | + | |
| 1378 | write("MESSAGE: "..obj.text, 10, 6)
| |
| 1379 | - | changeColor(x,"cBack") |
| 1379 | + | |
| 1380 | else | |
| 1381 | - | changeTransparence(x,"tBack") |
| 1381 | + | |
| 1382 | write("CHAT", 10, 10)
| |
| 1383 | write("REDNET", 10 , 11)
| |
| 1384 | end | |
| 1385 | ||
| 1386 | if type(obj) == "table" then | |
| 1387 | if obj.action_type == "TEXT" then | |
| 1388 | write("| X: "..obj.action_x, 10, 8+relY)
| |
| 1389 | write("| Y: "..obj.action_y, 10, 9+relY)
| |
| 1390 | write("| TEXT: "..obj.action_text, 10, 10+relY)
| |
| 1391 | drawColor(obj.action_text_color, 11+relY) | |
| 1392 | elseif obj.action_type == "ACTIVATION" then | |
| 1393 | write("| UNIT: "..obj.action_unit, 10, 8+relY)
| |
| 1394 | write("| METHOD: "..obj.action_method, 10, 9+relY)
| |
| 1395 | elseif obj.action_type == "REDNET" then | |
| 1396 | write("| MESSAGE: "..obj.action_text, 10, 8+relY)
| |
| 1397 | end | |
| 1398 | end | |
| 1399 | ||
| 1400 | -- EVENT | |
| 1401 | local event = { os.pullEvent() }
| |
| 1402 | if checkEvent(event) then | |
| 1403 | x, y = event[3], event[4] | |
| 1404 | if y == 1 and x <= 6 and type(site[199][selectedObj]) == "table" then | |
| 1405 | site[199][selectedObj] = nil | |
| 1406 | if selectedObj >= 2 then | |
| 1407 | selectedObj = selectedObj - 1 | |
| 1408 | end | |
| 1409 | elseif y == 1 and x >= 48 then | |
| 1410 | save() | |
| 1411 | selected = previousSelected | |
| 1412 | selectedObj = 1 | |
| 1413 | mode = "mainmenu" | |
| 1414 | - | elseif y == 12 then |
| 1414 | + | |
| 1415 | - | site[selected][selectedObj] = {type="tank",x=1,y=1,w=15,h=40,cBorder=1,tBorder=1,cBack=2,tBack=1,unit="NONE",method="NONE",maxNumber=1337, liquid="water", arguments={}}
|
| 1415 | + | |
| 1416 | - | elseif y == 13 and mode == "site" then |
| 1416 | + | |
| 1417 | elseif selectedObj > 1 then | |
| 1418 | selectedObj = selectedObj - 1 | |
| 1419 | end | |
| 1420 | elseif type(site[199][selectedObj]) == "table" and site[199][selectedObj].type == "ALARM" then -- ALARM | |
| 1421 | if y == 6 then | |
| 1422 | menuUnit("unit","method","arguments")
| |
| 1423 | elseif y == 7 then | |
| 1424 | if x < 20 then | |
| 1425 | menuMethod("method", "unit","arguments",true)
| |
| 1426 | else | |
| 1427 | menuMethod("method", "unit","arguments",false)
| |
| 1428 | end | |
| 1429 | elseif y == 8 and x >=19 and x <= 21 then | |
| 1430 | if site[199][selectedObj].operator == "=" then | |
| 1431 | site[199][selectedObj].operator = ">" | |
| 1432 | elseif site[199][selectedObj].operator == ">" then | |
| 1433 | site[199][selectedObj].operator = "<" | |
| 1434 | elseif site[199][selectedObj].operator == "<" then | |
| 1435 | site[199][selectedObj].operator = "=" | |
| 1436 | end | |
| 1437 | elseif y == 8 then | |
| 1438 | betterRead(23,y,true,"number",x) | |
| 1439 | elseif y == 9 then | |
| 1440 | setAction() | |
| 1441 | elseif site[199][selectedObj].action_type == "TEXT" then -- ALARM: TEXT | |
| 1442 | if y == 10 then | |
| 1443 | betterRead(21,y,true,"action_x",x) | |
| 1444 | elseif y == 11 then | |
| 1445 | betterRead(21,y,true,"action_y",x) | |
| 1446 | elseif y == 12 then | |
| 1447 | betterRead(21,y,false,"action_text",x) | |
| 1448 | elseif y == 13 then | |
| 1449 | changeColor(x,"action_text_color") | |
| 1450 | end | |
| 1451 | elseif site[199][selectedObj].action_type == "ACTIVATION" then -- ALARM: ACTIVATION | |
| 1452 | if y == 10 then | |
| 1453 | menuUnit("action_unit","action_method","action_arguments")
| |
| 1454 | elseif y == 11 then | |
| 1455 | if x < 20 then | |
| 1456 | menuMethod("action_method", "action_unit", "action_arguments", true)
| |
| 1457 | else | |
| 1458 | menuMethod("action_method", "action_unit", "action_arguments",false)
| |
| 1459 | end | |
| 1460 | end | |
| 1461 | elseif site[199][selectedObj].action_type == "REDNET" then -- ALARM: REDNET | |
| 1462 | if y == 11 then | |
| 1463 | betterRead(21,y,false,"action_text",x) | |
| 1464 | end | |
| 1465 | end | |
| 1466 | ||
| 1467 | elseif type(site[199][selectedObj]) == "table" and ( site[199][selectedObj].type == "CHAT" or site[199][selectedObj].type == "REDNET") then -- CHAT AND REDNET | |
| 1468 | if y == 6 then | |
| 1469 | betterRead(21,y,false,"text",x) | |
| 1470 | elseif y == 7 then | |
| 1471 | setAction() | |
| 1472 | elseif site[199][selectedObj].action_type == "TEXT" then -- ALARM: TEXT | |
| 1473 | if y == 8 then | |
| 1474 | betterRead(21,y,true,"action_x",x) | |
| 1475 | elseif y == 9 then | |
| 1476 | betterRead(21,y,true,"action_y",x) | |
| 1477 | elseif y == 10 then | |
| 1478 | betterRead(21,y,false,"action_text",x) | |
| 1479 | elseif y == 11 then | |
| 1480 | changeColor(x,"action_text_color") | |
| 1481 | end | |
| 1482 | elseif site[199][selectedObj].action_type == "ACTIVATION" then -- ALARM: ACTIVATION | |
| 1483 | if y == 8 then | |
| 1484 | menuUnit("action_unit","action_method","action_arguments")
| |
| 1485 | elseif y == 9 then | |
| 1486 | if x < 20 then | |
| 1487 | menuMethod("action_method", "action_unit","action_arguments",true)
| |
| 1488 | else | |
| 1489 | menuMethod("action_method", "action_unit", "action_arguments",false)
| |
| 1490 | end | |
| 1491 | end | |
| 1492 | elseif site[199][selectedObj].action_type == "REDNET" then -- ALARM: REDNET | |
| 1493 | if y == 8 then | |
| 1494 | betterRead(21,y,false,"action_text",x) | |
| 1495 | end | |
| 1496 | end | |
| 1497 | ||
| 1498 | else -- CREATE NEW | |
| 1499 | site[199][selectedObj] = {}
| |
| 1500 | if y == 9 then | |
| 1501 | site[199][selectedObj] = {type="ALARM" ,unit="NONE", method="NONE", arguments={}, operator="=", number=42, action_type="NONE"}
| |
| 1502 | elseif y == 10 then | |
| 1503 | site[199][selectedObj] = {type="CHAT",text="NONE",action_type="NONE"}
| |
| 1504 | elseif y == 11 then | |
| 1505 | site[199][selectedObj] = {type="REDNET",text="NONE",action_type="NONE"}
| |
| 1506 | end | |
| 1507 | end | |
| 1508 | end | |
| 1509 | ||
| 1510 | -- BACK TO MENU | |
| 1511 | if not (mode == "alarm") then | |
| 1512 | selected = previousSelected | |
| 1513 | break | |
| 1514 | end | |
| 1515 | end | |
| 1516 | end | |
| 1517 | ||
| 1518 | function setAction() -- DONE 1 | |
| 1519 | if site[199][selectedObj].action_type == "NONE" then | |
| 1520 | site[199][selectedObj].action_type = "TEXT" | |
| 1521 | site[199][selectedObj].action_x = 1 | |
| 1522 | site[199][selectedObj].action_y = 1 | |
| 1523 | site[199][selectedObj].action_text = "UNOBTANIUM" | |
| 1524 | site[199][selectedObj].action_text_color = 1 | |
| 1525 | elseif site[199][selectedObj].action_type == "TEXT" then | |
| 1526 | site[199][selectedObj].action_type = "ACTIVATION" | |
| 1527 | site[199][selectedObj].action_unit = "NONE" | |
| 1528 | site[199][selectedObj].action_method = "NONE" | |
| 1529 | site[199][selectedObj].action_arguments = {}
| |
| 1530 | site[199][selectedObj].action_text_color = nil | |
| 1531 | site[199][selectedObj].action_text = nil | |
| 1532 | site[199][selectedObj].action_x = nil | |
| 1533 | site[199][selectedObj].action_y = nil | |
| 1534 | elseif site[199][selectedObj].action_type == "ACTIVATION" then | |
| 1535 | site[199][selectedObj].action_type = "REDNET" | |
| 1536 | site[199][selectedObj].action_text = "UNOBTANIUM" | |
| 1537 | site[199][selectedObj].action_unit = nil | |
| 1538 | site[199][selectedObj].action_method = nil | |
| 1539 | site[199][selectedObj].action_arguments = nil | |
| 1540 | elseif site[199][selectedObj].action_type == "REDNET" then | |
| 1541 | site[199][selectedObj].action_type = "NONE" | |
| 1542 | site[199][selectedObj].action_text = nil | |
| 1543 | end | |
| 1544 | end | |
| 1545 | ||
| 1546 | ||
| 1547 | ||
| 1548 | -- PRIMARY MENUS | |
| 1549 | ||
| 1550 | function mainMenu() -- DONE 1 | |
| 1551 | mode = "mainmenu" | |
| 1552 | while true do | |
| 1553 | for _, side in pairs(rednetSide) do | |
| 1554 | if peripheral.getType(side) == "modem" then | |
| 1555 | rednet.open(side) | |
| 1556 | end | |
| 1557 | end | |
| 1558 | ||
| 1559 | -- DRAW | |
| 1560 | clear() | |
| 1561 | centered("CLIENT FOR OPENPERIPERAL'S GLASSES", 1)
| |
| 1562 | fill("-", 2)
| |
| 1563 | write("by UNOBTANIUM", w-13, h)
| |
| 1564 | write("Site",20,6)
| |
| 1565 | write("Frame",20,8)
| |
| 1566 | write("Alarm'n'Action",20,10)
| |
| 1567 | write("Quit",20,13)
| |
| 1568 | write("< " .. updateInterval .. " >",2, h)
| |
| 1569 | ||
| 1570 | -- EVENT | |
| 1571 | local event = { os.pullEvent() }
| |
| 1572 | if checkEvent(event) then | |
| 1573 | x, y = event[3], event[4] | |
| 1574 | if y == 6 then | |
| 1575 | menuSiteOrFrame("site")
| |
| 1576 | elseif y == 8 then | |
| 1577 | menuSiteOrFrame("frame")
| |
| 1578 | elseif y == 10 then | |
| 1579 | menuAlarm() | |
| 1580 | elseif y == 13 then | |
| 1581 | save() | |
| 1582 | b.clear() | |
| 1583 | mode = "quit" | |
| 1584 | elseif y == h then | |
| 1585 | if x <= 3 then | |
| 1586 | updateInterval = updateInterval / 2 | |
| 1587 | elseif x >=10 and x <= 12 and updateInterval < 16 then | |
| 1588 | updateInterval = updateInterval * 2 | |
| 1589 | end | |
| 1590 | if updateInterval < 0.5 then | |
| 1591 | updateInterval = 0.5 | |
| 1592 | end | |
| 1593 | end | |
| 1594 | end | |
| 1595 | ||
| 1596 | if mode == "quit" then | |
| 1597 | break | |
| 1598 | end | |
| 1599 | end | |
| 1600 | end | |
| 1601 | ||
| 1602 | ||
| 1603 | ||
| 1604 | -- EVENT HANDLING | |
| 1605 | ||
| 1606 | function checkEvent(event, justUpdate, charAndKeyEvent) | |
| 1607 | charAndKeyEvent = charAndKeyEvent or false | |
| 1608 | justUpdate = justUpdate or false | |
| 1609 | if event[1] == "timer" and event[2] == delay then | |
| 1610 | if justUpdate then | |
| 1611 | update() | |
| 1612 | else | |
| 1613 | drawSite() | |
| 1614 | end | |
| 1615 | delay = os.startTimer(updateInterval) | |
| 1616 | ||
| 1617 | elseif event[1] == "mouse_click" then | |
| 1618 | return true | |
| 1619 | elseif charAndKeyEvent and ( event[1] == "char" or event[1] == "key" ) then | |
| 1620 | return true | |
| 1621 | ||
| 1622 | elseif event[1] == "chat_command" then | |
| 1623 | mode = "mainmenu" | |
| 1624 | checkAlarm(event[2]) | |
| 1625 | if event[2] == "clear" or event[2] == "" then | |
| 1626 | b.clear() | |
| 1627 | selected = 0 | |
| 1628 | elseif event[2] == "sync" then | |
| 1629 | b.clear() | |
| 1630 | local var = b.addText(10, 10, "Sync!", colorHex[14]) | |
| 1631 | setZDimension(var) | |
| 1632 | if selected == 0 then | |
| 1633 | selected = 1 | |
| 1634 | end | |
| 1635 | sleep(2) | |
| 1636 | delay = os.startTimer(0.2) | |
| 1637 | else | |
| 1638 | for i=1,99 do | |
| 1639 | if event[2] == "site"..i then | |
| 1640 | selected = i | |
| 1641 | drawSite() | |
| 1642 | break | |
| 1643 | end | |
| 1644 | end | |
| 1645 | end | |
| 1646 | ||
| 1647 | elseif event[1] == "rednet_message" then | |
| 1648 | checkAlarm("", tostring(event[3]))
| |
| 1649 | end | |
| 1650 | ||
| 1651 | return false | |
| 1652 | end | |
| 1653 | ||
| 1654 | ||
| 1655 | -- START | |
| 1656 | ||
| 1657 | load() | |
| 1658 | mainMenu() | |
| 1659 | clear() |