Page 1 of 1

GUI, countdown with progress bar

Posted: Fri Feb 19, 2021 9:34 pm
by darkfrei
Hi!

I've made small example for timer with countdown and GUI.

Re: GUI, countdown with progress bar

Posted: Fri Feb 19, 2021 10:54 pm
by Xugro
Nice design :)

I found it a bit confusing that the "10" timer starts at "9" and stops after "0". This happens because you round down. If you round half away from from zero (commercial rounding) then the timer feels better:

Code: Select all

line.button.text = math.floor (time+0.5) .. ' s'
And I would extract a function to create "lines". This removes a lot of duplicated code and makes love.load() much smaller:

Code: Select all

function create_line(y, time)
	return { -- line
			area = get_area{x=10, y=y, h=40, sw=10},
			button =
				{
					area=get_area{x=10, y=y, h=40, w=200, s=2},
					text="timer "..time.." s",
					default_text="timer "..time.." s",
					progress = 0
				},
			result = 
				{
					area=get_area{x=210, y=y, h=40, sw=10, s=2},
					text=0,
				},
			start = 0,
			enabled = false,
			timer = time -- seconds
		}
end
I was especially surprised by your empty love.update() function. But after I found your calculations with love.timer it was pretty easy to understand how you "update" the timers.

Here are the changes I talked about:
countdown-timer-xugro.love
(1.48 KiB) Downloaded 187 times

Re: GUI, countdown with progress bar

Posted: Sat Feb 20, 2021 10:18 am
by darkfrei
Thanks Xurgo!
You are right, I have this feeling too: the 0 seconds is shown really too long. After multiple showing was ok, but at start I was some confused.
Maybe it must be ceil(time), the same as the microwave :)

It wasn't in function for better understanding.

I want to use the timer such way, I hope that the timer can work if this program will be closed, like by all mobile games.

Re: GUI, countdown with progress bar

Posted: Sun Feb 21, 2021 6:08 pm
by darkfrei
Now it works! You can start all timers, close the program, but the progress will be continued!

Special functions:

Code: Select all

function load_table(name)
	local chunk, errormsg = love.filesystem.load( name..'.lua' )
	if not (errormsg) then
		return chunk()
	else
		print('errormsg: '..errormsg)
	end
end

Code: Select all

function savetable(tabl, name)
	love.filesystem.write(name..".lua", 'return '.. serialize(tabl))
end

Code: Select all

serialize = function (tabl, indent)
	indent = indent and indent .. '	' or '	'
	local str = indent..'{'
	local bool = true
	for i, v in pairs (tabl) do
		local pr = (type(i)=="string") and i..'=' or ''
		if type (v) == "table" then
			str=str..string.char(10) -- new line before table
			str = str..pr..serialize(v, indent)..','..string.char(10)
			bool = true
		elseif type (v) == "string" then
			str = str..pr..'"'..tostring(v)..'"'..','
			bool = false
		else
			str = str..pr..tostring(v)..','
			bool = false
		end
	end
	if bool then
		str = str:sub(1, -3) -- remove last comma and char10
	else
		str = str:sub(1, -2) -- remove last comma
	end
	str=str..'}'
	return str
end

Re: GUI, countdown with progress bar

Posted: Mon Feb 22, 2021 9:26 pm
by darkfrei
Why the version 04 has this issue?

Re: GUI, countdown with progress bar

Posted: Sat Feb 27, 2021 10:45 am
by darkfrei
Updated version, with smooth timer and resizable.

Re: GUI, countdown with progress bar

Posted: Sat Feb 27, 2021 3:36 pm
by darkfrei
Why the version 06 is portrait on the PC, but landscape on the android?