Toggling Gui Visiblity
by Kirby Webber · in Torque Game Engine · 12/18/2002 (7:28 pm) · 10 replies
What I am trying to accomplish, is simply setting a particular gui to display in 1st person only. (For reference, it is a vehicle dashboard.)
I defined 2 functions in the playGui script:
I am hoping that this will be as simple as implementing this type of command:
Only problem is that I am not sure exactly WHERE to impliment this?!
I have looked through camera.cs, commands.cs, and several others, but cannot figure out where the camera actually changes from 1st to 3rd person perspective.
There is a setMode() in camera.cs, though I believe that to be the camera mode.
Any advice? Will this even work, or am I chasing down a rabbit trail?
I had hoped to do this without modifying source, though I could do it that way. I just need to start learning this scripting language... it's anything but natural to me. =/
Thanks in advance.
I defined 2 functions in the playGui script:
function GuiBitmapCtrl::DashOff()
{
//If the panel is on, turn it off
DashPanel.setVisible = false;
}
function GuiBitmapCtrl::DashOn()
{
//if the panel is off, trun it on
DashPanel.setVisible = true;
}I am hoping that this will be as simple as implementing this type of command:
if ($firstPerson)
{DashOn();}
if (!$firstPerson)
{DashOff();}Only problem is that I am not sure exactly WHERE to impliment this?!
I have looked through camera.cs, commands.cs, and several others, but cannot figure out where the camera actually changes from 1st to 3rd person perspective.
There is a setMode() in camera.cs, though I believe that to be the
Any advice? Will this even work, or am I chasing down a rabbit trail?
I had hoped to do this without modifying source, though I could do it that way. I just need to start learning this scripting language... it's anything but natural to me. =/
Thanks in advance.
#2
Slowly but surely, this is starting to make sense. As you can probably tell from my coding "style" I am actually a C programmer who is "force feeding" myself C++! LOL
Thanks for your help.
12/19/2002 (5:21 am)
Yes Jared... that is a great help!Slowly but surely, this is starting to make sense. As you can probably tell from my coding "style" I am actually a C programmer who is "force feeding" myself C++! LOL
Thanks for your help.
#3
When I call Canvas.pushDialog(DashPanel); the image blows up to the size of the screen, and then won't return to normal when I call Canvas.popDialog(DashPanel)!
I don't get it?!
12/19/2002 (6:51 pm)
Okay, I am getting some pretty weird results. I have tried this several different ways, but the end result is this:When I call Canvas.pushDialog(DashPanel); the image blows up to the size of the screen, and then won't return to normal when I call Canvas.popDialog(DashPanel)!
I don't get it?!
#4
Another method to do the above that would work would be to use the .add method.
function YourGUI::toggle(%this)
{
if (%this.isAwake())
Canvas.getContent.Add(%this);
else
Canvas.getContent.Remove(%this);
}
12/20/2002 (10:48 am)
If you are going to use Canvas.pushDialog(); and Canvas.popDialog(); make sure that the GUI element you are specifying is a clear full screen element, and the GUI object you want to show is placed where you want it to be.Another method to do the above that would work would be to use the .add method.
function YourGUI::toggle(%this)
{
if (%this.isAwake())
Canvas.getContent.Add(%this);
else
Canvas.getContent.Remove(%this);
}
#5
I looked through the Torque Scripting reference, but found no details on the Canvas.pop/push functions.
Now it makes sense! Can't wait to get home and 'fix' it! =D
Thanks Harold. You da' man!
12/20/2002 (2:25 pm)
AHA!I looked through the Torque Scripting reference, but found no details on the Canvas.pop/push functions.
Now it makes sense! Can't wait to get home and 'fix' it! =D
Thanks Harold. You da' man!
#6
You can then use canvas.getContent(); to check what specific "dialogs" are currently being displayed and based on that decide on an action to perform.
add and remove work a bit different.
Add will add a GUI "ELEMENT" to a SCREEN regardless of if it is on the canvas stack or not.
remove will remove a GUI "ELEMENT" from a screen regardless of if it is on the canvas stack or not.
12/20/2002 (4:23 pm)
I guess the best explanation is that pushDialog pushes a new GUI "SCREEN" onto the Canvas stack, and popDialog pops the GUI "SCREEN" off of the stack.You can then use canvas.getContent(); to check what specific "dialogs" are currently being displayed and based on that decide on an action to perform.
add and remove work a bit different.
Add will add a GUI "ELEMENT" to a SCREEN regardless of if it is on the canvas stack or not.
remove will remove a GUI "ELEMENT" from a screen regardless of if it is on the canvas stack or not.
#7
First of all, in playGui.cs I have defined the following function as Harold suggested:
Then in default.bind.cs, I modified toggleFirstPerson as follows:
Okay, to qualify this, I have tried a number of different approaches, but nothing seems to work.
I verified that the function was being called during the camera toggle... experimented with the pop and pushDialog some more... but that is less memory efficient than I like. ;)
I apologize if my questioning seems ignorant... it IS! ;)
If someone would be willing to walk me through this step by step I'd be forever greatful. I am having a h*ll of a time wrapping my head around this engine!
12/28/2002 (5:47 pm)
Yikes! I thought I had this figured out, but apprently I need someone to hold my hand and walk me through. I am just not getting it.First of all, in playGui.cs I have defined the following function as Harold suggested:
function DashPanel::dashToggle(%this)
{
if (%this.isAwake())
Canvas.getContent.Add(%this);
else
Canvas.getContent.Remove(%this);
}Then in default.bind.cs, I modified toggleFirstPerson as follows:
function toggleFirstPerson(%val)
{
if (%val)
{
$firstPerson = !$firstPerson;
}
DashPanel.dashToggle(); //this is the only change
}Okay, to qualify this, I have tried a number of different approaches, but nothing seems to work.
I verified that the function was being called during the camera toggle... experimented with the pop and pushDialog some more... but that is less memory efficient than I like. ;)
I apologize if my questioning seems ignorant... it IS! ;)
If someone would be willing to walk me through this step by step I'd be forever greatful. I am having a h*ll of a time wrapping my head around this engine!
#8
canvas.getContent().remove
You need the () after getContent.
12/28/2002 (6:21 pm)
canvas.getContent().addcanvas.getContent().remove
You need the () after getContent.
#9
I am SUCH an idiot! Thanks Harold... it works beautifully! I REALLY appreciate your help. =)
12/28/2002 (6:31 pm)
ROFLMAO!!!!I am SUCH an idiot! Thanks Harold... it works beautifully! I REALLY appreciate your help. =)
#10
I'm having some troubles (Torque newbie you see :) so was just testing out the toggle dialog on the Loadinggui one from the examples.
I've setup my key bind stuff in default.bind.cs
moveMap.bind( keyboard, 0, JamboToggleOptions );
And have the proc (also in default.bind.cs)
function JamboToggleOptions()
{
LoadingGui.toggle();
}
Also... in 'loadinggui.cs'
function LoadingGui::toggle(%this)
{
if (%this.isAwake())
{ Canvas.getContent().Add(%this);
}
else
{ Canvas.getContent().Remove(%this);
}
}
However Im getting the following error?
Set::remove Object "LoadingGui" does not exist in set
But if goto the console and type:
Canvas.getContent().Add(LoadingGui); works.
Very (very) stuck and any help would be most appreachiated.
Thanks in advance.
Jamie
09/05/2006 (3:02 pm)
Hi all, I'm having some troubles (Torque newbie you see :) so was just testing out the toggle dialog on the Loadinggui one from the examples.
I've setup my key bind stuff in default.bind.cs
moveMap.bind( keyboard, 0, JamboToggleOptions );
And have the proc (also in default.bind.cs)
function JamboToggleOptions()
{
LoadingGui.toggle();
}
Also... in 'loadinggui.cs'
function LoadingGui::toggle(%this)
{
if (%this.isAwake())
{ Canvas.getContent().Add(%this);
}
else
{ Canvas.getContent().Remove(%this);
}
}
However Im getting the following error?
Set::remove Object "LoadingGui" does not exist in set
But if goto the console and type:
Canvas.getContent().Add(LoadingGui); works.
Very (very) stuck and any help would be most appreachiated.
Thanks in advance.
Jamie
Torque Owner Jared Schnelle
//in default.binds.cs function toggleFirstPerson(%val) { if (%val) { $firstPerson = !$firstPerson; } } moveMap.bind(keyboard, tab, toggleFirstPerson);This function is defined in your default.binds.cs script. I'm sure the $firstPerson variable is linked into the actual engine code, and it checks that value when its time to render a new frame.
Anyhow, I'd just stick a function right below the change in $firstPerson
I also highly suggest you dont set something to be "awake" or "asleep" manually like that, do something a little less obtrusive. Take a look at how the player list is turned on/off
function PlayerListGui::toggle(%this) { if (%this.isAwake()) Canvas.popDialog(%this); else Canvas.pushDialog(%this); }Hope this helps,
Jared