Help with GUI
by Do Not Delete · in Torque X 2D · 07/19/2007 (1:57 pm) · 4 replies
I need some help on how to get started on creating GUIs. I looked at this thread
http://www.garagegames.com/mg/forums/result.thread.php?qt=62248
but I tried to use that code and it wouldn't work.
Is there a simple tutorial that will teach me how to put up images and whatever in a GUI form?
I need to create something like the Help Screen in Torque Combat.
Any help would be appreciated.
http://www.garagegames.com/mg/forums/result.thread.php?qt=62248
but I tried to use that code and it wouldn't work.
Is there a simple tutorial that will teach me how to put up images and whatever in a GUI form?
I need to create something like the Help Screen in Torque Combat.
Any help would be appreciated.
About the author
#2
i.e. I have a grid that comes up when player presses a button with the center of the grid being at wherever the player's location is. So should I put this grid as a GUIBitmap or T2DStaticSprite?
08/05/2007 (8:19 pm)
Thanks James. So do you ever put GUI stuff in your components or do you leave that stuff in the GUI class?i.e. I have a grid that comes up when player presses a button with the center of the grid being at wherever the player's location is. So should I put this grid as a GUIBitmap or T2DStaticSprite?
#3
However, you can just do it yourself and get that functionality in the mean time.
08/05/2007 (9:09 pm)
The point of deriving from IGUIScreen is so that possibly in a future TorqueX release, the GUI objects that derive from that interface will be automatically instantiated via reflection.However, you can just do it yourself and get that functionality in the mean time.
#4
The GUI can definitely leverage the component system. Things like editable properties and registering or looking up interfaces for pushing or pulling data can be very useful. If you need some of the functionality in the component system, do it. If not, just use the simplest method that gets the job done.
08/06/2007 (7:09 am)
Lanemyer, you could do it either way. But I would probably just use T2DStaticSprite myself. The masking and mounting functionality comes in handy.The GUI can definitely leverage the component system. Things like editable properties and registering or looking up interfaces for pushing or pulling data can be very useful. If you need some of the functionality in the component system, do it. If not, just use the simplest method that gets the job done.
Associate James Ford
Sickhead Games
Note: If you don't specify a size, position, folder, and visibility for your controls you won't be able to see them.
For the various GUIs / Screens (they seem to be using the term Screens instead of GUI) heres how I have gone about defining them. Each of my Screens has their own .cs file in my project in which I define the Screen as a class which is derived from one or more Control type classes. For example my playscreen derives from GUISceneview and IGUIScreen, and my MainScreen derives from GUIBitmap and IGUIScreen, and my SplashScreen derives from GUISplash and IGUIScreen. Note: Probably I could have just derived from IGUIScreen and GUIControl or just GUIControl and made the other element a subcontrol, in fact I'm not completely sure what the point of deriving from IGUIScreen is, theres more than one way to do this. Then in my new screen-class-contructor is where I define everything about the screen. For example, here is most of the contructor of my PlayScreen class:
// defining styles
GUIStyle playStyle = new GUIStyle();
GUIStyle playerGUIStyle = new GUIStyle();
playerGUIStyle.HasBorder = true;
playerGUIStyle.BorderColor[CustomColor.ColorBase] = Color.Black;
playerGUIStyle.FillColor[CustomColor.ColorBase] = Color.White;
playerGUIStyle.IsOpaque = true;
GUIBitmapStyle bitmapCtrlStyle = new GUIBitmapStyle();
bitmapCtrlStyle.SizeToBitmap = false;
bitmapCtrlStyle.PreserveAspectRatio = false;
_healthDisplayStyle = new GUITextStyle();
_healthDisplayStyle.FontType = "Arial20";
_healthDisplayStyle.TextColor[CustomColor.ColorBase] = Color.Black;
_healthDisplayStyle.SizeToText = true;
_healthDisplayStyle.Alignment = TextAlignment.JustifyCenter;
GUITextStyle conversationTextStyle = new GUITextStyle();
conversationTextStyle.FontType = "Arial20";
conversationTextStyle.TextColor[CustomColor.ColorBase] = Color.Black;
conversationTextStyle.SizeToText = true;
conversationTextStyle.Alignment = TextAlignment.JustifyLeft;
// define this control, the PlayScreen
Name = "PlayScreen";
Style = playStyle;
Size = new SizeF(800, 600);
Visible = true;
Position = new Vector2(0, 0);
OnGUIWake = OnPlayScreenWake;
HorizSizing = HorizSizing.Relative;
VertSizing = VertSizing.Relative;
//Folder = GUICanvas.Instance;
// define the player HUD controls (health, etc)
GUIControl p1Gui = new GUIControl();
p1Gui.Name = "p1Gui";
p1Gui.Style = playerGUIStyle;
p1Gui.Size = new SizeF(200, 50);
p1Gui.Position = new Vector2(0, 0);
p1Gui.Folder = this;
p1Gui.Visible = false;
HorizSizing = HorizSizing.Relative;
VertSizing = VertSizing.Relative;
_p1HealthDisplay = new GUIText();
_p1HealthDisplay.Name = "p1HealthDisplay";
_p1HealthDisplay.Size = new SizeF(100f, 100f);
_p1HealthDisplay.Position = new Vector2(0, 0);
_p1HealthDisplay.Style = _healthDisplayStyle;
_p1HealthDisplay.Text = "100";
_p1HealthDisplay.Visible = true;
_p1HealthDisplay.Folder = p1Gui;
Note: I'm not totally sure if the PlayScreen.Folder has to be set to GUICanvas.Instance, probably that gets done automatically when you do SetContent or PushDialogControl, but you do need to set the folder for any subcontrols, note that the p1gui control's folder is "this" and the p1healthdisplay's folder is p1gui, this is how you can nest controls.
I've seen some other ways to define screens for your game, like as a singleton, if other people have reccomendations just post them!