Warning : if you enter wrong args type for pop-up, it will skip the drawing of the pop-up to avoid crash
Introducing my easy to use GUI API.
It's a medium-advanced API wich mean that it allow you to do things very easily but with less personnalisation than a basic API. It's principally designed for debutant in Lua who want to create a GUI without complicated code.
I will add features as long as I got idea so if you have a request, ask for it ! Sadly, i can code more than I can test it so if you want to help, test it for me ! Thanks ;)/>
Obviously, I let you use and modify this code, but please don't redistribute it as your own. Link to this page or at least credit me in case of you wanted to make an installer. Please just let me know ! Thanks you by advance.
Functions :
Spoiler
All the color args are optionals, will set it to white and black if not specifiedAlso the a and b args mean "end x" and "end y", the bottom right corner of the button.
gui.getVersion() gives you the version of the API, useful to check if a function is present or not.
gui.render(reset) Use it to draw the content of the buffer to the screen, if reset is set to true, it will reset the buffer.
gui.drawButton(startx, starty, endx, endy, text, colorOfLine, colorOfBackground, clear) draw a rectangle with the text inside it. It's now an internal function, you could use this to draw a button without the buffer. Set clear to true will clear the screen before drawing the button.
gui.setButton(x, y, text, colorLine, colorBackground) It remplace the draw function, it draw into the buffer. Remplace gui.draw by this in your code.
gui.setHeader(text, colorLine) Use it to draw header into the buffer, it remplace the draw one.
gui.drawHeader(text, colorOfLine) draw the text at the first line and draw a line below it. Also set the cursor position to the third line. It's an internal function since 1.4.
gui.buttonClick(startx, starty, endx, endy) return true if the specified area is clicked, false if not.
gui.buttonWaitClick(startx, starty, endx, endy) same as above but will wait until the specified area is clicked, useful for use with the parallel API.
gui.fill(starx, starty, endx, endy, color) fill the area defined with the color specified. (Must be colors.grey for example)
gui.getSelection() Take all the drawn buttons with the set function, not the draw one, and return the one which has been clicked. (Look in the example spoiler)
gui.popUp(title, text, x, y, colorLine, colorBackground, textButton1, textButton2) draw a pop-up with a title has a header, a text and a specified background color wich will close when clicked. The x and y are the coords of the upper right corner. If the buttons args are specified it will return the one which has been clicked.
gui.clearBuffer() self-explanatory
gui.setTickBox(x, y, colorLine, isTrue) draw a tickbox wich is a little button with a green T or red F inside, depend of isTrue. If it is clicked it will change what is inside and you can get what it is by the return of the function (Will be functionnal for 1.7)
gui.initializeLog() will make the functions write what they are doing to /guiapi/log, call it to start register what the API is doing
Download :
Spoiler
http://pastebin.com/RZYPqxCpBeta version non-tested, could be buggy. Please report any bug, or just say "it work !"
http://pastebin.com/5TudhQRb
Planned features :
Spoiler
Add a list function (maybe)Allow multi-lines pop-up
Tickbox as suggested by archangel (40%)
Custom error message(100%)(maybe debug needed ?)
Changelog :
Spoiler
V1.6.1 in betaAdded more logs message, especially for errors
Added custom error messages
Added skipping of pop-up if args not correct
V1.6
Added log file
Added initializeLog()
Fixed animation for pop-up
V1.5
Fixed header
Added clearBuffer() requested by Oct125
Changed the way the pop-up work, now support up to 2 buttons, automatic resizement
Fixed the coords buttons don't clear when it should (thanks to Oct125)
Added an animation for the pop-up ! (Actually buggy)
Automatic resizement of the button depending on the lenght of the text
V1.4.1
Combined sRender() and render(), and setButtonc() and setButton()
Also added an animation for cPopUp. (I will combine it with popUp() later)
V1.4
Rewrite a lot of function and the buffer system
Added render() and sRender()
Added getSelection()
Fixed the coords buttons to not clear when it should (thanks to Oct125)
V1.3
Allow color customisation for button and header
Add a buffer (save the button and header datas)(thanks to ArchAngel0075)
Add the update() function, to draw the buffer's content. You don't have to normally use it, it's a internal function but you may want to use it.
Fix the pop-up glitch
V1.2
Fix the buttonClick() bug
The pop-up doesn't close as expected, even if it is clicked and detected
Fix the fill() bug
And other bugs fix I forgot
V1.1
Added two functions : popUp() and fill()
Fix a lot of bugs
The detection function still not work
The pop-up don't close
V1.0
First release
Example and screenshoots : (a bit old)
Spoiler
A colourfull one :
Example of code for getSelection :
gui.setButton(x, y, a, b, text, colorline, colorbackground) --button 1
gui.setButton(x, y, a, b, text, colorline, colorbackground) --button 2
gui.drawButton(x, y, a, b, text, colorline, colorbackground) --button 3
gui.render()
gui.getSelection() --Will return 1 if button is clicked, 2 if button 2 is clicked but will not check for button 3 as I used draw instead of set.
Any feedback and suggestions are welcome !