Game Development Community

More GUI Help!

by Chase Webb · in Torque 2D Beginner · 07/16/2014 (6:30 am) · 2 replies

Howdy Y'all!

I'll get straight into this. I've been playing around with my Menus, working on Buttons in a frame around the main section of my little editor. I've planned to have three sides around the main section split into three parts of a frame. I've got a left frame, a top frame, and a bottom frame, which I want to pop and push (including all the buttons contained within) individually.

Here is my problem: I've got two of these frame sections set as GuiSpriteCtrls, with GuiButtonCtrls as the children. When I load two GuiSpriteCtrls they appear to overlap, so that I can only push the buttons attached to one of them. If I alter the extent it changes it somehow, but since I can't seem to attach a background color or border, the only way I can tell it is changing is from the location/size of the buttons. Trying to change the position does not appear to change anything (as the buttons do not move).

I'm open to suggestions at this point. Here are some samples of the code I am using:

function LoadLevelBuilderLeftFrame(%this){

%LoadLevelBuilderLeftFrame = new GuiSpriteCtrl(LoadLevelBuilderLeftFrame) {
    Name="LoadLevelBuilderLeftFrame";
    Profile="LevelBuilderGuiToolboxProfile";
    HorizSizing="relative";
    VertSizing="relative";
    Position="0 0";
    Extent="1024 768";
    MinExtent="320 320";
    Visible="1";
};

//(%this, %Frame, %Position, %Profile, %ButtonName, %ButtonTextName, %text)
LevelBuilder::CreatePushButton(%this, %LoadLevelBuilderLeftFrame, 0 SPC 0, "BlueButtonProfile", ToolboxObjectsButton, ToolboxObjectsButtonText, "Toolbox<br>Objects");

//(%this, %Frame, %Position, %Profile, %ButtonName, %ButtonTextName, %text)
LevelBuilder::CreatePushButton(%this, %LoadLevelBuilderLeftFrame, 0 SPC 80, "BlueButtonProfile", PermanentObjectsButton, PermanentObjectsButtonText, "Permanent<br>Objects");
	  
}

function LevelBuilder::CreatePushButton(%this, %Frame, %Position, %Profile, %ButtonName, %ButtonTextName, %text){

 %Button = new GuiButtonCtrl(%buttonname)
      {
        Profile=%Profile;
        ButtonType="PushButton";
        canSaveDynamicFields="0";
        isContainer="1";
        HorizSizing="relative";
        VertSizing="relative";
        Position=%Position;
        Extent=$buttonsize SPC $buttonsize*0.8;
        MinExtent=$buttonsize SPC $buttonsize*0.8;
        canSave="1";
        Visible="1";
        Active="1";
        hovertime="1000";
        groupNum="-1";
        useMouseEvents="1";
      };

	  LevelBuilder::CreateButtonText(%this, %ButtonTextName, %text, %Button); 
	
	  %Frame.add(%Button); 
}

function LevelBuilder::CreateButtonText(%this, %Name, %text, %Button){

	 %ButtonText = new guiMLTextCtrl(%Name){
        Profile="LevelBuilderGuiMLTextProfile";
        Text="<just:center>" @ %text;
        Position= 0 SPC $buttonsize*0.2;
		extent = $buttonsize SPC $buttonsize*0.8;
		minextent = $buttonsize*0.75 SPC $buttonsize*0.6;
      };
	  %Button.add(%ButtonText); 

}

Note: The Button and Text functions work quite well. I don't use taml files because I need more flexibility.

#1
07/16/2014 (6:55 am)
Try setting position and extent after button creation.
function LevelBuilder::CreatePushButton(%this, %Frame, %Position, %Profile, %ButtonName, %ButtonTextName, %text){  
  
 %Button = new GuiButtonCtrl(%buttonname)  
      {  
        Profile=%Profile;  
        ButtonType="PushButton";  
        canSaveDynamicFields="0";  
        isContainer="1";  
        HorizSizing="relative";  
        VertSizing="relative";  
        MinExtent=$buttonsize SPC $buttonsize*0.8;  
        canSave="1";  
        Visible="1";  
        Active="1";  
        hovertime="1000";  
        groupNum="-1";  
        useMouseEvents="1";  
      };  
  
      %Button.Position=%Position;  
      %Button.Extent=$buttonsize SPC $buttonsize*0.8;  

      LevelBuilder::CreateButtonText(%this, %ButtonTextName, %text, %Button);   
      
      %Frame.add(%Button);   
}
That might help, not sure. I remember having a lot of weirdness creating dynamic gui panels when working on 3SS and this usually solved positioning issues. Also, just a reminder - position will be relative to the container.
#2
07/19/2014 (5:43 pm)
I ended up finding a different solution to the problem. Changing the positions apparently does nothing in regards to the overlay over other GuiSpriteCtrls, but by adding the modal=false to the LevelBuilderGuiToolboxProfile and then changing to visible="0" I was able to make it so buttons can be clicked regardless of which GuiSpriteCtrl is loaded.

Also, thanks for trying Richard, but the Buttons were not the problems. Position actually works for them.