Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Script by Savage_Me55iah of CraftAU.com.au--
- --Other Savage_Me55iah scripts @ http://pastebin.com/u/Savage_Me55iah
- --INSTRUCTIONS ON USE--
- --Instruction video on http://youtube.com/savagemessiah5
- --Contact Savage_Me55iah @ CraftAU.com.au or http://www.computercraft.info/forums2/ with suggestions/fixes/bugs
- local scriptName = "buttonmanip"
- fileDetail = fileDetail or {}
- fileDetail[scriptName] = {["version"] = 0.1, ["pastebin"] = "qtD3jeMK"}
- local tArgs = {...}
- if tArgs[1] == "update" then
- print("UPDATING") shell.run("pastebin get "..fileDetail[scriptName].pastebin.." "..scriptName.."_update")
- if fs.exists(scriptName.."_update") then fs.remove(shell.getRunningProgram()) fs.copy(scriptName.."_update", shell.getRunningProgram()) fs.remove(scriptName.."_update") print("UPDATE SUCCESS") else print("UPDATE FAILED") end
- end
- -----------------------------------------------------------------------------------------------------------
- -- Variables --
- -----------------------------------------------------------------------------------------------------------
- buttonList = {}
- local functionNum = "0"
- -----------------------------------------------------------------------------------------------------------
- -- API Functions --
- -----------------------------------------------------------------------------------------------------------
- -- buttonmanip.add(functionNum, <window>, <name>, <displayName>, <textColor>, <BackgroundColor>, <number>, <number>, <function>, paramArg) -- [1] returns function ran correctly [2] returns nil
- --
- function add(param_functionNum, paramWindow, paramName, paramText, paramTColor, paramBColor, paramX, paramY, paramFunc, paramArg)
- local result, functionNum = {false}, param_functionNum.."/007"
- if booleanmanip.massCheck(functionNum, "and", {booleanmanip.variableCheck(functionNum, {"string"}, {paramWindow, paramName, paramText})[2], booleanmanip.variableCheck(functionNum, {"number"}, {paramX, paramY})[2], booleanmanip.check(functionNum, paramFunc)[1], booleanmanip.check(functionNum, paramArg)[1]})[2] then
- buttonList[paramWindow] = booleanmanip.quickChoice(functionNum, booleanmanip.check(functionNum, buttonList[paramWindow])[1], buttonList[paramWindow], {})[2]
- result, buttonList[paramWindow][paramName] = true, {["text"] = paramText, ["textColor"] = paramTColor, ["BackGroundColor"] = paramBColor, ["x"] = paramX, ["y"] = paramY, ["func"] = paramFunc, ["arg"] = paramArg}
- else
- logger.logger(functionNum, {"Function Error, Expected: buttonAdd(functionNum, <window>, <name>, <displayName>, <textColor>, <BackgroundColor>, <number>, <number>, <function>, paramArg)"}, 2, " ")
- end
- return result
- end
- -- buttonmanip.Remove(functionNum, <window>, <name>) -- [1] returns function ran correctly [2] returns nil
- --
- function Remove(param_functionNum, paramWindow, paramName)
- local result, functionNum = {false}, param_functionNum.."/007"
- if booleanmanip.variableCheck(functionNum, {"string"}, {paramWindow, paramName})[2] then
- result, buttonList[paramWindow][paramName] = true, nil
- else
- logger.logger(functionNum, {"Function Error, Expected: buttonRemove(functionNum, <window>, <name>)"}, 2, " ")
- end
- end
- function generate(param_functionNum, paramWindow, paramName)
- local result, functionNum = {false}, param_functionNum.."/007"
- if booleanmanip.check(functionNum, buttonList[paramWindow][paramName])[1] then
- tempList = buttonList[paramWindow][paramName]
- term.setCursorPos(tempList["x"], tempList["y"])
- term.setTextColor(tempList["textColor"])
- term.setBackgroundColor(tempList["BackGroundColor"])
- term.write(tempList["text"])
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1, 1)
- result[1] = true
- else
- logger.logger(functionNum, {"Function Error, Expected: buttonmanip.generate(functionNum, <window>, <name>)"}, 1, " ")
- end
- return result
- end
- function generateWindow(param_functionNum, paramWindow)
- local result, functionNum = {false}, param_functionNum.."/007"
- if booleanmanip.check(functionNum, buttonList[paramWindow])[1] then
- result[1] = true
- for a,b in pairs(buttonList[paramWindow]) do
- result[1] = booleanmanip.quickChoice(functionNum, generate(functionNum, paramWindow, a)[1], result[1], false)[2]
- end
- else
- logger.logger(functionNum, {"Function Error, Expected: buttonmanip.generate(functionNum, <window>, <name>)"}, 1, " ")
- end
- return result
- end
- -- buttonmanip.scan(functionNum, <window>, <x>, <y>) -- [1] returns function ran correctly [2] returns nil
- --
- function scan(param_functionNum, param_window, param_x, param_y)
- local result, functionNum = {false}, param_functionNum.."/007"
- if booleanmanip.variableCheck(functionNum, {"string"}, {param_window})[2] and booleanmanip.variableCheck(functionNum, {"number"}, {param_x, param_y})[2] then
- if booleanmanip.check(functionNum, buttonList[param_window])[1] then
- for a,b in pairs(buttonList[param_window]) do
- if booleanmanip.tolerance(functionNum, "relative", buttonList[param_window][a]["x"], param_x, string.len(buttonList[param_window][a]["text"]), 0)[2] and param_y == buttonList[param_window][a]["y"] then
- buttonList[param_window][a]["func"](functionNum, buttonList[param_window][a]["arg"])
- result = {true}
- end
- end
- else
- logger.logger(functionNum, {"Variable Error, Window doesn't exist"}, 1, " ")
- end
- else
- logger.logger(functionNum, {"Function Error, Expected: buttonmanip.generate(functionNum, <window>, <name>)"}, 1, " ")
- end
- return result
- end
- -----------------------------------------------------------------------------------------------------------
- -- Old Functions --
- -------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment