Dynamic Positioning of GUI Elements
by Clark Kromenaker · in Torque Game Engine · 03/22/2006 (5:39 pm) · 6 replies
I have a GUI which appears whenever a selectable item is clicked on. This GUI contains such actions as examine, talk, open, close, etc. The problem I noticed is that if an object can't do one of the actions and I hide that button, I would have a big gaping hole between my buttons, so it would be best if I could position my buttons on the GUI dynamically during script executuion depending on what actions are available, rather than hard-coding the button positions.
I looked at the GUIControl object and it appears to only have a getPosition() function, but before I start messing with engine code, I wanted to check here before making a setPosition(), in case there was already a way to do this.
I looked at the GUIControl object and it appears to only have a getPosition() function, but before I start messing with engine code, I wanted to check here before making a setPosition(), in case there was already a way to do this.
#2
I looked at the resize function and managed to make a setPosition pretty easily. For the record...
Add this to GUIControl.h, right above the resize() declaration:
-----
virtual void setPosition(const Point2I &newPosition);
-----
Then added this to GUIControl.cc:
------
void GuiControl::setPosition(const Point2I &newPosition)
{
mBounds.point = newPosition;
}
-----
and
-----
ConsoleMethod( GuiControl, setPosition, void, 4, 4, "(int x, int y)")
{
Point2I newPos(dAtoi(argv[2]), dAtoi(argv[3]));
object->setPosition(newPos);
}
-----
Its pretty simple...I don't see why it wasn't already there.
But again, thanks :)
03/23/2006 (7:03 pm)
Thanks, I looked at the resize function and managed to make a setPosition pretty easily. For the record...
Add this to GUIControl.h, right above the resize() declaration:
-----
virtual void setPosition(const Point2I &newPosition);
-----
Then added this to GUIControl.cc:
------
void GuiControl::setPosition(const Point2I &newPosition)
{
mBounds.point = newPosition;
}
-----
and
-----
ConsoleMethod( GuiControl, setPosition, void, 4, 4, "(int x, int y)")
{
Point2I newPos(dAtoi(argv[2]), dAtoi(argv[3]));
object->setPosition(newPos);
}
-----
Its pretty simple...I don't see why it wasn't already there.
But again, thanks :)
#3
03/23/2006 (9:45 pm)
Personally for any advanced GUI manipulation and GUI object moving I'd recommend getting TGB (Torque Game Builder) and using it as an overlay advanced GUI system.
#4
-Jeff
03/24/2006 (2:20 pm)
I would suggest just having the un-used buttons displayed as disabled/ greyed out. From an end-users point of view, multiple button layouts require having to 'learn' what is possible every time that gui opens. If the buttons are just greyed out, then the user can quickly understand what is possible, without having to 'read' the button text, since the buttons are always in the same location.-Jeff
#5
As example, for a past game we had a circular inventory menu done purely using a script. A function would fill a specific GuiControl with buttons, text (for labels) and GuiObjectView controls (for displaying the item itself as an icon), in a circular distribution to represent all itens in the inventory. It only required some trig and lots of resize() calls.
03/25/2006 (9:32 am)
Creating GUI elements from script is easy and straightforward: the GUI files *are* scripts. They just call the contructors for the GUI controls, and you can do the same dynamically if you want.As example, for a past game we had a circular inventory menu done purely using a script. A function would fill a specific GuiControl with buttons, text (for labels) and GuiObjectView controls (for displaying the item itself as an icon), in a circular distribution to represent all itens in the inventory. It only required some trig and lots of resize() calls.
#6
In this design, its much more logical to simply give the player the buttons that will work. If they click on a barrel, they shouldn't have to stare at a dozen greyed out buttons for functions such as eat, talk, sneak, take, climb, etc...
It seems to be working pretty well now. Thanks, guys.
03/27/2006 (7:05 am)
Greying out buttons would be illogical in this case. The GUI is a verb-chooser menu with an upward of 20-30 buttons for specific cases. You can imagine the space it would take up.In this design, its much more logical to simply give the player the buttons that will work. If they click on a barrel, they shouldn't have to stare at a dozen greyed out buttons for functions such as eat, talk, sneak, take, climb, etc...
It seems to be working pretty well now. Thanks, guys.
Associate Orion Elenzil
Real Life Plus
i highly recommend adding a reposition(),
because resize() is going to do unneccessary work if all you're doing is changing the position,
and because it's a hassle to always have to go find the current extent and pass it back in when all you want to do is move the thing.
you might also be interested in this amazing resource.