Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ -- Либа для проги m_file.lua //Библиотека создающая список и стилизованный курсор для выбора//
- Файл либы должен возвращать таблицу с созданными функциями:
- local liba = {}
- function liba.menu()
- ...
- end
- function liba.test()
- ...
- end
- return liba
- --]]
- -- указание локальной переменной local тоже имеет значение
- local library = {}
- local component = require("component")
- local gpu = component.gpu
- local term = require("term")
- local w, h = gpu.getResolution()
- local event = require("event")
- function library.mprint (array, this, s1, s2, x, y)
- for i = 1, #array do
- term.setCursor(x, y)
- --Check if option selected
- if i == this then
- --Option selected
- io.write(s1)
- else
- --Option NOT selected
- io.write(s2)
- end
- --Print the string
- print(array[i])
- y = y + 1
- end
- end
- function library.CreateMenu(array, state1, state2, pos_x, pos_y)
- local select = 1
- local x, y = term.getCursor()
- while true do
- term.setCursor(x, y)
- library.mprint(array, select, state1, state2, pos_x, pos_y)
- local name, address, char, code, player = event.pull("key_down")
- --Enter
- if code == 28 then
- return select
- end
- if #array > 1 then
- --Arrow UP or W key
- if code == 200 or code == 17 then
- select = select - 1
- if select < 1 then
- select = #array
- end
- --Arrow Down or S key
- elseif code == 208 or code == 31 then
- select = select + 1
- if select > #array then select = 1 end
- end
- end
- end
- end
- return library
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement