Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bedrockPath='Build/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end
- local receivingComputer = 475
- local currentSelection
- rednet.open('back')
- local program
- function init()
- program = Bedrock:Initialise()
- program:Run(function()
- program:LoadView('main')
- -- Load Button (loadBtn)
- program:GetObject('loadBtn').OnClick = function(self, event, side, x, y)
- -- Request file from other computer
- program:StartTimer(updateResidentList, 0.1)
- end
- -- Add Button (addBtn)
- program:GetObject('addBtn').OnClick = function(self, event, side, x, y)
- -- Request file from other computer
- addNew()
- end
- -- Save Button (saveBtn)
- program:GetObject('saveBtn').OnClick = function(self, event, side, x, y)
- -- Send file to pc.
- local newResidents = ''
- for key, item in ipairs(program:GetObject('residentList').Items) do
- newResidents = newResidents .. item .. '\n'
- end
- rednet.send(receivingComputer, newResidents, 'resident_controller')
- end
- -- Delete Button (deleteBtn)
- program:GetObject('deleteBtn').OnClick = function(self, event, side, x, y)
- -- Remove from Items, tried to remvoe the key, only works with new table element.
- if ( currentSelection ) then
- program:DisplayAlertWindow('Are you sure?', 'Delete "'..currentSelection..'"?', {'No', 'Yes'}, function(value)
- if ( value == 'Yes' ) then
- local newResidents = {}
- for key, item in ipairs(program:GetObject('residentList').Items) do
- if ( item ~= currentSelection ) then
- table.insert(newResidents, item)
- end
- end
- program:GetObject('residentList').Items = newResidents
- end
- end)
- end
- end
- program:GetObject('residentList').OnSelect = function(_, item)
- currentSelection = item
- end
- end)
- end
- function addNew()
- program:AddObject({
- Name="add_window",
- X=3,
- Y="30%",
- Width=22,
- ShadowColour = "transparent",
- Height=3,
- Type="Window",
- Title="Add New",
- Children={
- {
- X=1,
- Y=2,
- Width=22,
- BackgroundColour="white",
- Placeholder="Name Here",
- PlaceholderTextColour="grey",
- Height=1,
- Name="add_editbox",
- Type="TextBox"
- },
- {
- X=17,
- Y=3,
- Width=6,
- BackgroundColour="green",
- Height=1,
- Text="Add",
- Name="add_btn",
- Type="Button"
- }
- }
- })
- program:GetObject('add_btn').OnClick = function(self, event, side, x, y)
- -- Request file from other computer
- local newResident = program:GetObject('add_editbox').Text
- local newResidents = {}
- for key, item in ipairs(program:GetObject('residentList').Items) do
- table.insert(newResidents, item)
- end
- table.insert(newResidents, newResident)
- program:GetObject('residentList').Items = newResidents
- program:GetObject('add_window'):Close()
- end
- end
- function updateResidentList()
- rednet.send(receivingComputer, 'rc_load', 'resident_controller')
- -- Wait for reply
- local senderId, message, protocol = rednet.receive('resident_controller', 1)
- if ( senderId and senderId == receivingComputer ) then
- local residents = split(message, '\n')
- program:GetObject('residentList').Items = residents
- elseif ( not senderId ) then
- program:DisplayAlertWindow('No Connection', ' Not in range or offline!', {'Retry', 'Later'}, function(value)
- if ( value == 'Retry' ) then
- program:StartTimer(updateResidentList, 0.1)
- end
- end)
- end
- end
- -- Utility Functions
- function split(str,sep)
- local sep, fields = sep or ":", {}
- local pattern = string.format("([^%s]+)", sep)
- str:gsub(pattern, function(c) fields[#fields+1] = c end)
- return fields
- end
- -- Start Init Function
- init()
Add Comment
Please, Sign In to add comment