MinApp Tutorial #1 - Adding console support
by John Vanderbeck · 01/21/2004 (6:25 pm) · 27 comments
Download Code File
Series Overview
With the release of the Basic GUI Demo by James Yong, I thought it would be nice to build a series of tutorials around it. What James released is an excellent stripped down minimal application using Torque. It does nothing more than display a main menu with a background picture and an "Exit" button. That's it. It doesn't even have the standard tools and console in it. It is a perfect starting place on wich to build, and more importantly, learn.
From here on out i'm referring to this base release by James as the MinApp and each tutorial will be build upon that. The goal is to end up with a basic FPS when we're all done.
I am no expert on Torque myself, but I do have about 10 years of game development experience in general. This series of tutorials is as much to teach myself the workings of Torque as it is to teach others. We will be making this journey of discovery together and at any time I am wide open to comments and crisitiscm from the peanut gallery :)
Tutorial Overview
So now that we have the general overview of the tutorial series out of the way, let's begin with tutorial #1. This is a relatively small tutorial. The MinApp is so basic, it doesn't even have the functionality of the development console. This tutorial will add in support for that development tool. This tutorial feels a bit like a hack because we will be copying some files from the standard Torque demo application for our use, but that is simply the best way to do it. As the saying goes, don't reinvent the wheel.
Preperation
If you haven't already downloaded and "installed" the MinApp, then please do so at this point. Right now we're starting from James' original "Basic GUI Demo" so i'm not including a seperate copy for download. You can download it from the original resource here.
For the sake of this tutorial series, we are going to make just a mindset change about the "Basic GUI Demo". From here on out it will be referred to as the "MinApp" and we will be expanding and building upon it in each tutorial. So, let's rename the directory. When you unzipped it you ended up with a directory named "SimpleTorqueDemo". Let's rename that to "MinApp" or "TorqueMinApp" if you need the name Torque in there to keep your stuff organized :) Once you have done that, copy the torque exectuable and support DLLs in there.
Execution
Ok, now we should be all setup, and ready to add console support to the MinApp. To begin with, we are goign to copy over some of the files that come with the official Torque demo app from GG.
1) Copy files from original Torque demo to MinApp
Copy the following files from your original torque example common files to your minapp ones. They will be in ~/common/ui and you will be placing them in the same spot in your minapp
ConsoleDlg.gui
darkScroll.png
osxScroll.png
What does this do?
The "What does this do?" section will be used often in the tutorials and basically explains why we did what we did in the step. In this case, we are copying over the console GUI definition and some graphics. The GUI definition defines what the console looks like as well as some support code. These are all contained in the .gui file, which is a simple text file. Take a look at it in your text editor to learn more. The two .png files are simply graphics files used by the GUI. In this case, scroll bars. The Torque demos use two "variants" of GUI graphics, named "dark" and "osx". "dark" is used when running on Windows platforms, while "osx" is used when running on Macintosh platforms.
2) Modify defaultProfiles.cs
In SimpleTorqueDemo/common/ui/defaultProfiles.cs add the following code:
What does this do?
This adds some basic default GUI information for the Window, Scroll, and Text Edit GUI controls. The default stuff is then inherited by any controls created. Technically you could do this a different way. Instead of adding in default profile information, you could instead add the GUI properties specifically in the console GUI definition (that stuff we talked about in the .gui file), but I decided to do it this way as it was more clear for the tutorial. Its a toss up which way is more technically correct. I prefer this way since i'd most likely be using these same settings on more than one GUI control, hence the purpose of the defaults. If you had instead planned to only use these settings for the console window, then it would be better to define them specifically in the .gui for the console.
3) Modify canvas.cs
In MinApp/common/client/canvas.cs add the following code to the initCanvas() function:
What does this do?
The exec() statement runs the gui definition for the console window. The other statement, (GlobalActionMap) creates a keyboard binding so that when we hit the tilde it will run the toggleConsole function and .. well.. toggle the console :)
Another technical note here is that the Action map really belongs in the default binds but since this minapp doesn't have one (Yet!), it was more clear to put it in here for now.
4) Delete the .dso files from the scripts you modified (not always neccesary but I prefer to do it to make SURE the changes will take effect. This helps to avoid problems later that cause me to lose hair.) and then run the demo. Once at the pretty main menu, hit the tilde and you should see your console.
Summary
Let's just sum up what was required to add this new functionality. In a nutshell all we really had to do was make the GUI definition for the console (although it was already made for us in this case), and then add in support code to use it. The addition of the GUI Profiles that we made (in defaultProfiles.cs) really wasn't directly tied to the addition of the console, but was mainly added because we didn't already have it. That code will allow us to add more GUIs in the future.
This is the first tutorial in this series, and so i'm sure it was rather rough. I'll polish that as we move along in this series. Comments and problems with this one just speak up and i'll get this one cleaned up as well.
I haven't mapped out what the next tutorial will be, but considering our goal for the series and what there is to do, it will most likely be more GUI work. The next one will probably add in support for more of the Torque tools like the GUI editor and Mission Editors. Probably the GUI editor first now that I think about it.
An off the top of my head roadmap for this series (defintely subject to change)
1) Console Functionality
2) Torque Tools - GUI Editor
3) Torque Tools - World Editors
4) Main Menu GUI
5) Play Game GUI
6) Mission Loading
7) Spawning
8) Player Controls
9) Static Objects
10) Weapons & Collisions
11) Vehicles
12) A look at multiplayer
This is completely off the top of my head so we'll see what directions it takes.
Series Overview
With the release of the Basic GUI Demo by James Yong, I thought it would be nice to build a series of tutorials around it. What James released is an excellent stripped down minimal application using Torque. It does nothing more than display a main menu with a background picture and an "Exit" button. That's it. It doesn't even have the standard tools and console in it. It is a perfect starting place on wich to build, and more importantly, learn.
From here on out i'm referring to this base release by James as the MinApp and each tutorial will be build upon that. The goal is to end up with a basic FPS when we're all done.
I am no expert on Torque myself, but I do have about 10 years of game development experience in general. This series of tutorials is as much to teach myself the workings of Torque as it is to teach others. We will be making this journey of discovery together and at any time I am wide open to comments and crisitiscm from the peanut gallery :)
Tutorial Overview
So now that we have the general overview of the tutorial series out of the way, let's begin with tutorial #1. This is a relatively small tutorial. The MinApp is so basic, it doesn't even have the functionality of the development console. This tutorial will add in support for that development tool. This tutorial feels a bit like a hack because we will be copying some files from the standard Torque demo application for our use, but that is simply the best way to do it. As the saying goes, don't reinvent the wheel.
Preperation
If you haven't already downloaded and "installed" the MinApp, then please do so at this point. Right now we're starting from James' original "Basic GUI Demo" so i'm not including a seperate copy for download. You can download it from the original resource here.
For the sake of this tutorial series, we are going to make just a mindset change about the "Basic GUI Demo". From here on out it will be referred to as the "MinApp" and we will be expanding and building upon it in each tutorial. So, let's rename the directory. When you unzipped it you ended up with a directory named "SimpleTorqueDemo". Let's rename that to "MinApp" or "TorqueMinApp" if you need the name Torque in there to keep your stuff organized :) Once you have done that, copy the torque exectuable and support DLLs in there.
Execution
Ok, now we should be all setup, and ready to add console support to the MinApp. To begin with, we are goign to copy over some of the files that come with the official Torque demo app from GG.
1) Copy files from original Torque demo to MinApp
Copy the following files from your original torque example common files to your minapp ones. They will be in ~/common/ui and you will be placing them in the same spot in your minapp
ConsoleDlg.gui
darkScroll.png
osxScroll.png
What does this do?
The "What does this do?" section will be used often in the tutorials and basically explains why we did what we did in the step. In this case, we are copying over the console GUI definition and some graphics. The GUI definition defines what the console looks like as well as some support code. These are all contained in the .gui file, which is a simple text file. Take a look at it in your text editor to learn more. The two .png files are simply graphics files used by the GUI. In this case, scroll bars. The Torque demos use two "variants" of GUI graphics, named "dark" and "osx". "dark" is used when running on Windows platforms, while "osx" is used when running on Macintosh platforms.
2) Modify defaultProfiles.cs
In SimpleTorqueDemo/common/ui/defaultProfiles.cs add the following code:
// JWV: Begin - Added for console functionality
if(!isObject(GuiWindowProfile)) new GuiControlProfile (GuiWindowProfile)
{
opaque = true;
border = 2;
fillColor = ($platform $= "macos") ? "211 211 211" : "192 192 192";
fillColorHL = ($platform $= "macos") ? "190 255 255" : "64 150 150";
fillColorNA = ($platform $= "macos") ? "255 255 255" : "150 150 150";
fontColor = ($platform $= "macos") ? "0 0 0" : "255 255 255";
fontColorHL = ($platform $= "macos") ? "200 200 200" : "0 0 0";
text = "GuiWindowCtrl test";
bitmap = ($platform $= "macos") ? "./osxWindow" : "./darkWindow";
textOffset = ($platform $= "macos") ? "5 5" : "6 6";
hasBitmapArray = true;
justify = ($platform $= "macos") ? "center" : "left";
};
if(!isObject(GuiScrollProfile)) new GuiControlProfile (GuiScrollProfile)
{
opaque = true;
fillColor = "255 255 255";
border = 3;
borderThickness = 2;
borderColor = "0 0 0";
bitmap = ($platform $= "macos") ? "./osxScroll" : "./darkScroll";
hasBitmapArray = true;
};
if(!isObject(GuiTextEditProfile)) new GuiControlProfile (GuiTextEditProfile)
{
opaque = true;
fillColor = "255 255 255";
fillColorHL = "128 128 128";
border = 3;
borderThickness = 2;
borderColor = "0 0 0";
fontColor = "0 0 0";
fontColorHL = "255 255 255";
fontColorNA = "128 128 128";
textOffset = "0 2";
autoSizeWidth = false;
autoSizeHeight = true;
tab = true;
canKeyFocus = true;
};
// JWV: End - Added for console functionalityWhat does this do?
This adds some basic default GUI information for the Window, Scroll, and Text Edit GUI controls. The default stuff is then inherited by any controls created. Technically you could do this a different way. Instead of adding in default profile information, you could instead add the GUI properties specifically in the console GUI definition (that stuff we talked about in the .gui file), but I decided to do it this way as it was more clear for the tutorial. Its a toss up which way is more technically correct. I prefer this way since i'd most likely be using these same settings on more than one GUI control, hence the purpose of the defaults. If you had instead planned to only use these settings for the console window, then it would be better to define them specifically in the .gui for the console.
3) Modify canvas.cs
In MinApp/common/client/canvas.cs add the following code to the initCanvas() function:
// Common GUI's
// JWV: Added for Console Functionality
exec("~/ui/ConsoleDlg.gui");
// Action map for console activation
// JWV: Added for Console Functionality
GlobalActionMap.bind(keyboard, "tilde", toggleConsole);What does this do?
The exec() statement runs the gui definition for the console window. The other statement, (GlobalActionMap) creates a keyboard binding so that when we hit the tilde it will run the toggleConsole function and .. well.. toggle the console :)
Another technical note here is that the Action map really belongs in the default binds but since this minapp doesn't have one (Yet!), it was more clear to put it in here for now.
4) Delete the .dso files from the scripts you modified (not always neccesary but I prefer to do it to make SURE the changes will take effect. This helps to avoid problems later that cause me to lose hair.) and then run the demo. Once at the pretty main menu, hit the tilde and you should see your console.
Summary
Let's just sum up what was required to add this new functionality. In a nutshell all we really had to do was make the GUI definition for the console (although it was already made for us in this case), and then add in support code to use it. The addition of the GUI Profiles that we made (in defaultProfiles.cs) really wasn't directly tied to the addition of the console, but was mainly added because we didn't already have it. That code will allow us to add more GUIs in the future.
This is the first tutorial in this series, and so i'm sure it was rather rough. I'll polish that as we move along in this series. Comments and problems with this one just speak up and i'll get this one cleaned up as well.
I haven't mapped out what the next tutorial will be, but considering our goal for the series and what there is to do, it will most likely be more GUI work. The next one will probably add in support for more of the Torque tools like the GUI editor and Mission Editors. Probably the GUI editor first now that I think about it.
An off the top of my head roadmap for this series (defintely subject to change)
1) Console Functionality
2) Torque Tools - GUI Editor
3) Torque Tools - World Editors
4) Main Menu GUI
5) Play Game GUI
6) Mission Loading
7) Spawning
8) Player Controls
9) Static Objects
10) Weapons & Collisions
11) Vehicles
12) A look at multiplayer
This is completely off the top of my head so we'll see what directions it takes.
#2
01/22/2004 (4:20 am)
Implementation of the GUI editor is in the next tutorial which I am almost finished. You should be able to see it today.
#4
MinApp Tutorial #2 - Torque Tools Support
MinApp Tutorial #3 - Main Menu GUI
MinApp Tutorial #4 - More GUI Work
01/22/2004 (12:48 pm)
Just as a handy cross reference:MinApp Tutorial #2 - Torque Tools Support
MinApp Tutorial #3 - Main Menu GUI
MinApp Tutorial #4 - More GUI Work
#5
01/22/2004 (4:47 pm)
Great idea - I think it's good to learn how to do it from the ground up. I found one mistake though - when adding the code to canvas.cs, you should mention that it needs to be pasted into the "initCanvas" function. I pasted it at the end, and the demo kept crashing on me. (I figured it out by refering back to the original example.)
#6
01/22/2004 (4:50 pm)
My bad. Thanks for pointing that out.
#7
01/22/2004 (4:53 pm)
I've updated the resource to make that more clear. I also added a file for download. The ZIP file contains the completed version of the MinApp for this tutorial.
#8
I have a small suggestion for the first tutorial. Before digging in and playing with files I think it would be nice to have a small introduction to the organization of files.
- The two avenues of development, scripting and the actual game engine.
- Guidelines on when you should play with one or the other.
- Explain the significance of main.cs, what do the 'common' and 'demo' folder contain and how they relate.
Basically a listing of the files/folders in MinApp at the start with a small 1-2 sentence explaination on its purpose and how it ties in to the whole.
Again thanks you for your contribution.
01/23/2004 (10:27 am)
Thank you for your work in this area. It is really needed. I have a small suggestion for the first tutorial. Before digging in and playing with files I think it would be nice to have a small introduction to the organization of files.
- The two avenues of development, scripting and the actual game engine.
- Guidelines on when you should play with one or the other.
- Explain the significance of main.cs, what do the 'common' and 'demo' folder contain and how they relate.
Basically a listing of the files/folders in MinApp at the start with a small 1-2 sentence explaination on its purpose and how it ties in to the whole.
Again thanks you for your contribution.
#9
01/23/2004 (2:09 pm)
Yeah I could do that. Not a bad idea.
#10
A big pat on the back there John!!
01/28/2004 (3:32 am)
All cred for this project, John. I was thinking about making a tutorial on how to start things up in Torque based on my own experience but with this great idea there simply is no need ... !! :-)A big pat on the back there John!!
#11
01/29/2004 (1:51 pm)
This is awesome! Thank you very much John, I was struggling with Torque and this guide has helped me greatly in understanding some of the basic stuff. Thanks again and keep up the work.
#12
Many thanks in advance.
01/31/2004 (5:46 pm)
Fantastic. Does anyone know where I can find detailed info on what the code does that was added to defaultprofiles.cs?Many thanks in advance.
#13
01/31/2004 (6:24 pm)
Did I not explain it well enough? Or are you asking for like deatiled information on the various properties for GUI controls and what they do?
#14
Many thanks
01/31/2004 (9:16 pm)
Yeah, I was hoping you could point me in the direction to find detailed info on the various properties.Many thanks
#15
02/02/2004 (5:06 am)
I am not aware of such a document.
#16
Everything you put in your "road map" is of interest to me. I'm looking forward to reading more.
Thank you!
03/12/2004 (7:55 am)
Yes, keep the tutorials coming! I've been away from programming for a while now and was feeling like I was in the deep end of the pool with Torque. This is helping me to learn how to "swim."Everything you put in your "road map" is of interest to me. I'm looking forward to reading more.
Thank you!
#17
Keep up the great work!
06/10/2004 (10:46 am)
A great introductory tutorial to Torque's demo application! Thanks for your help John! Another great example of the communities sharing of knowledge of understanding and getting to grips with the nitty gritty.Keep up the great work!
#18
06/15/2004 (3:41 pm)
It would help for a newbie if you could please tell us what is the common directory and client directory used for?
#19
Just wondering. Newbie here.
06/15/2004 (4:00 pm)
Is it possible that when adding the code to the 2 files above, it could be added into a new 3rd file and referenced from the 2 files? Kind of like a separate class file (for us C#'ers)?Just wondering. Newbie here.
#20
08/22/2004 (2:45 pm)
Although a simple tutorial, working through to tutorial 4 really helps get a kick start on how the GUI works :) Nice work, look forward to more. 
Torque Owner Joe Bird