[Tutorial] Making a Gui

Poll

Did you find this helpful?

Yes
No

Author Topic: [Tutorial] Making a Gui  (Read 40755 times)

Making Gui's
Something not many people know how to do...

Introduction
I have decided to make this tutorial because there are barely any recent ones on this topic. I have recently started to learn how to make GUI’s myself, but I think I know enough now to teach other people how to make GUI’s.  In this tutorial I will:
  • Explain how to get the Mod Editor in the first place
  • Explain what some of the different controls are
  • How to get those cool looking round buttons
  • What the various characteristic controls do
  • How to make your buttons do things
  • How to do various other things
  • Give you some references
So here we go.
*NOTE* The [number] boxes indicate that the thing I'm talking about can be found in the diagram at the bottom, so if you have some trouble and need help visualizing it, check the diagram down there and look for the labeled part you are looking for. They also have links to the diagram part of this tutorial *END OF NOTE*

Index
and all that jazz

To use this index, press cntrl f and type in the code that pertains to the specific part you are trying to find:
[GT1] -------------- Gui's and what they are
[GT2] -------------- Starting out, getting mod editor
[GT3] -------------- Making your own GUI
[GT4] -------------- "Characteristic Controls"
[GT5] -------------- THE DIAGRAM
[GT6] -------------- The... Gallery?
[GT7] -------------- Some other Gui Controls
[GT8] -------------- The final words

Gui's
   And what they are...

[GT1] Gui stands for Graphic user interface, which is exactly what this is. Everything you see right now, all the windows on your computer are GUI's. Gui's make it easy to  interact with programs and such without having to type console commands and such. Instead of typing a function into the console like:
Code: [Select]
findClientByname("Blah").player.kill
You can press a button that carries out that specific function. Now you know how in Blockland we have commands like /magicwand? Well that admin wand button on the Admin menu GUI carries out the function to give you that admin wand as if you were typing it in game. You can create Gui's to make it easier for The rest of us to use your add-on, plus I think it's fun to make them. It (if you have a need for a Gui) can put your Add-on above the rest.

Starting out
Getting Mod editor

[GT2] The first step to being able to make your own GUI's is to get the GUI editor which comes with the Mod editor. Now to get mod editor you need to do a simple shortcut change for Blockland. First, you right-click the Blockland shortcut on your desktop, and then on the drop-down menu, click properties. You go into the target text box and add to the end of  C:\Blockland\Blockland.exe, -mod editor. So in the end it should look like this: C:\Blockland\Blockland.exe -mod editor. Don’t change anything else and then click OK at the bottom and you should be able to open Blockland and press f10 to open the GUI editor and press f11 for mission editor. *NOTE* My computers OS version is Windows Vista, and as Truce said, XP installs Blockland into Program files which has a space in it. So if you use Windows XP, you will need to put "" (quotes) around the path file in order for it to not get screwed up. So it should look like this: "C:\Program Files\Blockland\Blockland.exe" -mod editor



Making a GUI
getting to the meat...

[GT3] Now load up Blockland and press f10. You can use the drop down menu[1] at the top to look through various other GUI’s for the game. Now once you are done looking through those, you can get on to making your own. To make your own, you click on the file button[2] in the top left hand corner and click New Gui. A menu should pop up and on this, you name your GUI. For this, just name it Testgui and then click Create. Now on the new menu you should see a turquoise color. To make new controls, you obviously click New Control[3] and then click on the drop-down menu, what new control you want to put in your GUI. Before we get to creating the GUI, I am going to go through some of the GUI controls that I know and what they do:

  • Gui Bitmap cntrl With this, you can insert pictures in png format into your GUI
  • Gui Bitmap Button cntrl With this, you can insert different button designs
  • Gui button cntrl Not very pretty, but it is a button.
  • Gui check box cntrl Obvious, it makes a checkbox
  • Gui Ml text cntrl Makes a ml text insert thing
  • Gui ML text edit cntrl Does that ^^^ only you can edit it in game.
  • Gui slider cntrl Makes a slider that you can control things with
  • Gui scroll cntrl it’s a scroll bar! One of my favorite controls.
  • Gui Slider control This allows you to increase a number and decrease using the buttons it comes with
  • Gui swatch control This does nothing, it’s simply for aesthetics, makes GUI’s cool lookin’
  • Gui various text cntrls Various regular text controls
  • Gui Window cntrl Probably the most important control, it’s the window!

