Game Development Community

Displaying GUI control from engine

by Gordon Marsh · in Torque Game Engine · 09/06/2006 (1:00 pm) · 3 replies

All,

I have created a new GUI control which inherits directly from GuiControl. The control is simply a button which should pop up when the player enters a certain mode.

However, the event which causes the player to enter this mode is signalled in the engine (player.cc), so I need to display this control from within the engine, not script.

From tests I suppose I need more than:
myGuiCtrl* temp = new myGuiCtrl();
temp->setVisibility(true);
But am unsure of what I am missing - do I need to pop the control onto the screen somehow?

Or, on further reading, is it better to build a .cs/.gui file and exec it somehow from the engine?

Thanks, Gords

#1
09/06/2006 (1:19 pm)
I believe you'll need to add the control to a parent control such as PlayGui.
if you're creating it in the engine you'll probably also need to Register() it yourself.

i would advise doing it the more standard way,
which is including it in the appropriate .GUI file, but hidden,
and then in player.cc make a callback to script to show the button.

eg

playGui.gui (for example)
new myGuiControl(mySpecialButton) {
      profile = "GuiDefaultProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "0 0";
      extent = "30 30";
      visible = "0";
   };


engine
void Player::foo()
{
   bool visible = 1;
   Con::executef(this, 2, "fooCallback", Con::getIntArg(visible));
}

script
function Player::fooCallback(%this, %visible)
{
   mySpecialButton.setVisible(%visible);
}

.. it may seem like a waste to call out to script for this,
but it's surprising how often it's nice to be able to fool with the logic and such behind GUI elements in scripts.
#2
09/06/2006 (1:50 pm)
Thanks for the very rapid response Orion! That's exactly what I wanted. I'll have to rework some stuff, but it should be pretty easy from here...

Gords
#3
09/06/2006 (2:19 pm)
My pleasure!