Author Topic: Generating GUI Elements  (Read 907 times)

How is this done? For instance, in the Blockland Add-Ons List, it lists all the add-ons that you have. How is this sort of thing done through script?

How is this done? For instance, in the Blockland Add-Ons List, it lists all the add-ons that you have. How is this sort of thing done through script?

Yes. It determines from a list and lists.

It wasn't a yes or no question

There are two primary functions that I use to create lists.

Code: [Select]
while(%i < 2)
{
%i++;
echo("I: " @ %i);
}

Code: [Select]
//Inventory is the name of the GUI list. %I = the row ID.
Inventory.addRow(%i, "Text");
« Last Edit: May 05, 2010, 10:41:38 PM by Desolation »

There are two primary functions that I use to create lists.

Code: [Select]
%i++;
while(%i < 2)
{
echo("I: " @ %i);
}
Wouldn't that create an endless loop?


How is this done? For instance, in the Blockland Add-Ons List, it lists all the add-ons that you have. How is this sort of thing done through script?
This is done one of two ways.

The first possibility is loop through your add-on files, like so:

Code: [Select]
%file = findFirstFile("Add-Ons/*/server.cs");
for(%i=1;%i<getFileCount("Add-Ons/*/server.cs");%i++)
{
%substring=getSubStr(%file,8,strLen(%file));
%substring = getSubStr(%substring,0,strLen(%substring)-10);
%inventory.addRow(%i,%substring)
%file=findNextFile("Add-Ons/*/server.cs");
}

Or, it searches through a list of variables which define if addons are enabled or disabled. I don't know how it would do this.

to actually add new GUI controls on the fly you put something like this inside your loop:

%newControl = new GuiControl() {
<positioning stuff and properties>
};

Parent.add(%newControl);


Getting the positioning and stuff right is where the challenge is.  Its best to add 1 or 2 controls inside the GUI editor manually so you can see what stuff should look like, and then go from there.

Well, if I was to create a list of files with checks, I would do something like this:

Code: [Select]
for( %file = findFirstFile("directory/*.*"); %file !$= ""; %file = findNextFile("directory/*.*") )
{
new GuistuffThing("GUIcheck_"@%file)
{
stuff = 1;
};
new GuiTextCtrl("GUItext_"@%file)
{
text = %file;
otherstuff = 1;
};
GUIlistScroll.add("GUIcheck_"@%file);
GUIlistScroll.add("GUItext_"@%file);
}

This is un-tested and was written on the fly.

Or, it searches through a list of variables which define if addons are enabled or disabled. I don't know how it would do this.

Something like this (double post):

Code: [Select]
// %addon = "Vehicle_Jeep";
eval("if($AddOn__"@%addon@" $= 1) { echo(\""@%addon@" is enabled.\"); } else { echo(\""@%addon@" is disabled.\");");

I'm sure it could be done in a better way than Eval, but still.

Hello. tr1pl3 p0st 4nd bump

The Client_Hub add-on does what you're looking for.