Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('ui')
- --Pattern:
- -- add(listUI, component name, X, Y, Text, FG, BG, button action, pages, output)
- -- draw(listUI, pages, FG, BG)
- -- mouse(listUI, x, y, pages)
- function loadUI()
- -- Create a list and adds components to it using the above pattern
- myUI = {}
- ui.reset(myUI) -- give myUI the right format
- ui.addUI(myUI, 'stop_button', 1,19, '[EXIT]', colors.black, -1, 'stop', {'all'}, {term})
- ui.addUI(myUI, 'p2', 49,19, '[>]', colors.black, -1, '2', {'1'}, {term})
- ui.addUI(myUI, 'p1', 46,19, '[<]', colors.black, -1, '1', {'2'}, {term})
- ui.addUI(myUI, 'p2_dis', myUI.ui.p1[1],myUI.ui.p1[2], '[<]', colors.lightGray, -1, 'nil', {'1'}, {term})
- ui.addUI(myUI, 'p1_dis', myUI.ui.p2[1],myUI.ui.p2[2], '[>]', colors.lightGray, -1, 'nil', {'2'}, {term})
- ui.addUI(myUI, 'page1', 5,4, 'This displays on page one', colors.blue, -1, 'nil', {'1'}, {term})
- ui.addUI(myUI, 'page2', 5,6, 'This displays on page two', colors.red, -1, 'nil', {'2'}, {term})
- ui.addShape(myUI, 'outline1', 'outline', 1, 2, 51, 18, 0, colors.lime, {'all'}, {term})
- ui.addShape(myUI, 'outline2', 'outline', 3, 4, 49, 13, 0, colors.purple, {'1'}, {term})
- ui.addShape(myUI, 'outline3', 'outline', 3, 6, 49, 16, 0, colors.green, {'2'}, {term})
- ui.addUI(myUI, 'mod1', 7,9, 'Use mod 1', colors.orange, colors.gray, 'mod1', {'1'}, {term})
- ui.addShape(myUI, 'modButton', 'box', 6, 8, 16, 10, 0, colors.gray, {'1'}, {term})
- ui.addUI(myUI, 'default', 7,11, 'Use default', colors.orange, -1, 'default', {'2'}, {term})
- end
- loadUI() -- Load the UI(s)
- pages = {'all','1'}
- loop = true
- action = 'none'
- pos = '0' -- Loads the variables
- while loop do
- -- ## Graphics part ## --
- ui.color(term, colors.white, colors.yellow) -- Sets the colors
- term.clear() -- Clears the screen
- ui.drawSingle(1, 1, 'A: '..action..' P: '..pos, colors.white, colors.yellow, {term}) -- Draws a single comonent that is only for display
- ui.drawSingle(2,2, 'Page '..pages[2], colors.black, colors.lime, {term})
- ui.draw(myUI, pages, colors.white, colors.yellow) -- Uses the list myUI to draw it
- -- ## Processing part ## --
- event, button, xx, yy = os.pullEvent('mouse_click') --Catches mouse click events
- action, key, pos = ui.mouse(myUI, xx, yy, pages, {term}) -- Finds out an action, key (in myUI) and pos on clicked text
- if action == nil then
- action = 'none'
- if not(pos) then
- pos = '0'
- end
- elseif action == 'stop' then
- break
- elseif action == 'mod1' then
- ui.editUI(myUI, 'stop_button', 'bg', colors.red)
- elseif action == 'default' then
- ui.editUI(myUI, 'stop_button', 'bg', -1)
- elseif ui.inTable({'1','2'},action) > 0 then
- pages[2] = action
- else error('something happened')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement