zeh@Posted: Sat Aug 07, 2004 9:10 pm :
Hi, and welcome to the third tutorial in the Complete GUI Scripting series, courtesy of doom3world.org publishing and partners. In this tutorial you'll learn how to set up and use the built-in GUI editor, to create GUI scripts using a more visual approach. And while the core of script editing will always be done on the script file itself, this GUI editor will be an invaluable tool in designing and previewing them.

Complete GUI Scripting - 2: Using the built-in GUI editor

Something that's cool with the DOOM 3 engine is that it has several built-in editors, allowing you to edit the game content right out of the box. While this can be pretty wacky - people would have to run the game, *then* the editor to open some content for edition - it means that you can preview whatever you are doing in real time.

This is pretty well know for map editing - the map editor is integrated with the game - but what many people don't know is that many other editors are integrated into the game too - and this include, among many others, a GUI editor.

To launch the GUI editor, the normal thing to do is to fire up the game, and type

Code:
editguis


DOOM 3 will 'close' and the GUI editor will launch.

There is, however, one catch. Like other editors, it launches a new windows-like application, and if you are using some low resolution on the game, you'll be stuck in a unusable resolution, and your mouse cursor will probably be gone for some reason.

That's why it's advisable to create a new shortcut for the game, or use a new DOOM 3 script to launch it. To do this, first, duplicate the "Doom 3" shortcut on your system and give it a new name, like "Doom 3 GUI Editor". Right-click it, edit its properties, and change its target from:

Code:
<whatever>\Doom3.exe


To:

Code:
<whatever>\Doom3.exe +exec run_guieditor.cfg


This allows you to run the game and execute a DOOM 3 script file immediately upon loading. You have to create a this new script file, though: open up notepad, and type this into it:

Code:
seta r_fullscreen "0"
seta r_gamma "1"
seta r_mode "8"
vid_restart
editguis


And save this as run_guieditor.cfg inside your DOOM 3's "/base" folder.

What this script does is:

