summaryrefslogtreecommitdiffhomepage
path: root/button.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-08-22 17:10:20 +0200
committerAki <nthirtyone@gmail.com>2016-08-22 17:10:20 +0200
commite57a5b0b77c1ba3a2f05371c551d0e61fc9ce709 (patch)
tree877e630b0afd749d5d75da830d3339dd751abaca /button.lua
parent6e9aa28e70ec842db643a06609454fff54b5d86a (diff)
downloadroflnauts-e57a5b0b77c1ba3a2f05371c551d0e61fc9ce709.zip
roflnauts-e57a5b0b77c1ba3a2f05371c551d0e61fc9ce709.tar.gz
roflnauts-e57a5b0b77c1ba3a2f05371c551d0e61fc9ce709.tar.bz2
Graphics, animation, general improvements
Diffstat (limited to 'button.lua')
-rw-r--r--button.lua34
1 files changed, 24 insertions, 10 deletions
diff --git a/button.lua b/button.lua
index 925baf3..fc4ca8b 100644
--- a/button.lua
+++ b/button.lua
@@ -2,26 +2,37 @@
-- Button used in `Menu`
Button = {
- text = "button",
+ text = "",
focused = false,
x = 0,
- y = 0
+ y = 0,
+ sprite,
+ quad = love.graphics.newQuad(0, 0, 58,15, 68,15),
+ arrow_l = love.graphics.newQuad(58, 0, 5, 5, 68,15),
+ arrow_r = love.graphics.newQuad(63, 0, 5, 5, 68,15),
+ delay = 0,
+ parent
}
-function Button:new(text)
+function Button:new(parent)
local o = {}
setmetatable(o, self)
self.__index = self
- o.text = text or self.text
+ o.parent = parent
+ self.sprite = love.graphics.newImage("assets/menu.png")
return o
end
+function Button:setText(text)
+ self.text = text or ""
+ return self
+end
function Button:setPosition(x, y)
self.x = x or 0
self.y = y or 0
return self
end
function Button:getPosition() return self.x,self.y end
-function Button:focus()
+function Button:focus(next)
self.focused = true
end
function Button:blur()
@@ -36,14 +47,17 @@ function Button:set(name, func)
end
function Button:draw(scale)
local x,y = self:getPosition()
+ love.graphics.setColor(255, 255, 255, 255)
+ love.graphics.draw(self.sprite, self.quad, x*scale, y*scale, 0, scale, scale)
if self.focused then
- love.graphics.setColor(255, 128, 0, 255)
- else
- love.graphics.setColor(255, 255, 255, 255)
+ love.graphics.draw(self.sprite, self.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale)
+ love.graphics.draw(self.sprite, self.arrow_r, (x-1-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale)
end
- love.graphics.print(self.text, x*scale, y*scale, 0, scale, scale)
+ love.graphics.printf(string.upper(self.text), (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale)
+end
+function Button:update(dt)
+ self.delay = (self.delay + dt)%2
end
-function Button:update(dt) end
function Button:controlpressed(set, action, key)
if action == "attack" and self.focused then
self:active()