These are the basic controls that you will need to become familiar with to make cool GUI’s. Although I won’t be going through how to use all of them, I will be going through most of them. Now, I am going to go through the steps to making your own Gui. First off, start by click the New control button and on the drop-down menu, click Gui Window Control and change it to whatever size you want to and try to center it. Here is what it should look like:


Now that we have that done... Oh wait! You see that menu to the right-hand side? With all those text boxes and stuff? Well those boxes control the aspects of the object they apply to. See the text[4] box? Well, in that box you can type in the text you want to appear on the Control. So type Test Gui and then click apply and in the top left hand corner of the GUI window, it should say Test Gui. But wait! Were not done! We have to add buttons and stuff like that! So lets do that right now. Before you add that new button control, right click the window control to parent the button to the window control. Doing this makes it so that the new control is mounted on the Window and a part of the window. If you did that right, a colorful outline[5] should appear around the window. So after doing that, click the New control button again and choose one of the two button controls. I prefer bitmap button controls since you can change what they look like and make your GUI look pretty. So pick Bitmap button! DO IT! Now, position it anywhere you want. And you might notice that it's an ugly gray box with the button text running off, let's fix that. So in the aspects window[6] look for the thing at the top that says: Profile. Click on that and change it to Blockbutton profile and then click apply. Then you can change the button text to whatever and then we come to making it those cool rounded buttons. To do this, you need to scroll down the aspects menu until you find bitmap. In that box, type this:
base/client/ui/button1
And then click apply again. It should look cool now! But one problem, it's white. You can fix this by typing in a standard RGB color code with alpha (transparency) to make it green, you would type in the mcolor box:
0 255 0 255
The first number is the intensity of red, the second is the intensity of Green, the third is the intensity of Blue, and the last number is the transparency. So mess around with that if you want. Now find the command box for the button control. In this, type in: Testcommand(); and we'll get to that later in the scripting. Now go back and click the GUI window control and type in the command box: canvas.popdialog(Testgui);
and that is the command to close the window, then find the Accelerator box and type into that: escape. These two last steps will allow us to close the window by pressing the Esc button on our keyboard. Then type in the close command box the same thing you typed in the command box: canvas.popdialog(Testgui); And now it seems we are done. Other things you could do are:
Insert a Gui swatch control to make it look pretty, make sure to change the color to something like 175 175 175 255 and then parenting it to the GUI window, and the parent the button to the swatch control. You could also insert a text control to title it more. And there are many more controls you can experiment around with. I'll also teach you to use some of the other controls later on. Now hit save and choose a directory to save it in, I would save it in Add-ons. Here is my final finished GUI:

