Hi CromCrom! Unfortunately, what you stumbled upon above was a discussion I was having with Petri about a GUI abstraction I am designing (about to sit down and do some now actually!), so that code was "theoretical" not real code.
On the plus side, there is already a basic GUI system available in the Scripting Reference. When you override onDrawGui in the Party component, you get passed a 'Graphics Context' object, which allows you to do immediate rendering of GUI elements in your method. So, you can do something like this...
Code: Select all
onDrawGui = function(self, context)
context.color(100, 100, 100, 200);
context.drawRect(10, 10, 210, 50);
context.color(0, 0, 0, 128);
context.drawRect(20, 20, 90, 30);
context.drawRect(120, 20, 90, 30);
context.color(255,255,255,255);
context.drawText("Button A", 30, 40);
context.drawText("Button B", 130, 40);
if ( context.button("button_a", 20, 20, 90, 90) ) then
print("Clicked A");
end
if ( context.button("button_b", 20, 20, 90, 90) ) then
print("Clicked A");
end
end
The above code will produce...
It's pretty powerful in terms of what you can do overall, but a little bit fiddly (notice all of the hard-coded numbers). I'm working on a GUI abstraction that will either let you...
1. Build a GUI state and control it separately
Code: Select all
-- THEORETICAL CODE - DOES NOT WORK YET!
defineGui{ name="name", ...}
local g = createGui("name");
g:show();
g:destroy();
2. Build an immediate GUI but with a system that will remember your current "panel" transform and handle the drawing of buttons with rectangles and text for you.
Code: Select all
-- THEORETICAL CODE - DOES NOT WORK YET
gui.startPanel({x=20, y=20, width=100, height=100, bgColor={200, 200, 200, 200});
if gui.button({x=10, y=10, width=100, height=40, text="Hello", textColor={255,255,255,255}, bgColor={0,0,0,255})
.. do something ..
end
gui.endPanel();