summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-08-24 04:57:23 +0200
committerAki <nthirtyone@gmail.com>2016-08-24 04:57:23 +0200
commit9fab96edd18260aaa2586901e7d28dfc387f17d2 (patch)
tree6deeeb3708e6220077ea7f5b2982a6714b29a56f
parente22d7b380513aec4d83dc06c59dfd461b5d3a8b2 (diff)
downloadroflnauts-9fab96edd18260aaa2586901e7d28dfc387f17d2.zip
roflnauts-9fab96edd18260aaa2586901e7d28dfc387f17d2.tar.gz
roflnauts-9fab96edd18260aaa2586901e7d28dfc387f17d2.tar.bz2
Testing: next/prev
-rw-r--r--selector.lua43
1 files 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