From 9fab96edd18260aaa2586901e7d28dfc387f17d2 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 04:57:23 +0200 Subject: Testing: next/prev --- selector.lua | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/selector.lua b/selector.lua index 96113df..fb2decb 100644 --- a/selector.lua +++ b/selector.lua @@ -62,16 +62,35 @@ function Selector:init() self.sets = Controller.getSets() self.locks = {} self.selections = {} - for i=1,#self.sets do - self.locks[i] = false - self.selections[i] = 1 + for n=1,#self.sets do + self.locks[n] = false + self.selections[n] = 1 end end + return self end -- Cycle through list on given number -function Selector:next(n) end -function Selector:previous(n) end +function Selector:next(n) + local total = #self.list + local current = self.selections[n] + local locked = self:isLocked(n) + if not locked then + self.selections[n] = (current % total) + 1 + end +end +function Selector:previous(n) + local total = #self.list + local current = self.selections[n] + local locked = self:isLocked(n) + if not locked then + if current == 1 then + self.selections[n] = total + else + self.selections[n] = current - 1 + end + end +end -- Get number associated with a given set function Selector:checkNumber(set) @@ -87,7 +106,7 @@ function Selector:isLocked(n) end -- Get value of selection of given number -function Selector:getSelectionValue(n) +function Selector:getSelection(n) return self.selections[n] end @@ -106,11 +125,19 @@ function Selector:blur() -- Called when Element loses focus end -- LÖVE2D callbacks -function Selector:draw(scale) end +function Selector:draw(scale) + local x,y = self:getPosition() + local text = self:getListValue(self:getSelection(1)) + love.graphics.setFont(Font) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.printf(text, (x)*scale, (y)*scale, 54, "center", 0, scale, scale) +end function Selector:update(dt) end -- Controller callbacks -function Selector:controlpressed(set, action, key) end +function Selector:controlpressed(set, action, key) + self:next(1) +end function Selector:controlreleased(set, action, key) end return Selector \ No newline at end of file -- cgit v1.1