I know, it's hideous, but once you (and I) get better, we can make cooler looking GUI's.Now before you ex out of the GUI editor, make sure to change the GUI back to Main Menu GUI and then quit normally. Now we get to the coding part. Go to your add on's folder and open the GUI file you just made in Notepad, it should look something like this:
Code: [Select]
//--- OBJECT WRITE BEGIN ---
new GuiControl(Testgui) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 2";
   visible = "1";

   new GuiWindowCtrl() {
      profile = "GuiWindowProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "149 66";
      extent = "337 340";
      minExtent = "8 2";
      visible = "1";
      command = "canvas.popdialog(Testgui);";
      accelerator = "escape";
      text = "Test GUI";
      maxLength = "255";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "1";
      canClose = "1";
      canMinimize = "1";
      canMaximize = "1";
      minSize = "50 50";
      closeCommand = "canvas.popdialog(Testgui);";

      new GuiSwatchCtrl() {
         profile = "GuiDefaultProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "59 52";
         extent = "223 53";
         minExtent = "8 2";
         visible = "1";
         color = "175 175 175 255";

         new GuiMLTextCtrl() {
            profile = "BlockChatChannelSize7Profile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "4 9";
            extent = "223 29";
            minExtent = "8 2";
            visible = "1";
            lineSpacing = "2";
            allowColorChars = "0";
            maxChars = "-1";
            text = "CLICK DA BUTTON";
            maxBitmapHeight = "-1";
            selectable = "1";
         };
      };
      new GuiBitmapButtonCtrl() {
         profile = "BlockButtonProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "97 181";
         extent = "143 46";
         minExtent = "8 2";
         visible = "1";
         command = "Testcommand();";
         text = "PUSH ME";
         groupNum = "-1";
         buttonType = "PushButton";
         bitmap = "base/client/ui/button1";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         mKeepCached = "0";
         mColor = "255 0 255 255";
      };
      new GuiBitmapCtrl() {
         profile = "GuiDefaultProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "20 163";
         extent = "65 64";
         minExtent = "8 2";
         visible = "1";
         bitmap = "base/client/ui/planterrors_small/planterror_limit";
         wrap = "0";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         keepCached = "0";
      };
      new GuiBitmapCtrl() {
         profile = "GuiDefaultProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "249 164";
         extent = "65 64";
         minExtent = "8 2";
         visible = "1";
         bitmap = "base/client/ui/planterrors_small/planterror_limit";
         wrap = "0";
         lockAspectRatio = "0";
         alignLeft = "0";
         overflowImage = "0";
         keepCached = "0";
      };
   };
};
//--- OBJECT WRITE END ---
Now before you close this, type in this under the //---OBJECT WRITE END ---  part:
Code: [Select]
function pushtestgui(%Gui)
{
   %Gui = canvas.pushDialog(Testgui);
}
This is the function to open it, well bind the test key later. Now save this and send it to a .zip file named Script_Testgui and then we go to the coding side. Open up the ol' Notepad and type in this:
Code: [Select]
exec("./Testgui.gui");
moveMap.bind(keyboard, "m", pushTestgui);

function testcommand()
{
MessageBoxOK("Thanks!","You have just pressed a button on a test GUI!");
}
Now this should make a keybind where if you press m it will open the GUI. Now once you have that done in Notepad, save it as a Client.cs and put it in the zip along with the GUI. Make sure to package that with a description.txt and then open up Blockland again. Look in the console for any syntax errors and then load up a server. Once you load, press cntrl m and see if it pops up. If it does, you did it! If it doesn't, go back through the steps again and see what you did wrong. And there you have it, your first GUI! It may not do much (Open a window that says thanks for clicking the button) but, I hope that it started you off. From here you can make more and more advanced GUI's and have some fun making them, I have made several myself and coded some of them. I'll show them later (at least my good ones.) Anyway, now we go to the other parts of this tutorial

Characteristic controls
and what they do...

[GT4] Now you might have noticed all of those "Characteristic controls" on the right-hand side of the GUI editor while you were making your own GUI. Well, these basically control everything about the Control they apply to. I'll go through some basic ones in this part.

Text: This controls what text goes on that control
Profile: This controls the design of the control
Visible: This controls whether you can see it or not
Variables: This allows you to specify a variable that you want the control to apply to, like for check box controls, you can apply a Global Variable to determine wether it's checked or not.
Command: This is the command that the control has
Accelerator: This is a specific button that you map that when that button is pressed, it activates the command specified to that control.
Maxlength: this is the max length for the text on the Control, for example a Text edit control you would put a limit on to cap how many letters they can type into that

It's getting too laggy for me to type any more on this post, one second.
« Last Edit: April 30, 2009, 04:51:40 PM by AGlass0fMilk »

Continuing:
Canmove: This one is obvious, determines whether you can move the window or not
Canclose Canminimize can maximize: All obvious
Close Command: this is the command to close the window, without it, you couldn't close the window!
Button type: Obvious...
Bitmap: this is the picture that the bitmap control thing will have in it, just put the directory for the picture for example: Base/client/ui/button1 will give you a cool round button as explained in the tutorial.
mcolor: Sets the color of the control
And then there are many more but these are just the basic ones, experiment!

THE DIAGRAM
Now I get it!
[GT5] Here is the diagram showing stuff:

Hope that helps you visualize it!

The... Gallery?
some of my Gui's

