Game Development Community

Issue creating new GUI instances via C

by Robert Geiman · in Torque Game Engine · 10/25/2005 (12:02 pm) · 1 replies

Ok, I created a new GUI container control class called GuiMyContainerCtrl. I would like it to automatically add a child GUI control (GuiMyChildCtrl) when GuiMyContainerCtrl is created. So I added this function to GuiMyContainerCtrl:

bool GuiMyContainerCtrl::onAdd()
{
   GuiMyChildCtrl *ctrl = new GuiMyChildCtrl();

   if (ctrl)
   {
      ctrl->setField("profile", "GuiMyChildProfile");

      ctrl->registerObject("MainChild");
      addObject(ctrl);
   }

   return true;
}

This seems to work, as when I add GuiMyContainerCtrl to my GUI via the GUI Editor, it correctly creates child GuiMyChildCtrl instance and I can see it on the screen and manipulate it via the console.

However, when I select it in the GUI editor, the profile editor on the right hand side shows empty values for all fields. If I try setting values, it instead creates NEW dynamic fields of the same name.

If I save my GUI, exit, and reload it, then I'm able to edit the profile just fine.

Does anyone know what I'm doing wrong?

#1
02/09/2006 (5:56 pm)
Im having the exact same problem. By the look of other C++ code that creates GUI elements, this is the correct way of doing it. Here is the code im trying:

GuiTextCtrl* txt = new GuiTextCtrl();
	if(txt)
	{
		txt->setText(name);
		txt->setField("position", "2 2");
		txt->setField("extent", "296 51");	
		txt->registerObject();

		GuiControl * playGui;
		Sim::findObject("PlayGUI", playGui);
		if(playGui)
		{
			playGui->addObject(txt);
			Con::printf("DONE!");
		}
	}