From 96b4407ae6410affd0db1e6d6d657d4f65d32235 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 28 Aug 2016 20:41:48 +0200 Subject: No blinking; buttons enabled/disabled --- button.lua | 17 +++++------------ config/menuhost.lua | 3 +++ config/menumain.lua | 12 ++++++------ config/menuselect.lua | 8 ++++++-- selector.lua | 2 ++ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/button.lua b/button.lua index 4b397cf..c5681b2 100644 --- a/button.lua +++ b/button.lua @@ -9,8 +9,7 @@ Button = { sprite, quads, delay = 2, - blinker = 1, - parent + parent, } function Button:new(parent) @@ -39,9 +38,7 @@ function Button:blur() self.focused = false end function Button:active() end -function Button:blink() - self.blinker = 0 -end +function Button:isEnabled() return true end function Button:set(name, func) if type(name) == "string" and type(func) == "function" then self[name] = func @@ -50,13 +47,12 @@ function Button:set(name, func) end function Button:draw(scale) local x,y = self:getPosition() - local blinker = math.floor(self.blinker*4) local quad = self.quads local sprite = self.sprite - if blinker%2 == 0 then + if self:isEnabled() then love.graphics.setColor(255, 255, 255, 255) else - love.graphics.setColor(255, 100, 100, 255) + love.graphics.setColor(140, 140, 140, 255) end love.graphics.draw(sprite, quad.button.normal, x*scale, y*scale, 0, scale, scale) if self.focused then @@ -71,12 +67,9 @@ function Button:update(dt) if self.delay > Button.delay then -- Button.delay is initial self.delay = self.delay - Button.delay end - if self.blinker < Button.blinker then -- Button.blink is initial - self.blinker = self.blinker + dt - end end function Button:controlpressed(set, action, key) - if action == "attack" and self.focused then + if action == "attack" and self.focused and self:isEnabled() then self:active() end end diff --git a/config/menuhost.lua b/config/menuhost.lua index 6e52482..487b75f 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -24,6 +24,9 @@ return { button:new(menu) :setText("Select") :setPosition(bx,101) + :set("isEnabled", function () + return map_selector:isLocked() + end) :set("active", function (self) MAP = map_selector:getFullSelection(true)[1][1] self.parent:load("menuselect") diff --git a/config/menumain.lua b/config/menumain.lua index 2ca2c59..e1bd89f 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -18,22 +18,22 @@ return { button:new(menu) :setText("Join") :setPosition(bx, 96) - :set("active", function (self) - self:blink() + :set("isEnabled", function (self) + return false end) , button:new(menu) :setText("Settings") :setPosition(bx, 112) - :set("active", function (self) - self:blink() + :set("isEnabled", function (self) + return false end) , button:new(menu) :setText("Credits") :setPosition(bx, 128) - :set("active", function (self) - self:blink() + :set("isEnabled", function (self) + return false end) , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index 31cf02e..c79396c 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -24,12 +24,16 @@ return { start_button :setText("Force start") :setPosition(bx,134) + :set("isEnabled", function () + if #naut_selector:getFullSelection(false) > 1 then + return true + end + return false + end) :set("active", function (self) local nauts = naut_selector:getFullSelection(false) if #nauts > 1 then changeScene(World:new(MAP, nauts)) - else - self:blink() end end) , diff --git a/selector.lua b/selector.lua index f382bbb..75c0190 100644 --- a/selector.lua +++ b/selector.lua @@ -136,11 +136,13 @@ end -- Check if given number is locked function Selector:isLocked(n) + local n = n or 1 return self.locks[n] end -- Get value of selection of given number function Selector:getSelection(n) + local n = n or 1 return self.selections[n] end -- cgit v1.1