This page was pulled into the static site from the original vBulletin thread — rescued from the Internet Archive or the vBulletin backup database after the forum upgrade made the live threads unreachable; original authorship is credited below.
This is going to be a (hopefully) simple tutorial that will serve as an introduction to dialogs. It will not teach you how to do things in the most effective or dynamic way possible, but is instead meant to explain how dialogs work to the point where the reader can start experimenting on his/her own.
If you are viewing this on http://starcraft-2-galaxy-editor-tut....thehelper.net , chances are that some tags are inactivated. For the best reading, read it here.
Table of contents
- Introduction
- Tutorial Goal
- Time to work
- Conclusion
1. Introduction
Assuming you wandered upon this tutorial by mistake, you might now be wondering: What's a dialog?
If you have experience with the warcraft 3 editor, you might've used dialogs back then for things like choosing a hero.
It probably looked something like this:
(credit goes to revolver for the picture)
In starcraft 2, the dialog was remade into a very powerful tool that you can use to create the most fascinating things.
Basically, a dialog is a surface you can create on the user's screen on which you can create buttons, images, dropdown menus and more.
To demonstrate some uses of a dialog, here's a screenshot from one of my maps:
Spoiler!
In this screenshot, I am using three dialogs. See if you can find out where the are.
Answer:
Spoiler!
2. Tutorial Goal
So what are we going to accomplish in this tutorial?
We are going to create a Hero selection dialog that will look something like this:
If you're disappointed in the looks of this, don't be. You could create much more intriguing dialogs given some time but due to the simplicity of this tutorial we will keep it simple.
If you're not disappointed, great! Let's move on.
3. Time to work
Time to get started with the actual work. Open up your map and open the trigger editor. For the rest of the tutorial, I will assume you know the absolute basics of the trigger editor(Creating new triggers, events, variables, conditions and actions) because if you don't, this is not what you should be focusing on for the moment.
Create a new trigger, we will call it "Create Hero Pick Dialog".
We want to create it when the map starts so we'll add the event "Map initialization". We always want to create it when the map starts so we don't need any conditions.
Let's move on to the actions. The first thing we need to do is to create the dialog itself. This is done with the action "Create Dialog".
When you add the "Create Dialog" action you will see that it has a number of parameters:
- Modal
- Width
- Height
- OffsetX
- OffsetY
- Anchor
Here's what each of them do:
Spoiler!
For this, we want a pretty big dialog to fit all our pictures and such so we will go for:
Width: 800
Height: 600
We'll use the anchor "Center" since we want the dialog in the middle of the screen.
No offsets needed since it's already where we want it to be.
Now if you test your map, you would expect there to be a dialog box on your screen, however to see it you first need to show it.
We might not want to show it as soon as the map starts, but let's make it so for now. Add the action "Show/Hide dialog".
Visible: Show
Dialog: Last created dialog
Players: All players
Now in almost all cases you want to be able to reference the dialog outside of the trigger where you create it. Maybe you want to hide it after the user clicks a button or you might want to modify it later on. This is why we're now going to save our newly created dialog in a variable.
Create a new variable(make sure it's global, that means it's in the list to the left along with all your triggers). Call it HeroDialog and change the type to Dialog.
Go back to your trigger and add the action "Set variable". Set HeroDialog = (Last Created Dialog).
Now it's time to create the content for the dialog. A dialog has items. An item can be an image, button, checkbox, etc.
First, let's create the portraits for our heroes. We will need a dialog item with the image type for this. Use the action "Create Dialog Item (Image)"
This action comes with a bunch of different parameters. I will go through them all(although a bit faster than I did with the "Create Dialog" action)
Spoiler!
Here are the parameters I used:
Create Dialog Item (Image)
Dialog: Last Created Dialog
Width: 200
Height: 300
Anchor: Top Left
Offset X: 50
Offset Y: 50
Tooltip: ""
Image: Assets\Textures\hightemplarportrait_static.dds
Image Type: Normal
Tiled: false
Tint Color: White
Blend Mode: Normal
Copy this action two times(we have three heroes, so we need a portrait for each one)
In the first copy, change Offset X to 300 and Image to "Assets\Textures\battlecruiserportrait_static.dds"
In the second copy, change Offset X to 550 and Image to "Assets\Textures\archonportrait_static.dds"
It's time to create the text you see under the portraits.
Text areas in Starcraft 2 are called "Labels" so let's create a new text field with the action: "Create Dialog Item (Label)"
As you can see, this action has mostly the same parameters as "Create Dialog Item (Image)". There are some new though. I've explained them here:
Spoiler!
I used these parameters:
Create Dialog Item (Label)
Dialog: Last Created Dialog
Width: 200
Height: 100
Anchor: Top Left
Offset X: 50
Offset Y: 400
Text: "Intelligence based hero. Abilities: Feedback, Psi Storm"
Color: White
Text Writeout: false
Text Writeout Duration: 2.0
Copy this action two times.
In the first copy, change Offset X to 300 and text to "Flying hero. Abilities: Yamato cannon, Warp Drive."
In the second copy, change Offset X to 550 and text to "Psionic Hero. Abilities: Psi Chain, Hallucination."
Now it's time for the buttons.
As you can see, this action as well uses mostly the same parameters as the other two dialog items.
The new parameters are explained here:
Spoiler!
Here are my parameters.
Create Dialog Item (Button)
Dialog: Last Created Dialog
Width: 200
Height: 50
Anchor: Top Left
Offset X: 50
Offset Y: 500
Tooltip: ""
Button Text: "Pick Hero"
Hover Image: ""
Copy this two times.
In the first copy, change offset X to 300.
In the second copy, change offset Y to 550.
Let's step back and think for a while. We will need to reference to our buttons outside of this trigger. Otherwise we wont know when the player presses a button. Therefore we need to save the dialog buttons in a variable.
Create three new variables with type "Dialog Item". Name them something like "HeroPick1", "HeroPick2", "HeroPick3".
We need to set these to the button we create. So create the action "Set variable" after each "Create Dialog Item (Button)". You should set all of them(HeroPick1, HeroPick2, HeroPick3) to (Last created Dialog).
Your triggers should now look something like:
Spoiler!
Now the dialog should look like the one in the picture of our goal. However we're not done yet. Our dialog might be good-looking, but it's completely useless since it does nothing.
Let's create a new trigger that we call "Pick Hero".
We want it to do stuff when we click a button so we add the Event "Dialog Item is used". We only want the trigger to run when one of our hero pick buttons is clicked so in conditions we add "Or". Under the "or" we add three conditions:
- (Used dialog item) == HeroPick1
- (Used dialog item) == HeroPick2
- (Used dialog item) == HeroPick3
Now we come to actions. When a player picks a hero we want to create the correct hero for the player and we also want to hide the hero dialog for the player so the player wont be able to pick additional heroes.
To create the correct hero we will use the "switch" action. The switch action chooses what case to do depending on the value of a variable. In our case we want the switch to depend on the value of (Used Dialog Item).
We will add one case for each hero.
In each case, change the value to the correct dialog item. For example, the high templar's case would look like this:
General - If (HeroPick1)
Actions
Unit - Create 1 High Templar for player (Triggering player) at (Current camera target of player (Triggering player)) using default facing (No Options)
In this case I create the hero in the middle of the screen for the player.
Outside of the switch you want the action "Show/Hide dialog".
You want to Hide HeroDialog for (Player group((Triggering player)))
Your code should now look like this:
Spoiler!
4. Conclusion
This is it! The end! Goal accomplished. Hopefully you'll be able to figure out the other stuff like checkboxes and dropdown menus.
I have one thing left to teach and it is an important thing. Use constants to store item sizes and offsets and such. As an example, let's say we wanted to change the portrait size. Since we have 3 heroes we would have to change the width and height three times each. That is unnecessary and when you're doing bigger more complex dialogs, editing each item by hand might be a real pain.
I didn't know this when I made a big tech tree for one of my first custom maps so I will probably never change how it looks even though I want to. Why? Because that means I would have to change the dimensions on 100 buttons and 100 images. That's just too much effort to be worth it.
So in our example we could've made a constant variable called HeroPortraitWidth and make all the images width use HeroPortraitWidth. Then we would only have to change HeroPortraitWidth to change the width of all portraits.
With some smart use of for-loops and constants, you can can make the offset work as well.
For examples on this, check out my JAVA library. It's very dynamic when it comes to stuff like this(http://www.thehelper.net/forums/show...et)?p=1364593)
One thing to keep in mind when you are working with dialogs is that all the measurements are in pixels. This means that a dialog that only covers half of your 25" screen might completely cover someone's laptop screen. Keep this in mind when creating your dialogs.
One way to fix this is to scale according to screen resolution. Problem is that you then need to get the screen resolution. There are some custom made libraries that does this for you, but be aware that you need the user to calibrate once.
Custom Screen Resolution libraries:
http://www.thehelper.net/forums/show...een-Resolution
http://www.sc2mapster.com/forums/res...et-resolution/
Advanced challenges:
Spoiler!
I've attached the map if there was something you didn't understand.