7508 posts
Location
Australia
Posted 11 January 2013 - 03:51 PM
Thread Closed in favour of merging to a single, easier to manage, thread and websiteSpoiler
Load Screen / Bar API
v2.0
After searching through the forums I was disappointed at the lack of a load screen API that was realtime and not just a fake sleep based screen. So I decided to make some… Here it is:
The load screen API provides an easy way to show your users in real time where your program is up to while loading… This API features the ability to render your logo in the middle of the screen AND event use it as the progress bar!
Now you can make multiple progress bars!
Whats new:
Spoiler
This API has had a full rewrite from ground up. Your load screen / bar are now objects. This means that each bar is in charge of its own progress.
What does this mean?
Well you can have multiple progress bars on the one screen*! Thats right, you can have for example an 'overall' progress and 'current operation' progress AND more*!
There are several new class functions as well as a few new functions for the objects themselves ( listed below in the 'Functions' section ).
Notable feature: Each object will only update WHEN REQUIRED and when required to update will send a custom event that ONLY they will respond to**.
* Up to 999
** Other event loops may pull this event, however no other progress bar object will, they only listen for their own
Functions:
Spoiler
tostring( loadObj )
Calling tostring on the load screen / bar object will return the apiIdentifier so that you can easily check if a passed variable is an object from this API
function getVersion()
Returns the version of the API
function getApiIdentifier()
Returns a string formatted as follows "Loading Bar API v<version> Object" ( recommended usage, to check against an object's tostring )
function getId()
Returns the id of the current loading bar object ( this is unique and is used internally when queueing and pulling events )
function getCurrentProgress()
Returns the current progress of the loading bar, minimum 0 maximum is the total events
function getFormattedProgress()
Returns the current progress as a string formatted as follows "<current>/<total>"
function init( mode, tLogo, count, width, y, loadColor, openingMsg, headMsg, footMsg )
Initialises the loading screen / bar with the values supplied, each mode is different with what values required ( see examples to see whats needed )
function setMessage( msg )
Changes the progress message that is displayed to the user without triggering progress
function removeMessage()
Removes the progress message that is displayed to the user without triggering progress, equivalent to
function dealloc()
Removes the current object and frees up memory allocation
function reset()
Resets the current progress count to zero ( and obviously the actual progress bar )
function forceStop()
Exits the render loop and allows your program to continue running ( suggested usage, when something goes wrong, such as a file doesn't exist that is needed and you want the load screen to stop )
function triggerUpdate( msg )
Triggers progress, incrementing the progress bar and displaying with the formula ( current_progress / total_required ) * bar_width
If a message is supplied it will change the message text. NOTE: If you do not want the message to change just call triggerUpdate()
function forceDraw()
This will force the load screen / bar to draw to the screen for 1 loop
function run( cleanup )
Runs the render loop ( note: this API uses a pullEvent loop, recommended method of calling is with parallels api so you can load your stuff, to exit loop see forceStop )
cleanup is an optional boolean parameter. if set to true the load object will dealloc once completed.
Loading Screen / Bar Object Modes:
Spoiler
load.STANDARD
This includes a load screen with the logo, all text and a progress bar ( NOTE: This will clear the screen )
load.BAR_ONLY
This draws only a progress bar to the screen ( NOTE: This will not clear the screen )
load.ASCII_BAR_ONLY
This draws only a progress bar to the screen on ASCII ( Suggested usage, non-advanced computers including CC 1.3 computers ) ( NOTE: This will not clear the screen )
load.LOGO_IS_LOAD
This draws a load screen with the logo and all the text. The logo is the progress bar and the supplied color ( see init ) will be drawn over the top of it.
load.LOGO_IS_OVERLAY
This draws a load screen with the logo and all the text. The logo is the progress bar and is initially greyed out, with the color representing progress.
load.ASCII
This includes a load screen with the logo, all text and a progress bar, all in ASCII ( NOTE: This will clear the screen )
For visual examples of all these look at the 'Screenshots' section
Example of Usage:
Spoiler
Generic Object/Class Functions
http://pastebin.com/XhVXdpHX
STANDARD mode example code:
http://pastebin.com/9WqxtPZP
BAR_ONLY mode example code:
http://pastebin.com/LcZJKxv4
ASCII_BAR_ONLY mode example code:
http://pastebin.com/6rBQDrqy
LOGO_IS_LOAD mode example code:
http://pastebin.com/msRYcMju
LOGO_IS_OVERLAY mode example code:
http://pastebin.com/0LiT8utH
ASCII mode example code:
http://pastebin.com/FgZK2t38
Multiple progress bar example code:
http://pastebin.com/80LZaVj0
and
http://pastebin.com/RF2rRazY Change Log
Spoiler
v2.0- New mode, bar only
- New mode, ascii bar only
- Your load screen / bar are now objects meaning you can now have more than one!
v1.1v1.0
Latest Version Download here
Or get it in-game with pastebin zeG34tu6 load
Version 1.1 Download here
Or get it in-game with pastebin 4iLhhffG load
3790 posts
Location
Lincoln, Nebraska
Posted 11 January 2013 - 05:31 PM
Wow….
I really like this! It doesn't use useless sleep methods, and you can set your own messages! I would give you +10 for this, but sadly, you only get one…
7508 posts
Location
Australia
Posted 11 January 2013 - 05:39 PM
Wow….
I really like this! It doesn't use useless sleep methods, and you can set your own messages! I would give you +10 for this, but sadly, you only get one…
yeh I originally had a sleep, but then I was like hey, why render the screen when I don't need to! then I remembered the os.queueEvent and I'm like "PERFECT!" …. haha why thank you :)/>
9 posts
Posted 11 January 2013 - 05:42 PM
I was working on this for my bar as well but…
you have me beat…I might as well stop now before i get too far.
screw it I'll still keep going anyway…
3790 posts
Location
Lincoln, Nebraska
Posted 11 January 2013 - 05:56 PM
I was working on this for my bar as well but…
you have me beat…I might as well stop now before i get too far.
screw it I'll still keep going anyway…
That's the spirit. Don't give up.
7508 posts
Location
Australia
Posted 11 January 2013 - 06:00 PM
I was working on this for my bar as well but…
you have me beat…I might as well stop now before i get too far.
screw it I'll still keep going anyway…
Good attitude… who knows maybe you will ad a feature that I don't have and make it more awesome…
EDIT: Feel free to read through my code as a learning experience of how I did it :)/>
Edited on 11 January 2013 - 05:01 PM
248 posts
Posted 11 January 2013 - 06:05 PM
What about a bar that's like a circle? Well, not a loading bar, since it's not a bar, but like the iPod's loadin circle. I can help if you want
7508 posts
Location
Australia
Posted 11 January 2013 - 06:07 PM
What about a bar that's like a circle? Well, not a loading bar, since it's not a bar, but like the iPod's loadin circle. I can help if you want
could do that ;)/> use some deg and rad calculations… could work…
currently I'm adding support for non-advanced computers…
7508 posts
Location
Australia
Posted 11 January 2013 - 07:18 PM
Update
v1.1
Added support for ComputerCraft 1.3
Added new ascii mode! See OP for details.
2088 posts
Location
South Africa
Posted 12 January 2013 - 03:15 AM
This is amazing :P/> Nice
7508 posts
Location
Australia
Posted 12 January 2013 - 03:17 AM
This is amazing :P/> Nice
Why thank you :)/>
59 posts
Posted 12 January 2013 - 03:21 AM
First thing I thought after seeing this was UPVOTE too much time on reddit…. anyway this looks really nice might use this actually :)/>
7508 posts
Location
Australia
Posted 12 January 2013 - 03:29 AM
First thing I thought after seeing this was UPVOTE too much time on reddit…. anyway this looks really nice might use this actually :)/>
haha! Thank you :)/> Well if you do let me know and I'll put a little "Uses this" section and a link to your program… This stands for EVERYONE, if you have used this and want me to include your program here, just post it :)/>
249 posts
Location
In the universe
Posted 12 January 2013 - 03:51 AM
Nice API! You did really deserve the +1
7508 posts
Location
Australia
Posted 12 January 2013 - 03:52 AM
Nice API! You did really deserve the +1
Thank you :)/>
1114 posts
Location
UK
Posted 13 January 2013 - 03:47 AM
ASCII Mode ( for Advanced computers only )Spoiler
local logo = {
"| | | | -. | | | ",
"| | | | | ",
"+-. +-. .-. .-. .- | .-. | .-. .-. | +-. | +-.",
"| | | | | | | | | | | | | | | | | | | | | ",
"| | | +-' | | | | '-+ | | | +-+ | | | | | ",
"\\ | | | | | | | | | | | | | | | | | \\ ",
" \\| | | '– '-' | | –' | | | | | | '-' | \\-"
}
load.initBarForAscii( logo, 15, 30, sizeY - 5, "Starting…", "Text At Top", "Text At Bottom", colors.red )
function tester()
load.setMessage( "1/15 Steps" )
– do something
load.triggerUpdate( "2/15 Steps" )
– do something
load.triggerUpdate( "3/15 Steps" )
end
parallel.waitForAll( load.run, tester )You missed out the
tag
1852 posts
Location
Sweden
Posted 13 January 2013 - 09:55 AM
So this works with tekkit?
Great work anyway because It just looks Awesome.
And could you maybe put a pastebin link too so it's easier to download.
7508 posts
Location
Australia
Posted 13 January 2013 - 12:23 PM
- snip -
You missed out the
tag
Thanx, didn't see that, did that one just before bed ;)/>
So this works with tekkit?
Great work anyway because It just looks Awesome.
And could you maybe put a pastebin link too so it's easier to download.
Yes it should work in Tekkit, definitely will in Tekkit_lite, I haven't actually tested yet, but the logic is sound, just note the known bug… this will cause an error in CC1.3 too… Still trying to fix that one, its an odd one!
Thank you :)/>
Yeh I've been meaning to do that, keep forgetting… sorry ill put that up now…
Note to all, there will be a new version at some point today that adds a new mode, and allows you to use multiple load bars at once!. :D/>
2088 posts
Location
South Africa
Posted 13 January 2013 - 01:02 PM
Note to all, there will be a new version at some point today that adds a new mode, and allows you to use multiple load bars at once!. :D/>/>
Will there even be space for more than one? O.o
7508 posts
Location
Australia
Posted 13 January 2013 - 01:06 PM
Note to all, there will be a new version at some point today that adds a new mode, and allows you to use multiple load bars at once!. :D/>/>
Will there even be space for more than one? O.o
Well the programmer decides where they are… you could have a screen full of them if you wish, the limit will be 999 of them ;)/> … I'm adding a new mode which is a bar only, no logo, no screen clearing…