User:Hendo:Tutorials:Display

From Bohemia Interactive Community
Jump to: navigation, search


Dynamic Display (Dialog) Tutorial

This tutorial shows how to create and hook a display GUI object, the dynamically adjust (move) it.

Step 0 : Create a simple Mission

Create a simple mission with a single playable unit. Name the unit player.

Step 1 : Create the resources

Go to your root mission folder (you need to save a mission first). For me, that's My Docs/VBS2/mpmissions/mymission.Intro

Create a text file named description.ext

Edit the file.

Place this code inside:

// Control types
#define CT_STATIC	0

// Static styles
#define ST_LEFT	0
#define ST_RIGHT	1
#define ST_CENTER	2
#define ST_UP		3
#define ST_DOWN	4
#define ST_VCENTER	5

#define ST_SINGLE	0
#define ST_MULTI	16
#define ST_PICTURE	48
#define ST_FRAME	64

#define ST_HUD_BACKGROUND 128
#define ST_TILE_PICTURE 144
#define ST_WITH_RECT 160
#define ST_LINE	176

#define ST_SHADOW	256
#define ST_NO_RECT	512

#define FontM "TahomaB"
#define ST_LEFT      0
#define ST_RIGHT     1
#define ST_CENTER    2
#define CT_STATIC    0
class RscText{        
	type = CT_STATIC;        
	idc = 889;
	style = ST_LEFT;        
	colorBackground[] = {0, 0, 0, 0};        
	colorText[] = {1, 1, 1, 1};        
	font = FontM;        
	sizeEx = 0.04;
};

class RscTestA
{  
	idd = 888;
	movingEnable = true;
	controlsBackground[] = { };
	objects[] = { };
	controls[] = { HELLO_WORLD };  
	class HELLO_WORLD : RscText  
	{    
		idc = 181;    
		style = ST_CENTER;    
		x = 0.4;    
		y = 0.45;    
		w = 0.5;    
		h = 0.5;    
		text = "Hello World!";  
	};
};



Save the file.

Note: If you want to read more about the description.ext file, check out Vektorboson's excellent tutorial at OFPEC.

Step 2 : Create a script to test your display

In your root mission folder, create another text file named text.sqf. Edit the file and paste in the following:


//Make a dialog
ok = createDialog "RscTestA";

//pause and wait for the resource
sleep 1;

//Get the dialog display (a viewport)
_display = findDisplay 888;

if (str (_display) != "no display") then 
{
	hint "FOUND DISPLAY 888";
	_ChildControl = _display displayCtrl 181;
	sleep 1;
        //Move it
	_ChildControl ctrlSetPosition [0.5, 0.5];

        //You need this to cue animation -- will smoothly animate to new position.  Could use zero here
	_ChildControl ctrlCommit 1;
	
};


This script creates a dialog using RscTestA then uses itself to 'hook' the dialog's display (viewport).

Once the display is found, it grabs the child control with id 181 (the actual text inside the display).

It then moves the child.

Note: You can probably use some of the other GUI commands to change the font, color, size, etc.

Step 3 : Set up an initialization for your script

Finally, call your script. In the player's initialization statement, put:

call {player execVM "text.sqf"; }

You can also do this with a trigger (untested)

If all goes well, you should see the text animating across the screen after a few seconds.

Tested with VBS2 v. 1.23.


Thanks to this forum post by Mandoble for showing the way.