1. Turn into windowed mode;
2. Reset gamma (so you'll have the original system gamma);
3. Set a high resolution (1600x1200);
4. Restart video
5. Open up the editor.

A note about step 3: even though r_mode is supposed to be 1600x1200, it looks that in this case it just forces the editor to be on a safe resolution. I use 1152x864 on windows myself, and using this shortcut/script combination, it always opens the GUI editor on my own resolution..

With that said, we're ready to open the editor. Double-click the shortcut you're just created, and the editor is launched.

Image
This is the main window on the GUI editor. The first thing you'll notice is the editor name - "Quake IV GUI Editor". This is because this editor was developed by Raven Software, which is producing Quake IV. It was probably put on the DOOM 3 engine to give mod authors an easier start on designing GUIs. At least that's my theory...

Anyways, it's quite a straightforward program. The first thing you'll want to do is to go to the "View > Options..." menu, make sure the "Ignore Desktop Select" option is off on the "General" tab, and go to the "Grid" tab and set your options as follows:

Image

I'm suggesting this to provide an easier editing interface; if you don't turn the grid on, there's no way to know what's inside the 640x480 editing area and it's easy to get lost. Feel free to skip this step, but be warned.

With that done, go to the menu and select "File > New" (or press CTRL+N) to create a new GUI script. Your editing area is filled with an empty GUI script.

Image
On the right side of the screen (or wherever you moved it) you can see the "Navigator" window, which indicates which elements are visible and how they relate to each other. It works a lot like the way you expect a layer list to work on Photoshop, for example. Look at the list and, sure enough, our brand new GUI has only a Desktop windowDef, and it is visible. Clicking on it...

Image
...selects it. This means two things: there's a selection halo visible on the editing area, and the windowDef attributes are visible on the "properties" window.

The selection halo is useful if you want to move the windowDef around, or resize it: just click and drag on a corner/side handler to resize it (as you'd do with any modern graphic editing package), or click and drag the windowDef itself to move. You can also use the keyboard keys: the arrow keys move the windowDef around one pixel at a time, and SHIFT+arrow keys resize it.

On the properties list, you'll see all the attributes we used on our previous lesson to create a new windowDef. In this case of a simple Desktop windowDef, only the rect is available, and that's all it needs anyway.

Since this is our main Desktop windowDef, we won't be messing around with it too much. It's time to add another windowDef to spice things up.

Image
Go to the "Item > New > windowDef" menu and add a new windowDef. Yes, I know, there a lot of other items on the menu that can be added, but hold on, we'll get to that on later lessons...

Well, after adding our new windowDef, it sits there on the GUI. Double-click it and a nifty new window will open, with several properties to be edited. Type in a name for it (I'm using "Title") then go to the "Text" tab, since we'll be doing a text element like we did in the previous lesson. Here's what I've filled it with...

Image
It's pretty easy and you can see how all properties available here translate to the attributes we manually created on the previous lesson. The good thing here is that you don't have to know all property names by memory or look into a GUI reference (which doesn't exist yet anyways): you can just play with the settings and see the result.

After filling the data, press OK to see it applied.

Image
There it is, quite easy. Be sure to resize the windowDef to see all text, of course, as well as position it somewhere you want. Pretty cool, uh? Really easy, and the real-time preview is a real godsend.

We'll add another windowDef: this time, an image, just like we did in the previous tutorial. Select "Item > New > windowDef" again, double click the windowDef that was created, give it a name (I'm using "pentaImage", since I'm using a pentagram doodle) and then go to the "Image" tab. use this data:

Image
What I'm doing here is giving it a backcolor - since I want the drawing to be fully visible - and assigning a material to it. Again, the "material" here refers to the path and filename used for the material. I'm using "tut2_penta" as a name, so this means "<doom3>/base/tut2penta.tga" (the file is attached to the tutorial source files, you can find the link to download it in the end of this tutorial).

There are other options available, but I'll leave them as is for now. Feel free to try them out, though.

Pressing OK will redraw the screen with our new windowDef options.

Image
Sure enough, the image is applied to it. You can resize and move the windowDef, and see how it works visually.

You can will also notice the new properties - background, matcolor, and so on - were applied to the windowDef and are shown on the property window.

Other thing.. it's important to remember that, even though I made one text windowDef and one image windowDef, it doesn't mean you have to *chose* between one of these functionalities. You can have as many properties as you wish on it, and you could combine a background image with text on it, for example. The windowDefs I created are simple examples, but that doesn't mean they *have* to be like that.

Okey, now comes the cool part. While previewing it in the editor is close enough to seeing it in the game, it still isn't... perfect. It's static, and if you're playing with animations or scripting (we aren't yet), you won't be able to see the results.

But now, remember you are still inside of the DOOM 3 engine, and you are, in fact, able to test it right away without having to run it again and using the "testgui" command on the console. Select the "Tools > Viewer" menu (or press CTRL+T)...
Image

...and a new window pops up, which is the GUI viewer rendered by the engine itself...

Image

...and it works! While we have built an static GUI that doesn't depend that much on the in-game player for testing, the GUI viewer is a powerful tool and will help us a lot in the future, when testing animations and scripts.

And, of course, what the GUI editor has created is the GUI script code itself. Save the GUI into a file - I'm using the "tut2.gui" name myself - and have a look at it. This is the code it generates,

Code:
windowDef Desktop
{
   rect   0,0,640,480
   windowDef Title
   {
      rect   15,10,200,50
      visible   1
      forecolor   1,1,1,1
      text   "Hello."
      textscale   1
      font   "fonts/english"
   }
   windowDef pentaImage
   {
      rect   190,124,260,261
      visible   1
      background   "tut2_penta"
      matcolor   1,1,1,1
      backcolor   0.50196081,0.25098041,0,1
   }
}


Pure, simple, GUI script code.

This sums it all. To wrap up this lesson, I'd like to say something important. Why didn't I just show how to use the editor in the first place, in the previous lesson, instead of showing how to write scripts from scratch?

Well, to answer that, once again, I'll have to compare GUI scripting to HTML... that is: you can do cool sites on, say, DreamWeaver, but unless you have a wide knowledge of the way HTML code works, you'll never be able to produce quality pages. You know, the same applies to GUI scripts. A WYSIWYG tool is very cool to create GUI files fast and previewing them, but you WILL have to dwell with the code and the way it works deep inside if you want to create GUI scripts that are more than a simple box with text and an image.

Also, sometimes, changing the code itself will be faster and easier than opening a .GUI file on the GUI editor, so keep in mind...: the code is your friend.

On most of the next tutorials, while we'll use the official GUI editor, we'll also get a lot more into technical details, so be sure to play around with this powerful GUI editor in the mean time.

Download source and example files



BNA!@Posted: Sun Aug 08, 2004 8:41 am :
Thumbs up zeh - many thanks!



Vash@Posted: Sun Aug 08, 2004 10:21 am :
Going to read it all later. From my skimming, it looks great.



dataangel@Posted: Thu Aug 12, 2004 4:51 am :
This tutorial mentions there are other builtin editors. What others exist besides the map one?



zeh@Posted: Thu Aug 12, 2004 5:15 pm :
dataangel wrote:
This tutorial mentions there are other builtin editors. What others exist besides the map one?


From a previous message by rich_is_bored, these are the mod tools included in the game, some are editors and some are tools:

Code:
  debugger              launches the Script Debugger
  dmap                  compiles a map
  editAFs               launches the in-game Articulated Figure Editor
  editDecls             launches the in-game Declaration Editor
  editGUIs              launches the GUI Editor
  editLights            launches the in-game Light Editor
  editor                launches the level editor Radiant
  editParticles         launches the in-game Particle Editor
  editPDAs              launches the in-game PDA Editor
  editScripts           launches the in-game Script Editor
  editSounds            launches the in-game Sound Editor
  renderbump            renders a bump map
  renderbumpFlat        renders a flat bump map
  roq                   encodes a roq file
  runAAS                compiles an AAS file for a map
  runAASDir             compiles AAS files for all maps in a folder
  runReach              calculates reachability for an AAS file



MNeMiC@Posted: Sat Aug 28, 2004 5:27 pm :
There should be tutorials which describes some basics on all of them.

BTW! Awsome tutorials Zeh!



b0ksah@Posted: Mon Sep 06, 2004 6:46 pm :
Bumpy :) Bump



heXum@Posted: Wed Sep 08, 2004 4:16 am :
Does the gui refer to the image file that you apply to it or does it imbed it into the gui file?

In other words, in this tutorial, if he was to send this map to a friend (the one with this gui in it) would he just need to pak up the .gui or the .gui and the .tga?



zeh@Posted: Wed Sep 08, 2004 11:50 am :
heXum wrote:
Does the gui refer to the image file that you apply to it or does it imbed it into the gui file?

In other words, in this tutorial, if he was to send this map to a friend (the one with this gui in it) would he just need to pak up the .gui or the .gui and the .tga?


Unless it's a material already included in the game (so everyone would have), he'd need to send both. Think of a GUI script as being an HTML file, and materials as being images. They're all external; GUI scripts are simple text files that refer to them.



djPhrank@Posted: Thu Oct 14, 2004 3:46 am :
I'm having two problems with the script editor.

1. When I try to change the target of the Doom 3 shortcut I get an error that says the path in the target box is not valid.

2. I can open the GUI editor form the console, but the workspace is blank. I can open files and everything, but the workspace is always blank. I tried clicking around and found that I could select objects even thought I could not see them. WTF?

Any help would be greatly appreciated. Thanks.



zeh@Posted: Thu Oct 14, 2004 1:34 pm :
djPhrank wrote:
1. When I try to change the target of the Doom 3 shortcut I get an error that says the path in the target box is not valid.


if you have spaces on your d3 dir location (and it uses quotes to enclose it), put the new command line arguments outside of the quotes. As in

Code:
"c:\whatever\doom3.exe" +exec run_guieditor.cfg


Quote:
2. I can open the GUI editor form the console, but the workspace is blank. I can open files and everything, but the workspace is always blank. I tried clicking around and found that I could select objects even thought I could not see them. WTF?


No clue. Most likely, it's not finding the materials used on the gui scripts you opened. Be sure to have the materials/textures/shaders extracted too (to the right dir) when opening gui scripts from d3 itself, or to have your own shaders correctly available to the game. Remember that materials are relative to the current mod dir (/base or /moddir) and not to the gui script location.



djPhrank@Posted: Thu Oct 14, 2004 11:31 pm :
Well, the shortcut thing helped. It works fine now. Thanks.

Unfortunately, I still can't use the editor. When you press file > new, you get a black screen with a grid on it. When I press file > new, my workspace is a blank grey screen. I don't know what to do.

I have no problem skipping the editor, and just coding my GUI in notepad, but how do I test them without the editor? I tried the testgui command, and that works great, except I don't have any mouse functionality. Any more advice would be greatly appreciated. Thanks again.



zeh@Posted: Fri Oct 15, 2004 1:21 am :
djPhrank wrote:
Unfortunately, I still can't use the editor. When you press file > new, you get a black screen with a grid on it. When I press file > new, my workspace is a blank grey screen. I don't know what to do.


This isn't much of a help, but I've seen some people reporting that to me before. I never learnt how to avoid it though, as it never occured to me. Perhaps it's the same problem that happens with the map editor when antialiasing is turned on - so, just as a last resort, if you have antialias/fsaa/whatever on on the game, try turning it off.

Quote:
I have no problem skipping the editor, and just coding my GUI in notepad, but how do I test them without the editor? I tried the testgui command, and that works great, except I don't have any mouse functionality. Any more advice would be greatly appreciated. Thanks again.


It depends which kind of gui you are working on. I prefer doing it on text editors and testing them in game directly much more - but basically because you can test then on a real environment (you just can't test a hud gui on the editor, for example). For testing hud and menu guis, the best way is to fire any map and do a reloadguis each time you change the gui script (on another window). With in-game guis for levels, I'd say the same applies, although maybe you'll need to restart the map. In this case, testing it on the gui editor would be really better unless it's a very complex gui script.



djPhrank@Posted: Fri Oct 15, 2004 3:01 am :
Turning off Anti-aliasing fixed the problem. Thanks a lot. Is there a console command to turn off AA? If so, you should add it to run_guieditor.cfg It would solve some future problems for others.

Thanks again



evilartist@Posted: Sun Nov 28, 2004 11:28 pm :
I've sort of got things down. I can successfully open the GUI editor, but I'm having problems creating the .cfg file you suggested creating. For starters, what is a .cfg file" Second, how do I create it? Notepad only creates .txt files. Am I missing something here?

I have no choice but to open the GUI editor up by having the shortcut's target like this:
Quote:
.../Doom3.exe" +editguis

What a crappy, small resolution I get...



zeh@Posted: Mon Nov 29, 2004 12:19 am :
evilartist wrote:
I've sort of got things down. I can successfully open the GUI editor, but I'm having problems creating the .cfg file you suggested creating. For starters, what is a .cfg file" Second, how do I create it? Notepad only creates .txt files. Am I missing something here?

I have no choice but to open the GUI editor up by having the shortcut's target like this:
Quote:
.../Doom3.exe" +editguis

What a crappy, small resolution I get...


A .cfg file is just a plain, standard text file, it simply has a different extension. You can create it with notepad, editpad, ultraedit, wordpad, DOS echos... any text editor will do.



BNA!@Posted: Mon Nov 29, 2004 12:22 am :
evilartist wrote:
Second, how do I create it? Notepad only creates .txt files. Am I missing something here?


Save it as .txt and then rename it to .cfg or change the file saving dialogue drop down from "text files" to "all file types".



evilartist@Posted: Mon Nov 29, 2004 12:57 am :
I had no clue I could independently choose a file extension by picking "All File Types"!

I was confused at first because normally, when a file has an extension that certain software supports (like .tga with Photoshop), simply renaming the file "picture" (picture.tga) with "picture.bmp" will make the whole file name "picture.bmp.tga". But now I've got the idea.

Also, I still couldn't get Doom 3 to read the .cfg. My real problem was that I placed the file in the "Doom 3 folder," as quoted by zeh himself. Did zeh mean the base folder or the Doom 3 folder? It worked when I put it in the base folder.

I still, however, learned new, useful information. Thanks.



zeh@Posted: Mon Nov 29, 2004 1:53 pm :
evilartist wrote:
I had no clue I could independently choose a file extension by picking "All File Types"!

I was confused at first because normally, when a file has an extension that certain software supports (like .tga with Photoshop), simply renaming the file "picture" (picture.tga) with "picture.bmp" will make the whole file name "picture.bmp.tga". But now I've got the idea.


Watch out: that only happens if you have extensions display turned off on your windows configurations. If you're a medium-to-advanced user (that includes people playing with modding), you should never, ever have that turned off. If you turn that off on the folder options, then you'll be able to change the file extensions normally.

Quote:
Also, I still couldn't get Doom 3 to read the .cfg. My real problem was that I placed the file in the "Doom 3 folder," as quoted by zeh himself. Did zeh mean the base folder or the Doom 3 folder? It worked when I put it in the base folder.


Oops - it's wrong! It should go on /<Doom 3>/base yes, not on /<Doom3>. Thanks for pointing that out, I'll fix it.



SeanWar@Posted: Sat Jan 08, 2005 7:02 pm :
When I try to resize the desktop windowdef by the arrow keys or by grabbing the corner\side handler it wont resize or even move. Anyone know why this is happening to me?