diff options
Diffstat (limited to 'menu.lua')
-rw-r--r-- | menu.lua | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -1,8 +1,8 @@ -- `Menu` (Scene) -- It creates single screen of a menu +-- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope. require "selector" -require "button" -- Here it begins Menu = { @@ -23,14 +23,9 @@ function Menu:delete() end -- Load menu from file function Menu:load(name) local name = "config/" .. (name or "menumain") .. ".lua" - print(name) local menu = love.filesystem.load(name) self.elements = menu() -end - --- Creators -function Menu:newButton() - local button = Button:new() + self.elements[self.active]:focus() end -- LÖVE2D callbacks @@ -38,27 +33,29 @@ function Menu:update(dt) end function Menu:draw() local scale = self.scale love.graphics.setFont(Font) - for i,v in ipairs(self.elements) do - if self.active == i then - love.graphics.setColor(255, 128, 0, 255) - else - love.graphics.setColor(255, 255, 255, 255) - end - love.graphics.print(v, 10, (80-5*#self.elements+10*i)*scale, 0, scale, scale) + for _,element in pairs(self.elements) do + element:draw(scale) end end -- Controller callbacks function Menu:controlpressed(set, action, key) if action == "down" then + self.elements[self.active]:blur() self.active = (self.active%#self.elements)+1 + self.elements[self.active]:focus() end if action == "up" then + self.elements[self.active]:blur() if self.active == 1 then self.active = #self.elements else self.active = self.active - 1 end + self.elements[self.active]:focus() + end + for _,element in pairs(self.elements) do + element:controlpressed(set, action, key) end end function Menu:controlreleased(set, action, key) end
\ No newline at end of file |