Author Topic: Add a button  (Read 1621 times)

Can somebody tell me the function or code to add a button into a specific gui control?
Is this right?
Code: [Select]
function nameofcontrol::addTab(%this,%tab)
{
nameofcontrol.add(nameofbutton);


if(getWord(nameofbutton.position,0) > 0)
{
nameofbutton.position = 0 SPC 0;
}
else
{
nameofbutton.position = getWord(nameofbutton.position,0) SPC 0;
}

%width = 0;

for(%i = 0;%i < nameofbutton.getCount();%i++)
{
%width += 80;
}

nameofbutton.extent = %width SPC 25;
}

I think you can set the GUI control as a global variable and then use originalguiname.add($newgui);
Code: [Select]
$newguistuff = new guibuttonctrl { //stuff here
Originalguiname.add($newguistuff);

Ok, could it be like?
Every time you press "add", it would add the tabs (NewBtun, NewBtun2, and so on).
« Last Edit: March 17, 2014, 10:16:18 PM by KingDavid »

I think you can set the GUI control as a global variable and then use originalguiname.add($newgui);
Code: [Select]
$newguistuff = new guibuttonctrl { //stuff here
Originalguiname.add($newguistuff);
Nah. I just got syntax errors.

I was talking about just the adding part, like the nameofcontrol.add(nameofbutton); . Set the name of the button to a global variable, then use nameofcontrol.add($button);. For example (this won't do your thing but is similar to what you want it to do, it adds a button to the Admin Gui).

$button = new GuiBitmapButtonCtrl(stuff_adminMenuButton) {
         profile = "BlockButtonProfile";
         horizSizing = "left";
         vertSizing = "bottom";
         position = "250 50";
         extent = "100 19";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "canvas.popDialog(adminGui);";
         text = "Teleporter";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "base/client/ui/button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         alignTop = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "100 150 200 255";
      };

//adds button to adminGui
adminGui.add($button);

I was talking about just the adding part, like the nameofcontrol.add(nameofbutton); . Set the name of the button to a global variable, then use nameofcontrol.add($button);. For example (this won't do your thing but is similar to what you want it to do, it adds a button to the Admin Gui).

$button = new GuiBitmapButtonCtrl(stuff_adminMenuButton) {
         profile = "BlockButtonProfile";
         horizSizing = "left";
         vertSizing = "bottom";
         position = "250 50";
         extent = "100 19";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         command = "canvas.popDialog(adminGui);";
         text = "Teleporter";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "base/client/ui/button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         alignTop = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "100 150 200 255";
      };

//adds button to adminGui
adminGui.add($button);

If your creating the button inside of a function, you can just use a local variable. Also, you don't need to give the button a name at this point, unless your planning on doing things with it, other than adding it in.

I asumed you meant to put it all in the server.cs
Code: [Select]
function clientCmdStore_TabButtonsAdd(%this,%tab)
{
New_Btun.extent = %width SPC 25;

Store_TabButtons.add(%button);
}
%button = new GuiBitmapButtonCtrl(New_Btun) {
         profile = "BlockButtonProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "0 0";
         extent = "100 30";
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         text = "";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "base/client/ui/tab1";
         lockAspectRatio = "0";
         alignLeft = "0";
         alignTop = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "220 220 220 255";
      };
I also need to know if there is a way to change the color of a control. specifically a button.
something like
Code: [Select]
controlName.setmColor = r g b a
« Last Edit: March 18, 2014, 10:15:14 PM by KingDavid »

There's a simple way. Download mission editor, You may not be able to use the mission editor, but you can use the GUI Editor. It gererates the script for everything.

There's a simple way. Download mission editor, You may not be able to use the mission editor, but you can use the GUI Editor. It gererates the script for everything.

I think he wants to dynamically add tabs, like google chrome's window tabs.

There's a simple way. Download mission editor, You may not be able to use the mission editor, but you can use the GUI Editor. It gererates the script for everything.
I already have that. I'm not talking manually edit the gui. I want to use code. Take the picture I posted earlier. There are a few codes I know of that do it, but they are rtb. If you can support it,  the add-on is called "GUI_TabShiftingBrickSelector". The add-on adds tabs to the brick selector if you have excess amount of brick categories turned on, so that you may switch and not have to turn any off. Sorry I don't know how to post a .zip.
« Last Edit: March 29, 2014, 08:11:13 PM by KingDavid »

The add-on adds tabs to the brick selector if you have excess amount of brick categories turned on,
No it doesn't, the default script creates the tabs and the tab shifter just adds buttons to move them around.

No it doesn't, the default script creates the tabs and the tab shifter just adds buttons to move them around.
Sorry for not being more specific, but that's what I'm asking for. I already realize that this is a default script using add-on.

I already have that. I'm not talking manually edit the gui. I want to use code. Take the picture I posted earlier. There are a few codes I know of that do it, but they are rtb. If you can support it,  the add-on is called "GUI_TabShiftingBrickSelector". The add-on adds tabs to the brick selector if you have excess amount of brick categories turned on, so that you may switch and not have to turn any off. Sorry I don't know how to post a .zip.

I would not recommend that mod as a reference.  That mod actually deletes the default brick inventory and then loads a new one with the buttons on it, instead of just adding the buttons manually like you are talking about in this thread.

I would not recommend that mod as a reference.  That mod actually deletes the default brick inventory and then loads a new one with the buttons on it, instead of just adding the buttons manually like you are talking about in this thread.
No it doesn't, the default script creates the tabs and the tab shifter just adds buttons to move them around.



You misunderstand, I am referring to the execution of the mod itself, and not the way it handles tabs.

Code: [Select]
if($BSD_TabShifting != 1)
{
exec("./ui/BrickSelectorDlg.gui");
$BSD_SelectedTab = 0;
$BSD_TabShifting = 1;
}

The new gui that is loaded then overwrites the namespace for BrickSelectorDlg, effectively replacing the existing one instead of modifying it.