diff options
author | Aki <nthirtyone@gmail.com> | 2016-08-24 01:57:39 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2016-08-24 01:57:39 +0200 |
commit | a1d3d14781565f226e7795e4d426c28614baab88 (patch) | |
tree | 3a3d3824a28ca2666c244593a247f1bfee649de6 | |
parent | db941f6b371774b7b9f5de0e8db86a9b4f5a1d7b (diff) | |
download | roflnauts-a1d3d14781565f226e7795e4d426c28614baab88.zip roflnauts-a1d3d14781565f226e7795e4d426c28614baab88.tar.gz roflnauts-a1d3d14781565f226e7795e4d426c28614baab88.tar.bz2 |
First steps in new selector
-rw-r--r-- | selector.lua | 147 |
1 files changed, 55 insertions, 92 deletions
diff --git a/selector.lua b/selector.lua index afdfed7..9e2ad23 100644 --- a/selector.lua +++ b/selector.lua @@ -1,112 +1,75 @@ --- `Selector` --- Used in menu; selecting nauts? +-- `Selector` (Element) +-- Used in Menu for selecting various things from list. Works for each Controller set or globally. +--[[ +How to use `Selector` in `Menu` config file? +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 +]] + Selector = { - naut = 1, + parent, x = 0, y = 0, - parent = nil, - controlset = nil, - locked = false + focused = false, + global = false, + list, + sets, + locks, + selections } -function Selector:new(menu) + +-- Constructor +function Selector:new(parent) local o = {} setmetatable(o, self) self.__index = self - o.parent = menu + o.parent = parent + o.list = {} + o.sets = {} + o.locks = {} + o.selections = {} return o end + -- Position -function Selector:setPosition(x,y) - self.x = x - self.y = y -end function Selector:getPosition() return self.x, self.y end --- Control Sets -function Selector:assignControlSet(set) - self.controlset = set - self.naut = 2 -end -function Selector:getControlSet() - if self.controlset ~= nil then - return self.controlset - end +function Selector:setPosition(x,y) + self.x, self.y = x, y + return self end --- States -function Selector:getState() - if self:getControlSet() ~= nil then - if self.locked then - return 2 -- has controls and locked - end - return 1 -- has controls but not locked + +-- General setter for Menu configuration files +function Selector:set(name, func) + if type(name) == "string" and func ~= nil then + self[name] = func end - return 0 -- no controls and not locked -end -function Selector:clear() - self.controlset = nil - self.naut = 1 - self.locked = false -end -function Selector:getSelectionName() - return self.parent.nauts[self.naut] + return self end +-- Selecting functions +function Selector:getSelection(n) end +function Selector:next(n) end +function Selector:previous(n) end + +-- Menu callbacks +function Selector:focus() -- Called when Element gains focus + self.focused = true + return true +end +function Selector:blur() -- Called when Element loses focus + self.focused = false +end + -- LÖVE2D callbacks -function Selector:draw() - -- portrait, sprite - local name = self.parent.nauts[self.naut] - local p = self.parent.portrait_sheet[name] - local sprite = self.parent.portrait_sprite - -- scale, position - local scale = self.parent.scale - local x,y = self:getPosition() - -- arrows - local arrowl = self.parent.portrait_sheet.arrow_left - local arrowr = self.parent.portrait_sheet.arrow_right - if not self.locked then - love.graphics.draw(sprite, p.normal, x*scale, y*scale, 0, scale, scale) - if self.controlset ~= nil then - love.graphics.draw(sprite, arrowl, (x-2)* scale, (y+13)*scale, 0, scale, scale) - love.graphics.draw(sprite, arrowr, (x+30)*scale, (y+13)*scale, 0, scale, scale) - end - else - love.graphics.draw(sprite, p.active, x*scale, y*scale, 0, scale, scale) - end - if self.naut ~= 1 then - love.graphics.printf(string.upper(name), (x-8)*scale, (y+33)*scale, 48, "center", 0, scale, scale) - end -end +function Selector:draw(scale) end +function Selector:update(dt) end -- Controller callbacks -function Selector:controlpressed(set, action, key) - -- locals - local n = #self.parent.nauts - if set == self:getControlSet() then - if action == "left" and not self.locked then - if self.naut == 2 or self.naut == 1 then - self.naut = n - else - self.naut = self.naut - 1 - end - elseif action == "right" and not self.locked then - if self.naut == n then - self.naut = 2 - else - self.naut = self.naut + 1 - end - elseif action == "attack" then - if self.naut ~= 1 then - self.locked = true - end - elseif action == "jump" then - if self.locked == true then - self.locked = false - else - self:clear() - end - end - end -end -function Selector:controlreleased(set, action, key) -end
\ No newline at end of file +function Selector:controlpressed(set, action, key) end +function Selector:controlreleased(set, action, key) end + +return Selector
\ No newline at end of file |