Here are some of my GUI's, they were for the AziCity mod, but that has been postponed:

AziCity Memberlist, it's not done

AziCity Text message window - I wanted to implement the cell phone into AziCity like Darklight's city rp

AziCity Cell phone GUI, It's the cell phone for AziCity

AziCity Rules Creator, this one sucks, it was my first operational GUI

Some other GUI controls
COOL!

Now we get into some other controls and how to use them, like the scroll control (My favorite =D)
Scroll Control
To use the Scroll control, you parent it on a window and then right click the scroll control to parent a Text control to it (ML text, Ml Text edit, Text, Text Edit, Ect....) or anything else. And then, once its in game, it should scroll according to the object inside it. Make sure to fit the Scroll bar Characteristic controls to your needs.
Check box control
Also, you can use the check box control by assigning a Global variable to it (IE: $TestGUI::checkboxtest) and then if it's check, the Global variable will be 1 and if it's un-checked, the Global variable will equal 0 so you could use it in code like this:
Code: [Select]
if($TestGUI::Checkboxtest == 1)
{
   //Some stuff you want to happen if it's checked
}

GUI bitmap control
This is a very useful GUI control, it allows you to insert pictures into your GUI. You can create custom icons by placing the picture (in PNG format) into your zip folder. Then, in your GUI, you place a GUI Bitmap control and in the Bitmap box the directory for your image:
Code: [Select]
add-ons/add-on name/icon name

For example, I used a bitmap control in my cell phone GUI, see that little battery icon? That's a bitmap. So for that I typed in the bitmap box:

Add-ons/Azi_Guis/Icons/battery
Then I clicked apply and then battery appeared. And there you go! A picture on your GUI.
A fond adieu
some final words

[GT8] I hope you found this tutorial helpful, and if I made any mistakes or if there is something else that you want to know, please post it! I'll try to help to the best of my abilities. Now to some sub-sections, Yay =D
References

These references are not just for GUI making, but for torque too.
References:
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5
And...
Reference 6
Credits to people
This is a list of people who helped me in the first place:
Tom
Space Guy
Resonance_Cascade
and any one else who posted on my topic
Now one final note, there are some controls for the GUI editor. You can nudge the Control you are handling using the arrow keys to get an exact area, it is very useful when you need it just right.
Thanks guys. And thank you for reading this, hope this was helpful and, have fun...
« Last Edit: April 30, 2009, 06:45:06 PM by AGlass0fMilk »

Wow, your tutorial can be really helpful, thanks ;)

Oops, forgot the diagram... Oh god, now it's too small...

And my other works...
Ok, its all there now. Have fun with it.
Darn, I forgot some of the controls...
NOW IT IS DONE!
Don't forget guys, tell me things that I got wrong, and things that you want to know and I'll try to get to them.
« Last Edit: April 28, 2009, 02:14:45 PM by AGlass0fMilk »

What do we name the main script?

What do you mean by that? The .cs file with the functions in it? You can name it Client.cs (so people won't have to download the GUI) and server.cs (Which I think makes people download them, but I'm not sure) And the GUI file should be named whatever you named it (by default).

Cell phone gui? Have your released it O_o

No, it's not done. Plus it will be packaged with the AziCity mod, but I don't think we plan on releasing that to the public, we will probably just give it to people in high places and our friends, plus people who worked on it (DUH)


It won't work for me it says C:\Program Files\Blockland\Blockland.exe -mod editor does not exist.
Fixed but the name has to be "C:\Program Files\Blockland\Blockland.exe" -mod editor
« Last Edit: April 30, 2009, 04:01:28 PM by MagicAhrim »

You probably have XP or something older than Vista.

You probably have XP or something older than Vista.
yeah i have xp like alot of people.

You probably have XP or something older than Vista.

Computer version doesn't matter. If their Blockland path has spaces in it, then you need the quotations or it won't work. XP Just so happens to install into Program Files by default, which has spaces, where Vista doesn't.

Oh, I'll put that in the guide so as for people not to get confuzzled.

How do i reopen a file i was working on then closed? I already have it ina add-on like other gui but it won't show up in the list of them.
« Last Edit: April 30, 2009, 08:25:58 PM by MagicAhrim »