So I was working on a project and had a need for a basic cooldown timer. After a bit of browsing/searching around I didn't find anything that did everything I needed, but I did find the following POST. So I spent a bit of time rewriting it to use Geyser. If you reuse a name, it will reuse the gauge associated with it, giving it the new constructor information, adding it to the proper container (or removing it from all containers, if no container is passed), time, etc. This means if you recall the same timer with the same arguments, it will essentially reset even if it's not finished running from the first time. It also means if you give it different arguments (such as a new position or size) then it will use these when it resets.
Big thanks to Lin of Aetolia, most of the core logic to the algorithm really didn't get changed. I just gussied it up a bit.
EDIT: There is now a video demo at http://www.youtube.com/watch?v=NlL0H_SjnPs
Usage:
demonnic.anitimer:new(name, constructor, time, container, showTime, timerCaption, css, cssback)
name: any name you wish to give the timer in string format
constructor: The same constructor you would pass to Geyser.Gauge:new(). This is where you specify your coordinates, height, width, etc.
time: How long in seconds you want the cooldown to run. Accepts decimal values
container: Optional argument. Give the timer a Geyser container to bind to. If you don't wish to bind to a container, but do wish to set up a stylesheet or turn off the display of the timeleft, then pass the empty string for this argument.
showTime: Optional argument, except if you want to pass further arguments. I may try to restructure this soon. This determines whether or not the time remaining is shown on the timer. Defaults to true if you leave it empty
timerCaption: Optional argument, except if you want to pass further arguments. This provides a way to give a caption to the timer, so that you can label it with something other than the time
css: Optional argument. The stylesheet to apply to the front portion of the gauge.
cssback: Optional argument. The stylesheet to apply to the back portion of the gauge.
Here are the contents of a sort of example alias to show some different timers, with and without css and container binding. For my own testing I just put it in an alias with pattern ^animateme$ . The gauges themselves aren't fancy, but that's because I slapped thew alias together in a few seconds. Using CSS you could do some pretty wicked things with these.Usage
demonnic.anitimer:stop(name)
name: the name of the timer you want to remove/stop
CHANGELOG
2.0 - added :stop(name) function. Also, when a timer expires or is stopped it will stop the stop watch. Added argument for whether to display the time on the timer or not.
2.1 - Added option to provide a caption for the timer, such that the text appears after the time (if showTime is true) or just as the text on the gauge (if showTime is false)