1
0
mirror of https://github.com/AR2000AR/openComputers_codes.git synced 2025-09-08 22:51:14 +02:00

[yawl] reworked reset time logic

This commit is contained in:
2023-08-11 17:05:06 +02:00
parent 6194e66e8e
commit e1d16c8ba9

View File

@@ -8,16 +8,15 @@ local Button = require('libClass2')(Rectangle)
function Button:defaultCallback(_, eventName, uuid, x, y, button, playerName)
if (not (eventName == "touch")) then return end
if self:shouldReset() then self:state(true) else self:state(not self:state()) end
self:state(not self:state())
end
function Button:draw()
if (not self:visible()) then return end
local isActive = self:state()
if isActive and self:shouldReset() and computer.uptime() - self._pressed > self:resetTime() then
if self:resetTime() > 0 and self:state() and (computer.uptime() - self._pressed) > self:resetTime() then
self:state(false)
end
local newBG = isActive and (self:foregroundColor() or 0xffffff - self:backgroundColor()) or self:backgroundColor()
local newBG = self:state() and (self:foregroundColor() or 0xffffff - self:backgroundColor()) or self:backgroundColor()
local oldBG = gpu.setBackground(newBG)
gpu.fill(self:absX(), self:absY(), self:width(), self:height(), " ")
gpu.setBackground(oldBG)
@@ -49,10 +48,4 @@ function Button:resetTime(time)
return oldValue
end
---Should the wiget state retrun to false after a fixed time
---@return boolean
function Button:shouldReset()
return self._resettime > 0
end
return Button