From e22d7b380513aec4d83dc06c59dfd461b5d3a8b2 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 04:12:07 +0200 Subject: locks, selections, init --- selector.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/selector.lua b/selector.lua index 9e2ad23..96113df 100644 --- a/selector.lua +++ b/selector.lua @@ -6,6 +6,7 @@ selector:new(menu) :setPosition(x, y) :set("list", require "file_with_list") :set("global", true/false) -- true: single selector; false: selector for each controller set present + :init() ]] Selector = { @@ -26,10 +27,6 @@ function Selector:new(parent) setmetatable(o, self) self.__index = self o.parent = parent - o.list = {} - o.sets = {} - o.locks = {} - o.selections = {} return o end @@ -50,11 +47,55 @@ function Selector:set(name, func) return self end --- Selecting functions -function Selector:getSelection(n) end +-- Initialize Selector with current settings. +function Selector:init() + -- Make sure that there is list present + if self.list == nil then + self.list = {} + end + -- Initialize global Selector + if self.global then + self.locks = {false} + self.selections = {1} + -- Initialize Selector for Controllers + else + self.sets = Controller.getSets() + self.locks = {} + self.selections = {} + for i=1,#self.sets do + self.locks[i] = false + self.selections[i] = 1 + end + end +end + +-- Cycle through list on given number function Selector:next(n) end function Selector:previous(n) end +-- Get number associated with a given set +function Selector:checkNumber(set) + if self.global then return 1 end -- For global Selector + for n,check in pairs(self.sets) do + if check == set then return n end + end +end + +-- Check if given number is locked +function Selector:isLocked(n) + return self.locks[n] +end + +-- Get value of selection of given number +function Selector:getSelectionValue(n) + return self.selections[n] +end + +-- Get value from list by selection +function Selector:getListValue(i) + return self.list[i] +end + -- Menu callbacks function Selector:focus() -- Called when Element gains focus self.focused = true -- cgit v1.1