diff options
-rw-r--r-- | config/menumain.lua | 12 | ||||
-rw-r--r-- | config/menustart.lua | 5 | ||||
-rw-r--r-- | element.lua | 46 |
3 files changed, 62 insertions, 1 deletions
diff --git a/config/menumain.lua b/config/menumain.lua index 629284c..24f66ef 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -2,6 +2,7 @@ local menu = ... local button = require "button" local header = require "header" +local element = require "element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local button_x = width/2-29 @@ -31,6 +32,17 @@ return { :setPosition(button_x, 144) :set("active", love.event.quit) , + element:new(menu) + :setPosition(width/2, 15) + :set("sprite", love.graphics.newImage("assets/two.png")) + :set("draw", function (self, scale) + local x,y = self:getPosition() + love.graphics.setColor(255, 255, 255, 255) + love.graphics.setFont(Bold) + love.graphics.print("1", (x-17)*scale, y*scale, 0, scale*2, scale*2, 12) + love.graphics.print("1", (x+13)*scale, y*scale, 0, scale*2, scale*2, 12) + end) + , header:new(menu) :setText("Roflnauts") :setPosition(width/2,40) diff --git a/config/menustart.lua b/config/menustart.lua index 2472df5..1830f0d 100644 --- a/config/menustart.lua +++ b/config/menustart.lua @@ -1,11 +1,14 @@ local menu = ... local button = require "button" +local selector = require "selector" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() return { button:new(menu) :setText("Go back") - :setPosition(10,40) + :setPosition(10,height-25) :set("active", function (self) self.parent:load("menumain") end) diff --git a/element.lua b/element.lua new file mode 100644 index 0000000..bc8bc6d --- /dev/null +++ b/element.lua @@ -0,0 +1,46 @@ +-- `Element` +-- Empty element for `Menu` creation. Can be anything. +Element = { + x = 0, + y = 0, + parent +} +function Element:new(parent) + local o = {} + setmetatable(o, self) + self.__index = self + o.parent = parent + return o +end +function Element:delete() end -- deletes Element +function Element:getPosition() return self.x, self.y end -- gives x,y of Element +function Element:setPosition(x,y) + self.x, self.y = x, y + return self +end +function Element:set(name, func) + if type(name) == "string" and func ~= nil then + self[name] = func + end + return self +end + +-- Menu callbacks +function Header:focus(next) -- Called when Element gains focus + if next and self.parent then + self.parent:next() + else + self.parent:previous() + end +end +function Element:blur() end -- Called when Element loses focus + +-- LÖVE2D callbacks +function Element:draw(scale) end +function Element:update(dt) end + +-- Controller callbacks +function Element:controlpressed(set, action, key) end +function Element:controlreleased(set, action, key) end + +return Element
\ No newline at end of file |